Skip to content

Commit b5359e4

Browse files
committed
Warnings for new C++ buffer API
1 parent ae87007 commit b5359e4

2 files changed

Lines changed: 34 additions & 30 deletions

File tree

src/node_buffer.cc

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ char* Buffer::Data(Handle<Object> obj) {
101101

102102
// Return true for "SlowBuffer"
103103
if (constructor_template->HasInstance(obj)) {
104-
return ObjectWrap::Unwrap<Buffer>(obj)->data();
104+
return ObjectWrap::Unwrap<Buffer>(obj)->data_;
105105
}
106106

107107
// Not a buffer.
@@ -118,7 +118,7 @@ size_t Buffer::Length(Handle<Object> obj) {
118118

119119
// Return true for "SlowBuffer"
120120
if (constructor_template->HasInstance(obj)) {
121-
return ObjectWrap::Unwrap<Buffer>(obj)->length();
121+
return ObjectWrap::Unwrap<Buffer>(obj)->length_;
122122
}
123123

124124
// Not a buffer.
@@ -144,9 +144,9 @@ Handle<Value> Buffer::New(const Arguments &args) {
144144
}
145145

146146
buffer->Wrap(args.This());
147-
args.This()->SetIndexedPropertiesToExternalArrayData(buffer->data(),
147+
args.This()->SetIndexedPropertiesToExternalArrayData(buffer->data_,
148148
kExternalUnsignedByteArray,
149-
buffer->length());
149+
buffer->length_);
150150
args.This()->Set(length_symbol, Integer::New(buffer->length_));
151151

152152
return args.This();
@@ -169,17 +169,12 @@ Buffer::~Buffer() {
169169
}
170170

171171

172-
char* Buffer::data() {
173-
return data_;
174-
}
175-
176-
177172
Handle<Value> Buffer::BinarySlice(const Arguments &args) {
178173
HandleScope scope;
179174
Buffer *parent = ObjectWrap::Unwrap<Buffer>(args.This());
180175
SLICE_ARGS(args[0], args[1])
181176

182-
char *data = parent->data() + start;
177+
char *data = parent->data_ + start;
183178
//Local<String> string = String::New(data, end - start);
184179

185180
Local<Value> b = Encode(data, end - start, BINARY);
@@ -193,7 +188,7 @@ Handle<Value> Buffer::AsciiSlice(const Arguments &args) {
193188
Buffer *parent = ObjectWrap::Unwrap<Buffer>(args.This());
194189
SLICE_ARGS(args[0], args[1])
195190

196-
char* data = parent->data() + start;
191+
char* data = parent->data_ + start;
197192
Local<String> string = String::New(data, end - start);
198193

199194
return scope.Close(string);
@@ -204,7 +199,7 @@ Handle<Value> Buffer::Utf8Slice(const Arguments &args) {
204199
HandleScope scope;
205200
Buffer *parent = ObjectWrap::Unwrap<Buffer>(args.This());
206201
SLICE_ARGS(args[0], args[1])
207-
char *data = parent->data() + start;
202+
char *data = parent->data_ + start;
208203
Local<String> string = String::New(data, end - start);
209204
return scope.Close(string);
210205
}
@@ -240,10 +235,10 @@ Handle<Value> Buffer::Base64Slice(const Arguments &args) {
240235
bool b1_oob, b2_oob;
241236

242237
while (i < end) {
243-
bitbuf[0] = parent->data()[i++];
238+
bitbuf[0] = parent->data_[i++];
244239

245240
if (i < end) {
246-
bitbuf[1] = parent->data()[i];
241+
bitbuf[1] = parent->data_[i];
247242
b1_oob = false;
248243
} else {
249244
bitbuf[1] = 0;
@@ -252,7 +247,7 @@ Handle<Value> Buffer::Base64Slice(const Arguments &args) {
252247
i++;
253248

254249
if (i < end) {
255-
bitbuf[2] = parent->data()[i];
250+
bitbuf[2] = parent->data_[i];
256251
b2_oob = false;
257252
} else {
258253
bitbuf[2] = 0;
@@ -312,7 +307,7 @@ Handle<Value> Buffer::Copy(const Arguments &args) {
312307
ssize_t target_start = args[1]->Int32Value();
313308
ssize_t source_start = args[2]->Int32Value();
314309
ssize_t source_end = args[3]->IsInt32() ? args[3]->Int32Value()
315-
: source->length();
310+
: source->length_;
316311

317312
if (source_end < source_start) {
318313
return ThrowException(Exception::Error(String::New(
@@ -324,29 +319,29 @@ Handle<Value> Buffer::Copy(const Arguments &args) {
324319
return scope.Close(Integer::New(0));
325320
}
326321

327-
if (target_start < 0 || target_start >= target->length()) {
322+
if (target_start < 0 || target_start >= target->length_) {
328323
return ThrowException(Exception::Error(String::New(
329324
"targetStart out of bounds")));
330325
}
331326

332-
if (source_start < 0 || source_start >= source->length()) {
327+
if (source_start < 0 || source_start >= source->length_) {
333328
return ThrowException(Exception::Error(String::New(
334329
"sourceStart out of bounds")));
335330
}
336331

337-
if (source_end < 0 || source_end > source->length()) {
332+
if (source_end < 0 || source_end > source->length_) {
338333
return ThrowException(Exception::Error(String::New(
339334
"sourceEnd out of bounds")));
340335
}
341336

342337
ssize_t to_copy = MIN(MIN(source_end - source_start,
343-
target->length() - target_start),
344-
source->length() - source_start);
338+
target->length_ - target_start),
339+
source->length_ - source_start);
345340

346341

347342
// need to use slightly slower memmove is the ranges might overlap
348-
memmove((void*)(target->data() + target_start),
349-
(const void*)(source->data() + source_start),
343+
memmove((void*)(target->data_ + target_start),
344+
(const void*)(source->data_ + source_start),
350345
to_copy);
351346

352347
return scope.Close(Integer::New(to_copy));
@@ -376,7 +371,7 @@ Handle<Value> Buffer::Utf8Write(const Arguments &args) {
376371
: args[2]->Uint32Value();
377372
max_length = MIN(buffer->length_ - offset, max_length);
378373

379-
char* p = buffer->data() + offset;
374+
char* p = buffer->data_ + offset;
380375

381376
int char_written;
382377

@@ -418,7 +413,7 @@ Handle<Value> Buffer::AsciiWrite(const Arguments &args) {
418413
: args[2]->Uint32Value();
419414
max_length = MIN(s->Length(), MIN(buffer->length_ - offset, max_length));
420415

421-
char *p = buffer->data() + offset;
416+
char *p = buffer->data_ + offset;
422417

423418
int written = s->WriteAscii(p,
424419
0,
@@ -466,7 +461,7 @@ Handle<Value> Buffer::Base64Write(const Arguments &args) {
466461
}
467462

468463
char a, b, c, d;
469-
char* dst = buffer->data() + offset;
464+
char* dst = buffer->data_ + offset;
470465
const char *src = *s;
471466
const char *const srcEnd = src + s.length();
472467

@@ -511,7 +506,7 @@ Handle<Value> Buffer::BinaryWrite(const Arguments &args) {
511506
"Offset is out of bounds")));
512507
}
513508

514-
char *p = (char*)buffer->data() + offset;
509+
char *p = (char*)buffer->data_ + offset;
515510

516511
size_t towrite = MIN((unsigned long) s->Length(), buffer->length_ - offset);
517512

@@ -544,7 +539,7 @@ Handle<Value> Buffer::MakeFastBuffer(const Arguments &args) {
544539
uint32_t offset = args[2]->Uint32Value();
545540
uint32_t length = args[3]->Uint32Value();
546541

547-
fast_buffer->SetIndexedPropertiesToPixelData((uint8_t*)buffer->data() + offset,
542+
fast_buffer->SetIndexedPropertiesToPixelData((uint8_t*)buffer->data_ + offset,
548543
length);
549544

550545
return Undefined();

src/node_buffer.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <node.h>
55
#include <node_object_wrap.h>
66
#include <v8.h>
7+
#include <assert.h>
78

89
namespace node {
910

@@ -39,8 +40,16 @@ class Buffer : public ObjectWrap {
3940
static char* Data(v8::Handle<v8::Object>);
4041
static size_t Length(v8::Handle<v8::Object>);
4142

42-
char* data();
43-
size_t length() const { return length_; }
43+
char* data() {
44+
assert(0 && "v0.3 API change: Use node::Buffer::Data().");
45+
return NULL;
46+
}
47+
48+
49+
size_t length() const {
50+
assert(0 && "v0.3 API change: Use node::Buffer::Length().");
51+
return 0;
52+
}
4453

4554
int AsciiWrite(char *string, int offset, int length);
4655
int Utf8Write(char *string, int offset, int length);

0 commit comments

Comments
 (0)