comparison 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
comparison
equal deleted inserted replaced
99:e4f7cc6beafe 100:b3cc704c035e
348 348
349 PYM_ENSURE_RUNTIME_MATCH(self->runtime, obj->runtime); 349 PYM_ENSURE_RUNTIME_MATCH(self->runtime, obj->runtime);
350 PYM_ENSURE_RUNTIME_MATCH(self->runtime, fun->base.runtime); 350 PYM_ENSURE_RUNTIME_MATCH(self->runtime, fun->base.runtime);
351 351
352 uintN argc = PyTuple_Size(funcArgs); 352 uintN argc = PyTuple_Size(funcArgs);
353 jsval argv[argc]; 353
354 jsval *argv = (jsval *) PyMem_Malloc(sizeof(jsval) * argc);
355 if (argv == NULL)
356 return PyErr_NoMemory();
357
354 jsval *currArg = argv; 358 jsval *currArg = argv;
355 359
356 for (unsigned int i = 0; i < argc; i++) { 360 for (unsigned int i = 0; i < argc; i++) {
357 PyObject *item = PyTuple_GET_ITEM(funcArgs, i); 361 PyObject *item = PyTuple_GET_ITEM(funcArgs, i);
358 if (item == NULL || 362 if (item == NULL ||
359 PYM_pyObjectToJsval(self, item, currArg) == -1) 363 PYM_pyObjectToJsval(self, item, currArg) == -1) {
364 PyMem_Free(argv);
360 return NULL; 365 return NULL;
366 }
361 currArg++; 367 currArg++;
362 } 368 }
363 369
364 jsval rval; 370 jsval rval;
365 371
370 Py_BEGIN_ALLOW_THREADS; 376 Py_BEGIN_ALLOW_THREADS;
371 result = JS_CallFunction(self->cx, obj->obj, 377 result = JS_CallFunction(self->cx, obj->obj,
372 (JSFunction *) fun->base.obj, 378 (JSFunction *) fun->base.obj,
373 argc, argv, &rval); 379 argc, argv, &rval);
374 Py_END_ALLOW_THREADS; 380 Py_END_ALLOW_THREADS;
381
382 PyMem_Free(argv);
375 383
376 if (!result) { 384 if (!result) {
377 PYM_jsExceptionToPython(self); 385 PYM_jsExceptionToPython(self);
378 return NULL; 386 return NULL;
379 } 387 }