FAQ
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


begin 666 sort.txt
M4$A07TDQ.$Y?05!)('IE;F1?8F]O;"!I8W5?8V]L;&%T;W)?<V]R="A#;VQL
M871O<B J8V]L;"P@#0H)"0D)"7IV86P@*FET96US+" -"@D)"0D)>F5N9%]B
M;V]L(&%S8V5N9&EN9RP@#0H)"0D)"7IV86P@*G)E<W5L="!44U)-3%-?1$,I
M#0I[#0H):6YT,S)?="!C;W5N=" ](# L(&EN9&5X+"!I.PT*"6-O;&Q?<V]R
M=%]K97D@("IS;W)T7VME>7,@/2!.54Q,.PT*"7IV86P@*BIE;G1R>3L-"@EZ
M=F%L("IZ:71E;7,@/2!.54Q,.PT*"7IV86P@*GIS='([#0H)>F5N9%]B;V]L
M(&9R;VU?:71E<F%T;W(@/2!&04Q313L-"@T*"6EF("A:7U194$5?4"AI=&5M
M<RD@/3T@25-?3T)*14-4*2![#0H)"7IE;F1?;V)J96-T7VET97)A=&]R("II
M=&5R(#T@3E5,3#L-"@D)>F5N9%]C;&%S<U]E;G1R>2 J8V4@/2!:7T]"2D-%
M7U H:71E;7,I.PT*"0EI;G0S,E]T(&-A[#0H-"@D):68@
M*"$H8V4@)B8@8V4M/F=E=%]I=&5R871O<BDI('L-"@D)"7IE;F1?=&AR;W=?
M97AC97!T:6]N7V5X*$Y53$PL(# @5%-234Q37T-#+" B3V)J96-T(&]F('1Y
M<&4@)7,@9&ED(&YO="!C<F5A=&4@86X@271E<F%T;W(B+"!C92T^;F%M92D[
M#0H)"0ER971U<FX@,#L-"@D)?0T*#0H)"6ET97(@/2!C92T^9V5T7VET97)A
M=&]R*&-E+"!I=&5M<RP@,"!44U)-3%-?0T,I.PT*#0H)"69R;VU?:71E<F%T
M;W(@/2!44E5%.PT*#0H)"6EF("@A:71E<B!\?"!%1RAE>&-E<'1I;VXI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T7VME>7,I.PT*"7)E='5R;B P.PT*?0T*+RH@?7U]("HO
`
end

Search Discussions

  • Marcus Boerger at Feb 15, 2006 at 9:52 pm
    Hello l0t3k,

    first of all your question does not make any sense to me whatsoever.

    Anyway looking at the code you seem to be using a c-level iterator
    manually instead of using it inside foreach() construct.

    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. But one thing i can say is that your usage revealed
    an error in the engien code. Index is incremented to early. Which is fixed
    by now.

    The second thing is that you did not use the dtor() handler so you have
    a memory leak.

    Otherwise i cannot see anything wrong with your iterator usage. And the
    more i think over it you are probably right in using that index.

    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().

    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
  • L0t3k at Feb 15, 2006 at 10:30 pm
    "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...
    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 ?
    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
  • Marcus Boerger at Feb 15, 2006 at 10:37 pm
    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
  • L0t3k at Feb 15, 2006 at 10:48 pm

    ic, sounds interesting. Actually Andrei doesn't it look like something for
    ext/unicode?
    that's what it's for, actually...
    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 :-)
    Solid ! Thanks again..

    clayton






    Best regards,
    Marcus
  • L0t3k at Feb 17, 2006 at 12:11 am
    Marcus,
    one last question ...
    You should never touch the data member of that iterator
    does this mean that i should make a copy of whatever i get from
    the get_current_data() handler ? There seems to be a bit of inconsistency
    in dealing with the current element in the iterators For example, the
    TextIterator
    reuses the same zval value, whereas the classes in SPL call zval_ptr_dtor()
    between iterations.

    clayton
  • Marcus Boerger at Feb 17, 2006 at 8:18 am
    Hello l0t3k,

    in SPL the iterator classes can be overloaded in TextIterator not.
    Foreach does what is necccessary and especially if inside foreach()
    someone uses the value it is being copied automatically. Since you do
    it all yourself you also need to do the copying yourself. So there is
    no inconsistency, just diiferent usage.

    regards
    marcus

    Friday, February 17, 2006, 1:09:37 AM, you wrote:
    Marcus,
    one last question ...
    You should never touch the data member of that iterator
    does this mean that i should make a copy of whatever i get from
    the get_current_data() handler ? There seems to be a bit of inconsistency
    in dealing with the current element in the iterators For example, the
    TextIterator
    reuses the same zval value, whereas the classes in SPL call zval_ptr_dtor()
    between iterations.
    clayton



    Best regards,
    Marcus

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedFeb 15, '06 at 5:25p
activeFeb 17, '06 at 8:18a
posts7
users2
websitephp.net

2 users in discussion

L0t3k: 4 posts Marcus Boerger: 3 posts

People

Translate

site design / logo © 2022 Grokbase