Skip to content

Commit

Permalink
solve SoAsciiText unicode/bytes-problem
Browse files Browse the repository at this point in the history
  • Loading branch information
looooo committed Oct 16, 2018
1 parent 7af5e02 commit 75fb1c9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
16 changes: 14 additions & 2 deletions Inventor/fields/SoMFName.i
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@
if (len > 0) {
$1 = (char **)malloc(len * sizeof(char *));
for (int i = 0; i < len; i++) {
PyObject * item = PyObject_Str(PySequence_GetItem($input,i));
#ifdef PY_2
PyObject * item = PyObject_Str(PySequence_GetItem($input,i));
$1[i] = PyString_AsString(item);
#else
$1[i] = PyBytes_AsString(PyUnicode_AsEncodedString(item, "utf-8", "Error ~"));
PyObject * item = PySequence_GetItem($input,i);
if (PyBytes_Check(item))
{
$1[i] = PyBytes_AsString(item);
}
else if (PyUnicode_Check(item))
{
$1[i] = PyBytes_AsString(PyUnicode_AsEncodedString(item, "utf-8", "Error ~"));
}
else
{
$1[i] = PyBytes_AsString(PyUnicode_AsEncodedString(PyObject_Str(item), "utf-8", "Error ~"));
}
#endif
Py_DECREF(item);
}
Expand Down
2 changes: 1 addition & 1 deletion Inventor/fields/SoMFPlane.i
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
SbPlane * plane = NULL;
PyObject * item = PyList_GetItem($input,i);
SWIG_ConvertPtr(item, (void **) &plane, $1_descriptor, 1);
if (time != NULL) { $1[i] = *plane; }
$1[i] = *plane;
}
} else { $1 = NULL; }
} else {
Expand Down
29 changes: 22 additions & 7 deletions Inventor/fields/SoMFString.i
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
%typemap(in) const char * [] {
int len;
/* typemap for char* is used from SoMFName!!! */
/* maybe it's not possible to define two typemaps for the same type? */
/*
%typemap(in) const char * strings[] {
int len;
if (PySequence_Check($input)) {
len = PySequence_Length($input);
if (len > 0) {
$1 = (char **)malloc(len * sizeof(char *));
for (int i = 0; i < len; i++ ) {
PyObject * item = PyObject_Str(PySequence_GetItem($input,i));
for (int i = 0; i < len; i++) {
#ifdef PY_2
PyObject * item = PyObject_Str(PySequence_GetItem($input,i));
$1[i] = PyString_AsString(item);
#else
$1[i] = PyBytes_AsString(item);
PyObject * item = PySequence_GetItem($input,i);
if (PyBytes_Check(item))
{
$1[i] = PyBytes_AsString(item);
}
else if (PyUnicode_Check(item))
{
$1[i] = PyBytes_AsString(PyUnicode_AsEncodedString(item, "utf-8", "Error ~"));
}
else
{
$1[i] = PyBytes_AsString(PyUnicode_AsEncodedString(PyObject_Str(item), "utf-8", "Error ~"));
}
#endif
Py_DECREF(item);
}
}
else { $1 = NULL; }
} else { $1 = NULL; }
} else {
PyErr_SetString(PyExc_TypeError, "expected a sequence.");
return NULL;
}
}
*/

/* free the list */
%typemap(freearg) const char * [] {
Expand Down
2 changes: 1 addition & 1 deletion Inventor/fields/SoMFTime.i
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
SbTime * time = NULL;
PyObject * item = PyList_GetItem($input,i);
SWIG_ConvertPtr(item, (void **) &time, $1_descriptor, 1);
if (time != NULL) { $1[i] = *time; }
$1[i] = *time;
}
} else { $1 = NULL; }
} else {
Expand Down

0 comments on commit 75fb1c9

Please sign in to comment.