Bug 564068 Test plugin should always use the NPN allocator r=jst
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Tue, 11 May 2010 10:46:38 +0100
changeset 42123 aa0171d3680585f5afb0b39607633cce8348d5ba
parent 42122 c5976fc3311c5408a80e6faf9ab5572c6c7e55f3
child 42124 ce9f07472020dbac7cb53418831c22fefcff260d
push idunknown
push userunknown
push dateunknown
reviewersjst
bugs564068
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 564068 Test plugin should always use the NPN allocator r=jst
modules/plugin/test/testplugin/Makefile.in
modules/plugin/test/testplugin/nptest.cpp
--- a/modules/plugin/test/testplugin/Makefile.in
+++ b/modules/plugin/test/testplugin/Makefile.in
@@ -44,16 +44,19 @@ include $(DEPTH)/config/autoconf.mk
 
 MODULE       = nptest
 LIBRARY_NAME = nptest
 MODULE_NAME  = TestPlugin
 
 # Don't use STL wrappers; nptest isn't Gecko code
 STL_FLAGS =
 
+# must link statically with the CRT; nptest isn't Gecko code
+USE_STATIC_LIBS = 1
+
 # Need to custom install plugins
 NO_DIST_INSTALL	= 1
 NO_INSTALL = 1
 
 CPPSRCS   =  \
   nptest.cpp \
   nptest_utils.cpp \
   $(NULL)
--- a/modules/plugin/test/testplugin/nptest.cpp
+++ b/modules/plugin/test/testplugin/nptest.cpp
@@ -1373,16 +1373,22 @@ NPN_ReleaseObject(NPObject* obj)
 }
 
 void*
 NPN_MemAlloc(uint32_t size)
 {
   return sBrowserFuncs->memalloc(size);
 }
 
+char*
+NPN_StrDup(const char* str)
+{
+  return strcpy((char*)sBrowserFuncs->memalloc(strlen(str) + 1), str);
+}
+
 void
 NPN_MemFree(void* ptr)
 {
   return sBrowserFuncs->memfree(ptr);
 }
 
 uint32_t
 NPN_ScheduleTimer(NPP instance, uint32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID))
@@ -1626,17 +1632,17 @@ scriptableInvokeDefault(NPObject* npobj,
         break;
       case NPVariantType_Null:
         value << ";null";
         break;
       default:
         value << ";other";
     }
   }
-  STRINGZ_TO_NPVARIANT(strdup(value.str().c_str()), *result);
+  STRINGZ_TO_NPVARIANT(NPN_StrDup(value.str().c_str()), *result);
   return true;
 }
 
 bool
 scriptableHasProperty(NPObject* npobj, NPIdentifier name)
 {
   for (int i = 0; i < int(ARRAY_LENGTH(sPluginPropertyIdentifiers)); i++) {
     if (name == sPluginPropertyIdentifiers[i])
@@ -2119,19 +2125,19 @@ static bool
 getError(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
 {
   if (argCount != 0)
     return false;
 
   NPP npp = static_cast<TestNPObject*>(npobj)->npp;
   InstanceData* id = static_cast<InstanceData*>(npp->pdata);
   if (id->err.str().length() == 0)
-    STRINGZ_TO_NPVARIANT(strdup(SUCCESS_STRING), *result);
+    STRINGZ_TO_NPVARIANT(NPN_StrDup(SUCCESS_STRING), *result);
   else
-    STRINGZ_TO_NPVARIANT(strdup(id->err.str().c_str()), *result);
+    STRINGZ_TO_NPVARIANT(NPN_StrDup(id->err.str().c_str()), *result);
   return true;
 }
 
 static bool
 doInternalConsistencyCheck(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
 {
   if (argCount != 0)
     return false;