gpt4 book ai didi

c - GLib-GObject-创建 gobject 时发出警告

转载 作者:行者123 更新时间:2023-11-30 17:50:05 25 4
gpt4 key购买 nike

我正在尝试用 c (c_glib) 创建一个 Flume-thrift 客户端,但在创建应发送到服务器的 gobject 时遇到问题。我在 main.c 中的行中收到以下错误:

`GLib-GObject-WARNING **: IA__g_object_new_valist: object class `ThriftFlumeEventType' has no property named `timestamp'`

flume_types.h和flume_types.c中的代码是从thrift自动生成的。如果您需要查看更多代码,请告诉我。我感谢我能得到的所有帮助!

flume_types.h中的部分代码:

struct _ThriftFlumeEvent
{
ThriftStruct parent;

/* public */
gint64 timestamp;
gboolean __isset_timestamp;
Priority priority;
gboolean __isset_priority;
GByteArray * body;
gboolean __isset_body;
gint64 nanos;
gboolean __isset_nanos;
gchar * host;
gboolean __isset_host;
GHashTable * fields;
gboolean __isset_fields;
};
typedef struct _ThriftFlumeEvent ThriftFlumeEvent;


GType thrift_flume_event_get_type (void);
#define TYPE_THRIFT_FLUME_EVENT (thrift_flume_event_get_type())

flume_types.c中的部分代码:

void 
thrift_flume_event_instance_init (ThriftFlumeEvent * object)
{
printf("thrift_flume_event_instance_init");

/* satisfy -Wall */
THRIFT_UNUSED_VAR (object);
object->timestamp = 0;
object->__isset_timestamp = FALSE;
object->__isset_priority = FALSE;
object->body = NULL;
object->__isset_body = FALSE;
object->nanos = 0;
object->__isset_nanos = FALSE;
object->host = NULL;
object->__isset_host = FALSE;
object->fields = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
object->__isset_fields = FALSE;
}

GType
thrift_flume_event_get_type (void)
{
static GType type = 0;

if (type == 0)
{
static const GTypeInfo type_info =
{
sizeof (ThriftFlumeEventClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) thrift_flume_event_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (ThriftFlumeEvent),
0, /* n_preallocs */
(GInstanceInitFunc) thrift_flume_event_instance_init,
NULL, /* value_table */
};

type = g_type_register_static (THRIFT_TYPE_STRUCT,
"ThriftFlumeEventType",
&type_info, 0);
type.timestamp;
}

return type;
}

main.c中的部分代码:

  gpointer eventObj = g_object_new(TYPE_THRIFT_FLUME_EVENT,
"timestamp", 0,
"__isset_timestamp", 0,
"priority", 0,
"__isset_priority", 0,
"body", 0,
"__isset_body", 0,
"nanos", 0,
"__isset_nanos", 0,
"fields", 0,
"__isset_fields", 0,
0);

最佳答案

这在 Thrift 0.9.2 中发生了变化:由 C (GLib) 编译器生成的代表 Thrift 结构的对象现在将其成员公开为 GObject 属性,从而避免了直接修改对象实例结构的危险(且糟糕)的做法。

从 0.9.2 开始,初始化 struct 对象的首选方式基本上就是发帖者最初期望的方式:

ThriftFlumeEvent *event =
g_object_new (TYPE_THRIFT_FLUME_EVENT,
"timestamp", (gint64)t_stamp.tv_sec * 1000,
"priority", priority,
...
NULL);

请注意,__isset_ 字段由对象本身管理,不应直接设置。

关于c - GLib-GObject-创建 gobject 时发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17471332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com