diff --git a/libdeno/binding.cc b/libdeno/binding.cc index 55a78069e8..c5f582aaee 100644 --- a/libdeno/binding.cc +++ b/libdeno/binding.cc @@ -243,7 +243,7 @@ void Send(const v8::FunctionCallbackInfo& args) { DCHECK_EQ(d->currentArgs, nullptr); d->currentArgs = &args; - d->cb(d, req_id, control, data); + d->cb(d->user_data, req_id, control, data); if (d->currentArgs == nullptr) { // This indicates that deno_repond() was called already. @@ -431,11 +431,6 @@ void deno_init() { v8::V8::Initialize(); } -void* deno_get_data(const Deno* d) { - CHECK(d->user_data != nullptr); - return d->user_data; -} - const char* deno_v8_version() { return v8::V8::GetVersion(); } void deno_set_v8_flags(int* argc, char** argv) { diff --git a/libdeno/deno.h b/libdeno/deno.h index c166c7fde2..5fad6a1c32 100644 --- a/libdeno/deno.h +++ b/libdeno/deno.h @@ -23,8 +23,8 @@ typedef struct deno_s Deno; // A callback to receive a message from a libdeno.send() javascript call. // control_buf is valid for only for the lifetime of this callback. // data_buf is valid until deno_respond() is called. -typedef void (*deno_recv_cb)(Deno* d, int32_t req_id, deno_buf control_buf, - deno_buf data_buf); +typedef void (*deno_recv_cb)(void* user_data, int32_t req_id, + deno_buf control_buf, deno_buf data_buf); void deno_init(); const char* deno_v8_version(); @@ -33,9 +33,6 @@ void deno_set_v8_flags(int* argc, char** argv); Deno* deno_new(deno_recv_cb cb); void deno_delete(Deno* d); -// Returns the void* user_data provided in deno_new. -void* deno_get_data(Deno*); - // Returns false on error. // Get error text with deno_last_exception(). // 0 = fail, 1 = success diff --git a/libdeno/libdeno_test.cc b/libdeno/libdeno_test.cc index 2748a60cce..e46c629786 100644 --- a/libdeno/libdeno_test.cc +++ b/libdeno/libdeno_test.cc @@ -69,16 +69,17 @@ TEST(LibDenoTest, RecvReturnEmpty) { TEST(LibDenoTest, RecvReturnBar) { static int count = 0; - Deno* d = deno_new([](auto deno, int req_id, auto buf, auto data_buf) { + Deno* d = deno_new([](auto user_data, int req_id, auto buf, auto data_buf) { + auto d = reinterpret_cast(user_data); assert_null(data_buf); count++; EXPECT_EQ(static_cast(3), buf.data_len); EXPECT_EQ(buf.data_ptr[0], 'a'); EXPECT_EQ(buf.data_ptr[1], 'b'); EXPECT_EQ(buf.data_ptr[2], 'c'); - deno_respond(deno, nullptr, req_id, strbuf("bar")); + deno_respond(d, user_data, req_id, strbuf("bar")); }); - EXPECT_TRUE(deno_execute(d, nullptr, "a.js", "RecvReturnBar()")); + EXPECT_TRUE(deno_execute(d, d, "a.js", "RecvReturnBar()")); EXPECT_EQ(count, 1); deno_delete(d); } @@ -91,7 +92,8 @@ TEST(LibDenoTest, DoubleRecvFails) { TEST(LibDenoTest, SendRecvSlice) { static int count = 0; - Deno* d = deno_new([](auto deno, int req_id, auto buf, auto data_buf) { + Deno* d = deno_new([](auto user_data, int req_id, auto buf, auto data_buf) { + auto d = reinterpret_cast(user_data); assert_null(data_buf); static const size_t alloc_len = 1024; size_t i = count++; @@ -115,9 +117,9 @@ TEST(LibDenoTest, SendRecvSlice) { buf2.data_ptr[0] = 200 + i; buf2.data_ptr[buf2.data_len - 1] = 200 - i; // Send back. - deno_respond(deno, nullptr, req_id, buf2); + deno_respond(d, user_data, req_id, buf2); }); - EXPECT_TRUE(deno_execute(d, nullptr, "a.js", "SendRecvSlice()")); + EXPECT_TRUE(deno_execute(d, d, "a.js", "SendRecvSlice()")); EXPECT_EQ(count, 5); deno_delete(d); } diff --git a/src/isolate.rs b/src/isolate.rs index 8f8e798fb1..dc44b11e2c 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -100,8 +100,8 @@ impl Isolate { self as *mut _ as *mut c_void } - pub fn from_c<'a>(d: *const libdeno::isolate) -> &'a mut Isolate { - let ptr = unsafe { libdeno::deno_get_data(d) } as *mut _; + pub fn from_void_ptr<'a>(ptr: *mut c_void) -> &'a mut Isolate { + let ptr = ptr as *mut _; unsafe { &mut *ptr } } @@ -236,7 +236,7 @@ impl From for libdeno::deno_buf { // Dereferences the C pointer into the Rust Isolate object. extern "C" fn pre_dispatch( - d: *const libdeno::isolate, + user_data: *mut c_void, req_id: i32, control_buf: libdeno::deno_buf, data_buf: libdeno::deno_buf, @@ -256,7 +256,7 @@ extern "C" fn pre_dispatch( ) }; - let isolate = Isolate::from_c(d); + let isolate = Isolate::from_void_ptr(user_data); let dispatch = isolate.dispatch; let (is_sync, op) = dispatch(isolate, control_slice, data_slice); diff --git a/src/libdeno.rs b/src/libdeno.rs index 77f7f5c3ef..4417ac5448 100644 --- a/src/libdeno.rs +++ b/src/libdeno.rs @@ -20,7 +20,7 @@ pub struct deno_buf { } type DenoRecvCb = unsafe extern "C" fn( - d: *const isolate, + user_data: *mut c_void, req_id: i32, buf: deno_buf, data_buf: deno_buf, @@ -33,7 +33,6 @@ extern "C" { pub fn deno_new(cb: DenoRecvCb) -> *const isolate; pub fn deno_delete(i: *const isolate); pub fn deno_last_exception(i: *const isolate) -> *const c_char; - pub fn deno_get_data(i: *const isolate) -> *mut c_void; pub fn deno_respond( i: *const isolate, user_data: *mut c_void,