Skip to content

Commit

Permalink
Merge pull request #884 from edoapra/flaccid-fraction
Browse files Browse the repository at this point in the history
python 3 fixes
  • Loading branch information
nwchemgit authored Oct 10, 2023
2 parents dd76c40 + 48fac05 commit 7b06d34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions QA/tests/pyqa3/pyqa3.nw
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ end

python
print ("value check:")
print ("INT = "), INT
print ("DBL = "), DBL
print ("CHAR = "), CHAR
print ("LOGICAL = "), LOGICAL
print ("INT = ", INT)
print ("DBL = ", DBL)
print ("CHAR = ", CHAR)
print ("LOGICAL = ", LOGICAL)

rtdb_put("test_int2", 22)
print (' Done 1')
Expand Down
13 changes: 10 additions & 3 deletions src/python/nwchem_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,12 @@ static int check_type(PyObject *obj)
char *Parse_String(PyObject *arg)
{
char *out;
PyObject *ascii_string;
if (PyUnicode_Check(arg)) {
ascii_string = PyUnicode_AsASCIIString(arg);
PyObject* ascii_string = PyUnicode_AsASCIIString(arg);
if (NULL == ascii_string ) {
PyErr_SetString(PyExc_TypeError, "PyUnicode_AsASCIIString failed");
return NULL;
}
out = PyBytes_AsString(ascii_string);
Py_DECREF(ascii_string);
} else if (PyBytes_Check(arg)) {
Expand Down Expand Up @@ -294,7 +297,6 @@ static PyObject *wrap_rtdb_put(PyObject *self, PyObject *args)
void *array = 0;
PyObject *obj, *option_obj;

name = Parse_String(PyTuple_GetItem(args, 0));
obj = PyTuple_GetItem(args, 1);

if (PyList_Check(obj))
Expand Down Expand Up @@ -405,6 +407,7 @@ static PyObject *wrap_rtdb_put(PyObject *self, PyObject *args)
break;
}

name = Parse_String(PyTuple_GetItem(args, 0));
if (!(rtdb_put(rtdb_handle, name, ma_type, list_len, array))) {
PyErr_SetString(NwchemError, "rtdb_put failed");
if ((ma_type != MT_CHAR) && array) free(array);
Expand Down Expand Up @@ -1838,6 +1841,10 @@ void initnwchem()
#endif
if (module == NULL)
INITERROR;

NwchemError = PyErr_NewException("nwchem.NwchemError", NULL, NULL);
PyModule_AddObject(module, "NwchemError", NwchemError);

struct module_state *st = GETSTATE(module);
st->error = PyErr_NewException("nwchem.error", NULL, NULL);
if (st->error == NULL) {
Expand Down

0 comments on commit 7b06d34

Please sign in to comment.