Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
buffer: update constructor prototype
Browse files Browse the repository at this point in the history
Change Buffer::New(char*, size_t) to Buffer::New(const char*, size_t).
  • Loading branch information
langpavel authored and bnoordhuis committed Sep 13, 2012
1 parent bec863b commit 7ab4a77
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/node_buffer.cc
Expand Up @@ -137,14 +137,14 @@ Buffer* Buffer::New(size_t length) {
}


Buffer* Buffer::New(char* data, size_t length) {
Buffer* Buffer::New(const char* data, size_t length) {
HandleScope scope;

Local<Value> arg = Integer::NewFromUnsigned(0);
Local<Object> obj = constructor_template->GetFunction()->NewInstance(1, &arg);

Buffer *buffer = ObjectWrap::Unwrap<Buffer>(obj);
buffer->Replace(data, length, NULL, NULL);
buffer->Replace(const_cast<char*>(data), length, NULL, NULL);

return buffer;
}
Expand Down Expand Up @@ -198,6 +198,8 @@ Buffer::~Buffer() {
}


// if replace doesn't have a callback, data must be copied
// const_cast in Buffer::New requires this
void Buffer::Replace(char *data, size_t length,
free_callback callback, void *hint) {
HandleScope scope;
Expand Down
10 changes: 7 additions & 3 deletions src/node_buffer.h
Expand Up @@ -102,10 +102,14 @@ class NODE_EXTERN Buffer: public ObjectWrap {
static v8::Handle<v8::Object> New(v8::Handle<v8::String> string);

static void Initialize(v8::Handle<v8::Object> target);
static Buffer* New(size_t length); // public constructor
static Buffer* New(char *data, size_t len); // public constructor

// public constructor
static Buffer* New(size_t length);
// public constructor - data is copied
static Buffer* New(const char *data, size_t len);
// public constructor
static Buffer* New(char *data, size_t length,
free_callback callback, void *hint); // public constructor
free_callback callback, void *hint);

private:
static v8::Handle<v8::Value> New(const v8::Arguments &args);
Expand Down

0 comments on commit 7ab4a77

Please sign in to comment.