在编译和运行下面的代码时,我得到了一个警告和一个分段错误,它使用
to_utf32_fast
方法
string
并应返回在
codepoint_count
变量。这个方法发展到c函数
g_utf8_to_ucs4_fast
不知何故
out codepoint_count
结果是
long * *
参数而不是预期的
long *
.
我确实有解决办法,所以这不急。
int main (string[] args) {
string test = "abc";
long codepoint_count;
string utf32_version = test.to_utf32_fast(-1, out codepoint_count).to_string();
stdout.printf("success");
return 0;
}
输出的相关部分:
C:/msys64/usr/src/outerror.vala.c: In function '_vala_main':
C:/msys64/usr/src/outerror.vala.c:78:50: warning: passing argument 3 of 'g_utf8_to_ucs4_fast' from incompatible pointer type [-Wincompatible-pointer-types]
_tmp2_ = g_utf8_to_ucs4_fast (test, (glong) -1, &_tmp1_);
^
In file included from C:/msys64/mingw64/include/glib-2.0/glib/gstring.h:33:0,
from C:/msys64/mingw64/include/glib-2.0/glib/giochannel.h:34,
from C:/msys64/mingw64/include/glib-2.0/glib.h:54,
from C:/msys64/usr/src/outerror.vala.c:5:
C:/msys64/mingw64/include/glib-2.0/glib/gunicode.h:798:12: note: expected 'glong * {aka long int *}' but argument is of type 'glong ** {aka long int **}'
gunichar * g_utf8_to_ucs4_fast (const gchar *str,
^~~~~~~~~~~~~~~~~~~
我研究了发出来的C源代码和
G_tf8_到UCS4_快速
是指向long的未初始化指针的地址,稍后将使用
g_free
. 当程序运行时,这会触发一个segfault。
我调用这个函数的方式有什么问题吗?它被宣布为
public string32 to_utf32_fast (long len = -1, out long? items_written = null)
我对Vala(更熟悉C)不太熟悉,不确定我是否掌握了参数注释。第二个论点不应该向C解释为
long **
而不是
长*
但可能是空性标记
?
或默认值
= null
导致Vala认为
items_written
是指向
long
(或其等价物)而不是
长的
. 如果是这样,那么方法的声明可能有错误,或者vala语法中有歧义。