fix extra calls to TypeQuery for 'char *' and 'wchar_t *'
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7968 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
cdff8ff3e2
commit
3ead254d42
10 changed files with 123 additions and 89 deletions
|
|
@ -2,37 +2,37 @@
|
|||
* utility methods for char strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%fragment("SWIG_AsCharPtrAndSize","header") {
|
||||
%fragment("SWIG_AsCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsCharPtrAndSize(SV *obj, char** cptr, size_t* psize, int *alloc)
|
||||
{
|
||||
static swig_type_info* pchar_info = 0;
|
||||
char* vptr = 0;
|
||||
if (!pchar_info) pchar_info = SWIG_TypeQuery("char *");
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_info, 0) == SWIG_OK) {
|
||||
if (cptr) *cptr = vptr;
|
||||
if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
|
||||
if (alloc) *alloc = SWIG_OLDOBJ;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if (SvPOK(obj)) {
|
||||
STRLEN len = 0;
|
||||
char *cstr = SvPV(obj, len);
|
||||
size_t size = len + 1;
|
||||
if (cptr) {
|
||||
if (alloc) {
|
||||
if (*alloc == SWIG_NEWOBJ) {
|
||||
*cptr = %new_copy_array(cstr, size, char);
|
||||
} else {
|
||||
*cptr = cstr;
|
||||
*alloc = SWIG_OLDOBJ;
|
||||
}
|
||||
if (SvPOK(obj)) {
|
||||
STRLEN len = 0;
|
||||
char *cstr = SvPV(obj, len);
|
||||
size_t size = len + 1;
|
||||
if (cptr) {
|
||||
if (alloc) {
|
||||
if (*alloc == SWIG_NEWOBJ) {
|
||||
*cptr = %new_copy_array(cstr, size, char);
|
||||
} else {
|
||||
*cptr = cstr;
|
||||
*alloc = SWIG_OLDOBJ;
|
||||
}
|
||||
}
|
||||
if (psize) *psize = size;
|
||||
}
|
||||
if (psize) *psize = size;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
char* vptr = 0;
|
||||
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
|
||||
if (pchar_descriptor && (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_descriptor, 0) == SWIG_OK)) {
|
||||
if (cptr) *cptr = vptr;
|
||||
if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
|
||||
if (alloc) *alloc = SWIG_OLDOBJ;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -367,8 +367,13 @@ namespace swig {
|
|||
return x.distance(*this);
|
||||
}
|
||||
|
||||
static swig_type_info* desc() {
|
||||
static swig_type_info* desc = SWIG_TypeQuery("swig::PySequence_OutputIterator *");
|
||||
static swig_type_info* descriptor() {
|
||||
static int init = 0;
|
||||
static swig_type_info* desc = 0;
|
||||
if (!init) {
|
||||
desc = SWIG_TypeQuery("swig::PySequence_OutputIterator *");
|
||||
init = 1;
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
};
|
||||
|
|
@ -714,15 +719,15 @@ namespace swig
|
|||
%typemap(out,noblock=1,fragment="PySequence_Cont")
|
||||
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
|
||||
$result = SWIG_NewPointerObj(swig::make_output_iterator((const $type &)$1),
|
||||
swig::PySequence_OutputIterator::desc(),SWIG_POINTER_OWN);
|
||||
swig::PySequence_OutputIterator::descriptor(),SWIG_POINTER_OWN);
|
||||
}
|
||||
%typemap(out,noblock=1,fragment="PySequence_Cont")
|
||||
std::pair<iterator, iterator>, std::pair<const_iterator, const_iterator> {
|
||||
$result = PyTuple_New(2);
|
||||
PyTuple_SetItem($result,0,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
|
||||
swig::PySequence_OutputIterator::desc(),SWIG_POINTER_OWN));
|
||||
swig::PySequence_OutputIterator::descriptor(),SWIG_POINTER_OWN));
|
||||
PyTuple_SetItem($result,1,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).second),
|
||||
swig::PySequence_OutputIterator::desc(),SWIG_POINTER_OWN));
|
||||
swig::PySequence_OutputIterator::descriptor(),SWIG_POINTER_OWN));
|
||||
}
|
||||
|
||||
%fragment("PyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="PySequence_Cont") {}
|
||||
|
|
@ -731,7 +736,7 @@ namespace swig
|
|||
std::pair<iterator, bool>, std::pair<const_iterator, bool> {
|
||||
$result = PyTuple_New(2);
|
||||
PyTuple_SetItem($result,0,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
|
||||
swig::PySequence_OutputIterator::desc(),SWIG_POINTER_OWN));
|
||||
swig::PySequence_OutputIterator::descriptor(),SWIG_POINTER_OWN));
|
||||
PyTuple_SetItem($result,1,SWIG_From(bool)(%static_cast($1,const $type &).second));
|
||||
}
|
||||
|
||||
|
|
@ -740,7 +745,7 @@ namespace swig
|
|||
reverse_iterator(swig::PySequence_OutputIterator *iter),
|
||||
const_iterator(swig::PySequence_OutputIterator *iter),
|
||||
const_reverse_iterator(swig::PySequence_OutputIterator *iter) {
|
||||
if (SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::PySequence_OutputIterator::desc(), 0) != SWIG_OK) {
|
||||
if (SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::PySequence_OutputIterator::descriptor(), 0) != SWIG_OK) {
|
||||
%argument_fail(SWIG_TypeError, "$type", $argnum);
|
||||
}
|
||||
if (iter) {
|
||||
|
|
@ -756,7 +761,7 @@ namespace swig
|
|||
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
|
||||
swig::PySequence_OutputIterator *iter = 0;
|
||||
$1 = ((SWIG_ConvertPtr($input, %as_voidptrptr(&iter),
|
||||
swig::PySequence_OutputIterator::desc(), 0) == SWIG_OK)
|
||||
swig::PySequence_OutputIterator::descriptor(), 0) == SWIG_OK)
|
||||
&& iter
|
||||
&& (dynamic_cast<swig::PySequence_OutputIterator_T<$type > *>(iter) != 0));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
/* ------------------------------------------------------------
|
||||
* utility methods for char strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%fragment("SWIG_AsCharPtrAndSize","header") {
|
||||
%fragment("SWIG_AsCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
|
||||
{
|
||||
|
|
@ -40,10 +39,9 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
|
|||
if (psize) *psize = len + 1;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
char* vptr = 0;
|
||||
static swig_type_info* pchar_info = 0;
|
||||
if (!pchar_info) pchar_info = SWIG_TypeQuery("char *");
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_info, 0) == SWIG_OK) {
|
||||
char* vptr = 0;
|
||||
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
|
||||
if (pchar_descriptor && (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_descriptor, 0) == SWIG_OK)) {
|
||||
if (cptr) *cptr = vptr;
|
||||
if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
|
||||
if (alloc) *alloc = SWIG_OLDOBJ;
|
||||
|
|
@ -54,14 +52,15 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
|
|||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromCharPtrAndSize","header") {
|
||||
%fragment("SWIG_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
|
||||
SWIGINTERNINLINE PyObject *
|
||||
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
|
||||
{
|
||||
if (carray) {
|
||||
if (size > INT_MAX) {
|
||||
return SWIG_NewPointerObj(%const_cast(carray,char *),
|
||||
SWIG_TypeQuery("char *"), 0);
|
||||
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
|
||||
return pchar_descriptor ?
|
||||
SWIG_NewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
|
||||
} else {
|
||||
return PyString_FromStringAndSize(carray, %numeric_cast(size,int));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,28 +23,22 @@
|
|||
~SWIG_Python_Thread_Block() { end(); }
|
||||
};
|
||||
class SWIG_Python_Thread_Allow {
|
||||
bool status;
|
||||
PyThreadState *save;
|
||||
public:
|
||||
SWIG_Python_Thread_Allow() : save(PyEval_SaveThread()) {}
|
||||
~SWIG_Python_Thread_Allow() { PyEval_RestoreThread(save); }
|
||||
void end() { if (status) { PyEval_RestoreThread(save); status = false; }}
|
||||
SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {}
|
||||
~SWIG_Python_Thread_Allow() { end(); }
|
||||
};
|
||||
# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK)
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block
|
||||
# endif
|
||||
# if !defined(SWIG_PYTHON_THREAD_END_BLOCK)
|
||||
# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end()
|
||||
# endif
|
||||
# if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW)
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_ALLOW { SWIG_Python_Thread_Allow _swig_thread_allow
|
||||
# endif
|
||||
# if !defined(SWIG_PYTHON_THREAD_END_ALLOW)
|
||||
# define SWIG_PYTHON_THREAD_END_ALLOW }
|
||||
# endif
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block
|
||||
# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end()
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow
|
||||
# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end()
|
||||
# else /* C code */
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure()
|
||||
# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block)
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_ALLOW { PyThreadState *_swig_thread_allow = PyEval_SaveThread()
|
||||
# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow); }
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread()
|
||||
# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow)
|
||||
# endif
|
||||
# else /* Old thread way, not implemented, user must provide it */
|
||||
# if !defined(SWIG_PYTHON_INITIALIZE_THREADS)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
* utility methods for wchar_t strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%fragment("SWIG_AsWCharPtrAndSize","header",fragment="<wchar.h>") {
|
||||
%fragment("SWIG_AsWCharPtrAndSize","header",fragment="<wchar.h>",fragment="SWIG_pwchar_descriptor") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
|
||||
{
|
||||
|
|
@ -26,10 +26,9 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
|
|||
if (tmp) Py_DECREF(tmp);
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
static swig_type_info* pwchar_info = 0;
|
||||
swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor();
|
||||
wchar_t * vptr = 0;
|
||||
if (!pwchar_info) pwchar_info = SWIG_TypeQuery("wchar_t *");
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, pwchar_info, 0) == SWIG_OK) {
|
||||
if (pwchar_descriptor && (SWIG_ConvertPtr(obj, (void**)&vptr, pwchar_descriptor, 0) == SWIG_OK)) {
|
||||
if (cptr) *cptr = vptr;
|
||||
if (psize) *psize = vptr ? (wcslen(vptr) + 1) : 0;
|
||||
return SWIG_OK;
|
||||
|
|
@ -39,14 +38,15 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
|
|||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromWCharPtrAndSize","header",fragment="<wchar.h>") {
|
||||
%fragment("SWIG_FromWCharPtrAndSize","header",fragment="<wchar.h>",fragment="SWIG_pwchar_descriptor") {
|
||||
SWIGINTERNINLINE PyObject *
|
||||
SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size)
|
||||
{
|
||||
if (carray) {
|
||||
if (size > INT_MAX) {
|
||||
return SWIG_NewPointerObj(%const_cast(carray,wchar_t *),
|
||||
SWIG_TypeQuery("wchar_t *"), 0);
|
||||
swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor();
|
||||
return pwchar_descriptor ?
|
||||
SWIG_NewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : SWIG_Py_Void();
|
||||
} else {
|
||||
return PyUnicode_FromWideChar(carray, %numeric_cast(size,int));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,47 +2,48 @@
|
|||
* utility methods for char strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%fragment("SWIG_AsCharPtrAndSize","header") {
|
||||
%fragment("SWIG_AsCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc)
|
||||
{
|
||||
static swig_type_info* pchar_info = 0;
|
||||
char* vptr = 0;
|
||||
if (!pchar_info) pchar_info = SWIG_TypeQuery("char *");
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_info, 0) == SWIG_OK) {
|
||||
if (cptr) *cptr = vptr;
|
||||
if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
|
||||
if (alloc) *alloc = SWIG_OLDOBJ;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if (TYPE(obj) == T_STRING) {
|
||||
char *cstr = rb_string_value_ptr(&(obj));
|
||||
size_t size = RSTRING(obj)->len + 1;
|
||||
if (cptr) {
|
||||
if (alloc) {
|
||||
if (*alloc == SWIG_NEWOBJ) {
|
||||
*cptr = %new_copy_array(cstr, size, char);
|
||||
} else {
|
||||
*cptr = cstr;
|
||||
*alloc = SWIG_OLDOBJ;
|
||||
}
|
||||
if (TYPE(obj) == T_STRING) {
|
||||
char *cstr = rb_string_value_ptr(&(obj));
|
||||
size_t size = RSTRING(obj)->len + 1;
|
||||
if (cptr) {
|
||||
if (alloc) {
|
||||
if (*alloc == SWIG_NEWOBJ) {
|
||||
*cptr = %new_copy_array(cstr, size, char);
|
||||
} else {
|
||||
*cptr = cstr;
|
||||
*alloc = SWIG_OLDOBJ;
|
||||
}
|
||||
}
|
||||
if (psize) *psize = size;
|
||||
}
|
||||
if (psize) *psize = size;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
char* vptr = 0;
|
||||
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
|
||||
if (pchar_descriptor && (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_descriptor, 0) == SWIG_OK)) {
|
||||
if (cptr) *cptr = vptr;
|
||||
if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
|
||||
if (alloc) *alloc = SWIG_OLDOBJ;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromCharPtrAndSize","header") {
|
||||
%fragment("SWIG_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
|
||||
{
|
||||
if (carray) {
|
||||
if (size > LONG_MAX) {
|
||||
return SWIG_NewPointerObj(%const_cast(carray,char *), SWIG_TypeQuery("char *"), 0);
|
||||
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
|
||||
return pchar_descriptor ?
|
||||
SWIG_NewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : Qnil;
|
||||
} else {
|
||||
return rb_str_new(carray, %numeric_cast(size,long));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,23 @@
|
|||
|
||||
%ensure_fragment(SWIG_AsCharPtrAndSize)
|
||||
%ensure_fragment(SWIG_FromCharPtrAndSize)
|
||||
|
||||
%types(char *);
|
||||
|
||||
%fragment("SWIG_pchar_descriptor","header") {
|
||||
SWIGINTERN swig_type_info*
|
||||
SWIG_pchar_descriptor()
|
||||
{
|
||||
static int init = 0;
|
||||
static swig_type_info* info = 0;
|
||||
if (!init) {
|
||||
info = SWIG_TypeQuery("_p_char");
|
||||
init = 1;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%include <typemaps/strings.swg>
|
||||
%typemaps_string(char, Char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, strlen,
|
||||
"<limits.h>", CHAR_MIN, CHAR_MAX)
|
||||
|
|
|
|||
|
|
@ -166,6 +166,7 @@ nocppval
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#define %mangle(Type...) #@Type
|
||||
#define %descriptor(Type...) SWIGTYPE_ ## #@Type
|
||||
#define %string_name(Name) "SWIG_" %str(Name)
|
||||
#define %symbol_name(Name, Type...) SWIG_ ## Name ## _ #@Type
|
||||
#define %checkcode(Code) SWIG_TYPECHECK_ ## Code
|
||||
|
|
|
|||
|
|
@ -1,6 +1,23 @@
|
|||
%ensure_fragment(SWIG_AsWCharPtrAndSize)
|
||||
%ensure_fragment(SWIG_FromWCharPtrAndSize)
|
||||
|
||||
|
||||
%types(wchar_t *);
|
||||
|
||||
%fragment("SWIG_pwchar_descriptor","header") {
|
||||
SWIGINTERN swig_type_info*
|
||||
SWIG_pwchar_descriptor()
|
||||
{
|
||||
static int init = 0;
|
||||
static swig_type_info* info = 0;
|
||||
if (!init) {
|
||||
info = SWIG_TypeQuery("_p_wchar_t");
|
||||
init = 1;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
%include <typemaps/strings.swg>
|
||||
%typemaps_string(wchar_t, WChar, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize, wcslen,
|
||||
"<wchar.h>", WCHAR_MIN, WCHAR_MAX)
|
||||
|
|
|
|||
|
|
@ -2122,6 +2122,7 @@ public:
|
|||
Printf(f_directors_h," msg += method_name;\n");
|
||||
Printf(f_directors_h," Swig::DirectorMethodException::raise(msg.c_str());\n");
|
||||
Printf(f_directors_h," }\n");
|
||||
Printf(f_directors_h," Py_DECREF(swig_get_self());\n");
|
||||
Printf(f_directors_h," vtable[method_index] = method;\n");
|
||||
Printf(f_directors_h," };\n");
|
||||
Printf(f_directors_h," return method;\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue