swarm-support
[Top][All Lists]
Advanced

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

[Swarm-Support] did gcc change the way "message to nil" is handled?


From: Paul Johnson
Subject: [Swarm-Support] did gcc change the way "message to nil" is handled?
Date: Mon, 06 Sep 2004 23:04:43 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040803

I am trying to find a bug in a big program. A nil gets inserted at the very end of the collection, and somehow that magically makes the loop go over and over. Its a loop like this:

for( aThing=[index next];[index getLoc]==Member;[aThing=[index next]])

Very confounding, I can't figure how the nil gets in there.

Anyway, while bug shooting I started to suspect some monkey business with Swarm collections and the old [index remove] as applied to the last element. So I made a test app to see if removing the last item with that method caused the nil to appear at the end.

It did not unearth the cause of my trouble, but it did reveal another problem with gcc-3.3.2 and Swarm-2.1.150. Now, you can send messages to nil and no error is returned. It just returns a 0. This is the way it had worked a long time ago, but about 3 years ago, we started getting errors about sending messages to nils.

If you run the attached, you see it doesn't give any errors when nils are told to do things.

I'm thinking this is bad, how about you? I used to think it was good, but that was when I was a lazier programmer.

If you've ever had the problem of a nil magically appearing at the end of a collection and causing an index to malfunction and repeat over and over, I'd be glad to know.

--
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ku.edu/~pauljohn
1541 Lilac Lane, Rm 504
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66044-3177           FAX: (785) 864-5700
#import <simtools.h>
#import <defobj/Create.h>
#import <objectbase.h>
#import <objectbase/SwarmObject.h>
#import <random.h>
#import <collections.h>

@interface Bug: SwarmObject
{
  int RI;
}

- setRI: (int) x;
- (int)getRI;

@end

@implementation Bug

-setRI: (int)x
{
  RI= x;
  printf("RI is %d \n",x);
  return self;
}

- (int)getRI
{
  return RI;
}

@end


int
main (int argc, const char **argv)
{
  id aCollection, index;
  id aThing;
  int i;
  initSwarm (argc, argv);
  aCollection = [List create: globalZone];

  for (i =0; i< 100; i++)
    {
      [aCollection addFirst: [[Bug create: globalZone] setRI: i]];
      fprintf(stderr,"collection getcount %d \n",[aCollection getCount]);
    }

  index = [aCollection begin: globalZone];
  for ( aThing = [index next]; [index getLoc]==Member; aThing=[index next])
    {
      fprintf(stderr,"first RI=%d\n", [aThing getRI]);
    }

  [index drop];


 [aCollection atOffset: 99 put: nil];
  index = [aCollection begin: globalZone];
  for ( aThing = [index next]; [index getLoc]==Member; aThing=[index next])
    {
      fprintf(stderr,"second RI=%d\n", [aThing getRI]);
      if ([aThing getRI] == 0)
        [index remove];
    }

  [index drop];


  fprintf(stderr,"aCollection has %d elements\n",[aCollection getCount]);
  fprintf(stderr,"here's an object %d \n",[[aCollection atOffset: 97] getRI]);
  [aCollection atOffset: 97 put: nil];
  fprintf(stderr,"I just put a nil in the last spot in the list\n");
  index = [aCollection begin: globalZone];
  for ( aThing = [index next]; [index getLoc]==Member; aThing=[index next])
    {
      fprintf(stderr,"third RI=%d\n", [aThing getRI]);
      if (!aThing)fprintf(stderr,"yes, that last one was a nil!\n");
    }

  [index drop];
  return 0;
}

/* 
Local Variables: 
compile-command: "$SWARMHOME/bin/libtool-swarm --mode=link gcc -D_GNU_SOURCE 
-Wall -o listWithNil  -g -Wno-import \
-I$SWARMHOME/include -I$SWARMHOME/include/swarm -L$SWARMHOME/lib \
-L$SWARMHOME/lib/swarm listWithNil.m -lswarm -lobjc " 
End: 
*/







reply via email to

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