node-gtk 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -218,6 +218,13 @@ cd ~/oss
218
218
  git clone https://github.com/romgrk/node-gtk
219
219
  cd node-gtk
220
220
 
221
+ # don't include /mingw64/include directly since it conflicts with
222
+ # Windows SDK headers. we copy needed headers to __extra__ directory:
223
+ ./windows/mingw_include_extra.sh
224
+
225
+ # if MSYS2 is NOT installed in C:/msys64 run:
226
+ export MINGW_WINDOWS_PATH=$(./windows/mingw_windows_path.sh)
227
+
221
228
  # first run might take a while
222
229
  GYP_MSVS_VERSION=2015 npm install
223
230
  ```
package/binding.gyp CHANGED
@@ -39,19 +39,20 @@
39
39
  "include_dirs" : [
40
40
  "<!(node -e \"require('nan')\")"
41
41
  ],
42
- "cflags": [
43
- "<!@(pkg-config --cflags gobject-introspection-1.0 cairo) -Wall -g",
44
- ],
45
- "ldflags": [
46
- "-Wl,-no-as-needed",
47
- "<!@(pkg-config --libs gobject-introspection-1.0 cairo)",
48
- ],
49
42
  "conditions": [
50
- ['OS != "linux"', {
43
+ ['OS == "linux"', {
51
44
  "defines": [
52
- "ulong=unsigned long",
53
45
  "PLATFORM_LINUX=1",
54
- ]
46
+ ],
47
+ "cflags": [
48
+ "<!@(pkg-config --cflags gobject-introspection-1.0 cairo)",
49
+ "-Wall",
50
+ "-g",
51
+ ],
52
+ "ldflags": [
53
+ "-Wl,-no-as-needed",
54
+ "<!@(pkg-config --libs gobject-introspection-1.0 cairo)",
55
+ ],
55
56
  }],
56
57
  ['OS == "mac"', {
57
58
  "defines": [
@@ -69,16 +70,34 @@
69
70
  }],
70
71
  ['OS == "win"', {
71
72
  "defines": [
72
- "uint=unsigned int",
73
73
  "PLATFORM_WIN=1",
74
74
  ],
75
+ "variables": {
76
+ # If MSYS2 is NOT installed in C:/msys64 run:
77
+ # $ export MINGW_WINDOWS_PATH=$(./windows/mingw_windows_path.sh)
78
+ # before compiling
79
+ "MINGW_PREFIX": "<!(bash -c 'echo ${MINGW_WINDOWS_PATH:-/msys64}')",
80
+ },
75
81
  "include_dirs": [
76
- "include",
77
- "/msys64/mingw64/include/gobject-introspection-1.0",
78
- "/msys64/mingw64/lib/libffi-3.2.1/include",
79
- "/msys64/mingw64/include/glib-2.0",
80
- "/msys64/mingw64/lib/glib-2.0/include",
81
- "/msys64/mingw64/include/cairo"
82
+ # Don't include /mingw64/include directly.
83
+ # To make extra include dir run:
84
+ # $ ./windows/mingw_include_extra.sh
85
+ # before compiling
86
+ "<(MINGW_PREFIX)/mingw64/include/__extra__",
87
+
88
+ "<(MINGW_PREFIX)/mingw64/include/gobject-introspection-1.0",
89
+ "<(MINGW_PREFIX)/mingw64/include/glib-2.0",
90
+ "<(MINGW_PREFIX)/mingw64/lib/glib-2.0/include",
91
+ "<(MINGW_PREFIX)/mingw64/include/cairo",
92
+ "<(MINGW_PREFIX)/mingw64/include/freetype2",
93
+ ],
94
+ "libraries": [
95
+ "<(MINGW_PREFIX)/mingw64/lib/libglib-2.0.dll.a",
96
+ "<(MINGW_PREFIX)/mingw64/lib/libgmodule-2.0.dll.a",
97
+ "<(MINGW_PREFIX)/mingw64/lib/libgobject-2.0.dll.a",
98
+ "<(MINGW_PREFIX)/mingw64/lib/libffi.dll.a",
99
+ "<(MINGW_PREFIX)/mingw64/lib/libgirepository-1.0.dll.a",
100
+ "<(MINGW_PREFIX)/mingw64/lib/libcairo.dll.a",
82
101
  ]
83
102
  }]
84
103
  ]
package/package.json CHANGED
@@ -1,15 +1,8 @@
1
1
  {
2
2
  "name": "node-gtk",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "GNOME Gtk+ bindings for NodeJS",
5
5
  "main": "lib/index.js",
6
- "scripts": {
7
- "install": "if [ \"$(uname)\" = \"Darwin\" ] && [ \"$(which brew)\" != \"\" ]; then export PKG_CONFIG_PATH=$(brew --prefix libffi)/lib/pkgconfig; fi; node-pre-gyp install --fallback-to-build",
8
- "test": "mocha tests/__run__.js",
9
- "build": "node-pre-gyp build",
10
- "build:full": "node-pre-gyp rebuild",
11
- "configure": "node-pre-gyp configure --debug"
12
- },
13
6
  "repository": {
14
7
  "type": "git",
15
8
  "url": "git+https://github.com/romgrk/node-gtk.git"
@@ -62,5 +55,12 @@
62
55
  "remote_path": "./{module_name}/v{version}/",
63
56
  "package_name": "{module_name}-{node_abi}-{platform}-{arch}.tar.gz",
64
57
  "host": "https://node-gtk-1.s3.amazonaws.com"
58
+ },
59
+ "scripts": {
60
+ "install": "npx node-pre-gyp install --fallback-to-build",
61
+ "test": "mocha tests/__run__.js",
62
+ "build": "npx node-pre-gyp build",
63
+ "build:full": "npx node-pre-gyp rebuild",
64
+ "configure": "npx node-pre-gyp configure --debug"
65
65
  }
66
- }
66
+ }
package/scripts/ci.sh CHANGED
File without changes
package/src/boxed.cc CHANGED
@@ -183,7 +183,7 @@ static void BoxedConstructor(const Nan::FunctionCallbackInfo<Value> &info) {
183
183
  boxed = g_boxed_copy (gtype, boxed);
184
184
  }
185
185
  else if ((size = Boxed::GetSize(gi_info)) != 0) {
186
- void *boxedCopy = malloc(size);
186
+ void *boxedCopy = g_malloc(size);
187
187
  memcpy(boxedCopy, boxed, size);
188
188
  boxed = boxedCopy;
189
189
  }
@@ -223,7 +223,7 @@ static void BoxedConstructor(const Nan::FunctionCallbackInfo<Value> &info) {
223
223
  boxed = return_value.v_pointer;
224
224
 
225
225
  } else if ((size = Boxed::GetSize(gi_info)) != 0) {
226
- boxed = calloc(1, size);
226
+ boxed = g_malloc0(size);
227
227
 
228
228
  } else {
229
229
  Nan::ThrowError("Boxed allocation failed: no constructor found");
@@ -267,7 +267,7 @@ static void BoxedDestroyed(const Nan::WeakCallbackInfo<Boxed> &info) {
267
267
  }
268
268
  else if (box->size != 0) {
269
269
  // Allocated in ./function.cc @ AllocateArgument
270
- free(box->data);
270
+ g_free(box->data);
271
271
  }
272
272
  else if (box->data != NULL) {
273
273
  /*
package/src/callback.cc CHANGED
@@ -22,7 +22,7 @@ using Nan::TryCatch;
22
22
 
23
23
  namespace GNodeJS {
24
24
 
25
- static uint callbackLevel = 0;
25
+ static guint callbackLevel = 0;
26
26
  static GSList* notifiedCallbacks = NULL;
27
27
 
28
28
  static Local<Object> GetSelfInstance(GIArgument **args) {
@@ -91,10 +91,10 @@ void Callback::Execute (GIArgument *result, GIArgument **args, Callback *callbac
91
91
 
92
92
  /* Skip the object instance in first place */
93
93
  int args_offset = isVFunc ? 1 : 0;
94
- uint n_native_args = (uint) g_callable_info_get_n_args(callback->info);
95
- uint n_return_values = 1;
94
+ guint n_native_args = (guint) g_callable_info_get_n_args(callback->info);
95
+ guint n_return_values = 1;
96
96
 
97
- uint primitive_out_arguments_mask = 0;
97
+ guint primitive_out_arguments_mask = 0;
98
98
 
99
99
  #ifndef __linux__
100
100
  Local<Value>* js_args = new Local<Value>[n_native_args];
@@ -102,7 +102,7 @@ void Callback::Execute (GIArgument *result, GIArgument **args, Callback *callbac
102
102
  Local<Value> js_args[n_native_args];
103
103
  #endif
104
104
 
105
- for (uint i = 0; i < n_native_args; i++) {
105
+ for (guint i = 0; i < n_native_args; i++) {
106
106
  GIArgInfo arg_info;
107
107
  GITypeInfo arg_type;
108
108
  g_callable_info_load_arg (callback->info, i, &arg_info);
@@ -144,12 +144,11 @@ void Callback::Execute (GIArgument *result, GIArgument **args, Callback *callbac
144
144
  auto jsReturnValue = maybeReturnValue.ToLocalChecked();
145
145
  auto jsRealReturnValue = jsReturnValue;
146
146
  Local<Array> jsReturnArray;
147
- uint returnIndex = 0;
147
+ guint returnIndex = 0;
148
148
  bool success;
149
149
  bool isOutPrimitive;
150
- uint n_js_return_values = n_return_values - (hasVoidReturn ? 1 : 0);
150
+ guint n_js_return_values = n_return_values - (hasVoidReturn ? 1 : 0);
151
151
 
152
- uint i;
153
152
  GIArgInfo arg_info;
154
153
  GITypeInfo arg_type;
155
154
 
@@ -172,7 +171,7 @@ void Callback::Execute (GIArgument *result, GIArgument **args, Callback *callbac
172
171
  else
173
172
  jsRealReturnValue = Nan::Get(jsReturnArray, returnIndex++).ToLocalChecked();
174
173
 
175
- for (i = 0; i < n_native_args; i++) {
174
+ for (guint i = 0; i < n_native_args; i++) {
176
175
  isOutPrimitive = (primitive_out_arguments_mask & (1 << i)) != 0;
177
176
  if (!isOutPrimitive)
178
177
  continue;
package/src/closure.cc CHANGED
@@ -35,7 +35,7 @@ GClosure *Closure::New (Local<Function> function, GICallableInfo* info, guint si
35
35
 
36
36
  void Closure::Execute(GICallableInfo *info, guint signal_id,
37
37
  const Nan::Persistent<v8::Function> &persFn,
38
- GValue *g_return_value, uint n_param_values,
38
+ GValue *g_return_value, guint n_param_values,
39
39
  const GValue *param_values) {
40
40
  Nan::HandleScope scope;
41
41
  auto func = Nan::New<Function>(persFn);
@@ -45,7 +45,7 @@ void Closure::Execute(GICallableInfo *info, guint signal_id,
45
45
  g_signal_query(signal_id, &signal_query);
46
46
 
47
47
  // We don't pass the implicit instance as first argument
48
- uint n_js_args = n_param_values - 1;
48
+ auto n_js_args = n_param_values - 1;
49
49
 
50
50
  #ifndef __linux__
51
51
  Local<Value>* js_args = new Local<Value>[n_js_args];
@@ -58,7 +58,7 @@ void Closure::Execute(GICallableInfo *info, guint signal_id,
58
58
  GIArgument argument;
59
59
  GIArgInfo arg_info;
60
60
  GITypeInfo type_info;
61
- for (uint i = 1; i < n_param_values; i++) {
61
+ for (guint i = 1; i < n_param_values; i++) {
62
62
  memcpy(&argument, &param_values[i].data[0], sizeof(GIArgument));
63
63
  g_callable_info_load_arg(info, i - 1, &arg_info);
64
64
  g_arg_info_load_type(&arg_info, &type_info);
@@ -76,7 +76,7 @@ void Closure::Execute(GICallableInfo *info, guint signal_id,
76
76
  }
77
77
  } else {
78
78
  /* CallableInfo is not available: use GValueToV8 */
79
- for (uint i = 1; i < n_param_values; i++) {
79
+ for (guint i = 1; i < n_param_values; i++) {
80
80
  bool mustCopy = true;
81
81
 
82
82
  if (signal_query.signal_id) {
@@ -123,7 +123,7 @@ throw_exception:
123
123
 
124
124
  void Closure::Marshal(GClosure *base,
125
125
  GValue *g_return_value,
126
- uint n_param_values,
126
+ guint n_param_values,
127
127
  const GValue *param_values,
128
128
  gpointer invocation_hint,
129
129
  gpointer marshal_data) {
package/src/closure.h CHANGED
@@ -30,12 +30,12 @@ struct Closure {
30
30
 
31
31
  static void Execute(GICallableInfo *info, guint signal_id,
32
32
  const Nan::Persistent<v8::Function> &persFn,
33
- GValue *g_return_value, uint n_param_values,
33
+ GValue *g_return_value, guint n_param_values,
34
34
  const GValue *param_values);
35
35
 
36
36
  static void Marshal(GClosure *closure,
37
37
  GValue *g_return_value,
38
- uint argc, const GValue *g_argv,
38
+ guint argc, const GValue *g_argv,
39
39
  gpointer invocation_hint,
40
40
  gpointer marshal_data);
41
41
 
package/src/debug.cc CHANGED
@@ -158,7 +158,7 @@ void print_callable_info (GICallableInfo *info) {
158
158
  g_callable_info_load_return_type(info, &return_info);
159
159
  auto typeName = GetTypeName(&return_info);
160
160
  printf("%s %s (", typeName, g_base_info_get_name(info));
161
- free(typeName);
161
+ g_free(typeName);
162
162
 
163
163
  int n_args = g_callable_info_get_n_args(info);
164
164
  for (int i = 0; i < n_args; i++) {
@@ -168,7 +168,7 @@ void print_callable_info (GICallableInfo *info) {
168
168
  g_arg_info_load_type(&arg_info, &type_info);
169
169
  auto typeName = GetTypeName(&type_info);
170
170
  printf("%s %s", typeName, g_base_info_get_name(&arg_info));
171
- free(typeName);
171
+ g_free(typeName);
172
172
  if (i < n_args - 1)
173
173
  printf(", ");
174
174
  }
package/src/function.cc CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  #include <string.h>
3
2
  #include <girffi.h>
4
3
 
@@ -56,7 +55,7 @@ static void* AllocateArgument (GIBaseInfo *arg_info) {
56
55
 
57
56
  GIBaseInfo* base_info = g_type_info_get_interface (&arg_type);
58
57
  size_t size = Boxed::GetSize (base_info);
59
- void* pointer = calloc(1, size);
58
+ void* pointer = g_malloc0(size);
60
59
 
61
60
  g_base_info_unref(base_info);
62
61
  return pointer;
@@ -165,14 +164,14 @@ bool FunctionInfo::Init() {
165
164
 
166
165
  call_parameters[i].direction = direction;
167
166
 
168
- if (call_parameters[i].type == ParameterType::SKIP)
167
+ if (call_parameters[i].type == ParameterType::kSKIP)
169
168
  continue;
170
169
 
171
170
  // If there is an array length, this is an array
172
171
  int length_i = g_type_info_get_array_length (&type_info);
173
172
  if (tag == GI_TYPE_TAG_ARRAY && length_i >= 0) {
174
- call_parameters[i].type = ParameterType::ARRAY;
175
- call_parameters[length_i].type = ParameterType::SKIP;
173
+ call_parameters[i].type = ParameterType::kARRAY;
174
+ call_parameters[length_i].type = ParameterType::kSKIP;
176
175
 
177
176
  // If array length came before, we need to remove it from args count
178
177
 
@@ -190,9 +189,9 @@ bool FunctionInfo::Init() {
190
189
  if (interface_type == GI_INFO_TYPE_CALLBACK) {
191
190
  if (IsDestroyNotify(interface_info)) {
192
191
  /* Skip GDestroyNotify if they appear before the respective callback */
193
- call_parameters[i].type = ParameterType::SKIP;
192
+ call_parameters[i].type = ParameterType::kSKIP;
194
193
  } else {
195
- call_parameters[i].type = ParameterType::CALLBACK;
194
+ call_parameters[i].type = ParameterType::kCALLBACK;
196
195
 
197
196
  int destroy_i = g_arg_info_get_destroy(&arg_info);
198
197
  int closure_i = g_arg_info_get_closure(&arg_info);
@@ -204,10 +203,10 @@ bool FunctionInfo::Init() {
204
203
  }
205
204
 
206
205
  if (destroy_i >= 0 && destroy_i < n_callable_args)
207
- call_parameters[destroy_i].type = ParameterType::SKIP;
206
+ call_parameters[destroy_i].type = ParameterType::kSKIP;
208
207
 
209
208
  if (closure_i >= 0 && closure_i < n_callable_args)
210
- call_parameters[closure_i].type = ParameterType::SKIP;
209
+ call_parameters[closure_i].type = ParameterType::kSKIP;
211
210
 
212
211
  if (destroy_i < i) {
213
212
  if (IsDirectionIn(call_parameters[destroy_i].direction))
@@ -271,7 +270,7 @@ bool FunctionInfo::TypeCheck (const Nan::FunctionCallbackInfo<Value> &arguments)
271
270
  for (int in_arg = 0, i = 0; i < n_callable_args; i++) {
272
271
  Parameter &param = call_parameters[i];
273
272
 
274
- if (param.type == ParameterType::SKIP)
273
+ if (param.type == ParameterType::kSKIP)
275
274
  continue;
276
275
 
277
276
  GIArgInfo arg_info;
@@ -325,7 +324,12 @@ Local<Value> FunctionCall (
325
324
  * and for error, if it can throw
326
325
  */
327
326
 
328
- GIArgument total_arg_values[func->n_total_args];
327
+ #ifndef __linux__
328
+ GIArgument *total_arg_values = new GIArgument[func->n_total_args]();
329
+ #else
330
+ GIArgument total_arg_values[func->n_total_args];
331
+ #endif
332
+
329
333
  GIArgument *callable_arg_values;
330
334
  GError *error_stack = nullptr;
331
335
 
@@ -340,7 +344,6 @@ Local<Value> FunctionCall (
340
344
  if (func->can_throw)
341
345
  callable_arg_values[func->n_callable_args].v_pointer = error != NULL ? error : &error_stack;
342
346
 
343
-
344
347
  /*
345
348
  * Second, allocate OUT-arguments and fill IN-arguments
346
349
  */
@@ -348,7 +351,7 @@ Local<Value> FunctionCall (
348
351
  for (int in_arg = 0, i = 0; i < func->n_callable_args; i++) {
349
352
  Parameter& param = func->call_parameters[i];
350
353
 
351
- if (param.type == ParameterType::SKIP)
354
+ if (param.type == ParameterType::kSKIP)
352
355
  continue;
353
356
 
354
357
  GIArgInfo arg_info;
@@ -357,7 +360,7 @@ Local<Value> FunctionCall (
357
360
  g_arg_info_load_type (&arg_info, &type_info);
358
361
  GIDirection direction = g_arg_info_get_direction (&arg_info);
359
362
 
360
- if (param.type == ParameterType::ARRAY) {
363
+ if (param.type == ParameterType::kARRAY) {
361
364
  GIArgInfo array_length_arg;
362
365
  GITypeInfo array_length_type;
363
366
 
@@ -383,7 +386,7 @@ Local<Value> FunctionCall (
383
386
  callable_arg_values[length_i].v_pointer = &len_param.data;
384
387
  }
385
388
  }
386
- else if (param.type == ParameterType::CALLBACK) {
389
+ else if (param.type == ParameterType::kCALLBACK) {
387
390
  Callback *callback;
388
391
  ffi_closure *closure;
389
392
 
@@ -402,12 +405,12 @@ Local<Value> FunctionCall (
402
405
  int closure_i = g_arg_info_get_closure(&arg_info);
403
406
 
404
407
  if (destroy_i >= 0) {
405
- g_assert (func->call_parameters[destroy_i].type == ParameterType::SKIP);
408
+ g_assert (func->call_parameters[destroy_i].type == ParameterType::kSKIP);
406
409
  callable_arg_values[destroy_i].v_pointer = callback ? (void*) Callback::DestroyNotify : NULL;
407
410
  }
408
411
 
409
412
  if (closure_i >= 0) {
410
- g_assert (func->call_parameters[closure_i].type == ParameterType::SKIP);
413
+ g_assert (func->call_parameters[closure_i].type == ParameterType::kSKIP);
411
414
  callable_arg_values[closure_i].v_pointer = callback;
412
415
  }
413
416
 
@@ -426,7 +429,7 @@ Local<Value> FunctionCall (
426
429
  else /* (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) */ {
427
430
 
428
431
  // Callback GIArgument is filled above, for the rest...
429
- if (param.type != ParameterType::CALLBACK) {
432
+ if (param.type != ParameterType::kCALLBACK) {
430
433
 
431
434
  // FIXME(handle failure here)
432
435
  FillArgument(&arg_info, &callable_arg_values[i], info[in_arg]);
@@ -448,16 +451,24 @@ Local<Value> FunctionCall (
448
451
  * Third, make the actual ffi_call
449
452
  */
450
453
 
451
- void *ffi_args[func->n_total_args];
452
- for (int i = 0; i < func->n_total_args; i++)
453
- ffi_args[i] = &total_arg_values[i];
454
+ #ifndef __linux__
455
+ void **ffi_args = new void*[func->n_total_args]();
456
+ #else
457
+ void *ffi_args[func->n_total_args];
458
+ #endif
454
459
 
460
+ for (int i = 0; i < func->n_total_args; i++)
461
+ ffi_args[i] = (void *)&total_arg_values[i];
455
462
 
456
- GIArgument return_value_stack;
463
+ GIArgument return_value_stack = {0};
457
464
 
458
465
  ffi_call (&func->invoker.cif, FFI_FN (func->invoker.native_address),
459
466
  use_return_value ? return_value : &return_value_stack, ffi_args);
460
467
 
468
+ #ifndef __linux__
469
+ delete[] ffi_args;
470
+ #endif
471
+
461
472
 
462
473
  /*
463
474
  * Fourth, convert the return value & OUT-arguments back to JS
@@ -507,13 +518,13 @@ Local<Value> FunctionCall (
507
518
  GIDirection direction = g_arg_info_get_direction (&arg_info);
508
519
  GITransfer transfer = g_arg_info_get_ownership_transfer (&arg_info);
509
520
 
510
- if (param.type == ParameterType::ARRAY) {
521
+ if (param.type == ParameterType::kARRAY) {
511
522
  if (direction == GI_DIRECTION_INOUT || direction == GI_DIRECTION_OUT)
512
523
  FreeGIArgumentArray (&arg_type, (GIArgument*)arg_value.v_pointer, transfer, direction, param.length);
513
524
  else
514
525
  FreeGIArgumentArray (&arg_type, &arg_value, transfer, direction, param.length);
515
526
  }
516
- else if (param.type == ParameterType::CALLBACK) {
527
+ else if (param.type == ParameterType::kCALLBACK) {
517
528
  Callback *callback = static_cast<Callback*>(func->call_parameters[i].data.v_pointer);
518
529
 
519
530
  g_assert(direction == GI_DIRECTION_IN);
@@ -530,6 +541,10 @@ Local<Value> FunctionCall (
530
541
  }
531
542
  }
532
543
 
544
+ #ifndef __linux__
545
+ delete[] total_arg_values;
546
+ #endif
547
+
533
548
  return jsReturnValue;
534
549
  }
535
550
 
@@ -595,7 +610,7 @@ Local<Value> FunctionInfo::GetReturnValue (
595
610
 
596
611
  if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) {
597
612
 
598
- if (param.type == ParameterType::ARRAY) {
613
+ if (param.type == ParameterType::kARRAY) {
599
614
 
600
615
  int length_i = g_type_info_get_array_length(&arg_type);
601
616
  GIArgInfo length_arg;
@@ -614,7 +629,7 @@ Local<Value> FunctionInfo::GetReturnValue (
614
629
 
615
630
  ADD_RETURN (result)
616
631
 
617
- } else if (param.type == ParameterType::NORMAL) {
632
+ } else if (param.type == ParameterType::kNORMAL) {
618
633
 
619
634
  if (IsPointerType(&arg_type) && g_arg_info_is_caller_allocates(&arg_info)) {
620
635
  void *pointer = &arg_value.v_pointer;
package/src/function.h CHANGED
@@ -16,7 +16,7 @@ using v8::String;
16
16
  namespace GNodeJS {
17
17
 
18
18
  enum ParameterType {
19
- NORMAL, ARRAY, SKIP, CALLBACK
19
+ kNORMAL, kARRAY, kSKIP, kCALLBACK
20
20
  };
21
21
 
22
22
  struct Parameter {
package/src/gi.cc CHANGED
@@ -1,4 +1,4 @@
1
- #include <gobject-introspection-1.0/girepository.h>
1
+ #include <girepository.h>
2
2
  #include <node.h>
3
3
  #include <nan.h>
4
4
 
@@ -345,22 +345,22 @@ NAN_METHOD(RegisterVFunc) {
345
345
  void InitModule(Local<Object> exports, Local<Value> module, void *priv) {
346
346
  GNodeJS::AsyncCallEnvironment::Initialize();
347
347
 
348
- NAN_EXPORT(exports, Bootstrap);
349
- NAN_EXPORT(exports, GetModuleCache);
350
- NAN_EXPORT(exports, GetBaseClass);
351
- NAN_EXPORT(exports, GetTypeSize);
352
- NAN_EXPORT(exports, GetConstantValue);
353
- NAN_EXPORT(exports, MakeBoxedClass);
354
- NAN_EXPORT(exports, MakeObjectClass);
355
- NAN_EXPORT(exports, MakeFunction);
356
- NAN_EXPORT(exports, StructFieldGetter);
357
- NAN_EXPORT(exports, StructFieldSetter);
358
- NAN_EXPORT(exports, ObjectPropertyGetter);
359
- NAN_EXPORT(exports, ObjectPropertySetter);
360
- NAN_EXPORT(exports, StartLoop);
361
- NAN_EXPORT(exports, GetLoopStack);
362
- NAN_EXPORT(exports, RegisterClass);
363
- NAN_EXPORT(exports, RegisterVFunc);
348
+ Nan::Export(exports, "Bootstrap", Bootstrap);
349
+ Nan::Export(exports, "GetModuleCache", GetModuleCache);
350
+ Nan::Export(exports, "GetBaseClass", GetBaseClass);
351
+ Nan::Export(exports, "GetTypeSize", GetTypeSize);
352
+ Nan::Export(exports, "GetConstantValue", GetConstantValue);
353
+ Nan::Export(exports, "MakeBoxedClass", MakeBoxedClass);
354
+ Nan::Export(exports, "MakeObjectClass", MakeObjectClass);
355
+ Nan::Export(exports, "MakeFunction", MakeFunction);
356
+ Nan::Export(exports, "StructFieldGetter", StructFieldGetter);
357
+ Nan::Export(exports, "StructFieldSetter", StructFieldSetter);
358
+ Nan::Export(exports, "ObjectPropertyGetter", ObjectPropertyGetter);
359
+ Nan::Export(exports, "ObjectPropertySetter", ObjectPropertySetter);
360
+ Nan::Export(exports, "StartLoop", StartLoop);
361
+ Nan::Export(exports, "GetLoopStack", GetLoopStack);
362
+ Nan::Export(exports, "RegisterClass", RegisterClass);
363
+ Nan::Export(exports, "RegisterVFunc", RegisterVFunc);
364
364
 
365
365
  Nan::Set(exports, UTF8("System"), GNodeJS::System::GetModule());
366
366
  Nan::Set(exports, UTF8("Cairo"), GNodeJS::Cairo::GetModule());
package/src/gobject.cc CHANGED
@@ -87,7 +87,11 @@ static GObject* CreateGObjectFromObject(GType gtype, Local<Value> object) {
87
87
 
88
88
  out:
89
89
  g_strfreev ((gchar**) names);
90
+
91
+ for (int i = 0; i < n_properties; i++)
92
+ g_value_unset(&values[i]);
90
93
  g_free (values);
94
+
91
95
  g_type_class_unref (klass);
92
96
 
93
97
  return gobject;
@@ -346,7 +350,7 @@ NAN_METHOD(SignalConnect) {
346
350
  guint signalId;
347
351
  GQuark detail;
348
352
  GClosure *gclosure;
349
- ulong handler_id;
353
+ gulong handler_id;
350
354
 
351
355
  const char *signalName = *Nan::Utf8String (TO_STRING (info[0]));
352
356
  if (!g_signal_parse_name(signalName, gtype, &signalId, &detail, FALSE)) {
@@ -386,7 +390,7 @@ NAN_METHOD(SignalDisconnect) {
386
390
  }
387
391
 
388
392
  gpointer instance = static_cast<gpointer>(gobject);
389
- ulong handler_id = TO_LONG (info[0]);
393
+ gulong handler_id = TO_LONG (info[0]);
390
394
  g_signal_handler_disconnect (instance, handler_id);
391
395
 
392
396
  info.GetReturnValue().Set((double)handler_id);
@@ -443,7 +447,7 @@ NAN_METHOD(SignalEmit) {
443
447
  g_value_set_object(&args[0], gobject);
444
448
 
445
449
  failed = false;
446
- for (uint i = 0; i < signal_query.n_params; i++) {
450
+ for (guint i = 0; i < signal_query.n_params; i++) {
447
451
  GValue *gvalue = &args[i + 1];
448
452
 
449
453
  g_value_init(gvalue, signal_query.param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE);
@@ -466,7 +470,7 @@ NAN_METHOD(SignalEmit) {
466
470
  }
467
471
  }
468
472
 
469
- for (uint i = 0; i < argc; i++) {
473
+ for (guint i = 0; i < argc; i++) {
470
474
  g_value_unset(&args[i]);
471
475
  }
472
476
  }
@@ -486,7 +490,7 @@ NAN_METHOD(GObjectToString) {
486
490
  char *className = *Nan::Utf8String(self->GetConstructorName());
487
491
  void *address = self->GetAlignedPointerFromInternalField(0);
488
492
 
489
- char *str = g_strdup_printf("[%s:%s %#zx]", typeName, className, (unsigned long)address);
493
+ char *str = g_strdup_printf("[%s:%s %#zx]", typeName, className, (size_t)address);
490
494
 
491
495
  info.GetReturnValue().Set(UTF8(str));
492
496
  g_free(str);
package/src/loop.cc CHANGED
@@ -92,9 +92,14 @@ static GSourceFuncs uv_loop_source_funcs = {
92
92
  static GSource *loop_source_new (uv_loop_t *loop) {
93
93
  struct uv_loop_source *source = (struct uv_loop_source *) g_source_new (&uv_loop_source_funcs, sizeof (*source));
94
94
  source->loop = loop;
95
+ #if OS_WINDOWS
96
+ // FIXME
97
+ // https://github.com/nodejs/node/issues/36015
98
+ #else
95
99
  g_source_add_unix_fd (&source->source,
96
100
  uv_backend_fd (loop),
97
101
  (GIOCondition) (G_IO_IN | G_IO_OUT | G_IO_ERR));
102
+ #endif
98
103
  return &source->source;
99
104
  }
100
105
 
@@ -1336,119 +1336,115 @@ NAN_METHOD(tagEnd) {
1336
1336
  }
1337
1337
  #endif
1338
1338
 
1339
- #define SET_METHOD(tpl, name) Nan::SetPrototypeMethod(tpl, #name, name)
1340
-
1341
1339
  static void AttachMethods(Local<FunctionTemplate> tpl) {
1342
- SET_METHOD(tpl, status);
1343
- SET_METHOD(tpl, save);
1344
- SET_METHOD(tpl, restore);
1345
- SET_METHOD(tpl, getTarget);
1346
- SET_METHOD(tpl, pushGroup);
1347
- SET_METHOD(tpl, pushGroupWithContent);
1348
- SET_METHOD(tpl, popGroup);
1349
- SET_METHOD(tpl, popGroupToSource);
1350
- SET_METHOD(tpl, getGroupTarget);
1351
- SET_METHOD(tpl, setSourceRgb);
1352
- SET_METHOD(tpl, setSourceRgba);
1353
- SET_METHOD(tpl, setSource);
1354
- SET_METHOD(tpl, setSourceSurface);
1355
- SET_METHOD(tpl, getSource);
1356
- SET_METHOD(tpl, setAntialias);
1357
- SET_METHOD(tpl, getAntialias);
1358
- SET_METHOD(tpl, getDashCount);
1359
- SET_METHOD(tpl, getDash);
1360
- SET_METHOD(tpl, setFillRule);
1361
- SET_METHOD(tpl, getFillRule);
1362
- SET_METHOD(tpl, setLineCap);
1363
- SET_METHOD(tpl, getLineCap);
1364
- SET_METHOD(tpl, setLineJoin);
1365
- SET_METHOD(tpl, getLineJoin);
1366
- SET_METHOD(tpl, setLineWidth);
1367
- SET_METHOD(tpl, getLineWidth);
1368
- SET_METHOD(tpl, setMiterLimit);
1369
- SET_METHOD(tpl, getMiterLimit);
1370
- SET_METHOD(tpl, setOperator);
1371
- SET_METHOD(tpl, getOperator);
1372
- SET_METHOD(tpl, setTolerance);
1373
- SET_METHOD(tpl, getTolerance);
1374
- SET_METHOD(tpl, clip);
1375
- SET_METHOD(tpl, clipPreserve);
1376
- SET_METHOD(tpl, clipExtents);
1377
- SET_METHOD(tpl, inClip);
1378
- SET_METHOD(tpl, resetClip);
1379
- SET_METHOD(tpl, copyClipRectangleList);
1380
- SET_METHOD(tpl, fill);
1381
- SET_METHOD(tpl, fillPreserve);
1382
- SET_METHOD(tpl, fillExtents);
1383
- SET_METHOD(tpl, inFill);
1384
- SET_METHOD(tpl, mask);
1385
- SET_METHOD(tpl, maskSurface);
1386
- SET_METHOD(tpl, paint);
1387
- SET_METHOD(tpl, paintWithAlpha);
1388
- SET_METHOD(tpl, stroke);
1389
- SET_METHOD(tpl, strokePreserve);
1390
- SET_METHOD(tpl, strokeExtents);
1391
- SET_METHOD(tpl, inStroke);
1392
- SET_METHOD(tpl, copyPage);
1393
- SET_METHOD(tpl, showPage);
1394
- SET_METHOD(tpl, getReferenceCount);
1395
- SET_METHOD(tpl, copyPath);
1396
- SET_METHOD(tpl, copyPathFlat);
1397
- SET_METHOD(tpl, appendPath);
1398
- SET_METHOD(tpl, hasCurrentPoint);
1399
- SET_METHOD(tpl, getCurrentPoint);
1400
- SET_METHOD(tpl, newPath);
1401
- SET_METHOD(tpl, newSubPath);
1402
- SET_METHOD(tpl, closePath);
1403
- SET_METHOD(tpl, arc);
1404
- SET_METHOD(tpl, arcNegative);
1405
- SET_METHOD(tpl, curveTo);
1406
- SET_METHOD(tpl, lineTo);
1407
- SET_METHOD(tpl, moveTo);
1408
- SET_METHOD(tpl, rectangle);
1409
- SET_METHOD(tpl, glyphPath);
1410
- SET_METHOD(tpl, textPath);
1411
- SET_METHOD(tpl, relCurveTo);
1412
- SET_METHOD(tpl, relLineTo);
1413
- SET_METHOD(tpl, relMoveTo);
1414
- SET_METHOD(tpl, pathExtents);
1415
- SET_METHOD(tpl, showText);
1416
- SET_METHOD(tpl, showGlyphs);
1417
- SET_METHOD(tpl, showTextGlyphs);
1418
- SET_METHOD(tpl, fontExtents);
1419
- SET_METHOD(tpl, textExtents);
1420
- SET_METHOD(tpl, glyphExtents);
1421
- SET_METHOD(tpl, selectFontFace);
1422
- SET_METHOD(tpl, setFontSize);
1423
- SET_METHOD(tpl, setFontMatrix);
1424
- SET_METHOD(tpl, getFontMatrix);
1425
- SET_METHOD(tpl, setFontOptions);
1426
- SET_METHOD(tpl, getFontOptions);
1427
- SET_METHOD(tpl, setFontFace);
1428
- SET_METHOD(tpl, getFontFace);
1429
- SET_METHOD(tpl, setScaledFont);
1430
- SET_METHOD(tpl, getScaledFont);
1431
- SET_METHOD(tpl, translate);
1432
- SET_METHOD(tpl, scale);
1433
- SET_METHOD(tpl, rotate);
1434
- SET_METHOD(tpl, transform);
1435
- SET_METHOD(tpl, setMatrix);
1436
- SET_METHOD(tpl, getMatrix);
1437
- SET_METHOD(tpl, identityMatrix);
1438
- SET_METHOD(tpl, userToDevice);
1439
- SET_METHOD(tpl, userToDeviceDistance);
1440
- SET_METHOD(tpl, deviceToUser);
1441
- SET_METHOD(tpl, deviceToUserDistance);
1340
+ SET_PROTOTYPE_METHOD(tpl, status);
1341
+ SET_PROTOTYPE_METHOD(tpl, save);
1342
+ SET_PROTOTYPE_METHOD(tpl, restore);
1343
+ SET_PROTOTYPE_METHOD(tpl, getTarget);
1344
+ SET_PROTOTYPE_METHOD(tpl, pushGroup);
1345
+ SET_PROTOTYPE_METHOD(tpl, pushGroupWithContent);
1346
+ SET_PROTOTYPE_METHOD(tpl, popGroup);
1347
+ SET_PROTOTYPE_METHOD(tpl, popGroupToSource);
1348
+ SET_PROTOTYPE_METHOD(tpl, getGroupTarget);
1349
+ SET_PROTOTYPE_METHOD(tpl, setSourceRgb);
1350
+ SET_PROTOTYPE_METHOD(tpl, setSourceRgba);
1351
+ SET_PROTOTYPE_METHOD(tpl, setSource);
1352
+ SET_PROTOTYPE_METHOD(tpl, setSourceSurface);
1353
+ SET_PROTOTYPE_METHOD(tpl, getSource);
1354
+ SET_PROTOTYPE_METHOD(tpl, setAntialias);
1355
+ SET_PROTOTYPE_METHOD(tpl, getAntialias);
1356
+ SET_PROTOTYPE_METHOD(tpl, getDashCount);
1357
+ SET_PROTOTYPE_METHOD(tpl, getDash);
1358
+ SET_PROTOTYPE_METHOD(tpl, setFillRule);
1359
+ SET_PROTOTYPE_METHOD(tpl, getFillRule);
1360
+ SET_PROTOTYPE_METHOD(tpl, setLineCap);
1361
+ SET_PROTOTYPE_METHOD(tpl, getLineCap);
1362
+ SET_PROTOTYPE_METHOD(tpl, setLineJoin);
1363
+ SET_PROTOTYPE_METHOD(tpl, getLineJoin);
1364
+ SET_PROTOTYPE_METHOD(tpl, setLineWidth);
1365
+ SET_PROTOTYPE_METHOD(tpl, getLineWidth);
1366
+ SET_PROTOTYPE_METHOD(tpl, setMiterLimit);
1367
+ SET_PROTOTYPE_METHOD(tpl, getMiterLimit);
1368
+ SET_PROTOTYPE_METHOD(tpl, setOperator);
1369
+ SET_PROTOTYPE_METHOD(tpl, getOperator);
1370
+ SET_PROTOTYPE_METHOD(tpl, setTolerance);
1371
+ SET_PROTOTYPE_METHOD(tpl, getTolerance);
1372
+ SET_PROTOTYPE_METHOD(tpl, clip);
1373
+ SET_PROTOTYPE_METHOD(tpl, clipPreserve);
1374
+ SET_PROTOTYPE_METHOD(tpl, clipExtents);
1375
+ SET_PROTOTYPE_METHOD(tpl, inClip);
1376
+ SET_PROTOTYPE_METHOD(tpl, resetClip);
1377
+ SET_PROTOTYPE_METHOD(tpl, copyClipRectangleList);
1378
+ SET_PROTOTYPE_METHOD(tpl, fill);
1379
+ SET_PROTOTYPE_METHOD(tpl, fillPreserve);
1380
+ SET_PROTOTYPE_METHOD(tpl, fillExtents);
1381
+ SET_PROTOTYPE_METHOD(tpl, inFill);
1382
+ SET_PROTOTYPE_METHOD(tpl, mask);
1383
+ SET_PROTOTYPE_METHOD(tpl, maskSurface);
1384
+ SET_PROTOTYPE_METHOD(tpl, paint);
1385
+ SET_PROTOTYPE_METHOD(tpl, paintWithAlpha);
1386
+ SET_PROTOTYPE_METHOD(tpl, stroke);
1387
+ SET_PROTOTYPE_METHOD(tpl, strokePreserve);
1388
+ SET_PROTOTYPE_METHOD(tpl, strokeExtents);
1389
+ SET_PROTOTYPE_METHOD(tpl, inStroke);
1390
+ SET_PROTOTYPE_METHOD(tpl, copyPage);
1391
+ SET_PROTOTYPE_METHOD(tpl, showPage);
1392
+ SET_PROTOTYPE_METHOD(tpl, getReferenceCount);
1393
+ SET_PROTOTYPE_METHOD(tpl, copyPath);
1394
+ SET_PROTOTYPE_METHOD(tpl, copyPathFlat);
1395
+ SET_PROTOTYPE_METHOD(tpl, appendPath);
1396
+ SET_PROTOTYPE_METHOD(tpl, hasCurrentPoint);
1397
+ SET_PROTOTYPE_METHOD(tpl, getCurrentPoint);
1398
+ SET_PROTOTYPE_METHOD(tpl, newPath);
1399
+ SET_PROTOTYPE_METHOD(tpl, newSubPath);
1400
+ SET_PROTOTYPE_METHOD(tpl, closePath);
1401
+ SET_PROTOTYPE_METHOD(tpl, arc);
1402
+ SET_PROTOTYPE_METHOD(tpl, arcNegative);
1403
+ SET_PROTOTYPE_METHOD(tpl, curveTo);
1404
+ SET_PROTOTYPE_METHOD(tpl, lineTo);
1405
+ SET_PROTOTYPE_METHOD(tpl, moveTo);
1406
+ SET_PROTOTYPE_METHOD(tpl, rectangle);
1407
+ SET_PROTOTYPE_METHOD(tpl, glyphPath);
1408
+ SET_PROTOTYPE_METHOD(tpl, textPath);
1409
+ SET_PROTOTYPE_METHOD(tpl, relCurveTo);
1410
+ SET_PROTOTYPE_METHOD(tpl, relLineTo);
1411
+ SET_PROTOTYPE_METHOD(tpl, relMoveTo);
1412
+ SET_PROTOTYPE_METHOD(tpl, pathExtents);
1413
+ SET_PROTOTYPE_METHOD(tpl, showText);
1414
+ SET_PROTOTYPE_METHOD(tpl, showGlyphs);
1415
+ SET_PROTOTYPE_METHOD(tpl, showTextGlyphs);
1416
+ SET_PROTOTYPE_METHOD(tpl, fontExtents);
1417
+ SET_PROTOTYPE_METHOD(tpl, textExtents);
1418
+ SET_PROTOTYPE_METHOD(tpl, glyphExtents);
1419
+ SET_PROTOTYPE_METHOD(tpl, selectFontFace);
1420
+ SET_PROTOTYPE_METHOD(tpl, setFontSize);
1421
+ SET_PROTOTYPE_METHOD(tpl, setFontMatrix);
1422
+ SET_PROTOTYPE_METHOD(tpl, getFontMatrix);
1423
+ SET_PROTOTYPE_METHOD(tpl, setFontOptions);
1424
+ SET_PROTOTYPE_METHOD(tpl, getFontOptions);
1425
+ SET_PROTOTYPE_METHOD(tpl, setFontFace);
1426
+ SET_PROTOTYPE_METHOD(tpl, getFontFace);
1427
+ SET_PROTOTYPE_METHOD(tpl, setScaledFont);
1428
+ SET_PROTOTYPE_METHOD(tpl, getScaledFont);
1429
+ SET_PROTOTYPE_METHOD(tpl, translate);
1430
+ SET_PROTOTYPE_METHOD(tpl, scale);
1431
+ SET_PROTOTYPE_METHOD(tpl, rotate);
1432
+ SET_PROTOTYPE_METHOD(tpl, transform);
1433
+ SET_PROTOTYPE_METHOD(tpl, setMatrix);
1434
+ SET_PROTOTYPE_METHOD(tpl, getMatrix);
1435
+ SET_PROTOTYPE_METHOD(tpl, identityMatrix);
1436
+ SET_PROTOTYPE_METHOD(tpl, userToDevice);
1437
+ SET_PROTOTYPE_METHOD(tpl, userToDeviceDistance);
1438
+ SET_PROTOTYPE_METHOD(tpl, deviceToUser);
1439
+ SET_PROTOTYPE_METHOD(tpl, deviceToUserDistance);
1442
1440
  #if CAIRO_VERSION_MAJOR >= 1 && CAIRO_VERSION_MINOR >= 16
1443
- SET_METHOD(tpl, tagBegin);
1441
+ SET_PROTOTYPE_METHOD(tpl, tagBegin);
1444
1442
  #endif
1445
1443
  #if CAIRO_VERSION_MAJOR >= 1 && CAIRO_VERSION_MINOR >= 16
1446
- SET_METHOD(tpl, tagEnd);
1444
+ SET_PROTOTYPE_METHOD(tpl, tagEnd);
1447
1445
  #endif
1448
1446
  }
1449
1447
 
1450
- #undef SET_METHOD
1451
-
1452
1448
  /* </ auto-generated */
1453
1449
 
1454
1450
  static void InstanceDestroyed(const Nan::WeakCallbackInfo<ContextInfo> &info);
@@ -521,8 +521,6 @@ function getReturn(fn, outArguments) {
521
521
 
522
522
  function getAttachMethods(name, functions) {
523
523
  return unindent(`
524
- #define SET_METHOD(tpl, name) Nan::SetPrototypeMethod(tpl, #name, name)
525
-
526
524
  static void AttachMethods(Local<FunctionTemplate> tpl) {
527
525
  ${functions.map(fn =>
528
526
  (fn.attributes.version ? (() => {
@@ -533,12 +531,10 @@ function getAttachMethods(name, functions) {
533
531
  (micro ? 'CAIRO_VERSION_MICRO >= ' + micro : undefined),
534
532
  ].filter(Boolean).join(' && ') + '\n '
535
533
  })() : '')
536
- + `SET_METHOD(tpl, ${getJSName(fn.name)});`
534
+ + `SET_PROTOTYPE_METHOD(tpl, ${getJSName(fn.name)});`
537
535
  + (fn.attributes.version ? '\n #endif' : '')
538
536
  ).join('\n ')}
539
537
  }
540
-
541
- #undef SET_METHOD
542
538
  `)
543
539
  }
544
540
 
package/src/type.cc CHANGED
@@ -256,13 +256,13 @@ GITypeTag GetStorageType (GITypeInfo *type_info) {
256
256
  GITypeTag type_tag = g_type_info_get_tag (type_info);
257
257
 
258
258
  if (type_tag == GI_TYPE_TAG_INTERFACE) {
259
- GIBaseInfo *interface = g_type_info_get_interface (type_info);
260
- GIInfoType interface_type = g_base_info_get_type (interface);
259
+ GIBaseInfo *iface = g_type_info_get_interface (type_info);
260
+ GIInfoType iface_type = g_base_info_get_type (iface);
261
261
 
262
- if (interface_type == GI_INFO_TYPE_ENUM || interface_type == GI_INFO_TYPE_FLAGS)
263
- type_tag = g_enum_info_get_storage_type ((GIEnumInfo *)interface);
262
+ if (iface_type == GI_INFO_TYPE_ENUM || iface_type == GI_INFO_TYPE_FLAGS)
263
+ type_tag = g_enum_info_get_storage_type ((GIEnumInfo *)iface);
264
264
 
265
- g_base_info_unref (interface);
265
+ g_base_info_unref (iface);
266
266
  }
267
267
 
268
268
  return type_tag;
package/src/value.cc CHANGED
@@ -68,8 +68,8 @@ Local<Value> GIArgumentToV8(GITypeInfo *type_info, GIArgument *arg, long length,
68
68
  case GI_TYPE_TAG_UINT64:
69
69
  return New<Number> (arg->v_uint64);
70
70
 
71
- case GI_TYPE_TAG_GTYPE: /* c++: gulong */
72
- return v8::BigInt::NewFromUnsigned(Isolate::GetCurrent(), arg->v_ulong);
71
+ case GI_TYPE_TAG_GTYPE: /* c++: gsize */
72
+ return v8::BigInt::NewFromUnsigned(Isolate::GetCurrent(), arg->v_size);
73
73
 
74
74
  case GI_TYPE_TAG_UNICHAR:
75
75
  {
@@ -238,6 +238,55 @@ Local<Value> GErrorToV8 (GITypeInfo *type_info, GError *err) {
238
238
  return obj;
239
239
  }
240
240
 
241
+ template<typename T>
242
+ static bool isZero(void* value) {
243
+ return *(reinterpret_cast<T*>(value)) == 0;
244
+ }
245
+
246
+ static bool isZero(GIArgument &value, GITypeInfo *type_info) {
247
+ GITypeTag type_tag = g_type_info_get_tag (type_info);
248
+
249
+ switch (type_tag) {
250
+ case GI_TYPE_TAG_BOOLEAN:
251
+ ERROR("Boolean zero-terminated array not supported");
252
+ return false;
253
+ case GI_TYPE_TAG_INT8:
254
+ return isZero<gint8>(&value);
255
+ case GI_TYPE_TAG_UINT8:
256
+ return isZero<guint8>(&value);
257
+ case GI_TYPE_TAG_INT16:
258
+ return isZero<gint16>(&value);
259
+ case GI_TYPE_TAG_UINT16:
260
+ return isZero<guint16>(&value);
261
+ case GI_TYPE_TAG_INT32:
262
+ return isZero<gint32>(&value);
263
+ case GI_TYPE_TAG_UINT32:
264
+ return isZero<guint32>(&value);
265
+ case GI_TYPE_TAG_INT64:
266
+ return isZero<gint64>(&value);
267
+ case GI_TYPE_TAG_UINT64:
268
+ return isZero<guint64>(&value);
269
+ case GI_TYPE_TAG_FLOAT:
270
+ return isZero<float>(&value);
271
+ case GI_TYPE_TAG_DOUBLE:
272
+ return isZero<double>(&value);
273
+ case GI_TYPE_TAG_UNICHAR:
274
+ return isZero<gunichar>(&value);
275
+
276
+ case GI_TYPE_TAG_GTYPE:
277
+ case GI_TYPE_TAG_INTERFACE:
278
+ case GI_TYPE_TAG_ARRAY:
279
+ case GI_TYPE_TAG_VOID:
280
+ case GI_TYPE_TAG_UTF8:
281
+ case GI_TYPE_TAG_FILENAME:
282
+ case GI_TYPE_TAG_GLIST:
283
+ case GI_TYPE_TAG_GSLIST:
284
+ case GI_TYPE_TAG_GHASH:
285
+ case GI_TYPE_TAG_ERROR:
286
+ return isZero<gpointer>(&value);
287
+ }
288
+ }
289
+
241
290
  Local<Value> ArrayToV8 (GITypeInfo *type_info, void* data, long length) {
242
291
 
243
292
  auto array = New<Array>();
@@ -253,20 +302,15 @@ Local<Value> ArrayToV8 (GITypeInfo *type_info, void* data, long length) {
253
302
  switch (array_type) {
254
303
  case GI_ARRAY_TYPE_C:
255
304
  {
256
- if (length == -1) {
257
- if (g_type_info_is_zero_terminated (type_info)) {
258
- length = g_strv_length ((gchar **)data);
259
- }
260
- else {
261
- length = g_type_info_get_array_fixed_size (type_info);
262
- if (G_UNLIKELY (length == -1)) {
263
- g_critical ("Unable to determine array length for %p", data);
264
- length = 0;
265
- break;
266
- }
305
+ if (length == -1 && !g_type_info_is_zero_terminated (type_info)) {
306
+ length = g_type_info_get_array_fixed_size (type_info);
307
+ if (G_UNLIKELY (length == -1)) {
308
+ g_critical ("Unable to determine array length for %p", data);
309
+ length = 0;
310
+ break;
267
311
  }
268
312
  }
269
- g_assert (length >= 0);
313
+ // length remains -1 for zero-terminated array.
270
314
  break;
271
315
  }
272
316
  case GI_ARRAY_TYPE_ARRAY:
@@ -301,9 +345,16 @@ Local<Value> ArrayToV8 (GITypeInfo *type_info, void* data, long length) {
301
345
 
302
346
  GIArgument value;
303
347
 
304
- for (int i = 0; i < length; i++) {
305
- void** pointer = (void**)((ulong)data + i * item_size);
348
+ for (int i = 0; ; i++) {
349
+ if (length != -1 && i >= length)
350
+ break;
351
+
352
+ void** pointer = (void**)((size_t)data + i * item_size);
306
353
  memcpy(&value, pointer, item_size);
354
+
355
+ if (length == -1 && isZero(value, item_type_info))
356
+ break;
357
+
307
358
  Nan::Set(array, i, GIArgumentToV8(item_type_info, &value));
308
359
  }
309
360
 
@@ -407,7 +458,7 @@ static void *V8ArrayToCArray(GITypeInfo *type_info, Local<Value> value) {
407
458
  GITypeInfo* element_info = g_type_info_get_param_type (type_info, 0);
408
459
  gsize element_size = GetTypeSize(element_info);
409
460
 
410
- void *result = malloc(element_size * (length + (isZeroTerminated ? 1 : 0)));
461
+ void *result = g_malloc0(element_size * (length + (isZeroTerminated ? 1 : 0)));
411
462
 
412
463
  for (int i = 0; i < length; i++) {
413
464
  auto value = Nan::Get(array, i).ToLocalChecked();
@@ -415,7 +466,7 @@ static void *V8ArrayToCArray(GITypeInfo *type_info, Local<Value> value) {
415
466
  GIArgument arg;
416
467
 
417
468
  if (V8ToGIArgument(element_info, &arg, value, true)) {
418
- void* pointer = (void*)((ulong)result + i * element_size);
469
+ void* pointer = (void*)((size_t)result + i * element_size);
419
470
  memcpy(pointer, &arg, element_size);
420
471
  } else {
421
472
  WARN("couldnt convert value: %s", *Nan::Utf8String(TO_STRING (value)));
@@ -423,7 +474,10 @@ static void *V8ArrayToCArray(GITypeInfo *type_info, Local<Value> value) {
423
474
  }
424
475
 
425
476
  if (isZeroTerminated) {
426
- void* pointer = (void*)((ulong)result + length * element_size);
477
+ // TODO:
478
+ // Since g_malloc0 above already zeros the memory
479
+ // it's better to assert the last element is zero
480
+ void* pointer = (void*)((size_t)result + length * element_size);
427
481
  memset(pointer, 0, element_size);
428
482
  }
429
483
 
@@ -439,12 +493,15 @@ static void *V8TypedArrayToCArray(GITypeInfo *type_info, Local<Value> value) {
439
493
  GITypeInfo* element_info = g_type_info_get_param_type (type_info, 0);
440
494
  gsize element_size = GetTypeSize(element_info);
441
495
 
442
- void *result = malloc(element_size * (length + (isZeroTerminated ? 1 : 0)));
496
+ void *result = g_malloc0(element_size * (length + (isZeroTerminated ? 1 : 0)));
443
497
 
444
498
  array->CopyContents(result, length);
445
499
 
446
500
  if (isZeroTerminated) {
447
- void* pointer = (void*)((ulong)result + length * element_size);
501
+ // TODO:
502
+ // Since g_malloc0 above already zeros the memory
503
+ // it's better to assert the last element is zero
504
+ void* pointer = (void*)((size_t)result + length * element_size);
448
505
  memset(pointer, 0, element_size);
449
506
  }
450
507
 
@@ -597,14 +654,14 @@ gpointer V8ToGHash (GITypeInfo *type_info, Local<Value> value) {
597
654
  if (!V8ToGIArgument(key_type_info, &key_arg, key, false)) {
598
655
  char* message = g_strdup_printf("Couldn't convert key '%s'", *Nan::Utf8String(key));
599
656
  Nan::ThrowError(message);
600
- free(message);
657
+ g_free(message);
601
658
  goto item_error;
602
659
  }
603
660
 
604
661
  if (!V8ToGIArgument(value_type_info, &value_arg, value, false)) {
605
662
  char* message = g_strdup_printf("Couldn't convert value for key '%s'", *Nan::Utf8String(key));
606
663
  Nan::ThrowError(message);
607
- free(message);
664
+ g_free(message);
608
665
  goto item_error;
609
666
  }
610
667
 
@@ -628,6 +685,8 @@ item_error:
628
685
  bool V8ToGIArgument(GIBaseInfo *gi_info, GIArgument *arg, Local<Value> value) {
629
686
  GIInfoType type = g_base_info_get_type (gi_info);
630
687
 
688
+ memset(arg, 0, sizeof(GIArgument));
689
+
631
690
  switch (type) {
632
691
  case GI_INFO_TYPE_BOXED:
633
692
  case GI_INFO_TYPE_STRUCT:
@@ -665,6 +724,8 @@ bool V8ToGIArgument(GIBaseInfo *gi_info, GIArgument *arg, Local<Value> value) {
665
724
  bool V8ToGIArgument(GITypeInfo *type_info, GIArgument *arg, Local<Value> value, bool may_be_null) {
666
725
  GITypeTag type_tag = g_type_info_get_tag (type_info);
667
726
 
727
+ memset(arg, 0, sizeof(GIArgument));
728
+
668
729
  if (value->IsUndefined () || value->IsNull ()) {
669
730
  arg->v_pointer = NULL;
670
731
 
@@ -697,7 +758,10 @@ bool V8ToGIArgument(GITypeInfo *type_info, GIArgument *arg, Local<Value> value,
697
758
  arg->v_int = Nan::To<int32_t> (value).ToChecked();
698
759
  break;
699
760
  case GI_TYPE_TAG_INT64:
700
- arg->v_int64 = Nan::To<int64_t> (value).ToChecked();
761
+ if (value->IsBigInt())
762
+ arg->v_int64 = value.As<v8::BigInt>()->Int64Value();
763
+ else
764
+ arg->v_int64 = Nan::To<int64_t> (value).ToChecked();
701
765
  break;
702
766
  case GI_TYPE_TAG_UINT8:
703
767
  arg->v_uint8 = Nan::To<uint32_t> (value).ToChecked();
@@ -709,7 +773,10 @@ bool V8ToGIArgument(GITypeInfo *type_info, GIArgument *arg, Local<Value> value,
709
773
  arg->v_uint = Nan::To<uint32_t> (value).ToChecked();
710
774
  break;
711
775
  case GI_TYPE_TAG_UINT64:
712
- arg->v_uint64 = Nan::To<int64_t> (value).ToChecked();
776
+ if (value->IsBigInt())
777
+ arg->v_uint64 = value.As<v8::BigInt>()->Uint64Value();
778
+ else
779
+ arg->v_uint64 = Nan::To<int64_t> (value).ToChecked();
713
780
  break;
714
781
  case GI_TYPE_TAG_FLOAT:
715
782
  arg->v_float = Nan::To<double> (value).ToChecked();
@@ -719,9 +786,9 @@ bool V8ToGIArgument(GITypeInfo *type_info, GIArgument *arg, Local<Value> value,
719
786
  break;
720
787
  case GI_TYPE_TAG_GTYPE:
721
788
  if (value->IsBigInt())
722
- arg->v_ulong = value.As<v8::BigInt>()->Uint64Value();
789
+ arg->v_size = value.As<v8::BigInt>()->Uint64Value();
723
790
  else
724
- arg->v_ulong = Nan::To<int64_t> (value).ToChecked();
791
+ arg->v_size = Nan::To<int64_t> (value).ToChecked();
725
792
  break;
726
793
 
727
794
  case GI_TYPE_TAG_UTF8:
@@ -810,6 +877,8 @@ bool V8ToOutGIArgument(GITypeInfo *type_info, GIArgument *arg, Local<Value> valu
810
877
  */
811
878
  GITypeTag type_tag = g_type_info_get_tag (type_info);
812
879
 
880
+ memset(arg, 0, sizeof(GIArgument));
881
+
813
882
  if (value->IsUndefined () || value->IsNull ()) {
814
883
  arg->v_pointer = NULL;
815
884
 
@@ -835,7 +904,10 @@ bool V8ToOutGIArgument(GITypeInfo *type_info, GIArgument *arg, Local<Value> valu
835
904
  *(gint*)arg->v_pointer = Nan::To<int32_t> (value).ToChecked();
836
905
  break;
837
906
  case GI_TYPE_TAG_INT64:
838
- *(gint64*)arg->v_pointer = Nan::To<int64_t> (value).ToChecked();
907
+ if (value->IsBigInt())
908
+ *(gint64*)arg->v_pointer = value.As<v8::BigInt>()->Int64Value();
909
+ else
910
+ *(gint64*)arg->v_pointer = Nan::To<int64_t> (value).ToChecked();
839
911
  break;
840
912
  case GI_TYPE_TAG_UINT8:
841
913
  *(guint8*)arg->v_pointer = Nan::To<uint32_t> (value).ToChecked();
@@ -847,7 +919,10 @@ bool V8ToOutGIArgument(GITypeInfo *type_info, GIArgument *arg, Local<Value> valu
847
919
  *(guint*)arg->v_pointer = Nan::To<uint32_t> (value).ToChecked();
848
920
  break;
849
921
  case GI_TYPE_TAG_UINT64:
850
- *(guint64*)arg->v_pointer = Nan::To<int64_t> (value).ToChecked();
922
+ if (value->IsBigInt())
923
+ *(guint64*)arg->v_pointer = value.As<v8::BigInt>()->Uint64Value();
924
+ else
925
+ *(guint64*)arg->v_pointer = Nan::To<int64_t> (value).ToChecked();
851
926
  break;
852
927
  case GI_TYPE_TAG_FLOAT:
853
928
  *(gfloat*)arg->v_pointer = Nan::To<double> (value).ToChecked();
@@ -857,9 +932,9 @@ bool V8ToOutGIArgument(GITypeInfo *type_info, GIArgument *arg, Local<Value> valu
857
932
  break;
858
933
  case GI_TYPE_TAG_GTYPE:
859
934
  if (value->IsBigInt())
860
- *(gulong*)arg->v_pointer = value.As<v8::BigInt>()->Uint64Value();
935
+ *(gsize*)arg->v_pointer = value.As<v8::BigInt>()->Uint64Value();
861
936
  else
862
- *(gulong*)arg->v_pointer = Nan::To<int64_t> (value).ToChecked();
937
+ *(gsize*)arg->v_pointer = Nan::To<int64_t> (value).ToChecked();
863
938
  break;
864
939
 
865
940
  case GI_TYPE_TAG_UTF8:
@@ -913,15 +988,15 @@ bool CanConvertV8ToGIArgument(GITypeInfo *type_info, Local<Value> value, bool ma
913
988
  case GI_TYPE_TAG_INT8:
914
989
  case GI_TYPE_TAG_INT16:
915
990
  case GI_TYPE_TAG_INT32:
916
- case GI_TYPE_TAG_INT64:
917
991
  case GI_TYPE_TAG_UINT8:
918
992
  case GI_TYPE_TAG_UINT16:
919
993
  case GI_TYPE_TAG_UINT32:
920
- case GI_TYPE_TAG_UINT64:
921
994
  case GI_TYPE_TAG_FLOAT:
922
995
  case GI_TYPE_TAG_DOUBLE:
923
996
  return value->IsNumber ();
924
997
 
998
+ case GI_TYPE_TAG_INT64:
999
+ case GI_TYPE_TAG_UINT64:
925
1000
  case GI_TYPE_TAG_GTYPE:
926
1001
  return value->IsNumber () || value->IsBigInt ();
927
1002
 
@@ -1251,7 +1326,7 @@ void FreeGIArgumentArray(GITypeInfo *type_info, GIArgument *arg, GITransfer tran
1251
1326
 
1252
1327
  for (int i = 0; i < length; i++) {
1253
1328
  GIArgument item;
1254
- memcpy (&item, (void*)((ulong)data + element_size * i), sizeof (GIArgument));
1329
+ memcpy (&item, (void*)((size_t)data + element_size * i), sizeof (GIArgument));
1255
1330
  FreeGIArgument (element_info, &item, item_transfer, direction);
1256
1331
  }
1257
1332
 
@@ -1270,7 +1345,7 @@ void FreeGIArgumentArray(GITypeInfo *type_info, GIArgument *arg, GITransfer tran
1270
1345
  switch (array_type) {
1271
1346
  case GI_ARRAY_TYPE_C:
1272
1347
  {
1273
- free(data);
1348
+ g_free (data);
1274
1349
  break;
1275
1350
  }
1276
1351
  case GI_ARRAY_TYPE_ARRAY:
package/src/value.h CHANGED
@@ -26,7 +26,7 @@ void FreeGIArgument (GITypeInfo *type_info, GIArgument *argument, GITran
26
26
  void FreeGIArgumentArray (GITypeInfo *type_info, GIArgument *arg, GITransfer transfer = GI_TRANSFER_EVERYTHING, GIDirection direction = GI_DIRECTION_OUT, long length = -1);
27
27
  bool CanConvertV8ToGIArgument (GITypeInfo *type_info, Local<Value> value, bool may_be_null);
28
28
 
29
- bool V8ToGValue(GValue *gvalue, Local<Value> value, bool mustCopy = false) __attribute__((warn_unused_result));
29
+ bool V8ToGValue(GValue *gvalue, Local<Value> value, bool mustCopy = false);
30
30
  Local<Value> GValueToV8(const GValue *gvalue, bool mustCopy = false);
31
31
  bool CanConvertV8ToGValue(GValue *gvalue, Local<Value> value);
32
32