我想使用 GObject 调用的函数如下所示:
char * some_object_fun(SomeObject *self, char *input);
Run Code Online (Sandbox Code Playgroud)
有没有好的方法来实现这一目标?我对一个优雅的解决方案非常感兴趣。
我正在解析对“net.connman.Manager.GetServices”函数的响应,如下所示:
<method name="GetServices">
<arg name="services" type="a(oa{sv})" direction="out"/>
</method>
Run Code Online (Sandbox Code Playgroud)
这是一个相当复杂的结构。
到目前为止我得到的是这样的:
GVariant* result = ... // response containing data
GVariantIter* iter1;
g_variant_get( result, "a(oa{sv})", &iter1 );
GVariant* child = g_variant_iter_next_value( iter1 );
while ( nullptr != child )
{
gchar* string;
GVariant* data;
g_variant_get( child, "(oa{sv})", &string, &data );
// how to access inner array?
g_variant_unref( child );
child = g_variant_iter_next_value( iter1 );
}
g_variant_iter_free( iter1 );
Run Code Online (Sandbox Code Playgroud)
那么,如何访问内部数组数据呢?
我尝试了这个:GVariantIter* iter2; g_variant_get( 数据, "a{sv}", &iter2 ); GVariant* child2 = g_variant_iter_next_value( iter2 ); …
我有一个最小的GStreamer程序:
#include <gst/gst.h>
int main() {
gst_init(NULL, NULL);
gst_deinit();
}
Run Code Online (Sandbox Code Playgroud)
我使用gcc test.c $(pkg-config --cflags --libs gstreamer-1.0) -fsanitize=address(gcc 版本为 12.1.0)构建它,运行它并从地址清理器获得以下输出:
==87326==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 16384 byte(s) in 1 object(s) allocated from:
#0 0x7f53e28bfa89 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x7f53e26c1b19 in g_malloc (/usr/lib/libglib-2.0.so.0+0x5db19)
SUMMARY: AddressSanitizer: 16384 byte(s) leaked in 1 allocation(s).
Run Code Online (Sandbox Code Playgroud)
我是 GStreamer 和 GLib 的新手。这对于 GStreamer 程序来说正常吗?如果是的话,在使用消毒剂运行单元测试时,有什么优雅的方法可以忽略这种泄漏?
我有一个配置文件,其中我有键和值,如下所示:
key1=value1
key2=value2
key3=value3
Run Code Online (Sandbox Code Playgroud)
那么在Gtk/Glib中是否有任何实用程序函数可以读取此文件并检索与键对应的值?
我拿起了这段代码,我将其复制到我的程序中.这似乎是我通过char**迭代的一种新方式:
char** vArray; // The array containing values
// Go throught properties
if(szKey == "KeyMgmt")
{
vArray = (char**)g_value_get_boxed((GValue*)value);
for( ; vArray && *vArray ; vArray++) // Why does this work ?!
pWpaKey->addKeyMgmt(std::string(*vArray));
}
else if(szKey == "Pairwise")
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
它看起来像一个魅力,但我不明白为什么!假设vArray包含一个地址吗?并且*vArray"字符串"值.那么,为什么当我"和"一个有价值的地址时,这给了我一个平等的呢?
我需要从驻留在内核中的模块进行一些RPC调用.我想知道是否可以使用glib来实现这个目的.有没有人尝试在内核中使用glib库?这甚至可能吗?
我对开发人员和用户点的这些术语感到有些困惑.例如,我在Ubuntu上.
GNU libs(https://www.gnu.org/software/libc/)默认安装,gnulib(https://www.gnu.org/software/gnulib)不是,对吧?GNU libs遵循POSIX stadard,但是:http://www.gnu.org/software/libc/manual/html_mono/libc.html#POSIX-Threads,
所以看起来,例如,pthread_create这里没有实现并实现Gnulib,对吧?Gnome glib只是第3个图书馆,对吗?但它基于GNU libs或
Gnulib?还有其他类似的图书馆吗?谢谢.
我的问题与GLib,C编程有关.当我初始化struct GHashtable时.
struct _GHashTable
{
gint size;
gint mod;
guint mask;
gint nnodes;
gint noccupied; /* nnodes + tombstones */
gpointer *keys;
guint *hashes;
gpointer *values;
GHashFunc hash_func;
GEqualFunc key_equal_func;
gint ref_count;
GDestroyNotify key_destroy_func;
GDestroyNotify value_destroy_func;
Run Code Online (Sandbox Code Playgroud)
};
GHashTable *hash_table;
hash_table = (GHashTable *)malloc(sizeof(GHashTable));
Run Code Online (Sandbox Code Playgroud)
在我的hash_table中,我有三个数组来存储键,值和哈希值.
gpointer *keys;
guint *hashes;
gpointer *values;
Run Code Online (Sandbox Code Playgroud)
我在初始化函数中初始化这些数组:
hash_table->keys = malloc(sizeof(gpointer) * hash_table->size);
hash_table->values = hash_table->keys;
hash_table->hashes = malloc(sizeof(guint) * hash_table->size);
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我在分配内存后显示hash_tables时,我发现在values数组中存储了一个数字.
[0] key: (null) hash: 0 values: (null)
[1] key: (null) hash: 0 values: (null)
// …Run Code Online (Sandbox Code Playgroud) 我想在ubuntu 14.04上安装gtk +(3.20.3).我下载了gtk +包并运行了configure命令.我有
Requested 'atk >= 2.15.1' but version of Atk is 2.10.0
Requested 'pango >= 1.37.3' but version of Pango is 1.36.3
Requested 'cairo >= 1.14.0' but version of cairo is 1.13.1
Requested 'cairo-gobject >= 1.14.0' but version of cairo-gobject is 1.13.1
Run Code Online (Sandbox Code Playgroud)
我还安装了glib的上述版本不匹配错误,并安装了它要求的其他一些先决条件.
我现在递归地坚持安装上面的每一个,每个问别的东西.对于ATK,我得到一些错误,比如"../atk/.libs/libatk-1.0.so:nubfined reference to`g_type_check_instance_is_fundamentally_a'",我必须尝试解决.
问题为何如此复杂?难道我做错了什么?没有像"apt-get install gtk"这样的步骤.我花了2个多小时才完成任务.
我只是想安装gtk +,因为我需要一个简单的UI用于某个C程序.我没意识到安装会那么困难.
glib a提供g_atomic_int_get原子读取标准C int类型的函数.是不是将32位整数从存储器读入寄存器还不能保证是处理器的原子操作(例如mov <reg32>, <mem>)?
如果是,那么glib g_atomic_int_get功能的目的是什么?