2013-11-16 07:56:47 +01:00
|
|
|
%module hammer
|
2013-11-19 02:41:45 -06:00
|
|
|
%nodefaultctor;
|
2013-11-16 07:56:47 +01:00
|
|
|
|
2013-11-17 15:55:38 -06:00
|
|
|
%include "stdint.i"
|
2013-11-19 00:18:25 -06:00
|
|
|
//%include "typemaps.i"
|
|
|
|
|
//%apply char [ANY] { uint8_t [ANY] };
|
2013-11-18 17:19:46 -06:00
|
|
|
|
|
|
|
|
#if defined(SWIGPYTHON)
|
2013-11-19 00:18:25 -06:00
|
|
|
%ignore HCountedArray_;
|
2013-11-18 17:19:46 -06:00
|
|
|
%typemap(in) uint8_t* {
|
2013-11-19 02:41:45 -06:00
|
|
|
Py_INCREF($input);
|
2013-11-18 17:19:46 -06:00
|
|
|
$1 = (uint8_t*)PyString_AsString($input);
|
|
|
|
|
}
|
2013-11-18 21:14:44 -06:00
|
|
|
%typemap(out) uint8_t* {
|
|
|
|
|
$result = PyString_FromString((char*)$1);
|
|
|
|
|
}
|
2013-11-22 19:42:02 -06:00
|
|
|
|
|
|
|
|
%typemap(newfree) HParseResult* {
|
|
|
|
|
h_parse_result_free($1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%newobject h_parse
|
|
|
|
|
%delobject h_parse_result_free
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
%typemap(in) (uint8_t* str, size_t len) {
|
|
|
|
|
if (PyString_Check($input) ||
|
|
|
|
|
PyUnicode_Check($input)) {
|
|
|
|
|
PyString_AsStringAndSize($input, (char**)&$1, &$2);
|
|
|
|
|
} else {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "Argument must be a str or unicode");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
%apply (char *STRING, size_t LENGTH) {(uint8_t* str, size_t len)}
|
|
|
|
|
%apply (uint8_t* str, size_t len) {(const uint8_t* input, size_t length)}
|
|
|
|
|
%apply (uint8_t* str, size_t len) {(const uint8_t* str, const size_t len)}
|
|
|
|
|
%apply (uint8_t* str, size_t len) {(const uint8_t* charset, size_t length)}
|
2013-11-19 02:41:45 -06:00
|
|
|
%typemap(in) void*[] {
|
|
|
|
|
if (PyList_Check($input)) {
|
|
|
|
|
Py_INCREF($input);
|
|
|
|
|
int size = PyList_Size($input);
|
|
|
|
|
int i = 0;
|
|
|
|
|
int res = 0;
|
2013-11-22 19:42:02 -06:00
|
|
|
$1 = (void**)malloc((size+1)*sizeof(HParser*));
|
2013-11-19 02:41:45 -06:00
|
|
|
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" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-22 19:42:02 -06:00
|
|
|
$1[size] = NULL;
|
2013-11-19 02:41:45 -06:00
|
|
|
} else {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "__a functions take lists of parsers as their argument");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-18 21:50:28 -06:00
|
|
|
%typemap(in) uint8_t {
|
|
|
|
|
if (PyInt_Check($input)) {
|
|
|
|
|
$1 = PyInt_AsLong($input);
|
|
|
|
|
}
|
|
|
|
|
else if (!PyString_Check($input)) {
|
|
|
|
|
PyErr_SetString(PyExc_ValueError, "Expecting a string");
|
|
|
|
|
return NULL;
|
|
|
|
|
} else {
|
|
|
|
|
$1 = *(uint8_t*)PyString_AsString($input);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
%typemap(out) HBytes* {
|
|
|
|
|
$result = PyString_FromStringAndSize((char*)$1->token, $1->len);
|
|
|
|
|
}
|
2013-11-19 00:18:25 -06:00
|
|
|
%typemap(out) struct HCountedArray_* {
|
|
|
|
|
int i;
|
|
|
|
|
$result = PyList_New($1->used);
|
|
|
|
|
for (i=0; i<$1->used; i++) {
|
|
|
|
|
HParsedToken *t = $1->elements[i];
|
|
|
|
|
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_HParsedToken_, 0 | 0);
|
|
|
|
|
PyList_SetItem($result, i, o);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-18 17:19:46 -06:00
|
|
|
#else
|
2013-11-18 21:14:44 -06:00
|
|
|
#warning no uint8_t* typemaps defined
|
2013-11-18 17:19:46 -06:00
|
|
|
#endif
|
2013-11-17 15:55:38 -06:00
|
|
|
|
|
|
|
|
// All the include paths are relative to the build, i.e., ../../. If you need to build these manually (i.e., not with scons), keep that in mind.
|
2013-11-16 20:24:05 +01:00
|
|
|
%{
|
|
|
|
|
#include "allocator.h"
|
|
|
|
|
#include "hammer.h"
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
%}
|
|
|
|
|
%include "allocator.h"
|
|
|
|
|
%include "hammer.h"
|
|
|
|
|
|