【问题标题】:(GObjectIntrospection) Segmentation fault when trying to create ibus engine using javascript(GObjectIntrospection)尝试使用 javascript 创建 ibus 引擎时出现分段错误
【发布时间】: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中它每次都失败。 任何想法 ?我敲了几天,没有任何效果:(

【问题讨论】:

标签: javascript linux gobject


【解决方案1】:

在 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));
}

【讨论】:

  • IBus*.gir 不在 ubuntu 存储库中。您需要从源代码编译 ibus,编译时会生成 gir。或者你可以尝试使用我的 opensuse。我在这里上传了/usr/lib/girepository-1.0/IBus-1.0.typelib/usr/share/gir-1.0/IBus-1.0.gir mediafire.com/?e41bmf3owb1ud
  • 我刚刚发现问题出在 vmware fusion 中。我在我的笔记本电脑(真正的opensuse)中运行代码并且运行良好。首先,我在 vmware(guest opensuse)中的 mac 中尝试。非常感谢。
猜你喜欢
  • 2015-01-20
  • 1970-01-01
  • 2018-09-24
  • 1970-01-01
  • 2021-08-05
  • 2015-09-04
  • 1970-01-01
  • 2022-11-16
  • 1970-01-01
相关资源
最近更新 更多