Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callf.c @ 315:3840e0188520
- allowing lookup of running executable's path by passing NULL to dynload's dlGetLibraryPath()
author | Tassilo Philipp |
---|---|
date | Wed, 06 Nov 2019 14:13:49 +0100 |
parents | f5577f6bf97a |
children | 30aae7371373 |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: dyncall | |
5 File: dyncall/dyncall_callf.c | |
6 Description: formatted call C interface (extension module) | |
7 License: | |
8 | |
281 | 9 Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>, |
0 | 10 Tassilo Philipp <tphilipp@potion-studios.com> |
11 | |
12 Permission to use, copy, modify, and distribute this software for any | |
13 purpose with or without fee is hereby granted, provided that the above | |
14 copyright notice and this permission notice appear in all copies. | |
15 | |
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
23 | |
24 */ | |
25 | |
26 | |
27 | |
28 #include "dyncall_callf.h" | |
29 | |
30 | |
171
011b5e3a8548
- compatibility for older platforms - use ANSI comments
cslag
parents:
74
diff
changeset
|
31 /* Shareable implementation for argument binding used in ArgF and CallF below. */ |
0 | 32 static void dcArgF_impl(DCCallVM* vm, const DCsigchar** sigptr, va_list args) |
33 { | |
34 DCsigchar ch; | |
35 dcReset(vm); | |
36 while((ch=*(*sigptr)++) != '\0' && ch != DC_SIGCHAR_ENDARG) { | |
37 switch(ch) { | |
38 case DC_SIGCHAR_BOOL: dcArgBool (vm, (DCbool) va_arg(args, DCint )); break; | |
39 case DC_SIGCHAR_CHAR: dcArgChar (vm, (DCchar) va_arg(args, DCint )); break; | |
40 case DC_SIGCHAR_UCHAR: dcArgChar (vm, (DCchar)(DCuchar) va_arg(args, DCint )); break; | |
41 case DC_SIGCHAR_SHORT: dcArgShort (vm, (DCshort) va_arg(args, DCint )); break; | |
42 case DC_SIGCHAR_USHORT: dcArgShort (vm, (DCshort)(DCushort)va_arg(args, DCint )); break; | |
43 case DC_SIGCHAR_INT: dcArgInt (vm, (DCint) va_arg(args, DCint )); break; | |
44 case DC_SIGCHAR_UINT: dcArgInt (vm, (DCint)(DCuint) va_arg(args, DCint )); break; | |
45 case DC_SIGCHAR_LONG: dcArgLong (vm, (DClong) va_arg(args, DClong )); break; | |
46 case DC_SIGCHAR_ULONG: dcArgLong (vm, (DCulong) va_arg(args, DClong )); break; | |
47 case DC_SIGCHAR_LONGLONG: dcArgLongLong(vm, (DClonglong) va_arg(args, DClonglong)); break; | |
48 case DC_SIGCHAR_ULONGLONG: dcArgLongLong(vm, (DCulonglong) va_arg(args, DClonglong)); break; | |
49 case DC_SIGCHAR_FLOAT: dcArgFloat (vm, (DCfloat) va_arg(args, DCdouble )); break; | |
50 case DC_SIGCHAR_DOUBLE: dcArgDouble (vm, (DCdouble) va_arg(args, DCdouble )); break; | |
51 case DC_SIGCHAR_POINTER: dcArgPointer (vm, (DCpointer) va_arg(args, DCpointer )); break; | |
52 case DC_SIGCHAR_STRING: dcArgPointer (vm, (DCpointer) va_arg(args, DCpointer )); break; | |
53 } | |
54 } | |
55 } | |
56 | |
57 void dcVArgF(DCCallVM* vm, const DCsigchar* signature, va_list args) | |
58 { | |
59 dcArgF_impl(vm, &signature, args); | |
60 } | |
61 | |
62 void dcArgF(DCCallVM* vm, const DCsigchar* signature, ...) | |
63 { | |
64 va_list va; | |
65 va_start(va, signature); | |
66 dcVArgF(vm,signature,va); | |
67 va_end(va); | |
68 } | |
69 | |
70 void dcVCallF(DCCallVM* vm, DCValue* result, DCpointer funcptr, const DCsigchar* signature, va_list args) | |
71 { | |
72 const DCsigchar* ptr = signature; | |
73 dcArgF_impl(vm, &ptr, args); | |
74 | |
75 switch(*ptr) { | |
74
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
76 case DC_SIGCHAR_VOID: dcCallVoid (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
77 case DC_SIGCHAR_BOOL: result->B = dcCallBool (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
78 case DC_SIGCHAR_CHAR: result->c = dcCallChar (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
79 case DC_SIGCHAR_UCHAR: result->C = (DCuchar)dcCallChar (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
80 case DC_SIGCHAR_SHORT: result->s = dcCallShort (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
81 case DC_SIGCHAR_USHORT: result->S = dcCallShort (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
82 case DC_SIGCHAR_INT: result->i = dcCallInt (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
83 case DC_SIGCHAR_UINT: result->I = dcCallInt (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
84 case DC_SIGCHAR_LONG: result->j = dcCallLong (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
85 case DC_SIGCHAR_ULONG: result->J = dcCallLong (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
86 case DC_SIGCHAR_LONGLONG: result->l = dcCallLongLong (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
87 case DC_SIGCHAR_ULONGLONG: result->L = dcCallLongLong (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
88 case DC_SIGCHAR_FLOAT: result->f = dcCallFloat (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
89 case DC_SIGCHAR_DOUBLE: result->d = dcCallDouble (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
90 case DC_SIGCHAR_POINTER: result->p = dcCallPointer (vm,funcptr); break; |
f2a8dfd795e8
- pointer cast for callf to make C++ compilers happy that don't do void* implicit casts (also, as DC_POINTER might be set to something other than void*, this cast would be needed)
cslag
parents:
0
diff
changeset
|
91 case DC_SIGCHAR_STRING: result->Z = (DCstring)dcCallPointer(vm,funcptr); break; |
0 | 92 } |
93 } | |
94 | |
95 void dcCallF(DCCallVM* vm, DCValue* result, DCpointer funcptr, const DCsigchar* signature, ...) | |
96 { | |
97 va_list va; | |
98 va_start(va, signature); | |
99 dcVCallF(vm,result,funcptr,signature,va); | |
100 va_end(va); | |
101 } | |
102 |