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
This commit is contained in:
Marcelo Matus 2004-01-21 00:46:08 +00:00
commit 9cfb9a490b
6 changed files with 80 additions and 11 deletions

View file

@ -0,0 +1,34 @@
%module(directors="1") frob;
%header %{
#include <iostream>
%}
%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()";
}
%}

View file

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

View file

@ -0,0 +1,7 @@
from frob import *
foo = Bravo();
s = foo.abs_method();
if s != "Bravo::abs_method()":
raise RuntimeError, s

View file

@ -0,0 +1,6 @@
require 'frob'
foo = Frob::Bravo.new;
s = foo.abs_method;
raise RuntimeError if s != "Bravo::abs_method()"

View file

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

View file

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