Skip to content

Commit 2054e3a

Browse files
committed
Merge pull request nodegit#957 from srajko/new-type-safety
Use type safe pointer instead of void * for New
2 parents bf3983a + fb1bd51 commit 2054e3a

File tree

10 files changed

+13
-13
lines changed

10 files changed

+13
-13
lines changed

generate/templates/manual/include/wrapper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Wrapper : public Nan::ObjectWrap {
2020
static void InitializeComponent (Local<v8::Object> target);
2121

2222
void *GetValue();
23-
static Local<v8::Value> New(void *raw);
23+
static Local<v8::Value> New(const void *raw);
2424

2525
private:
2626
Wrapper(void *raw);

generate/templates/manual/src/convenient_patch.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ NAN_METHOD(ConvenientPatch::OldFile) {
303303
git_diff_file *old_file = (git_diff_file *)malloc(sizeof(git_diff_file));
304304
*old_file = Nan::ObjectWrap::Unwrap<ConvenientPatch>(info.This())->GetOldFile();
305305

306-
to = GitDiffFile::New((void *)old_file, true);
306+
to = GitDiffFile::New(old_file, true);
307307

308308
return info.GetReturnValue().Set(to);
309309
}
@@ -315,7 +315,7 @@ NAN_METHOD(ConvenientPatch::NewFile) {
315315
git_diff_file *new_file = (git_diff_file *)malloc(sizeof(git_diff_file));
316316
*new_file = Nan::ObjectWrap::Unwrap<ConvenientPatch>(info.This())->GetNewFile();
317317
if (new_file != NULL) {
318-
to = GitDiffFile::New((void *)new_file, true);
318+
to = GitDiffFile::New(new_file, true);
319319
} else {
320320
to = Nan::Null();
321321
}

generate/templates/manual/src/wrapper.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ NAN_METHOD(Wrapper::JSNewFunction) {
4242
info.GetReturnValue().Set(info.This());
4343
}
4444

45-
Local<v8::Value> Wrapper::New(void *raw) {
45+
Local<v8::Value> Wrapper::New(const void *raw) {
4646
Nan::EscapableHandleScope scope;
4747

4848
Local<v8::Value> argv[1] = { Nan::New<External>((void *)raw) };

generate/templates/partials/callback_helpers.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_async(uv_as
5555
{% if arg.isEnum %}
5656
Nan::New((int)baton->{{ arg.name }}),
5757
{% elsif arg.isLibgitType %}
58-
{{ arg.cppClassName }}::New((void *)baton->{{ arg.name }}, false),
58+
{{ arg.cppClassName }}::New(baton->{{ arg.name }}, false),
5959
{% elsif arg.cType == "size_t" %}
6060
// HACK: NAN should really have an overload for Nan::New to support size_t
6161
Nan::New((unsigned int)baton->{{ arg.name }}),

generate/templates/partials/convert_to_v8.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
if ({{= parsedName =}} != NULL) {
6060
// {{= cppClassName }} {{= parsedName }}
6161
{% if cppClassName == 'Wrapper' %}
62-
to = {{ cppClassName }}::New((void *){{= parsedName =}});
62+
to = {{ cppClassName }}::New({{= parsedName =}});
6363
{% else %}
64-
to = {{ cppClassName }}::New((void *){{= parsedName =}}, false);
64+
to = {{ cppClassName }}::New({{= parsedName =}}, false);
6565
{% endif %}
6666
}
6767
else {

generate/templates/partials/field_accessors.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
{% if arg.isEnum %}
150150
Nan::New((int)baton->{{ arg.name }}),
151151
{% elsif arg.isLibgitType %}
152-
{{ arg.cppClassName }}::New((void *)baton->{{ arg.name }}, false),
152+
{{ arg.cppClassName }}::New(baton->{{ arg.name }}, false),
153153
{% elsif arg.cType == "size_t" %}
154154
// HACK: NAN should really have an overload for Nan::New to support size_t
155155
Nan::New((unsigned int)baton->{{ arg.name }}),

generate/templates/templates/class_content.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ using namespace node;
9898
info.GetReturnValue().Set(info.This());
9999
}
100100

101-
Local<v8::Value> {{ cppClassName }}::New(void *raw, bool selfFreeing) {
101+
Local<v8::Value> {{ cppClassName }}::New(const {{ cType }} *raw, bool selfFreeing) {
102102
Nan::EscapableHandleScope scope;
103103
Local<v8::Value> argv[2] = { Nan::New<External>((void *)raw), Nan::New(selfFreeing) };
104104
return scope.Escape(Nan::NewInstance(Nan::New({{ cppClassName }}::constructor_template), 2, argv).ToLocalChecked());

generate/templates/templates/class_header.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class {{ cppClassName }} : public Nan::ObjectWrap {
4545
{{ cType }} *GetValue();
4646
void ClearValue();
4747

48-
static Local<v8::Value> New(void *raw, bool selfFreeing);
48+
static Local<v8::Value> New(const {{ cType }} *raw, bool selfFreeing);
4949
{%endif%}
5050
bool selfFreeing;
5151

generate/templates/templates/struct_content.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void {{ cppClassName }}::ConstructFields() {
7373
{% if not field.isEnum %}
7474
{% if field.hasConstructor |or field.isLibgitType %}
7575
Local<Object> {{ field.name }}Temp = {{ field.cppClassName }}::New(
76-
&this->raw->{{ field.name }},
76+
{%if not field.cType|isPointer %}&{%endif%}this->raw->{{ field.name }},
7777
false
7878
)->ToObject();
7979
this->{{ field.name }}.Reset({{ field.name }}Temp);
@@ -131,7 +131,7 @@ NAN_METHOD({{ cppClassName }}::JSNewFunction) {
131131
info.GetReturnValue().Set(info.This());
132132
}
133133

134-
Local<v8::Value> {{ cppClassName }}::New(void* raw, bool selfFreeing) {
134+
Local<v8::Value> {{ cppClassName }}::New(const {{ cType }} * raw, bool selfFreeing) {
135135
Nan::EscapableHandleScope scope;
136136

137137
Local<v8::Value> argv[2] = { Nan::New<External>((void *)raw), Nan::New<Boolean>(selfFreeing) };

generate/templates/templates/struct_header.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class {{ cppClassName }} : public Nan::ObjectWrap {
3030
{{ cType }} *GetValue();
3131
void ClearValue();
3232

33-
static Local<v8::Value> New(void *raw, bool selfFreeing);
33+
static Local<v8::Value> New(const {{ cType }} *raw, bool selfFreeing);
3434

3535
bool selfFreeing;
3636

0 commit comments

Comments
 (0)