On Sat, 31 Aug 2002, Greg Stein wrote:
> On Sat, Aug 31, 2002 at 07:39:44PM -0400, Daniel Berlin wrote:
> > On Sat, 31 Aug 2002, Greg Stein wrote:
> >...
> > > Using obj9 directly was the idea that I had in mind, actually :-) That's
> > > why I said it was fragile. If SWIG changed how it generated code, then it
> > > would break (and I've already seen changes in the generated output, in the
> > > past, which would have broken this kind of construct).
> >
> > Um, IIRC, when i tried this, it placed the initialization of obj9 (it was
> > obj6 in the function i was looking at) after the call we needed it for.
> > IE it didn't work.
>
> Hmm. Seems like there would have to be some slot to hook it in... oh well.
> >...
> > > Right. I'm not entirely sure what that change would be, nor did I really
> > > understand what Dan wrote. I imagine something along the lines of enabling
> > > parameters to the typemaps. You could then define one typemap to invoke the
> > > other pameterized-typemap (e.g. pass the name of the pool arg).
> >
> > This isn't as hard as one would think.
>
> Cool. I know a bit about SWIG, but obviously you're the local pro :-)
>
> > It should only require modifying cwrap.c and typemap.c
> >
> > You should just be able to change Swig_typemap_apply to merge the param
> > attribute, then in Swig_cargs (which outputs the argument handling), set
> > the value.
> >
> > It actually already does something like this for reference parameters,
> > setting a default value.
> >
> > The parameters you pass to a typemap are just set as attributes, so you
> > don't need to do anything special to pass a new parameter to a typemap.
> >
> > I'll work up a patch in a moment.
>
> Cool! I bet if it's clean, we can wrangle Beazley to add it. Or at least use
> it as a demonstration of our particular problem, and have him ponder on a
> "SWIGgish solution" if he doesn't like yours.
I did it an easier way that isn't subversion specific.
All our pool arguments are always last (or at least, we can force them to
be, no?).
So I added a new SWIG replacement variable, "$last" (like we have $input,
$1,$2,$3,etc), that will properly expand to the name of the converted last
argument (IE arg9 in the case we were talking about).
In order to ensure conversion order correctness, I have it defer
arguments whose conversion contains "$last" till after we've converted
the last argument.
Using $last as the pool argument for apr_array_stuff ends up with
conversion code like this (this is svn_client_log):
if(!PyArg_ParseTuple(args,(char *)"OOOiiOOOO:svn_client_log",&obj0,,&obj2,&obj3,&arg5,&arg6,&obj6,&obj7,&obj8,&obj1)) goto fail;
if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_svn_client_auth_baton_t,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
if ((SWIG_ConvertPtr(obj2,(void **) &arg3, SWIGTYPE_p_svn_client_revision_t,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
if ((SWIG_ConvertPtr(obj3,(void **) &arg4, SWIGTYPE_p_svn_client_revision_t,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
if ((SWIG_ConvertPtr(obj6,(void **) &arg7, SWIGTYPE_svn_log_message_receiver_t,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
if ((SWIG_ConvertPtr(obj7,(void **) &arg8, 0, SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
if ((SWIG_ConvertPtr(obj8,(void **) &arg9, SWIGTYPE_p_apr_pool_t,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
{
arg2 = svn_swig_py_strings_to_array(obj1, arg9);
if (arg2 == NULL)
return NULL;
}
result = (svn_error_t *)svn_client_log(arg1,(apr_array_header_t const *)arg2,(svn_client_revision_t const *)arg3,(svn_client_revision_t const *)arg4,arg5,arg6,arg7,arg8,arg9);
Which is what we want (arg9 is the apr_pool_t)
This patch to do this to swig requires only changes to the language
specific modules, rather than any core swig stuff.
That should make it much easier to get into swig.
I think, anyway.
Let me send it in, and if they are cool to the idea of $last, i'll add
code to the other Language modules.
It's about 20 lines per, max.
>
> So then the question would become how to tackle the problem? Apply my patch
> for now, then rip it back out when we get a new SWIG?
Without proper arg deferring, you can't use arg9.
If you use arg9 rather than $last, you'll get (i changed it to arg9 in
the typemap and reran swig, so this is not a guess, but the actual code):
if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_svn_client_auth_baton_t,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
{
arg2 = svn_swig_py_strings_to_array(obj1, arg9);
if (arg2 == NULL)
return NULL;
}
if ((SWIG_ConvertPtr(obj2,(void **) &arg3, SWIGTYPE_p_svn_client_revision_t,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
if ((SWIG_ConvertPtr(obj3,(void **) &arg4, SWIGTYPE_p_svn_client_revision_t,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
if ((SWIG_ConvertPtr(obj6,(void **) &arg7, SWIGTYPE_svn_log_message_receiver_t,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
if ((SWIG_ConvertPtr(obj7,(void **) &arg8, 0, SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
if ((SWIG_ConvertPtr(obj8,(void **) &arg9, SWIGTYPE_p_apr_pool_t,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
Which is wrong, since arg9 is used before it's inited.
I'm not sure if any of the other solutions presented will work around this
yet, my brain is kinda off right now. :)
> >
Cheers, > -g > >
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sun Sep 1 06:24:56 2002