Merge branch 'ahnolds-classic_python'

* ahnolds-classic_python:
  Updating changelog and marking -classic as passing CI
  Support checking names of old-style classic classes
  Don't claim to new-style support in classic mode
  Clean up setting _object
  Removing __swig_getmethods__ for static methods
  Support python(pre|ap)pend on static methods in classic mode
  Add support for static methods in classic mode
  When possible, use PyInt rather than PyLong
This commit is contained in:
William S Fulton 2016-02-06 08:01:08 +00:00
commit bb01ed3286
8 changed files with 53 additions and 34 deletions

View file

@ -158,10 +158,6 @@ matrix:
os: linux
env: SWIGLANG=ocaml
# Not quite working yet
- compiler: gcc
os: linux
env: SWIGLANG=python SWIG_FEATURES=-classic
# Not quite working yet
- compiler: gcc
os: linux
env: SWIGLANG=python SWIG_FEATURES=-O

View file

@ -13,6 +13,18 @@ Version 3.0.9 (in progress)
2016-01-27: steeve
[Go] Ensure structs are properly packed between gc and GCC/clang.
2016-01-25: ahnolds
[Python] Support the full Python test suite in -classic mode
* Convert long/unsigned long/long long/unsigned long long to PyInt
rather than PyLong when possible. Certain python functions like
len() require a PyInt when operating on old-style classes.
* Add support for static methods in classic mode, including support
for pythonappend, pythonprepend, and docstrings.
* Removing the use of __swig_getmethods__ for static member methods
since they will always be found by the standard argument lookup
* Fix a bug where the wrong type of exception was caught when
checking for new-style class support
2016-01-23: ahnolds
[Go] Enable support for the Go test-suite on OSX:
* The linker on OSX requires that all symbols (even weak symbols)

View file

@ -8,6 +8,12 @@ import pkg2.foo
print " Finished importing pkg2.foo"
var2 = pkg2.foo.Pkg2_Foo()
if str(type(var2)).find("'pkg2.foo.Pkg2_Foo'") == -1:
raise RuntimeError("failed type checking: " + str(type(var2)))
classname = str(type(var2))
# Check for an old-style class if swig was run in -classic mode
if classname == "<type 'instance'>":
classname = str(var2.__class__)
if classname.find("pkg2.foo.Pkg2_Foo") == -1:
raise RuntimeError("failed type checking: " + classname)
print " Successfully created object pkg2.foo.Pkg2_Foo"

View file

@ -7,6 +7,12 @@ import pkg1.pkg2.foo
print " Finished importing pkg1.pkg2.foo"
var2 = pkg1.pkg2.foo.Pkg2_Foo()
if str(type(var2)).find("'pkg1.pkg2.foo.Pkg2_Foo'") == -1:
raise RuntimeError("failed type checking: " + str(type(var2)))
classname = str(type(var2))
# Check for an old-style class if swig was run in -classic mode
if classname == "<type 'instance'>":
classname = str(var2.__class__)
if classname.find("pkg1.pkg2.foo.Pkg2_Foo") == -1:
raise RuntimeError("failed type checking: " + classname)
print " Successfully created object pkg1.pkg2.foo.Pkg2_Foo"

View file

@ -20,3 +20,10 @@ if grabpath() != os.path.dirname(mypath):
if grabstaticpath() != os.path.basename(mypath):
raise RuntimeError("grabstaticpath failed")
clearstaticpath()
if grabstaticpath() != None:
raise RuntimeError("Resetting staticfuncpath failed")
Test.static_func()
if grabstaticpath() != os.path.basename(mypath):
raise RuntimeError("grabstaticpath failed")

View file

@ -12,6 +12,9 @@ def grabpath():
return funcpath
def grabstaticpath():
return staticfuncpath
def clearstaticpath():
global staticfuncpath
staticfuncpath = None
%}
%pythonappend Test::func %{

View file

@ -67,7 +67,7 @@ SWIGINTERNINLINE PyObject*
/* long */
%fragment(SWIG_From_frag(long),"header") {
%define_as(SWIG_From_dec(long), PyLong_FromLong)
%define_as(SWIG_From_dec(long), PyInt_FromLong)
}
%fragment(SWIG_AsVal_frag(long),"header",
@ -123,7 +123,7 @@ SWIGINTERNINLINE PyObject*
SWIG_From_dec(unsigned long)(unsigned long value)
{
return (value > LONG_MAX) ?
PyLong_FromUnsignedLong(value) : PyLong_FromLong(%numeric_cast(value,long));
PyLong_FromUnsignedLong(value) : PyInt_FromLong(%numeric_cast(value,long));
}
}
@ -186,7 +186,7 @@ SWIGINTERNINLINE PyObject*
SWIG_From_dec(long long)(long long value)
{
return ((value < LONG_MIN) || (value > LONG_MAX)) ?
PyLong_FromLongLong(value) : PyLong_FromLong(%numeric_cast(value,long));
PyLong_FromLongLong(value) : PyInt_FromLong(%numeric_cast(value,long));
}
%#endif
}
@ -244,7 +244,7 @@ SWIGINTERNINLINE PyObject*
SWIG_From_dec(unsigned long long)(unsigned long long value)
{
return (value > LONG_MAX) ?
PyLong_FromUnsignedLongLong(value) : PyLong_FromLong(%numeric_cast(value,long));
PyLong_FromUnsignedLongLong(value) : PyInt_FromLong(%numeric_cast(value,long));
}
%#endif
}

View file

@ -912,17 +912,12 @@ public:
tab4, "try:\n", tab8, "strthis = \"proxy of \" + self.this.__repr__()\n",
tab4, "except __builtin__.Exception:\n", tab8, "strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL);
if (!classic) {
/* Usage of types.ObjectType is deprecated.
* But don't sure wether this would broken old Python?
*/
if (!classic && !modern) {
Printv(f_shadow,
// "import types\n",
"try:\n",
// " _object = types.ObjectType\n",
tab4, "_object = object\n", tab4, "_newclass = 1\n", "except AttributeError:\n", tab4, "class _object:\n", tab8, "pass\n", tab4, "_newclass = 0\n",
// "del types\n",
"\n\n", NIL);
tab4, "_object = object\n", tab4, "_newclass = 1\n",
"except __builtin__.Exception:\n",
tab4, "class _object:\n", tab8, "pass\n", tab4, "_newclass = 0\n\n", NIL);
}
}
if (modern) {
@ -1007,7 +1002,7 @@ public:
if (shadow) {
Swig_banner_target_lang(f_shadow_py, "#");
if (!modern) {
if (!modern && !classic) {
Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL);
}
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
@ -4710,7 +4705,7 @@ public:
}
if (shadow) {
if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) {
if (!Getattr(n, "feature:python:callback") && have_addtofunc(n)) {
int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
String *parms = make_pyParmList(n, false, false, kw);
String *callParms = make_pyParmList(n, false, true, kw);
@ -4726,25 +4721,19 @@ public:
} else {
Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL);
}
if (!modern)
Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL);
Printv(f_shadow, tab4, symname, " = staticmethod(", symname, ")\n", NIL);
if (!modern) {
Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL);
}
} else {
if (!modern) {
Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n",
NIL);
}
if (!classic) {
if (!modern)
Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL);
Printv(f_shadow, tab4, symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname),
")\n", NIL);
}
if (classic || !modern) {
if (!classic)
Printv(f_shadow, tab4, "else:\n", tab4, NIL);
Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL);
}
}
}
return SWIG_OK;