Wonderful day in Beijing Happy-Valley

昨天周二,我们team的“老少”同事到欢乐谷outing。早上7:30接到延栋,路上比较拥堵,8点了,还没出清河收费站呢。看来定在9点的集合时间,是要迟到了。过了红领巾桥,前面开始通畅了起来,结果不到8:50,我们就到了。等到9:30,大家才陆续到齐,排队入园。

虽说是周二,但是来游玩的人,还是不少。尤以学生居多。 每个项目都要排很长的队。上午主要玩儿了碰碰车,和天地双雄、悬挂式过山车两个大型的项目,爽!中午草草吃了点东西,然后到“蚂蚁乐园”,玩儿了几个儿童项目,发现自己对于纯水平旋转的项目,还是和小时候一样,晕得厉害。缓了半天,才将心神稳了下来。

最后回到上午刚入园的地方,参加“奥德赛之旅”。为了保护相机,我只是在旁参观。随着小艇俯冲而下,真是水势冲天,甚是壮观。

昨天的第一勇士是yugo同学,他去玩儿了传说有4.3G重力加速度的恐怖的“太阳神车”。因此获得了此次活动的一等奖。

SCIM and UIM packages for Solaris Nevada (or SDX) are available on OS.o

The scim-1.4.6 and uim-1.4.1 packages for Solaris nevada (or Solaris Developer Express) x86 are available on OpenSolaris.org Input Method project.

Download the following archives from http://www.opensolaris.org/os/project/input-method/files:

im-libs-nv-x86.tar.bz2
scim-base-nv-x86.tar.bz2
scim-imes-nv-x86.tar.bz2
scim-tables-nv-x86.tar.bz2
uim-nv-x86.tar.bz2

Extract the archived files, then install the packages:

$ for i in `ls *.bz2`; do bzcat $i | tar xvf -; done
# pkgadd -d . OSIM*

To use scim or uim, for gnome applications, in the text edit area, right click your mouse, and from the popup context menu, slip your pointer to "Input Methods", and select "SCIM Input Method" or "uim". However, in this way, after you application is closed, the scim daemons also exit, and starting scim daemons really requires some time.

To enable scim as the default IM service, modify the im startup script for you login locale, e.g., for zh_CN.UTF-8,
/usr/openwin/lib/locale/zh_CN.UTF-8/imsscript/S505multi (it's actually a symbol link to common/imsscript/S505multi, and all UTF-8 locale use the same file). Then apply the following patch

--- S505multi.orig      Mon Jun 25 09:39:35 2007
+++ S505multi           Mon Jun 25 09:40:04 2007
@@ -4,8 +4,8 @@
# Start iiimx for each desktop.
if [ -x /usr/bin/iiimx ]; then
-    GTK_IM_MODULE=iiim
+    GTK_IM_MODULE=scim
export GTK_IM_MODULE
-    /usr/bin/iiimx -iiimd
+    /usr/bin/scim -d
unset DTSTARTIMS
fi

Then re-login your desktop session.

Note:

currently, the XIM client does not work well with scim XIM front-end. And firefox/thunderbird would start another panel instance with scim im module, therefore I recommend you to use the scim-bridge im module. If you want to use uim, I'd recommend you to start uim-toolbar-gtk (or uim-toolbar-gtk-systray) to show the current IME status, add it to the "Startup Programs" by gnome-session-properties.

Here are some screenshots:

static constructors and symbol bindings in ld.so (2)

Rod Evans suggested me NOT to use "-Bdirect" for a C++ library. And thanks a lot to Stephen Clamage (ANSI C++ chairman), taught me to use "-instlib" option of CC. 

$ CC -flags
... ...
-instlib=<library>    Inhibit generation of instances already in <library>
... ...

The option causes the the compiler to scan the named library for template instances (and inline functions generated out of line), then omit generating them in the current .o file. Therefore, by specifying -instlib=./libbase.so when building libtest.so, the instantiated template "std::basic_string<unsigned int> str" would not be linked into libtest.so. So that the cyclic dependencies would not happen.

I added this option in the Makefile.am of im-scim.so, and it worked as expected.

-im_scim_la_CXXFLAGS=@GTK2_CFLAGS@
+im_scim_la_CXXFLAGS=@GTK2_CFLAGS@ \
+                   -instlib=$(top_builddir)/src/.libs/libscim-1.0.so

You could refer to [osol-tools-linking] thread for details.

static constructors and symbol bindings in ld.so

libbase.cpp:

#include <stdio.h>
#include <stdlib.h>
#include <string>

class Bar
{
public:
        std::basic_string<unsigned int> name;
        char *buf;
        Bar ()  { buf = new char[10]; buf[9] = '';}
        ~Bar () { delete [] buf; }

};

static Bar bar;

void __initialize_libbase ()
{
        printf ("%s\n", bar.buf);
}

libtest.cpp: 

#include <string>
#include "libbase.h"

class Foo {
public:
        std::basic_string<unsigned int> str;
        Foo () { __initialize_libbase (); }
        void test () { printf ("test ()!\n"); }
};

static Foo foo;

test.c:

#include <dlfcn.h>
#include <link.h>

int main (int argc, char **argv)
{
        dlopen ("./libtest.so", RTLD_LAZY|RTLD_GLOBAL);
}

When the main program call dlopen ("libtest.so"), it resolves the dependencies, then adds libbase.so in the initialization sequence ahead of libtest.so (the order is reversed). And the static constructors in a shared library are in the .init routine.

In our case, while it's trying to initialize the static object "bar", it finds there is a symbol "xxx::__null_string_ref_rep<xxx>" (introduced by std::basic_string<unsigned int>), then looks up this symbol in loaded libraries. Firstly, it looks up the symbol in main program, then in libc.so, then finds matched one in libtest.so, and stops to move on (actually, libbase.so also has this symbol). Then it tries to initialize libtest.so, and initializes the static object "foo". Unfortunately, the constructor of Foo calls a external function in libbase, and this function accesses the static instance "bar", which is not initialized yet (the "buf" is not allocated).

So, it cores. That's the root cause why Scim GtkIMModule makes applications core.

While, if you added a main() in libtest.cpp, and compile it to an executable program, this problem would not happen. If you changed the flag from RTLD_LAZY to RTLD_NOW, this problem would not happen either. To resolve this, add -Bdirect option when you link the library. Refer to the new "Direct Binding" chapter of "Linker and Libraries guide".

And I need thank Rod Evans, he taught me to set LD_DEBUG env variable to show the debug informations. You could refer to [osol-tools-linking] thread for details.

Scim GtkIMModule makes applications core on Nevada 66

When I build the scim-1.4.6 packages on Solaris Nevada build 66 with SunStudio 12 (or 11) and CBE 1.6. I found gtk-query-immodules-2.0 would core after loading im-scim.so. In dbx, it reports "no mapping at the fault address", as following:

signal SEGV (no mapping at the fault address) in __rwstd::__rb_tree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,__rwstd::__select1st<std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >::begin at line 741 in file "tree"

It's really a nightmare to tell what's wrong from the error message :( I thought it's a STL problem at the beginning.

It took me 1 day to find the real reason, which is fairly simple: the static object instance initializations are not in proper order.

In im-scim.so, there is a static
object instance, and it calls a global function in libscim-1.0.so, in
that global function, it accesses another static object instance which is not initialized yet. I
wrote a small test program, it just uses dlopen() to load im-scim.so. From
the debugger, I could see, the static constructor in im-scim.so is
called before the static constructor in libscim-1.0.so. Therefore, the test
program cores. I don't know if it is a bug of libCrun or ld.so?

I also asked this question in SunStudio C++ forum as well as [osol-tools-linking]. Here is an workaround patch, please note, it leaves an un-finalized heap object,  __config_repository, so your configuration may not be saved.

P.S., when I am using snv_62, the shared objects works fine, but failed on snv_66.

A simple python utility for updating and merging Java properties

Gnu gettext is a set of tools to manipulate the po files, e.g., msgattribute, msgmerge etc. When I am doing localization for Java program these days, I did not find similar tools to do such kind of things. Then I had to write a little python script to deal with that, -- proputil.py.

$ ./proputil.py --help

Usage:

    proputil merge eng.properties loc1.properties loc2.properties
        merge loc1.propeties and loc2.properties, output to standard output,
        NOTE: loc1.properties has higher priority!

    proputil update eng_orig.properties eng_new.properties
        report the updated and newly added properties from eng_orig.properties
        to eng_new.properties

    proputil status eng.properties loc.properties
        report the localization status of loc.properties

    proputil wordcount test.properties
        report the wordcount of test.properties

For a more sophisticated property parser, you may refer to "ASPN Python Cookbook: A python replacement for java.util.Properties".

Build uim-1.4.1 packages on nevada with SunStudio 11 and CBE 1.6

  • Download the patches and spec files , extract the archive file, and copy them to ~/packages/SOURCES and ~/packages/SPECS separately.
  • Change directory to ~/packages/SPECS, build and install the packages with pkgtool
$ pkgtool build *.spec

Enable Input Method Services in C locale on Solaris

Copy the IM startup scripts to C locale: 


# cp /usr/dt/config/zh_CN.UTF-8/0020.dtims /usr/dt/config/C/
# cp -r /usr/openwin/lib/locale/zh_CN.UTF-8/imsscript /usr/openwin/lib/locale/C/

Then re-login with dtlogin.

However, we don't encourage you to do so,  all XIM clients (e.g., CDE applications) can not use the IM. The better way is to login to to en_US.UTF-8 locale, then all IM services are available.

Add google reader folders to gmail box

I just found an useful tip, to add the folders in your google reader to gmail,

1. Install the Firefox extension Greasemonkey, then restart your firefox
2. Open http://userscripts.org/scripts/show/8598, and click the "Install this script" black button.
3. Go to http://gmail.google.com, and check the result.

I also found an interesting script to add "Search" in your google reader. Refer to these two articles:

1. How to Add Search to Google Reader.
2. Script for Google Reader Search.

However, I failed with the "Google Reader Custom Search (2)" script, maybe this script is not compatible with Firefox 2.0, or google reader has some changes in the UI. :(