@@ -103,6 +103,7 @@ class JitCall {
103
103
enum Kind : char {
104
104
kUnknown = 0 ,
105
105
kGenericCall ,
106
+ kConstructorCall ,
106
107
kDestructorCall ,
107
108
};
108
109
struct ArgList {
@@ -116,20 +117,25 @@ class JitCall {
116
117
// FIXME: Hide these implementation details by moving wrapper generation in
117
118
// this class.
118
119
// (self, nargs, args, result, nary)
119
- using GenericCall = void (*)(void *, size_t , void **, void *, size_t );
120
+ using GenericCall = void (*)(void *, size_t , void **, void *);
121
+ // (result, nary, nargs, args, is_arena)
122
+ using ConstructorCall = void (*)(void *, size_t , size_t , void **, void *);
120
123
// (self, nary, withFree)
121
124
using DestructorCall = void (*)(void *, size_t , int );
122
125
123
126
private:
124
127
union {
125
128
GenericCall m_GenericCall;
129
+ ConstructorCall m_ConstructorCall;
126
130
DestructorCall m_DestructorCall;
127
131
};
128
132
Kind m_Kind;
129
133
TCppConstFunction_t m_FD;
130
134
JitCall () : m_GenericCall(nullptr ), m_Kind(kUnknown ), m_FD(nullptr ) {}
131
135
JitCall (Kind K, GenericCall C, TCppConstFunction_t FD)
132
136
: m_GenericCall(C), m_Kind(K), m_FD(FD) {}
137
+ JitCall (Kind K, ConstructorCall C, TCppConstFunction_t Ctor)
138
+ : m_ConstructorCall(C), m_Kind(K), m_FD(Ctor) {}
133
139
JitCall (Kind K, DestructorCall C, TCppConstFunction_t Dtor)
134
140
: m_DestructorCall(C), m_Kind(K), m_FD(Dtor) {}
135
141
@@ -164,20 +170,36 @@ class JitCall {
164
170
// self can go in the end and be nullptr by default; result can be a nullptr
165
171
// by default. These changes should be synchronized with the wrapper if we
166
172
// decide to directly.
167
- void Invoke (void * result, ArgList args = {}, void * self = nullptr ,
168
- size_t nary = 0UL ) const {
173
+ void Invoke (void * result, ArgList args = {}, void * self = nullptr ) const {
169
174
// NOLINTBEGIN(*-type-union-access)
170
- // Forward if we intended to call a dtor with only 1 parameter.
171
- if (m_Kind == kDestructorCall && result && !args.m_Args ) {
172
- InvokeDestructor (result, nary, /* withFree=*/ true );
173
- return ;
174
- }
175
+ // Its possible the JitCall object deals with structor decls but went
176
+ // through Invoke
177
+
178
+ switch (m_Kind) {
179
+ case kUnknown :
180
+ assert (0 && " Attempted to call an invalid function declaration" );
181
+ break ;
175
182
183
+ case kGenericCall :
176
184
#ifndef NDEBUG
177
- assert (AreArgumentsValid (result, args, self) && " Invalid args!" );
178
- ReportInvokeStart (result, args, self);
185
+ // We pass 1UL to nary which is only relevant for structors
186
+ assert (AreArgumentsValid (result, args, self, 1UL ) && " Invalid args!" );
187
+ ReportInvokeStart (result, args, self);
179
188
#endif // NDEBUG
180
- m_GenericCall (self, args.m_ArgSize , args.m_Args , result, nary);
189
+ m_GenericCall (self, args.m_ArgSize , args.m_Args , result);
190
+ break ;
191
+
192
+ case kConstructorCall :
193
+ // Forward if we intended to call a constructor (nary cannot be inferred,
194
+ // so we stick to constructing a single object)
195
+ InvokeConstructor (result, /* nary=*/ 1UL , args, self);
196
+ break ;
197
+ case kDestructorCall :
198
+ // Forward if we intended to call a dtor with only 1 parameter.
199
+ assert (!args.m_Args && " Destructor called with arguments" );
200
+ InvokeDestructor (result, /* nary=*/ 0UL , /* withFree=*/ true );
201
+ break ;
202
+ }
181
203
// NOLINTEND(*-type-union-access)
182
204
}
183
205
// / Makes a call to a destructor.
@@ -195,6 +217,24 @@ class JitCall {
195
217
#endif // NDEBUG
196
218
m_DestructorCall (object, nary, withFree);
197
219
}
220
+
221
+ // / Makes a call to a constructor.
222
+ // /\param[in] result - the memory address at which we construct the object
223
+ // / (placement new).
224
+ // /\param[in] nary - Use array new if we have to construct an array of
225
+ // / objects (nary > 1).
226
+ // /\param[in] args - a pointer to a argument list and argument size.
227
+ // FIXME: Change the type of withFree from int to bool in the wrapper code.
228
+ void InvokeConstructor (void * result, unsigned long nary = 1 ,
229
+ ArgList args = {}, void * is_arena = nullptr ) const {
230
+ assert (m_Kind == kConstructorCall && " Wrong overload!" );
231
+ #ifndef NDEBUG
232
+ assert (AreArgumentsValid (result, args, /* self=*/ nullptr , nary) &&
233
+ " Invalid args!" );
234
+ ReportInvokeStart (result, args, nullptr );
235
+ #endif // NDEBUG
236
+ m_ConstructorCall (result, nary, args.m_ArgSize , args.m_Args , is_arena);
237
+ }
198
238
};
199
239
200
240
// /\returns the version string information of the library.
0 commit comments