fixes for new flag attribute convention

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7605 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-07 13:19:06 +00:00
commit fe00d5cb85
7 changed files with 53 additions and 45 deletions

View file

@ -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);

View file

@ -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

View file

@ -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