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
This commit is contained in:
parent
d062b8cce8
commit
12af360d6f
6 changed files with 294 additions and 453 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue