Page MenuHome

Fix for Freestyle Python Iterators
ClosedPublic

Authored by Folkert de Vries (flokkievids) on Jan 16 2014, 9:38 PM.

Details

Summary

The Freestyle iterators had a big flaw when being used in for loops, being that the iterator object wasn't in sync with the object returned by
next(). This would crash when referencing the iterator on the final iteration (it.object would point to nothing).

This patch fixes that by not incrementing the iterator on the first call of next() (iternext internally). to make sure referencing the iterator object doesn't crash, the iterator is also validated by checking whether it has reached its end. since the iterator object should now always be valid, the changes made in revision rBc592ebf5df4a2be3b70bd3e2f2bba0e3d5908704 and revision 61233 can be reverted.

This change does not have any influence on the operation of current scripts, but will allow the use of for loops in more cases in the future.

NB: I also changed 'reversed' to be a bool, but it seems that reversed is not referenced from the outside (nor is it referable through the api)
to me it seems that reversed could be removed. if someone needs a reversed iterator, the reversed() Python built-in should be used.

Diff Detail

Event Timeline

Folkert de Vries (flokkievids) updated this revision to Unknown Object (????).Jan 28 2014, 1:01 PM

I added an iter() method for all types with an iternext() method. if the "at_start" attribute wasn't propperly set the first object of the iterator would be skipped. The added iter() method will set this variable correctly.

Folkert de Vries (flokkievids) updated this revision to Unknown Object (????).Feb 1 2014, 4:44 PM

Some changes suggested by TK (@Tamito Kajiyama (kjym3)), most notably:

  • convert the reversed attribute to a bool in all places
  • make sure the Python/c++ conversion doesn't give problems
  • make the following idiom work: for svert in stroke: ...

I also adjusted some docstrings to resemble current and past changes.

The latest revision (Diff 3, ID 820) looks okay to me. I will commit the changes to git master.

What is the status here? The patch gets a bit dusty. Thanks.

The changes suggested here were committed a while ago, but not from here (this patch was not closed by the commit). It can be closed now.