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

Re: [Patch] (swig-py) accept core.svn_stream_t object for svn_stream_t *

From: Jun Omae <jun66j5_at_gmail.com>
Date: Tue, 11 Dec 2018 20:12:25 +0900

Hi,

On 2018/12/10 22:37, Michael Pilato wrote:
> Most of the patch is fine. Besides some minor code formatting tweaks,
> there's only one bit I really changed when committing (as r1848577):

Thanks for the reviewing and tweaking.

Reconsidering the checking instance of svn_stream_t in svn_swig_py_make_stream(),
I think the code is redundant. Using svn_swig_py_convert_ptr() would simplify
the converting the given py_io parameter to a svn_stream_t pointer.

Thoughts?

---- START OF PATCH ----
commit f857f1f529cc0e621a074a48e7c689a0b32d18cf
Author: Jun Omae <jun66j5_at_gmail.com>
Date: Tue Dec 11 19:41:25 2018 +0900

     swig-py: Followup to r1848577, simplify the handling svn_stream_t pointer.

     * subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
       (svn_swig_py_make_stream): Use svn_swig_py_convert_ptr() rather than
       checking instance of libsvn.core.svn_stream_t using Python APIs.

diff --git a/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c b/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
index 93d4cb378..2c90a6a46 100644
--- a/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
+++ b/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
@@ -2578,36 +2578,18 @@ svn_swig_py_stream_destroy(void *py_io)
  svn_stream_t *
  svn_swig_py_make_stream(PyObject *py_io, apr_pool_t *pool)
  {
- PyObject *libsvn_core = NULL;
- PyObject *py_stream_t = NULL;
    PyObject *_stream = NULL;
- svn_stream_t *result = NULL;
+ void *result = NULL;
    swig_type_info *typeinfo = svn_swig_TypeQuery("svn_stream_t *");

- libsvn_core = PyImport_ImportModule("libsvn.core");
- if (PyErr_Occurred()) {
- goto finished;
- }
- py_stream_t = PyObject_GetAttrString(libsvn_core, "svn_stream_t");
- if (PyErr_Occurred()) {
- goto finished;
- }
- if (PyObject_IsInstance(py_io, py_stream_t)) {
- result = (svn_stream_t *)svn_swig_py_must_get_ptr(py_io, typeinfo, 0);
- if (PyErr_Occurred()) {
- result = NULL;
- goto finished;
- }
- }
- else if (PyObject_HasAttrString(py_io, "_stream")) {
- _stream = PyObject_GetAttrString(py_io, "_stream");
- if (PyObject_IsInstance(_stream, py_stream_t)) {
- result = (svn_stream_t *)svn_swig_py_must_get_ptr(_stream, typeinfo, 0);
- if (PyErr_Occurred()) {
- result = NULL;
- goto finished;
+ if (svn_swig_py_convert_ptr(py_io, &result, typeinfo) != 0) {
+ PyErr_Clear();
+ if (PyObject_HasAttrString(py_io, "_stream")) {
+ _stream = PyObject_GetAttrString(py_io, "_stream");
+ if (svn_swig_py_convert_ptr(_stream, &result, typeinfo) != 0) {
+ PyErr_Clear();
+ }
        }
- }
    }
    if (result == NULL) {
      if (!PyObject_HasAttrString(py_io, "read")
@@ -2627,8 +2609,6 @@ svn_swig_py_make_stream(PyObject *py_io, apr_pool_t *pool)

  finished:
    Py_XDECREF(_stream);
- Py_XDECREF(py_stream_t);
- Py_XDECREF(libsvn_core);

    return result;
  }
---- END OF PATCH ----

-- 
Jun Omae <jun66j5_at_gmail.com> (大前 潤)
Received on 2018-12-11 12:12:49 CET

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

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.