diff options
author | Pavel Lang <langpavel@phpskelet.org> | 2012-09-13 08:31:50 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-09-13 16:31:04 +0200 |
commit | 7ab4a77d6fdb2b98b3c34fda9d001ed9d91297c7 (patch) | |
tree | 36fca8570400cde2450814a42b12b5a515f5dbbc /src | |
parent | bec863b7de8ab45cf599372b16274fa526bd86a0 (diff) | |
download | node-7ab4a77d6fdb2b98b3c34fda9d001ed9d91297c7.tar.gz |
buffer: update constructor prototype
Change Buffer::New(char*, size_t) to Buffer::New(const char*, size_t).
Diffstat (limited to 'src')
-rw-r--r-- | src/node_buffer.cc | 6 | ||||
-rw-r--r-- | src/node_buffer.h | 10 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc index e80611f87..11829dfa0 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -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; } @@ -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; diff --git a/src/node_buffer.h b/src/node_buffer.h index a092faa75..137a6cfb4 100644 --- a/src/node_buffer.h +++ b/src/node_buffer.h @@ -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); |