diff options
| author | 2009-10-17 10:41:18 +0200 | |
|---|---|---|
| committer | 2009-10-17 10:41:18 +0200 | |
| commit | 6f453688c0b97ea979b2b2b515f4030e69e846fb (patch) | |
| tree | 68ea509582004bfb5e5df61756e7e8b30ac56dd4 | |
| parent | e6a0149e3be353da436c9b3cbc960233c2df2076 (diff) | |
| download | libplist-6f453688c0b97ea979b2b2b515f4030e69e846fb.tar.gz libplist-6f453688c0b97ea979b2b2b515f4030e69e846fb.tar.bz2 | |
Use custom typemap for binary buffers as we want to hadle them as strings in python.
| -rw-r--r-- | swig/plist.i | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/swig/plist.i b/swig/plist.i index 91124b2..1b97451 100644 --- a/swig/plist.i +++ b/swig/plist.i | |||
| @@ -23,11 +23,26 @@ PListNode *allocate_plist_wrapper(plist_t plist, char should_keep_plist) { | |||
| 23 | } | 23 | } |
| 24 | %} | 24 | %} |
| 25 | 25 | ||
| 26 | %include "stl.i" | 26 | %include "std_string.i" |
| 27 | |||
| 28 | #if SWIGPYTHON | ||
| 29 | %typemap(out) std::vector<char> { | ||
| 30 | $result = PyString_FromStringAndSize((const char*)&($1[0]),(int)($1.size())); | ||
| 31 | } | ||
| 32 | |||
| 33 | %typemap(in) (const std::vector<char>& v) | ||
| 34 | { | ||
| 35 | if (!PyString_Check($input)) { | ||
| 36 | PyErr_SetString(PyExc_ValueError,"Expected a string"); | ||
| 37 | return NULL; | ||
| 38 | } | ||
| 39 | char* buffer = PyString_AsString($input); | ||
| 40 | int length = PyString_Size($input); | ||
| 41 | $1 = std::vector<char>(buffer, buffer + length); | ||
| 42 | } | ||
| 43 | #else | ||
| 44 | #endif | ||
| 27 | 45 | ||
| 28 | namespace std { | ||
| 29 | %template(vectorc) vector<char>; | ||
| 30 | }; | ||
| 31 | 46 | ||
| 32 | %rename(__assign__) *::operator=; | 47 | %rename(__assign__) *::operator=; |
| 33 | %rename(__getitem__) *::operator[]; | 48 | %rename(__getitem__) *::operator[]; |
