きりかノート 3冊め

おあそびプログラミング

RubyCocoaのLionでの問題を修正 - (3)

つづき。ここいらはSnow Leopardのときにもあったような気がする。

thread_hooksパッチ未適用のrubyだと実行時にエラー

こんなエラーがでる。

 ../ext/rubycocoa/rubycocoa.bundle: dlopen(../ext/rubycocoa/rubycocoa.bundle,
 9): Symbol not found: _rb_add_threadswitch_hook (LoadError)
   Referenced from: /...RubyCocoa.framework/Versions/A/RubyCocoa
   Expected in: flat namespace

たぶん10.5-10.6あたりのときにlazy bindingの動作まわりがなんとなく変わったような感じなのでその影響かと。weak_importしてるのがNULLにならずに参照エラーになってしまう。

 /* The following two functions are marked as weak imports so that RubyCocoa
    will still load without thread switching hooks support in the ruby
    interpreter.
 */
 extern void *rb_add_threadswitch_hook(rb_threadswitch_hook_func_t func)
   __attribute__ ((weak_import));
 extern void rb_remove_threadswitch_hook(void *handle)
   __attribute__ ((weak_import));

なので、参照前にNSLookupSymbolInImage()でシンボルを解決してシンボルが見つからなければ処理を抜けるようにした(r2311)。

作業中に思い出したんだけど、NS...系のdyldの関数はdeprecatedなのでdlopenやdlsymを使うようにしたほうがよい。とりあえずコメントにTODOと書いておいてあとで直すことにしておく。

mach-o/dyld.hから。

 /*
  * The following dyld API's are deprecated as of Mac OS X 10.5.  They are either
  * no longer necessary or are superceeded by dlopen and friends in <dlfcn.h>.
  * dlopen/dlsym/dlclose have been available since Mac OS X 10.3 and work with
  * dylibs and bundles.
  *
  *    NSAddImage                           -> dlopen
  *    NSLookupSymbolInImage                -> dlsym
  *    NSCreateObjectFileImageFromFile      -> dlopen
  *    NSDestroyObjectFileImage             -> dlclose
  *    NSLinkModule                         -> not needed when dlopen used
  *    NSUnLinkModule                       -> not needed when dlclose used
  *    NSLookupSymbolInModule               -> dlsym
  *    _dyld_image_containing_address       -> dladdr
  *    NSLinkEditError                      -> dlerror
  *
  */

plistのテストが失敗する

plistのテストがいくつか失敗する。調べてみると、OSX.load_plist()でバイナリ形式のplistデータを文字にしようとしてNoMethodErrorになっている。to_plist()でバイナリ形式を作成できるようにしたのに、逆方向のload_plist()は対応してなかったのが問題。

いくつか考えてみたのだけど、単純にUTF-8文字列への変換が失敗したときはNSDataとして扱うように修正(r2312-2313)。本当はデータだけを受け付けるようにするべきだけど、文字的なもので渡したいケースのほうが多いよなと思ってこんな感じに。

残っている問題

NSDecimalのところと、test_cary_structが残り。自分にわかるかなあ。