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

Re: Status of ctypes Subversion bindings

From: David James <james_at_cs.toronto.edu>
Date: Sat, 21 Jun 2008 09:07:14 -0700

On Tue, Jun 17, 2008 at 7:41 PM, Eric Gillespie <epg_at_pretzelnet.org> wrote:
> I started testing csvn again, and found a problem.
> csvn/core/__init__.py calls svn_cmdline_init! That function does
> all kinds of things that are inappropriate for many programs
> (e.g. mucking with locale, mucking with stdout, printing to
> stderr, terminating the process). And it certainly shouldn't be
> called on import.
>
>
> Maybe we can add a csvn.SimpleInit function for high-level
> consumers who don't want to think about; anyone else will have to
> read the documentation to see what all they may have to
> initialize, and how those things may fail.

Great points. This will break compatibility with all scripts, but,
fortunately, this is OK because the ctypes python bindings haven't
been released yet. If everyone is OK with this idea I'll go ahead and
implement this.

On Tue, Jun 17, 2008 at 8:25 PM, Eric Gillespie <epg_at_pretzelnet.org> wrote:
> Eric Gillespie <epg_at_pretzelnet.org> writes:
>
>> I started testing csvn again, and found a problem.
>
> One more, and then I'm done for now.
>
>>>> revprops = csvn.core.apr_hash_make(pool)
>>>> csvn.core.apr_hash_set(revprops, 'svn:log', csvn.core.APR_HASH_KEY_STRING, csvn.core.svn_string_create('log message', pool))
>>>> val = csvn.core.apr_hash_get(revprops, 'key', csvn.core.APR_HASH_KEY_STRING)
>>>> val
> <ctypes.LP_c_void object at 0xf7aae6a4>
>>>> val_s = ctypes.cast(val, csvn.core.svn_string_t)
>
> Process Python segmentation fault (core dumped)

Looks like there's some typos in your script. (You put 'key' instead
of 'svn:log' in the apr_hash_get line, and you cast the val to a
svn_string_t instead of a pointer to a svn_string_t). When I fix these
typos your script works great:

import csvn.core
import csvn.types
import ctypes
pool = csvn.core.Pool()
revprops = csvn.core.apr_hash_make(pool)
s = csvn.core.svn_string_create('log message', pool)
csvn.core.apr_hash_set(revprops, 'svn:log', csvn.core.APR_HASH_KEY_STRING, s)
val = csvn.core.apr_hash_get(revprops, 'svn:log', csvn.core.APR_HASH_KEY_STRING)
val_s = ctypes.cast(val, ctypes.POINTER(csvn.core.svn_string_t))
print val_s[0].data

>
> OK, so I probably did something wrong. Maybe I can get
> csvn.types.Hash to work, and then I can pare that down until I
> understand what to do with a hash.
>
>>>> revprops = csvn.types.Hash(csvn.core.svn_string_t, wrapper=csvn.types.SvnStringPtr)
>>>> revprops
> {}
>>>> revprops['svn:log'] = 'log message'
>>>> revprops['svn:log']
>
> Process Python segmentation fault (core dumped)

You want a pointer to an svn_string_t here too:

revprops = csvn.types.Hash(ctypes.POINTER(csvn.core.svn_string_t),
wrapper=csvn.types.SvnStringPtr)
revprops['svn:log'] = 'log message'
print revprops['svn:log']

>
> Well, maybe guessing from uses of Hash in the high-level binding
> was wrong and I don't want the wrapper= parameter.
>
>>>> revprops = csvn.types.Hash(csvn.core.svn_string_t)
>>>> revprops['svn:log'] = 'log message'
>>>> revprops['svn:log']
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/local/google/home/epg/work/svn/ctypes-python-bindings6/csvn/types.py", line 59, in __getitem__
> raise KeyError(key)
> KeyError: 'svn:log'
>>>> revprops
>
> Process Python segmentation fault (core dumped)
>

Here's a working version of that script too:

revprops = csvn.types.Hash(ctypes.POINTER(csvn.core.svn_string_t))
s = csvn.core.svn_string_create('log message', pool)
revprops['svn:log'] = s
print revprops['svn:log'][0].data

Cheers,

David

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: dev-help_at_subversion.tigris.org
Received on 2008-06-21 18:07:30 CEST

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.