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

Commit

Permalink
Merge branch 'v0.6'
Browse files Browse the repository at this point in the history
Conflicts:
	src/handle_wrap.cc
	src/node_zlib.cc
	src/process_wrap.cc
  • Loading branch information
indutny committed Jan 11, 2012
2 parents 8abb73e + 07701e7 commit 9e6957b
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -177,7 +177,7 @@ bench-idle:
./node benchmark/idle_clients.js &

jslint:
PYTHONPATH=tools/closure_linter/ $(PYTHON) tools/closure_linter/closure_linter/gjslint.py --unix_mode --strict --nojsdoc -r lib/ -r src/ -r test/
PYTHONPATH=tools/closure_linter/ $(PYTHON) tools/closure_linter/closure_linter/gjslint.py --unix_mode --strict --nojsdoc -r lib/ -r src/ -r test/ --exclude_files lib/punycode.js

cpplint:
@$(PYTHON) tools/cpplint.py $(wildcard src/*.cc src/*.h src/*.c)
Expand Down
Binary file removed doc/full-white-stripe.bmp
Binary file not shown.
Binary file added doc/full-white-stripe.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/thin-white-stripe.bmp
Binary file not shown.
Binary file added doc/thin-white-stripe.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/handle_wrap.cc
Expand Up @@ -100,8 +100,11 @@ Handle<Value> HandleWrap::Close(const Arguments& args) {

UNWRAP

// guard against uninitialized handle or double close
if (wrap->handle__ == NULL) return v8::Null();
assert(!wrap->object_.IsEmpty());
uv_close(wrap->handle__, OnClose);
wrap->handle__ = NULL;

HandleWrap::Ref(args);

Expand Down Expand Up @@ -143,6 +146,9 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
// The wrap object should still be there.
assert(wrap->object_.IsEmpty() == false);

// But the handle pointer should be gone.
assert(wrap->handle__ == NULL);

wrap->object_->SetPointerInInternalField(0, NULL);
wrap->object_.Dispose();
wrap->object_.Clear();
Expand Down
80 changes: 34 additions & 46 deletions src/node_zlib.cc
Expand Up @@ -29,9 +29,6 @@

#include <node.h>
#include <node_buffer.h>
#include <node_vars.h>
#include <req_wrap.h>

#include <node_vars.h>
// We do the following to minimize the detal between v0.6 branch. We want to
// use the variables as they were being used before.
Expand All @@ -41,8 +38,6 @@
namespace node {
using namespace v8;

// write() returns one of these, and then calls the cb() when it's done.
typedef ReqWrap<uv_work_t> WorkReqWrap;

enum node_zlib_mode {
DEFLATE = 1,
Expand Down Expand Up @@ -81,14 +76,16 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
}

// write(flush, in, in_off, in_len, out, out_off, out_len)
static Handle<Value>
Write(const Arguments& args) {
static Handle<Value> Write(const Arguments& args) {
HandleScope scope;
assert(args.Length() == 7);

ZCtx<mode> *ctx = ObjectWrap::Unwrap< ZCtx<mode> >(args.This());
assert(ctx->init_done_ && "write before init");

assert(!ctx->write_in_progress_ && "write already in progress");
ctx->write_in_progress_ = true;

unsigned int flush = args[0]->Uint32Value();
Bytef *in;
Bytef *out;
Expand All @@ -104,55 +101,49 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
assert(Buffer::HasInstance(args[1]));
Local<Object> in_buf;
in_buf = args[1]->ToObject();
in_off = (size_t)args[2]->Uint32Value();
in_len = (size_t)args[3]->Uint32Value();
in_off = args[2]->Uint32Value();
in_len = args[3]->Uint32Value();

assert(in_off + in_len <= Buffer::Length(in_buf));
in = reinterpret_cast<Bytef *>(Buffer::Data(in_buf) + in_off);
}

assert(Buffer::HasInstance(args[4]));
Local<Object> out_buf = args[4]->ToObject();
out_off = (size_t)args[5]->Uint32Value();
out_len = (size_t)args[6]->Uint32Value();
out_off = args[5]->Uint32Value();
out_len = args[6]->Uint32Value();
assert(out_off + out_len <= Buffer::Length(out_buf));
out = reinterpret_cast<Bytef *>(Buffer::Data(out_buf) + out_off);

WorkReqWrap *req_wrap = new WorkReqWrap();
// build up the work request
uv_work_t* work_req = &(ctx->work_req_);

req_wrap->data_ = ctx;
ctx->strm_.avail_in = in_len;
ctx->strm_.next_in = &(*in);
ctx->strm_.next_in = in;
ctx->strm_.avail_out = out_len;
ctx->strm_.next_out = out;
ctx->flush_ = flush;

// set this so that later on, I can easily tell how much was written.
ctx->chunk_size_ = out_len;

// build up the work request
uv_work_t* work_req = new uv_work_t();
work_req->data = req_wrap;

uv_queue_work(Loop(),
work_req,
ZCtx<mode>::Process,
ZCtx<mode>::After);

req_wrap->Dispatched();
ctx->Ref();

return req_wrap->object_;
return ctx->handle_;
}


// thread pool!
// This function may be called multiple times on the uv_work pool
// for a single write() call, until all of the input bytes have
// been consumed.
static void
Process(uv_work_t* work_req) {
WorkReqWrap *req_wrap = reinterpret_cast<WorkReqWrap *>(work_req->data);
ZCtx<mode> *ctx = (ZCtx<mode> *)req_wrap->data_;
static void Process(uv_work_t* work_req) {
ZCtx<mode> *ctx = container_of(work_req, ZCtx<mode>, work_req_);

// If the avail_out is left at 0, then it means that it ran out
// of room. If there was avail_out left over, then it means
Expand All @@ -162,13 +153,13 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
case DEFLATE:
case GZIP:
case DEFLATERAW:
err = deflate(&(ctx->strm_), ctx->flush_);
err = deflate(&ctx->strm_, ctx->flush_);
break;
case UNZIP:
case INFLATE:
case GUNZIP:
case INFLATERAW:
err = inflate(&(ctx->strm_), ctx->flush_);
err = inflate(&ctx->strm_, ctx->flush_);

// If data was encoded with dictionary
if (err == Z_NEED_DICT) {
Expand Down Expand Up @@ -197,35 +188,33 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
}

// v8 land!
static void
After(uv_work_t* work_req) {
static void After(uv_work_t* work_req) {
HandleScope scope;
WorkReqWrap *req_wrap = reinterpret_cast<WorkReqWrap *>(work_req->data);
ZCtx<mode> *ctx = (ZCtx<mode> *)req_wrap->data_;
ZCtx<mode> *ctx = container_of(work_req, ZCtx<mode>, work_req_);

Local<Integer> avail_out = Integer::New(ctx->strm_.avail_out);
Local<Integer> avail_in = Integer::New(ctx->strm_.avail_in);

ctx->write_in_progress_ = false;

// call the write() cb
assert(req_wrap->object_->Get(callback_sym)->IsFunction() &&
assert(ctx->handle_->Get(callback_sym)->IsFunction() &&
"Invalid callback");
Local<Value> args[2] = { avail_in, avail_out };
MakeCallback(req_wrap->object_, "callback", 2, args);
MakeCallback(ctx->handle_, "callback", 2, args);

// delete the ReqWrap
delete req_wrap;
ctx->Unref();
}

static Handle<Value>
New(const Arguments& args) {
static Handle<Value> New(const Arguments& args) {
HandleScope scope;
ZCtx<mode> *ctx = new ZCtx<mode>();
ctx->Wrap(args.This());
return args.This();
}

// just pull the ints out of the args and call the other Init
static Handle<Value>
Init(const Arguments& args) {
static Handle<Value> Init(const Arguments& args) {
HandleScope scope;

assert((args.Length() == 4 || args.Length() == 5) &&
Expand Down Expand Up @@ -265,14 +254,8 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
return Undefined();
}

static void
Init(ZCtx *ctx,
int level,
int windowBits,
int memLevel,
int strategy,
char* dictionary,
size_t dictionary_len) {
static void Init(ZCtx *ctx, int level, int windowBits, int memLevel,
int strategy, char* dictionary, size_t dictionary_len) {
ctx->level_ = level;
ctx->windowBits_ = windowBits;
ctx->memLevel_ = memLevel;
Expand Down Expand Up @@ -340,6 +323,7 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
assert(err == Z_OK && "Failed to set dictionary");
}

ctx->write_in_progress_ = false;
ctx->init_done_ = true;
}

Expand All @@ -359,6 +343,10 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
int flush_;

int chunk_size_;

bool write_in_progress_;

uv_work_t work_req_;
};


Expand Down
14 changes: 8 additions & 6 deletions src/process_wrap.cc
Expand Up @@ -178,10 +178,14 @@ class ProcessWrap : public HandleWrap {

int r = uv_spawn(Loop(), &wrap->process_, options);

wrap->SetHandle((uv_handle_t*)&wrap->process_);
assert(wrap->process_.data == wrap);

wrap->object_->Set(String::New("pid"), Integer::New(wrap->process_.pid));
if (r) {
SetErrno(uv_last_error(Loop()));
}
else {
wrap->SetHandle((uv_handle_t*)&wrap->process_);
assert(wrap->process_.data == wrap);
wrap->object_->Set(String::New("pid"), Integer::New(wrap->process_.pid));
}

if (options.args) {
for (int i = 0; options.args[i]; i++) free(options.args[i]);
Expand All @@ -196,8 +200,6 @@ class ProcessWrap : public HandleWrap {
delete [] options.env;
}

if (r) SetErrno(uv_last_error(Loop()));

return scope.Close(Integer::New(r));
}

Expand Down
15 changes: 10 additions & 5 deletions src/stream_wrap.cc
Expand Up @@ -35,6 +35,7 @@
#define slab_sym NODE_VAR(slab_sym)
#define handle_that_last_alloced NODE_VAR(handle_that_last_alloced)
#define buffer_sym NODE_VAR(buffer_sym)
#define buffer_constructor_template NODE_VAR(buffer_constructor_template)
#define write_queue_size_sym NODE_VAR(write_queue_size_sym)
#define stream_wrap_initialized NODE_VAR(stream_wrap_initialized)

Expand Down Expand Up @@ -153,13 +154,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);
}

Expand Down
4 changes: 2 additions & 2 deletions tools/msvs/msi/product.wxs
Expand Up @@ -114,8 +114,8 @@
</UI>

<UIRef Id="WixUI_Common" />
<WixVariable Id="WixUIBannerBmp" Value="..\..\..\doc\thin-white-stripe.bmp" />
<WixVariable Id="WixUIDialogBmp" Value="..\..\..\doc\full-white-stripe.bmp" />
<WixVariable Id="WixUIBannerBmp" Value="..\..\..\doc\thin-white-stripe.jpg" />
<WixVariable Id="WixUIDialogBmp" Value="..\..\..\doc\full-white-stripe.jpg" />
</Product>

</Wix>

0 comments on commit 9e6957b

Please sign in to comment.