From 609fa0de039f4285c402ac3f646fcd5d4828d3aa Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 29 Apr 2015 19:57:41 +0200 Subject: [PATCH 1/3] src: fix NODE_DEPRECATED macro The NODE_DEPRECATED macro was piggybacking on the V8_DEPRECATED macro but that macro is silent unless V8_DEPRECATION_WARNINGS is defined, something io.js doesn't do. Ergo, no deprecation notices were being issued. PR-URL: https://github.com/iojs/io.js/pull/1565 Reviewed-By: Trevor Norris --- src/node.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/node.h b/src/node.h index 28b40aa0721b3a..5962c32d5b46ab 100644 --- a/src/node.h +++ b/src/node.h @@ -42,7 +42,16 @@ #include "v8.h" // NOLINT(build/include_order) #include "node_version.h" // NODE_MODULE_VERSION -#define NODE_DEPRECATED(msg, fn) V8_DEPRECATED(msg, fn) +#if defined(__GNUC__) +# define NODE_DEPRECATED(message, declarator) \ + __attribute__((deprecated(message))) declarator +#elif defined(_MSC_VER) +# define NODE_DEPRECATED(message, declarator) \ + __declspec(deprecated) declarator +#else +# define NODE_DEPRECATED(message, declarator) \ + declarator +#endif // Forward-declare libuv loop struct uv_loop_s; From ccb199af1770ae5ee190c8f6752469931df9a51e Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 29 Apr 2015 20:03:15 +0200 Subject: [PATCH 2/3] src: fix deprecation warnings The previous commit enables deprecation warnings, this commit fixes the handful of offending sites where the isolate was not explicitly being passed around. PR-URL: https://github.com/iojs/io.js/pull/1565 Reviewed-By: Trevor Norris --- src/node_buffer.cc | 2 +- src/node_crypto.cc | 2 +- src/spawn_sync.cc | 6 +++--- src/spawn_sync.h | 2 +- src/util.cc | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 61b80c622a809e..a0618675872aac 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -98,7 +98,7 @@ Local New(Isolate* isolate, Handle string, enum encoding enc) { size_t length = StringBytes::Size(isolate, string, enc); - Local buf = New(length); + Local buf = New(isolate, length); char* data = Buffer::Data(buf); StringBytes::Write(isolate, data, length, string, enc); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index b6cb4f10e5698f..04b50361bab264 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4593,7 +4593,7 @@ void RandomBytesCheck(RandomBytesRequest* req, Local argv[2]) { size_t size; req->return_memory(&data, &size); argv[0] = Null(req->env()->isolate()); - argv[1] = Buffer::Use(data, size); + argv[1] = Buffer::Use(req->env()->isolate(), data, size); } } diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index b014bae40dffc9..901a4a001df051 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -165,9 +165,9 @@ void SyncProcessStdioPipe::Close() { } -Local SyncProcessStdioPipe::GetOutputAsBuffer() const { +Local SyncProcessStdioPipe::GetOutputAsBuffer(Isolate* isolate) const { size_t length = OutputLength(); - Local js_buffer = Buffer::New(length); + Local js_buffer = Buffer::New(isolate, length); CopyOutput(Buffer::Data(js_buffer)); return js_buffer; } @@ -679,7 +679,7 @@ Local SyncProcessRunner::BuildOutputArray() { for (uint32_t i = 0; i < stdio_count_; i++) { SyncProcessStdioPipe* h = stdio_pipes_[i]; if (h != nullptr && h->writable()) - js_output->Set(i, h->GetOutputAsBuffer()); + js_output->Set(i, h->GetOutputAsBuffer(env()->isolate())); else js_output->Set(i, Null(env()->isolate())); } diff --git a/src/spawn_sync.h b/src/spawn_sync.h index 4a71b75202b5b2..9a544fa0576402 100644 --- a/src/spawn_sync.h +++ b/src/spawn_sync.h @@ -72,7 +72,7 @@ class SyncProcessStdioPipe { int Start(); void Close(); - Local GetOutputAsBuffer() const; + Local GetOutputAsBuffer(Isolate* isolate) const; inline bool readable() const; inline bool writable() const; diff --git a/src/util.cc b/src/util.cc index f382b3d565a8cf..a793368c2cdfa8 100644 --- a/src/util.cc +++ b/src/util.cc @@ -13,7 +13,7 @@ Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Handle value) return; // Allocate enough space to include the null terminator - size_t len = StringBytes::StorageSize(string, UTF8) + 1; + size_t len = StringBytes::StorageSize(isolate, string, UTF8) + 1; if (len > sizeof(str_st_)) { str_ = static_cast(malloc(len)); CHECK_NE(str_, nullptr); From 73062521a424614fccfe6399b47030ee065e1977 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 29 Apr 2015 19:04:59 +0100 Subject: [PATCH 3/3] src: deprecate smalloc public functions Upcoming V8 changes will make it impossible to keep supporting the smalloc functionality so deprecate the functions in smalloc.h now and tell people to switch to typed arrays. This commit shuffles code around in smalloc.cc to avoid generating the deprecation warnings when building io.js itself. PR-URL: https://github.com/iojs/io.js/pull/1565 Reviewed-By: Trevor Norris --- src/smalloc.cc | 67 +++++++++++++++++++++++--------------------- src/smalloc.h | 75 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 81 insertions(+), 61 deletions(-) diff --git a/src/smalloc.cc b/src/smalloc.cc index 1ac92ecb76bbfe..afddc7991a07ce 100644 --- a/src/smalloc.cc +++ b/src/smalloc.cc @@ -129,12 +129,37 @@ void CallbackInfo::WeakCallback( } +inline size_t InternalExternalArraySize(enum ExternalArrayType type) { + switch (type) { + case v8::kExternalUint8Array: + return sizeof(uint8_t); + case v8::kExternalInt8Array: + return sizeof(int8_t); + case v8::kExternalInt16Array: + return sizeof(int16_t); + case v8::kExternalUint16Array: + return sizeof(uint16_t); + case v8::kExternalInt32Array: + return sizeof(int32_t); + case v8::kExternalUint32Array: + return sizeof(uint32_t); + case v8::kExternalFloat32Array: + return sizeof(float); // NOLINT(runtime/sizeof) + case v8::kExternalFloat64Array: + return sizeof(double); // NOLINT(runtime/sizeof) + case v8::kExternalUint8ClampedArray: + return sizeof(uint8_t); + } + return 0; +} + + void CallbackInfo::WeakCallback(Isolate* isolate, Local object) { void* array_data = object->GetIndexedPropertiesExternalArrayData(); size_t array_length = object->GetIndexedPropertiesExternalArrayDataLength(); enum ExternalArrayType array_type = object->GetIndexedPropertiesExternalArrayDataType(); - size_t array_size = ExternalArraySize(array_type); + size_t array_size = InternalExternalArraySize(array_type); CHECK_GT(array_size, 0); if (array_size > 1 && array_data != NULL) { CHECK_GT(array_length * array_size, array_length); // Overflow check. @@ -152,27 +177,7 @@ void CallbackInfo::WeakCallback(Isolate* isolate, Local object) { // return size of external array type, or 0 if unrecognized size_t ExternalArraySize(enum ExternalArrayType type) { - switch (type) { - case v8::kExternalUint8Array: - return sizeof(uint8_t); - case v8::kExternalInt8Array: - return sizeof(int8_t); - case v8::kExternalInt16Array: - return sizeof(int16_t); - case v8::kExternalUint16Array: - return sizeof(uint16_t); - case v8::kExternalInt32Array: - return sizeof(int32_t); - case v8::kExternalUint32Array: - return sizeof(uint32_t); - case v8::kExternalFloat32Array: - return sizeof(float); // NOLINT(runtime/sizeof) - case v8::kExternalFloat64Array: - return sizeof(double); // NOLINT(runtime/sizeof) - case v8::kExternalUint8ClampedArray: - return sizeof(uint8_t); - } - return 0; + return InternalExternalArraySize(type); } @@ -200,12 +205,12 @@ void CopyOnto(const FunctionCallbackInfo& args) { size_t source_length = source->GetIndexedPropertiesExternalArrayDataLength(); enum ExternalArrayType source_type = source->GetIndexedPropertiesExternalArrayDataType(); - size_t source_size = ExternalArraySize(source_type); + size_t source_size = InternalExternalArraySize(source_type); size_t dest_length = dest->GetIndexedPropertiesExternalArrayDataLength(); enum ExternalArrayType dest_type = dest->GetIndexedPropertiesExternalArrayDataType(); - size_t dest_size = ExternalArraySize(dest_type); + size_t dest_size = InternalExternalArraySize(dest_type); // optimization for Uint8 arrays (i.e. Buffers) if (source_size != 1 || dest_size != 1) { @@ -261,7 +266,7 @@ void SliceOnto(const FunctionCallbackInfo& args) { size_t source_len = source->GetIndexedPropertiesExternalArrayDataLength(); enum ExternalArrayType source_type = source->GetIndexedPropertiesExternalArrayDataType(); - size_t source_size = ExternalArraySize(source_type); + size_t source_size = InternalExternalArraySize(source_type); CHECK_NE(source_size, 0); @@ -304,7 +309,7 @@ void Alloc(const FunctionCallbackInfo& args) { array_type = kExternalUint8Array; } else { array_type = static_cast(args[2]->Uint32Value()); - size_t type_length = ExternalArraySize(array_type); + size_t type_length = InternalExternalArraySize(array_type); CHECK_GE(type_length * length, length); length *= type_length; } @@ -318,7 +323,7 @@ void Alloc(Environment* env, Handle obj, size_t length, enum ExternalArrayType type) { - size_t type_size = ExternalArraySize(type); + size_t type_size = InternalExternalArraySize(type); CHECK_LE(length, kMaxLength); CHECK_GT(type_size, 0); @@ -345,7 +350,7 @@ void Alloc(Environment* env, enum ExternalArrayType type) { CHECK_EQ(false, obj->HasIndexedPropertiesInExternalArrayData()); env->isolate()->AdjustAmountOfExternalAllocatedMemory(length); - size_t size = length / ExternalArraySize(type); + size_t size = length / InternalExternalArraySize(type); obj->SetIndexedPropertiesToExternalArrayData(data, type, size); CallbackInfo::New(env->isolate(), CallbackInfo::kInternal, @@ -378,7 +383,7 @@ void AllocDispose(Environment* env, Handle obj) { size_t length = obj->GetIndexedPropertiesExternalArrayDataLength(); enum ExternalArrayType array_type = obj->GetIndexedPropertiesExternalArrayDataType(); - size_t array_size = ExternalArraySize(array_type); + size_t array_size = InternalExternalArraySize(array_type); CHECK_GT(array_size, 0); CHECK_GE(length * array_size, length); @@ -412,7 +417,7 @@ static void Alloc(Environment* env, env->set_using_smalloc_alloc_cb(true); CallbackInfo* info = CallbackInfo::New(isolate, ownership, obj, fn, hint); obj->SetHiddenValue(env->smalloc_p_string(), External::New(isolate, info)); - size_t size = length / ExternalArraySize(type); + size_t size = length / InternalExternalArraySize(type); obj->SetIndexedPropertiesToExternalArrayData(data, type, size); } @@ -425,7 +430,7 @@ void Alloc(Environment* env, enum ExternalArrayType type) { CHECK_LE(length, kMaxLength); - size_t type_size = ExternalArraySize(type); + size_t type_size = InternalExternalArraySize(type); CHECK_GT(type_size, 0); CHECK_GE(length * type_size, length); diff --git a/src/smalloc.h b/src/smalloc.h index a2d0f978a23973..2cb8cb54d62c53 100644 --- a/src/smalloc.h +++ b/src/smalloc.h @@ -26,7 +26,9 @@ NODE_EXTERN typedef void (*FreeCallback)(char* data, void* hint); /** * Return byte size of external array type. */ -NODE_EXTERN size_t ExternalArraySize(enum v8::ExternalArrayType type); +NODE_DEPRECATED( + "Use typed arrays", + NODE_EXTERN size_t ExternalArraySize(enum v8::ExternalArrayType type)); /** * Allocate external array data onto obj. @@ -55,45 +57,58 @@ NODE_EXTERN size_t ExternalArraySize(enum v8::ExternalArrayType type); * v8::Integer::NewFromUnsigned(array_length)); * \code */ -NODE_EXTERN void Alloc(v8::Isolate* isolate, - v8::Handle obj, - size_t length, - enum v8::ExternalArrayType type = - v8::kExternalUnsignedByteArray); -NODE_EXTERN void Alloc(v8::Isolate* isolate, - v8::Handle obj, - char* data, - size_t length, - enum v8::ExternalArrayType type = - v8::kExternalUnsignedByteArray); -NODE_EXTERN void Alloc(v8::Isolate* isolate, - v8::Handle obj, - size_t length, - FreeCallback fn, - void* hint, - enum v8::ExternalArrayType type = - v8::kExternalUnsignedByteArray); -NODE_EXTERN void Alloc(v8::Isolate* isolate, - v8::Handle obj, - char* data, - size_t length, - FreeCallback fn, - void* hint, - enum v8::ExternalArrayType type = - v8::kExternalUnsignedByteArray); +NODE_DEPRECATED( + "Use typed arrays", + NODE_EXTERN void Alloc(v8::Isolate* isolate, + v8::Handle obj, + size_t length, + enum v8::ExternalArrayType type = + v8::kExternalUnsignedByteArray)); +NODE_DEPRECATED( + "Use typed arrays", + NODE_EXTERN void Alloc(v8::Isolate* isolate, + v8::Handle obj, + char* data, + size_t length, + enum v8::ExternalArrayType type = + v8::kExternalUnsignedByteArray)); +NODE_DEPRECATED( + "Use typed arrays", + NODE_EXTERN void Alloc(v8::Isolate* isolate, + v8::Handle obj, + size_t length, + FreeCallback fn, + void* hint, + enum v8::ExternalArrayType type = + v8::kExternalUnsignedByteArray)); +NODE_DEPRECATED( + "Use typed arrays", + NODE_EXTERN void Alloc(v8::Isolate* isolate, + v8::Handle obj, + char* data, + size_t length, + FreeCallback fn, + void* hint, + enum v8::ExternalArrayType type = + v8::kExternalUnsignedByteArray)); /** * Free memory associated with an externally allocated object. If no external * memory is allocated to the object then nothing will happen. */ -NODE_EXTERN void AllocDispose(v8::Isolate* isolate, v8::Handle obj); +NODE_DEPRECATED( + "Use typed arrays", + NODE_EXTERN void AllocDispose(v8::Isolate* isolate, + v8::Handle obj)); /** * Check if the Object has externally allocated memory. */ -NODE_EXTERN bool HasExternalData(v8::Isolate* isolate, - v8::Local obj); +NODE_DEPRECATED( + "Use typed arrays", + NODE_EXTERN bool HasExternalData(v8::Isolate* isolate, + v8::Local obj)); // Internal use