Re: C Level Iterators and Userland Classes

From: Date: Wed, 15 Feb 2006 22:36:05 +0000
Subject: Re: C Level Iterators and Userland Classes
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-21875@lists.php.net to get a copy of this message
Hello l0t3k, Anrei, Wednesday, February 15, 2006, 11:28:15 PM, you wrote: > "Marcus Boerger" <helly@php.net> wrote in message > news:1355657626.20060215225041@marcus-boerger.de... >> Hello l0t3k, >> >> first of all your question does not make any sense to me whatsoever. > What im trying to allow for is sorting by iterator as well as standard > arrays, for example : > // assume en_US as default locale > $coll = new Collator("en_US"); > $iter = new TextIterator("The rain in Spain drop gently on the Plains", > TextIterator::WORD); > var_dump( $coll->sort($iter)); // returns the sorted list of words > $expr = new Regex($patttern, $input, $flags); > var_dump($coll->sort($expr, SORT_DESC)); // Sorts matches in descending > order >> Anyway looking at the code you seem to be using a c-level iterator >> manually instead of using it inside foreach() construct. > see above... ic, sounds interesting. Actually Andrei doesn't it look like something for ext/unicode? >> The first thing i can see is that you use the iterator index while the >> source code (zend_interface.h) says: >> ulong index; /* private to fe_reset/fe_fetch opcodes */ >> Unil now noone tried to emulate this stuff so i am not sure whether this >> is correct or not. > i wrote this more than ayear ago and i remember copying it from engine code. >> The second thing is that you did not use the dtor() handler so you have >> a memory leak. > which dtor handler ? Zend/zend_iterators.h: typedef struct _zend_object_iterator_funcs { /* release all resources associated with this iterator instance */ void (*dtor)(zend_object_iterator *iter TSRMLS_DC); ^^^that one :-) >> To try to answer what i think you want to know: What ever object you use. >> If it implements Traversable or derived its zend_class_entry has a >> get_iterator function that gets you access to an iteator struct and the >> handler table. You should never touch the data member of that iterator >> struct and the handlers are documented. In your case there is no need to >> use handler invalidate_current(). > That helps. Thanks a lot.... > clayton >> hope this helps >> marcus >> >> Wednesday, February 15, 2006, 6:23:44 PM, you wrote: >> >>> A quick question about using iterators in C code: >> >>> If it sufficient to use the interface gotten from >>> zend_class_entry->get_iterator to handle userland classes which >>> implement >>> Iterator ? >>> The attachment is part of code i'm using to do Unicode based collation. >>> Will >>> this work for userland iterators as well ? >> >>> l0t3k >> >> Best regards, >> Marcus Best regards, Marcus

« previous php.internals (#21875) next »