Skip to content
Snippets Groups Projects
Commit 8b4b8ddc authored by Alex Willmer's avatar Alex Willmer
Browse files

Use PyBytes_* Python CAPI functions

This removes any doubts about what type of string is in use.
parent c8239094
No related branches found
No related tags found
No related merge requests found
%module hammer %module hammer
%begin %{
#define SWIG_PYTHON_STRICT_BYTE_CHAR
%}
%nodefaultctor; %nodefaultctor;
...@@ -83,11 +86,11 @@ ...@@ -83,11 +86,11 @@
PyErr_SetString(PyExc_ValueError, "Expecting a string"); PyErr_SetString(PyExc_ValueError, "Expecting a string");
return NULL; return NULL;
} else { } else {
$1 = *(uint8_t*)PyString_AsString($input); $1 = *(uint8_t*)PyBytes_AsString($input);
} }
} }
%typemap(out) HBytes* { %typemap(out) HBytes* {
$result = PyString_FromStringAndSize((char*)$1->token, $1->len); $result = PyBytes_FromStringAndSize((char*)$1->token, $1->len);
} }
%typemap(out) struct HCountedArray_* { %typemap(out) struct HCountedArray_* {
int i; int i;
...@@ -187,7 +190,7 @@ ...@@ -187,7 +190,7 @@
return PyObject_CallFunctionObjArgs(_helper_Placeholder, NULL); return PyObject_CallFunctionObjArgs(_helper_Placeholder, NULL);
break; break;
case TT_BYTES: case TT_BYTES:
return PyString_FromStringAndSize((char*)token->token_data.bytes.token, token->token_data.bytes.len); return PyBytes_FromStringAndSize((char*)token->token_data.bytes.token, token->token_data.bytes.len);
case TT_SINT: case TT_SINT:
// TODO: return PyINT if appropriate // TODO: return PyINT if appropriate
return PyLong_FromLong(token->token_data.sint); return PyLong_FromLong(token->token_data.sint);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment