[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH]: SWIG/Python interface bug

From: Marshall White <cscidork_at_yahoo.com>
Date: 2003-02-01 05:49:37 CET

At the bottom of this email is the patch for the bug I wrote about in my last email.

Here is a before and after:
BEFORE:
mwhite@big-dog:/storage/code/python# ./py_broke.py /home/svnrepos /trunk
commit date = `_60141a08_p_char`
commit author = `_f0371a08_p_char`

AFTER:
mwhite@big-dog:/storage/code/python# ./py_broke.py /home/svnrepos /trunk
commit date = `2003-01-31T04:46:32.052521Z`
commit author = `mwhite`

Comments/suggestions?

Marshall

Log:
Fix SWIG Python interface so that C functions with arguments of type
"const char **" behave correctly.
* subversion/bindings/swig/svn_string.i
  (%typemap(python,argout,fragment="t_output_helper") const char **OUTPUT):
  Return an empty string instead of a Py_None binding. If the Python code
  is expecting something, and the function generates nothing, a run-time
  error will result.
  Added "in,numinputs=0" and an initial value for "temp" to
  (%typemap(python,in,numinputs=0) const char **OUTPUT
  (const char *temp = (const char *)0))

* subversion/bindings/swig/svn_fs.i:
  Move "const char **" from "%apply SWIGTYPE **OUTPARAM" to
  "%apply const char **OUTPUT"
  This forces C functions with "const char **" args to use the right binding.

Fix return value check for function fixed above
* tools/cvs2svn/cvs2svn.py (Commit::commit):
  Fixed return value check from "fs.commit_xtn"

Index: subversion/bindings/swig/svn_string.i
===================================================================
--- subversion/bindings/swig/svn_string.i (revision 4694)
+++ subversion/bindings/swig/svn_string.i (working copy)
@@ -115,19 +115,23 @@
 */
 
 /* ### note that SWIG drops the const in the arg decl, so we must cast */
-%typemap(python) const char **OUTPUT (const char *temp) {
+%typemap(python,in,numinputs=0) const char **OUTPUT (const char *temp = (const char *)0) {
     $1 = (char **)&temp;
 }
 %typemap(python,argout,fragment="t_output_helper") const char **OUTPUT {
     PyObject *s;
     if (*$1 == NULL) {
- Py_INCREF(Py_None);
- s = Py_None;
+ /* We MUST return a string, even if it is empty.
+ * Returning Py_None will cause errors...
+ */
+ s = PyString_FromString("");
     }
     else {
         s = PyString_FromString(*$1);
- if (s == NULL)
- return NULL;
+ }
+ if (s == NULL) {
+ PyErr_SetString(PyExc_TypeError, "Could not create string");
+ return NULL;
     }
     $result = t_output_helper($result, s);
 }
Index: subversion/bindings/swig/svn_fs.i
===================================================================
--- subversion/bindings/swig/svn_fs.i (revision 4694)
+++ subversion/bindings/swig/svn_fs.i (working copy)
@@ -40,9 +40,9 @@
     svn_fs_txn_t **,
     void **,
     svn_fs_id_t **,
- const char **,
     svn_stream_t **
 };
+%apply const char **OUTPUT { const char ** };
 
 /* ### need to deal with IN params which have "const" and OUT params which
    ### return non-const type. SWIG's type checking may see these as
Index: tools/cvs2svn/cvs2svn.py
===================================================================
--- tools/cvs2svn/cvs2svn.py (revision 4694)
+++ tools/cvs2svn/cvs2svn.py (working copy)
@@ -439,8 +439,8 @@
     # set the time to the proper (past) time
     fs.change_rev_prop(t_fs, new_rev, 'svn:date', date, c_pool)
 
- ### how come conflicts is a newline?
- if conflicts != '\n':
+ # If there was a conflict, print it.
+ if conflicts != '':
       print ' CONFLICTS:', `conflicts`
     print ' new revision:', new_rev
 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Feb 1 05:50:14 2003

This is an archived mail posted to the Subversion Dev mailing list.