2007-10-20 09:03:51 +02:00
|
|
|
// Convert an incoming Python list to a tid_t[] array
|
|
|
|
%typemap(in) tid_t[ANY](tid_t temp[$1_dim0]) {
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
if (!PySequence_Check($input))
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_TypeError,"Expecting a sequence");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cap the number of elements to copy */
|
|
|
|
len = PySequence_Length($input) < $1_dim0 ? PySequence_Length($input) : $1_dim0;
|
|
|
|
|
|
|
|
for (i =0; i < len; i++)
|
|
|
|
{
|
|
|
|
PyObject *o = PySequence_GetItem($input,i);
|
|
|
|
if (!PyLong_Check(o))
|
|
|
|
{
|
|
|
|
Py_XDECREF(o);
|
|
|
|
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of long integers");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp[i] = PyLong_AsUnsignedLong(o);
|
|
|
|
Py_DECREF(o);
|
|
|
|
}
|
|
|
|
$1 = &temp[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
%define %cstring_output_maxstr_none(TYPEMAP, SIZE)
|
|
|
|
%typemap (default) SIZE {
|
2009-05-23 18:35:50 +02:00
|
|
|
$1 = MAXSTR;
|
|
|
|
}
|
2007-10-20 09:03:51 +02:00
|
|
|
%typemap(in,numinputs=0) (TYPEMAP, SIZE) {
|
|
|
|
#ifdef __cplusplus
|
2009-05-23 18:35:50 +02:00
|
|
|
$1 = ($1_ltype) new char[MAXSTR+1];
|
2007-10-20 09:03:51 +02:00
|
|
|
#else
|
2009-05-23 18:35:50 +02:00
|
|
|
$1 = ($1_ltype) malloc(MAXSTR+1);
|
2007-10-20 09:03:51 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
%typemap(out) ssize_t {
|
|
|
|
/* REMOVING ssize_t return value in $symname */
|
|
|
|
}
|
|
|
|
%typemap(argout) (TYPEMAP,SIZE) {
|
2009-05-23 18:35:50 +02:00
|
|
|
if (result > 0)
|
|
|
|
{
|
|
|
|
resultobj = PyString_FromString($1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
resultobj = Py_None;
|
|
|
|
}
|
2007-10-20 09:03:51 +02:00
|
|
|
#ifdef __cplusplus
|
2009-05-23 18:35:50 +02:00
|
|
|
delete [] $1;
|
2007-10-20 09:03:51 +02:00
|
|
|
#else
|
2009-05-23 18:35:50 +02:00
|
|
|
free($1);
|
2007-10-20 09:03:51 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
%enddef
|
|
|
|
|
|
|
|
%define %cstring_bounded_output_none(TYPEMAP,MAX)
|
|
|
|
%typemap(in, numinputs=0) TYPEMAP(char temp[MAX+1]) {
|
2009-05-23 18:35:50 +02:00
|
|
|
$1 = ($1_ltype) temp;
|
2007-10-20 09:03:51 +02:00
|
|
|
}
|
|
|
|
%typemap(argout,fragment="t_output_helper") TYPEMAP {
|
2009-05-23 18:35:50 +02:00
|
|
|
PyObject *o;
|
|
|
|
$1[MAX] = 0;
|
2007-10-20 09:03:51 +02:00
|
|
|
|
2009-05-23 18:35:50 +02:00
|
|
|
if ($1 > 0)
|
|
|
|
{
|
|
|
|
o = PyString_FromString($1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
o = Py_None;
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
}
|
|
|
|
$result = t_output_helper($result,o);
|
2007-10-20 09:03:51 +02:00
|
|
|
}
|
|
|
|
%enddef
|
|
|
|
|
2009-03-29 18:54:13 +02:00
|
|
|
%define %binary_output_or_none(TYPEMAP, SIZE)
|
|
|
|
%typemap (default) SIZE {
|
2009-05-23 18:35:50 +02:00
|
|
|
$1 = MAXSPECSIZE;
|
2009-03-29 18:54:13 +02:00
|
|
|
}
|
|
|
|
%typemap(in,numinputs=0) (TYPEMAP, SIZE) {
|
|
|
|
#ifdef __cplusplus
|
2009-05-23 18:35:50 +02:00
|
|
|
$1 = (char *) new char[MAXSPECSIZE+1];
|
2009-03-29 18:54:13 +02:00
|
|
|
#else
|
2009-05-23 18:35:50 +02:00
|
|
|
$1 = (char *) malloc(MAXSPECSIZE+1);
|
2009-03-29 18:54:13 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
%typemap(out) ssize_t {
|
|
|
|
/* REMOVING ssize_t return value in $symname */
|
|
|
|
}
|
|
|
|
%typemap(argout) (TYPEMAP,SIZE) {
|
2009-05-23 18:35:50 +02:00
|
|
|
if (result > 0)
|
|
|
|
{
|
|
|
|
resultobj = PyString_FromStringAndSize((char *)$1, result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
resultobj = Py_None;
|
|
|
|
}
|
2009-03-29 18:54:13 +02:00
|
|
|
#ifdef __cplusplus
|
2009-05-23 18:35:50 +02:00
|
|
|
delete [] (char *)$1;
|
2009-03-29 18:54:13 +02:00
|
|
|
#else
|
2009-05-23 18:35:50 +02:00
|
|
|
free((char *)$1);
|
2009-03-29 18:54:13 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
%enddef
|
|
|
|
|
2009-05-04 21:07:51 +02:00
|
|
|
%define %binary_output_with_size(TYPEMAP, SIZE)
|
|
|
|
%typemap (default) SIZE {
|
|
|
|
size_t ressize = MAXSPECSIZE;
|
|
|
|
$1 = &ressize;
|
|
|
|
}
|
|
|
|
%typemap(in,numinputs=0) (TYPEMAP, SIZE) {
|
|
|
|
#ifdef __cplusplus
|
|
|
|
$1 = (char *) new char[MAXSPECSIZE+1];
|
|
|
|
#else
|
|
|
|
$1 = (char *) malloc(MAXSPECSIZE+1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
%typemap(out) ssize_t {
|
|
|
|
/* REMOVING ssize_t return value in $symname */
|
|
|
|
}
|
|
|
|
%typemap(argout) (TYPEMAP,SIZE) {
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
resultobj = PyString_FromStringAndSize((char *)$1, *$2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Py_INCREF(Py_None);
|
2011-04-18 18:07:00 +02:00
|
|
|
resultobj = Py_None;
|
2009-05-04 21:07:51 +02:00
|
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
|
|
delete [] (char *)$1;
|
|
|
|
#else
|
|
|
|
free((char *)$1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
%enddef
|
|
|
|
|
2009-05-23 18:35:50 +02:00
|
|
|
// Check that the argument is a callable Python object
|
2008-08-17 19:45:06 +02:00
|
|
|
%typemap(in) PyObject *pyfunc {
|
2009-05-23 18:35:50 +02:00
|
|
|
if (!PyCallable_Check($input)) {
|
2011-04-18 18:07:00 +02:00
|
|
|
PyErr_SetString(PyExc_TypeError, "Expected a callable object");
|
2009-05-23 18:35:50 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
$1 = $input;
|
2008-08-17 19:45:06 +02:00
|
|
|
}
|
2011-04-18 18:07:00 +02:00
|
|
|
|
|
|
|
// Convert ea_t
|
|
|
|
%typemap(in) ea_t
|
|
|
|
{
|
|
|
|
uint64 $1_temp;
|
|
|
|
if ( !PyW_GetNumber($input, &$1_temp) )
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_TypeError, "Expected an ea_t type");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
$1 = ea_t($1_temp);
|
|
|
|
}
|