You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Eric Gillespie <ep...@pretzelnet.org> on 2007/05/04 18:58:21 UTC

[PATCH] Wrap wcprop callbacks for svn_ra_callbacks_t

[[[
* subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
  (ra_callbacks_open_tmp_file): Allow Python open_tmp_file callback to be
    None, as the C callback can be NULL.
  (ra_callbacks_get_wc_prop, ra_callbacks_invalidate_wc_props,
   ra_callbacks_set_wc_prop, ra_callbacks_push_wc_prop): New callback
    wrappers, also allowing the Python callback to be None.
  (ra_callbacks_push_or_set_wc_prop): New helper, the common implementation
    of ra_callbacks_set_wc_prop and ra_callbacks_push_wc_prop.
  (svn_swig_py_setup_ra_callbacks): Install wc_prop callbacks.
]]]

Index: subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
===================================================================
--- subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c	(revision 24935)
+++ subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c	(working copy)
@@ -2601,23 +2601,31 @@ ra_callbacks_open_tmp_file(apr_file_t **
                            apr_pool_t *pool)
 {
   PyObject *callbacks = (PyObject *)callback_baton;
-  PyObject *result;
+  PyObject *py_callback, *result;
   svn_error_t *err = SVN_NO_ERROR;
 
+  *fp = NULL;
+
   svn_swig_py_acquire_py_lock();
 
-  if ((result = PyObject_CallMethod(callbacks, 
-                                    "open_tmp_file",
-                                    (char *)"O&", 
-                                    make_ob_pool, pool)) == NULL)
+  py_callback = PyObject_GetAttrString(callbacks, (char *)"open_tmp_file");
+  if (py_callback == NULL)
     {
       err = callback_exception_error();
+      goto finished;
     }
-  else if (result == Py_None)
+  else if (py_callback == Py_None)
+    {
+      goto finished;
+    }
+
+  if ((result = PyObject_CallFunction(py_callback,
+                                      (char *)"O&",
+                                      make_ob_pool, pool)) == NULL)
     {
-      *fp = NULL;
+      err = callback_exception_error();
     }
-  else 
+  else if (result != Py_None)
     {
       *fp = svn_swig_py_make_file(result, pool);
       if (*fp == NULL)
@@ -2627,6 +2635,171 @@ ra_callbacks_open_tmp_file(apr_file_t **
     }
 
   Py_XDECREF(result);
+finished:
+  Py_XDECREF(py_callback);
+  svn_swig_py_release_py_lock();
+  return err;
+}
+
+/* svn_ra_callbacks_t */
+static svn_error_t *
+ra_callbacks_get_wc_prop(void *baton,
+                         const char *path,
+                         const char *name,
+                         const svn_string_t **value,
+                         apr_pool_t *pool)
+{
+  PyObject *callbacks = (PyObject *)baton;
+  PyObject *py_callback, *result;
+  svn_error_t *err = SVN_NO_ERROR;
+
+  *value = NULL;
+
+  svn_swig_py_acquire_py_lock();
+
+  py_callback = PyObject_GetAttrString(callbacks, (char *)"get_wc_prop");
+  if (py_callback == NULL)
+    {
+      err = callback_exception_error();
+      goto finished;
+    }
+  else if (py_callback == Py_None)
+    {
+      goto finished;
+    }
+
+  if ((result = PyObject_CallFunction(py_callback,
+                                      (char *)"ssO&", path, name,
+                                      make_ob_pool, pool)) == NULL)
+    {
+      err = callback_exception_error();
+    }
+  else if (result != Py_None)
+    {
+      char *buf;
+      int len;
+      if (PyString_AsStringAndSize(result, &buf, &len) == -1)
+        {
+      	  err = callback_exception_error();
+        }
+      else
+        {
+          *value = svn_string_ncreate(buf, len, pool);
+        }
+    }
+
+  Py_XDECREF(result);
+finished:
+  Py_XDECREF(py_callback);
+  svn_swig_py_release_py_lock();
+  return err;
+}
+
+/* svn_ra_callbacks_t */
+static svn_error_t *
+ra_callbacks_push_or_set_wc_prop(const char *callback,
+                                 void *baton,
+                                 const char *path,
+                                 const char *name,
+                                 const svn_string_t *value,
+                                 apr_pool_t *pool)
+{
+  PyObject *callbacks = (PyObject *)baton;
+  PyObject *py_callback, *py_value, *result;
+  svn_error_t *err = SVN_NO_ERROR;
+
+  svn_swig_py_acquire_py_lock();
+
+  py_callback = PyObject_GetAttrString(callbacks, (char *)callback);
+  if (py_callback == NULL)
+    {
+      err = callback_exception_error();
+      goto finished;
+    }
+  else if (py_callback == Py_None)
+    {
+      goto finished;
+    }
+
+  if ((py_value = PyString_FromStringAndSize(value->data, value->len)) == NULL)
+    {
+      err = callback_exception_error();
+      goto finished;
+    }
+
+  if ((result = PyObject_CallFunction(py_callback,
+                                      (char *)"ssOO&", path, name, py_value,
+                                      make_ob_pool, pool)) == NULL)
+    {
+      err = callback_exception_error();
+    }
+
+  Py_XDECREF(result);
+finished:
+  Py_XDECREF(py_callback);
+  svn_swig_py_release_py_lock();
+  return err;
+}
+
+/* svn_ra_callbacks_t */
+static svn_error_t *
+ra_callbacks_set_wc_prop(void *baton,
+                         const char *path,
+                         const char *name,
+                         const svn_string_t *value,
+                         apr_pool_t *pool)
+{
+  return ra_callbacks_push_or_set_wc_prop("set_wc_prop", baton, path,
+                                          name, value, pool);
+}
+
+/* svn_ra_callbacks_t */
+static svn_error_t *
+ra_callbacks_push_wc_prop(void *baton,
+                          const char *path,
+                          const char *name,
+                          const svn_string_t *value,
+                          apr_pool_t *pool)
+{
+  return ra_callbacks_push_or_set_wc_prop("push_wc_prop", baton, path,
+                                          name, value, pool);
+}
+
+/* svn_ra_callbacks_t */
+static svn_error_t *
+ra_callbacks_invalidate_wc_props(void *baton,
+                                 const char *path,
+                                 const char *name,
+                                 apr_pool_t *pool)
+{
+  PyObject *callbacks = (PyObject *)baton;
+  PyObject *py_callback, *result;
+  svn_error_t *err = SVN_NO_ERROR;
+
+  svn_swig_py_acquire_py_lock();
+
+  py_callback = PyObject_GetAttrString(callbacks,
+                                       (char *)"invalidate_wc_prop");
+  if (py_callback == NULL)
+    {
+      err = callback_exception_error();
+      goto finished;
+    }
+  else if (py_callback == Py_None)
+    {
+      goto finished;
+    }
+
+  if ((result = PyObject_CallFunction(py_callback,
+                                      (char *)"ssO&", path, name,
+                                      make_ob_pool, pool)) == NULL)
+    {
+      err = callback_exception_error();
+    }
+
+  Py_XDECREF(result);
+finished:
+  Py_XDECREF(py_callback);
   svn_swig_py_release_py_lock();
   return err;
 }
@@ -2648,7 +2821,7 @@ svn_swig_py_setup_ra_callbacks(svn_ra_ca
 
   (*callbacks)->open_tmp_file = ra_callbacks_open_tmp_file;
 
-  py_auth_baton = PyObject_GetAttrString(py_callbacks, "auth_baton");
+  py_auth_baton = PyObject_GetAttrString(py_callbacks, (char *)"auth_baton");
 
   if (svn_swig_ConvertPtrString(py_auth_baton, 
                                 (void **)&((*callbacks)->auth_baton),
@@ -2662,6 +2835,11 @@ svn_swig_py_setup_ra_callbacks(svn_ra_ca
   
   Py_XDECREF(py_auth_baton);
 
+  (*callbacks)->get_wc_prop = ra_callbacks_get_wc_prop;
+  (*callbacks)->set_wc_prop = ra_callbacks_set_wc_prop;
+  (*callbacks)->push_wc_prop = ra_callbacks_push_wc_prop;
+  (*callbacks)->invalidate_wc_props = ra_callbacks_invalidate_wc_props;
+
   *baton = py_callbacks;
 }
 

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

Re: [PATCH] Wrap wcprop callbacks for svn_ra_callbacks_t

Posted by Eric Gillespie <ep...@pretzelnet.org>.
"David James" <ja...@cs.toronto.edu> writes:

> If you're going to work on new tests for the Python DAV layer, I'd
> encourage you to write those tests for the ctypes python bindings,
> because I think that we are going to encourage folks to migrate to the
> ctypes bindings soon :)

Oh, don't worry, switching to ctypes is higher on my list than
working on a davautocheck for the Python binding...

-- 
Eric Gillespie <*> epg@pretzelnet.org

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

Re: [PATCH] Wrap wcprop callbacks for svn_ra_callbacks_t

Posted by David James <ja...@cs.toronto.edu>.
On 5/4/07, Eric Gillespie <ep...@pretzelnet.org> wrote:
> "David James" <ja...@cs.toronto.edu> writes:
>
> > Nice work, Eric! I haven't tested your patch, but the code looks good.
>
> Thanks.  I meant to note this, but forgot: This is not really
> testable yet, as the callbacks are only used by ra-dav (and i
> guess ra-serf, too).  I have tested this extensively with a test
> suite for another application, over http.  If i can find the
> time, i'll work on a davautocheck-swig-py target.

If it's tested and ready to go, feel free to commit. Automated tests
are nice but not a requirement if a committer can vouch for the code.

If you're going to work on new tests for the Python DAV layer, I'd
encourage you to write those tests for the ctypes python bindings,
because I think that we are going to encourage folks to migrate to the
ctypes bindings soon :)

Cheers,

David

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

Re: [PATCH] Wrap wcprop callbacks for svn_ra_callbacks_t

Posted by Eric Gillespie <ep...@pretzelnet.org>.
"David James" <ja...@cs.toronto.edu> writes:

> Nice work, Eric! I haven't tested your patch, but the code looks good.

Thanks.  I meant to note this, but forgot: This is not really
testable yet, as the callbacks are only used by ra-dav (and i
guess ra-serf, too).  I have tested this extensively with a test
suite for another application, over http.  If i can find the
time, i'll work on a davautocheck-swig-py target.

-- 
Eric Gillespie <*> epg@pretzelnet.org

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

Re: [PATCH] Wrap wcprop callbacks for svn_ra_callbacks_t

Posted by David James <ja...@cs.toronto.edu>.
Nice work, Eric! I haven't tested your patch, but the code looks good.

Cheers,

David

On 5/4/07, Eric Gillespie <ep...@pretzelnet.org> wrote:
> [[[
> * subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
>   (ra_callbacks_open_tmp_file): Allow Python open_tmp_file callback to be
>     None, as the C callback can be NULL.
>   (ra_callbacks_get_wc_prop, ra_callbacks_invalidate_wc_props,
>    ra_callbacks_set_wc_prop, ra_callbacks_push_wc_prop): New callback
>     wrappers, also allowing the Python callback to be None.
>   (ra_callbacks_push_or_set_wc_prop): New helper, the common implementation
>     of ra_callbacks_set_wc_prop and ra_callbacks_push_wc_prop.
>   (svn_swig_py_setup_ra_callbacks): Install wc_prop callbacks.
> ]]]
>
> Index: subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
> ===================================================================
> --- subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c        (revision 24935)
> +++ subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c        (working copy)
> @@ -2601,23 +2601,31 @@ ra_callbacks_open_tmp_file(apr_file_t **
>                             apr_pool_t *pool)
>  {
>    PyObject *callbacks = (PyObject *)callback_baton;
> -  PyObject *result;
> +  PyObject *py_callback, *result;
>    svn_error_t *err = SVN_NO_ERROR;
>
> +  *fp = NULL;
> +
>    svn_swig_py_acquire_py_lock();
>
> -  if ((result = PyObject_CallMethod(callbacks,
> -                                    "open_tmp_file",
> -                                    (char *)"O&",
> -                                    make_ob_pool, pool)) == NULL)
> +  py_callback = PyObject_GetAttrString(callbacks, (char *)"open_tmp_file");
> +  if (py_callback == NULL)
>      {
>        err = callback_exception_error();
> +      goto finished;
>      }
> -  else if (result == Py_None)
> +  else if (py_callback == Py_None)
> +    {
> +      goto finished;
> +    }
> +
> +  if ((result = PyObject_CallFunction(py_callback,
> +                                      (char *)"O&",
> +                                      make_ob_pool, pool)) == NULL)
>      {
> -      *fp = NULL;
> +      err = callback_exception_error();
>      }
> -  else
> +  else if (result != Py_None)
>      {
>        *fp = svn_swig_py_make_file(result, pool);
>        if (*fp == NULL)
> @@ -2627,6 +2635,171 @@ ra_callbacks_open_tmp_file(apr_file_t **
>      }
>
>    Py_XDECREF(result);
> +finished:
> +  Py_XDECREF(py_callback);
> +  svn_swig_py_release_py_lock();
> +  return err;
> +}
> +
> +/* svn_ra_callbacks_t */
> +static svn_error_t *
> +ra_callbacks_get_wc_prop(void *baton,
> +                         const char *path,
> +                         const char *name,
> +                         const svn_string_t **value,
> +                         apr_pool_t *pool)
> +{
> +  PyObject *callbacks = (PyObject *)baton;
> +  PyObject *py_callback, *result;
> +  svn_error_t *err = SVN_NO_ERROR;
> +
> +  *value = NULL;
> +
> +  svn_swig_py_acquire_py_lock();
> +
> +  py_callback = PyObject_GetAttrString(callbacks, (char *)"get_wc_prop");
> +  if (py_callback == NULL)
> +    {
> +      err = callback_exception_error();
> +      goto finished;
> +    }
> +  else if (py_callback == Py_None)
> +    {
> +      goto finished;
> +    }
> +
> +  if ((result = PyObject_CallFunction(py_callback,
> +                                      (char *)"ssO&", path, name,
> +                                      make_ob_pool, pool)) == NULL)
> +    {
> +      err = callback_exception_error();
> +    }
> +  else if (result != Py_None)
> +    {
> +      char *buf;
> +      int len;
> +      if (PyString_AsStringAndSize(result, &buf, &len) == -1)
> +        {
> +         err = callback_exception_error();
> +        }
> +      else
> +        {
> +          *value = svn_string_ncreate(buf, len, pool);
> +        }
> +    }
> +
> +  Py_XDECREF(result);
> +finished:
> +  Py_XDECREF(py_callback);
> +  svn_swig_py_release_py_lock();
> +  return err;
> +}
> +
> +/* svn_ra_callbacks_t */
> +static svn_error_t *
> +ra_callbacks_push_or_set_wc_prop(const char *callback,
> +                                 void *baton,
> +                                 const char *path,
> +                                 const char *name,
> +                                 const svn_string_t *value,
> +                                 apr_pool_t *pool)
> +{
> +  PyObject *callbacks = (PyObject *)baton;
> +  PyObject *py_callback, *py_value, *result;
> +  svn_error_t *err = SVN_NO_ERROR;
> +
> +  svn_swig_py_acquire_py_lock();
> +
> +  py_callback = PyObject_GetAttrString(callbacks, (char *)callback);
> +  if (py_callback == NULL)
> +    {
> +      err = callback_exception_error();
> +      goto finished;
> +    }
> +  else if (py_callback == Py_None)
> +    {
> +      goto finished;
> +    }
> +
> +  if ((py_value = PyString_FromStringAndSize(value->data, value->len)) == NULL)
> +    {
> +      err = callback_exception_error();
> +      goto finished;
> +    }
> +
> +  if ((result = PyObject_CallFunction(py_callback,
> +                                      (char *)"ssOO&", path, name, py_value,
> +                                      make_ob_pool, pool)) == NULL)
> +    {
> +      err = callback_exception_error();
> +    }
> +
> +  Py_XDECREF(result);
> +finished:
> +  Py_XDECREF(py_callback);
> +  svn_swig_py_release_py_lock();
> +  return err;
> +}
> +
> +/* svn_ra_callbacks_t */
> +static svn_error_t *
> +ra_callbacks_set_wc_prop(void *baton,
> +                         const char *path,
> +                         const char *name,
> +                         const svn_string_t *value,
> +                         apr_pool_t *pool)
> +{
> +  return ra_callbacks_push_or_set_wc_prop("set_wc_prop", baton, path,
> +                                          name, value, pool);
> +}
> +
> +/* svn_ra_callbacks_t */
> +static svn_error_t *
> +ra_callbacks_push_wc_prop(void *baton,
> +                          const char *path,
> +                          const char *name,
> +                          const svn_string_t *value,
> +                          apr_pool_t *pool)
> +{
> +  return ra_callbacks_push_or_set_wc_prop("push_wc_prop", baton, path,
> +                                          name, value, pool);
> +}
> +
> +/* svn_ra_callbacks_t */
> +static svn_error_t *
> +ra_callbacks_invalidate_wc_props(void *baton,
> +                                 const char *path,
> +                                 const char *name,
> +                                 apr_pool_t *pool)
> +{
> +  PyObject *callbacks = (PyObject *)baton;
> +  PyObject *py_callback, *result;
> +  svn_error_t *err = SVN_NO_ERROR;
> +
> +  svn_swig_py_acquire_py_lock();
> +
> +  py_callback = PyObject_GetAttrString(callbacks,
> +                                       (char *)"invalidate_wc_prop");
> +  if (py_callback == NULL)
> +    {
> +      err = callback_exception_error();
> +      goto finished;
> +    }
> +  else if (py_callback == Py_None)
> +    {
> +      goto finished;
> +    }
> +
> +  if ((result = PyObject_CallFunction(py_callback,
> +                                      (char *)"ssO&", path, name,
> +                                      make_ob_pool, pool)) == NULL)
> +    {
> +      err = callback_exception_error();
> +    }
> +
> +  Py_XDECREF(result);
> +finished:
> +  Py_XDECREF(py_callback);
>    svn_swig_py_release_py_lock();
>    return err;
>  }
> @@ -2648,7 +2821,7 @@ svn_swig_py_setup_ra_callbacks(svn_ra_ca
>
>    (*callbacks)->open_tmp_file = ra_callbacks_open_tmp_file;
>
> -  py_auth_baton = PyObject_GetAttrString(py_callbacks, "auth_baton");
> +  py_auth_baton = PyObject_GetAttrString(py_callbacks, (char *)"auth_baton");
>
>    if (svn_swig_ConvertPtrString(py_auth_baton,
>                                  (void **)&((*callbacks)->auth_baton),
> @@ -2662,6 +2835,11 @@ svn_swig_py_setup_ra_callbacks(svn_ra_ca
>
>    Py_XDECREF(py_auth_baton);
>
> +  (*callbacks)->get_wc_prop = ra_callbacks_get_wc_prop;
> +  (*callbacks)->set_wc_prop = ra_callbacks_set_wc_prop;
> +  (*callbacks)->push_wc_prop = ra_callbacks_push_wc_prop;
> +  (*callbacks)->invalidate_wc_props = ra_callbacks_invalidate_wc_props;
> +
>    *baton = py_callbacks;
>  }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: dev-help@subversion.tigris.org
>
>

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