From 1c4ec59e450643e641ebe7e8095f8b911bc41fd9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 2 Dec 2008 20:21:16 +0000 Subject: [PATCH] Apply patch #2143727 for Python from Serge Monkewitz to fix importing base classes when the package option is specified in %module and that module is %import'ed git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10960 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 10 +++++++--- Examples/test-suite/packageoption.h | 9 +++++---- Examples/test-suite/packageoption.list | 1 + Examples/test-suite/packageoption_a.i | 10 ++++++++-- Examples/test-suite/packageoption_b.i | 2 +- Examples/test-suite/packageoption_c.i | 13 +++++++++++++ Examples/test-suite/perl5/packageoption_runme.pl | 8 ++++---- Source/Modules/python.cxx | 6 +++++- 8 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 Examples/test-suite/packageoption_c.i diff --git a/CHANGES.current b/CHANGES.current index c00ae694c..d2d5131dc 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,10 +1,14 @@ Version 1.3.37 (in progress) ============================ +2008-12-02: wsfulton + [Python] Apply patch #2143727 from Serge Monkewitz to fix importing base classes + when the package option is specified in %module and that module is %import'ed. + 2008-11-28: wsfulton - [UTL] Fix some incorrect acceptance of types in the STL, eg a double * element passed - into a vector constructor would be accepted, but the ensuing behaviour was - undefined. Now the type conversion correctly raises an exception. + [UTL] Fix #2080497. Some incorrect acceptance of types in the STL, eg a double * element + passed into a vector constructor would be accepted, but the ensuing behaviour + was undefined. Now the type conversion correctly raises an exception. 2008-11-24: wsfulton Add -outcurrentdir option. This sets the default output directory to the current diff --git a/Examples/test-suite/packageoption.h b/Examples/test-suite/packageoption.h index a7ef499aa..82f29d1c7 100644 --- a/Examples/test-suite/packageoption.h +++ b/Examples/test-suite/packageoption.h @@ -1,5 +1,6 @@ -class A -{ - public: - int testInt() { return 2;} +struct Base { + virtual int vmethod() { return 1; } + int basemethod() { return 1; } + virtual ~Base() {} }; + diff --git a/Examples/test-suite/packageoption.list b/Examples/test-suite/packageoption.list index 4bdabeccf..da125c2a3 100644 --- a/Examples/test-suite/packageoption.list +++ b/Examples/test-suite/packageoption.list @@ -1,2 +1,3 @@ packageoption_a packageoption_b +packageoption_c diff --git a/Examples/test-suite/packageoption_a.i b/Examples/test-suite/packageoption_a.i index e95091b0d..b28278282 100644 --- a/Examples/test-suite/packageoption_a.i +++ b/Examples/test-suite/packageoption_a.i @@ -1,4 +1,4 @@ -%module(package="C") "packageoption_a"; +%module(package="CommonPackage") "packageoption_a"; %inline %{ class A @@ -6,5 +6,11 @@ class A public: int testInt() { return 2;} }; - %} + +%{ +#include "packageoption.h" +%} + +%include "packageoption.h" + diff --git a/Examples/test-suite/packageoption_b.i b/Examples/test-suite/packageoption_b.i index 466853cc0..40a44be14 100644 --- a/Examples/test-suite/packageoption_b.i +++ b/Examples/test-suite/packageoption_b.i @@ -1,4 +1,4 @@ -%module(package="C") "packageoption_b"; +%module(package="CommonPackage") "packageoption_b"; %inline %{ class B diff --git a/Examples/test-suite/packageoption_c.i b/Examples/test-suite/packageoption_c.i new file mode 100644 index 000000000..f43e47002 --- /dev/null +++ b/Examples/test-suite/packageoption_c.i @@ -0,0 +1,13 @@ +%module(package="PackageC") "packageoption_c"; + +%import "packageoption_a.i" + +%inline %{ +#include "packageoption.h" + +struct Derived : Base { + virtual int vmethod() { return 2; } + virtual ~Derived() {} +}; + +%} diff --git a/Examples/test-suite/perl5/packageoption_runme.pl b/Examples/test-suite/perl5/packageoption_runme.pl index debea78e1..d94a7a1fd 100644 --- a/Examples/test-suite/perl5/packageoption_runme.pl +++ b/Examples/test-suite/perl5/packageoption_runme.pl @@ -14,11 +14,11 @@ sub ok_not ($;$) { ok($test, $name); } -my $a = C::A->new(); +my $a = CommonPackage::A->new(); -isa_ok($a, 'C::A'); +isa_ok($a, 'CommonPackage::A'); -my $b = C::B->new(); +my $b = CommonPackage::B->new(); -isa_ok($b, 'C::B'); +isa_ok($b, 'CommonPackage::B'); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 5b20f88a1..a9a3833ff 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -925,7 +925,11 @@ public: if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) { Printf(import, "_%s\n", modname); if (!Strstr(f_shadow_imports, import)) { - Printf(f_shadow, "import %s\n", modname); + if (pkg && (!package || Strcmp(pkg, package) != 0)) { + Printf(f_shadow, "import %s.%s\n", pkg, modname); + } else { + Printf(f_shadow, "import %s\n", modname); + } Printv(f_shadow_imports, import, NULL); } }