New changes in arrays

Mike Mason mmlnx@us.ibm.com
Fri Jan 19 17:47:00 GMT 2007


The array changes aren't working as expected for membership tests. The script below results in the following output:

zero
one
one

Should I file a separate bug?

- Mike

Script:

global testarr
probe begin
{
        testarr["zero"] = 0
        testarr["one"] = 1
        foreach (str in testarr) printf("%s\n", str)
        if ("zero" in testarr)   printf("%s\n", "zero")
        if ("one" in testarr)    printf("%s\n", "one")
}


Martin Hunt wrote:
> I've checked in a minor change to how arrays work. This probably won't
> break any scripts, but it might. You should also be aware of the change
> because it can make some scripts simpler.
> 
> In the past setting an array element to 0 or "" internally deleted it.
> Now it keeps the element and simply sets its value. The only difference
> this makes to scripts is when "foreach" is used to iterate through the
> elements of a list or when testing for membership.
> 
> Examples:
> 
> for (i=0;i<11;i++)
>   foo[i] = i*i
> foreach (i in foo)
>   printf("foo[%d] = %d\n", i, foo[i])
> 
> This previously would have printed "foo[1] = 1 ..." but now it starts
> with "foo[0] = 0 ..."
> 
> To remove an element from an array and free up its memory, you must use
> "delete". That has always worked, but you used to also be able to set
> the element to 0 or an empty string. If you see code that sets array
> elements to 0 or "", you probably want to update it.
> 
> Martin
> 
> 
> 
> 



More information about the Systemtap mailing list