# HG changeset patch # User Tassilo Philipp # Date 1603820658 -3600 # Node ID 0f86a5ecfe61ed6ed75c014fcc9e4e8959f30d5e # Parent 1086ca64971589026b2cceeff203b9ef3c5dace2 - python: allow None to be passed for 'p'ointers, always passing NULL diff -r 1086ca649715 -r 0f86a5ecfe61 python/pydc/README.txt --- a/python/pydc/README.txt Wed Apr 15 21:58:13 2020 +0200 +++ b/python/pydc/README.txt Tue Oct 27 18:44:18 2020 +0100 @@ -11,6 +11,7 @@ Apr 12, 2020: breaking change: restrict 'Z' conversions to immutable types and 'p' to mutable types (and handles) Apr 13, 2020: added signature char support to specify calling conventions +Oct 27, 2020: allowing 'None' for 'p' params, always passing NULL BUILD/INSTALLATION @@ -75,6 +76,7 @@ 'p' | bytearray (PyByteArray) & | bytearray (PyByteArray) & | void* | int,long (Py_ssize_t) | int (Py_ssize_t) | int (PyInt) | int (PyLong) | void* | int,long (Py_ssize_t) | int (Py_ssize_t) | long (PyLong) | - | void* | int,long (Py_ssize_t) | int (Py_ssize_t) + | None (Py_None) | None (Py_None) | void* (always NULL) | int,long (Py_ssize_t) | int (Py_ssize_t) 'Z' | str (PyString) ! | str (PyUnicode) ! | const char* (UTF-8 for unicode) | int (PyString) | str (PyUnicode) | unicode (PyUnicode) ! | - | const char* (UTF-8 for unicode) | int (PyString) | str (PyUnicode) | - | bytes (PyBytes) ! | const char* (UTF-8 for unicode) | int (PyString) | str (PyUnicode) diff -r 1086ca649715 -r 0f86a5ecfe61 python/pydc/pydcext.c --- a/python/pydc/pydcext.c Wed Apr 15 21:58:13 2020 +0200 +++ b/python/pydc/pydcext.c Tue Oct 27 18:44:18 2020 +0100 @@ -359,6 +359,8 @@ #endif else if ( PyLong_Check(po) ) p = (DCpointer) PyLong_AsVoidPtr(po); + else if ( po == Py_None ) + p = NULL; else return PyErr_Format( PyExc_RuntimeError, "arg %d - expecting a promoting pointer-type (int, bytearray)", pos ); dcArgPointer(gpCall, p); diff -r 1086ca649715 -r 0f86a5ecfe61 python/pydc/test/types.py --- a/python/pydc/test/types.py Wed Apr 15 21:58:13 2020 +0200 +++ b/python/pydc/test/types.py Tue Oct 27 18:44:18 2020 +0100 @@ -132,6 +132,7 @@ t(l, "p)p", "const char*", "ccp_plus_one", "(const char*)", ' "xY" => p+1 (~ odd addr)', bytearray(b'xY')) # bytearray object t(l, "p)p", "const char*", "ccp_plus_one", "(const char*)", ' 0xdeadc0de => 0xdeadc0de+1=3735929055', long_h) # handle (integer interpreted as ptr) t(l, "p)p", "const char*", "ccp_plus_one", "(const char*)", ' 0xdeadc0de => 0xdeadc0de+1=3735929055', long_h) # handle (integer interpreted as ptr, long in Python 2) +t(l, "p)p", "const char*", "ccp_plus_one", "(const char*)", ' NULL => NULL+1=1', None) # NULL, addin gone will result in 0x1 # functions that change buffers theader('TESTS OF IMMUTABLE AND MUTABLE PYTHON BUFFERS:')