diff options
author | Jonathan Beck | 2009-10-18 13:02:29 +0200 |
---|---|---|
committer | Jonathan Beck | 2009-10-18 13:02:29 +0200 |
commit | ba71f950c188ff3ff1524935dc7794aea214ddd9 (patch) | |
tree | 9e12d3f4ef36ed5648efdc4eae5478f83983ae67 /swig/plist.i | |
parent | 7fa91f0b07b2ffd2143041cb52b8405d152e7b05 (diff) | |
download | libplist-ba71f950c188ff3ff1524935dc7794aea214ddd9.tar.gz libplist-ba71f950c188ff3ff1524935dc7794aea214ddd9.tar.bz2 |
Reduce Python specific code in swig header.
Diffstat (limited to 'swig/plist.i')
-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 @@ #include <plist/plist.h> #include <plist/plist++.h> -#include <ctime> -//for datetime in python -#include <datetime.h> - typedef struct { plist_t node; char should_keep_plist; @@ -29,22 +25,26 @@ PListNode *allocate_plist_wrapper(plist_t plist, char should_keep_plist) { %include "std_string.i" -#if SWIGPYTHON + %typemap(out) std::vector<char> { - $result = PyString_FromStringAndSize((const char*)&($1[0]),(int)($1.size())); + $result = SWIG_FromCharPtrAndSize((const char*)&($1[0]),(int)($1.size())); } %typemap(in) (const std::vector<char>& v) { - if (!PyString_Check($input)) { - PyErr_SetString(PyExc_ValueError,"Expected a string"); - return NULL; - } - char* buffer = PyString_AsString($input); - int length = PyString_Size($input); + char* buffer = NULL; + int length = 0; + SWIG_AsCharPtrAndSize($input, &buffer, &length, NULL); $1 = std::vector<char>(buffer, buffer + length); } +#if SWIGPYTHON +//for datetime in python +%{ +#include <ctime> +#include <datetime.h> +%} + %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) timeval { PyDateTime_IMPORT; $1 = PyDateTime_Check($input) ? 1 : 0; @@ -78,6 +78,7 @@ PListNode *allocate_plist_wrapper(plist_t plist, char should_keep_plist) { timeval ret = {(int)mktime(&t), PyDateTime_DATE_GET_MICROSECOND($input)}; $1 = ret; } +#endif %apply SWIGTYPE *DYNAMIC { PList::Node* }; %apply SWIGTYPE *DYNAMIC { PList::Structure* }; @@ -127,9 +128,6 @@ static swig_type_info *Node_dynamic(void **ptr) DYNAMIC_CAST(SWIGTYPE_p_PList__Node, Node_dynamic); DYNAMIC_CAST(SWIGTYPE_p_PList__Structure, Node_dynamic); -#else -#endif - %rename(__assign__) *::operator=; %rename(__getitem__) *::operator[]; |