kindasorta working. all tests (except h_action and h_attr_bool, need typemaps) have passed at one time or another, but some segfault at not-quite-random; h_and, h_epsilon_p, h_end_p, h_ignore, h_not, maybe h_choice seem culprity.
This commit is contained in:
parent
5ced9fe9d5
commit
2e0c56f403
3 changed files with 116 additions and 93 deletions
|
|
@ -1,4 +1,5 @@
|
|||
%module hammer
|
||||
%nodefaultctor;
|
||||
|
||||
%include "stdint.i"
|
||||
//%include "typemaps.i"
|
||||
|
|
@ -7,11 +8,31 @@
|
|||
#if defined(SWIGPYTHON)
|
||||
%ignore HCountedArray_;
|
||||
%typemap(in) uint8_t* {
|
||||
Py_INCREF($input);
|
||||
$1 = (uint8_t*)PyString_AsString($input);
|
||||
}
|
||||
%typemap(out) uint8_t* {
|
||||
$result = PyString_FromString((char*)$1);
|
||||
}
|
||||
%typemap(in) void*[] {
|
||||
if (PyList_Check($input)) {
|
||||
Py_INCREF($input);
|
||||
int size = PyList_Size($input);
|
||||
int i = 0;
|
||||
int res = 0;
|
||||
$1 = (void**)malloc(size*sizeof(HParser*));
|
||||
for (i=0; i<size; i++) {
|
||||
PyObject *o = PyList_GetItem($input, i);
|
||||
res = SWIG_ConvertPtr(o, &($1[i]), SWIGTYPE_p_HParser_, 0 | 0);
|
||||
if (!SWIG_IsOK(res)) {
|
||||
SWIG_exception_fail(SWIG_ArgError(res), "that wasn't an HParser" );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "__a functions take lists of parsers as their argument");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
%typemap(in) uint8_t {
|
||||
if (PyInt_Check($input)) {
|
||||
$1 = PyInt_AsLong($input);
|
||||
|
|
@ -23,11 +44,6 @@
|
|||
$1 = *(uint8_t*)PyString_AsString($input);
|
||||
}
|
||||
}
|
||||
/*
|
||||
%typemap(out) uint8_t {
|
||||
$result = PyString_FromString(&$1);
|
||||
}
|
||||
*/
|
||||
%typemap(out) HBytes* {
|
||||
$result = PyString_FromStringAndSize((char*)$1->token, $1->len);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue