Skip to content

Commit

Permalink
Merge pull request #417 from LLNL/bug-mcm86-05sep24-python-overwrite2
Browse files Browse the repository at this point in the history
Fix for python 2 or python 3
  • Loading branch information
markcmiller86 committed Sep 11, 2024
1 parent f9d5898 commit 3c9c530
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 5 additions & 5 deletions tools/python/pydbfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ static PyObject *DBfile_DBWrite(PyObject *self, PyObject *args)
}

PyObject *item = PySequence_GetItem(pydata, 0);
if (PyUnicode_Check(item) && PyUnicode_GET_SIZE(item)==1)
if (PyString_Check(item) && PyString_Size(item)==1)
dtype = DB_CHAR;
else if (PyInt_Check(item))
dtype = DB_INT;
Expand Down Expand Up @@ -639,12 +639,12 @@ static PyObject *DBfile_DBWrite(PyObject *self, PyObject *args)
{
case DB_CHAR:
{
if (!PyUnicode_Check(item) || PyUnicode_GET_SIZE(item)>1)
if (!PyString_Check(item) || PyString_Size(item)>1)
{
PyErr_SetString(PyExc_TypeError, "Data is not a single DB_CHAR");
goto fail_exit;
}
*p = *(PyUnicode_AS_DATA(item));
*p = *(PyString_AsString(item));
break;
}
case DB_SHORT:
Expand All @@ -655,7 +655,7 @@ static PyObject *DBfile_DBWrite(PyObject *self, PyObject *args)
goto fail_exit;
}
short *ps = (short*)p;
*ps = (short) PyInt_AsLong(item);
*ps = (short) PyLong_AsLong(item);
break;
}
case DB_INT:
Expand All @@ -666,7 +666,7 @@ static PyObject *DBfile_DBWrite(PyObject *self, PyObject *args)
goto fail_exit;
}
int *pi = (int*)p;
*pi = (int) PyInt_AsLong(item);
*pi = (int) PyLong_AsLong(item);
break;
}
case DB_LONG:
Expand Down
4 changes: 1 addition & 3 deletions tools/python/pysilo.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,11 @@ void SiloErrorFunc(const char *errString);
#define PyInt_FromLong PyLong_FromLong
#define PyInt_AS_LONG PyLong_AS_LONG
#define PyInt_Check PyLong_Check
#endif

#if PY_VERSION_GE(3,0,0)
#define PyString_FromString PyUnicode_FromString
#define PyString_Check PyUnicode_Check
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
#define PyString_AsString PyUnicode_AsUTF8
#define PyString_Size PyUnicode_GetLength
#endif


Expand Down

0 comments on commit 3c9c530

Please sign in to comment.