You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Brandon Ehle <az...@yahoo.com> on 2003/07/21 16:32:20 UTC

[PATCH] Add some missing functionality to SWIG Python wrappers

It's been awhile since I've sent a patch so hopefully I remembered 
everything you need to do...

* Add a typemap for the svn_client_prompt_t structure that allows you to 
specify a python function as the callback

* Supply a return type mapping for the type svn_stream_t ** so that 
"stream = core.svn_stream_for_stdout(pool)" works.

* Fix a comment svn_client.i

|Index: bindings/swig/core.i
===================================================================
--- bindings/swig/core.i    (revision 6521)
+++ bindings/swig/core.i    (working copy)
@@ -90,6 +90,10 @@
   svn_auth_baton_t **
 }
 
+%apply SWIGTYPE **OUTPARAM {
+  svn_stream_t **
+}
+
 /* -----------------------------------------------------------------------
    apr_size_t * is always an IN/OUT parameter in svn_io.h
 */
Index: bindings/swig/svn_client.i
===================================================================
--- bindings/swig/svn_client.i    (revision 6521)
+++ bindings/swig/svn_client.i    (working copy)
@@ -152,6 +152,12 @@
    handle svn_client_prompt_t/baton pairs
 */
 
+%typemap(python,in) (svn_client_prompt_t prompt_func,
+                     void *prompt_baton) {
+  $1 = svn_swig_py_client_prompt_func;
+  $2 = $input;
+}
+
 %typemap(java,memberin) (svn_client_prompt_t prompt_func,
                    void *prompt_baton) {
   //$1 = svn_swig_java_client_prompt_func;
@@ -170,7 +176,7 @@
 %typemap(java, javain) svn_client_prompt_t "$javainput"
 
 /* -----------------------------------------------------------------------
-   handle svn_client_get_commit_log_t/baton pairs
+   handle svn_log_message_receiver_t/baton pairs
 */
 
 %typemap(java,in) (svn_log_message_receiver_t receiver,
Index: bindings/swig/swigutil_py.c
===================================================================
--- bindings/swig/swigutil_py.c    (revision 6521)
+++ bindings/swig/swigutil_py.c    (working copy)
@@ -1026,7 +1026,47 @@
   return err;
 }
 
+svn_error_t *
+svn_swig_py_client_prompt_func(const char **info,
+                               const char *prompt,
+                               svn_boolean_t hide,
+                               void *baton,
+                               apr_pool_t *pool)
+{
+  PyObject *function = baton;
+  PyObject *result;
+  svn_error_t *err;
 
+  acquire_py_lock();
+
+  if ((result = PyObject_CallFunction(function, (char *)"UiO&", prompt, 
hide, make_ob_pool, pool)) == NULL)
+    {
+          err = convert_python_error();
+    }
+  else if (result == Py_None)
+    {
+      Py_DECREF(result);
+      *info = NULL;
+      err = SVN_NO_ERROR;
+    }
+  else if (PyString_Check(result))
+    {
+      *info = apr_pstrdup(pool, PyString_AS_STRING(result));
+      Py_DECREF(result);
+      err = SVN_NO_ERROR;
+    }
+  else
+    {
+      Py_DECREF(result);
+      PyErr_SetString(PyExc_TypeError, "not a string");
+      err = convert_python_error();
+    }
+  
+  release_py_lock();
+  return err;
+}
+
+
 
 /*** Other Wrappers for SVN Functions ***/
 
Index: bindings/swig/swigutil_py.h
===================================================================
--- bindings/swig/swigutil_py.h    (revision 6521)
+++ bindings/swig/swigutil_py.h    (working copy)
@@ -119,6 +119,14 @@
                                               void *baton,
                                               apr_pool_t *pool);
 
+/* thunked client prompter */
+svn_error_t *
+svn_swig_py_client_prompt_func(const char **info,
+                               const char *prompt,
+                               svn_boolean_t hide,
+                               void *baton,
+                               apr_pool_t *pool);
+
 /* thunked log receiver function.  */
 svn_error_t * svn_swig_py_thunk_log_receiver(void *py_receiver,
                                              apr_hash_t *changed_paths,|


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