Archive for the ‘Code’ Category

超嚴重 memory leak

Tuesday, November 13th, 2007

怎麼想也想不通,為甚麼用 GTK+ 的程式會變得那麼恐佈。兩三天前試寫一個空白的 GTK+ window,然後用 valgrind 檢查一下(萬分感謝 valgrind),肯定的 memory leak 是 0 byte,但只要隨便加一個 widget 上去,情況就失控了:

沒有 widget 0 byte
加一個 vbox 0 byte
再加一個 statusbar 131KB (!)
不加 statusbar,改為加 notebook 和加一個空白 page 62KB
再加回 statusbar 131KB
再加 button box,其中有一個 button 131KB

註:只計算 “definitely lost” 和 “indirectly lost” 的部份。

嚇一跳之後,定一定神,使用 valgrind 的 --leak-check=full 選項,發現不約而同地,每種情況都大約有 99.5% memory leak 是來自 fontconfig 的。似乎任何會觸碰到 pango 的 widget 都會引致同一結果:

132,396 (39,680 direct, 92,716 indirect) bytes in 154 blocks are definitely lost in loss record 160 of 166
    at 0x402071B: realloc (vg_replace_malloc.c:306)
    by 0x45C6253: (within /usr/lib/libfontconfig.so.1.2.0)
    by 0x45C6C06: (within /usr/lib/libfontconfig.so.1.2.0)
    by 0x45C70FB: (within /usr/lib/libfontconfig.so.1.2.0)
    by 0x45C3892: FcFontRenderPrepare (in /usr/lib/libfontconfig.so.1.2.0)
    by 0x49CF7E2: (within /usr/lib/libpangoft2-1.0.so.0.1600.2)
    by 0x462625F: pango_font_map_load_fontset (in /usr/lib/libpango-1.0.so.0.1600.2)
    by 0x4624206: (within /usr/lib/libpango-1.0.so.0.1600.2)
    by 0x4624591: pango_itemize_with_base_dir (in /usr/lib/libpango-1.0.so.0.1600.2)
    by 0x462CA1A: (within /usr/lib/libpango-1.0.so.0.1600.2)
    by 0x462D646: (within /usr/lib/libpango-1.0.so.0.1600.2)
    by 0x418398F: gtk_label_size_request (gtklabel.c:2117)

現在還不知道是否我做漏了甚麼事情。真是想不通。但這樣下去,每次 130 KB,有多少 RAM 夠我用呀?

初步解碼成功!

Thursday, October 25th, 2007

終於成功突破第一個難關。現在不需要依賴 sniffer,可以直接接駁伺服器傳送資料了。 :-)

0035577
0035578
0034
4980
0024,GDCTRpCcNW.mFY5A55u1DbA-,HUMAN,0,0,http://hk.yimg.com/i/ga/img_no_profile_90.gif,612720,10,0,,False,False,1669,709,0,,1,ken19770421,M,0
30310,1,4,0,0,0,4,0,1,1,1,1,1,1,1,1,1,1,0,0
0025595,@Explorer595,COMPUTER,0,0,computer.gif,10000,1,0,,False,False,0,0,0,,2,@Explorer595,,0
30310,1,4,5595,0,0,4,0,1,1,1,1,1,1,1,1,1,1,0,0
0025596,@FifthElement596,COMPUTER,0,0,computer.gif,10000,1,0,,False,False,0,0,0,,3,@FifthElement596,,0
30310,1,4,5595,5596,0,4,0,1,1,1,1,1,1,1,1,1,1,0,0
0025597,@NoBadWords597,COMPUTER,0,0,computer.gif,10000,1,0,,False,False,0,0,0,,4,@NoBadWords597,,0
30310,2,4,5595,5596,5597,4,0,1,1,1,1,1,1,1,1,1,1,0,0
4980
30310,2,4,5596,5597,4,5595,0,1,1,1,1,1,1,1,1,1,1,0,0
30310,2,4,5596,5597,4,5595,0,1,1,1,1,1,1,0,1,1,1,0,0
30310,2,4,5596,5597,4,5595,0,1,1,1,1,1,1,0,0,1,1,0,0
30310,2,4,5596,5597,4,5595,0,0,1,1,1,1,1,0,0,1,1,0,0
4980

一個本來以為是 random number 的地方,原來不是 random,而是從伺服器取回來的 unique ID。也許開始設計伺服器時就預先估計會有人像我那樣嘗試解謎語。Paros 真是幫了很大忙,值得推薦。

被 Google Code 和 Ubuntu 擺了一道

Monday, October 15th, 2007

搞 software project,其中一種最怕的情況就是 toolchain 出問題。例如 compiler 有 bug, libtool/automake/autoconf 亂來等等都是很難追查的。今天遇到的,雖然不是棘手得很過份,但也算是 toolchain 的一部份吧。

第一個是 subversion 出事,今次買到教訓了,真不該安裝 Ubuntu 的 proposed update,自招的。本來能好好地經 HTTPS 存取 subversion repository,裝了 update package 就不行了。結果是自己 compile 來解決(其實也可以回復到舊版本的,不過反正也是壞了,就試試新版吧)。

第二個是發現了 google code 如何運作的「秘密」:原來編輯 project 的 wiki page 也是 subversion commit。本來我一向是以自己的 subversion repository 為主導,定期將 source code synchronize 至 Google Code 那邊的。但今天一試,svnsync 竟突然說 out of sync 了。最初我怎麼都搞不懂是甚麼一回事,的確兩邊的版本不同了,但 Google Code 那邊最後的版本卻是甚麼改動都沒有,甚至連 commit message 也是空白一片。到最後嘗試翻抽屉,看一看整個 repository,呵,原來最後的版本是改了 wiki page,它竟然將我編輯的 wiki page 加入 subversion 裏面。

這次沒得選擇了,唯有放棄自己本身的 repository,「安份守已」地用 google 那個。或許當初選擇 Sourceforge 就不會那麼麻煩吧?

GNOME panel analog clock

Friday, October 12th, 2007

GNOME panel analog clock screenshot

I’ve been using for vertical panel for quite a while, and keep wondering why those GNOME people removed analog clock entirely and don’t even consider porting it to GNOME 2. Being afraid of writing one myself, I keep searching on net to no avail. Recently noticed MacSlow’s Cairo-Clock and it’s quite beautiful; but hell no, it doesn’t work without compiz!

However luck is on my side; Joachim Breitner has got one. :-) But the patch is for GNOME 2.12, so I anticipate some effort to port it to 2.18 — and I’m right. Not a no-brainer, but at least got it working on my machine without any apparent error.

The patch (against Ubuntu Feisty gnome-panel 2.18.1-0ubuntu3.1 package) can be downloaded here. It should work with Debian package as well. Later I’ll also upload deb binary package somewhere when time permits.

WP-GownFull

Tuesday, July 17th, 2007

上個月 Ben Lau 向我提及功夫輸入法這個 project;其中一個有趣的地方是,這個 project 是由兩個香港人負責的。撇開負責的人不說,單說 project 本身,是一個在 web 介面使用的中文(也可以是別的語言)輸入法,系統本身不需要安裝任何輸入法,只要有個瀏覽器就可以用了。即是說用英文 Windows 也可以在瀏覽器中入中文字。當我看過 demo 不久,就在想有沒有可能在 WordPress 裏面用 —— 於是寫了點東西出來。

WordPress 的留言欄位中使用 GownFull

花的時間不多,主要都是用在解讀 GownFull 輸入法如何讀取設定,和考慮如何將設定簡化,並透過 WordPress 的資料庫儲存設定。本來 GownFull 的設定方法頗為原始,要人手修改 config.php,現在不用了,而且可以在 WordPress 的管理介面選擇啟用哪幾種輸入法。暫時只在 blog 留言的位置啟動輸入法,遲些考慮會不會在 post 文章的介面也啟動吧。

其實已經想不到有甚麼功能要加了,日後最麻煩的,恐怕就是要從 GownFull 的 source code 定期更新;只是一個月,就多了 mimeTeX 的輸入法了,看來他們開發的速度不算慢。還有就是想更新一下它的倉頡和速成碼表:好像很多字都 map 到 PUA(即造字區)去,這樣對於 Unicode adoption 很不利。

有興趣想試的話可以在這裏留言,或者私下問我,因為我還未想 Google 找得到自己的 subversion repository。另一方面也在自己的站安裝了(在留言時留意一下左上角)。本應到 WordPress 登記開一個 subversion 戶口的,但 WordPress 已漸漸顯露出商品化的徵兆,不能賺錢的事務已經開始拖得就拖,有些人一個月也沒有回覆。或者我在 Google Code 開個 project 算了。

Uploading to WordPress as draft in Drivel

Sunday, June 17th, 2007

Drivel used to be a versatile GUI blog posting application, but it is suffering bit rotting. I’ve been using it since 2005, and noticed its lack of activity at that time. Though some refresh occurred around mid-2006, that is just temporary. Too sad that Drivel looks like not reviving now; it has been unofficially abandoned. And problems likely won’t be fixed now, such as unable to cope with newest blogger API (using Google authentication), selecting multiple blog post categories and so on.

Right now the single thing that annoys me most is, Drivel always publish the post upon clicking the ‘Post’ button, and in no way can I change setting and categories before letting the cat out of the bag. If it can be published as draft, there is still chance to go to web admin interface and change necessary settings.

New option in drivel post dialog

Thus this patch — it adds a checkbox to determine whether the post is published or not when submitting it. The patch also fixes GNOME bug#402672 I have reported (essentially making spellchecking usable again). Just apply the patch and recompile, and it’s done. BUT just for Movable Type and WordPress ONLY, I don’t have LiveJournal account so will not be making any changes for LiveJournal support. BTW LiveJournal bloggers are recommended to use LogJam anyway.

Since all bug reports will be ignored for now, I guess making it available on my own is better.

CLI theme alternative plugin superseded

Monday, June 11th, 2007

PipperL’s alternative theme plugin is convenient when people want to try one of the most geekish WordPress theme, CLI theme, by Rod McFarland. Other than setting it as default theme (most people wouldn’t want that), or using ThemeSwitcher, PipperL’s plugin is the 3rd method — appending '/cli' to the end of site URL automatically changes to CLI theme.

Even though I don’t use PipperL’s plugin anymore (using ThemeSwitcher now), this might still be useful for others: somebody else extended it and gave it a new life: CLI switch. The original plugin no more works for CLI theme 2.0 or above.

Dennys also posts some instruction on how to update the plugin so it works for CLI 2.0 theme. However the instruction is hackish, and not feasible for Joe users.