Enable weak-style references in "ng" configuration#55
Conversation
Currently, all code emulating weak references by just not retaining it is essentially UB when interfacing with ARC. The clang flag enables the use of '__weak' in non-ARC translation units.
rfm
left a comment
There was a problem hiding this comment.
I don't understand the rationale for this: I don't see why we would say that non-arc code which sets a variable without retaining an object is intending to use that variable as a weak pointer, or that the behaviour is undefined.
My understanding is that the lifetime of the referenced object is until the end of the enclosing auto release pool, and if the object is passed to code in an ARC compilation unit which wants to keep it, that code will retain it.
The primary purpose of GNUstep is a portable framework not just that it should build everywhere but, that it should facilitate the development of applications that can run anywhere.
ARC, while really nice, is non-portable, but it's only used when explicitly requested. My assumption is that when ARC is not requested we are going with the normal objective of writing portable code.
If that's the case, this change seems like a bad option because it enables/encourages use of a non-portable (clang-only) compiler feature.
If we really want a weak pointer we can write portable (independent of the compiler/runtime) code for that by calling the runtime functions to set/get values in the pointer (yes it's less convenient than compiler support, but it's not hard). On the other hand, if we don't really need a weak pointer then using _weak would result in code that fails to compile except with the ng library combo.
So, if there is a need for this compiler support of weak variables (I don't see what it is yet), I think we should try to do it in another way.
Perhaps we could do this by adding a new mechanism to generally enable non-portable compiler features similarly to the way we enable ARC. The _weak keyword could be #define'd to nothing if this was not enabled, but allowed if it is enabled. I realise that would be a much bigger patch, but I'm willing to work on it if you agree.
Currently, all code emulating weak references by just not retaining it is essentially UB when interfacing with ARC. The clang flag enables the use of '__weak' in non-ARC translation units.