Mercurial > pub > dyncall > bindings
comparison python/pydc/pydcext.c @ 31:622914f1f3bf
- some cleanups
author | Tassilo Philipp |
---|---|
date | Fri, 10 Apr 2020 20:41:48 +0200 |
parents | baf087cf5971 |
children | 2089026debae |
comparison
equal
deleted
inserted
replaced
30:baf087cf5971 | 31:622914f1f3bf |
---|---|
73 { | 73 { |
74 const char* libpath; | 74 const char* libpath; |
75 void* libhandle; | 75 void* libhandle; |
76 | 76 |
77 if (!PyArg_ParseTuple(args,"s", &libpath)) | 77 if (!PyArg_ParseTuple(args,"s", &libpath)) |
78 return PyErr_Format(PyExc_RuntimeError, "libpath argument (string) missing"); | 78 return PyErr_Format(PyExc_RuntimeError, "libpath argument (str) missing"); |
79 | 79 |
80 libhandle = dlLoadLibrary(libpath); | 80 libhandle = dlLoadLibrary(libpath); |
81 | 81 |
82 if (!libhandle) | 82 if (!libhandle) |
83 return PyErr_Format(PyExc_RuntimeError, "dlLoadLibrary('%s') failed", libpath); | 83 return PyErr_Format(PyExc_RuntimeError, "dlLoadLibrary('%s') failed", libpath); |
194 if (PyUnicode_GET_SIZE(po) != 1) | 194 if (PyUnicode_GET_SIZE(po) != 1) |
195 #else | 195 #else |
196 Py_UCS4 cu; | 196 Py_UCS4 cu; |
197 if (PyUnicode_GET_LENGTH(po) != 1) | 197 if (PyUnicode_GET_LENGTH(po) != 1) |
198 #endif | 198 #endif |
199 return PyErr_Format( PyExc_RuntimeError, "arg %d - expecting a string with length of 1 (a char string)", pos ); | 199 return PyErr_Format( PyExc_RuntimeError, "arg %d - expecting a str with length of 1 (a char string)", pos ); |
200 | 200 |
201 #if (PY_VERSION_HEX < 0x03030000) | 201 #if (PY_VERSION_HEX < 0x03030000) |
202 cu = PyUnicode_AS_UNICODE(po)[0]; | 202 cu = PyUnicode_AS_UNICODE(po)[0]; |
203 #else | 203 #else |
204 cu = PyUnicode_ReadChar(po, 0); | 204 cu = PyUnicode_ReadChar(po, 0); |
205 #endif | 205 #endif |
206 // check against UCHAR_MAX in every case b/c Py_UCS4 is unsigned | 206 // check against UCHAR_MAX in every case b/c Py_UCS4 is unsigned |
207 if ( (cu > UCHAR_MAX)) | 207 if ( (cu > UCHAR_MAX)) |
208 return PyErr_Format( PyExc_RuntimeError, "arg %d out of range - expecting a char code", pos ); //@@@ error message needs to specify python types | 208 return PyErr_Format( PyExc_RuntimeError, "arg %d out of range - expecting a char code", pos ); |
209 c = (DCchar) cu; | 209 c = (DCchar) cu; |
210 } | 210 } |
211 else if ( DcPyString_Check(po) ) | 211 else if ( DcPyString_Check(po) ) |
212 { | 212 { |
213 size_t l; | 213 size_t l; |
214 char* s; | 214 char* s; |
215 l = DcPyString_GET_SIZE(po); | 215 l = DcPyString_GET_SIZE(po); |
216 if (l != 1) | 216 if (l != 1) |
217 return PyErr_Format( PyExc_RuntimeError, "arg %d - expecting a string with length of 1 (a char string)", pos ); | 217 return PyErr_Format( PyExc_RuntimeError, "arg %d - expecting a str with length of 1 (a char string)", pos ); |
218 s = DcPyString_AsString(po); | 218 s = DcPyString_AsString(po); |
219 c = (DCchar) s[0]; | 219 c = (DCchar) s[0]; |
220 } | 220 } |
221 else if ( DcPyInt_Check(po) ) | 221 else if ( DcPyInt_Check(po) ) |
222 { | 222 { |
309 p = (DCpointer) PyInt_AS_LONG(po); | 309 p = (DCpointer) PyInt_AS_LONG(po); |
310 #endif | 310 #endif |
311 else if ( PyLong_Check(po) ) | 311 else if ( PyLong_Check(po) ) |
312 p = (DCpointer) PyLong_AsVoidPtr(po); | 312 p = (DCpointer) PyLong_AsVoidPtr(po); |
313 else | 313 else |
314 return PyErr_Format( PyExc_RuntimeError, "arg %d - expecting a promoting pointer-type (int,string)", pos ); //@@@ error message could be better | 314 return PyErr_Format( PyExc_RuntimeError, "arg %d - expecting a promoting pointer-type (int,str)", pos ); |
315 dcArgPointer(gpCall, p); | 315 dcArgPointer(gpCall, p); |
316 Py_XDECREF(bo); | 316 Py_XDECREF(bo); |
317 } | 317 } |
318 break; | 318 break; |
319 | 319 |
325 if((bo = PyUnicode_AsEncodedString(po, "utf-8", "strict"))) // !new ref! | 325 if((bo = PyUnicode_AsEncodedString(po, "utf-8", "strict"))) // !new ref! |
326 p = PyBytes_AS_STRING(bo); // Borrowed pointer | 326 p = PyBytes_AS_STRING(bo); // Borrowed pointer |
327 } else if ( DcPyString_Check(po) ) { | 327 } else if ( DcPyString_Check(po) ) { |
328 p = DcPyString_AsString(po); | 328 p = DcPyString_AsString(po); |
329 } else | 329 } else |
330 return PyErr_Format( PyExc_RuntimeError, "arg %d - expecting a string", pos ); | 330 return PyErr_Format( PyExc_RuntimeError, "arg %d - expecting a str", pos ); |
331 dcArgPointer(gpCall, (DCpointer) p); | 331 dcArgPointer(gpCall, (DCpointer) p); |
332 Py_XDECREF(bo); | 332 Py_XDECREF(bo); |
333 } | 333 } |
334 break; | 334 break; |
335 | 335 |