(GObjectIntrospection)尝试使用javascript创建ibus引擎时出现分段错误

(GObjectIntrospection) Segmentation fault when trying to create ibus engine using javascript

本文关键字:引擎 ibus 错误 分段 创建 javascript GObjectIntrospection      更新时间:2023-09-26

GObjectIntrospection允许在任何高级语言中使用C对象。https://live.gnome.org/GObjectIntrospection

IBus是linux的一个输入法框架。code.google.com/p/ibus

我在使用GObjectIntrospection/javascript时遇到了一些麻烦。我试过了创建ibus引擎。同样的代码适用于vala、python。但在javascript seg错误。我使用的是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)
   });
}

它在"新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测试代码在https://github.com/ibus/ibus/blob/master/bindings/vala/test/enchant.vala它编译和运行良好。在附魔.vala第148行中,

var factory = new Factory(bus.get_connection());

创建Factory的代码与我在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())

这似乎也很好,没有seg故障。但在javascript中,它每次都会失败。知道吗?我已经讨论了几天了,但没有任何效果:(

在IBusFactory中:

"connection"               IBusConnection*       : Read / Write / Construct Only

文件上写着"Construct Only"。这一点目前有待解释,但对我来说,这意味着它可能是一个私人或受保护的阶级成员。也就是说,构造函数被定义为:

IBusFactory *       ibus_factory_new                    (IBusConnection *connection);

构造函数中有一个连接变量。请注意,当你以这种方式提供时,你的应用程序运行良好。

const IBus = imports.gi.IBus;
//get the ibus bus
var bus = new IBus.Bus();
if(bus.is_connected()){
    var factory = new IBus.Factory(bus.get_connection());
}

现在对于factory.add_engine(),定义如下:

void                ibus_factory_add_engine             (IBusFactory *factory,
                                                         const gchar *engine_name,
                                                         GType engine_type);

这意味着您必须提供engine_nameengine_type作为函数参数。这项工作:

factory.add_engine('ibus-engine-name', some-engine-type);

请参阅http://ibus.googlecode.com/svn/docs/ibus/ch03.html发动机创意。这段代码不会出错,但也不起作用。它指示直到add_engine()的第二个参数为止的正确语法。

#!/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(bus.get_connection());
    factory.add_engine("ibus-sarim", typeof(this));
}