Merged the wxPy_newswig branch into the HEAD branch (main trunk)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24541 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-11-12 21:34:20 +00:00
parent eb6a4098a0
commit d14a1e2856
987 changed files with 671143 additions and 783083 deletions

47
wxPython/SWIG/README.txt Normal file
View File

@@ -0,0 +1,47 @@
SWIG 1.3 Patches
================
This directory holds a set of patches for the CVS version of SWIG that
are required if you wish to use SWIG for wxPython development, or for
building your own extension modules that need to interface with
wxPython. These have been submitted to SWIG's SourceForge patch
tracker, so hopefully they will get incorporated into the main SWIG
source tree soon.
------------------------------------------------------------------------
swig.python-2.patch Adds the ability to turn off the automatic
generation of __repr__ methods on a class
by class basis. Used in wxPython for
classes that have a __repr__ added in
%pythoncode directives. See SF Patch
#835471.
------------------------------------------------------------------------
These patches have already been checked in to SWIG's CVS
------------------------------------------------------------------------
swig.SplitLines.patch Adds a new SplitLines function to the DOH
library. See SF Patch #829317.
*Checked in 10/31/2003*
swig.xml.patch Adds an option that drastically reduces
the size of the XML output of SWIG, which
increases the performance of the
build_renamers script used in the wxPython
build. See SF Patch #829319.
*Checked in 10/31/2003*
swig.python.patch Lots of changes for SWIG's Python module,
especially in how the proxy code is
generated. See swig.python.patch.txt for
more details, also SF Patch #829325.
*Checked in 10/31/2003*
------------------------------------------------------------------------

View File

@@ -0,0 +1,75 @@
Index: Source/DOH/doh.h
===================================================================
RCS file: /cvsroot/SWIG/Source/DOH/doh.h,v
retrieving revision 1.7
diff -u -r1.7 doh.h
--- Source/DOH/doh.h 11 Sep 2003 20:26:53 -0000 1.7
+++ Source/DOH/doh.h 24 Oct 2003 00:00:41 -0000
@@ -99,6 +99,7 @@
#define DohNewHash DOH_NAMESPACE(NewHash)
#define DohNewVoid DOH_NAMESPACE(NewVoid)
#define DohSplit DOH_NAMESPACE(Split)
+#define DohSplitLines DOH_NAMESPACE(SplitLines)
#define DohNone DOH_NAMESPACE(None)
#define DohCall DOH_NAMESPACE(Call)
#define DohObjMalloc DOH_NAMESPACE(ObjMalloc)
@@ -304,6 +305,7 @@
extern DOHVoid *DohNewVoid(void *ptr, void (*del)(void *));
extern DOHList *DohSplit(DOHFile *input, char ch, int nsplits);
+extern DOHList *DohSplitLines(DOHFile *input);
extern DOH *DohNone;
extern void DohMemoryDebug(void);
@@ -378,6 +380,7 @@
#define Strchr DohStrchr
#define Copyto DohCopyto
#define Split DohSplit
+#define SplitLines DohSplitLines
#define Setmark DohSetmark
#define Getmark DohGetmark
#define None DohNone
Index: Source/DOH/fio.c
===================================================================
RCS file: /cvsroot/SWIG/Source/DOH/fio.c,v
retrieving revision 1.2
diff -u -r1.2 fio.c
--- Source/DOH/fio.c 15 Aug 2003 19:37:27 -0000 1.2
+++ Source/DOH/fio.c 24 Oct 2003 00:00:42 -0000
@@ -497,6 +497,36 @@
}
/* -----------------------------------------------------------------------------
+ * DohSplitLines()
+ *
+ * Split an input stream into a list of strings delimited by newline characters.
+ * ----------------------------------------------------------------------------- */
+
+DOH *
+DohSplitLines(DOH *in) {
+ DOH *list;
+ DOH *str;
+ int c = 0;
+
+ list = NewList();
+
+ if (DohIsString(in)) {
+ Seek(in,0,SEEK_SET);
+ }
+
+ while (c != EOF) {
+ str = NewString("");
+ while ((c = Getc(in)) != '\n' && c != EOF) {
+ Putc(c, str);
+ }
+ Append(list,str);
+ Delete(str);
+ }
+ return list;
+}
+
+
+/* -----------------------------------------------------------------------------
* DohReadline()
*
* Read a single input line and return it as a string.

View File

@@ -0,0 +1,19 @@
Index: Source/Modules/python.cxx
===================================================================
RCS file: /cvsroot/SWIG/Source/Modules/python.cxx,v
retrieving revision 1.26
diff -u -r1.26 python.cxx
--- Source/Modules/python.cxx 31 Oct 2003 17:55:38 -0000 1.26
+++ Source/Modules/python.cxx 4 Nov 2003 01:34:47 -0000
@@ -1870,7 +1870,10 @@
classic = 0;
modern = 1;
}
-
+ if (Getattr(n,"feature:noautorepr")) {
+ have_repr = 1;
+ }
+
shadow_indent = (String *) tab4;
class_name = Getattr(n,"sym:name");

View File

@@ -0,0 +1,598 @@
Index: Source/Modules/python.cxx
===================================================================
RCS file: /cvsroot/SWIG/Source/Modules/python.cxx,v
retrieving revision 1.25
diff -u -r1.25 python.cxx
--- Source/Modules/python.cxx 23 Sep 2003 21:26:04 -0000 1.25
+++ Source/Modules/python.cxx 30 Oct 2003 02:39:33 -0000
@@ -292,6 +292,9 @@
static String *shadow_indent = 0;
static int in_class = 0;
static int classic = 0;
+static int modern = 0;
+static int apply = 0;
+static int new_repr = 0;
/* C++ Support + Shadow Classes */
@@ -306,6 +309,9 @@
-interface <lib>- Set the lib name to <lib>\n\
-keyword - Use keyword arguments\n\
-classic - Use classic classes only\n\
+ -modern - Use modern python features only, without compatibility code\n\
+ -apply - Use apply() in proxy classes\n\
+ -new_repr - Use more informative version of __repr__ in proxy classes\n\
-noexcept - No automatic exception handling\n\
-noproxy - Don't generate proxy classes \n\n";
@@ -344,6 +350,12 @@
} else if ((strcmp(argv[i],"-shadow") == 0) || ((strcmp(argv[i],"-proxy") == 0))) {
shadow = 1;
Swig_mark_arg(i);
+ } else if (strcmp(argv[i],"-apply") == 0) {
+ apply = 1;
+ Swig_mark_arg(i);
+ } else if (strcmp(argv[i],"-new_repr") == 0) {
+ new_repr = 1;
+ Swig_mark_arg(i);
} else if ((strcmp(argv[i],"-noproxy") == 0)) {
shadow = 0;
Swig_mark_arg(i);
@@ -353,6 +365,10 @@
} else if (strcmp(argv[i],"-classic") == 0) {
classic = 1;
Swig_mark_arg(i);
+ } else if (strcmp(argv[i],"-modern") == 0) {
+ classic = 0;
+ modern = 1;
+ Swig_mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stderr);
} else if (strcmp (argv[i], "-ldflags") == 0) {
@@ -480,47 +496,54 @@
Printv(f_shadow,
"# This file was created automatically by SWIG.\n",
"# Don't modify this file, modify the SWIG interface instead.\n",
- "# This file is compatible with both classic and new-style classes.\n",
NIL);
- Printf(f_shadow,"import %s\n", module);
-
- // Python-2.2 object hack
-
- Printv(f_shadow,
- "def _swig_setattr(self,class_type,name,value):\n",
- tab4, "if (name == \"this\"):\n",
- tab4, tab4, "if isinstance(value, class_type):\n",
- tab4, tab8, "self.__dict__[name] = value.this\n",
- tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n",
- tab4, tab8, "del value.thisown\n",
- tab4, tab8, "return\n",
- // tab8, "if (name == \"this\") or (name == \"thisown\"): self.__dict__[name] = value; return\n",
- tab4, "method = class_type.__swig_setmethods__.get(name,None)\n",
- tab4, "if method: return method(self,value)\n",
- tab4, "self.__dict__[name] = value\n\n",
- NIL);
+ if (! modern) {
+ Printv(f_shadow,
+ "# This file is compatible with both classic and new-style classes.\n",
+ NIL);
+ }
+
+ Printf(f_shadow,"\nimport %s\n\n", module);
- Printv(f_shadow,
- "def _swig_getattr(self,class_type,name):\n",
- tab4, "method = class_type.__swig_getmethods__.get(name,None)\n",
- tab4, "if method: return method(self)\n",
- tab4, "raise AttributeError,name\n\n",
- NIL);
+ if (! modern) {
+ // Python-2.2 object hack
+ Printv(f_shadow,
+ "def _swig_setattr(self,class_type,name,value):\n",
+ tab4, "if (name == \"this\"):\n",
+ tab4, tab4, "if isinstance(value, class_type):\n",
+ tab4, tab8, "self.__dict__[name] = value.this\n",
+ tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n",
+ tab4, tab8, "del value.thisown\n",
+ tab4, tab8, "return\n",
+ // tab8, "if (name == \"this\") or (name == \"thisown\"): self.__dict__[name] = value; return\n",
+ tab4, "method = class_type.__swig_setmethods__.get(name,None)\n",
+ tab4, "if method: return method(self,value)\n",
+ tab4, "self.__dict__[name] = value\n\n",
+ NIL);
- if (!classic) {
- Printv(f_shadow,
- "import types\n",
- "try:\n",
- " _object = types.ObjectType\n",
- " _newclass = 1\n",
- "except AttributeError:\n",
- " class _object : pass\n",
- " _newclass = 0\n",
- "\n\n",
- NIL);
+ Printv(f_shadow,
+ "def _swig_getattr(self,class_type,name):\n",
+ tab4, "method = class_type.__swig_getmethods__.get(name,None)\n",
+ tab4, "if method: return method(self)\n",
+ tab4, "raise AttributeError,name\n\n",
+ NIL);
+
+ if (!classic) {
+ Printv(f_shadow,
+ "import types\n",
+ "try:\n",
+ " _object = types.ObjectType\n",
+ " _newclass = 1\n",
+ "except AttributeError:\n",
+ " class _object : pass\n",
+ " _newclass = 0\n",
+ "del types\n",
+ "\n\n",
+ NIL);
+ }
}
-
+
if (directorsEnabled()) {
// Try loading weakref.proxy, which is only available in Python 2.1 and higher
Printv(f_shadow,
@@ -610,6 +633,83 @@
return Language::importDirective(n);
}
+
+ /* ------------------------------------------------------------
+ * emitFuncCallHelper()
+ * Write the shadow code to call a function in the extension
+ * module. Takes into account the -apply flag and whether
+ * to use keyword args or not.
+ * ------------------------------------------------------------ */
+
+ String *funcCallHelper(String *name, int kw) {
+ String *str;
+
+ str = NewString("");
+ if (apply) {
+ Printv(str, "apply(", module, ".", name, ", args", (kw ? ", kwargs" : ""), ")", NIL);
+ } else {
+ Printv(str, module, ".", name, "(*args", (kw ? ", **kwargs" : ""), ")", NIL);
+ }
+ return str;
+ }
+
+
+ /* ------------------------------------------------------------
+ * emitFunctionShadowHelper()
+ * Refactoring some common code out of functionWrapper and
+ * dispatchFunction that writes the proxy code for non-member
+ * functions.
+ * ------------------------------------------------------------ */
+
+ void emitFunctionShadowHelper(Node *n, File *f_dest, String *name, int kw) {
+ if ( ! have_addtofunc(n) ) {
+ /* If there is no addtofunc directive then just assign from the extension module */
+ Printv(f_dest, "\n", name, " = ", module, ".", name, "\n", NIL);
+ } else {
+ /* Otherwise make a wrapper function to insert the code into */
+ Printv(f_dest, "\ndef ", name, "(*args", (kw ? ", **kwargs" : ""), "):\n", NIL);
+ Printv(f_dest, tab4, "val = ", funcCallHelper(name, kw), "\n", NIL);
+ Printv(f_dest, tab4, addtofunc(n), "\n", NIL);
+ Printv(f_dest, tab4, "return val\n", NIL);
+ }
+ }
+
+
+ /* ------------------------------------------------------------
+ * check_kwargs()
+ * check if using kwargs is allowed for this Node
+ * ------------------------------------------------------------ */
+
+ int check_kwargs(Node *n) {
+ return ((use_kw || Getattr(n,"feature:kwargs")) && !Getattr(n, "feature:nokwargs")) ? 1 : 0;
+ }
+
+
+ /* ------------------------------------------------------------
+ * have_addtofunc()
+ * Check if there is a %addtofunc directive and it has text
+ * ------------------------------------------------------------ */
+
+ bool have_addtofunc(Node *n) {
+ String* str = Getattr(n, "feature:addtofunc");
+ return (str != NULL && Len(str) > 0);
+ }
+
+ /* ------------------------------------------------------------
+ * addtofunc()
+ * Get the %addtofunc code, stripping off {} if neccessary
+ * ------------------------------------------------------------ */
+
+ String *addtofunc(Node *n) {
+ String* str = Getattr(n, "feature:addtofunc");
+ char* t = Char(str);
+ if (*t == '{') {
+ Delitem(str ,0);
+ Delitem(str,DOH_END);
+ }
+ return str;
+ }
+
/* ------------------------------------------------------------
* add_method()
* ------------------------------------------------------------ */
@@ -650,7 +750,7 @@
int num_required;
int num_arguments;
int varargs = 0;
- int allow_kwargs = (use_kw || Getattr(n,"feature:kwargs")) ? 1 : 0;
+ int allow_kwargs = check_kwargs(n);
/* member of a director class? */
String *nodeType = Getattr(n, "nodeType");
@@ -1007,11 +1107,7 @@
/* Create a shadow for this function (if enabled and not in a member function) */
if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) {
- if (in_class) {
- Printv(f_shadow_stubs,iname, " = ", module, ".", iname, "\n\n", NIL);
- } else {
- Printv(f_shadow,iname, " = ", module, ".", iname, "\n\n", NIL);
- }
+ emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, iname, allow_kwargs);
}
} else {
if (!Getattr(n,"sym:nextSibling")) {
@@ -1068,7 +1164,7 @@
/* Create a shadow for this function (if enabled and not in a member function) */
if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) {
- Printv(f_shadow_stubs,symname, " = ", module, ".", symname, "\n\n", NIL);
+ emitFunctionShadowHelper(n, f_shadow_stubs, symname, 0);
}
DelWrapper(f);
Delete(dispatch);
@@ -1754,6 +1850,7 @@
virtual int classHandler(Node *n) {
int oldclassic = classic;
+ int oldmodern = modern;
if (shadow) {
@@ -1763,8 +1860,16 @@
if (Getattr(n,"cplus:exceptionclass")) {
classic = 1;
+ modern = 0;
+ }
+ if (Getattr(n,"feature:classic")) {
+ classic = 1;
+ modern = 0;
+ }
+ if (Getattr(n,"feature:modern")) {
+ classic = 0;
+ modern = 1;
}
- if (Getattr(n,"feature:classic")) classic = 1;
shadow_indent = (String *) tab4;
@@ -1798,30 +1903,32 @@
Printf(f_shadow,"(%s)", base_class);
} else {
if (!classic) {
- Printf(f_shadow,"(_object)");
+ Printf(f_shadow, modern ? "(object)" : "(_object)");
}
}
Printf(f_shadow,":\n");
- Printv(f_shadow,tab4,"__swig_setmethods__ = {}\n",NIL);
- if (Len(base_class)) {
- Printf(f_shadow,"%sfor _s in [%s]: __swig_setmethods__.update(_s.__swig_setmethods__)\n",tab4,base_class);
- }
+ if (!modern) {
+ Printv(f_shadow,tab4,"__swig_setmethods__ = {}\n",NIL);
+ if (Len(base_class)) {
+ Printf(f_shadow,"%sfor _s in [%s]: __swig_setmethods__.update(_s.__swig_setmethods__)\n",tab4,base_class);
+ }
- Printv(f_shadow,
- tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n",
- NIL);
+ Printv(f_shadow,
+ tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n",
+ NIL);
- Printv(f_shadow,tab4,"__swig_getmethods__ = {}\n",NIL);
- if (Len(base_class)) {
- Printf(f_shadow,"%sfor _s in [%s]: __swig_getmethods__.update(_s.__swig_getmethods__)\n",tab4,base_class);
- }
+ Printv(f_shadow,tab4,"__swig_getmethods__ = {}\n",NIL);
+ if (Len(base_class)) {
+ Printf(f_shadow,"%sfor _s in [%s]: __swig_getmethods__.update(_s.__swig_getmethods__)\n",tab4,base_class);
+ }
- Printv(f_shadow,
- tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n",
- NIL);
+ Printv(f_shadow,
+ tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n",
+ NIL);
+ }
}
-
+
/* Emit all of the members */
in_class = 1;
@@ -1853,21 +1960,37 @@
if (!have_repr) {
/* Supply a repr method for this class */
- Printv(f_shadow,
- tab4, "def __repr__(self):\n",
- tab8, "return \"<C ", class_name," instance at %s>\" % (self.this,)\n",
- NIL);
+ if (new_repr) {
+ Printv(f_shadow,
+ tab4, "def __repr__(self):\n",
+ tab8, "return \"<%s.%s; proxy of ", CPlusPlus ? "C++ " : "C ", real_classname," instance at %s>\" % (self.__class__.__module__, self.__class__.__name__, self.this,)\n",
+ NIL);
+ }
+ else {
+ Printv(f_shadow,
+ tab4, "def __repr__(self):\n",
+ tab8, "return \"<C ", real_classname," instance at %s>\" % (self.this,)\n",
+ NIL);
+ }
}
- /* Now build the real class with a normal constructor */
+ /* Now the Ptr class */
Printv(f_shadow,
"\nclass ", class_name, "Ptr(", class_name, "):\n",
- tab4, "def __init__(self,this):\n",
- tab8, "_swig_setattr(self, ", class_name, ", 'this', this)\n",
- tab8, "if not hasattr(self,\"thisown\"): _swig_setattr(self, ", class_name, ", 'thisown', 0)\n",
+ tab4, "def __init__(self, this):\n", NIL);
+ if (!modern) {
+ Printv(f_shadow,
+ tab8, "_swig_setattr(self, ", class_name, ", 'this', this)\n",
+ tab8, "if not hasattr(self,\"thisown\"): _swig_setattr(self, ", class_name, ", 'thisown', 0)\n",
+ tab8, "_swig_setattr(self, ", class_name, ",self.__class__,", class_name, ")\n",
+ NIL);
+ } else {
+ Printv(f_shadow,
+ tab8, "self.this = this\n",
+ tab8, "if not hasattr(self,\"thisown\"): self.thisown = 0\n",
+ tab8, "self.__class__ = ", class_name, "\n", NIL);
// tab8,"try: self.this = this.this; self.thisown = getattr(this,'thisown',0); this.thisown=0\n",
// tab8,"except AttributeError: self.this = this\n"
- tab8, "_swig_setattr(self, ", class_name, ",self.__class__,", class_name, ")\n",
- NIL);
+ }
Printf(f_shadow,"%s.%s_swigregister(%sPtr)\n", module, class_name, class_name,0);
shadow_indent = 0;
@@ -1875,6 +1998,7 @@
Clear(f_shadow_stubs);
}
classic = oldclassic;
+ modern = oldmodern;
return SWIG_OK;
}
@@ -1894,7 +2018,7 @@
if (!Getattr(n,"sym:nextSibling")) {
if (shadow) {
- int allow_kwargs = (use_kw || Getattr(n,"feature:kwargs")) ? 1 : 0;
+ int allow_kwargs = (check_kwargs(n) && !Getattr(n,"sym:overloaded")) ? 1 : 0;
if (Strcmp(symname,"__repr__") == 0)
have_repr = 1;
@@ -1902,14 +2026,18 @@
String *pycode = pythoncode(Getattr(n,"feature:shadow"),tab4);
Printv(f_shadow,pycode,"\n",NIL);
} else {
- if (allow_kwargs && !Getattr(n,"sym:overloaded")) {
- Printv(f_shadow,tab4, "def ", symname, "(*args, **kwargs): ", NIL);
- Printv(f_shadow, "return apply(", module, ".", Swig_name_member(class_name,symname), ",args, kwargs)\n", NIL);
- } else {
- Printv(f_shadow, tab4, "def ", symname, "(*args): ", NIL);
- Printv(f_shadow, "return apply(", module, ".", Swig_name_member(class_name,symname), ",args)\n",NIL);
- }
- }
+
+ Printv(f_shadow, tab4, "def ", symname, "(*args", (allow_kwargs ? ", **kwargs" : ""), "): ", NIL);
+ if ( have_addtofunc(n) ) {
+ Printv(f_shadow, "\n", NIL);
+ Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL);
+ Printv(f_shadow, tab8, addtofunc(n), "\n", NIL);
+ Printv(f_shadow, tab8, "return val\n", NIL);
+ } else {
+ Printv(f_shadow, "return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL);
+ }
+ }
+
}
}
return SWIG_OK;
@@ -1923,10 +2051,28 @@
String *symname = Getattr(n,"sym:name");
Language::staticmemberfunctionHandler(n);
if (shadow) {
- Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(class_name, symname), "\n", NIL);
- if (!classic) {
- Printv(f_shadow, tab4, "if _newclass:", symname, " = staticmethod(", module, ".",
- Swig_name_member(class_name, symname), ")\n", NIL);
+ if ( !classic && have_addtofunc(n) ) {
+ int kw = (check_kwargs(n) && !Getattr(n,"sym:overloaded")) ? 1 : 0;
+ Printv(f_shadow, tab4, "def ", symname, "(*args", (kw ? ", **kwargs" : ""), "):\n", NIL);
+ Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n", NIL);
+ Printv(f_shadow, tab8, addtofunc(n), "\n", NIL);
+ Printv(f_shadow, tab8, "return val\n", NIL);
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", 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(class_name, symname), "\n", NIL);
+ }
+ if (!classic) {
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname,
+ " = staticmethod(", module, ".",
+ Swig_name_member(class_name, symname), ")\n", NIL);
+ }
}
}
return SWIG_OK;
@@ -1972,7 +2118,7 @@
if (!Getattr(n,"sym:nextSibling")) {
if (shadow) {
- int allow_kwargs = (use_kw || Getattr(n,"feature:kwargs")) ? 1 : 0;
+ int allow_kwargs = (check_kwargs(n) && (!Getattr(n,"sym:overloaded"))) ? 1 : 0;
if (!have_constructor) {
if (Getattr(n,"feature:shadow")) {
String *pycode = pythoncode(Getattr(n,"feature:shadow"),tab4);
@@ -1991,18 +2137,25 @@
tab8, tab4, "args = (self,) + args\n",
NIL);
}
- if ((allow_kwargs) && (!Getattr(n,"sym:overloaded"))) {
- Printv(f_shadow, tab4, "def __init__(self,*args,**kwargs):\n", NIL);
- Printv(f_shadow, pass_self, NIL);
- Printv(f_shadow, tab8, "_swig_setattr(self, ", rclassname, ", 'this', apply(", module, ".", Swig_name_construct(symname), ",args, kwargs))\n", NIL);
- } else {
- Printv(f_shadow, tab4, "def __init__(self,*args):\n",NIL);
- Printv(f_shadow, pass_self, NIL);
- Printv(f_shadow, tab8, "_swig_setattr(self, ", rclassname, ", 'this', apply(", module, ".", Swig_name_construct(symname), ",args))\n", NIL);
- }
- Printv(f_shadow,
- tab8, "_swig_setattr(self, ", rclassname, ", 'thisown', 1)\n",
- NIL);
+
+ Printv(f_shadow, tab4, "def __init__(self, *args",
+ (allow_kwargs ? ", **kwargs" : ""), "):\n", NIL);
+ Printv(f_shadow, pass_self, NIL);
+ if (!modern) {
+ Printv(f_shadow, tab8, "_swig_setattr(self, ", rclassname, ", 'this', ",
+ funcCallHelper(Swig_name_construct(symname), allow_kwargs), ")\n", NIL);
+ Printv(f_shadow,
+ tab8, "_swig_setattr(self, ", rclassname, ", 'thisown', 1)\n",
+ NIL);
+ } else {
+ Printv(f_shadow, tab8, "newobj = ",
+ funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", NIL);
+ Printv(f_shadow, tab8, "self.this = newobj.this\n", NIL);
+ Printv(f_shadow, tab8, "self.thisown = 1\n", NIL);
+ Printv(f_shadow, tab8, "del newobj.thisown\n", NIL);
+ }
+ if ( have_addtofunc(n) )
+ Printv(f_shadow, tab8, addtofunc(n), "\n", NIL);
Delete(pass_self);
}
have_constructor = 1;
@@ -2014,19 +2167,16 @@
String *pycode = pythoncode(Getattr(n,"feature:shadow"),"");
Printv(f_shadow_stubs,pycode,"\n",NIL);
} else {
- if ((allow_kwargs) && (!Getattr(n,"sym:overloaded")))
- Printv(f_shadow_stubs, "def ", symname, "(*args,**kwargs):\n", NIL);
- else
- Printv(f_shadow_stubs, "def ", symname, "(*args):\n", NIL);
-
- Printv(f_shadow_stubs, tab4, "val = apply(", NIL);
- if ((allow_kwargs) && (!Getattr(n,"sym:overloaded")))
- Printv(f_shadow_stubs, module, ".", Swig_name_construct(symname), ",args,kwargs)\n", NIL);
- else
- Printv(f_shadow_stubs, module, ".", Swig_name_construct(symname), ",args)\n", NIL);
- Printv(f_shadow_stubs,tab4, "val.thisown = 1\n",
- tab4, "return val\n\n", NIL);
- }
+
+ Printv(f_shadow_stubs, "\ndef ", symname, "(*args",
+ (allow_kwargs ? ", **kwargs" : ""), "):\n", NIL);
+ Printv(f_shadow_stubs, tab4, "val = ",
+ funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", NIL);
+ Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL);
+ if ( have_addtofunc(n) )
+ Printv(f_shadow_stubs, tab4, addtofunc(n), "\n", NIL);
+ Printv(f_shadow_stubs, tab4, "return val\n", NIL);
+ }
}
}
}
@@ -2045,7 +2195,9 @@
Language::destructorHandler(n);
shadow = oldshadow;
if (shadow) {
- Printv(f_shadow, tab4, "def __del__(self, destroy= ", module, ".", Swig_name_destroy(symname), "):\n", NIL);
+ Printv(f_shadow, tab4, "def __del__(self, destroy=", module, ".", Swig_name_destroy(symname), "):\n", NIL);
+ if ( have_addtofunc(n) )
+ Printv(f_shadow, tab8, addtofunc(n), "\n", NIL);
Printv(f_shadow, tab8, "try:\n", NIL);
Printv(f_shadow, tab4, tab8, "if self.thisown: destroy(self)\n", NIL);
Printv(f_shadow, tab8, "except: pass\n", NIL);
@@ -2066,21 +2218,22 @@
shadow = oldshadow;
if (shadow) {
- int immutable = 0;
- if (!Getattr(n,"feature:immutable")) {
- Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", Swig_name_set(Swig_name_member(class_name,symname)), "\n", NIL);
- } else {
- immutable = 1;
+ int immutable = (Getattr(n,"feature:immutable") != NULL);
+ if (!modern) {
+ if (!immutable) {
+ Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", Swig_name_set(Swig_name_member(class_name,symname)), "\n", NIL);
+ }
+ Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", Swig_name_get(Swig_name_member(class_name,symname)),"\n", NIL);
}
- Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", Swig_name_get(Swig_name_member(class_name,symname)),"\n", NIL);
-
if (!classic) {
if (immutable) {
- Printv(f_shadow,tab4,"if _newclass:", symname," = property(", module, ".",
+ Printv(f_shadow,tab4, modern ? "" : "if _newclass:",
+ symname," = property(", module, ".",
Swig_name_get(Swig_name_member(class_name,symname)),")\n", NIL);
} else {
- Printv(f_shadow,tab4,"if _newclass:", symname," = property(",
- module, ".", Swig_name_get(Swig_name_member(class_name,symname)),",",
+ Printv(f_shadow,tab4, modern ? "" : "if _newclass:",
+ symname," = property(",
+ module, ".", Swig_name_get(Swig_name_member(class_name,symname)),", ",
module, ".", Swig_name_set(Swig_name_member(class_name,symname)),")\n", NIL);
}
}
@@ -2142,8 +2295,9 @@
Delitem(temp,0);
Delitem(temp,DOH_END);
}
+
/* Split the input text into lines */
- List *clist = DohSplit(temp,'\n',-1);
+ List *clist = DohSplitLines(temp);
Delete(temp);
int initial = 0;
String *s = 0;
@@ -2194,7 +2348,7 @@
if ((!ImportMode) && ((Cmp(section,"python") == 0) || (Cmp(section,"shadow") == 0))) {
if (shadow) {
String *pycode = pythoncode(code,shadow_indent);
- Printv(f_shadow, pycode, "\n", NIL);
+ Printv(f_shadow, pycode, NIL);
Delete(pycode);
}
} else {

View File

@@ -0,0 +1,43 @@
This patch makes a number of changes to the SWIG python module.
1. Add -apply option, and change the default code output to use the
foo(*args, **kw) calling syntax instead of using apply(). If the
-apply option is given then code is generated as before. This is
very similar to Patch #737281 but the new -modern option makes the
second half of that patch unnecessary so it is not included here.
2. Add -new_repr option. This is the same as my Patch #797002 which I
will mark as closed since it is no longer needed. When this new
option is used then the __repr__ methods that are generated for
proxy classes will be more informative and give details about the
python class and the C++ class.
3. Add %feature("addtofunc"). It allows you to insert one or more
lines of code inside the shadow method or function that is already
generated, instead of replacing the whole thing like
%feature("shadow") does. For __init__ it goes at the end, for
__del__ it goes at the begining and for all others the code
generated is expanded out to be like
def Bar(*args, **kwargs):
val = _module.Foo_Bar(*args, **kwargs)
return val
and the "addtofunc" code is inserted just before the return
statement. If the feature is not used for a particular method or
function then the shorter code is generated just like before.
4. A little bit of refactoring to make implementing addtofunc a little
easier.
5. Added a -modern command-line flag that will cause SWIG to omit the
cruft in the proxy modules that allows it to work with versions of
Python prior to 2.2. The result is a simpler, cleaner and faster
python proxy module, but one that requires Python 2.2 or greater.
For most of us this requirement is easy to live with!
I've been using and greatly benefiting from all these features with
wxPython for the last few weeks and have had no problems.
This patch depends upon Patch #829317.

View File

@@ -0,0 +1,58 @@
Index: Source/Modules/xml.cxx
===================================================================
RCS file: /cvsroot/SWIG/Source/Modules/xml.cxx,v
retrieving revision 1.7
diff -u -r1.7 xml.cxx
--- Source/Modules/xml.cxx 11 Sep 2003 20:26:56 -0000 1.7
+++ Source/Modules/xml.cxx 30 Oct 2003 01:29:32 -0000
@@ -14,6 +14,7 @@
static const char *usage = "\
XML Options (available with -xml)\n\
-xmllang <lang> - Typedef language\n\
+ -xmllite - More lightweight version of XML\n\
------\n\
deprecated (use -o): -xml <output.xml> - Use <output.xml> as output file (extension .xml mandatory)\n";
@@ -22,6 +23,8 @@
//static Node *view_top = 0;
static File *out = 0;
+static int xmllite = 0;
+
class XML
: public Language
@@ -79,6 +82,11 @@
{
fputs( usage, stderr );
}
+ if( strcmp( argv[iX], "-xmllite" ) == 0 )
+ {
+ Swig_mark_arg (iX);
+ xmllite = 1;
+ }
}
// Add a symbol to the parser for conditional compilation
@@ -93,6 +101,7 @@
{
String *outfile = Getattr(n,"outfile");
Replaceall(outfile,".cxx", ".xml");
+ Replaceall(outfile,".cpp", ".xml");
Replaceall(outfile,".c", ".xml");
out = NewFile(outfile,"w");
if (!out)
@@ -159,11 +168,11 @@
{
Xml_print_baselist( Getattr(obj,k) );
}
- else if (Cmp(k,"typescope") == 0)
+ else if (!xmllite && Cmp(k,"typescope") == 0)
{
Xml_print_typescope( Getattr(obj,k) );
}
- else if (Cmp(k,"typetab") == 0)
+ else if (!xmllite && Cmp(k,"typetab") == 0)
{
Xml_print_typetab( Getattr(obj,k) );
}