swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

defobj follow up/ Reflective objects


From: Paul E. Johnson
Subject: defobj follow up/ Reflective objects
Date: Mon, 05 Jun 2000 11:59:40 -0500

The ASM revision I'm working on now and then has fairly complicated data
management needs. I'm looking for a nice way to grab all floats, ints,
out of a class and write them into a file.  The current approach is to
write many many methods that individually grab each variable, send it to
an output object, and proceed. 

While browsing defobj.m, I notice that each object (SwarmObject) has
variables inside it that allow one to get a list of all IVARS.  The
variable is "ivarList".  So I decided to have some fun and try to use
it.  In Heatbug.m's step method, I get a segfault whenever I try to
access, and I wondered what is the magic in it. 

Looking at the -lispOutShallow: method in DefClass.m, I don't understand
why this will not work.

 {
  struct objc_ivar_list *ivars = ((Class_s *) self)->ivarList;
  unsigned  count = ivars->ivar_count;
  printf ("ivar count %d ", count);
}

gdb says:

144       struct objc_ivar_list *ivars = ((Class_s *) self)->ivarList;
(gdb) s
_i_Heatbug__step (self=0x816a020, _cmd=0x804e438) at Heatbug.m:146
146       printf ("ivar count %d ", count);
(gdb) s
145       unsigned  count = ivars->ivar_count;
(gdb) s
Program received signal SIGSEGV, Segmentation fault.
_i_Heatbug__step (self=0x816a020, _cmd=0x804e438) at Heatbug.m:145
145       unsigned  count = ivars->ivar_count;


A while ago, Benedikt S. explained about how objects can be reflective
and he proposed this way of printing out IVARS, but I was interested in
doing it without probes, just for fun and my personal education. 

---------------------
index = [[self getProbeMap] begin: [self getZone]];

for (probe = [index next]; [index getLoc] == Member; probe = [index
next])
{
    if(([probe class] == [VarProbe class]))
        printf("Ivar %s,value %f\n",[probe getProbedVariable],[probe
probeAsDouble: self]);
    else
        printf("Method %s\n",[probe getProbedMessage]);
}
[index drop];
---------------------

-- 
Paul E. Johnson                         email: address@hidden
Dept. of Political Science              http://lark.cc.ukans.edu/~pauljohn
University of Kansas                    Office: (785) 864-9086
Lawrence, Kansas 66045                  FAX: (785) 864-5700

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]