From fe00d5cb85ca41e760c9a3ebd9c38f3750e559e9 Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Fri, 7 Oct 2005 13:19:06 +0000 Subject: [PATCH] fixes for new flag attribute convention git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7605 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/test-suite/common.mk | 1 + SWIG/Examples/test-suite/python/autodoc.i | 2 +- SWIG/Examples/test-suite/python/nondynamic.i | 19 ++++---- SWIG/Examples/test-suite/refcount.i | 10 ++-- SWIG/Lib/python/pyopers.swg | 6 +-- SWIG/Lib/python/pyruntime.swg | 10 ++++ SWIG/Lib/python/pyuserdir.swg | 50 ++++++++++---------- 7 files changed, 53 insertions(+), 45 deletions(-) diff --git a/SWIG/Examples/test-suite/common.mk b/SWIG/Examples/test-suite/common.mk index 63e20e1db..239cd795b 100644 --- a/SWIG/Examples/test-suite/common.mk +++ b/SWIG/Examples/test-suite/common.mk @@ -194,6 +194,7 @@ CPP_TEST_CASES += \ protected_rename \ pure_virtual \ redefined \ + refcount \ reference_global_vars \ register_par \ rename_scope \ diff --git a/SWIG/Examples/test-suite/python/autodoc.i b/SWIG/Examples/test-suite/python/autodoc.i index e471a9e6f..1a80d003e 100644 --- a/SWIG/Examples/test-suite/python/autodoc.i +++ b/SWIG/Examples/test-suite/python/autodoc.i @@ -62,7 +62,7 @@ %typemap(doc) int a "a: special comment for parameter a"; %typemap(doc) int b "b: another special comment for parameter b"; -%pythoncallback(1) func_cb; +%callback(1) func_cb; %inline { diff --git a/SWIG/Examples/test-suite/python/nondynamic.i b/SWIG/Examples/test-suite/python/nondynamic.i index 7139bd4a5..2acc9bf8b 100644 --- a/SWIG/Examples/test-suite/python/nondynamic.i +++ b/SWIG/Examples/test-suite/python/nondynamic.i @@ -1,11 +1,11 @@ %module nondynamic /* - Use the "static" feature to make the wrapped class a static one, - ie, a python class that doesn't dynamically add new attributes. - Hence, for the class + Use the %pythonnondynamic directuve to make the wrapped class a + nondynamic one, ie, a python class that doesn't dynamically add new + attributes. Hence, for the class - %feature("static") A; + %pythonnondynamic A; struct A { int a; @@ -19,11 +19,11 @@ aa.b = 1 # Ok aa.c = 3 # error - Since "static" is a feature, if you use + Since "nondynamic" is a feature, if you use - %feature("static"); + %pythonnondynamic; - it will make all the wrapped class static ones. + it will make all the wrapped class nondynamic ones. The implementation is based on the recipe: @@ -35,9 +35,8 @@ -//%pythonnondynamic(1); -%pythonnondynamic(1) A; -%pythonnondynamic(0) C; +%pythonnondynamic A; +%pythondynamic C; %inline %{ diff --git a/SWIG/Examples/test-suite/refcount.i b/SWIG/Examples/test-suite/refcount.i index f43e9f4f9..fe34d14e9 100644 --- a/SWIG/Examples/test-suite/refcount.i +++ b/SWIG/Examples/test-suite/refcount.i @@ -1,6 +1,6 @@ %module refcount -#warnfilter(362); +%warnfilter(362); %{ #include @@ -33,8 +33,8 @@ RefCount(B); // using the ref/unref features you can active the ref. counting // for RCObj and all its descendents at once // -%feature("ref") RCObj "$this->ref();" -%feature("unref") RCObj "$this->unref();" +%refobject RCObj "$this->ref();" +%unrefobject RCObj "$this->unref();" #endif @@ -108,7 +108,7 @@ RefCount(B); /* Other ref/unref uses: // deactive the refcounting for A1 and its descendents -%feature("noref") A1; -%feature("nounref") A1; +%noref A1; +%nounref A1; */ diff --git a/SWIG/Lib/python/pyopers.swg b/SWIG/Lib/python/pyopers.swg index c636c7bb6..26728bdb3 100644 --- a/SWIG/Lib/python/pyopers.swg +++ b/SWIG/Lib/python/pyopers.swg @@ -6,7 +6,7 @@ #ifdef __cplusplus %define %pybinoperator(pyname,oper) %rename(pyname) oper; -%pythonmaybecall(1) oper; +%pythonmaybecall oper; %enddef %pybinoperator(__add__, *::operator+); @@ -31,8 +31,8 @@ %pybinoperator(__ne__, *::operator!=); %define %pybinoperation(oper) -%pythonmaybecall(1) __ ## oper ## __; -%pythonmaybecall(1) __r ## oper ## __; +%pythonmaybecall __ ## oper ## __; +%pythonmaybecall __r ## oper ## __; %enddef %pybinoperation(add); diff --git a/SWIG/Lib/python/pyruntime.swg b/SWIG/Lib/python/pyruntime.swg index bdf9bb70d..b9d83a7f1 100644 --- a/SWIG/Lib/python/pyruntime.swg +++ b/SWIG/Lib/python/pyruntime.swg @@ -6,3 +6,13 @@ %insert(runtime) "swigrun.swg"; /* Common C API type-checking code */ %insert(runtime) "pyapi.swg"; /* SWIG/Pyton API */ %insert(runtime) "pyrun.swg"; /* Python run-time code */ + + +/* When using -nortti, tell directors to avoid RTTI */ +#ifdef SWIG_NORTTI +%insert("runtime") %{ +#ifndef SWIG_DIRECTOR_NORTTI +#define SWIG_DIRECTOR_NORTTI +#endif +%} +#endif diff --git a/SWIG/Lib/python/pyuserdir.swg b/SWIG/Lib/python/pyuserdir.swg index 2e07e21c0..d3ec314cf 100644 --- a/SWIG/Lib/python/pyuserdir.swg +++ b/SWIG/Lib/python/pyuserdir.swg @@ -13,7 +13,7 @@ one, ie, a python class that doesn't dynamically add new attributes. For example, for the class -%pythonnondynamic(1) A; +%pythonnondynamic A; struct A { int a; @@ -27,28 +27,25 @@ you will get: aa.b = 1 # Ok aa.c = 3 # error -Since "nondynamic" is a feature, if you use it like +Since nondynamic is a feature, if you use it like -%pythonnondynamic(1); + %pythonnondynamic; it will make all the wrapped classes nondynamic ones. The implementation is based on the recipe: - http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158 + http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158 -and works for modern (-modern) and plain python. We don't use __slots__, -so, it works with old python versions. - -You can also use the raw %feature form - -%feature("pythonnondynamic") A; +and works for modern (-modern) and plain python. We don not use __slots__, +so, it works with old python versions. */ - -#define %pythonnondynamic(FLAG) %feature("python:nondynamic", #FLAG) - +#define %pythonnondynamic %feature("python:nondynamic", "1") +#define %nopythonnondynamic %feature("python:nondynamic", "0") +#define %clearpythonnondynamic %feature("python:nondynamic", "") +#define %pythondynamic %nopythonnondynamic /* @@ -59,7 +56,9 @@ These methods "may be called" if needed. */ -%define %pythonmaybecall(FLAG) %feature("python:maybecall",#FLAG) %enddef +#define %pythonmaybecall %feature("python:maybecall", "1") +#define %nopythonmaybecall %feature("python:maybecall", "0") +#define %clearpythonmaybecall %feature("python:maybecall", "") /* The %pythoncallback feature produce a more natural callback wrap @@ -102,26 +101,25 @@ These methods "may be called" if needed. */ -#define %pythoncallback(x) %feature("python:callback",`x`) -#define %nopythoncallback %feature("python:callback","") +#define %pythoncallback %feature("python:callback") +#define %nopythoncallback %feature("python:callback","0") +#define %clearpythoncallback %feature("python:callback","") + /* Support for the old %callback directive name */ #ifdef %callback #undef %callback #endif -#define %callback(x) %pythoncallback(x) #ifdef %nocallback #undef %nocallback #endif -#define %nocallback %nopythoncallback; %feature("callback","") +#ifdef %clearcallback +#undef %clearcallback +#endif + +#define %callback(x) %feature("python:callback",`x`) +#define %nocallback %nopythoncallback +#define %clearcallback %clearpythoncallback -/* When using -nortti, tell directors to avoid RTTI */ -#ifdef SWIG_NORTTI -%insert("runtime") %{ -#ifndef SWIG_DIRECTOR_NORTTI -#define SWIG_DIRECTOR_NORTTI -#endif -%} -#endif