diff options
Diffstat (limited to 'swig')
| -rw-r--r-- | swig/plist.i | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/swig/plist.i b/swig/plist.i index 0a40cf6..e3c2be2 100644 --- a/swig/plist.i +++ b/swig/plist.i | |||
| @@ -6,10 +6,6 @@ | |||
| 6 | #include <plist/plist.h> | 6 | #include <plist/plist.h> |
| 7 | #include <plist/plist++.h> | 7 | #include <plist/plist++.h> |
| 8 | 8 | ||
| 9 | #include <ctime> | ||
| 10 | //for datetime in python | ||
| 11 | #include <datetime.h> | ||
| 12 | |||
| 13 | typedef struct { | 9 | typedef struct { |
| 14 | plist_t node; | 10 | plist_t node; |
| 15 | char should_keep_plist; | 11 | char should_keep_plist; |
| @@ -29,22 +25,26 @@ PListNode *allocate_plist_wrapper(plist_t plist, char should_keep_plist) { | |||
| 29 | 25 | ||
| 30 | %include "std_string.i" | 26 | %include "std_string.i" |
| 31 | 27 | ||
| 32 | #if SWIGPYTHON | 28 | |
| 33 | %typemap(out) std::vector<char> { | 29 | %typemap(out) std::vector<char> { |
| 34 | $result = PyString_FromStringAndSize((const char*)&($1[0]),(int)($1.size())); | 30 | $result = SWIG_FromCharPtrAndSize((const char*)&($1[0]),(int)($1.size())); |
| 35 | } | 31 | } |
| 36 | 32 | ||
| 37 | %typemap(in) (const std::vector<char>& v) | 33 | %typemap(in) (const std::vector<char>& v) |
| 38 | { | 34 | { |
| 39 | if (!PyString_Check($input)) { | 35 | char* buffer = NULL; |
| 40 | PyErr_SetString(PyExc_ValueError,"Expected a string"); | 36 | int length = 0; |
| 41 | return NULL; | 37 | SWIG_AsCharPtrAndSize($input, &buffer, &length, NULL); |
| 42 | } | ||
| 43 | char* buffer = PyString_AsString($input); | ||
| 44 | int length = PyString_Size($input); | ||
| 45 | $1 = std::vector<char>(buffer, buffer + length); | 38 | $1 = std::vector<char>(buffer, buffer + length); |
| 46 | } | 39 | } |
| 47 | 40 | ||
| 41 | #if SWIGPYTHON | ||
| 42 | //for datetime in python | ||
| 43 | %{ | ||
| 44 | #include <ctime> | ||
| 45 | #include <datetime.h> | ||
| 46 | %} | ||
| 47 | |||
| 48 | %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) timeval { | 48 | %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) timeval { |
| 49 | PyDateTime_IMPORT; | 49 | PyDateTime_IMPORT; |
| 50 | $1 = PyDateTime_Check($input) ? 1 : 0; | 50 | $1 = PyDateTime_Check($input) ? 1 : 0; |
| @@ -78,6 +78,7 @@ PListNode *allocate_plist_wrapper(plist_t plist, char should_keep_plist) { | |||
| 78 | timeval ret = {(int)mktime(&t), PyDateTime_DATE_GET_MICROSECOND($input)}; | 78 | timeval ret = {(int)mktime(&t), PyDateTime_DATE_GET_MICROSECOND($input)}; |
| 79 | $1 = ret; | 79 | $1 = ret; |
| 80 | } | 80 | } |
| 81 | #endif | ||
| 81 | 82 | ||
| 82 | %apply SWIGTYPE *DYNAMIC { PList::Node* }; | 83 | %apply SWIGTYPE *DYNAMIC { PList::Node* }; |
| 83 | %apply SWIGTYPE *DYNAMIC { PList::Structure* }; | 84 | %apply SWIGTYPE *DYNAMIC { PList::Structure* }; |
| @@ -127,9 +128,6 @@ static swig_type_info *Node_dynamic(void **ptr) | |||
| 127 | DYNAMIC_CAST(SWIGTYPE_p_PList__Node, Node_dynamic); | 128 | DYNAMIC_CAST(SWIGTYPE_p_PList__Node, Node_dynamic); |
| 128 | DYNAMIC_CAST(SWIGTYPE_p_PList__Structure, Node_dynamic); | 129 | DYNAMIC_CAST(SWIGTYPE_p_PList__Structure, Node_dynamic); |
| 129 | 130 | ||
| 130 | #else | ||
| 131 | #endif | ||
| 132 | |||
| 133 | 131 | ||
| 134 | %rename(__assign__) *::operator=; | 132 | %rename(__assign__) *::operator=; |
| 135 | %rename(__getitem__) *::operator[]; | 133 | %rename(__getitem__) *::operator[]; |
