You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Greg Stein <gs...@lyra.org> on 2003/03/01 00:42:26 UTC

multi-valued returns in SWIG (was: Rcsparse.py)

On Fri, Feb 28, 2003 at 06:29:14AM -0800, Marshall White wrote:
> Greg,
> 
> Your patch for svn_string.i was almost exactly what I posted a month ago.  :-)

Unfortunate :-(  But recall from the HACKING document:

  If you don't get a response for a while, and don't see the patch
  applied, it may just mean that people are really busy.  Go ahead and
  repost, and don't hesitate to point out that you're still waiting for
  a response.  One way to think of it is that patch management is highly
  parallizable, and we need you to shoulder your share of the management
  as well as the coding.  Every patch needs someone to shepherd it
  through the process, and the person best qualified to do that is the
  original submitter.

>...
> However, doesn't that just always reduce it down to the OTHER type of problem?
> I see you hacked around one specific case in svn_fs.i, but what about any others?

The others will also need to be fixed. I'm not sure how many functions have
multiple-value returns. I don't think a general solution is possible, but
certainly wouldn't mind finding one :-)

> As of Jan 31, the affected functions that had "const char **" args were:
> svn_repos_get_committed_info
> svn_repos_fs_commit_txn
> svn_fs_commit_txn
> svn_fs_txn_name
> svn_fs_copied_from
> svn_fs_merge
> svn_opt_format_option
> svn_io_open_unique_file
> svn_io_detect_mimetype
> 
> That list might be slightly different now.

I fixed the svn_fs functions. The repos functions would need to be fixed,
and SWIG shouldn't bind svn_opt_* or svn_io_open_unique_file(). Those don't
need bindings on the assumption that the native language has better
equivalents. The svn_io_detect_mimetype should probably be bound so that an
app can potentially use the same logic as SVN itself.

Just checked. The svn_repos functions are now working cuz svn_repos.i
imports svn_fs.i, which includes the typemap for 'const char **'. The
svn_io_detect_mimetype is already working.

> Isn't this really a general case problem anyway?
> As in, SWIG doesn't correctly handle functions that return NULL valued pointers as their first
> return values?

Well, it isn't specifically tied to NULL pointers, but any value where the
bindings treat a value as Py_None. The t_output_helper() function has a hard
time distinguishing between the fallback Py_None as the return value, and a
"real" return value of Py_None.

> Ultimately this sounds like something that should be fixed in SWIG, not hacked around in
> Subversion (even though that may be necessary in the short term.)

If we can figure out the Right Solution, then heck yah. I'd be more than
happy to see SWIG fixed for this. I just don't have that solution right now.
It would certainly require some thinking about how to revamp the computation
of the result.

> So if Subversion is going to hack around it, wouldn't it be better to have a general solution that
> works in every case rather than hack it one arg list at a time?

Of course.

> I would argue that this is
> exactly what Dale (and myself to some extent) seemed to be getting to.

Your solutions turned single-value-return functions into returning singleton
tuples. That wasn't right. If there is a way to avoid that, then great. I'm
totally fine with that.

> This same problem can and and I am sure will affect types other than "const char **".
> 
> I guess I am looking for your feelings on the overall status of this.  Do you consider this a case
> closed, or something that still needs attention?  Should any more attention be given here, or
> should someone start a SWIG crusade?

I got a problem fixed using a solution that is quite fine in my mind.
However, it doesn't address the larger problem at hand. It *would* be good
to do that, but I haven't seen a good solution for that (yet).

So no... not closed.

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: multi-valued returns in SWIG

Posted by Greg Stein <gs...@lyra.org>.
On Sat, Mar 01, 2003 at 12:43:47PM -0800, Marshall White wrote:
>...
> If the variable "temp" is not initialized to NULL and the Subversion function doesn't explicitly
> set it to NULL, who knows what will happen.
> Although I haven't seen Subversion do it YET, my test code seg faults without the initialization.
> If you can guarantee that the Subversion functions will always set it to NULL, then it is not such
> a big deal.

Ah. Gotcha. Good call... will apply in a sec.

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: multi-valued returns in SWIG (was: Rcsparse.py)

Posted by Marshall White <cs...@yahoo.com>.
--- Greg Stein <gs...@lyra.org> wrote:
> On Fri, Feb 28, 2003 at 09:14:15PM -0800, Marshall White wrote:
> >...
> > BTW:  This one other piece is really important:
> > 
> > Log:
> > * subversion/bindings/swig/svn_string.i
> >   Initialize the temp variable to NULL for the SWIG binding
> >   %typemap(in, numinputs=0) const char **OUTPUT
> 
> Why is this important? What is the problem that it is trying to solve?
> 
> I know that our functions are not expecting the temp var to be NULL. IOW,
> whenever we have a 'const char **foo' function, where foo is a return value,
> then the function typically doesn't care what the input value is. Does one
> of the SVN functions actually require the initialization?

It wasn't the Subversion function that expects it to be NULL, it is the SWIG function.
The generated code goes roughly like this:

char *temp;
char **temp_ptr = &temp;
subversion_func(temp_ptr);
if (temp == NULL)

If the variable "temp" is not initialized to NULL and the Subversion function doesn't explicitly
set it to NULL, who knows what will happen.
Although I haven't seen Subversion do it YET, my test code seg faults without the initialization.
If you can guarantee that the Subversion functions will always set it to NULL, then it is not such
a big deal.



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

Re: multi-valued returns in SWIG (was: Rcsparse.py)

Posted by Greg Stein <gs...@lyra.org>.
On Fri, Feb 28, 2003 at 09:14:15PM -0800, Marshall White wrote:
>...
> BTW:  This one other piece is really important:
> 
> Log:
> * subversion/bindings/swig/svn_string.i
>   Initialize the temp variable to NULL for the SWIG binding
>   %typemap(in, numinputs=0) const char **OUTPUT

Why is this important? What is the problem that it is trying to solve?

I know that our functions are not expecting the temp var to be NULL. IOW,
whenever we have a 'const char **foo' function, where foo is a return value,
then the function typically doesn't care what the input value is. Does one
of the SVN functions actually require the initialization?

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: multi-valued returns in SWIG (was: Rcsparse.py)

Posted by Marshall White <cs...@yahoo.com>.
--- Greg Stein <gs...@lyra.org> wrote:
> I got a problem fixed using a solution that is quite fine in my mind.
> However, it doesn't address the larger problem at hand. It *would* be good
> to do that, but I haven't seen a good solution for that (yet).
> 
> So no... not closed.
> 

Good because I don't intend to give up just yet.  :-)


BTW:  This one other piece is really important:

Log:
* subversion/bindings/swig/svn_string.i
  Initialize the temp variable to NULL for the SWIG binding
  %typemap(in, numinputs=0) const char **OUTPUT



Index: svn_string.i
===================================================================
--- svn_string.i        (revision 5152)
+++ svn_string.i        (working copy)
@@ -117,7 +117,7 @@
 */

 /* ### note that SWIG drops the const in the arg decl, so we must cast */
-%typemap(in, numinputs=0) const char **OUTPUT (const char *temp)
+%typemap(in, numinputs=0) const char **OUTPUT (const char *temp = NULL)
     "$1 = (char **)&temp;"

 %typemap(python,argout,fragment="t_output_helper") const char **OUTPUT {




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