Hi Tristan, On 7 Jan 2015, at 10:15, Arnaud Charlet wrote:
> Use _NSGetEnviron to get environment. > > Tested on x86_64-pc-linux-gnu, committed on trunk > > 2015-01-07 Tristan Gingold <ging...@adacore.com> > > PR ada/64349 > * env.c (__gnat_environ): Adjust for darwin9/darwin10. > > <difs.txt> So my original patch assumed that, while it was not legal to use environ from a shlib, it is legal to use _NSGetEnviron () from an application ... .. and, OK fine, I see the point about ! defined (__arm__) .. but a few other comments. ISTM that there's a partial implementation to distinguish between IN_RTS and application? Index: env.c =================================================================== --- env.c (revision 219191) +++ env.c (working copy) @@ -44,6 +44,12 @@ #include <stdlib.h> #endif +#if defined (__APPLE__) && !defined (__arm__) +/* On Darwin, _NSGetEnviron must be used for shared libraries; but it is not + available on iOS. */ +#include <crt_externs.h> +#endif + This definition ^ fires for IN_RTS ... ... but there's no definition of _NSGetEnviron in the other branch unless it happens to get pulled in via config.h / system.h - I don't know that this is guaranteed, do you? ---- #if defined (__vxworks) #if defined (__RTP__) /* On VxWorks 6 Real-Time process mode, environ is defined in unistd.h. */ @@ -212,6 +218,8 @@ #elif ! (defined (__vxworks)) extern char **environ; return environ; ^ I don't expect __vxworks to be defined for a Darwin compiler ... .. so not sure what the code below will achieve. +#elif defined (__APPLE__) && !defined (__arm__) + return *_NSGetEnviron (); ^ here you use _NSGetEnviron () unconditionally (see comment re. IN_RTS). #else return environ; #endif ==== If we want to distinguish between in IN_RTS and application maybe sth pseudo-code like: if IN_RTS if apple && ! arm include crt_externals.h define environ (*_ _NSGetEnviron ()) end else if apple and ! arm extern "C" char ** environ; end end ...... amend the vxworks case ... +#elif defined (__APPLE__) && !defined (__arm__) + return environ; ==== Am I missing some point here? Iain