[GRASS-dev] bound_box in python

Glynn Clements glynn at gclements.plus.com
Mon Jun 1 00:59:06 EDT 2009


Markus Neteler wrote:

> but I get
> Traceback (most recent call last):
>   File "examples/vectoraccess.py", line 45, in <module>
>     print 'Map box:', grassvect.Vect_get_map_box(map, box)
> TypeError: in method 'Vect_get_map_box', argument 2 of type 'BOUND_BOX *'
> 
> Using instead BOUND_BOX, it also fails:
> Traceback (most recent call last):
>   File "examples/vectoraccess.py", line 32, in <module>
>     box = grassvect.BOUND_BOX()
> AttributeError: 'module' object has no attribute 'BOUND_BOX'

Right. SWIG only generates wrappers for the "struct bound_box" type,
but requires that you pass a "BOUND_BOX *" to the function.

Like most things which deal with C, it gets confused by preprocessor
macros.

> Looking at the GRASS includes, I see
> include/vect/dig_structs.h:#define BOUND_BOX struct bound_box
> 
> Is there a strategic advantage to define 'struct bound_box' like this while
> for example 'struct Map_info' isn't defined as MAP_INFO in the Vector
> libs?

No. If you really want an alias, use typedef, e.g.:

	typedef struct bound_box BOUND_BOX;

But I would prefer to just use "struct bound_box" everywhere to make
it clear that it's a structure.

I intend to commit a fix once the test compilation has completed.

More generally: avoid using the preprocessor unless it's absolutely
essential. Any convenience which it appears to offer is usually
illusory; you get convenience in one aspect, and inconvenience in a
dozen others.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list