On Fri, Jan 10, 2014 at 07:50:36PM +0100, Rafał Krypa wrote:
On 2014-01-10 17:50, Jarkko Sakkinen wrote:
>Hi José,
>
>On Fri, Jan 10, 2014 at 04:57:01PM +0100, José Bollo wrote:
>>On ven, 2014-01-10 at 15:41 +0100, José Bollo wrote:
>>
>>>The tree version does a natural sorting of the rules but the rules have
>>>to be iterated using the function 'twalk'.
>>well the problem with twalk is that it doesn't have a user pointer.
>>
>>The solution is to index the accesses struct instead of next rule (same
>>memory size) and to record the FILE in accesses instead of first/last.
>>
>>twalk(root, emit);
>>
>>void emit(const void*node,const VISIT visit,const int depth)
>>{
>> if(visit==postorder) {
>> rule_t * rule = *(rule_t**)node; /* const ... */
>> fprintf(rule->access->file,"%s %s %s %s",rule->....);
>> }
>>}
>>
>>That would work. But 3 callback calls by rule! And the price of
>>retrieving file...
>Maybe I'm missing something but why you would you wnat to use twalk
>in the first place? We could just traverse the directly? List traversal
>is trivial even without using a library function. Please correct me
>if I'm now ignoring something.
The problem with direct traversal of glibc tree is that tree data
structures are not exported. The struct node_t, containing left and
right pointers isn't defined nor even declared in any header. It
appears only in implementation file, misc/tsearch.c. For tree API
(tsearch() and friends) tree is typed as void**. The only supported
way to traverse it is the library function twalk().
We could define our copy of struct node_t in libsmack, but it
doesn't sound like a good idea to me.
That is definitely something you don't want to do because struct
node_t can change from GLIBC version to another and who knows what
internal structure is used in other libc implementations.
The next best option is then to use TLS for the state.
/Jarkko