Mercurial > pub > dyncall > dyncall
comparison dyncall/dyncall_aggregate.c @ 533:71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
* integration of aggregate-by-value (struct, union) support patch for x64 (win and sysv)
* windows/x64 asm additions to specify how stack unwinds (help for debuggers, exception handling, etc.)
* see Changelog for details
- new calling convention modes for thiscalls (platform agnostic, was specific before)
* new signature character for platform agnostic thiscalls ('*' / DC_SIGCHAR_CC_THISCALL)
- dcCallF(), dcVCallF(), dcArgF() and dcVArgF():
* added support for aggregates-by-value (wasn't part of patch)
* change that those functions don't implicitly call dcReset() anymore, which was unflexible (breaking change)
- added macros to feature test implementation for aggregate-by-value and syscall support
- changed libdyncall_s.lib and libdyncallback_s.lib order in callback test makefiles, as some toolchains are picky about order
- doc:
* man page updates to describe aggregate interface
* manual overview changes to highlight platforms with aggregate-by-value support
- test/plain: replaced tests w/ old/stale sctruct interface with new aggregate one
author | Tassilo Philipp |
---|---|
date | Thu, 21 Apr 2022 13:35:47 +0200 |
parents | |
children | ba70fb631bea |
comparison
equal
deleted
inserted
replaced
532:d4bf63ab9164 | 533:71c884e610f0 |
---|---|
1 /* | |
2 | |
3 Package: dyncall | |
4 Library: dyncall | |
5 File: dyncall/dyncall_aggregate.c | |
6 Description: C interface to compute struct size | |
7 License: | |
8 | |
9 Copyright (c) 2021-2022 Tassilo Philipp <tphilipp@potion-studios.com> | |
10 | |
11 Permission to use, copy, modify, and distribute this software for any | |
12 purpose with or without fee is hereby granted, provided that the above | |
13 copyright notice and this permission notice appear in all copies. | |
14 | |
15 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
22 | |
23 */ | |
24 | |
25 | |
26 | |
27 #include "dyncall.h" | |
28 #include "dyncall_signature.h" | |
29 #include "dyncall_aggregate.h" | |
30 #include "dyncall_alloc.h" | |
31 #include <stdio.h> | |
32 #include <assert.h> | |
33 #include <stdarg.h> | |
34 | |
35 | |
36 | |
37 #if defined(DC__Arch_AMD64) && defined(DC_UNIX) | |
38 # include "dyncall_aggregate_x64.c" | |
39 #else | |
40 static void dcFinishAggr(DCaggr *ag) | |
41 { | |
42 } | |
43 #endif | |
44 | |
45 | |
46 DCaggr* dcNewAggr(DCsize maxFieldCount, DCsize size) | |
47 { | |
48 DCaggr* ag = (DCaggr*)dcAllocMem(sizeof(DCaggr) + maxFieldCount * sizeof(DCfield)); | |
49 ag->n_fields = 0; | |
50 ag->size = size; | |
51 return ag; | |
52 } | |
53 | |
54 | |
55 void dcAggrField(DCaggr* ag, DCsigchar type, DCint offset, DCsize array_len, ...) | |
56 { | |
57 DCfield *f = ag->fields + (ag->n_fields++); | |
58 f->type = type; | |
59 f->offset = offset; | |
60 f->array_len = array_len; | |
61 f->sub_aggr = NULL; | |
62 switch(type) { | |
63 case DC_SIGCHAR_BOOL: f->size = sizeof(DCbool); break; | |
64 case DC_SIGCHAR_CHAR: | |
65 case DC_SIGCHAR_UCHAR: f->size = sizeof(DCchar); break; | |
66 case DC_SIGCHAR_SHORT: | |
67 case DC_SIGCHAR_USHORT: f->size = sizeof(DCshort); break; | |
68 case DC_SIGCHAR_INT: | |
69 case DC_SIGCHAR_UINT: f->size = sizeof(DCint); break; | |
70 case DC_SIGCHAR_LONG: | |
71 case DC_SIGCHAR_ULONG: f->size = sizeof(DClong); break; | |
72 case DC_SIGCHAR_LONGLONG: | |
73 case DC_SIGCHAR_ULONGLONG: f->size = sizeof(DClonglong); break; | |
74 case DC_SIGCHAR_FLOAT: f->size = sizeof(DCfloat); break; | |
75 case DC_SIGCHAR_DOUBLE: f->size = sizeof(DCdouble); break; | |
76 case DC_SIGCHAR_POINTER: | |
77 case DC_SIGCHAR_STRING: f->size = sizeof(DCpointer); break; | |
78 case DC_SIGCHAR_AGGREGATE: | |
79 { | |
80 va_list ap; | |
81 va_start(ap, array_len); | |
82 f->sub_aggr = va_arg(ap, const DCaggr*); | |
83 va_end(ap); | |
84 | |
85 f->size = f->sub_aggr->size; | |
86 break; | |
87 } | |
88 default: | |
89 assert(0); | |
90 } | |
91 } | |
92 | |
93 | |
94 void dcCloseAggr(DCaggr* ag) | |
95 { | |
96 dcFinishAggr(ag); | |
97 } | |
98 | |
99 | |
100 void dcFreeAggr(DCaggr* ag) | |
101 { | |
102 dcFreeMem(ag); | |
103 } | |
104 |