diff context.cpp @ 100:b3cc704c035e

PYM_callFunction() now uses PyMem_Malloc() to dynamically allocate space for arguments on the heap, since MSVC doesn't seem to support dynamically-sized arrays on the stack.
author Atul Varma <varmaa@toolness.com>
date Sat, 15 Aug 2009 16:13:13 -0700
parents 3570ab12747b
children 00c1351b3e82
line wrap: on
line diff
--- a/context.cpp	Sat Aug 15 15:51:55 2009 -0700
+++ b/context.cpp	Sat Aug 15 16:13:13 2009 -0700
@@ -350,14 +350,20 @@
   PYM_ENSURE_RUNTIME_MATCH(self->runtime, fun->base.runtime);
 
   uintN argc = PyTuple_Size(funcArgs);
-  jsval argv[argc];
+
+  jsval *argv = (jsval *) PyMem_Malloc(sizeof(jsval) * argc);
+  if (argv == NULL)
+    return PyErr_NoMemory();
+
   jsval *currArg = argv;
 
   for (unsigned int i = 0; i < argc; i++) {
     PyObject *item = PyTuple_GET_ITEM(funcArgs, i);
     if (item == NULL ||
-        PYM_pyObjectToJsval(self, item, currArg) == -1)
+        PYM_pyObjectToJsval(self, item, currArg) == -1) {
+      PyMem_Free(argv);
       return NULL;
+    }
     currArg++;
   }
 
@@ -373,6 +379,8 @@
                            argc, argv, &rval);
   Py_END_ALLOW_THREADS;
 
+  PyMem_Free(argv);
+
   if (!result) {
     PYM_jsExceptionToPython(self);
     return NULL;