From 73062521a424614fccfe6399b47030ee065e1977 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 29 Apr 2015 19:04:59 +0100 Subject: [PATCH] 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