summaryrefslogtreecommitdiff
path: root/Lib/python
diff options
context:
space:
mode:
authorMarcelo Matus <mmatus@acms.arizona.edu>2004-05-27 11:25:31 +0000
committerMarcelo Matus <mmatus@acms.arizona.edu>2004-05-27 11:25:31 +0000
commit12af360d6f54e2308fc38964eee40bb412bd045c (patch)
treee505616b881837a2d582fc233e202d9a1299b612 /Lib/python
parentd062b8cce8916a7528e82f7e775fe878ab00fb2a (diff)
downloadswig-12af360d6f54e2308fc38964eee40bb412bd045c.tar.gz
fixes for char[], const char[], and cleaning wchar_t
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5930 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Lib/python')
-rw-r--r--Lib/python/pystrbase.swg268
-rw-r--r--Lib/python/pystrings.swg232
-rw-r--r--Lib/python/python.swg2
-rw-r--r--Lib/python/pywstrings.swg236
-rw-r--r--Lib/python/std_wstring.i2
-rw-r--r--Lib/python/wchar.i7
6 files changed, 294 insertions, 453 deletions
diff --git a/Lib/python/pystrbase.swg b/Lib/python/pystrbase.swg
new file mode 100644
index 000000000..88122da50
--- /dev/null
+++ b/Lib/python/pystrbase.swg
@@ -0,0 +1,268 @@
+/* ------------------------------------------------------------
+ * String typemaps for type Char (char or wchar_t)
+ * ------------------------------------------------------------ */
+
+%define %typemap_pystring(Char,
+ SWIG_AsCharPtr,
+ SWIG_AsCharPtrAndSize,
+ SWIG_FromCharPtr,
+ SWIG_AsNewCharPtr,
+ SWIG_AsCharArray,
+ SWIG_FromCharArray)
+/* in */
+
+%typemap(in,fragment=#SWIG_AsCharPtr)
+ Char *, Char const*, Char *const, Char const *const
+ "if (!SWIG_AsCharPtr($input, (Char**)&$1)) SWIG_fail;";
+
+%typemap(in,fragment=#SWIG_AsCharPtr)
+ Char const*&, Char *const&, Char const *const &
+{
+ $*ltype temp;
+ if (!SWIG_AsCharPtr($input, (Char**)&temp)) SWIG_fail;
+ $1 = &temp;
+}
+
+/* out */
+
+%typemap(out,fragment=#SWIG_FromCharPtr)
+ Char *, Char const*, Char *const, Char const *const
+ "$result = SWIG_FromCharPtr($1);";
+
+%typemap(out,fragment=#SWIG_FromCharPtr)
+ Char *const &, Char const* &, Char const *const &
+ "$result = SWIG_FromCharPtr(*$1);";
+
+/* varin */
+
+%typemap(varin,fragment=#SWIG_AsNewCharPtr) Char *
+{
+ Char *cptr = 0;
+ if (!SWIG_AsNewCharPtr($input, &cptr)) {
+ PyErr_Clear();
+ PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'");
+ return 1;
+ }
+ if ($1) swig_delete_array($1);
+ $1 = cptr;
+}
+
+%typemap(varin,fragment=#SWIG_AsNewCharPtr,
+ warning="451:Setting const Char * variable may leak memory")
+ const Char *
+{
+ Char *cptr;
+ if (!SWIG_AsNewCharPtr($input, &cptr)) {
+ PyErr_Clear();
+ PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'");
+ return 1;
+ }
+ $1 = cptr;
+}
+
+/* varout */
+
+%typemap(varout,fragment=#SWIG_FromCharPtr)
+ Char*, Char const*, Char *const, Char const *const
+ "$result = SWIG_FromCharPtr($1);";
+
+/* constant */
+
+%typemap(constcode,fragment=#SWIG_FromCharPtr)
+ Char *, Char const*, Char * const, Char const* const
+ "PyDict_SetItemString(d,\"$symname\", SWIG_FromCharPtr($value));";
+
+/* directorin */
+
+%typemap(directorin,fragment=#SWIG_FromCharPtr)
+ Char *, Char const*, Char *const, Char const *const,
+ Char const *&, Char *const &, Char const *const &
+ "$input = SWIG_NewPointerObj((Char*)($1_name), $descriptor(Char *), 0);"
+ /* "$input = SWIG_FromCharPtr($1_name);"; */
+
+
+/* directorout */
+
+%typemap(directorout,fragment=#SWIG_AsCharPtr)
+ Char *, Char const*, Char *const, Char const* const
+ "if (!SWIG_AsCharPtr($input, (Char**) &$result)) {
+ Swig::DirectorTypeMismatchException(\"Error converting Python object into Char*\");
+ }";
+
+%typemap(directorout,fragment=#SWIG_AsCharPtr)
+ Char const *&, Char *const &, Char const *const &
+{
+ Char* temp;
+ if (!SWIG_AsCharPtr($input, &temp)) {
+ Swig::DirectorTypeMismatchException("Error converting Python object into Char*");
+ }
+ $result = ($1_ltype) &temp;
+}
+
+/* typecheck */
+
+%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING,
+ fragment=#SWIG_AsCharPtr)
+ Char *, Char const*, Char *const, Char const *const,
+ Char const*&, Char *const&, Char const *const &
+ "$1 = SWIG_AsCharPtr($input, (Char **)(0));";
+
+/* throws */
+
+%typemap(throws,fragment=#SWIG_FromCharPtr)
+ Char *, Char const*, Char * const, Char const* const
+{
+ PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharPtr($1));
+ SWIG_fail;
+}
+
+
+/* ------------------------------------------------------------
+ * Unknown size const Character array Char[ANY] handling
+ * ------------------------------------------------------------ */
+
+%typemap(in) Char [] = Char *;
+%typemap(in) const Char [] = Char *;
+%typemap(out) Char [] = Char *;
+%typemap(out) const Char [] = const Char *;
+%typemap(varout) Char [] = Char *;
+%typemap(varout) const Char [] = const Char *;
+%typemap(constcode) Char [] = Char *;
+%typemap(directorin) Char [] = Char *;
+%typemap(directorin) const Char [] = Char *;
+%typemap(directorout) Char [] = Char *;
+%typemap(typecheck) Char [] = Char *;
+%typemap(typecheck) const Char [] = Char *;
+
+%typemap(varin,fragment=#SWIG_AsCharArray) Char []
+{
+ if (!SWIG_AsCharArray($input, $1, sizeof($1))) {
+ PyErr_Clear();
+ PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'");
+ return 1;
+ }
+}
+
+%typemap(varout,fragment=#SWIG_FromCharArray) const Char []
+ "$result = SWIG_FromCharArray($1, sizeof($1));";
+
+
+/* ------------------------------------------------------------
+ * Fix size Character array Char[ANY] handling
+ * ------------------------------------------------------------ */
+
+/* memberin and globalin typemaps */
+
+%typemap(memberin) Char [ANY]
+{
+ if ($input) memcpy($1,$input,$1_dim0*sizeof(Char));
+ else memset($1,0,$1_dim0*sizeof(Char));
+}
+
+%typemap(globalin) Char [ANY]
+{
+ if ($input) memcpy($1,$input,$1_dim0*sizeof(Char));
+ else memset($1,0,$1_dim0*sizeof(Char));
+}
+
+/* in */
+
+%typemap(in,fragment=#SWIG_AsCharArray)
+ Char [ANY] (Char temp[$1_dim0]),
+ const Char [ANY](Char temp[$1_dim0])
+{
+ if (!SWIG_AsCharArray($input, temp, $1_dim0)) SWIG_fail;
+ $1 = temp;
+}
+
+%typemap(out,fragment=#SWIG_FromCharArray)
+ Char [ANY], const Char[ANY]
+ "$result = SWIG_FromCharArray($1, $1_dim0);";
+
+
+/* varin */
+
+%typemap(varin,fragment=#SWIG_AsCharArray) Char [ANY]
+{
+ if (!SWIG_AsCharArray($input, $1, $1_dim0)) {
+ PyErr_Clear();
+ PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'");
+ return 1;
+ }
+}
+
+/* varout */
+
+%typemap(varout,fragment=#SWIG_FromCharArray)
+ Char [ANY], const Char [ANY]
+{
+ size_t size = $1_dim0;
+ //while (size && ($1[size - 1] == '\0')) --size;
+ $result = SWIG_FromCharArray($1, size);
+}
+
+/* constants */
+
+%typemap(constcode,fragment=#SWIG_FromCharArray)
+ Char [ANY], const Char [ANY]
+ "PyDict_SetItemString(d,\"$symname\", SWIG_FromCharArray($value, $value_dim0));";
+
+/* directorin */
+
+%typemap(directorin,fragment=#SWIG_FromCharArray)
+ Char [ANY], const Char [ANY]
+ "$input = SWIG_FromCharArray($1_name, $1_dim0);";
+
+/* directorout */
+
+%typemap(directorout,fragment=#SWIG_AsCharArray)
+ Char [ANY], const Char [ANY] (Char temp[$result_dim0])
+{
+ if (!SWIG_AsCharArray($input, temp, $result_dim0)) {
+ Swig::DirectorTypeMismatchException("Error converting Python object into Char[$result_dim0]");
+ }
+ $result = temp;
+}
+
+/* typecheck */
+
+%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING,
+ fragment=#SWIG_AsCharArray)
+ Char [ANY], const Char[ANY]
+ "$1 = SWIG_AsCharArray($input, (Char *)0, $1_dim0);";
+
+/* throws */
+
+%typemap(throws,fragment=#SWIG_FromCharArray)
+ Char [ANY], const Char[ANY]
+{
+ PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharArray($1, $1_dim0));
+ SWIG_fail;
+}
+
+
+
+/* ------------------------------------------------------------
+ * --- String & length ---
+ * ------------------------------------------------------------ */
+
+/* Here len doesn't include the '0' terminator */
+%typemap(in, fragment=#SWIG_AsCharPtrAndSize)
+ (Char *STRING, int LENGTH) (Char *buf, size_t size)
+{
+ int res = SWIG_AsCharPtrAndSize($input, &buf, &size);
+ if (!res) SWIG_fail;
+ $1 = ($1_ltype) buf;
+ $2 = ($2_ltype) size - 1;
+}
+
+/* Here size includes the '0' terminator */
+%typemap(in,fragment=#SWIG_AsCharPtrAndSize)
+ (Char *STRING, int SIZE) (Char *buf, size_t size)
+{
+ if (!SWIG_AsCharPtrAndSize($input, &buf, &size)) SWIG_fail;
+ $1 = ($1_ltype) buf;
+ $2 = ($2_ltype) size;
+}
+
+%enddef
diff --git a/Lib/python/pystrings.swg b/Lib/python/pystrings.swg
index c55be83bd..9116391c6 100644
--- a/Lib/python/pystrings.swg
+++ b/Lib/python/pystrings.swg
@@ -1,6 +1,6 @@
/* ------------------------------------------------------------
- * utility methods for strings handling
+ * utility methods for char strings
* ------------------------------------------------------------ */
%types(char *);
@@ -150,226 +150,10 @@ SWIG_FromCharArray(const char* carray, size_t size)
* The plain char * handling
* ------------------------------------------------------------ */
-/* in */
-
-%typemap(in,fragment="SWIG_AsCharPtr")
- char *, char const*, char *const, char const *const
- "if (!SWIG_AsCharPtr($input, (char**)&$1)) SWIG_fail;";
-
-%typemap(in,fragment="SWIG_AsCharPtr")
- char const*&, char *const&, char const *const &
-{
- $*ltype temp;
- if (!SWIG_AsCharPtr($input, (char**)&temp)) SWIG_fail;
- $1 = &temp;
-}
-
-/* out */
-
-%typemap(out,fragment="SWIG_FromCharPtr")
- char *, char const*, char *const, char const *const
- "$result = SWIG_FromCharPtr($1);";
-
-%typemap(out,fragment="SWIG_FromCharPtr")
- char *const &, char const* &, char const *const &
- "$result = SWIG_FromCharPtr(*$1);";
-
-/* varin */
-
-%typemap(varin,fragment="SWIG_AsNewCharPtr") char *
-{
- char *cptr = 0;
- if (!SWIG_AsNewCharPtr($input, &cptr)) {
- PyErr_Clear();
- PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'");
- return 1;
- }
- if ($1) swig_delete_array($1);
- $1 = cptr;
-}
-
-%typemap(varin,fragment="SWIG_AsNewCharPtr",
- warning="451:Setting const char * variable may leak memory")
- const char *
-{
- char *cptr;
- if (!SWIG_AsNewCharPtr($input, &cptr)) {
- PyErr_Clear();
- PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'");
- return 1;
- }
- $1 = cptr;
-}
-
-/* varout */
-
-%typemap(varout,fragment="SWIG_FromCharPtr")
- char*, char const*, char *const, char const *const
- "$result = SWIG_FromCharPtr($1);";
-
-/* constant */
-
-%typemap(constcode,fragment="SWIG_FromCharPtr")
- char *, char const*, char * const, char const* const
- "PyDict_SetItemString(d,\"$symname\", SWIG_FromCharPtr($value));";
-
-/* directorin */
-
-%typemap(directorin,fragment="SWIG_FromCharPtr")
- char *, char const*, char *const, char const *const,
- char const *&, char *const &, char const *const &
- "$input = SWIG_NewPointerObj((char*)($1_name), $descriptor(char *), 0);"
- /* "$input = SWIG_FromCharPtr($1_name);"; */
-
-
-/* directorout */
-
-%typemap(directorout,fragment="SWIG_AsCharPtr")
- char *, char const*, char *const, char const* const
- "if (!SWIG_AsCharPtr($input, (char**) &$result)) {
- Swig::DirectorTypeMismatchException(\"Error converting Python object into char*\");
- }";
-
-%typemap(directorout,fragment="SWIG_AsCharPtr")
- char const *&, char *const &, char const *const &
-{
- char* temp;
- if (!SWIG_AsCharPtr($input, &temp)) {
- Swig::DirectorTypeMismatchException("Error converting Python object into char*");
- }
- $result = ($1_ltype) &temp;
-}
-
-/* typecheck */
-
-%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING,
- fragment="SWIG_AsCharPtr")
- char *, char const*, char *const, char const *const,
- char const*&, char *const&, char const *const &
- "$1 = SWIG_AsCharPtr($input, (char **)(0));";
-
-/* throws */
-
-%typemap(throws,fragment="SWIG_FromCharPtr")
- char *, char const*, char * const, char const* const
-{
- PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharPtr($1));
- SWIG_fail;
-}
-
-
-/* ------------------------------------------------------------
- * Fix size character array char[ANY] handling
- * ------------------------------------------------------------ */
-
-/* memberin and globalin typemaps */
-
-%typemap(memberin) char [ANY]
-{
- if ($input) memcpy($1,$input,$1_dim0);
- else memset($1,0,$1_dim0);
-}
-
-%typemap(globalin) char [ANY]
-{
- if ($input) memcpy($1,$input,$1_dim0);
- else memset($1,0,$1_dim0);
-}
-
-/* in */
-
-%typemap(in,fragment="SWIG_AsCharArray")
- char [ANY], const char [ANY]
-{
- char temp[$1_dim0];
- if (!SWIG_AsCharArray($input, temp, $1_dim0)) SWIG_fail;
- $1 = temp;
-}
-
-/* out */
-
-%typemap(out,fragment="SWIG_FromCharArray")
- char [ANY], const char [ANY]
- "$result = SWIG_FromCharArray($1, $1_dim0);";
-
-/* varin */
-
-%typemap(varin,fragment="SWIG_AsCharArray")
- char [ANY]
-{
- if (!SWIG_AsCharArray($input, $1, $1_dim0)) {
- PyErr_Clear();
- PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'");
- return 1;
- }
-}
-
-/* varout */
-
-%typemap(varout,fragment="SWIG_FromCharArray")
- char [ANY], const char [ANY]
- "$result = SWIG_FromCharArray($1, $1_dim0);";
-
-
-/* constants */
-
-%typemap(constcode,fragment="SWIG_FromCharArray")
- char [ANY], const char [ANY]
- "PyDict_SetItemString(d,\"$symname\", SWIG_FromCharArray($value, $value_dim0));";
-
-/* directorin */
-
-%typemap(directorin,fragment="SWIG_FromCharArray")
- char [ANY], const char [ANY]
- "$input = SWIG_FromCharArray($1_name, $1_dim0);";
-
-/* directorout */
-
-%typemap(directorout,fragment="SWIG_AsCharArray")
- char [ANY], const char [ANY] (char temp[$result_dim0])
-{
- if (!SWIG_AsCharArray($input, temp, $result_dim0)) {
- Swig::DirectorTypeMismatchException("Error converting Python object into char[$result_dim0]");
- }
- $result = temp;
-}
-
-/* typecheck */
-
-%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING,
- fragment="SWIG_AsCharArray")
- char [ANY], const char[ANY]
-{
- return SWIG_AsCharArray($input, (char **)0, (size_t *)0);
-}
-
-/* throw */
-
-%typemap(throws,fragment="SWIG_FromCharArray")
- char[ANY], const char[ANY] {
- PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharArray($1,$1_dim0));
- SWIG_fail;
-}
-
-/* ------------------------------------------------------------
- * --- String & length ---
- * ------------------------------------------------------------ */
-
-/* Here len doesn't include the '0' terminator */
-%typemap(in, fragment="SWIG_AsCharPtrAndSize")
- (char *STRING, int LENGTH) (char *buf, size_t size)
-{
- int res = SWIG_AsCharPtrAndSize($input, &buf, &size);
- if (!res) SWIG_fail;
- $1 = ($1_ltype) buf;
- $2 = ($2_ltype) size - 1;
-}
-
-/* Here size includes the '0' terminator */
-%typemap(in,fragment="SWIG_AsCharPtrAndSize")
- (char *STRING, int SIZE) (char *buf, size_t size)
-{
- if (!SWIG_AsCharPtrAndSize($input, &buf, &size)) SWIG_fail;
- $1 = ($1_ltype) buf;
- $2 = ($2_ltype) size;
-}
+%typemap_pystring(char,
+ SWIG_AsCharPtr,
+ SWIG_AsCharPtrAndSize,
+ SWIG_FromCharPtr,
+ SWIG_AsNewCharPtr,
+ SWIG_AsCharArray,
+ SWIG_FromCharArray)
diff --git a/Lib/python/python.swg b/Lib/python/python.swg
index d38e0ff16..93e1ea7d5 100644
--- a/Lib/python/python.swg
+++ b/Lib/python/python.swg
@@ -35,8 +35,8 @@
%include "pyinout.swg"
%include "pyvoid.swg"
%include "pyobject.swg"
+%include "pystrbase.swg"
%include "pystrings.swg"
-%include "pywstrings.swg"
%include "pyvaltypes.swg"
%include "pyptrtypes.swg"
%include "pyprimtypes.swg"
diff --git a/Lib/python/pywstrings.swg b/Lib/python/pywstrings.swg
index 50edbc736..1642f031a 100644
--- a/Lib/python/pywstrings.swg
+++ b/Lib/python/pywstrings.swg
@@ -1,11 +1,8 @@
+
/* ------------------------------------------------------------
- * utility methods for wstrings handling
+ * utility methods for wchar_t strings
* ------------------------------------------------------------ */
-%types(wchar_t *);
-%{
-#include <wchar.h>
-%}
%fragment("SWIG_AsWCharPtrAndSize","header") %{
SWIGSTATIC(int)
SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize)
@@ -149,226 +146,11 @@ SWIG_FromWCharArray(const wchar_t * carray, size_t size)
* The plain wchar_t * handling
* ------------------------------------------------------------ */
-/* in */
-
-%typemap(in,fragment="SWIG_AsWCharPtr")
- wchar_t *, wchar_t const*, wchar_t *const, wchar_t const *const
- "if (!SWIG_AsWCharPtr($input, (wchar_t **)&$1)) SWIG_fail;";
-
-%typemap(in,fragment="SWIG_AsWCharPtr")
- wchar_t const*&, wchar_t *const&, wchar_t const *const &
-{
- $*ltype temp;
- if (!SWIG_AsWCharPtr($input, (wchar_t **)&temp)) SWIG_fail;
- $1 = &temp;
-}
-
-/* out */
-
-%typemap(out,fragment="SWIG_FromWCharPtr")
- wchar_t *, wchar_t const*, wchar_t *const, wchar_t const *const
- "$result = SWIG_FromWCharPtr($1);";
-
-%typemap(out,fragment="SWIG_FromWCharPtr")
- wchar_t *const &, wchar_t const* &, wchar_t const *const &
- "$result = SWIG_FromWCharPtr(*$1);";
-
-/* varin */
-
-%typemap(varin,fragment="SWIG_AsNewWCharPtr") wchar_t *
-{
- wchar_t *cptr = 0;
- if (!SWIG_AsNewWCharPtr($input, &cptr)) {
- PyErr_Clear();
- PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'");
- return 1;
- }
- if ($1) swig_delete_array($1);
- $1 = cptr;
-}
-
-%typemap(varin,fragment="SWIG_AsNewWCharPtr",
- warning="451:Setting const wchar_t * variable may leak memory")
- const wchar_t *
-{
- wchar_t *cptr;
- if (!SWIG_AsNewWCharPtr($input, &cptr)) {
- PyErr_Clear();
- PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'");
- return 1;
- }
- $1 = cptr;
-}
-
-/* varout */
-
-%typemap(varout,fragment="SWIG_FromWCharPtr")
- wchar_t *, wchar_t const*, wchar_t *const, wchar_t const *const
- "$result = SWIG_FromWCharPtr($1);";
-
-/* constant */
-
-%typemap(constcode,fragment="SWIG_FromWCharPtr")
- wchar_t *, wchar_t const*, wchar_t * const, wchar_t const* const
- "PyDict_SetItemString(d,\"$symname\", SWIG_FromWCharPtr($value));";
-
-/* directorin */
-
-%typemap(directorin,fragment="SWIG_FromWCharPtr")
- wchar_t *, wchar_t const*, wchar_t *const, wchar_t const *const,
- wchar_t const *&, wchar_t *const &, wchar_t const *const &
- "$input = SWIG_NewPointerObj((wchar_t *)($1_name), $descriptor(wchar_t *), 0);"
- /* "$input = SWIG_FromWCharPtr($1_name);"; */
-
-
-/* directorout */
-
-%typemap(directorout,fragment="SWIG_AsWCharPtr")
- wchar_t *, wchar_t const*, wchar_t *const, wchar_t const* const
- "if (!SWIG_AsWCharPtr($input, (wchar_t **) &$result)) {
- Swig::DirectorTypeMismatchException(\"Error converting Python object into wchar_t *\");
- }";
-
-%typemap(directorout,fragment="SWIG_AsWCharPtr")
- wchar_t const *&, wchar_t *const &, wchar_t const *const &
-{
- wchar_t * temp;
- if (!SWIG_AsWCharPtr($input, &temp)) {
- Swig::DirectorTypeMismatchException("Error converting Python object into wchar_t *");
- }
- $result = ($1_ltype) &temp;
-}
-
-/* typecheck */
-
-%typemap(typecheck,precedence=SWIG_TYPECHECK_UNISTRING,
- fragment="SWIG_AsWCharPtr")
- wchar_t *, wchar_t const*, wchar_t *const, wchar_t const *const,
- wchar_t const*&, wchar_t *const&, wchar_t const *const &
- "$1 = SWIG_AsWCharPtr($input, (wchar_t **)(0));";
-
-/* throws */
-
-%typemap(throws,fragment="SWIG_FromWCharPtr")
- wchar_t *, wchar_t const*, wchar_t * const, wchar_t const* const
-{
- PyErr_SetObject(PyExc_RuntimeError, SWIG_FromWCharPtr($1));
- SWIG_fail;
-}
-
-
-/* ------------------------------------------------------------
- * Fix size wcharacter array wchar_t[ANY] handling
- * ------------------------------------------------------------ */
-
-/* memberin and globalin typemaps */
+%typemap_pystring(wchar_t,
+ SWIG_AsWCharPtr,
+ SWIG_AsWCharPtrAndSize,
+ SWIG_FromWCharPtr,
+ SWIG_AsNewWCharPtr,
+ SWIG_AsWCharArray,
+ SWIG_FromWCharArray);
-%typemap(memberin) wchar_t [ANY]
-{
- if ($input) memcpy($1,$input,$1_dim0*sizeof(wchar_t));
- else memset($1,0,$1_dim0*sizeof(wchar_t));
-}
-
-%typemap(globalin) wchar_t [ANY]
-{
- if ($input) memcpy($1,$input,$1_dim0*sizeof(wchar_t));
- else memset($1,0,$1_dim0*sizeof(wchar_t));
-}
-
-/* in */
-
-%typemap(in,fragment="SWIG_AsWCharArray")
- wchar_t [ANY], const wchar_t [ANY]
-{
- wchar_t temp[$1_dim0];
- if (!SWIG_AsWCharArray($input, temp, $1_dim0)) SWIG_fail;
- $1 = temp;
-}
-
-/* out */
-
-%typemap(out,fragment="SWIG_FromWCharArray")
- wchar_t [ANY], const wchar_t [ANY]
- "$result = SWIG_FromWCharArray($1, $1_dim0);";
-
-/* varin */
-
-%typemap(varin,fragment="SWIG_AsWCharArray")
- wchar_t [ANY]
-{
- if (!SWIG_AsWCharArray($input, $1, $1_dim0)) {
- PyErr_Clear();
- PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'");
- return 1;
- }
-}
-
-/* varout */
-
-%typemap(varout,fragment="SWIG_FromWCharArray")
- wchar_t [ANY], const wchar_t [ANY]
- "$result = SWIG_FromWCharArray($1, $1_dim0);";
-
-
-/* constants */
-
-%typemap(constcode,fragment="SWIG_FromWCharArray")
- wchar_t [ANY], const wchar_t [ANY]
- "PyDict_SetItemString(d,\"$symname\", SWIG_FromWCharArray($value, $value_dim0));";
-
-/* directorin */
-
-%typemap(directorin,fragment="SWIG_FromWCharArray")
- wchar_t [ANY], const wchar_t [ANY]
- "$input = SWIG_FromWCharArray($1_name, $1_dim0);";
-
-/* directorout */
-
-%typemap(directorout,fragment="SWIG_AsWCharArray")
- wchar_t [ANY], const wchar_t [ANY] (wchar_t temp[$result_dim0])
-{
- if (!SWIG_AsWCharArray($input, temp, $result_dim0)) {
- Swig::DirectorTypeMismatchException("Error converting Python object into wchar_t[$result_dim0]");
- }
- $result = temp;
-}
-
-/* typecheck */
-
-%typemap(typecheck,precedence=SWIG_TYPECHECK_UNISTRING,
- fragment="SWIG_AsWCharArray")
- wchar_t [ANY], const wchar_t[ANY]
-{
- return SWIG_AsWCharArray($input, (wchar_t **)0, (size_t *)0);
-}
-
-/* throw */
-
-%typemap(throws,fragment="SWIG_FromWCharArray")
- wchar_t[ANY], const wchar_t[ANY] {
- PyErr_SetObject(PyExc_RuntimeError, SWIG_FromWCharArray($1,$1_dim0));
- SWIG_fail;
-}
-
-/* ------------------------------------------------------------
- * --- String & length ---
- * ------------------------------------------------------------ */
-
-/* Here len doesn't include the '0' terminator */
-%typemap(in, fragment="SWIG_AsWCharPtrAndSize")
- (wchar_t *STRING, int LENGTH) (wchar_t *buf, size_t size)
-{
- int res = SWIG_AsWCharPtrAndSize($input, &buf, &size);
- if (!res) SWIG_fail;
- $1 = ($1_ltype) buf;
- $2 = ($2_ltype) size - 1;
-}
-
-/* Here size includes the '0' terminator */
-%typemap(in,fragment="SWIG_AsWCharPtrAndSize")
- (wchar_t *STRING, int SIZE) (wchar_t *buf, size_t size)
-{
- if (!SWIG_AsWCharPtrAndSize($input, &buf, &size)) SWIG_fail;
- $1 = ($1_ltype) buf;
- $2 = ($2_ltype) size;
-}
diff --git a/Lib/python/std_wstring.i b/Lib/python/std_wstring.i
index e5083b55a..cf82ee28b 100644
--- a/Lib/python/std_wstring.i
+++ b/Lib/python/std_wstring.i
@@ -1,4 +1,4 @@
-%include pywstrings.swg
+%include wchar.i
%include std_basic_string.i
/* wide strings */
diff --git a/Lib/python/wchar.i b/Lib/python/wchar.i
new file mode 100644
index 000000000..1a76001b3
--- /dev/null
+++ b/Lib/python/wchar.i
@@ -0,0 +1,7 @@
+%{
+#include <wchar.h>
+%}
+
+%types(wchar_t *);
+
+%include pywstrings.swg