Skip to content

Commit 336bdb4

Browse files
committed
fix crash on x86_64
1 parent 152c292 commit 336bdb4

File tree

4 files changed

+11
-29
lines changed

4 files changed

+11
-29
lines changed

examples/test.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/NativeCall.mm

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "js_native_api_types.h"
77
#include "node_api_util.h"
88
#import <Foundation/Foundation.h>
9+
#include <cstring>
910
#include <objc/objc.h>
1011
#include <objc/runtime.h>
1112

@@ -25,7 +26,7 @@
2526
size_t argc = cif->argc;
2627
napi_get_cb_info(env, cbinfo, &argc, cif->argv, nullptr, nullptr);
2728

28-
void **avalues = cif->avalues;
29+
void *avalues[cif->argc];
2930
void *rvalue = cif->rvalue;
3031

3132
bool shouldFreeAny = false;
@@ -34,6 +35,7 @@
3435
if (cif->argc > 0) {
3536
for (unsigned int i = 0; i < cif->argc; i++) {
3637
shouldFree[i] = false;
38+
avalues[i] = cif->avalues[i];
3739
cif->argTypes[i]->toNative(env, cif->argv[i], avalues[i], &shouldFree[i],
3840
&shouldFreeAny);
3941
}
@@ -109,7 +111,7 @@ inline void objcNativeCall(napi_env env, napi_value jsThis, MethodCif *cif,
109111
size_t argc = cif->argc;
110112
napi_get_cb_info(env, cbinfo, &argc, cif->argv, &jsThis, nullptr);
111113

112-
void **avalues = cif->avalues;
114+
void *avalues[cif->cif.nargs];
113115
void *rvalue = cif->rvalue;
114116

115117
avalues[0] = (void *)&self;
@@ -121,10 +123,7 @@ inline void objcNativeCall(napi_env env, napi_value jsThis, MethodCif *cif,
121123
if (cif->argc > 0) {
122124
for (unsigned int i = 0; i < cif->argc; i++) {
123125
shouldFree[i] = false;
124-
napi_valuetype type;
125-
napi_typeof(env, cif->argv[i], &type);
126-
std::string encoding;
127-
cif->argTypes[i]->encode(&encoding);
126+
avalues[i] = cif->avalues[i + 2];
128127
cif->argTypes[i]->toNative(env, cif->argv[i], avalues[i + 2],
129128
&shouldFree[i], &shouldFreeAny);
130129
}
@@ -167,12 +166,9 @@ inline void objcNativeCall(napi_env env, napi_value jsThis, MethodCif *cif,
167166
method->bridgeData->getMethodCif(env, method->signature);
168167
}
169168

170-
void *avalues[2];
169+
void *avalues[2] = {&self, &method->selector};
171170
void *rvalue = cif->rvalue;
172171

173-
avalues[0] = (void *)&self;
174-
avalues[1] = (void *)&method->selector;
175-
176172
objcNativeCall(env, jsThis, cif, self, avalues, rvalue);
177173

178174
if (cif->returnType->kind == mdTypeInstanceObject) {
@@ -205,11 +201,9 @@ inline void objcNativeCall(napi_env env, napi_value jsThis, MethodCif *cif,
205201
method->bridgeData->getMethodCif(env, method->setterSignature);
206202
}
207203

208-
void **avalues = cif->avalues;
204+
void *avalues[3] = {&self, &method->setterSelector, cif->avalues[2]};
209205
void *rvalue = nullptr;
210206

211-
avalues[0] = (void *)&self;
212-
avalues[1] = (void *)&method->setterSelector;
213207
bool shouldFree = false;
214208
cif->argTypes[0]->toNative(env, argv, avalues[2], &shouldFree, &shouldFree);
215209

src/Struct.mm

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ void StructObject_finalize(napi_env env, void *data, void *hint) {
269269
StructObject::StructObject(napi_env env, StructInfo *info, napi_value object,
270270
void *memory) {
271271
this->info = info;
272-
NSLog(@"StructObject::StructObject %s, %p, %p", info->name, info, memory);
272+
273273
if (memory == nullptr) {
274274
this->owned = true;
275275
this->data = malloc(info->size);
@@ -279,18 +279,15 @@ void StructObject_finalize(napi_env env, void *data, void *hint) {
279279
}
280280

281281
for (auto &field : info->fields) {
282-
NSLog(@"struct field %s", field.name);
283282
bool hasProp = false;
284283
napi_has_named_property(env, object, field.name, &hasProp);
285-
if (!hasProp)
284+
if (!hasProp) {
286285
continue;
286+
}
287287
napi_value property;
288288
napi_get_named_property(env, object, field.name, &property);
289-
NSLog(@"struct.set %s", field.name);
290289
set(env, &field, property);
291290
}
292-
293-
NSLog(@"struct done");
294291
}
295292

296293
StructObject::~StructObject() {

src/TypeConv.mm

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,12 +1239,8 @@ void toNative(napi_env env, napi_value value, void *result, bool *shouldFree,
12391239
return;
12401240
}
12411241

1242-
NSLog(@"Struct.toNative info: %s, %d", info->name, info->size);
1243-
12441242
// Serialize directly to previously allocated memory
1245-
StructObject _(env, info, value, result);
1246-
1247-
NSLog(@"Struct.toNative done");
1243+
StructObject (env, info, value, result);
12481244
}
12491245
};
12501246

0 commit comments

Comments
 (0)