comparison test/callf/main.c @ 362:78dfa2f9783a

- added helper function dcGetModeFromCCSigChar() mapping callconv sig chars to respective mode - added a signature-based syscall to callf testcode - manual clarification about dcReset usage in combination with dcMode
author Tassilo Philipp
date Tue, 14 Apr 2020 16:56:57 +0200
parents 30aae7371373
children 3ff4a4ba7f0e
comparison
equal deleted inserted replaced
361:06c9adae114d 362:78dfa2f9783a
30 #include "../../dyncall/dyncall_callf.h" 30 #include "../../dyncall/dyncall_callf.h"
31 #include "../common/platformInit.h" 31 #include "../common/platformInit.h"
32 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ 32 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */
33 33
34 #include <stdarg.h> 34 #include <stdarg.h>
35 #if defined(DC_UNIX)
36 #include <sys/syscall.h>
37 #endif
35 38
36 39
37 /* sample void function */ 40 /* sample void function */
38 41
39 int vf_iii(int x,int y,int z) 42 int vf_iii(int x,int y,int z)
127 dcReset(vm); 130 dcReset(vm);
128 printf("\nargf ffiffiffi then call: "); 131 printf("\nargf ffiffiffi then call: ");
129 dcArgF(vm, "ffiffiffi", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9); 132 dcArgF(vm, "ffiffiffi", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9);
130 r = r && dcCallInt(vm, (void*)&vf_ffiffiffi); 133 r = r && dcCallInt(vm, (void*)&vf_ffiffiffi);
131 134
135 #if defined(DC_UNIX)
136 /* testing syscall using calling convention prefix - not available on all platforms */
137 dcReset(vm);
138 printf("\ncallf _$ipi)i");
139 fflush(NULL); /* needed before syscall write as it's immediate, or order might be incorrect */
140 dcCallF(vm, &ret, (DCpointer)(ptrdiff_t)SYS_write, "_$ipi)i", 1/*stdout*/, " = syscall: 1", 13);
141 r = ret.i == 13 && r;
142 #endif
132 143
133 /* free vm */ 144 /* free vm */
134 dcFree(vm); 145 dcFree(vm);
135 146
136 printf("\nresult: callf: %d\n", r); 147 printf("\nresult: callf: %d\n", r);