@@ -482,13 +482,19 @@ static PyObject* callBuffer[1024];
482
482
PyAPI_FUNC (PyObject * ) PyObject_CallFunctionObjArgs (PyObject * callable , ...) {
483
483
va_list myargs ;
484
484
va_start (myargs , callable );
485
+ PyObject * arg ;
485
486
int count = 0 ;
486
487
while (count <= 1024 ) {
487
- PyObject * o = va_arg (myargs , PyObject * );
488
- if (o == NULL ) {
488
+ arg = va_arg (myargs , PyObject * );
489
+ if (arg == NULL ) {
489
490
break ;
490
491
}
491
- callBuffer [count ++ ] = o ;
492
+ callBuffer [count ++ ] = arg ;
493
+ }
494
+ // test if buffer was too small
495
+ if (arg != NULL ) {
496
+ fprintf (stderr , "argument buffer for 'PyObject_CallFunctionObjArgs' is too small" );
497
+ exit (-1 );
492
498
}
493
499
PyObject * args = PyTuple_New (count );
494
500
for (int i = 0 ; i < count ; i ++ ) {
@@ -502,9 +508,46 @@ PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, ...) {
502
508
return result ;
503
509
}
504
510
505
- PyObject * PyObject_CallMethodObjArgs (PyObject * a , PyObject * b , ...) {
506
- printf ("PyObject_CallMethodObjArgs not implemented in capi_native - exiting\n" );
507
- exit (-1 );
511
+ PyObject * PyObject_CallMethodObjArgs (PyObject * obj , PyObject * name , ...) {
512
+ if ((obj == NULL || name == NULL ) && !PyErr_Occurred ()) {
513
+ PyErr_SetString (PyExc_SystemError ,
514
+ "null argument to internal routine" );
515
+ return NULL ;
516
+ }
517
+
518
+ PyObject * callable = NULL ;
519
+ int is_method = _PyObject_GetMethod (obj , name , & callable );
520
+ if (callable == NULL ) {
521
+ return NULL ;
522
+ }
523
+ obj = is_method ? obj : NULL ;
524
+
525
+ va_list myargs ;
526
+ va_start (myargs , name );
527
+ PyObject * arg ;
528
+ int count = 0 ;
529
+ while (count <= 1024 ) {
530
+ arg = va_arg (myargs , PyObject * );
531
+ if (arg == NULL ) {
532
+ break ;
533
+ }
534
+ callBuffer [count ++ ] = arg ;
535
+ }
536
+ // test if buffer was too small
537
+ if (arg != NULL ) {
538
+ fprintf (stderr , "argument buffer for 'PyObject_CallMethodObjArgs' is too small" );
539
+ exit (-1 );
540
+ }
541
+ PyObject * args = PyTuple_New (count );
542
+ for (int i = 0 ; i < count ; i ++ ) {
543
+ Py_INCREF (callBuffer [i ]);
544
+ PyTuple_SetItem (args , i , callBuffer [i ]);
545
+ }
546
+ va_end (myargs );
547
+
548
+ PyObject * result = PyObject_CallObject (callable , args );
549
+ Py_DECREF (args );
550
+ return result ;
508
551
}
509
552
510
553
PyObject * _PyObject_CallMethodIdObjArgs (PyObject * object , struct _Py_Identifier * name , ...) {
0 commit comments