diff --git a/Examples/python/funcptr2/example.i b/Examples/python/funcptr2/example.i index 81a66146a..681775a3e 100644 --- a/Examples/python/funcptr2/example.i +++ b/Examples/python/funcptr2/example.i @@ -8,11 +8,11 @@ extern int do_op(int a, int b, int (*op)(int, int)); /* Now install a bunch of "ops" as constants */ -%callback("%(upper)s") +%callback("%(upper)s"); int add(int, int); int sub(int, int); int mul(int, int); -%nocallback +%nocallback; extern int (*funcvar)(int,int); diff --git a/Examples/ruby/funcptr2/example.i b/Examples/ruby/funcptr2/example.i index 81a66146a..681775a3e 100644 --- a/Examples/ruby/funcptr2/example.i +++ b/Examples/ruby/funcptr2/example.i @@ -8,11 +8,11 @@ extern int do_op(int a, int b, int (*op)(int, int)); /* Now install a bunch of "ops" as constants */ -%callback("%(upper)s") +%callback("%(upper)s"); int add(int, int); int sub(int, int); int mul(int, int); -%nocallback +%nocallback; extern int (*funcvar)(int,int); diff --git a/Examples/test-suite/python/callback.i b/Examples/test-suite/python/callback.i index 3c923bb73..ac3ae1bfb 100644 --- a/Examples/test-suite/python/callback.i +++ b/Examples/test-suite/python/callback.i @@ -1,14 +1,13 @@ %module callback -%pythoncallback(1); -%pythoncallback(1) foo; -%pythoncallback(1) A::bar; -%pythoncallback(1) A::foom; -%pythoncallback(1) foo_T; +%callback(1) foo; +%callback(1) foof; +%callback(1) A::bar; +%callback(1) A::foom; +%callback("%s_Cb_Ptr") foo_T; // old style, still works. %inline %{ - int foo(int a) { return a; } diff --git a/Lib/python/pyuserdir.swg b/Lib/python/pyuserdir.swg index d201ba3d5..fe9118ab7 100644 --- a/Lib/python/pyuserdir.swg +++ b/Lib/python/pyuserdir.swg @@ -108,6 +108,17 @@ These methods "may be called" if needed. */ -%define %pythoncallback(FLAG) %feature("python:callback",#FLAG) %enddef -%define %nopythoncallback %feature("python:callback","") %enddef +#define %pythoncallback(x) %feature("python:callback",`x`) +#define %nopythoncallback %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","") diff --git a/Lib/swig.swg b/Lib/swig.swg index 92fb048ca..531c3412d 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -44,8 +44,8 @@ /* Experimental */ -#define %callback(x) %feature("callback") `x`; -#define %nocallback %feature("callback",""); +#define %callback(x) %feature("callback",`x`) +#define %nocallback %feature("callback","") /* Directives for attribute functions */ diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 47c8dafc9..f4348a068 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -502,8 +502,17 @@ public: int functionHandler(Node *n) { - if (Getattr(n,"feature:python:callback")) { - Setattr(n,"feature:callback","%s_cb_ptr"); + String *pcb = Getattr(n,"feature:python:callback"); + if (pcb && (Strcmp(pcb,"0") == 0)) { + Setattr(n,"feature:python:callback",""); + pcb = 0; + } + if (pcb) { + if (Strcmp(pcb,"1") == 0) { + Setattr(n,"feature:callback","%s_cb_ptr"); + } else { + Setattr(n,"feature:callback",pcb); + } autodoc_l dlevel = autodoc_level(Getattr(n, "feature:autodoc")); if (dlevel != NO_AUTODOC && dlevel > TYPES_AUTODOC) { Setattr(n,"feature:autodoc","1");