Skip to content

Commit

Permalink
Replace uses of PyUnicode_FromString with PyUnicode_FromStringAndSize
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcamilleri committed Aug 31, 2021
1 parent 901c3f9 commit 8061a9e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/runtime/python/pypgf.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#if PY_MAJOR_VERSION >= 3
#define PyString_Check PyUnicode_Check
#define PyString_FromString PyUnicode_FromString
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
#define PyString_FromFormat PyUnicode_FromFormat
#define PyString_Concat(ps,s) {PyObject* tmp = *(ps); *(ps) = PyUnicode_Concat(tmp,s); Py_DECREF(tmp);}
Expand Down Expand Up @@ -2867,7 +2866,7 @@ static PyObject*
PGF_getAbstractName(PGFObject *self, void *closure)
{
PgfText* txt = pgf_abstract_name(self->pgf);
return PyString_FromString(txt->text);
return PyString_FromStringAndSize(txt->text, txt->size);
}

// static void
Expand Down Expand Up @@ -2965,7 +2964,7 @@ pgf_collect_cats(PgfItor* fn, PgfText* key, void* value, PgfExn *err)

PyObject* py_name = NULL;

py_name = PyString_FromString(name->text);
py_name = PyString_FromStringAndSize(name->text, name->size);
if (py_name == NULL) {
err->type = PGF_EXN_OTHER_ERROR;
goto end;
Expand Down Expand Up @@ -3026,7 +3025,7 @@ pgf_collect_funs(PgfItor* fn, PgfText* key, void* value, PgfExn *err)

PyObject* py_name = NULL;

py_name = PyString_FromString(name->text);
py_name = PyString_FromStringAndSize(name->text, name->size);
if (py_name == NULL) {
err->type = PGF_EXN_OTHER_ERROR;
goto end;
Expand Down Expand Up @@ -3720,7 +3719,7 @@ MOD_INIT(pgf)
Py_INCREF(PGFError);

PyObject *dict = PyDict_New();
PyDict_SetItemString(dict, "token", PyString_FromString(""));
PyDict_SetItemString(dict, "token", PyString_FromStringAndSize("", 0));
ParseError = PyErr_NewException("pgf.ParseError", NULL, dict);
PyModule_AddObject(m, "ParseError", ParseError);
Py_INCREF(ParseError);
Expand Down

0 comments on commit 8061a9e

Please sign in to comment.