<pre style='margin:0'>
Chris Jones (cjones051073) pushed a commit to branch master
in repository macports-legacy-support.
</pre>
<p><a href="https://github.com/macports/macports-legacy-support/commit/f2884e3f569160f6b3e023e931504206c43596e5">https://github.com/macports/macports-legacy-support/commit/f2884e3f569160f6b3e023e931504206c43596e5</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit f2884e3f569160f6b3e023e931504206c43596e5
</span>Author: Marcus Calhoun-Lopez <marcuscalhounlopez@gmail.com>
AuthorDate: Thu Apr 7 12:02:05 2022 -0700
<span style='display:block; white-space:pre;color:#404040;'> when wrapping functions, use the original name
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Rust does not use C/C++ header files, so wrapping function calls
</span><span style='display:block; white-space:pre;color:#404040;'> using the preprocessor does not work.
</span><span style='display:block; white-space:pre;color:#404040;'> Instead, shadow the function name and use `dlsym` with `RTLD_NEXT`
</span><span style='display:block; white-space:pre;color:#404040;'> to call the original function version.
</span>---
include/MacportsLegacySupport.h | 10 ----------
include/stdlib.h | 22 ----------------------
include/unistd.h | 21 ---------------------
src/macports_legacy_realpath.c | 26 ++++++++++++++++++--------
src/macports_legacy_sysconf.c | 18 +++++++++++-------
5 files changed, 29 insertions(+), 68 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/include/MacportsLegacySupport.h b/include/MacportsLegacySupport.h
</span><span style='display:block; white-space:pre;color:#808080;'>index b078cec..cc5ce53 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/include/MacportsLegacySupport.h
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/include/MacportsLegacySupport.h
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -101,11 +101,6 @@
</span> /* realpath() on < 1060 does not support modern NULL buffer usage */
#define __MP_LEGACY_SUPPORT_REALPATH_WRAP__ (__APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1060)
<span style='display:block; white-space:pre;background:#ffe0e0;'>-/* realpath() wrap has bail-out macros in case we want to disable only function wrapping */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#define __ENABLE_MP_LEGACY_SUPPORT_REALPATH_WRAP__ (!__DISABLE_MP_LEGACY_SUPPORT_FUNCTION_WRAPPING__ && \
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- !__DISABLE_MP_LEGACY_SUPPORT_REALPATH_WRAP__ && \
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- __MP_LEGACY_SUPPORT_REALPATH_WRAP__)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> /* setattrlistat */
#define __MP_LEGACY_SUPPORT_FSETATTRLIST__ (__APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1060)
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -124,11 +119,6 @@
</span> /* sysconf() is missing some functions on some systems */
#define __MP_LEGACY_SUPPORT_SYSCONF_WRAP__ (__APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101100)
<span style='display:block; white-space:pre;background:#ffe0e0;'>-/* sysconf() wrap has bail-out macros in case we want to disable only function wrapping */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#define __ENABLE_MP_LEGACY_SUPPORT_SYSCONF_WRAP__ (!__DISABLE_MP_LEGACY_SUPPORT_FUNCTION_WRAPPING__ && \
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- !__DISABLE_MP_LEGACY_SUPPORT_SYSCONF_WRAP__ && \
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- __MP_LEGACY_SUPPORT_SYSCONF_WRAP__)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> /* pthread_rwlock_initializer is not defined on Tiger */
#define __MP_LEGACY_SUPPORT_PTHREAD_RWLOCK__ (__APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/include/stdlib.h b/include/stdlib.h
</span><span style='display:block; white-space:pre;color:#808080;'>index 34688ce..b3b8f43 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/include/stdlib.h
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/include/stdlib.h
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -21,31 +21,9 @@
</span> /* MP support header */
#include "MacportsLegacySupport.h"
<span style='display:block; white-space:pre;background:#ffe0e0;'>-/* realpath wrap */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#if __ENABLE_MP_LEGACY_SUPPORT_REALPATH_WRAP__
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-/* we are going to move the old realpath definition out of the way */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#undef realpath
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#define realpath(a,b) realpath_macports_original(a,b)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#endif /*__ENABLE_MP_LEGACY_SUPPORT_REALPATH_WRAP__*/
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> /* Include the primary system stdlib.h */
#include_next <stdlib.h>
<span style='display:block; white-space:pre;background:#ffe0e0;'>-/* realpath wrap */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#if __ENABLE_MP_LEGACY_SUPPORT_REALPATH_WRAP__
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-/* and now define realpath as our new wrapped function */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#undef realpath
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-__MP__BEGIN_DECLS
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-extern char *realpath(const char * __restrict, char * __restrict)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-__MP_LEGACY_WRAPPER_ALIAS(realpath);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-__MP__END_DECLS
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#endif /*__ENABLE_MP_LEGACY_SUPPORT_REALPATH_WRAP__*/
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> /* posix_memalign */
#if __MP_LEGACY_SUPPORT_POSIX_MEMALIGN__
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/include/unistd.h b/include/unistd.h
</span><span style='display:block; white-space:pre;color:#808080;'>index c5db705..c5a1f6b 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/include/unistd.h
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/include/unistd.h
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -80,29 +80,8 @@
</span> /* MP support header */
#include "MacportsLegacySupport.h"
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#if __ENABLE_MP_LEGACY_SUPPORT_SYSCONF_WRAP__
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-/* redefine the original sysconf */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#undef sysconf
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#define sysconf(a) sysconf_orig(a)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#endif /*__ENABLE_MP_LEGACY_SUPPORT_SYSCONF_WRAP__*/
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> #include_next <unistd.h>
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#if __ENABLE_MP_LEGACY_SUPPORT_SYSCONF_WRAP__
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-/* and now define sysconf as our new wrapped function */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#undef sysconf
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#include "MacportsLegacyWrappers/sysconf_support.h"
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-__MP__BEGIN_DECLS
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-extern long sysconf(int) __MP_LEGACY_WRAPPER_ALIAS(sysconf);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-__MP__END_DECLS
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#endif /* __ENABLE_MP_LEGACY_SUPPORT_SYSCONF_WRAP__ */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> #if __MP_LEGACY_SUPPORT_FSETATTRLIST__
#ifdef __LP64__
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/macports_legacy_realpath.c b/src/macports_legacy_realpath.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 842791c..1309b02 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/macports_legacy_realpath.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/macports_legacy_realpath.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -20,25 +20,35 @@
</span> /* realpath wrap */
#if __MP_LEGACY_SUPPORT_REALPATH_WRAP__
<span style='display:block; white-space:pre;background:#ffe0e0;'>-/* we need this blocker so as to not get caught in our own wrap */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#undef __DISABLE_MP_LEGACY_SUPPORT_REALPATH_WRAP__
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#define __DISABLE_MP_LEGACY_SUPPORT_REALPATH_WRAP__ 1
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> #include <limits.h>
#include <stdlib.h>
<span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <dlfcn.h>
</span>
<span style='display:block; white-space:pre;background:#ffe0e0;'>-char *
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-__MP_LEGACY_WRAPPER(realpath)(const char * __restrict stringsearch, char * __restrict buffer)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+char *realpath(const char __restrict *stringsearch, char __restrict *buffer)
</span> {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ char *(*real_realpath)(const char __restrict *, char __restrict *);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#if (__DARWIN_UNIX03 && !defined(_POSIX_C_SOURCE)) || defined(_DARWIN_C_SOURCE) || defined(_DARWIN_BETTER_REALPATH)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ real_realpath = dlsym(RTLD_NEXT, "realpath$DARWIN_EXTSN");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# else
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ real_realpath = dlsym(RTLD_NEXT, "realpath");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#endif
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (real_realpath == NULL) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ exit(EXIT_FAILURE);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> if (buffer == NULL) {
char *myrealpathbuf = malloc(PATH_MAX);
if (myrealpathbuf != NULL) {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- return(realpath(stringsearch, myrealpathbuf));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return(real_realpath(stringsearch, myrealpathbuf));
</span> } else {
return(NULL);
}
} else {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- return(realpath(stringsearch, buffer));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return(real_realpath(stringsearch, buffer));
</span> }
}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* compatibility function so code does not have to be recompiled */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+char *macports_legacy_realpath(const char __restrict *stringsearch, char __restrict *buffer) { return realpath(stringsearch, buffer); }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> #endif /*__MP_LEGACY_SUPPORT_REALPATH_WRAP__*/
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/macports_legacy_sysconf.c b/src/macports_legacy_sysconf.c
</span><span style='display:block; white-space:pre;color:#808080;'>index aecaf47..6e97f95 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/macports_legacy_sysconf.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/macports_legacy_sysconf.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -20,21 +20,19 @@
</span> /* sysconf wrap, 10.4 */
#if __MP_LEGACY_SUPPORT_SYSCONF_WRAP__
<span style='display:block; white-space:pre;background:#ffe0e0;'>-/* we need this blocker so as to not get caught in our own wrap */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#undef __DISABLE_MP_LEGACY_SUPPORT_SYSCONF_WRAP__
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-#define __DISABLE_MP_LEGACY_SUPPORT_SYSCONF_WRAP__ 1
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> #include <sys/types.h>
#include <sys/sysctl.h>
#include <unistd.h>
<span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <dlfcn.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <stdlib.h>
</span>
/* emulate several commonly used but missing selectors from sysconf() on various OS versions */
#include <MacportsLegacyWrappers/sysconf_support.h>
<span style='display:block; white-space:pre;background:#ffe0e0;'>-long __MP_LEGACY_WRAPPER(sysconf)(int name){
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+long sysconf(int name) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ long (*real_sysconf)(int);
</span>
#if __MP_LEGACY_SUPPORT_SYSCONF_WRAP_NEED_SC_NPROCESSORS_ONLN__
if ( name == _SC_NPROCESSORS_ONLN ) {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -89,8 +87,14 @@ long __MP_LEGACY_WRAPPER(sysconf)(int name){
</span> #endif
/* for any other values of "name", call the real sysconf() */
<span style='display:block; white-space:pre;background:#ffe0e0;'>- return (long)sysconf(name);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ real_sysconf = dlsym(RTLD_NEXT, "sysconf");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (real_sysconf == NULL) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ exit(EXIT_FAILURE);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return real_sysconf(name);
</span> }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+/* compatibility function so code does not have to be recompiled */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+long macports_legacy_sysconf(int name) { return sysconf(name); }
</span>
#endif /*__MP_LEGACY_SUPPORT_SYSCONF_WRAP__*/
</pre><pre style='margin:0'>
</pre>