Skip to content

Instantly share code, notes, and snippets.

@piscisaureus piscisaureus/slab.patch Secret
Created Jan 9, 2012

Embed
What would you like to do?
From 119b27b26d0affd87018b3372db743486fe98d9e Mon Sep 17 00:00:00 2001
From: Bert Belder <bertbelder@gmail.com>
Date: Tue, 10 Jan 2012 00:34:53 +0100
Subject: [PATCH 1/1] slab
---
src/node_buffer.h | 1 +
src/stream_wrap.cc | 14 +++++++++-----
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/node_buffer.h b/src/node_buffer.h
index 3d1c2b2..ef7cf4f 100644
--- a/src/node_buffer.h
+++ b/src/node_buffer.h
@@ -65,6 +65,7 @@ namespace node {
class NODE_EXTERN Buffer: public ObjectWrap {
public:
+ static v8::Persistent<v8::FunctionTemplate> constructor_template;
static bool HasInstance(v8::Handle<v8::Value> val);
diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc
index a64b4c3..d7dcc66 100644
--- a/src/stream_wrap.cc
+++ b/src/stream_wrap.cc
@@ -153,13 +153,17 @@ Handle<Value> StreamWrap::ReadStop(const Arguments& args) {
}
-inline char* StreamWrap::NewSlab(Handle<Object> global,
- Handle<Object> wrap_obj) {
- Buffer* b = Buffer::New(SLAB_SIZE);
- global->SetHiddenValue(slab_sym, b->handle_);
+char* StreamWrap::NewSlab(Handle<Object> global,
+ Handle<Object> wrap_obj) {
+ HandleScope scope;
+ Local<Value> arg = Integer::NewFromUnsigned(SLAB_SIZE);
+ Local<Object> b = Buffer::constructor_template->GetFunction()->
+ NewInstance(1, &arg);
+ if (b.IsEmpty()) return NULL;
+ global->SetHiddenValue(slab_sym, b);
assert(Buffer::Length(b) == SLAB_SIZE);
slab_used = 0;
- wrap_obj->SetHiddenValue(slab_sym, b->handle_);
+ wrap_obj->SetHiddenValue(slab_sym, b);
return Buffer::Data(b);
}
--
1.7.6.msysgit.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.