From: Axel R. <ro...@us...> - 2017-03-15 10:54:37
|
Update of /cvsroot/sdif/Easdif/swig/python In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv30563/swig/python Modified Files: sdiftypemap-python.i Log Message: Summary: Version 1.4.25 - Python 3 fix Fixed typemap for converting strings into sdif signatures. Index: sdiftypemap-python.i =================================================================== RCS file: /cvsroot/sdif/Easdif/swig/python/sdiftypemap-python.i,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** sdiftypemap-python.i 3 Dec 2015 18:03:01 -0000 1.7 --- sdiftypemap-python.i 15 Mar 2017 10:54:34 -0000 1.8 *************** *** 6,9 **** --- 6,14 ---- // // $Log$ + // Revision 1.8 2017/03/15 10:54:34 roebel + // Summary: Version 1.4.25 - Python 3 fix + // + // Fixed typemap for converting strings into sdif signatures. + // // Revision 1.7 2015/12/03 18:03:01 roebel // Added support for python 3. *************** *** 39,52 **** %typemap(in) SdifSignature { if (PyString_Check($input) && (PyString_Size($input) == 4)) { $1 = SdifStringToSignature(PyString_AsString($input)); } ! %#if PY_MAJOR_VERSION < 3 ! else if (PyInt_Check($input)) { $1 = PyInt_AS_LONG($input); } %#else else if (PyInt_Check($input)) { --- 44,76 ---- %typemap(in) SdifSignature { + %#if PY_MAJOR_VERSION < 3 + fprintf(stderr,"StringCheck %d\n",PyString_Check($input)); + if(PyString_Check($input)) + fprintf(stderr,"StringSize %ld\n",PyString_Size($input)); if (PyString_Check($input) && (PyString_Size($input) == 4)) { $1 = SdifStringToSignature(PyString_AsString($input)); } ! else if (PyInt_Check($input)) { $1 = PyInt_AS_LONG($input); } %#else + if (PyUnicode_Check($input) ) + { + Py_ssize_t len = 0; + char *ascii_string = PyUnicode_AsUTF8AndSize($input, &len); + + if (ascii_string==0) { + /* exception is set in conversion function */ + return NULL; + } + if(len ==4) + $1 = SdifStringToSignature(ascii_string); + else{ + PyErr_SetString(PyExc_TypeError, "Signature argument has to be an integer or a 4 char ASCII string"); + return NULL; + } + } else if (PyInt_Check($input)) { *************** *** 57,61 **** else { ! PyErr_SetString(PyExc_TypeError, "Signature argument has to be an integer or a 4 char string"); return NULL; } --- 81,85 ---- else { ! PyErr_SetString(PyExc_TypeError, "Signature argument has to be an integer or a 4 char ASCII string"); return NULL; } |