gnustep / libobjc2

Objective-C runtime library intended for use with Clang.
http://www.gnustep.org/
MIT License
429 stars 117 forks source link

NSZone Selector Missmatch #297

Open hmelder opened 4 weeks ago

hmelder commented 4 weeks ago

The NSZone stub here has in a different signature which results in a warning at runtime when passing a gnustep-base NSZone struct to objc_allocWithZone: (@24@0:8^{_NSZone=^?^?^?^?^?^?^?Q@^{_NSZone}}16), selector has @24@0:8^{_NSZone=}16.

@davidchisnall how about changing the NSZone struct in fast_path.m to follow the same layout as in gnustep-base?

davidchisnall commented 3 weeks ago

Hmm, this is a special case of a general problem that we should probably fix:

If one compilation unit has a selector that takes a pointer to a forward-declared structure and another has one that takes a pointer to the same forward-declared structure but can see the definition, their types will not match. This is likely to be true for anything where structures are handed out as opaque types.

The right solution here is probably to have the selector hashing code skip everything between the = and } in pointers to structures (not in structures passed by value. We should hash ^{_NSZone=^?^?^?^?^?^?^?Q@^{_NSZone} and ^{_NSZone=} to the same value, but also make sure that (for example) {_NSZone=^?^?^?^?^?^?^?Q@^{_NSZone} and {_NSZone=I} hash to different values.

hmelder commented 3 days ago

The right solution here is probably to have the selector hashing code skip everything between the = and } in pointers to structures

Good idea. Let's merge https://github.com/gnustep/libobjc2/pull/298 first to avoid merge conflicts later on :)