2015-11-30

Build TclBlend

TclBlend 相關文件:
Tcl/Java interoperability with TclBlend 1.4. A new precompiled binary for Window


環境:
Windows XP
MINGW/MSYS
ActiveTcl 8.6.4.1
Java SE 8u65


使用 MINGW/MSYS 參考文章:
Building TclBlend with msys_mingw


下載 Tclblend 1.4.1 以後,加上 Source Forge 的 3 個 patch:
21 allow TclBlend to load Tcl 8.5 into a Java process
22 Compile/​Run against Tcl 8.6
24 Patch for TclJava Bug 2866640


然後加上 tclBlend\src\native\javaInterp.c 的一些小改變(for Tcl/Tk 8.6):

    if (exception) {
        (*env)->DeleteLocalRef(env, exception);
        (void) Tcl_GetStringResult(interp);
        tPtr->errMsg = (char *) 
            ckalloc((unsigned) (strlen(Tcl_GetStringResult(interp)) + 1));
            //ckalloc((unsigned) (strlen(interp->result) + 1));
        //strcpy(tPtr->errMsg, interp->result);
        strcpy(tPtr->errMsg, Tcl_GetStringResult(interp));
        result = tPtr->errMsg;
    }

就 build 出來了。能不能使用則還不知道。

(update) 嘗試使用更加相容其它版本的寫法

        #if TCL_MAJOR_VERSION > 8 || \
           (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION > 5)
            ckalloc((unsigned) (strlen(Tcl_GetStringResult(interp)) + 1));
        #else
            ckalloc((unsigned) (strlen(interp->result) + 1));
        #endif
        #if TCL_MAJOR_VERSION > 8 || \
           (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION > 5)
        strcpy(tPtr->errMsg, Tcl_GetStringResult(interp));
        #else
        strcpy(tPtr->errMsg, interp->result);
        #endif



更新:
無法正確執行範例,會發生 crash 的問題。
使用參考文件所提供的檔案可以成功執行,但是我自己編譯的 tclBlend 如果執行範例會 crash,不知道問題出在哪裡。

更新:
使用 TclBlend, Tcl/Tk 8.5.18 and Thread extension 2.7.2 and JDK 8
(單純的 TclBlend 1.4.1,沒有使用 patch)
測試成功

% package require java
1.4.1

% java::import java.net.InetAddress

% puts "My IP Address is: [ [ java::call InetAddress getLocalHost ] getHostAddress ] "
My IP Address is: 192.168.2.105


更新 2015/12/01:
會是 Tcl 8.5.18 與 Tcl 8.6.4 的版本差異所造成的問題嗎?


更新 2015/12/01:
測試 Tcl 8.6.0,
測試成功
看起來跟 Thread Extension 與 JDK 版本無關


更新 2015/12/01:
測試 Tcl 8.6.1, 結果 crash

TCLBLEND_DEBUG: Interp.evalString()
TCLBLEND_DEBUG: cmd is : ->package provide java 1.4.1<- br="">TCLBLEND_DEBUG: JavaInitBlend returning
TCLBLEND_DEBUG: Tclblend_Init finished
TCLBLEND_DEBUG: JavaInitBlend returned TCL_OK
1.4.1
% java::import java.net.InetAddress
TCLBLEND_DEBUG: JavaCmdProc()
% puts "My IP Address is: [ [ java::call InetAddress getLocalHost ] getHostAddre
ss ] "
TCLBLEND_DEBUG: JavaCmdProc()


更新:
記錄我對 TclBlend 在 MinGW/MSYS 與 Tcl 8.6.x 編譯的做法(雖然 TclBlend 在 Tcl 8.6.1 及以後的版本沒辦法用)

1. 使用下列的 script 編譯出 Tcl/Tk 8.6.x

(Tcl 與 Tk 的 source code 放在 /src/tcl 與 /src/tk 的目錄下)

#!/bin/sh
mkdir -p /src
mkdir -p /opt/tcl
mkdir -p /build/tcl
mkdir -p /build/tk
[ -e /src/tcl ] && {
    cd /build/tcl
    /src/tcl/win/configure --prefix=/opt/tcl --enable-threads && make && make install && {
        [ -e /src/tk ] && {
        cd /build/tk
        /src/tk/win/configure --prefix=/opt/tcl --enable-threads --with-tcl=/build/tcl \
            && make && make install
        }
    }
}

2.Build TclBlend

假設已經下載完 source code package,並且放在 /src/tclBlend

2-1 mkdir /build/tclblend
2-2 cd /build/tclblend
2-3 /src/tclBlend/configure --prefix=/opt/tcl --with-tcl=/build/tcl --with-thread=/build/tcl/pkgs/thread2.7.2/ --with-jdk=/c/JDK8/
2-4 make
2-5 make install

在 2-3 的 thread 要看 Tcl/Tk 8.6.x 當時附帶的 Thread extension 版本。因為 8.6.x 已經會附帶一個 Thread extension 而且在第一個步驟就已經編譯完成,所以不用自己再去下載一個來編譯。

要執行 TclBlend 的時候,使用 jtclsh.bat 或者是 jtclsh 啟動。jtclsh.bat 或者是 jtclsh 都是在設定環境變數,主要有下列幾個可以指定的地方:

set PREFIX=C:/MinGW/msys/1.0/opt/tcl
set EXEC_PREFIX=C:/MinGW/msys/1.0/opt/tcl
set TCLSH=C:/MinGW/msys/1.0/opt/tcl/bin/tclsh86

例如說,如果你複製 C:/MinGW/msys/1.0/opt/tcl 目錄下的檔案到 C:/Tcl/ 下,那麼就需要對這幾個環境變數做相對應的修改。


更新:
TclBlend: Tcl core patch

所以預計在 8.6.6 可以修正 crash 問題,8.6.1 ~ 8.6.5 則需要自己 patch Tcl source code。

2015-11-27

tcl-lmdb v0.2.4

檔案放置網頁


tcl-lmdb - Tcl interface to the Lightning Memory-Mapped Database

About


This is the Lightning Memory-Mapped Database (LMDB) extension for Tcl using the Tcl Extension Architecture (TEA).

LMDB is a Btree-based database management library with an API similar to BerkeleyDB. The library is thread-aware and supports concurrent read/write access from multiple processes and threads. The DB structure is multi-versioned, and data pages use a copy-on-write strategy, which also provides resistance to corruption and eliminates the need for any recovery procedures. The database is exposed in a memory map, requiring no page cache layer of its own. This extension provides an easy to use interface for accessing LMDB database files from Tcl.

Change Log

  • generic/mdb.c: Update source code. LMDB 0.9.16 with extra fixes from github.
  • generic/tclmdb.c: env_handle open command add option -nosubdir

一些說明


這個版本只有進行一點小更新,env_handle open command 新增一個 option -nosubdir,然後更新 LMDB 到目前的 code base。

2015-11-24

Firebird/Interbase Extension

如果是用 Firebird 尋找,答案是 SQL Relay。

如果是用 Interbase 跟在 Great Unified Tcl/Tk Extension Repository 找答案,
  • dbi - Generic Tcl interface to SQL databases,有支援 Firebird 與 Interbase
  • ibtcl
  • tcl-sql-ibase
這些應該就是除了 TDBC-ODBC 以外的選擇了,但是我就沒有去實際測試,只是尋找一下目前 Firebird 的 Tcl extension 狀況。

2015-11-19

Push tclunqlite and tcl-lmdb code to Github

二個我都只是建立一個「沒有版本」的空白 Git 儲存庫,然後把 source code push 上去。


tcl-lmdb
Tclunqlite


我不知道這樣對於這二個案子有沒有幫助,不過試看看。


* 更新,也將 Tcltaglib 的 source code push 上去。
tcltaglib

2015-11-18

TDBC-ODBC and Firebird ODBC

測試環境:
Windows XP
Firebird 2.5.4
Firebird ODBC 2.0.3
Active Tcl 8.6.4.1


目前如果要使用 Firebird,TDBC 沒有提供相關的 driver,但是因為 Firebird 有 ODBC driver 而 TDBC-ODBC 已經有提供了,所以測試一下目前 TDBC-ODBC via Firebird ODBC 的狀況。

ODBC DSN 設定如下:


然後使用下列的方式測試:

package require tdbc::odbc

set connStr "DSN=Firebird DSN; UID=danilo; PWD=danilo;"
tdbc::odbc::connection create db $connStr

set statement [db prepare {create table person (id integer, name varchar(40))}]
$statement execute
$statement close

set statement [db prepare {insert into person values(1, 'leo')}]
$statement execute
$statement close

set statement [db prepare {insert into person values(2, 'yui')}]
$statement execute
$statement close

set statement [db prepare {SELECT * FROM person}]

$statement foreach row {
    puts [dict get $row ID]
    puts [dict get $row NAME]
}

$statement close

db close


然後再測試刪除 table:

package require tdbc::odbc

set connStr "DSN=Firebird DSN; UID=danilo; PWD=danilo;"
tdbc::odbc::connection create db $connStr

set statement [db prepare {drop table person}]
$statement execute
$statement close
db close


看起來是正確工作的。

2015-11-13

tcl-lmdb v0.2.3

檔案放置網頁


tcl-lmdb - Tcl interface to the Lightning Memory-Mapped Database

About


This is the Lightning Memory-Mapped Database (LMDB) extension for Tcl using the Tcl Extension Architecture (TEA).

LMDB is a Btree-based database management library with an API similar to BerkeleyDB. The library is thread-aware and supports concurrent read/write access from multiple processes and threads. The DB structure is multi-versioned, and data pages use a copy-on-write strategy, which also provides resistance to corruption and eliminates the need for any recovery procedures. The database is exposed in a memory map, requiring no page cache layer of its own. This extension provides an easy to use interface for accessing LMDB database files from Tcl.

Change Log

  • generic/tclmdb.c: env_handle open command add option -fixedmap
  • generic/tclmdb.c: Add a thread exit handler to delete hash table.
  • generic/tclmdb.c: Try to use ThreadSpecificData to per thread hash table.
  • generic/mdb.c: Update source code. LMDB 0.9.16 with extra fixes from github.

一些說明


試著使用更 thread-safe 的寫法。

2015-11-12

TDBC stub (tdbcpostgres)

Tool:
pkgs/tdbc1.0.3/tools/genExtStubs.tcl


就實驗的結果來看(接下來以 tdbcpostgres1.0.3 為例),應該要準備二個檔案:
  • pqStubDefs.txt:會使用到的 client function 與可能的 client 名稱
  • pqStubInit.c -> DO NOT EDIT THESE NAMES 的部份就是程式產生的部份 (pqStubLibNames, pqSymbolNames),其它的部份要參考其它的 driver 先寫好
然後準備一個沒有標準的 client header 檔時會用到的 fakepq.h,tdbcpostgres.c 就是透過剛才產生的 stub 使用 client function 來存取資料庫,也就是所有的實作都集中在這個檔案。

2015-11-08

tcl-lmdb v0.2.2

檔案放置網頁


tcl-lmdb - Tcl interface to the Lightning Memory-Mapped Database

About


This is the Lightning Memory-Mapped Database (LMDB) extension for Tcl using the Tcl Extension Architecture (TEA).

LMDB is a Btree-based database management library with an API similar to BerkeleyDB. The library is thread-aware and supports concurrent read/write access from multiple processes and threads. The DB structure is multi-versioned, and data pages use a copy-on-write strategy, which also provides resistance to corruption and eliminates the need for any recovery procedures. The database is exposed in a memory map, requiring no page cache layer of its own. This extension provides an easy to use interface for accessing LMDB database files from Tcl.

Change Log

  • generic/tclmdb.c: Fix cursor_handle renew issue. (update)
  • generic/tclmdb.c: Implement dbi_handle del command behavior.

一些說明


加強 dbi_handle del 的功能。希望我網頁的說明足夠清楚。

The command dbi_handle del delete items from a database. If the database supports sorted duplicates and the data parameter is "" (empty string), all of the duplicate data items for the key will be deleted. Otherwise, if the data parameter is non-NULL only the matching data item will be deleted.

2015-11-07

tcl-lmdb v0.2.1

檔案放置網頁


tcl-lmdb - Tcl interface to the Lightning Memory-Mapped Database

About


This is the Lightning Memory-Mapped Database (LMDB) extension for Tcl using the Tcl Extension Architecture (TEA).

LMDB is a Btree-based database management library with an API similar to BerkeleyDB. The library is thread-aware and supports concurrent read/write access from multiple processes and threads. The DB structure is multi-versioned, and data pages use a copy-on-write strategy, which also provides resistance to corruption and eliminates the need for any recovery procedures. The database is exposed in a memory map, requiring no page cache layer of its own. This extension provides an easy to use interface for accessing LMDB database files from Tcl.

Change Log

  • generic/tclmdb.c: Implement cursor_handle get command option: -set_range -get_both_range
  • generic/mdb.c: Update source code. LMDB 0.9.16 with extra fixes from github.

Update, keep version to v0.2.1

  • generic/tclmdb.c: Add more check in env_handle copy command. Fix --with-system-lmdb option issue.

2015-11-05

tcl-lmdb v0.2

檔案放置網頁


tcl-lmdb - Tcl interface to the Lightning Memory-Mapped Database

About


This is the Lightning Memory-Mapped Database (LMDB) extension for Tcl using the Tcl Extension Architecture (TEA).

LMDB is a Btree-based database management library with an API similar to BerkeleyDB. The library is thread-aware and supports concurrent read/write access from multiple processes and threads. The DB structure is multi-versioned, and data pages use a copy-on-write strategy, which also provides resistance to corruption and eliminates the need for any recovery procedures. The database is exposed in a memory map, requiring no page cache layer of its own. This extension provides an easy to use interface for accessing LMDB database files from Tcl.

Change Log


  • generic/tclmdb.c: Update source code
  • generic/mdb.c: Update source code
  • generic/tclmdb.c: Implement dbi_handle stat command
  • generic/tclmdb.c: lmdb open command add option:-reversekey and -reversedup
  • Makefile.in: add workaround for glibc pthread robust mutex support fix (for Linux glibc < 2.12)

2015/11/06 update, keep version to 0.2


  • configure.ac: add --with-system-lmdb option, causes the TCL bindings to LMDB to use the system shared library for LMDB. Default setting is no.
  • generic/tclmdb.c: Add LMDB version check in env_handle copy command. Using mdb_env_copy2 function need >= version 0.9.14.

Add --with-system-lmdb option to configure file (default setting is no).

If your Linux distribution (ex. Debian, Ubuntu, Fedora, and OpenSuSE) includes LMDB, now tcl-lmdb support to use the system shared library for LMDB.

Below is an example:
./configure --with-system-lmdb=yes

2015-11-04

tcl-lmdb v0.1.1

檔案放置網頁


tcl-lmdb - Tcl interface to the Lightning Memory-Mapped Database

About


This is the Lightning Memory-Mapped Database (LMDB) extension for Tcl using the Tcl Extension Architecture (TEA).

LMDB is a Btree-based database management library with an API similar to BerkeleyDB. The library is thread-aware and supports concurrent read/write access from multiple processes and threads. The DB structure is multi-versioned, and data pages use a copy-on-write strategy, which also provides resistance to corruption and eliminates the need for any recovery procedures. The database is exposed in a memory map, requiring no page cache layer of its own. This extension provides an easy to use interface for accessing LMDB database files from Tcl.

一些說明


實作 cursor_handle count command。

本來我以為解決 GLIBC 2.11 版本(及以下)對於 pthread robust mutex 支援度的問題,結果發現我寫錯了,所以沒有放進來這個版本。這個版本只有多實作一個 command。

所以,這是一個測試 (Tclunqlite and tcl-lmdb)

設定為 1000

UQLite (without transction)
寫入 26590 microseconds per iteration
讀取 11439 microseconds per iteration

LMDB
寫入 64458 microseconds per iteration
讀取 11631 microseconds per iteration


設定為 10000

UQLite (without transction) 
寫入 57926 microseconds per iteration
讀取 75323 microseconds per iteration

LMDB
寫入 97469 microseconds per iteration
讀取 67560 microseconds per iteration

設定為 100000

UQLite (without transction)
寫入 616260 microseconds per iteration
讀取 777202 microseconds per iteration

LMDB
寫入 371342 microseconds per iteration
讀取 632069 microseconds per iteration


測試程式 (UNQLite - write):

#!/usr/bin/tclsh

package require unqlite

unqlite db1 "test.db"

set result [time {
for {set i 1} {$i <= 100000} {incr i} {
    db1 kv_store $i $i
}
}]

puts $result

db1 close

測試程式 (UNQLite - read):

#!/usr/bin/tclsh

package require unqlite

unqlite db1 "test.db"

set result [time {
for {set i 1} {$i <= 100000} {incr i} {
    puts [db1 kv_fetch $i]
}
}]

puts $result

db1 close


測試程式 (LMDB - write):

#!/usr/bin/tclsh

package require lmdb

set myenv [lmdb env]
$myenv set_mapsize 1073741824
file mkdir "testdb"
$myenv open -path "testdb"
set mydbi [lmdb open -env $myenv]

set result [time {
set mytxn [env0 txn]
for {set i 1} {$i <= 100000} {incr i} {
    $mydbi put $i $i -txn $mytxn
}
$mytxn commit
}]

puts $result

$mytxn close
$mydbi close -env env0
$myenv close

測試程式 (LMDB - read):

#!/usr/bin/tclsh

package require lmdb

set myenv [lmdb env]
$myenv set_mapsize 1073741824
file mkdir "testdb"
$myenv open -path "testdb"
set mydbi [lmdb open -env $myenv]

set result [time {
set mytxn [env0 txn]
for {set i 1} {$i <= 100000} {incr i} {
    puts [$mydbi get $i -txn $mytxn]
}
$mytxn commit
}]

puts $result

$mytxn close
$mydbi close -env env0
$myenv close

tcl-lmdb v0.1

檔案放置網頁


tcl-lmdb - Tcl interface to the Lightning Memory-Mapped Database

About


This is the Lightning Memory-Mapped Database (LMDB) extension for Tcl using the Tcl Extension Architecture (TEA).

LMDB is a Btree-based database management library with an API similar to BerkeleyDB. The library is thread-aware and supports concurrent read/write access from multiple processes and threads. The DB structure is multi-versioned, and data pages use a copy-on-write strategy, which also provides resistance to corruption and eliminates the need for any recovery procedures. The database is exposed in a memory map, requiring no page cache layer of its own. This extension provides an easy to use interface for accessing LMDB database files from Tcl.

一些說明


實作一部份 Lightning Memory-Mapped Database (LMDB) API 的 Tcl command。

2015-11-01

wiki.tcl.tk has been hijacked

wiki.tcl.tk has been hijacked


(節錄資訊)

It remains down.  The server that manages .tk registrations was hacked into. By exploring DNS resolutions of other .tk sites, we found at least half a dozen other .tk domains that were also redirected to the same unpleasant place. 

Note that neither tcl.tk nor its DNS provider, cloudflare.net, has been attacked. The problem is with the administration of the top-level .tk domain and is not limited to tcl.tk sites. 


看起來是 .tk 網域的安全問題,所以在這個網域下的網站都會被轉址,而不只是 www.tcl.tk 或者是 wiki.tcl.tk 的問題。所以目前有暫時替代的網站網址可以用。