From 9cfb9a490b4db2e739ca7d8312f2f451649923eb Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Wed, 21 Jan 2004 00:46:08 +0000 Subject: [PATCH] fixes for the nodirector feature and the '0' director member case git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5657 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/frob.i | 34 ++++++++++++++++++++++++ Examples/test-suite/java/frob_runme.java | 24 +++++++++++++++++ Examples/test-suite/python/frob_runme.py | 7 +++++ Examples/test-suite/ruby/frob_runme.rb | 6 +++++ Source/Modules/java.cxx | 13 ++++----- Source/Modules/lang.cxx | 7 ++--- 6 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 Examples/test-suite/frob.i create mode 100644 Examples/test-suite/java/frob_runme.java create mode 100644 Examples/test-suite/python/frob_runme.py create mode 100644 Examples/test-suite/ruby/frob_runme.rb diff --git a/Examples/test-suite/frob.i b/Examples/test-suite/frob.i new file mode 100644 index 000000000..64280eda1 --- /dev/null +++ b/Examples/test-suite/frob.i @@ -0,0 +1,34 @@ +%module(directors="1") frob; + +%header %{ +#include +%} + +%feature("director") Alpha; +%feature("director") Bravo; + +%feature("nodirector") Bravo::abs_method(); + +%inline %{ + class Alpha + { + public: + Alpha() { } + virtual ~Alpha() { }; + virtual const char* abs_method() = 0; + }; + + class Bravo : public Alpha + { + public: + Bravo() { } + virtual ~Bravo() { }; + virtual const char* abs_method(); + }; + + const char* + Bravo::abs_method() + { + return "Bravo::abs_method()"; + } +%} diff --git a/Examples/test-suite/java/frob_runme.java b/Examples/test-suite/java/frob_runme.java new file mode 100644 index 000000000..9f906685f --- /dev/null +++ b/Examples/test-suite/java/frob_runme.java @@ -0,0 +1,24 @@ + +import frob.*; +import java.lang.reflect.*; + +public class frob_runme +{ + static { + try { + System.loadLibrary("frob"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String args[]) + { + Bravo foo = new Bravo(); + + String s = foo.abs_method(); + if (!s.equals("Bravo::abs_method()")) + throw new RuntimeException( "error" ); + } +} \ No newline at end of file diff --git a/Examples/test-suite/python/frob_runme.py b/Examples/test-suite/python/frob_runme.py new file mode 100644 index 000000000..83680096b --- /dev/null +++ b/Examples/test-suite/python/frob_runme.py @@ -0,0 +1,7 @@ +from frob import * + +foo = Bravo(); +s = foo.abs_method(); + +if s != "Bravo::abs_method()": + raise RuntimeError, s diff --git a/Examples/test-suite/ruby/frob_runme.rb b/Examples/test-suite/ruby/frob_runme.rb new file mode 100644 index 000000000..81772c1e7 --- /dev/null +++ b/Examples/test-suite/ruby/frob_runme.rb @@ -0,0 +1,6 @@ +require 'frob' + +foo = Frob::Bravo.new; +s = foo.abs_method; + +raise RuntimeError if s != "Bravo::abs_method()" diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 9c35f6a0c..b27305662 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -2536,10 +2536,6 @@ class JAVA : public Language { int gencomma = 0; int classmeth_off = curr_class_dmethod - first_class_dmethod; - /* Skip out of here if nodirector is set */ - - if (!Cmp(Getattr(n, "feature:nodirector"), "1")) - return SWIG_OK; // This is a kludge: functionWrapper has sym:overload set properly, but it // isn't at this point, so we have to manufacture it ourselves. At least @@ -3203,12 +3199,13 @@ class JAVA : public Language { Printf(w->code, "}\n"); Printf(w->code, "bool derived = (jenv->IsSameObject(baseclass, jcls) ? false : true);\n"); - if (first_class_dmethod != curr_class_dmethod) { - int n_methods = curr_class_dmethod - first_class_dmethod; + int n_methods = curr_class_dmethod - first_class_dmethod; + Printf(f_directors_h, "protected:\n"); + Printf(f_directors_h, " bool swig_override[%d];\n", n_methods); + + if (n_methods) { /* Emit the code to look up the class's methods, initialize the override array */ - Printf(f_directors_h, "protected:\n"); - Printf(f_directors_h, " bool swig_override[%d];\n", n_methods); Printf(w->code, "for (int i = 0; i < %d; ++i) {\n", n_methods); Printf(w->code, " if (methods[i].base_methid == NULL) {\n"); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 353aaa8bb..6d559d192 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1456,8 +1456,7 @@ int Language::unrollVirtualMethods(Node *n, if (!checkAttribute(ni, "storage", "virtual")) continue; nodeType = Getattr(ni, "nodeType"); /* we need to add only the methods(cdecl), no destructors */ - if (Cmp(nodeType, "cdecl") == 0 && - !checkAttribute(ni, "feature:nodirector", "1")) { + if ((Cmp(nodeType, "cdecl") == 0)) { decl = Getattr(ni, "decl"); /* extra check for function type and proper access */ if (SwigType_isfunction(decl) && @@ -1467,7 +1466,6 @@ int Language::unrollVirtualMethods(Node *n, String *method_id = NewStringf("%s|%s", name, local_decl); String *fqname = NewStringf("%s::%s", classname, name); Hash *item = NewHash(); - Setattr(ni, "feature:director", "1"); Setattr(item, "fqName", fqname); Setattr(item, "methodNode", ni); Setattr(vm, method_id, item); @@ -1557,6 +1555,9 @@ int Language::classDirectorMethods(Node *n) { item = k.item; String *method = Getattr(item, "methodNode"); String *fqname = Getattr(item, "fqName"); + if (!Cmp(Getattr(method, "feature:nodirector"), "1")) + continue; + if (classDirectorMethod(method, n, fqname) == SWIG_OK) { Setattr(item, "director", "1"); }