[Gambas-devel] New(er) enumeration API

Tobias Boege tobias at ...692...
Wed Oct 3 20:45:15 CEST 2012


Hi,

today while debugging the new List code for gb.data I encountered problems
with the new enumeration API. There are _few_ places to learn from (I took
CResult.c) but apparently something doesn't quite work out with it:

I want to run through all references I manage for a chunk in a List (a
'chunk' contains some Variants). These are the 'Current' pointer and all the
enumerations currently active. The ultimate goal is to update members of
these reference structures just because the elements they point to in the
chunk changed their location. The convenience macro looks like this:

#define for_all_persistent_vals(list, vp, es, ebuf)                     \
	for (ebuf = GB.BeginEnum(list), vp = &list->current, es = NULL;	\
	vp ? 1 : (GB.EndEnum(ebuf), 0);					\
		!GB.NextEnum() ? (es = (struct enum_state*) GB.GetEnum(),\
			vp = &es->next) : (vp = NULL))

(admittely not a very appealing piece of code)

where 'list' is the Gambas List object, 'vp' is a pointer to the structure
I want to update, 'es' is my struct enum_state and 'ebuf' is whatever I get
back from GB.BeginEnum() and have to pass to GB.EndEnum().

The thing now is that, even if no enumeration runs in the Gambas code, I get
some 'es' which contains information that could actually have been valid (in
fact, it refers to the last enumerated object in the last enumeration).
For some reason, the important part (the pointer to the chunk which sits at
offset 0 from the 'es' pointer) is set to NULL and thus, my library
segfaults on NULL pointer dereference.

Benoit, can you please enlighten me if I am doing something wrong with these
functions?

Regards,
Tobi





More information about the Devel mailing list