LLM inference in C/C++
C++ ggml
vendor: sync subprocess.h and drop local patches (#26808)
Pascal4c6766fd7e4b
diff --git a/scripts/sync_vendor.py b/scripts/sync_vendor.pyindex b8330c5753..4fcfd5267f 100755--- a/scripts/sync_vendor.py+++ b/scripts/sync_vendor.py@@ -21,34 +21,13 @@ vendor = {f"https://raw.githubusercontent.com/yhirose/cpp-httplib/{HTTPLIB_VERSION}/split.py": "split.py",f"https://raw.githubusercontent.com/yhirose/cpp-httplib/{HTTPLIB_VERSION}/LICENSE": "vendor/cpp-httplib/LICENSE",- "https://raw.githubusercontent.com/sheredom/subprocess.h/8671cee1fc09f11a70ce3782a0ee13177c3aa387/subprocess.h": "vendor/sheredom/subprocess.h",+ "https://raw.githubusercontent.com/sheredom/subprocess.h/9ce0d701b6fb10f8f8c4445edd31e7c60a1237e3/subprocess.h": "vendor/sheredom/subprocess.h",}-# TODO @ngxson : this is temporary, to be removed in the future-patches = [- # https://github.com/sheredom/subprocess.h/pull/102- "vendor/sheredom/patch-bsd.patch",- # https://github.com/sheredom/subprocess.h/pull/101- "vendor/sheredom/patch-windows-quote-backslash.patch",- # https://github.com/sheredom/subprocess.h/pull/104- # note: must be applied after patch-bsd.patch, they touch adjacent lines- "vendor/sheredom/patch-glibc-older-than-2.29.patch",-]-for url, filename in vendor.items():print(f"downloading {url} to {filename}") # noqa: NP100urllib.request.urlretrieve(url, filename)-for patch in patches:- print(f"applying {patch}") # noqa: NP100- try:- subprocess.check_call([- "git", "apply", "--directory", os.path.dirname(patch), patch- ])- except Exception as e:- print(f"Error: {e}") # noqa: NP100- sys.exit(1)-print("Splitting httplib.h...") # noqa: NP100try:subprocess.check_call([diff --git a/vendor/sheredom/patch-bsd.patch b/vendor/sheredom/patch-bsd.patchdeleted file mode 100644index 2532050e20..0000000000--- a/vendor/sheredom/patch-bsd.patch+++ /dev/null@@ -1,19 +0,0 @@-Fix build on NetBSD, which provides posix_spawn_file_actions_addchdir()-but not the _np() variant.--Upstream PR: https://github.com/sheredom/subprocess.h/pull/102-Applied locally by scripts/sync_vendor.py until it is merged upstream.--diff --git a/subprocess.h b/subprocess.h-index 5e809023a4..74a4e006c7 100644---- a/subprocess.h-+++ b/subprocess.h-@@ -1205,7 +1205,7 @@ cleanup:-- // Set working directory- if (process_cwd) {--#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 260000-+#if defined(__NetBSD__) || (defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 260000)- posix_error = posix_spawn_file_actions_addchdir(&actions, process_cwd);- #else- #if defined(__APPLE__) && defined(__clang__)diff --git a/vendor/sheredom/patch-glibc-older-than-2.29.patch b/vendor/sheredom/patch-glibc-older-than-2.29.patchdeleted file mode 100644index 9144213096..0000000000--- a/vendor/sheredom/patch-glibc-older-than-2.29.patch+++ /dev/null@@ -1,47 +0,0 @@-Fix building against glibc older than 2.29, which has no-posix_spawn_file_actions_addchdir_np (the symbol is genuinely absent from-libc.so, so no feature-test macro helps). Affects manylinux2014 (glibc 2.17)-and manylinux_2_28, and was reported on RHEL 8.1. A requested process_cwd now-fails with ENOSYS there instead of failing the build.--Upstream PR: https://github.com/sheredom/subprocess.h/pull/104-Applied locally by scripts/sync_vendor.py until it is merged upstream.--(the README.md and test/ changes from the PR are omitted, we only vendor-subprocess.h; rebased on top of patch-bsd.patch, so apply it after that one)--diff --git a/subprocess.h b/subprocess.h-index 1ef424a..c363393 100644---- a/subprocess.h-+++ b/subprocess.h-@@ -274,6 +274,21 @@ subprocess_weak int subprocess_alive(struct subprocess_s *const process);- #include <unistd.h>- #endif--+/* Whether subprocess_create_ex can honour process_cwd. glibc only gained-+ posix_spawn_file_actions_addchdir_np in 2.29. Define this yourself to-+ override the detection, for instance on musl older than 1.1.24. */-+#if !defined(SUBPROCESS_HAVE_CWD)-+#if defined(__GLIBC__)-+#if __GLIBC_PREREQ(2, 29)-+#define SUBPROCESS_HAVE_CWD 1-+#else-+#define SUBPROCESS_HAVE_CWD 0-+#endif-+#else-+#define SUBPROCESS_HAVE_CWD 1-+#endif-+#endif-+- #if defined(_WIN32)-- #include <wchar.h>-@@ -1219,6 +1234,8 @@ cleanup:- if (process_cwd) {- #if defined(__NetBSD__) || (defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 260000)- posix_error = posix_spawn_file_actions_addchdir(&actions, process_cwd);-+#elif !SUBPROCESS_HAVE_CWD-+ posix_error = ENOSYS;- #else- #if defined(__APPLE__) && defined(__clang__)- #pragma clang diagnostic pushdiff --git a/vendor/sheredom/patch-windows-quote-backslash.patch b/vendor/sheredom/patch-windows-quote-backslash.patchdeleted file mode 100644index 0204746d96..0000000000--- a/vendor/sheredom/patch-windows-quote-backslash.patch+++ /dev/null@@ -1,107 +0,0 @@-Fix Windows command line quoting of backslash runs: a trailing backslash, or-backslashes preceding a double quote, were not doubled, so CommandLineToArgvW-in the child parsed them as escapes and mangled the argument list.--Upstream PR: https://github.com/sheredom/subprocess.h/pull/101-Applied locally by scripts/sync_vendor.py until it is merged upstream.--(the test/ changes from the PR are omitted, we only vendor subprocess.h)--diff --git a/subprocess.h b/subprocess.h-index 5e80902..b06ad4d 100644---- a/subprocess.h-+++ b/subprocess.h-@@ -653,6 +653,7 @@ int subprocess_create_ex(const char *const commandLine[], int options,- int wide_len;- int i, j;- int need_quoting;-+ subprocess_size_t bs_run;- unsigned long flags = 0;- unsigned long last_error = 0;- int result = subprocess_error_unknown;-@@ -906,25 +907,29 @@ int subprocess_create_ex(const char *const commandLine[], int options,- len++;-- // Quote the argument if it has a space in it-- if (strpbrk(commandLine[i], "\t\v ") != SUBPROCESS_NULL ||-- commandLine[i][0] == SUBPROCESS_NULL)-+ need_quoting = strpbrk(commandLine[i], "\t\v ") != SUBPROCESS_NULL ||-+ commandLine[i][0] == SUBPROCESS_NULL;-+ if (need_quoting)- len += 2;--+ bs_run = 0;- for (j = 0; '\0' != commandLine[i][j]; j++) {-- switch (commandLine[i][j]) {-- default:-- break;-- case '\\':-- if (commandLine[i][j + 1] == '"') {-- len++;-- }-+ len++;--- break;-- case '"':-- len++;-- break;-+ if ('\\' == commandLine[i][j]) {-+ bs_run++;-+ } else {-+ if ('"' == commandLine[i][j]) {-+ // Duplicate the preceding run and escape the quote.-+ len += bs_run + 1;-+ }-+ bs_run = 0;- }-- len++;-+ }-+-+ if (need_quoting) {-+ // Duplicate trailing slashes before the generated closing quote.-+ len += bs_run;- }- }--@@ -949,22 +954,29 @@ int subprocess_create_ex(const char *const commandLine[], int options,- commandLineCombined[len++] = '"';- }--- for (j = 0; '\0' != commandLine[i][j]; j++) {-- switch (commandLine[i][j]) {-- default:-- break;-- case '\\':-- if (commandLine[i][j + 1] == '"') {-- commandLineCombined[len++] = '\\';-- }-+ for (j = 0; '\0' != commandLine[i][j];) {-+ bs_run = 0;-+ while ('\\' == commandLine[i][j]) {-+ bs_run++;-+ j++;-+ }-+-+ if ('"' == commandLine[i][j]) {-+ // 2n + 1 slashes preserve n slashes and escape the quote.-+ bs_run = (bs_run * 2) + 1;-+ } else if ('\0' == commandLine[i][j] && need_quoting) {-+ // 2n slashes preserve n slashes before the closing quote.-+ bs_run *= 2;-+ }--- break;-- case '"':-+ while (bs_run > 0) {- commandLineCombined[len++] = '\\';-- break;-+ bs_run--;- }--- commandLineCombined[len++] = commandLine[i][j];-+ if ('\0' != commandLine[i][j]) {-+ commandLineCombined[len++] = commandLine[i][j++];-+ }- }- if (need_quoting) {- commandLineCombined[len++] = '"';diff --git a/vendor/sheredom/subprocess.h b/vendor/sheredom/subprocess.hindex c363393873..c3af8a4980 100644--- a/vendor/sheredom/subprocess.h+++ b/vendor/sheredom/subprocess.h@@ -107,7 +107,8 @@ enum subprocess_error_e {subprocess_error_permission_denied = -5,subprocess_error_no_memory = -6,subprocess_error_pipe = -7,- subprocess_error_spawn = -8+ subprocess_error_spawn = -8,+ subprocess_error_not_supported = -9};#if defined(__cplusplus)@@ -275,8 +276,10 @@ subprocess_weak int subprocess_alive(struct subprocess_s *const process);#endif/* Whether subprocess_create_ex can honour process_cwd. glibc only gained- posix_spawn_file_actions_addchdir_np in 2.29. Define this yourself to- override the detection, for instance on musl older than 1.1.24. */+ posix_spawn_file_actions_addchdir_np in 2.29, and macOS in 10.15; the SDKs+ mark it unavailable on iOS, tvOS and watchOS, where the undefined version+ macro folds to 0 and so answers correctly. Define this yourself to override+ the detection, for instance on musl older than 1.1.24. */#if !defined(SUBPROCESS_HAVE_CWD)#if defined(__GLIBC__)#if __GLIBC_PREREQ(2, 29)@@ -284,11 +287,27 @@ subprocess_weak int subprocess_alive(struct subprocess_s *const process);#else#define SUBPROCESS_HAVE_CWD 0#endif+#elif defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < 101500+#define SUBPROCESS_HAVE_CWD 0#else#define SUBPROCESS_HAVE_CWD 1#endif#endif+/* Whether posix_spawn reports a failed exec back to the caller. glibc only+ started doing so in 2.24; before that the child silently exits with 127. */+#if !defined(SUBPROCESS_SPAWN_REPORTS_EXEC_ERRORS)+#if defined(__GLIBC__)+#if __GLIBC_PREREQ(2, 24)+#define SUBPROCESS_SPAWN_REPORTS_EXEC_ERRORS 1+#else+#define SUBPROCESS_SPAWN_REPORTS_EXEC_ERRORS 0+#endif+#else+#define SUBPROCESS_SPAWN_REPORTS_EXEC_ERRORS 1+#endif+#endif+#if defined(_WIN32)#include <wchar.h>@@ -554,6 +573,8 @@ int subprocess_error_from_errno(int error) {case ENFILE:case ENOMEM:return subprocess_error_no_memory;+ case ENOSYS:+ return subprocess_error_not_supported;default:return subprocess_error_unknown;}@@ -1358,6 +1379,17 @@ cleanup:goto cleanup;}} else {+#if !SUBPROCESS_SPAWN_REPORTS_EXEC_ERRORS+ /* posix_spawn cannot tell us the exec failed, so check up front */+ if (0 != access(commandLine[0], X_OK)) {+ saved_errno = errno;+ result = subprocess_error_from_errno(saved_errno);+ if (subprocess_error_unknown == result) {+ result = subprocess_error_spawn;+ }+ goto cleanup;+ }+#endifposix_error = posix_spawn(&child, commandLine[0], &actions,SUBPROCESS_NULL,SUBPROCESS_CONST_CAST(char *const *, commandLine),