MSYS2-packages/libargp/libargp-global-variables.patch
Christoph Reiter 873547124d libargp: Update to 20241207
* Sync with cygwin
* Move to a newer version as cygwin as that one fails with out autotools
  (it tries to patch generated files which are now different)
2024-12-07 20:53:18 +01:00

95 lines
3.4 KiB
Diff
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

diff -urN a/argp/gllib/argp.h b/argp/gllib/argp.h
--- a/argp/gllib/argp.h 2023-07-10 05:48:44.000000000 -0400
+++ b/argp/gllib/argp.h 2023-07-11 11:12:52.065260500 -0400
@@ -58,6 +58,18 @@
typedef int error_t;
# define __error_t_defined
#endif
+
+#ifndef DLL_EXPORT
+#ifdef __CYGWIN__
+#define __dllexport __declspec(dllexport)
+#endif
+#ifdef _WIN32
+#define __dllexport __declspec(dllexport)
+#endif
+#endif
+#ifndef __dllexport
+#define __dllexport
+#endif
#ifdef __cplusplus
extern "C" {
@@ -437,14 +449,14 @@
option --version is added (unless the ARGP_NO_HELP flag is used), which
will print this string followed by a newline and exit (unless the
ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */
-extern const char *argp_program_version;
+__dllexport extern const char *argp_program_version;
/* If defined or set by the user program to a non-zero value, then a default
option --version is added (unless the ARGP_NO_HELP flag is used), which
calls this function with a stream to print the version to and a pointer to
the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
used). This variable takes precedent over ARGP_PROGRAM_VERSION. */
-extern void (*argp_program_version_hook) (FILE *__restrict __stream,
+__dllexport extern void (*argp_program_version_hook) (FILE *__restrict __stream,
struct argp_state *__restrict
__state);
@@ -453,12 +465,12 @@
argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various
standard help messages), embedded in a sentence that says something like
"Report bugs to ADDR." */
-extern const char *argp_program_bug_address;
+__dllexport extern const char *argp_program_bug_address;
/* The exit status that argp will use when exiting due to a parsing error.
If not defined or set by the user program, this defaults to EX_USAGE from
<sysexits.h>. */
-extern error_t argp_err_exit_status;
+__dllexport extern error_t argp_err_exit_status;
/* Flags for argp_help. */
#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */
diff -urN a/argp/gllib/argp-parse.c b/argp/gllib/argp-parse.c
--- a/argp/gllib/argp-parse.c 2023-07-10 05:48:44.000000000 -0400
+++ b/argp/gllib/argp-parse.c 2023-07-11 12:16:25.342240900 -0400
@@ -63,6 +63,36 @@
/* EZ alias for ARGP_ERR_UNKNOWN. */
#define EBADKEY ARGP_ERR_UNKNOWN
+/* Windows does not support things like weak symbols, neither will it merge two
+ external symbols. So to make our global variables work, we have to perform
+ the following trick: we look up the respective variables in the main .exe
+ file, and patch our versions with correct pointers.
+ Note that this fix relies on the variables being declared with
+ __declspec(dllexport). */
+#ifdef DLL_EXPORT
+
+#include <windows.h>
+
+#define PatchPtr(var) \
+ p = (void **)GetProcAddress(NULL, #var); \
+ if (p) var = *p;
+
+#define PatchInt(var) \
+ i = (int *)GetProcAddress(NULL, #var); \
+ if (i) var = *i;
+
+static void __attribute__((constructor)) patch_vars(void)
+{
+ void **p;
+ int *i;
+
+ PatchPtr(argp_program_version);
+ PatchPtr(argp_program_version_hook);
+ PatchPtr(argp_program_bug_address);
+ PatchInt(argp_err_exit_status);
+}
+#endif
+
/* Default options. */
/* When argp is given the --HANG switch, _ARGP_HANG is set and argp will sleep