Mercurial > pub > dyncall > bindings
diff 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 |
line wrap: on
line diff
--- a/python/pydc/pydc.c Wed Aug 03 15:38:07 2022 +0200 +++ b/python/pydc/pydc.c Mon Apr 03 19:06:07 2023 +0200 @@ -4,7 +4,7 @@ ** ** python extension package in C ** Copyright 2007-2016 Daniel Adler - ** 2018-2020 Tassilo Philipp + ** 2018-2023 Tassilo Philipp ** ** See README.txt for details (about changes, how to use, etc.). ** @@ -437,7 +437,6 @@ { PyObject* bo = NULL; const char* p; - size_t s; if ( PyUnicode_Check(po) ) { #if defined(PYUNICODE_CACHES_UTF8) @@ -451,16 +450,22 @@ p = DcPyString_AsString(po); else if ( PyByteArray_Check(po) ) p = (DCpointer) PyByteArray_AsString(po); // adds an extra '\0', but that's ok //@@@ not sure if allowed to modify + else if ( po == Py_None ) + p = NULL; else return PyErr_Format( PyExc_RuntimeError, "arg %d - expecting a str", pos ); if(n_str_aux >= NUM_AUX_STRS) return PyErr_Format( PyExc_RuntimeError, "too many arguments (implementation limit of %d new UTF-8 string references reached) - abort", n_str_aux ); - // p points in every case to a buffer that shouldn't be modified, so pass a copy to dyncall (cleaned up after call) - s = strlen(p)+1; - str_aux[n_str_aux] = malloc(s); - strncpy(str_aux[n_str_aux], p, s); + if(!p) + str_aux[n_str_aux] = NULL; + else { + // p points in every case to a buffer that shouldn't be modified, so pass a copy to dyncall (cleaned up after call) + size_t s = strlen(p)+1; + str_aux[n_str_aux] = malloc(s); + strncpy(str_aux[n_str_aux], p, s); + } Py_XDECREF(bo); dcArgPointer(gpCall, (DCpointer)str_aux[n_str_aux++]); }