[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
andersca at apple.com
andersca at apple.com
Wed Dec 22 15:24:18 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit a1247b755728765613e327ea590e95c4646cec61
Author: andersca at apple.com <andersca at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Nov 2 21:18:18 2010 +0000
Add convenience functions for allocating NPAPI memory
https://bugs.webkit.org/show_bug.cgi?id=48870
Reviewed by Dan Bernstein.
Add npnMemAlloc, npnMemFree and createNPString functions and
npnMemNew, npnMemNewArray function templates.
* WebProcess/Plugins/Netscape/JSNPObject.cpp:
(WebKit::JSNPObject::getOwnPropertyNames):
Use npnMemFree.
* WebProcess/Plugins/Netscape/NPJSObject.cpp:
(WebKit::NPJSObject::enumerate):
Use npnMemNewArray.
* WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:
(WebKit::NPRuntimeObjectMap::convertJSValueToNPVariant):
Use createNPString.
* WebProcess/Plugins/Netscape/NPRuntimeUtilities.cpp:
(WebKit::npnMemAlloc):
Call malloc.
(WebKit::npnMemFree):
Call free.
(WebKit::createNPString):
Allocate the characters for a new NPString.
(WebKit::createNPObject):
Call npnMemNew.
(WebKit::deallocateNPObject):
Call npnMemFree.
(WebKit::releaseNPVariantValue):
Call npnMemFree.
* WebProcess/Plugins/Netscape/NPRuntimeUtilities.h:
(WebKit::npnMemNew):
(WebKit::npnMemNewArray):
Add new functions.
* WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
(WebKit::NPN_MemAlloc):
Call npnMemAlloc.
(WebKit::NPN_MemFree):
Call npnMemFree.
(WebKit::NPN_UTF8FromIdentifier):
Call npnMemNewArray.
(WebKit::copyCString):
Call npnMemNewArray. Correctly initialize the "len" out parameter.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@71169 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog
index 43242c3..7fad354 100644
--- a/WebKit2/ChangeLog
+++ b/WebKit2/ChangeLog
@@ -1,3 +1,62 @@
+2010-11-02 Anders Carlsson <andersca at apple.com>
+
+ Reviewed by Dan Bernstein.
+
+ Add convenience functions for allocating NPAPI memory
+ https://bugs.webkit.org/show_bug.cgi?id=48870
+
+ Add npnMemAlloc, npnMemFree and createNPString functions and
+ npnMemNew, npnMemNewArray function templates.
+
+ * WebProcess/Plugins/Netscape/JSNPObject.cpp:
+ (WebKit::JSNPObject::getOwnPropertyNames):
+ Use npnMemFree.
+
+ * WebProcess/Plugins/Netscape/NPJSObject.cpp:
+ (WebKit::NPJSObject::enumerate):
+ Use npnMemNewArray.
+
+ * WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:
+ (WebKit::NPRuntimeObjectMap::convertJSValueToNPVariant):
+ Use createNPString.
+
+ * WebProcess/Plugins/Netscape/NPRuntimeUtilities.cpp:
+ (WebKit::npnMemAlloc):
+ Call malloc.
+
+ (WebKit::npnMemFree):
+ Call free.
+
+ (WebKit::createNPString):
+ Allocate the characters for a new NPString.
+
+ (WebKit::createNPObject):
+ Call npnMemNew.
+
+ (WebKit::deallocateNPObject):
+ Call npnMemFree.
+
+ (WebKit::releaseNPVariantValue):
+ Call npnMemFree.
+
+ * WebProcess/Plugins/Netscape/NPRuntimeUtilities.h:
+ (WebKit::npnMemNew):
+ (WebKit::npnMemNewArray):
+ Add new functions.
+
+ * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
+ (WebKit::NPN_MemAlloc):
+ Call npnMemAlloc.
+
+ (WebKit::NPN_MemFree):
+ Call npnMemFree.
+
+ (WebKit::NPN_UTF8FromIdentifier):
+ Call npnMemNewArray.
+
+ (WebKit::copyCString):
+ Call npnMemNewArray. Correctly initialize the "len" out parameter.
+
2010-11-02 Jessie Berlin <jberlin at apple.com>
Windows build fix. Unreviewed.
diff --git a/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.cpp b/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.cpp
index 9465526..d7d626f 100644
--- a/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.cpp
+++ b/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.cpp
@@ -355,8 +355,7 @@ void JSNPObject::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propert
propertyNameArray.add(identifier);
}
- // This should use NPN_MemFree, but we know that it uses free under the hood.
- free(identifiers);
+ npnMemFree(identifiers);
}
JSValue JSNPObject::propertyGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
diff --git a/WebKit2/WebProcess/Plugins/Netscape/NPJSObject.cpp b/WebKit2/WebProcess/Plugins/Netscape/NPJSObject.cpp
index f420bd1..45c1e6e 100644
--- a/WebKit2/WebProcess/Plugins/Netscape/NPJSObject.cpp
+++ b/WebKit2/WebProcess/Plugins/Netscape/NPJSObject.cpp
@@ -238,8 +238,7 @@ bool NPJSObject::enumerate(NPIdentifier** identifiers, uint32_t* identifierCount
PropertyNameArray propertyNames(exec);
m_jsObject->getPropertyNames(exec, propertyNames);
- // This should use NPN_MemAlloc, but we know that it uses malloc under the hood.
- NPIdentifier* nameIdentifiers = static_cast<NPIdentifier*>(malloc(sizeof(NPIdentifier) * propertyNames.size()));
+ NPIdentifier* nameIdentifiers = npnMemNewArray<NPIdentifier>(propertyNames.size());
for (size_t i = 0; i < propertyNames.size(); ++i)
nameIdentifiers[i] = static_cast<NPIdentifier>(IdentifierRep::get(propertyNames[i].ustring().utf8().data()));
diff --git a/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp b/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp
index 7328d9d..4fa37c1 100644
--- a/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp
+++ b/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp
@@ -165,13 +165,8 @@ void NPRuntimeObjectMap::convertJSValueToNPVariant(ExecState* exec, JSValue valu
}
if (value.isString()) {
- CString utf8String = value.toString(exec).utf8();
-
- // This should use NPN_MemAlloc, but we know that it uses malloc under the hood.
- char* utf8Characters = static_cast<char*>(malloc(utf8String.length()));
- memcpy(utf8Characters, utf8String.data(), utf8String.length());
-
- STRINGN_TO_NPVARIANT(utf8Characters, utf8String.length(), variant);
+ NPString npString = createNPString(value.toString(exec).utf8());
+ STRINGN_TO_NPVARIANT(npString.UTF8Characters, npString.UTF8Length, variant);
return;
}
diff --git a/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeUtilities.cpp b/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeUtilities.cpp
index 1c7270f..20ff478 100644
--- a/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeUtilities.cpp
+++ b/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeUtilities.cpp
@@ -25,8 +25,36 @@
#include "NPRuntimeUtilities.h"
+#include <wtf/text/CString.h>
+
namespace WebKit {
+void* npnMemAlloc(uint32_t size)
+{
+ // We could use fastMalloc here, but there might be plug-ins that mix NPN_MemAlloc/NPN_MemFree with malloc and free,
+ // so having them be equivalent seems like a good idea.
+ return malloc(size);
+}
+
+void npnMemFree(void* ptr)
+{
+ // We could use fastFree here, but there might be plug-ins that mix NPN_MemAlloc/NPN_MemFree with malloc and free,
+ // so having them be equivalent seems like a good idea.
+ free(ptr);
+}
+
+NPString createNPString(const CString& string)
+{
+ char* utf8Characters = npnMemNewArray<char>(string.length());
+ memcpy(utf8Characters, string.data(), string.length());
+
+ NPString npString;
+ npString.UTF8Characters = utf8Characters;
+ npString.UTF8Length = string.length();
+
+ return npString;
+}
+
NPObject* createNPObject(NPP npp, NPClass* npClass)
{
ASSERT(npClass);
@@ -34,10 +62,8 @@ NPObject* createNPObject(NPP npp, NPClass* npClass)
NPObject* npObject;
if (npClass->allocate)
npObject = npClass->allocate(npp, npClass);
- else {
- // This should use NPN_MemAlloc, but we know that it uses malloc under the hood.
- npObject = static_cast<NPObject*>(malloc(sizeof(NPObject)));
- }
+ else
+ npObject = npnMemNew<NPObject>();
npObject->_class = npClass;
npObject->referenceCount = 1;
@@ -53,11 +79,8 @@ void deallocateNPObject(NPObject* npObject)
if (npObject->_class->deallocate)
npObject->_class->deallocate(npObject);
- else {
- // This should really call NPN_MemFree, but we know that it uses free
- // under the hood so it's fine.
- free(npObject);
- }
+ else
+ npnMemFree(npObject);
}
void retainNPObject(NPObject* npObject)
@@ -95,7 +118,7 @@ void releaseNPVariantValue(NPVariant* variant)
break;
case NPVariantType_String:
- free(const_cast<NPUTF8*>(variant->value.stringValue.UTF8Characters));
+ npnMemFree(const_cast<NPUTF8*>(variant->value.stringValue.UTF8Characters));
variant->value.stringValue.UTF8Characters = 0;
variant->value.stringValue.UTF8Length = 0;
break;
diff --git a/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeUtilities.h b/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeUtilities.h
index 393cb38..7309fd4 100644
--- a/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeUtilities.h
+++ b/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeUtilities.h
@@ -27,12 +27,28 @@
#define NPRuntimeUtilities_h
#include <WebCore/npruntime_internal.h>
+#include <wtf/Forward.h>
struct NPClass;
struct NPObject;
namespace WebKit {
+void* npnMemAlloc(uint32_t);
+void npnMemFree(void*);
+
+template<typename T> T* npnMemNew()
+{
+ return static_cast<T*>(npnMemAlloc(sizeof(T)));
+}
+
+template<typename T> T* npnMemNewArray(size_t count)
+{
+ return static_cast<T*>(npnMemAlloc(sizeof(T) * count));
+}
+
+NPString createNPString(const CString&);
+
NPObject* createNPObject(NPP, NPClass*);
void deallocateNPObject(NPObject*);
diff --git a/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp b/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp
index c5c705b..9703d25 100644
--- a/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp
+++ b/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp
@@ -336,16 +336,12 @@ static const char* NPN_UserAgent(NPP npp)
static void* NPN_MemAlloc(uint32_t size)
{
- // We could use fastMalloc here, but there might be plug-ins that mix NPN_MemAlloc/NPN_MemFree with malloc and free,
- // so having them be equivalent seems like a good idea.
- return malloc(size);
+ return npnMemAlloc(size);
}
static void NPN_MemFree(void* ptr)
{
- // We could use fastFree here, but there might be plug-ins that mix NPN_MemAlloc/NPN_MemFree with malloc and free,
- // so having them be equivalent seems like a good idea.
- free(ptr);
+ npnMemFree(ptr);
}
static uint32_t NPN_MemFlush(uint32_t size)
@@ -548,7 +544,7 @@ static NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
return 0;
uint32_t stringLength = strlen(string);
- char* utf8String = static_cast<char*>(NPN_MemAlloc(stringLength + 1));
+ char* utf8String = npnMemNewArray<char>(stringLength + 1);
memcpy(utf8String, string, stringLength);
utf8String[stringLength] = '\0';
@@ -687,11 +683,12 @@ static NPError copyCString(const CString& string, char** value, uint32_t* len)
ASSERT(value);
ASSERT(len);
- *value = static_cast<char*>(NPN_MemAlloc(string.length()));
+ *value = npnMemNewArray<char>(string.length());
if (!*value)
return NPERR_GENERIC_ERROR;
memcpy(*value, string.data(), string.length());
+ *len = string.length();
return NPERR_NO_ERROR;
}
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list