[gdal-dev] Some questions about the TransformPoints typemap

Even Rouault even.rouault at mines-paris.org
Thu Jun 4 15:05:13 EDT 2009


Rene,

Le Thursday 04 June 2009 14:51:40 Hogendoorn, Rene, vous avez écrit :
> In 1.6.1, TransformPoints got a python typemap such that a list of tuples
> can be transformed. I want to make it a little bit more general, such that
> the inner tuples can be lists as well. While looking at the typemap, I have
> the following questions:
>
> - Why is there an explicit check on Py_None? Py_None will fail the next
> test anyway and the error message is not entirely true since a tuple is a
> sequence as well (and works).

Just slightly suboptimal coding and approximate error message it looks. Patch 
appreciated ;-)

>
> - Memory is allocated with CPLMalloc; in some other typemaps it is plain
> malloc. In the latter case, there is no check on allocation failures.
> Should these be replaced by CPLMalloc?
>
> - If CPLMalloc fails, it calls a memory allocation failure hook (according
> to the docs). The default is to terminate the application; shouldn't this
> hook raise a python memory exception?

Using non fatal allocation and checking the return code could be an 
improvement. But malloc/CPLMalloc should not fail unless you pass it a very 
huge array. Not to mention that CPLMalloc is itself used in GDAL internals, 
although they are from time to time replaced by VSIMalloc when the 
probability of failure is likely, but that makes coding a bit more difficult 
(properly handling error cases). Anyway, patch appreciated ;-)

>
> - The transformpoints typemap returns a tuple of 2 lists. In general,
> python functions return tuples. Is there a reason to return lists in this
> case?

The first list of the tuple is a list of triplets with the tranformed 
coordinates of the input sequence. The second list of the tuple is a list of 
return codes for each tuple of the input sequence
They are lists to be consistant with other calls that return a big number of 
elements. Generally, at least by looking at the other typemaps in the GDAL 
python bindings, we use tuples for small sized arrays (2 or 3 values), and 
lists for bigger arrays. Not sure if there is really a clearly defined policy 
though (I've noticed one exception for example : the typemap returning GCP 
return a tuple of GCPs)

>
> Regards,
>
> Rene Hogendoorn




More information about the gdal-dev mailing list