John Levon
2006-Apr-11 15:16 UTC
[dtrace-discuss] Clearing structure-based associative arrays
Consider: struct str { string one; int two; }; struct str foo[string]; BEGIN { foo["bar"].one = "baz"; foo["bar"].two = 1; } tick-1s { foo["bar"].one = 0; foo["bar"].two = 0; } This gives: dtrace: error on enabled probe ID 2 (ID 43463: profile:::tick-1s): invalid address (0x0) in action #1 at DIF offset 52 which seems to make it impossible to clear associative arrays that contain structures with string members. Note that you /can/ clear "string foo[string]", which makes me think that this is simply a bug. Or at least I''m completely missing a way to clear an entry in such an array. I would have expected ''foo["bar"] = 0;'' to still work, actually. regards john
Noel Dellofano
2006-Apr-11 16:14 UTC
[dtrace-discuss] Clearing structure-based associative arrays
John, Setting the individual members of a structure to zero will not cause the structure to be deallocated, you''d actually need something like an undef() function or something of the sort to do this. There was some talk about providing such a function possibly a while ago, but I don''t think there''s been a big pull for it so I''m not sure if it ever officially made it onto the list to be done.> > dtrace: error on enabled probe ID 2 (ID 43463: profile:::tick-1s): > invalid address (0x0) in action #1 at DIF offset 52Also, you got an error because you cannot clear a string value by setting it to zero. You can do this by doing: foo["bar"].one = stringof(NULL); Noel ************************************************************************ ** "Question all the answers" On Apr 11, 2006, at 8:16 AM, John Levon wrote:> > Consider: > > struct str { > string one; > int two; > }; > > struct str foo[string]; > > BEGIN { > foo["bar"].one = "baz"; > foo["bar"].two = 1; > } > > tick-1s { > foo["bar"].one = 0; > foo["bar"].two = 0; > } > > This gives: > > dtrace: error on enabled probe ID 2 (ID 43463: profile:::tick-1s): > invalid address (0x0) in action #1 at DIF offset 52 > > which seems to make it impossible to clear associative arrays that > contain > structures with string members. Note that you /can/ clear "string > foo[string]", > which makes me think that this is simply a bug. Or at least I''m > completely > missing a way to clear an entry in such an array. > > I would have expected ''foo["bar"] = 0;'' to still work, actually. > > regards > john > > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org
John Levon
2006-Apr-11 16:27 UTC
[dtrace-discuss] Clearing structure-based associative arrays
On Tue, Apr 11, 2006 at 09:14:07AM -0700, Noel Dellofano wrote:> Setting the individual members of a structure to zero will not cause > the structure to be deallocatedSo I suspected... is there a bug on this yet?> >dtrace: error on enabled probe ID 2 (ID 43463: profile:::tick-1s): > >invalid address (0x0) in action #1 at DIF offset 52 > > Also, you got an error because you cannot clear a string value by > setting it to zero. You can do this by doing: > foo["bar"].one = stringof(NULL); > > "Question all the answers"OK then :) This actually does work for simple "string foo[string]" arrays; why the difference? regards john
Noel Dellofano
2006-Apr-11 16:42 UTC
[dtrace-discuss] Clearing structure-based associative arrays
> So I suspected... is there a bug on this yet?I don''t believe so, or at least not that I can track down in bugster...> OK then :) This actually does work for simple "string foo[string]" > arrays; why > the difference?Good question :) I''m not really sure, I''m assuming it was a design decision. Makes sense that you''d have to set a string to a string and not a string to a number, but the Dtrace team can answer this one more definitively than I can. Noel ************************************************************************ ** "Question all the answers" On Apr 11, 2006, at 9:27 AM, John Levon wrote:> On Tue, Apr 11, 2006 at 09:14:07AM -0700, Noel Dellofano wrote: > >> Setting the individual members of a structure to zero will not cause >> the structure to be deallocated > > So I suspected... is there a bug on this yet? > >>> dtrace: error on enabled probe ID 2 (ID 43463: profile:::tick-1s): >>> invalid address (0x0) in action #1 at DIF offset 52 >> >> Also, you got an error because you cannot clear a string value by >> setting it to zero. You can do this by doing: >> foo["bar"].one = stringof(NULL); >> >> "Question all the answers" > > OK then :) This actually does work for simple "string foo[string]" > arrays; why > the difference? > > regards > john
Michael Shapiro
2006-Apr-11 23:01 UTC
[dtrace-discuss] Clearing structure-based associative arrays
> > So I suspected... is there a bug on this yet? > > I don''t believe so, or at least not that I can track down in bugster... > > > OK then :) This actually does work for simple "string foo[string]" > > arrays; why > > the difference? > > Good question :) I''m not really sure, I''m assuming it was a design > decision. Makes sense that you''d have to set a string to a string and > not a string to a number, but the Dtrace team can answer this one more > definitively than I can. > > NoelAs Noel said, we need to add an operator to the compiler (e.g. undef()) or the ability to assign a structure to the literal zero and have that clear it. That capability does not currently exist. -Mike -- Mike Shapiro, Solaris Kernel Development. blogs.sun.com/mws/
John Levon
2006-Apr-11 23:12 UTC
[dtrace-discuss] Clearing structure-based associative arrays
On Tue, Apr 11, 2006 at 04:01:20PM -0700, Michael Shapiro wrote:> As Noel said, we need to add an operator to the compiler (e.g. undef()) or > the ability to assign a structure to the literal zero and have that clear it. > That capability does not currently exist.I filed: 6411981 need a way to unallocate struct dynamic variables thanks, john