You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Nik Clayton <ni...@ngo.org.uk> on 2007/02/26 21:10:13 UTC

svn_client_list, Perl, swig bindings

All,

I'm trying to wrap svn_client_list() using the SWIG bindings, to make it 
accessible to Perl.

Attached is a diff that's my first cut at doing that.  Since 
svn_client_list() takes a parameter that (in Perl) is a subroutine 
reference, I've modeled the approach on the svn_client_list() 
implementation, which does the same thing.

But it doesn't work.  My tests have involved:

a.  Checking out the perl-bindings-improvements branch (with the patch)

b.  Building the code

c.  Trying to run the attached list.t in subversion/bindings/swig/perl/native as

     % perl -Iblib/lib list.t
     ok 1 - use Test::SVN;
     ok 2 - use SVN::Client;
     ok 3 - The object isa SVN::Client
     Usage:
         svn_client_list(path_or_url,peg_revision,revision,recurse,
         dirent_fields,fetch_locks,list_func,baton,ctx,pool);1..3
     # Looks like your test died just after 3.

(lines wrapped).  I've about hit the extent of my swig-fu at this point.

Anyone spot my glaringly obvious mistake?

N

Re: svn_client_list, Perl, swig bindings

Posted by Nik Clayton <ni...@ngo.org.uk>.
[ This is intended as search engine fodder for those that come after me,
   rather than something that needs a response ]

Nik Clayton wrote:
> I see from the .i and .swg files in the repo that both these types have 
> been wrapped by the bindings.  But I can't for the life of me work out 
> how I go from the arguments passed to svn_swig_pl_thunk_list_receiver() 
> (*dirent and *lock), to appropriate arguments to include in the call in 
> to svn_swig_pl_callback_thunk().  Looking through the other code to see 
> if there are any examples of something similar haven't been fruitful.
> 
> Anyone know how to do this?

For the record, if you have a Subversion data type, and want to convert it 
to a wrapped type for a callback written in Perl using the Perl swig 
bindings is to use convert_to_swig_type().

As a pseudo-patch to the code I posted previously.

   svn_error_t *svn_swig_pl_thunk_list_receiver(void *baton,
                                               const char *path,
                                               const svn_dirent_t *dirent,
                                               const svn_lock_t *lock,
                                               const char *abs_path,
                                               apr_pool_t *pool)
   {
       SV *receiver = baton;
+     swig_type_info *dirent_type = _SWIG_TYPE("svn_dirent_t *");
+     swig_type_info *lock_type   = _SWIG_TYPE("svn_lock_t *");

       if (!SvOK(receiver))
          return SVN_NO_ERROR;

       svn_swig_pl_callback_thunk(CALL_SV, receiver, NULL, "sOOsS", path,
-                                &PL_sv_undef,
-                                &PL_sv_undef, abs_path,
-                                pool, POOLINFO);
+                                (dirent) ?
+                                  convert_to_swig_type(dirent, dirent_type)
+                                : &PL_sv_undef,
+                                (lock) ?
+                                  convert_to_swig_type(lock, lock_type)
+                                : &PL_sv_undef,
+			         abs_path, pool, POOLINFO);

       return SVN_NO_ERROR;
   }

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

Re: svn_client_list, Perl, swig bindings

Posted by Nik Clayton <ni...@ngo.org.uk>.
Nik Clayton wrote:
> is necessary.  Of course, now I have segfaults, but I can work on those :-)

I've fixed those, and am now moving on to the next challenge.

The bulk of the work takes place in a new function, 
svn_swig_pl_thunk_list_receiver().  Here's what I've got so far.

   svn_error_t *svn_swig_pl_thunk_list_receiver(void *baton,
                                               const char *path,
                                               const svn_dirent_t *dirent,
                                               const svn_lock_t *lock,
                                               const char *abs_path,
                                               apr_pool_t *pool)
   {
       SV *receiver = baton;

       if (!SvOK(receiver))
          return SVN_NO_ERROR;

       svn_swig_pl_callback_thunk(CALL_SV, receiver, NULL, "sOOsS", path,
                                  &PL_sv_undef,
                                  &PL_sv_undef, abs_path,
                                  pool, POOLINFO);

       return SVN_NO_ERROR;
   }

This (part of the attached patch) is enough to get svn_client_list() working 
from the Perl bindings.  With one caveat.  In the call to 
svn_swig_pl_callback_thunk() note the two references to &PL_sv_undef.  This 
is passing in C<undef> to the Perl callback, where it's expecting to see an 
svn_dirent_t and an svn_lock_t.

I see from the .i and .swg files in the repo that both these types have been 
wrapped by the bindings.  But I can't for the life of me work out how I go 
from the arguments passed to svn_swig_pl_thunk_list_receiver() (*dirent and 
*lock), to appropriate arguments to include in the call in to 
svn_swig_pl_callback_thunk().  Looking through the other code to see if 
there are any examples of something similar haven't been fruitful.

Anyone know how to do this?

The complete patch is attached.

N

Re: svn_client_list, Perl, swig bindings

Posted by Nik Clayton <ni...@ngo.org.uk>.
Nik Clayton wrote:
> I'm trying to wrap svn_client_list() using the SWIG bindings, to make it 
> accessible to Perl.

[...]

> Anyone spot my glaringly obvious mistake?

Judicious instrumentation with truss showed Perl wasn't picking up the newly 
built libraries.  Turns out that testing with:

     perl -Iblib/lib ...

is not sufficient,

     perl -Iblib/lib -Iblib/arch ...

is necessary.  Of course, now I have segfaults, but I can work on those :-)

N

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