You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by cm...@collab.net on 2002/09/16 20:27:33 UTC

Subversion SWIG patch.

Daniel, for reference, please check out your patch at:
http://subversion.tigris.org/servlets/ReadMsg?list=dev&msgNo=21138

Specifically, this section (which appears to be the real guts of the things):

   %typemap(arginit) apr_pool_t *pool(apr_pool_t *_global_pool) {
   SWIG_ConvertPtr(PyObject_GetItem(args, PyInt_FromLong($argnum)), (void 
   **)&$1, SWIGTYPE_p_apr_pool_t, SWIG_POINTER_EXCEPTION | 0);
   _global_pool = $1;
   }
   %typemap (in) apr_pool_t *pool "";

Now, I had all kinds of trouble trying to get that to compile.  So I
made some mods (which appear to be in accordance with SWIG docs):

   %typemap(arginit) apr_pool_t *pool(apr_pool_t *_global_pool) {
       if (SWIG_ConvertPtr(PyObject_GetItem(args, PyInt_FromLong($argnum)),
                           (void **)&$1, $1_descriptor, 0) == -1) {
           return NULL;
       }
       _global_pool = $1;
   }
   %typemap(in) apr_pool_t *pool "";

However, whenever I try to actually use the bindings, things SEGFAULT
left and right.  I managed to GDB one of those segfaults (by
temporarily inserting a sleep() into the code above and attaching to
the process), and it looks as though the pool at that context is just
garbage (0xc in my case).  Questions for you:

  - Did you actually test your patch?

  - What is the SWIG_POINTER_EXCEPTION flag?  I can't find any doc or
    code references to it in SWIG 1.3.12.

  - You are using the $argnum magic variable to get the argument which
    is the apr_pool_t, yes?  How does that hold up in the presence of
    other typemap directives that mod the argument list?  For example,
    svn_repos_open() as a C function takes 3 args, but as a python
    binding takes only two (since the svn_repos_t ** is converted to a
    return value).  Will $argnum still do what you expect in those
    cases?

Love, an exhausted C-Mike.

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

Re: Subversion SWIG patch.

Posted by Greg Stein <gs...@lyra.org>.
On Tue, Sep 17, 2002 at 10:22:00AM +0200, Michael Wood wrote:
> On Mon, Sep 16, 2002 at 03:27:33PM -0500, cmpilato@collab.net wrote:
> [snip]
> >    %typemap(arginit) apr_pool_t *pool(apr_pool_t *_global_pool) {
> >        if (SWIG_ConvertPtr(PyObject_GetItem(args, PyInt_FromLong($argnum)),
> >                            (void **)&$1, $1_descriptor, 0) == -1) {
> >            return NULL;
> >        }
> >        _global_pool = $1;
> >    }
> >    %typemap(in) apr_pool_t *pool "";
> [snip]
> 
> I've only played around with SWIG and Python C bindings a little, but
> shouldn't that "return NULL;" be something like this instead:
> 
>   Py_INCREF(Py_None); return PyNone;

Nope. If the ConvertPtr fails, then it raises a Python exception. The
presence of an exception is signalled to the caller by returning NULL.

(and Python int-valued functions will return -1 to signal this; if -1 is a
 legal return value, then you test for -1 and then test for an exception)

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

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

Re: Subversion SWIG patch.

Posted by Michael Wood <mw...@its.uct.ac.za>.
On Mon, Sep 16, 2002 at 03:27:33PM -0500, cmpilato@collab.net wrote:
[snip]
>    %typemap(arginit) apr_pool_t *pool(apr_pool_t *_global_pool) {
>        if (SWIG_ConvertPtr(PyObject_GetItem(args, PyInt_FromLong($argnum)),
>                            (void **)&$1, $1_descriptor, 0) == -1) {
>            return NULL;
>        }
>        _global_pool = $1;
>    }
>    %typemap(in) apr_pool_t *pool "";
[snip]

I've only played around with SWIG and Python C bindings a little, but
shouldn't that "return NULL;" be something like this instead:

  Py_INCREF(Py_None); return PyNone;

-- 
Michael Wood <mw...@its.uct.ac.za>

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

Re: Subversion SWIG patch.

Posted by Daniel Berlin <db...@dberlin.org>.
On Monday, September 16, 2002, at 04:27  PM, cmpilato@collab.net wrote:

> Daniel, for reference, please check out your patch at:
> http://subversion.tigris.org/servlets/ReadMsg?list=dev&msgNo=21138
>
> Specifically, this section (which appears to be the real guts of the 
> things):
>
>    %typemap(arginit) apr_pool_t *pool(apr_pool_t *_global_pool) {
>    SWIG_ConvertPtr(PyObject_GetItem(args, PyInt_FromLong($argnum)), 
> (void
>    **)&$1, SWIGTYPE_p_apr_pool_t, SWIG_POINTER_EXCEPTION | 0);
>    _global_pool = $1;
>    }
>    %typemap (in) apr_pool_t *pool "";
>
> Now, I had all kinds of trouble trying to get that to compile.  So I
> made some mods (which appear to be in accordance with SWIG docs):
>
>    %typemap(arginit) apr_pool_t *pool(apr_pool_t *_global_pool) {
>        if (SWIG_ConvertPtr(PyObject_GetItem(args, 
> PyInt_FromLong($argnum)),
>                            (void **)&$1, $1_descriptor, 0) == -1) {
>            return NULL;
>        }
>        _global_pool = $1;
>    }
>    %typemap(in) apr_pool_t *pool "";
>
This should work fine too.



> However, whenever I try to actually use the bindings, things SEGFAULT
> left and right.  I managed to GDB one of those segfaults (by
> temporarily inserting a sleep() into the code above and attaching to
> the process), and it looks as though the pool at that context is just
> garbage (0xc in my case).  Questions for you:
>
>   - Did you actually test your patch?
>
Yes

>   - What is the SWIG_POINTER_EXCEPTION flag?  I can't find any doc or
>     code references to it in SWIG 1.3.12.

It throws a python exception if the pointer conversion fails.
it's part of the swig python runtime.

>
>   - You are using the $argnum magic variable to get the argument which
>     is the apr_pool_t, yes?
No

>  How does that hold up in the presence of
>     other typemap directives that mod the argument list?  For example,
>     svn_repos_open() as a C function takes 3 args, but as a python
>     binding takes only two (since the svn_repos_t ** is converted to a
>     return value).  Will $argnum still do what you expect in those
>     cases?

It better.
This is what beazley suggested to me to do, and since he wrote SWIG, ...
:)


I should note i've only tried it with current SWIG CVS (1.3.15pre) , 
*not* with 1.3.12.
_global was brand new in 1.3.12.


>
> Love, an exhausted C-Mike.


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