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

Re: [PATCH] Missing Binding for svn_checksum_t

From: Daniel Shahaf <danielsh_at_elego.de>
Date: Fri, 7 Dec 2012 11:02:29 +0200

> Index: svn_checksum_t.swg
> ===================================================================
> --- svn_checksum_t.swg (revision 0)
> +++ svn_checksum_t.swg (revision 0)
> @@ -0,0 +1,47 @@
> +%module checksum/**
> + * TYPE: svn_checksum_t.; functions typemapped svn_checksum_t ; svn_checksum_kind_t, svn_checksum_create and avn_checksum_clear
> + * The input for the function svn_checksum_clear is of the Type svn_check_sum_t so by the typemap rules it maps to the typemap("in") defined here.
> + */
> +
> +#ifdef SWIGPYTHON
> +%typemap(in) svn_checksum_t * {
> + /* check if the input is not a const unsigned char* digest */
> + if(!PyBytes_Check($input)){

If the input is a 'bytes' instance, where do you stow the 'kind' member?

> + PyErr_SetString(PyExc_TypeError, "Not a valid Bit string");
> + /* return fail if it isnt*/
> + SWIG_fail;
> + }
> + /*else , pass is as the required argument for the svn_checksum_Clear function*/
> + $1 = svn_checksum_clear(PyBytes_FromString($input));

This line:

- Passes a 'bytes' object to a constructor of 'bytes' object;

- Passes a counted-length string to an API that expects a C string;

- Passes a PyObject * to a Subversion API function taking an svn_checksum_t *;

- Uses an svn_error_t * as the result of the typemap

Basically, you managed to condense four type mismatches into two
function calls and one assignment. And each one of those is a potential
segfault.

I won't blame you for not noticing that your patch generated new
compiler warnings --- the bindings build generates mountains of stderr
spam --- but did you compile and run the code?

> +}
> +#endif

Cheers

Daniel
Received on 2012-12-07 10:03:42 CET

This is an archived mail posted to the Subversion Dev mailing list.