> I asked:
> > What solution can you offer so that
> >   - in < 10.5, we have no error,
> >   - in >= 10.5, proc_pidinfo gets used?
> 
> Would this work?
> 
> int proc_pidinfo (int, int, uint64_t, void *, int) WEAK_IMPORT_ATTRIBUTE;
> 
> if (proc_pidinfo != NULL)
>   {
>     ... code that invokes proc_pidinfo ...
>   }
> 
> Based on [1].
> 
> Bruno
> 
> [1] 
> https://opensource.apple.com/source/dyld/dyld-44.17/unit-tests/test-cases/weak-symbol/
>  
> <https://opensource.apple.com/source/dyld/dyld-44.17/unit-tests/test-cases/weak-symbol/>
> 
> 

That is not usually how this is done, although it might work and is suitably 
simple. The problem I suppose is the function definition can change somewhat 
over time.

Usually, the SDK features automatically supply the weak import attribute 
features, based on your SDK and your deployment target.

What was traditionally done (before the @available() compiler feature came out) 
is something like this, using as an example the function 
“pthread_threadid_np()” which is defined in the MacOSX 10.6 SDK and available 
in MacOSX version 10.6 and later.

MAC_OS_X_VERSION_MAX_ALLOWED = the SDK you are building against
MAC_OS_X_VERSION_MIN_REQUIRED = the minimum system you are willing to support

==========
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
    native_id = pthread_mach_thread_np(pthread_self());
#elif MAC_OS_X_VERSION_MIN_REQUIRED < 1060
    if (&pthread_threadid_np) {
        (void) pthread_threadid_np(NULL, &native_id);
    } else {
        native_id = pthread_mach_thread_np(pthread_self());
    }
#else
    (void) pthread_threadid_np(NULL, &native_id);
#endif
========



with this method, if the SDK does not have the function, the fallback is always 
used. 

If the SDK does have the function, but the application might be deployed to a 
system where the function is unavailable, the null test for the function 
address is used. The function is automatically weak-linked by the SDK features. 
The fallback will then be used if the function is unavailable.

If the minimum deployment target is a system that is known to have the 
function, then no test is done and the function is strongly linked and assumed 
available. An error will result at runtime if there is no such function 
available.

Ken

Reply via email to