Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions generate/templates/manual/include/str_array_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class StrArrayConverter {
private:
static git_strarray *ConvertArray(Array *val);
static git_strarray *ConvertString(Handle<String> val);
static git_strarray *AllocStrArray(const size_t count);
static git_strarray *ConstructStrArray(int argc, char** argv);
};

Expand Down
17 changes: 11 additions & 6 deletions generate/templates/manual/src/str_array_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ git_strarray *StrArrayConverter::Convert(Handle<v8::Value> val) {
}
}

static git_strarray * StrArrayConverter::AllocStrArray(const size_t count) {
const size_t size = sizeof(git_strarray) + (sizeof(char*) * count);
uint8_t* memory = reinterpret_cast<uint8_t*>(malloc(size));
git_strarray *result = reinterpret_cast<git_strarray *>(memory);
result->count = count;
result->strings = reinterpret_cast<char**>(memory + sizeof(git_strarray));
return result;
}

git_strarray *StrArrayConverter::ConvertArray(Array *val) {
git_strarray *result = (git_strarray *)malloc(sizeof(git_strarray*));
result->count = val->Length();
result->strings = (char **)malloc(sizeof(char*) * result->count);
git_strarray *result = AllocStrArray(val->Length());

for(size_t i = 0; i < result->count; i++) {
NanUtf8String entry(val->Get(i));
Expand All @@ -47,9 +54,7 @@ git_strarray* StrArrayConverter::ConvertString(Handle<String> val) {
}

git_strarray *StrArrayConverter::ConstructStrArray(int argc, char** argv) {
git_strarray *result = (git_strarray *)malloc(sizeof(git_strarray*));
result->count = argc;
result->strings = (char **)malloc(sizeof(char*) * result->count);
git_strarray *result = AllocStrArray(argc);

for(size_t i = 0; i < result->count; i++) {
result->strings[i] = strdup(argv[i]);
Expand Down