discuss-gnustep
[Top][All Lists]
Advanced

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

Anyone else having heavy problems with NSInvocation? - Addendum and fix


From: Roland Schwingel
Subject: Anyone else having heavy problems with NSInvocation? - Addendum and fix
Date: Wed, 27 Nov 2002 17:00:36 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1) Gecko/20020826

Hi...

Today morning I posted the fowarded mail to discuss-gnustep (after days of frustrating debugging),
but soon afterwards I could isolate the problem...

When building up the structures for avcall (and vacall respectively) GSFFCallInvocation must take the alignment ot the certain datatypes in account. This alignment is stored
in NSArgumentInfo. NSArgumentInfo is filled by mframe.m in function
mframe_next_arg(). To determin the alignment of structures it uses the gcc's
__alignof__ . Here gcc (at least 2.95.3) returns 16 as alignment for structures. But
the alignment for  i386 is 4! => A 1000 funny crashes when using structures
over GSFFCallInvocation.

When replacing the __alignof__ with objc_alignof_type this problem can be fixed
(and now also structures are working very well for me).

Attached you find my changes to mframe.m. Maybe the change can find its way
into CVS (after verify)?

mframe.m: around line 360
     case _C_STRUCT_B:
   {
     int acc_size = 0;
     int defaultAlign= objc_alignof_type(typePtr-1);
     int acc_align = defaultAlign;

     /*
      *    Skip "<name>=" stuff.
      */
     while (*typePtr != _C_STRUCT_E)
       {
         if (*typePtr++ == '=')
       {
         break;
       }
       }
     /*
      *    Base structure alignment on first element.
      */
     if (*typePtr != _C_STRUCT_E)
       {
         typePtr = mframe_next_arg(typePtr, &local);
         if (typePtr == 0)
       {
         return 0;        /* error    */
       }
         acc_size = ROUND(acc_size, local.align);
         acc_size += local.size;
         acc_align = MAX(local.align,defaultAlign);
       }
     /*
      *    Continue accumulating structure size.
      */
     while (*typePtr != _C_STRUCT_E)
       {
         typePtr = mframe_next_arg(typePtr, &local);
         if (typePtr == 0)
       {
         return 0;        /* error    */
       }
         acc_size = ROUND(acc_size, local.align);
         acc_size += local.size;
       }
     info->size = acc_size;
     info->align = acc_align;
     typePtr++;    /* Skip end-of-struct    */
   }
   break;

Kind regards,

Roland

--- Begin Message --- Subject: Anyone else having heavy problems with NSInvocation? Date: Wed, 27 Nov 2002 11:20:37 +0100 User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1) Gecko/20020826
Hi...

As some might now I am running gnustep on Windows (mingw32)...

I ran it a long time with GSFrameInvocation as concrete class. Everything was fine. (NSInvocation is heavily in use). But then came XP and here it is (sometimes)
- not always, but much too often - crashing when invoking a NSInvocation.
Presumably a __builtin_apply() problem of gcc (I have to run 2.95.3)???

So I switched to ffcall. The random crashes disappeared, but for some
reason when using structs as arguments it crashes now reproducably and everytime on
all windows platforms (tested NT4,W2k,XP).

I try to invoke eg. a method like this.
- (void)methodWithRange:(NSRange)aRange andObject:(NSString *)string andRange:(NSRange)secondRange

The method is invoked with rubbish as arguments and when then acessing eg. the string
it crashes. Rubbish in rubbish out.... So I tried to debug it.

When peeking out the invocations arguments before invoking it it appears that everything is trashed right here. See the attached output of my little NSInvocation dumper. (It hooks in as category to NSInvocation -invoke and dumps right before invoking).
Arguments should be:
aRange={location=4,length=1} aString(id:0x0D4285D0)="hello" secondRange={location=4,length=0}
(the dumper shows the correct results when using GSFrameInvocation)

NSInvocation: aClass methodWithRange:andObject:andRange: with GSFFCallInvocation
Returntype=void
5 (retained) Arguments to invocation:
complete ArgumentString: @0:4{?=II}8@16{?=II}20
arg0: offset = 0
arg0: type = @ (object)
arg0: typeDescription = ID:0x0B3C4268 Class:aClass description:<aClass: b3c4268>
arg0: size = 4
arg0: align = 4
arg0: qual = 0
arg0: isReg = 0
===================
arg1: offset = 4
arg1: type = : (selector)
arg1: typeDescription = methodWithRange:andObject:andRange:
arg1: size = 4
arg1: align = 4
arg1: qual = 0
arg1: isReg = 0
===================
arg2: offset = 8
arg2: type = { (struct)
arg2: typeDescription = struct-layout:
     element0: offset:0 alignment:4 type:I (uint) descr:2005416376
     element1: offset:4 alignment:4 type:I (uint) descr:1
arg2: size = 8
arg2: align = 16
arg2: qual = 0
arg2: isReg = 0
===================
arg3: offset = 16
arg3: type = @ (object)
arg3: typeDescription = ID:0x00000004 Class:null description:null
arg3: size = 4
arg3: align = 4
arg3: qual = 0
arg3: isReg = 0
===================
arg4: offset = 20
arg4: type = { (struct)
arg4: typeDescription = struct-layout:
     element0: offset:0 alignment:4 type:I (uint) descr:0
     element1: offset:4 alignment:4 type:I (uint) descr:229240664
arg4: size = 8
arg4: align = 16
arg4: qual = 0
arg4: isReg = 0
===================
before invoke...
* imagine a fine crash here when the called method tries to access the object *

Using GSFrameInvocation everything is fine here (and in the invoked method) but it
crashes elsewhere (with other invocations) on XP by then.

Also when using only objects as parameters everything appears to be fine with
GSFFCallInvocation. But when using structs it goes crash.

So it appears when using GSFFCallInvocation that creating the callframe for avcall in gs_objc_msg_forward() in GSFFCallInvocation.m fails when structs are there as
arguments. But I can't find a bug here.

Are compiler options here of any influence?
-fno-omit-frame-pointer vs -fomit-frame-pointer

I tried compiling gnustep with both. -fno-omit-frame-pointer seems to present (sometimes)
partitially correct arguments...

Any help is appreciated... And thanks for your answers in advance.
(Maybe someone has a solution for the GSFrameInvocation problem on XP?)

Roland



--- End Message ---

reply via email to

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