【发布时间】:2012-02-10 06:43:42
【问题描述】:
GObjectIntrospection 允许在任何高级语言中使用 C 对象。 https://live.gnome.org/GObjectIntrospection
IBus 是 linux 的输入法框架。 code.google.com/p/ibus
我在使用 GObjectIntrospection / javascript 时遇到了一些麻烦。我试过了 创建一个 ibus 引擎。相同的代码适用于 vala,python。但在 javascript 段错误。 我正在使用opensuse 12.1 gnome3。 “ibus-devel”包提供了 GObjectIntrospection 所需的 /usr/share/gir-1.0/IBus-1.0.gir。
我正在尝试运行以下代码。
#!/usr/bin/env gjs
const IBus = imports.gi.IBus;
//get the ibus bus
var bus = new IBus.Bus();
if(bus.is_connected()){
var factory = new IBus.Factory({
connection: bus.get_connection()
});
factory.add_engine({
engine_name:"ibus-sarim",
engine_type:typeof(this)
});
}
它在“new IBus.Factory”的第 6 行崩溃。
终端输出,
(gjs:13353): GLib-GIO-CRITICAL **: g_dbus_connection_register_object:
assertion `object_path != NULL && g_variant_is_object_path
(object_path)' failed
Segmentation fault
我不知道问题出在哪里。我尝试了 vala 测试代码 在 ibus 上提供 https://github.com/ibus/ibus/blob/master/bindings/vala/test/enchant.vala 它编译并运行良好。 在 enchant.vala 第 148 行,
var factory = new Factory(bus.get_connection());
创建工厂的代码与我在 javascript 中尝试的代码相同。 也在python中,
from gi.repository import IBus
from gi.repository import GLib
from gi.repository import GObject
IBus.init()
bus = IBus.Bus()
if bus.is_connected():
factory = IBus.Factory.new(bus.get_connection())
这似乎也可以正常工作,没有段错误。但是在javascript中它每次都失败。 任何想法 ?我敲了几天,没有任何效果:(
【问题讨论】:
-
c 中的 IBus.Factory 构造函数位于 github.com/ibus/ibus/blob/master/src/ibusfactory.c 第 352 行。有
IBusEngine *object = g_object_new (IBUS_TYPE_FACTORY, "object-path", IBUS_PATH_FACTORY, "connection", connection, NULL);和 github.com/ibus/ibus/blob/master/src/ibusshare.h 第 81 行#define IBUS_PATH_FACTORY "/org/freedesktop/IBus/Factory"所以报告断言不可能失败。我不知道它为什么会失败!
标签: javascript linux gobject