[prev in list] [next in list] [prev in thread] [next in thread] 

List:       subversion-cvs
Subject:    svn commit: r15525 - in branches/python-bindings-improvements/subversion/bindings/swig: include
From:       djames () tigris ! org
Date:       2005-07-31 22:51:19
Message-ID: 200507312251.j6VMpJm31948 () morbius ! ch ! collab ! net
[Download RAW message or body]

Author: djames
Date: Sun Jul 31 17:51:18 2005
New Revision: 15525

Modified:
   branches/python-bindings-improvements/subversion/bindings/swig/core.i
   branches/python-bindings-improvements/subversion/bindings/swig/include/svn_global.swg
  branches/python-bindings-improvements/subversion/bindings/swig/include/svn_types.swg


Log:
Instead of reporting the SWIG/C argument number in error messages,
report argument numbers that correspond to the Python inputs. Our
reported argument numbers are now consistent with those reported
by the Python interpreter.

* swig/include/svn_global.swg:
  ($svn_argnum): New macro. Expands to the current Python argument number.
  (POOLINIT): New typemap for parameters which require a global pool
  and a global py_pool. Applied this typemap to SWIGTYPE, void *,
  SWIGTYPE *, and SWIGTYPE [].
  (SWIGTYPE *, SWIGTYPE []): Switch from $argnum to $svn_argnum. Apply
  typemap to void *.
  (char *, char const *, char * const, char const * const, char,
   unsigned char, short, unsigned short, int, enum SWIGTYPE, svn_boolean_t,
   apr_seek_where_t, apr_fileperms_t, unsigned int, long, ssize_t, unsigned
   long, size_t, __int64, long long, unsigned __int64, unsigned long long):
  Use Python format specifiers instead of standard SWIG typemaps to parse these
  basic types, because Python reports better error messages with correct
  argument numbers.
* swig/core.i:
  (apr_header_t *providers): Switch from $argnum to $svn_argnum.
* swig/include/svn_types.swg:
  (apr_pool_t *): Switch from $argnum to $svn_argnum.



Modified: branches/python-bindings-improvements/subversion/bindings/swig/core.i
Url: http://svn.collab.net/viewcvs/svn/branches/python-bindings-improvements/subversio \
n/bindings/swig/core.i?rev=15525&p1=branches/python-bindings-improvements/subversion/b \
indings/swig/core.i&p2=branches/python-bindings-improvements/subversion/bindings/swig/core.i&r1=15524&r2=15525
 ==============================================================================
--- branches/python-bindings-improvements/subversion/bindings/swig/core.i	(original)
+++ branches/python-bindings-improvements/subversion/bindings/swig/core.i	Sun Jul 31 \
17:51:18 2005 @@ -322,7 +322,7 @@
     ($1)->nelts = targlen;
     while (targlen--) {
         provider = svn_swig_MustGetPtr(PySequence_GetItem($input, targlen),
-          $descriptor(svn_auth_provider_object_t *), $argnum, NULL);
+          $descriptor(svn_auth_provider_object_t *), $svn_argnum, NULL);
         if (PyErr_Occurred()) {
           return NULL;
         }

Modified: branches/python-bindings-improvements/subversion/bindings/swig/include/svn_global.swg
                
Url: http://svn.collab.net/viewcvs/svn/branches/python-bindings-improvements/subversio \
n/bindings/swig/include/svn_global.swg?rev=15525&p1=branches/python-bindings-improveme \
nts/subversion/bindings/swig/include/svn_global.swg&p2=branches/python-bindings-improvements/subversion/bindings/swig/include/svn_global.swg&r1=15524&r2=15525
 ==============================================================================
--- branches/python-bindings-improvements/subversion/bindings/swig/include/svn_global.swg	(original)
                
+++ branches/python-bindings-improvements/subversion/bindings/swig/include/svn_global.swg	Sun \
Jul 31 17:51:18 2005 @@ -26,25 +26,83 @@
 static PyObject * _global_svn_swig_py_pool = NULL;
 %}
 
+/* The SWIG $argnum variable reports the current argument number
+   in the underlying C code. This is a bit counterintuitive for
+   Python programmers, because the underlying C function may have
+   very different argument numbers than the wrapper Python function.
+
+   SWIG doesn't provide any good way of getting Python argument 
+   numbers, so we extract the argument number using macros. This 
+   isn't a perfect solution, but it does the job. */
+#define $svn_argnum svn_argnum_$input
+
 /* Pointers, references, and arrays */
-%typemap (arginit) SWIGTYPE * (PyObject *_global_svn_swig_py_pool, \
-      apr_pool_t *_global_pool)
+%typemap (arginit) POOLINIT ( \
+  apr_pool_t *_global_pool, PyObject *_global_svn_swig_py_pool)
 {
   svn_swig_get_application_pool(&_global_pool, &_global_svn_swig_py_pool);
 }
+%apply POOLINIT { void *, SWIGTYPE *, SWIGTYPE [] };
 
-%typemap (in) SWIGTYPE *, SWIGTYPE []
-  "$1 = ($1_ltype)svn_swig_MustGetPtr($input, $descriptor, $argnum,
-     _global_svn_swig_py_is_local_pool ? NULL : &_global_svn_swig_py_pool);
-   if (PyErr_Occurred()) {
-     return NULL;
-   }
-  "
+/* Object passed as pointer */
+%typemap (in) void *, SWIGTYPE *, SWIGTYPE []
+{
+  $1 = ($1_ltype)svn_swig_MustGetPtr($input, $descriptor, $svn_argnum,
+    _global_svn_swig_py_is_local_pool ? NULL : &_global_svn_swig_py_pool);
+  if (PyErr_Occurred()) {
+    return NULL;
+  }
+}
 
 /* Output arguments */
 %typemap (out) SWIGTYPE *, SWIGTYPE &
     "$result = svn_swig_NewPointerObj((void*)($1), $descriptor, 
                                       _global_svn_swig_py_pool);";
+
+/* Python format specifiers. Use Python instead of SWIG to parse 
+   these basic types, because Python reports better error messages 
+   (with correct argument numbers). */
+%typemap (in, parse="s")
+  char *, char const *, char * const, char const * const "";
+%typemap (in, parse="c") char "";
+%typemap (in, parse="B") unsigned char "";
+%typemap (in, parse="h") short "";
+%typemap (in, parse="H") unsigned short "";
+%typemap (in, parse="i") int, enum SWIGTYPE, svn_boolean_t, apr_seek_where_t, \
+  apr_fileperms_t "";
+%typemap (in, parse="I") unsigned int "";
+%typemap (in, parse="l") long, ssize_t "";
+%typemap (in, parse="k") unsigned long, size_t "";
+%typemap (in, parse="L") long long, __int64 "";
+%typemap (in, parse="K") unsigned long long, unsigned __int64 "";
+
+/* We assume here that Subversion functions have no more than
+   20 fixed parameters. If you want to wrap a function that has
+   more fixed parameters, you'll need to add more #define
+   statements. */
+%{
+#define svn_argnum_obj0 1
+#define svn_argnum_obj1 2
+#define svn_argnum_obj2 3
+#define svn_argnum_obj3 4
+#define svn_argnum_obj4 5
+#define svn_argnum_obj5 6
+#define svn_argnum_obj6 7
+#define svn_argnum_obj7 8
+#define svn_argnum_obj8 9
+#define svn_argnum_obj9 10
+#define svn_argnum_obj10 11
+#define svn_argnum_obj11 12
+#define svn_argnum_obj12 13
+#define svn_argnum_obj13 14
+#define svn_argnum_obj14 15
+#define svn_argnum_obj15 16
+#define svn_argnum_obj16 17
+#define svn_argnum_obj17 18
+#define svn_argnum_obj18 19
+#define svn_argnum_obj19 20
+%}
+
 #endif
 
 /* SWIG doesn't handle variadic parameters well */

Modified: branches/python-bindings-improvements/subversion/bindings/swig/include/svn_types.swg
                
Url: http://svn.collab.net/viewcvs/svn/branches/python-bindings-improvements/subversio \
n/bindings/swig/include/svn_types.swg?rev=15525&p1=branches/python-bindings-improvemen \
ts/subversion/bindings/swig/include/svn_types.swg&p2=branches/python-bindings-improvements/subversion/bindings/swig/include/svn_types.swg&r1=15524&r2=15525
 ==============================================================================
--- branches/python-bindings-improvements/subversion/bindings/swig/include/svn_types.swg	(original)
                
+++ branches/python-bindings-improvements/subversion/bindings/swig/include/svn_types.swg	Sun \
Jul 31 17:51:18 2005 @@ -248,7 +248,8 @@
 
 %typemap(python, in) apr_pool_t * {
   if ($input != Py_None) {
-    _global_pool = svn_swig_MustGetPtr($input, $1_descriptor, $argnum, NULL);
+    _global_pool = svn_swig_MustGetPtr($input, $1_descriptor, $svn_argnum, 
+      NULL);
     if (PyErr_Occurred()) {
         return NULL;
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: svn-unsubscribe@subversion.tigris.org
For additional commands, e-mail: svn-help@subversion.tigris.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic