From c09006dbdd4ff54dfb25f1d425dbc60cb180428c Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Wed, 21 Dec 2005 02:09:13 +0000 Subject: [PATCH] Use safe Py_None in Windows or when using -DSWIG_PYTHON_SAFE_NONE git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8021 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyrun.swg | 24 ++++++++++++++++-------- Source/Modules/python.cxx | 4 ++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 7e49ca1f3..867868ab6 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -78,6 +78,15 @@ extern "C" { /* Safe Py_None and Py_Void accessors */ +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# ifndef SWIG_PYTHON_NO_SAFE_NONE +# ifndef SWIG_PYTHON_SAFE_NONE +# define SWIG_PYTHON_SAFE_NONE +# endif +# endif +#endif + +#ifdef SWIG_PYTHON_SAFE_NONE SWIGRUNTIME PyObject * _SWIG_Py_None(void) { @@ -88,23 +97,22 @@ _SWIG_Py_None(void) } return none; } - SWIGRUNTIMEINLINE PyObject * SWIG_Py_None(void) { static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); return none; } - -#ifdef Py_None -# undef Py_None -# define Py_None SWIG_Py_None() +# ifdef Py_None +# undef Py_None +# define Py_None SWIG_Py_None() +# endif #endif SWIGRUNTIMEINLINE PyObject * SWIG_Py_Void(void) { - PyObject *none = SWIG_Py_None(); + PyObject *none = Py_None; Py_INCREF(none); return none; } @@ -115,7 +123,7 @@ SWIGINTERN PyObject* SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { if (!result) { result = obj; - } else if (result == SWIG_Py_None()) { + } else if (result == Py_None) { Py_DECREF(result); result = obj; } else { @@ -867,7 +875,7 @@ SWIG_Python_AcquirePtr(PyObject *obj, int own) { SWIGRUNTIME int SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { if (!obj) return SWIG_ERROR; - if (obj == SWIG_Py_None()) { + if (obj == Py_None) { if (ptr) *ptr = 0; return SWIG_OK; } else { diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 1ab2a701d..8804aa3fd 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -401,7 +401,7 @@ public: } /* Set comparison with none for ConstructorToFunction */ - setSubclassInstanceCheck(NewString("$arg != SWIG_Py_None()")); + setSubclassInstanceCheck(NewString("$arg != Py_None")); /* Initialize all of the output files */ String *outfile = Getattr(n,"outfile"); @@ -1725,7 +1725,7 @@ public: /* if (constructor && (Getattr(n, "wrap:self") != 0)) { Wrapper_add_local(f, "subclassed", "int subclassed = 0"); - Printf(f->code, "subclassed = (arg1 != SWIG_Py_None());\n"); + Printf(f->code, "subclassed = (arg1 != Py_None);\n"); } */