diff --git a/src/branch.cc b/src/branch.cc index e633ffce6..cd6c94c64 100644 --- a/src/branch.cc +++ b/src/branch.cc @@ -93,7 +93,7 @@ Handle Branch::Create(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number force is required."))); } - git_reference *out = NULL; + git_reference * out = 0; git_repository * from_repo; from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const char * from_branch_name; @@ -220,7 +220,7 @@ Handle Branch::Move(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number force is required."))); } - git_reference *out = NULL; + git_reference * out = 0; git_reference * from_branch; from_branch = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const char * from_new_branch_name; @@ -271,7 +271,7 @@ Handle Branch::Lookup(const Arguments& args) { return ThrowException(Exception::Error(String::New("BranchT branch_type is required."))); } - git_reference *out = NULL; + git_reference * out = 0; git_repository * from_repo; from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const char * from_branch_name; @@ -314,7 +314,7 @@ Handle Branch::Name(const Arguments& args) { return ThrowException(Exception::Error(String::New("Reference ref is required."))); } - const char *out = NULL; + const char * out = 0; git_reference * from_ref; from_ref = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); @@ -345,7 +345,7 @@ Handle Branch::Upstream(const Arguments& args) { return ThrowException(Exception::Error(String::New("Reference branch is required."))); } - git_reference *out = NULL; + git_reference * out = 0; git_reference * from_branch; from_branch = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); diff --git a/src/commit.cc b/src/commit.cc index 43423dd35..a969aaa07 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -287,7 +287,7 @@ Handle GitCommit::NthGenAncestor(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number n is required."))); } - git_commit *ancestor = NULL; + git_commit * ancestor = 0; unsigned int from_n; from_n = (unsigned int) args[0]->ToUint32()->Value(); diff --git a/src/diff_list.cc b/src/diff_list.cc index 37691b435..9eae3e716 100755 --- a/src/diff_list.cc +++ b/src/diff_list.cc @@ -182,8 +182,8 @@ Handle GitDiffList::Patch(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number idx is required."))); } - git_diff_patch *patch_out = NULL; - const git_diff_delta *delta_out = NULL; + git_diff_patch * patch_out = 0; + const git_diff_delta * delta_out = 0; size_t from_idx; from_idx = (size_t) args[0]->ToUint32()->Value(); diff --git a/src/index.cc b/src/index.cc index 725192951..f54f9c790 100644 --- a/src/index.cc +++ b/src/index.cc @@ -676,34 +676,29 @@ Handle GitIndex::RemoveBypath(const Arguments& args) { } /** - * @param {Number} at_pos * @param {String} path - * @return {Number} result + * @return {Number} at_pos */ Handle GitIndex::Find(const Arguments& args) { HandleScope scope; - if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number at_pos is required."))); - } - if (args.Length() == 1 || !args[1]->IsString()) { + if (args.Length() == 0 || !args[0]->IsString()) { return ThrowException(Exception::Error(String::New("String path is required."))); } - size_t * from_at_pos; - from_at_pos = (size_t *) args[0]->ToUint32()->Value(); - const char * from_path; - String::Utf8Value path(args[1]->ToString()); + size_t at_pos = 0; + const char * from_path; + String::Utf8Value path(args[0]->ToString()); from_path = strdup(*path); int result = git_index_find( - from_at_pos + &at_pos , ObjectWrap::Unwrap(args.This())->GetValue() , from_path ); free((void *)from_path); Handle to; - to = Int32::New(result); + to = Uint32::New(at_pos); return scope.Close(to); } diff --git a/src/odb.cc b/src/odb.cc index b02857571..0711eb479 100644 --- a/src/odb.cc +++ b/src/odb.cc @@ -80,7 +80,7 @@ git_odb *GitOdb::GetValue() { Handle GitOdb::Create(const Arguments& args) { HandleScope scope; - git_odb *out = NULL; + git_odb * out = 0; int result = git_odb_new( &out @@ -112,7 +112,7 @@ Handle GitOdb::Open(const Arguments& args) { return ThrowException(Exception::Error(String::New("String objects_dir is required."))); } - git_odb *out = NULL; + git_odb * out = 0; const char * from_objects_dir; String::Utf8Value objects_dir(args[0]->ToString()); from_objects_dir = strdup(*objects_dir); @@ -268,7 +268,7 @@ Handle GitOdb::ReadPrefix(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number len is required."))); } - git_odb_object *out = NULL; + git_odb_object * out = 0; git_odb * from_db; from_db = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const git_oid * from_short_id; @@ -300,38 +300,30 @@ Handle GitOdb::ReadPrefix(const Arguments& args) { } /** - * @param {Number} len_out - * @param {Number} type_out * @param {Odb} db * @param {Oid} id + * @return {Number} len_out + * @return {Number} type_out */ Handle GitOdb::ReadHeader(const Arguments& args) { HandleScope scope; - if (args.Length() == 0 || !args[0]->IsUint32()) { - return ThrowException(Exception::Error(String::New("Number len_out is required."))); - } - if (args.Length() == 1 || !args[1]->IsInt32()) { - return ThrowException(Exception::Error(String::New("Number type_out is required."))); - } - if (args.Length() == 2 || !args[2]->IsObject()) { + if (args.Length() == 0 || !args[0]->IsObject()) { return ThrowException(Exception::Error(String::New("Odb db is required."))); } - if (args.Length() == 3 || !args[3]->IsObject()) { + if (args.Length() == 1 || !args[1]->IsObject()) { return ThrowException(Exception::Error(String::New("Oid id is required."))); } - size_t * from_len_out; - from_len_out = (size_t *) args[0]->ToUint32()->Value(); - git_otype * from_type_out; - from_type_out = (git_otype *) args[1]->ToInt32()->Value(); - git_odb * from_db; - from_db = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); + size_t len_out = 0; + git_otype type_out = GIT_OBJ_ANY; + git_odb * from_db; + from_db = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); const git_oid * from_id; - from_id = ObjectWrap::Unwrap(args[3]->ToObject())->GetValue(); + from_id = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); int result = git_odb_read_header( - from_len_out - , from_type_out + &len_out + , &type_out , from_db , from_id ); @@ -343,7 +335,15 @@ Handle GitOdb::ReadHeader(const Arguments& args) { } } - return Undefined(); + Handle toReturn = Object::New(); + Handle to; + to = Uint32::New(len_out); + toReturn->Set(String::NewSymbol("len_out"), to); + + to = Int32::New(type_out); + toReturn->Set(String::NewSymbol("type_out"), to); + + return scope.Close(toReturn); } /** @@ -517,7 +517,7 @@ Handle GitOdb::Hash(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number type is required."))); } - git_oid *out = (git_oid *)malloc(sizeof(git_oid )); + git_oid *out = (git_oid *)malloc(sizeof(git_oid)); const void * from_data; from_data = Buffer::Data(args[0]->ToObject()); size_t from_len; @@ -563,7 +563,7 @@ Handle GitOdb::Hashfile(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number type is required."))); } - git_oid *out = (git_oid *)malloc(sizeof(git_oid )); + git_oid *out = (git_oid *)malloc(sizeof(git_oid)); const char * from_path; String::Utf8Value path(args[0]->ToString()); from_path = strdup(*path); diff --git a/src/oid.cc b/src/oid.cc index fbd8ee4a2..0f354998f 100755 --- a/src/oid.cc +++ b/src/oid.cc @@ -72,7 +72,7 @@ Handle GitOid::FromString(const Arguments& args) { return ThrowException(Exception::Error(String::New("String str is required."))); } - git_oid *out = (git_oid *)malloc(sizeof(git_oid )); + git_oid *out = (git_oid *)malloc(sizeof(git_oid)); const char * from_str; String::Utf8Value str(args[0]->ToString()); from_str = strdup(*str); diff --git a/src/patch.cc b/src/patch.cc index a28863254..1ee267a99 100644 --- a/src/patch.cc +++ b/src/patch.cc @@ -116,9 +116,9 @@ Handle GitPatch::Size(const Arguments& args) { Handle GitPatch::Stats(const Arguments& args) { HandleScope scope; - size_t total_context = NULL; - size_t total_additions = NULL; - size_t total_deletions = NULL; + size_t total_context = 0; + size_t total_additions = 0; + size_t total_deletions = 0; int result = git_diff_patch_line_stats( &total_context @@ -161,10 +161,10 @@ Handle GitPatch::Hunk(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number hunk_idx is required."))); } - const git_diff_range *range = NULL; - const char *header = NULL; - size_t header_len = NULL; - size_t lines_in_hunk = NULL; + const git_diff_range * range = 0; + const char * header = 0; + size_t header_len = 0; + size_t lines_in_hunk = 0; size_t from_hunk_idx; from_hunk_idx = (size_t) args[0]->ToUint32()->Value(); @@ -249,11 +249,11 @@ Handle GitPatch::Line(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number line_of_hunk is required."))); } - char line_origin = NULL; - const char *content = NULL; - size_t content_len = NULL; - int old_lineno = NULL; - int new_lineno = NULL; + char line_origin = 0; + const char * content = 0; + size_t content_len = 0; + int old_lineno = 0; + int new_lineno = 0; size_t from_hunk_idx; from_hunk_idx = (size_t) args[0]->ToUint32()->Value(); size_t from_line_of_hunk; @@ -303,7 +303,7 @@ Handle GitPatch::Line(const Arguments& args) { Handle GitPatch::ToString(const Arguments& args) { HandleScope scope; - char *string = NULL; + char * string = 0; int result = git_diff_patch_to_str( &string diff --git a/src/reference.cc b/src/reference.cc index 86258e948..a29744122 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -322,7 +322,7 @@ Handle GitReference::SetSymbolicTarget(const Arguments& args) { return ThrowException(Exception::Error(String::New("String target is required."))); } - git_reference *out = NULL; + git_reference * out = 0; const char * from_target; String::Utf8Value target(args[0]->ToString()); from_target = strdup(*target); @@ -360,7 +360,7 @@ Handle GitReference::setTarget(const Arguments& args) { return ThrowException(Exception::Error(String::New("Oid id is required."))); } - git_reference *out = NULL; + git_reference * out = 0; const git_oid * from_id; from_id = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); @@ -594,7 +594,7 @@ Handle GitReference::Peel(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number type is required."))); } - git_object *out = NULL; + git_object * out = 0; git_otype from_type; from_type = (git_otype) args[0]->ToInt32()->Value(); diff --git a/src/remote.cc b/src/remote.cc index 3445111a0..8090391b8 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -280,7 +280,7 @@ Handle GitRemote::Download(const Arguments& args) { if (args[0]->IsFunction()) { Persistent::New(Local::Cast(args[0])); } else { - from_progress_cb = NULL; + from_progress_cb = 0; } baton->progress_cb = from_progress_cb; baton->payloadReference = Persistent::New(args[1]); diff --git a/src/repo.cc b/src/repo.cc index 98e598050..c60013392 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -313,7 +313,7 @@ Handle GitRepo::Workdir(const Arguments& args) { Handle GitRepo::Odb(const Arguments& args) { HandleScope scope; - git_odb *out = NULL; + git_odb * out = 0; int result = git_repository_odb( &out @@ -621,7 +621,7 @@ Handle GitRepo::CreateCommit(const Arguments& args) { String::Utf8Value update_ref(args[0]->ToString()); from_update_ref = strdup(*update_ref); } else { - from_update_ref = NULL; + from_update_ref = 0; } baton->update_ref = from_update_ref; baton->authorReference = Persistent::New(args[1]); @@ -638,7 +638,7 @@ Handle GitRepo::CreateCommit(const Arguments& args) { String::Utf8Value message_encoding(args[3]->ToString()); from_message_encoding = strdup(*message_encoding); } else { - from_message_encoding = NULL; + from_message_encoding = 0; } baton->message_encoding = from_message_encoding; baton->messageReference = Persistent::New(args[4]); @@ -934,7 +934,7 @@ Handle GitRepo::CreateSymbolicReference(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number force is required."))); } - git_reference *out = NULL; + git_reference * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -988,7 +988,7 @@ Handle GitRepo::CreateReference(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number force is required."))); } - git_reference *out = NULL; + git_reference * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -1124,7 +1124,7 @@ void GitRepo::AddRemoteAfterWork(uv_work_t *req) { Handle GitRepo::CreateRevWalk(const Arguments& args) { HandleScope scope; - git_revwalk *out = NULL; + git_revwalk * out = 0; int result = git_revwalk_new( &out @@ -1157,7 +1157,7 @@ Handle GitRepo::GetSubmodule(const Arguments& args) { return ThrowException(Exception::Error(String::New("String name is required."))); } - git_submodule *submodule = NULL; + git_submodule * submodule = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -1203,7 +1203,7 @@ Handle GitRepo::AddSubmodule(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number use_gitlink is required."))); } - git_submodule *submodule = NULL; + git_submodule * submodule = 0; const char * from_url; String::Utf8Value url(args[0]->ToString()); from_url = strdup(*url); @@ -1800,7 +1800,7 @@ Handle GitRepo::GetReferences(const Arguments& args) { if (args[0]->IsUint32()) { from_list_flags = (unsigned int) args[0]->ToUint32()->Value(); } else { - from_list_flags = NULL; + from_list_flags = 0; } baton->list_flags = from_list_flags; baton->callback = Persistent::New(Local::Cast(args[1])); @@ -2160,7 +2160,7 @@ Handle GitRepo::Clone(const Arguments& args) { if (args[2]->IsObject()) { from_options = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); } else { - from_options = NULL; + from_options = 0; } baton->options = from_options; baton->callback = Persistent::New(Local::Cast(args[3])); @@ -2235,7 +2235,7 @@ Handle GitRepo::GetRemote(const Arguments& args) { return ThrowException(Exception::Error(String::New("String name is required."))); } - git_remote *out = NULL; + git_remote * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); diff --git a/src/signature.cc b/src/signature.cc index de0d84051..03ee935e5 100755 --- a/src/signature.cc +++ b/src/signature.cc @@ -88,7 +88,7 @@ Handle GitSignature::Create(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number offset is required."))); } - git_signature *out = NULL; + git_signature * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); @@ -140,7 +140,7 @@ Handle GitSignature::Now(const Arguments& args) { return ThrowException(Exception::Error(String::New("String email is required."))); } - git_signature *out = NULL; + git_signature * out = 0; const char * from_name; String::Utf8Value name(args[0]->ToString()); from_name = strdup(*name); diff --git a/src/tag.cc b/src/tag.cc index a0443dbb6..5d7ee92a8 100644 --- a/src/tag.cc +++ b/src/tag.cc @@ -271,7 +271,7 @@ Handle GitTag::Peel(const Arguments& args) { return ThrowException(Exception::Error(String::New("Tag tag is required."))); } - git_object *tag_target_out = NULL; + git_object * tag_target_out = 0; const git_tag * from_tag; from_tag = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); diff --git a/src/tree.cc b/src/tree.cc index 3e8eaa888..1ce6f5098 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -298,7 +298,7 @@ void GitTree::GetEntryAfterWork(uv_work_t *req) { Handle GitTree::Builder(const Arguments& args) { HandleScope scope; - git_treebuilder *out = NULL; + git_treebuilder * out = 0; int result = git_treebuilder_create( &out @@ -359,7 +359,7 @@ Handle GitTree::DiffTree(const Arguments& args) { if (args[2]->IsObject()) { from_opts = ObjectWrap::Unwrap(args[2]->ToObject())->GetValue(); } else { - from_opts = NULL; + from_opts = 0; } baton->opts = from_opts; baton->callback = Persistent::New(Local::Cast(args[3])); diff --git a/src/tree_builder.cc b/src/tree_builder.cc index 798f8098a..1fa52c5e9 100644 --- a/src/tree_builder.cc +++ b/src/tree_builder.cc @@ -81,12 +81,12 @@ git_treebuilder *GitTreeBuilder::GetValue() { Handle GitTreeBuilder::Create(const Arguments& args) { HandleScope scope; - git_treebuilder *out = NULL; + git_treebuilder * out = 0; const git_tree * from_source; if (args[0]->IsObject()) { from_source = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); } else { - from_source = NULL; + from_source = 0; } int result = git_treebuilder_create( @@ -195,7 +195,7 @@ Handle GitTreeBuilder::Insert(const Arguments& args) { return ThrowException(Exception::Error(String::New("Number filemode is required."))); } - const git_tree_entry *out = NULL; + const git_tree_entry * out = 0; const char * from_filename; String::Utf8Value filename(args[0]->ToString()); from_filename = strdup(*filename); diff --git a/src/wrapper.cc b/src/wrapper.cc index d513cb5ad..3849c37e1 100644 --- a/src/wrapper.cc +++ b/src/wrapper.cc @@ -4,6 +4,7 @@ #include #include #include +#include #include "../include/wrapper.h" #include "node_buffer.h" @@ -68,7 +69,7 @@ Handle Wrapper::ToBuffer(const Arguments& args) { Handle constructorArgs[1] = { Integer::New(len) }; Local nodeBuffer = bufferConstructor->NewInstance(1, constructorArgs); - memcpy(node::Buffer::Data(nodeBuffer), ObjectWrap::Unwrap(args.This())->GetValue(), len); + std::memcpy(node::Buffer::Data(nodeBuffer), ObjectWrap::Unwrap(args.This())->GetValue(), len); return scope.Close(nodeBuffer); } diff --git a/templates/class.cc.ejs b/templates/class.cc.ejs index 1ddc9d618..1fba50578 100644 --- a/templates/class.cc.ejs +++ b/templates/class.cc.ejs @@ -9,6 +9,19 @@ else return 'Object'; } + + function isPointer(cType) { + return /\s*\*\s*$/.test(cType); + } + + function unPointer(cType) { + return cType.replace(/\s*\*\s*$/,''); + } + + function defaultValue(cType) { + if (cType === 'git_otype') { return 'GIT_OBJ_ANY'; } + else { return '0'; } + } -%> /** * This code is auto-generated; unless you know what you're doing, do not modify! diff --git a/templates/convertFromV8.cc.ejs b/templates/convertFromV8.cc.ejs index 9d26d998f..58f238533 100644 --- a/templates/convertFromV8.cc.ejs +++ b/templates/convertFromV8.cc.ejs @@ -26,7 +26,7 @@ <% } -%> <% if (arg.isOptional) { -%> } else { - from_<%- arg.name %> = NULL; + from_<%- arg.name %> = 0; } <% } -%> <% } -%> \ No newline at end of file diff --git a/templates/syncFunction.cc.ejs b/templates/syncFunction.cc.ejs index 599fe4a49..a7c00aa05 100644 --- a/templates/syncFunction.cc.ejs +++ b/templates/syncFunction.cc.ejs @@ -11,9 +11,9 @@ Handle <%- cppClassName %>::<%- functionInfo.cppFunctionName %>(const Arg if (!arg.isReturn) continue; -%> <% if (arg.shouldAlloc) { -%> - <%- arg.cType %><%- arg.name %> = (<%- arg.cType %>)malloc(sizeof(<%- arg.cType.replace('*', '') %>)); + <%- arg.cType %><%- arg.name %> = (<%- arg.cType %>)malloc(sizeof(<%- unPointer(arg.cType) %>)); <% } else { -%> - <%- arg.cType.replace('*', '') %><%- arg.name %> = NULL; + <%- unPointer(arg.cType) %> <%- arg.name %> = <%- defaultValue(unPointer(arg.cType)) %>; <% } -%> <% } -%> <% diff --git a/v0.18.0.json b/v0.18.0.json index 8c781448c..932a3bf61 100644 --- a/v0.18.0.json +++ b/v0.18.0.json @@ -4858,6 +4858,7 @@ "args": [ { "name": "at_pos", + "isReturn": true, "cType": "size_t *", "cppClassName": "Uint32", "jsClassName": "Number", @@ -6779,6 +6780,7 @@ "args": [ { "name": "len_out", + "isReturn": true, "cType": "size_t *", "cppClassName": "Uint32", "jsClassName": "Number", @@ -6786,6 +6788,7 @@ }, { "name": "type_out", + "isReturn": true, "cType": "git_otype *", "cppClassName": "Int32", "jsClassName": "Number",