vala - Passing va_list as function argument -


i've created simple example demonstrating various ways pass va_list function arg. problem i'm trying solve passing va_list in callback shared object main module.

/*libcode.vala shared library (libvala-0.38)*/ namespace sotestlib {     public const string teststr = "my test string";     public const string expectformatstr = "expect test:%s";     public const string expectformatstr_va_arg0 = "1==1";     public delegate bool delegatefnexpect (bool expression, string format, va_list valist);     public delegatefnexpect delfnexpect;     public delegate bool delegatefnstring (string mystring);     public delegatefnstring delfnstring;      public string gteststr;     public string gexpectresultstr;      private void show_string(string mystring) {         stdout.printf("show_string mystring[%s] gteststr[%s]\n", mystring, gteststr);         assert (mystring == gteststr);         assert (delfnstring != null);         delfnstring(mystring);         }      private bool expect(bool expression, string sformat, ...) {         assert (delfnexpect != null);         assert (sformat == expectformatstr);          va_list _valist = va_list ();         gexpectresultstr = sformat.vprintf (_valist);         stdout.printf("expect[%s]\n", gexpectresultstr);         return delfnexpect(expression, sformat , _valist);         }      private void my_printf (string format, ...) {         va_list va_list = va_list ();         string res = format.vprintf (va_list);         stdout.puts (res);         }     public int run_demo() {         //refer:https://valadoc.org/glib-2.0/string.vprintf.html         // output: ``shut up, k-9!``         my_printf ("shut %s, %c-%d!\n", "up", 'k', 9);          gteststr = teststr;         show_string(teststr);         expect(1 == 1, expectformatstr, expectformatstr_va_arg0);         return 0;         }     } /*main.vala linked libcode.so shared library (libvala-0.38)*/ using sotestlib; public bool cbfnstring(string test_str) {     stdout.printf("cbfnstring test_str[%s] gteststr[%s]\n", test_str, gteststr);     assert (test_str == gteststr);     return true;     } public bool cbfnexpect(bool expression, string format, va_list args) {     stdout.printf("cbfnexpect format[%s] format.length[%d]\n",                   format, format.length);     assert (format == expectformatstr);     string res = format.vprintf(args);     assert (res != null);     stdout.printf("cbfnexpect res[%s] gexpectresultstr[%s]\n", res, gexpectresultstr);     assert(res == gexpectresultstr);     return expression;     } static int main(string[] args) {     delfnstring = (delegatefnstring)cbfnstring;     delfnexpect = (delegatefnexpect)cbfnexpect;      return run_demo();     } 

here result of running test...

=========================================================================== ---run main -- =========================================================================== ./stackoverflow/libcallback_strings/lib/libcallback_strings.exe shut up, k-9! show_string mystring[my test string] gteststr[my test string] cbfnstring test_str[my test string] gteststr[my test string] expect[expect test:1==1] cbfnexpect format[expect test:%s] format.length[14] cbfnexpect res[expect test:(null)] gexpectresultstr[expect test:1==1] ** error:/media/george/shareddata/projects/vala/languageserver/stackoverflow/libcallback_strings/main.vala:15:cbfnexpect: assertion failed: (res == gexpectresultstr) stackoverflow/so_examples.mk:252: recipe target 'libcallback_strings' failed make: *** [libcallback_strings] aborted terminal process terminated exit code: 2 

for reason in cbfnexpect, va_list args no longer valid. seems if va_list address (or addresses within struct) valid within shared library. not correct/allowed usage of va_list?


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -