|
|
Log in / Subscribe / Register

Loops

Loops

Posted May 27, 2013 20:52 UTC (Mon) by nix (subscriber, #2304)
In reply to: Loops by corbet
Parent article: Ktap — yet another kernel tracer

As long as the integer iteration and table iteration don't contain a way for the current loop value to be changed during the loop, that should be OK. I wonder what happens if you change a table while iterating over it... you *can* make that have defined, consistent, and always-terminating behaviour (I did it in a C hash table once) but it tends to lead to rather complex iterators which I doubt have been implemented here. (In my case, about 40% of the code of the iterator was to deal with the stable-iteration-over-mutation case.)


to post comments

Loops

Posted May 31, 2013 2:46 UTC (Fri) by bluss (guest, #47454) [Link]

I looked into the ktap code, it's interesting to see how much of the Lua VM and seeminly its table implementation is there.

So if it's like Lua's tables, then you can delete key-value pairs during iteration fine, but you shouldn't add key-value pairs during iteration; if you do, I think iteration is unpredictable.

I think it's a bit misleading that no notice is given in the license header of the files with copies of lua code (even if lua authors are credited elsewhere). It becomes misleading when the file lists 'Author:' without declaring all of them.

https://github.com/ktap/ktap/blob/master/interpreter/table.c

http://www.lua.org/source/5.2/ltable.c.html


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds