comparison python/pydc/pydc.c @ 61:c5a69c454963 default tip

- allow use of 'None' with 'Z' - bumped version to 1.4 (be in sync current dyncall version)
author Tassilo Philipp
date Mon, 03 Apr 2023 19:06:07 +0200
parents 8e905c0798c7
children
comparison
equal deleted inserted replaced
60:8e905c0798c7 61:c5a69c454963
2 ** 2 **
3 ** pydc - python dyncall package 3 ** pydc - python dyncall package
4 ** 4 **
5 ** python extension package in C 5 ** python extension package in C
6 ** Copyright 2007-2016 Daniel Adler 6 ** Copyright 2007-2016 Daniel Adler
7 ** 2018-2020 Tassilo Philipp 7 ** 2018-2023 Tassilo Philipp
8 ** 8 **
9 ** See README.txt for details (about changes, how to use, etc.). 9 ** See README.txt for details (about changes, how to use, etc.).
10 ** 10 **
11 *****************************************************************************/ 11 *****************************************************************************/
12 12
435 435
436 case DC_SIGCHAR_STRING: // strings are considered to be immutable objects 436 case DC_SIGCHAR_STRING: // strings are considered to be immutable objects
437 { 437 {
438 PyObject* bo = NULL; 438 PyObject* bo = NULL;
439 const char* p; 439 const char* p;
440 size_t s;
441 if ( PyUnicode_Check(po) ) 440 if ( PyUnicode_Check(po) )
442 { 441 {
443 #if defined(PYUNICODE_CACHES_UTF8) 442 #if defined(PYUNICODE_CACHES_UTF8)
444 p = PyUnicode_AsUTF8(po); 443 p = PyUnicode_AsUTF8(po);
445 #else 444 #else
449 #endif 448 #endif
450 } else if ( DcPyString_Check(po) ) 449 } else if ( DcPyString_Check(po) )
451 p = DcPyString_AsString(po); 450 p = DcPyString_AsString(po);
452 else if ( PyByteArray_Check(po) ) 451 else if ( PyByteArray_Check(po) )
453 p = (DCpointer) PyByteArray_AsString(po); // adds an extra '\0', but that's ok //@@@ not sure if allowed to modify 452 p = (DCpointer) PyByteArray_AsString(po); // adds an extra '\0', but that's ok //@@@ not sure if allowed to modify
453 else if ( po == Py_None )
454 p = NULL;
454 else 455 else
455 return PyErr_Format( PyExc_RuntimeError, "arg %d - expecting a str", pos ); 456 return PyErr_Format( PyExc_RuntimeError, "arg %d - expecting a str", pos );
456 457
457 if(n_str_aux >= NUM_AUX_STRS) 458 if(n_str_aux >= NUM_AUX_STRS)
458 return PyErr_Format( PyExc_RuntimeError, "too many arguments (implementation limit of %d new UTF-8 string references reached) - abort", n_str_aux ); 459 return PyErr_Format( PyExc_RuntimeError, "too many arguments (implementation limit of %d new UTF-8 string references reached) - abort", n_str_aux );
459 460
460 // p points in every case to a buffer that shouldn't be modified, so pass a copy to dyncall (cleaned up after call) 461 if(!p)
461 s = strlen(p)+1; 462 str_aux[n_str_aux] = NULL;
462 str_aux[n_str_aux] = malloc(s); 463 else {
463 strncpy(str_aux[n_str_aux], p, s); 464 // p points in every case to a buffer that shouldn't be modified, so pass a copy to dyncall (cleaned up after call)
465 size_t s = strlen(p)+1;
466 str_aux[n_str_aux] = malloc(s);
467 strncpy(str_aux[n_str_aux], p, s);
468 }
464 Py_XDECREF(bo); 469 Py_XDECREF(bo);
465 dcArgPointer(gpCall, (DCpointer)str_aux[n_str_aux++]); 470 dcArgPointer(gpCall, (DCpointer)str_aux[n_str_aux++]);
466 } 471 }
467 break; 472 break;
468 473