abac0-leakabac0-meicompt_changesgec13mei-idmei-rt0-nmei_rt0mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2tvf-new-xml
Last change
on this file since aa33ad9 was
ade843e,
checked in by Mike Ryan <mikeryan@…>, 14 years ago
|
support strings instead of bytearrays in python < 2.6
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | %typemap(argout) bool &success { |
---|
2 | PyObject *o, *o2, *o3; |
---|
3 | o = PyBool_FromLong(*$1); |
---|
4 | if ((!$result) || ($result == Py_None)) { |
---|
5 | $result = o; |
---|
6 | } else { |
---|
7 | if (!PyTuple_Check($result)) { |
---|
8 | PyObject *o2 = $result; |
---|
9 | $result = PyTuple_New(1); |
---|
10 | PyTuple_SetItem($result,0,o2); |
---|
11 | } |
---|
12 | o3 = PyTuple_New(2); |
---|
13 | PyTuple_SetItem(o3,0,o); |
---|
14 | PyTuple_SetItem(o3,1,$result); |
---|
15 | $result = o3; |
---|
16 | } |
---|
17 | } |
---|
18 | |
---|
19 | %typemap(in,numinputs=0) bool &success(bool temp) { |
---|
20 | $1 = &temp; |
---|
21 | } |
---|
22 | |
---|
23 | // bytearrays are new as of 2.6 |
---|
24 | %{ |
---|
25 | #if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 6) || PY_MAJOR_VERSION > 2 |
---|
26 | #define MODERN_PYTHON |
---|
27 | #endif |
---|
28 | %} |
---|
29 | |
---|
30 | // abac_chunk_t is a bytearray or a string |
---|
31 | %typemap(in) abac_chunk_t %{ |
---|
32 | #ifdef MODERN_PYTHON |
---|
33 | $1.ptr = (unsigned char *)PyByteArray_AS_STRING($input); |
---|
34 | $1.len = PyByteArray_GET_SIZE($input); |
---|
35 | #else |
---|
36 | PyString_AsStringAndSize( |
---|
37 | $input, |
---|
38 | (char **)&$1.ptr, |
---|
39 | &$1.len |
---|
40 | ); |
---|
41 | #endif |
---|
42 | %} |
---|
43 | |
---|
44 | %typemap(out) abac_chunk_t %{ |
---|
45 | #ifdef MODERN_PYTHON |
---|
46 | $result = PyByteArray_FromStringAndSize( |
---|
47 | (const char *)$1.ptr, |
---|
48 | $1.len |
---|
49 | ); |
---|
50 | #else |
---|
51 | $result = PyString_FromStringAndSize( |
---|
52 | (const char *)$1.ptr, |
---|
53 | $1.len |
---|
54 | ); |
---|
55 | #endif |
---|
56 | %} |
---|
Note: See
TracBrowser
for help on using the repository browser.