From a1d9905351fe86135bb7c872ca5d8c08c568d434 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Fri, 23 Aug 2024 23:55:58 +0200 Subject: [PATCH 01/11] Refactor part of glob.c as only ever used with Windows --- win32/glob.c | 149 ++++++++++++++++++++++----------------------------- win32/glob.h | 20 +++---- 2 files changed, 70 insertions(+), 99 deletions(-) diff --git a/win32/glob.c b/win32/glob.c index 5dd0f4661acbe..2ce62b5702381 100644 --- a/win32/glob.c +++ b/win32/glob.c @@ -58,34 +58,23 @@ * gl_matchc: * Number of matches in the current invocation of glob. */ -#ifdef PHP_WIN32 -#if _MSC_VER < 1800 -# define _POSIX_ -# include -# undef _POSIX_ -#else + /* Visual Studio 2013 removed all the _POSIX_ defines, but we depend on some */ -# ifndef ARG_MAX -# define ARG_MAX 14500 -# endif -#endif +#ifndef ARG_MAX +# define ARG_MAX 14500 #endif -#include "php.h" +#include "glob.h" +#include +#include #include #include -#ifndef PHP_WIN32 -#include -#include -#include -#include -#endif #include -#include "glob.h" #include #include #include +#include "php.h" #define DOLLAR '$' #define DOT '.' @@ -96,7 +85,8 @@ #define QUOTE '\\' #define RANGE '-' #define RBRACKET ']' -#define SEP DEFAULT_SLASH +/* As this is Windows we use a backslash for the separator */ +#define SEP '\\' #define STAR '*' #define TILDE '~' #define UNDERSCORE '_' @@ -137,11 +127,11 @@ typedef char Char; #define ismeta(c) (((c)&M_QUOTE) != 0) static int compare(const void *, const void *); -static int g_Ctoc(const Char *, char *, u_int); -static int g_lstat(Char *, zend_stat_t *, glob_t *); +static bool g_Ctoc(const Char *, char *, u_int); +static int g_lstat(Char *, php_win32_ioutil_stat_t *, glob_t *); static DIR *g_opendir(Char *, glob_t *); static Char *g_strchr(Char *, int); -static int g_stat(Char *, zend_stat_t *, glob_t *); +static int g_stat(Char *, php_win32_ioutil_stat_t *, glob_t *); static int glob0(const Char *, glob_t *); static int glob1(Char *, Char *, glob_t *, size_t *); static int glob2(Char *, Char *, Char *, Char *, Char *, Char *, @@ -152,7 +142,7 @@ static int globextend(const Char *, glob_t *, size_t *); static const Char *globtilde(const Char *, Char *, size_t, glob_t *); static int globexp1(const Char *, glob_t *); static int globexp2(const Char *, const Char *, glob_t *, int *); -static int match(Char *, Char *, Char *); +static bool match(Char *, Char *, Char *); #ifdef DEBUG static void qprintf(const char *, Char *); #endif @@ -341,9 +331,6 @@ static int globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv */ static const Char *globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob) { -#ifndef PHP_WIN32 - struct passwd *pwd; -#endif char *h; const Char *p; Char *b, *eb; @@ -359,38 +346,19 @@ static const Char *globtilde(const Char *pattern, Char *patbuf, size_t patbuf_le *h = EOS; -#if 0 - if (h == (char *)eb) - return what; -#endif - if (((char *) patbuf)[0] == EOS) { /* * handle a plain ~ or ~/ by expanding $HOME * first and then trying the password file */ if ((h = getenv("HOME")) == NULL) { -#ifndef PHP_WIN32 - if ((pwd = getpwuid(getuid())) == NULL) - return pattern; - else - h = pwd->pw_dir; -#else return pattern; -#endif } } else { /* * Expand a ~user */ -#ifndef PHP_WIN32 - if ((pwd = getpwnam((char*) patbuf)) == NULL) - return pattern; - else - h = pwd->pw_dir; -#else return pattern; -#endif } /* Copy the home directory */ @@ -504,11 +472,7 @@ static int compare(const void *p, const void *q) return(strcmp(*(char **)p, *(char **)q)); } -static int -glob1(pattern, pattern_last, pglob, limitp) - Char *pattern, *pattern_last; - glob_t *pglob; - size_t *limitp; +static int glob1(Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp) { Char pathbuf[MAXPATHLEN]; @@ -520,6 +484,11 @@ glob1(pattern, pattern_last, pglob, limitp) pattern, pattern_last, pglob, limitp)); } +static inline bool glob_is_slash(Char c) +{ + return c == '/' || c == '\\'; +} + /* * The functions glob2 and glob3 are mutually recursive; there is one level * of recursion for each segment in the pattern that contains one or more @@ -528,7 +497,7 @@ glob1(pattern, pattern_last, pglob, limitp) static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp) { - zend_stat_t sb = {0}; + php_win32_ioutil_stat_t sb = {0}; Char *p, *q; int anymeta; @@ -543,7 +512,7 @@ static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend return(0); if (((pglob->gl_flags & GLOB_MARK) && - !IS_SLASH(pathend[-1])) && (S_ISDIR(sb.st_mode) || + !glob_is_slash(pathend[-1])) && (S_ISDIR(sb.st_mode) || (S_ISLNK(sb.st_mode) && (g_stat(pathbuf, &sb, pglob) == 0) && S_ISDIR(sb.st_mode)))) { @@ -559,7 +528,7 @@ static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend /* Find end of next segment, copy tentatively to pathend. */ q = pathend; p = pattern; - while (*p != EOS && !IS_SLASH(*p)) { + while (*p != EOS && !glob_is_slash(*p)) { if (ismeta(*p)) anymeta = 1; if (q+1 > pathend_last) @@ -570,7 +539,7 @@ static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend if (!anymeta) { /* No expansion, do next segment. */ pathend = q; pattern = p; - while (IS_SLASH(*pattern)) { + while (glob_is_slash(*pattern)) { if (pathend+1 > pathend_last) return (1); *pathend++ = *pattern++; @@ -727,50 +696,58 @@ static int globextend(const Char *path, glob_t *pglob, size_t *limitp) * pattern matching function for filenames. Each occurrence of the * * pattern causes a recursion level. */ -static int match(Char *name, Char *pat, Char *patend) +static bool match(Char *name, Char *pat, Char *patend) { - int ok, negate_range; + bool ok, negate_range; Char c, k; while (pat < patend) { c = *pat++; switch (c & M_MASK) { case M_ALL: - if (pat == patend) - return(1); - do - if (match(name, pat, patend)) - return(1); - while (*name++ != EOS) - ; - return(0); + if (pat == patend) { + return true; + } + do { + if (match(name, pat, patend)) { + return true; + } + } while (*name++ != EOS); + return false; case M_ONE: - if (*name++ == EOS) - return(0); + if (*name++ == EOS) { + return false; + } break; case M_SET: - ok = 0; - if ((k = *name++) == EOS) - return(0); - if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) + ok = false; + if ((k = *name++) == EOS) { + return false; + } + if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) { ++pat; + } while (((c = *pat++) & M_MASK) != M_END) if ((*pat & M_MASK) == M_RNG) { - if (c <= k && k <= pat[1]) - ok = 1; + if (c <= k && k <= pat[1]) { + ok = true; + } pat += 2; - } else if (c == k) - ok = 1; - if (ok == negate_range) - return(0); + } else if (c == k) { + ok = true; + } + if (ok == negate_range) { + return false; + } break; default: - if (*name++ != c) - return(0); + if (*name++ != c) { + return false; + } break; } } - return(*name == EOS); + return *name == EOS; } /* Free allocated data belonging to a glob_t structure. */ @@ -806,7 +783,7 @@ static DIR * g_opendir(Char *str, glob_t *pglob) return(opendir(buf)); } -static int g_lstat(Char *fn, zend_stat_t *sb, glob_t *pglob) +static int g_lstat(Char *fn, php_win32_ioutil_stat_t *sb, glob_t *pglob) { char buf[MAXPATHLEN]; @@ -814,10 +791,10 @@ static int g_lstat(Char *fn, zend_stat_t *sb, glob_t *pglob) return(-1); if (pglob->gl_flags & GLOB_ALTDIRFUNC) return((*pglob->gl_lstat)(buf, sb)); - return(php_sys_lstat(buf, sb)); + return(php_win32_ioutil_lstat(buf, sb)); } -static int g_stat(Char *fn, zend_stat_t *sb, glob_t *pglob) +static int g_stat(Char *fn, php_win32_ioutil_stat_t *sb, glob_t *pglob) { char buf[MAXPATHLEN]; @@ -825,7 +802,7 @@ static int g_stat(Char *fn, zend_stat_t *sb, glob_t *pglob) return(-1); if (pglob->gl_flags & GLOB_ALTDIRFUNC) return((*pglob->gl_stat)(buf, sb)); - return(php_sys_stat(buf, sb)); + return(php_win32_ioutil_stat(buf, sb)); } static Char *g_strchr(Char *str, int ch) @@ -837,14 +814,14 @@ static Char *g_strchr(Char *str, int ch) return (NULL); } -static int g_Ctoc(const Char *str, char *buf, u_int len) +static bool g_Ctoc(const Char *str, char *buf, u_int len) { while (len--) { if ((*buf++ = (char) *str++) == EOS) - return (0); + return false; } - return (1); + return true; } #ifdef DEBUG diff --git a/win32/glob.h b/win32/glob.h index 42cf2f9d71dda..02d5a4b64be35 100644 --- a/win32/glob.h +++ b/win32/glob.h @@ -42,16 +42,13 @@ #ifndef _GLOB_H_ #define _GLOB_H_ -#ifndef PHP_WIN32 -# include -#endif - -#include "Zend/zend_stream.h" +#include +#include "ioutil.h" typedef struct { - int gl_pathc; /* Count of total paths so far. */ - int gl_matchc; /* Count of paths matching pattern. */ - int gl_offs; /* Reserved at beginning of gl_pathv. */ + size_t gl_pathc; /* Count of total paths so far. */ + unsigned int gl_matchc; /* Count of paths matching pattern. */ + size_t gl_offs; /* Reserved at beginning of gl_pathv. */ int gl_flags; /* Copy of flags parameter to glob. */ char **gl_pathv; /* List of paths matching pattern. */ /* Copy of errfunc parameter to glob. */ @@ -65,8 +62,8 @@ typedef struct { void (*gl_closedir)(void *); struct dirent *(*gl_readdir)(void *); void *(*gl_opendir)(const char *); - int (*gl_lstat)(const char *, zend_stat_t *); - int (*gl_stat)(const char *, zend_stat_t *); + int (*gl_lstat)(const char *, php_win32_ioutil_stat_t *); + int (*gl_stat)(const char *, php_win32_ioutil_stat_t *); } glob_t; /* Flags */ @@ -76,8 +73,6 @@ typedef struct { #define GLOB_MARK 0x0008 /* Append / to matching directories. */ #define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ #define GLOB_NOSORT 0x0020 /* Don't sort. */ - -#ifndef _POSIX_SOURCE #define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ #define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ @@ -86,7 +81,6 @@ typedef struct { #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ #define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ #define GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ -#endif /* Error values returned by glob(3) */ #define GLOB_NOSPACE (-1) /* Malloc call failed. */ From 6d4e6b3c3b05f144ca59890305ab9b18a9579c99 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Sat, 24 Aug 2024 00:02:06 +0200 Subject: [PATCH 02/11] glob.c: Remove alternative dir functions as unused --- win32/glob.c | 28 ++-------------------------- win32/glob.h | 12 ------------ 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/win32/glob.c b/win32/glob.c index 2ce62b5702381..b81620bc1222f 100644 --- a/win32/glob.c +++ b/win32/glob.c @@ -49,8 +49,6 @@ * GLOB_NOMAGIC: * Same as GLOB_NOCHECK, but it will only append pattern if it did * not contain any magic characters. [Used in csh style globbing] - * GLOB_ALTDIRFUNC: - * Use alternately specified directory access functions. * GLOB_TILDE: * expand ~user/foo to the /home/dir/of/user/foo * GLOB_BRACE: @@ -560,14 +558,6 @@ static int glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend DIR *dirp; int err; - /* - * The readdirfunc declaration can't be prototyped, because it is - * assigned, below, to two functions which are prototyped in glob.h - * and dirent.h as taking pointers to differently typed opaque - * structures. - */ - struct dirent *(*readdirfunc)(); - if (pathend > pathend_last) return (1); *pathend = EOS; @@ -589,11 +579,7 @@ static int glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend err = 0; /* Search directory for matching names. */ - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - readdirfunc = pglob->gl_readdir; - else - readdirfunc = readdir; - while ((dp = (*readdirfunc)(dirp))) { + while ((dp = readdir(dirp))) { register uint8_t *sc; register Char *dc; @@ -620,10 +606,7 @@ static int glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend break; } - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - (*pglob->gl_closedir)(dirp); - else - closedir(dirp); + closedir(dirp); return(err); } @@ -777,9 +760,6 @@ static DIR * g_opendir(Char *str, glob_t *pglob) return(NULL); } - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_opendir)(buf)); - return(opendir(buf)); } @@ -789,8 +769,6 @@ static int g_lstat(Char *fn, php_win32_ioutil_stat_t *sb, glob_t *pglob) if (g_Ctoc(fn, buf, sizeof(buf))) return(-1); - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_lstat)(buf, sb)); return(php_win32_ioutil_lstat(buf, sb)); } @@ -800,8 +778,6 @@ static int g_stat(Char *fn, php_win32_ioutil_stat_t *sb, glob_t *pglob) if (g_Ctoc(fn, buf, sizeof(buf))) return(-1); - if (pglob->gl_flags & GLOB_ALTDIRFUNC) - return((*pglob->gl_stat)(buf, sb)); return(php_win32_ioutil_stat(buf, sb)); } diff --git a/win32/glob.h b/win32/glob.h index 02d5a4b64be35..6ff703dbe6694 100644 --- a/win32/glob.h +++ b/win32/glob.h @@ -53,17 +53,6 @@ typedef struct { char **gl_pathv; /* List of paths matching pattern. */ /* Copy of errfunc parameter to glob. */ int (*gl_errfunc)(const char *, int); - - /* - * Alternate filesystem access methods for glob; replacement - * versions of closedir(3), readdir(3), opendir(3), stat(2) - * and lstat(2). - */ - void (*gl_closedir)(void *); - struct dirent *(*gl_readdir)(void *); - void *(*gl_opendir)(const char *); - int (*gl_lstat)(const char *, php_win32_ioutil_stat_t *); - int (*gl_stat)(const char *, php_win32_ioutil_stat_t *); } glob_t; /* Flags */ @@ -73,7 +62,6 @@ typedef struct { #define GLOB_MARK 0x0008 /* Append / to matching directories. */ #define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ #define GLOB_NOSORT 0x0020 /* Don't sort. */ -#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ #define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ #define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ From 095aa27b7250a71fc2532e7a8fdb387f3ae1fd82 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Sat, 24 Aug 2024 00:04:33 +0200 Subject: [PATCH 03/11] glob.c: Remove GLOB_NOSYS as obsolete See: https://pubs.opengroup.org/onlinepubs/9799919799/ --- win32/glob.h | 1 - 1 file changed, 1 deletion(-) diff --git a/win32/glob.h b/win32/glob.h index 6ff703dbe6694..09a4f9fc92756 100644 --- a/win32/glob.h +++ b/win32/glob.h @@ -74,7 +74,6 @@ typedef struct { #define GLOB_NOSPACE (-1) /* Malloc call failed. */ #define GLOB_ABORTED (-2) /* Unignored error. */ #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ -#define GLOB_NOSYS (-4) /* Function not supported. */ #define GLOB_ABEND GLOB_ABORTED BEGIN_EXTERN_C() From 5fd5e547dc9b71559191fc5799afdf85f1587514 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Sat, 24 Aug 2024 00:07:45 +0200 Subject: [PATCH 04/11] Remove unsupported non standard flags --- win32/glob.c | 5 ----- win32/glob.h | 8 ++++---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/win32/glob.c b/win32/glob.c index b81620bc1222f..9bcbda4296be0 100644 --- a/win32/glob.c +++ b/win32/glob.c @@ -41,9 +41,6 @@ * * Optional extra services, controlled by flags not defined by POSIX: * - * GLOB_QUOTE: - * Escaping convention: \ inhibits any special meaning the following - * character might have (except \ at end of string is retained). * GLOB_MAGCHAR: * Set in gl_flags if pattern contained a globbing character. * GLOB_NOMAGIC: @@ -151,12 +148,10 @@ PHPAPI int glob(const char *pattern, int flags, int (*errfunc)(const char *, int int c; Char *bufnext, *bufend, patbuf[MAXPATHLEN]; -#ifdef PHP_WIN32 /* Force skipping escape sequences on windows * due to the ambiguity with path backslashes */ flags |= GLOB_NOESCAPE; -#endif patnext = (uint8_t *) pattern; if (!(flags & GLOB_APPEND)) { diff --git a/win32/glob.h b/win32/glob.h index 09a4f9fc92756..d4db03bcd67b1 100644 --- a/win32/glob.h +++ b/win32/glob.h @@ -55,26 +55,26 @@ typedef struct { int (*gl_errfunc)(const char *, int); } glob_t; -/* Flags */ +/* Standard POSIX Flags */ #define GLOB_APPEND 0x0001 /* Append to output from previous call. */ #define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ #define GLOB_ERR 0x0004 /* Return on error. */ #define GLOB_MARK 0x0008 /* Append / to matching directories. */ #define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ +#define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ #define GLOB_NOSORT 0x0020 /* Don't sort. */ #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ + +/* Implementation defined flags */ #define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ #define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ -#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ -#define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ #define GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ /* Error values returned by glob(3) */ #define GLOB_NOSPACE (-1) /* Malloc call failed. */ #define GLOB_ABORTED (-2) /* Unignored error. */ #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ -#define GLOB_ABEND GLOB_ABORTED BEGIN_EXTERN_C() PHPAPI int glob(const char *, int, int (*)(const char *, int), glob_t *); From 08d7c608ad1c0f2ce065c31747481003c0fa6e81 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Sat, 24 Aug 2024 00:08:21 +0200 Subject: [PATCH 05/11] This header is not used anymore --- win32/glob.h | 1 - 1 file changed, 1 deletion(-) diff --git a/win32/glob.h b/win32/glob.h index d4db03bcd67b1..cc2042b316a2b 100644 --- a/win32/glob.h +++ b/win32/glob.h @@ -43,7 +43,6 @@ #define _GLOB_H_ #include -#include "ioutil.h" typedef struct { size_t gl_pathc; /* Count of total paths so far. */ From c1f3fcc45efd4ac2474d2e4963b1e7ee48c6d1e1 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Sat, 24 Aug 2024 00:16:15 +0200 Subject: [PATCH 06/11] Use PW32IO instead of PHP_API to export symbols --- win32/glob.c | 13 +++++-------- win32/glob.h | 5 +++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/win32/glob.c b/win32/glob.c index 9bcbda4296be0..0bf9d4de9dfae 100644 --- a/win32/glob.c +++ b/win32/glob.c @@ -62,14 +62,11 @@ #include "glob.h" #include #include -#include +#include "ioutil.h" +#include "readdir.h" -#include #include -#include -#include -#include -#include "php.h" +#include /* For strcmp() */ #define DOLLAR '$' #define DOT '.' @@ -142,7 +139,7 @@ static bool match(Char *, Char *, Char *); static void qprintf(const char *, Char *); #endif -PHPAPI int glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) +PW32IO int glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) { const uint8_t *patnext; int c; @@ -729,7 +726,7 @@ static bool match(Char *name, Char *pat, Char *patend) } /* Free allocated data belonging to a glob_t structure. */ -PHPAPI void globfree(glob_t *pglob) +PW32IO void globfree(glob_t *pglob) { register int i; register char **pp; diff --git a/win32/glob.h b/win32/glob.h index cc2042b316a2b..7c78366181c85 100644 --- a/win32/glob.h +++ b/win32/glob.h @@ -43,6 +43,7 @@ #define _GLOB_H_ #include +#include "ioutil.h" typedef struct { size_t gl_pathc; /* Count of total paths so far. */ @@ -76,7 +77,7 @@ typedef struct { #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ BEGIN_EXTERN_C() -PHPAPI int glob(const char *, int, int (*)(const char *, int), glob_t *); -PHPAPI void globfree(glob_t *); +PW32IO int glob(const char *, int, int (*)(const char *, int), glob_t *); +PW32IO void globfree(glob_t *); END_EXTERN_C() #endif /* !_GLOB_H_ */ From f96ce0000c9d1bd299e6512282566401db8e2771 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Sat, 24 Aug 2024 01:53:13 +0200 Subject: [PATCH 07/11] Fix export and remove strlcpy usage --- win32/glob.c | 8 ++++---- win32/glob.h | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/win32/glob.c b/win32/glob.c index 0bf9d4de9dfae..663b308bbb78a 100644 --- a/win32/glob.c +++ b/win32/glob.c @@ -66,7 +66,7 @@ #include "readdir.h" #include -#include /* For strcmp() */ +#include #define DOLLAR '$' #define DOT '.' @@ -139,7 +139,7 @@ static bool match(Char *, Char *, Char *); static void qprintf(const char *, Char *); #endif -PW32IO int glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) +PHP_WIN_GLOB int glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) { const uint8_t *patnext; int c; @@ -726,7 +726,7 @@ static bool match(Char *name, Char *pat, Char *patend) } /* Free allocated data belonging to a glob_t structure. */ -PW32IO void globfree(glob_t *pglob) +PHP_WIN_GLOB void globfree(glob_t *pglob) { register int i; register char **pp; @@ -746,7 +746,7 @@ static DIR * g_opendir(Char *str, glob_t *pglob) char buf[MAXPATHLEN]; if (!*str) - strlcpy(buf, ".", sizeof(buf)); + memcpy(buf, ".", strlen(".")); else { if (g_Ctoc(str, buf, sizeof(buf))) return(NULL); diff --git a/win32/glob.h b/win32/glob.h index 7c78366181c85..f232c45f465e6 100644 --- a/win32/glob.h +++ b/win32/glob.h @@ -42,8 +42,13 @@ #ifndef _GLOB_H_ #define _GLOB_H_ +#ifdef PHP_EXPORTS +# define PHP_WIN_GLOB __declspec(dllexport) +#else +# define PHP_WIN_GLOB __declspec(dllimport) +#endif + #include -#include "ioutil.h" typedef struct { size_t gl_pathc; /* Count of total paths so far. */ @@ -77,7 +82,7 @@ typedef struct { #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ BEGIN_EXTERN_C() -PW32IO int glob(const char *, int, int (*)(const char *, int), glob_t *); -PW32IO void globfree(glob_t *); +PHP_WIN_GLOB int glob(const char *, int, int (*)(const char *, int), glob_t *); +PHP_WIN_GLOB void globfree(glob_t *); END_EXTERN_C() #endif /* !_GLOB_H_ */ From d8df3ae28f2b3d7cc70901e9dca1dfa862202be2 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Sat, 24 Aug 2024 02:30:38 +0200 Subject: [PATCH 08/11] Add header dependencies in winutil header --- TSRM/tsrm_win32.c | 2 +- ext/random/csprng.c | 2 +- win32/winutil.c | 52 ++++++++++++++++++++++----------------------- win32/winutil.h | 17 +++++++++------ 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c index 52fbc95bbd457..3be0ccb5ecd5d 100644 --- a/TSRM/tsrm_win32.c +++ b/TSRM/tsrm_win32.c @@ -617,7 +617,7 @@ TSRM_API int pclose(FILE *stream) /* Returns a number between 0x2000_0000 and 0x3fff_ffff. On Windows, key_t is int. */ static key_t tsrm_choose_random_shm_key(key_t prev_key) { unsigned char buf[4]; - if (php_win32_get_random_bytes(buf, 4) != SUCCESS) { + if (!php_win32_get_random_bytes(buf, 4)) { return prev_key + 2; } uint32_t n = diff --git a/ext/random/csprng.c b/ext/random/csprng.c index 8b38985c6ac67..857a45b2b7969 100644 --- a/ext/random/csprng.c +++ b/ext/random/csprng.c @@ -70,7 +70,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_random_bytes_ex(void *bytes, size_ { #ifdef PHP_WIN32 /* Defer to CryptGenRandom on Windows */ - if (php_win32_get_random_bytes(bytes, size) == FAILURE) { + if (!php_win32_get_random_bytes(bytes, size)) { snprintf(errstr, errstr_size, "Failed to retrieve randomness from the operating system (BCryptGenRandom)"); return FAILURE; } diff --git a/win32/winutil.c b/win32/winutil.c index e09944d131b9b..c20f74b427acd 100644 --- a/win32/winutil.c +++ b/win32/winutil.c @@ -15,8 +15,8 @@ +----------------------------------------------------------------------+ */ -#include "php.h" #include "winutil.h" +#include "ioutil.h" #include "codepage.h" #include #include @@ -54,31 +54,31 @@ PHP_WINUTIL_API void php_win32_error_msg_free(char *msg) } }/*}}}*/ -int php_win32_check_trailing_space(const char * path, const size_t path_len) +bool php_win32_check_trailing_space(const char * path, const size_t path_len) {/*{{{*/ if (path_len > MAXPATHLEN - 1) { - return 1; + return true; } if (path) { if (path[0] == ' ' || path[path_len - 1] == ' ') { - return 0; + return false; } else { - return 1; + return true; } } else { - return 0; + return false; } }/*}}}*/ static BCRYPT_ALG_HANDLE bcrypt_algo; -static BOOL has_bcrypt_algo = 0; +static bool has_bcrypt_algo = false; #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0) #ifdef PHP_EXPORTS -BOOL php_win32_shutdown_random_bytes(void) +bool php_win32_shutdown_random_bytes(void) {/*{{{*/ - BOOL ret = TRUE; + bool ret = true; if (has_bcrypt_algo) { ret = NT_SUCCESS(BCryptCloseAlgorithmProvider(bcrypt_algo, 0)); @@ -88,10 +88,10 @@ BOOL php_win32_shutdown_random_bytes(void) return ret; }/*}}}*/ -BOOL php_win32_init_random_bytes(void) +bool php_win32_init_random_bytes(void) {/*{{{*/ if (has_bcrypt_algo) { - return TRUE; + return true; } has_bcrypt_algo = NT_SUCCESS(BCryptOpenAlgorithmProvider(&bcrypt_algo, BCRYPT_RNG_ALGORITHM, NULL, 0)); @@ -100,24 +100,22 @@ BOOL php_win32_init_random_bytes(void) }/*}}}*/ #endif -PHP_WINUTIL_API int php_win32_get_random_bytes(unsigned char *buf, size_t size) +PHP_WINUTIL_API bool php_win32_get_random_bytes(unsigned char *buf, size_t size) { /* {{{ */ - BOOL ret; - #if 0 /* Currently we fail on startup, with CNG API it shows no regressions so far and is secure. Should switch on and try to reinit, if it fails too often on startup. This means also bringing locks back. */ - if (has_bcrypt_algo == 0) { - return FAILURE; + if (!has_bcrypt_algo) { + return false; } #endif /* No sense to loop here, the limit is huge enough. */ - ret = NT_SUCCESS(BCryptGenRandom(bcrypt_algo, buf, (ULONG)size, 0)); + bool ret = NT_SUCCESS(BCryptGenRandom(bcrypt_algo, buf, (ULONG)size, 0)); - return ret ? SUCCESS : FAILURE; + return ret; } /* }}} */ @@ -439,7 +437,7 @@ PHP_WINUTIL_API char *php_win32_get_username(void) return uname; }/*}}}*/ -static zend_always_inline BOOL is_compatible(HMODULE handle, BOOL is_smaller, char *format, char **err) +static __forceinline bool is_compatible(HMODULE handle, bool is_smaller, char *format, char **err) {/*{{{*/ PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER) handle; PIMAGE_NT_HEADERS pNTHeader = (PIMAGE_NT_HEADERS)((char *) dosHeader + dosHeader->e_lfanew); @@ -470,19 +468,19 @@ static zend_always_inline BOOL is_compatible(HMODULE handle, BOOL is_smaller, ch } else { spprintf(err, 0, "Can't retrieve the module name (error %u)", GetLastError()); } - return FALSE; + return false; } - return TRUE; + return true; }/*}}}*/ -PHP_WINUTIL_API BOOL php_win32_image_compatible(HMODULE handle, char **err) +PHP_WINUTIL_API bool php_win32_image_compatible(HMODULE handle, char **err) {/*{{{*/ - return is_compatible(handle, TRUE, "Can't load module '%s' as it's linked with %u.%u, but the core is linked with %d.%d", err); + return is_compatible(handle, true, "Can't load module '%s' as it's linked with %u.%u, but the core is linked with %d.%d", err); }/*}}}*/ /* Expect a CRT module handle */ -PHP_WINUTIL_API BOOL php_win32_crt_compatible(char **err) +PHP_WINUTIL_API bool php_win32_crt_compatible(char **err) {/*{{{*/ #if PHP_LINKER_MAJOR == 14 /* Extend for other CRT if needed. */ @@ -494,9 +492,9 @@ PHP_WINUTIL_API BOOL php_win32_crt_compatible(char **err) HMODULE handle = GetModuleHandle(crt_name); if (handle == NULL) { spprintf(err, 0, "Can't get handle of module %s (error %u)", crt_name, GetLastError()); - return FALSE; + return false; } - return is_compatible(handle, FALSE, "'%s' %u.%u is not compatible with this PHP build linked with %d.%d", err); + return is_compatible(handle, false, "'%s' %u.%u is not compatible with this PHP build linked with %d.%d", err); #endif - return TRUE; + return true; }/*}}}*/ diff --git a/win32/winutil.h b/win32/winutil.h index 043195067529c..f868448bddb15 100644 --- a/win32/winutil.h +++ b/win32/winutil.h @@ -23,16 +23,21 @@ # define PHP_WINUTIL_API __declspec(dllimport) #endif +#include +#include +#include +#include + PHP_WINUTIL_API char *php_win32_error_to_msg(HRESULT error); PHP_WINUTIL_API void php_win32_error_msg_free(char *msg); #define php_win_err() php_win32_error_to_msg(GetLastError()) #define php_win_err_free(err) php_win32_error_msg_free(err) -int php_win32_check_trailing_space(const char * path, const size_t path_len); -PHP_WINUTIL_API int php_win32_get_random_bytes(unsigned char *buf, size_t size); +bool php_win32_check_trailing_space(const char * path, const size_t path_len); +PHP_WINUTIL_API bool php_win32_get_random_bytes(unsigned char *buf, size_t size); #ifdef PHP_EXPORTS -BOOL php_win32_init_random_bytes(void); -BOOL php_win32_shutdown_random_bytes(void); +bool php_win32_init_random_bytes(void); +bool php_win32_shutdown_random_bytes(void); #endif #if !defined(ECURDIR) @@ -53,7 +58,7 @@ PHP_WINUTIL_API int php_win32_code_to_errno(unsigned long w32Err); PHP_WINUTIL_API char *php_win32_get_username(void); -PHP_WINUTIL_API BOOL php_win32_image_compatible(HMODULE handle, char **err); -PHP_WINUTIL_API BOOL php_win32_crt_compatible(char **err); +PHP_WINUTIL_API bool php_win32_image_compatible(HMODULE handle, char **err); +PHP_WINUTIL_API bool php_win32_crt_compatible(char **err); #endif From 19c061271a0ad28d87408ac5935055ff49a58cd7 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Sat, 24 Aug 2024 02:35:37 +0200 Subject: [PATCH 09/11] Add header dependencies in codepage header --- win32/codepage.c | 2 +- win32/codepage.h | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/win32/codepage.c b/win32/codepage.c index 69b6a44aa9c8a..06b5916683726 100644 --- a/win32/codepage.c +++ b/win32/codepage.c @@ -420,7 +420,7 @@ PW32CP const struct php_win32_cp *php_win32_cp_set_by_id(DWORD id) return cur_cp; }/*}}}*/ -PW32CP BOOL php_win32_cp_use_unicode(void) +PW32CP bool php_win32_cp_use_unicode(void) {/*{{{*/ return 65001 == cur_cp->id; }/*}}}*/ diff --git a/win32/codepage.h b/win32/codepage.h index e69bf7cdc9d5c..7f1a5ae996e4e 100644 --- a/win32/codepage.h +++ b/win32/codepage.h @@ -27,6 +27,11 @@ extern "C" { # define PW32CP __declspec(dllimport) #endif +#include +#include +#include +#include + #define PHP_WIN32_CP_IGNORE_LEN (0) #define PHP_WIN32_CP_IGNORE_LEN_P ((size_t *)-1) @@ -40,7 +45,7 @@ struct php_win32_cp { char *desc; }; -PW32CP BOOL php_win32_cp_use_unicode(void); +PW32CP bool php_win32_cp_use_unicode(void); PW32CP const struct php_win32_cp *php_win32_cp_do_setup(const char *); #define php_win32_cp_setup() php_win32_cp_do_setup(NULL) PW32CP const struct php_win32_cp *php_win32_cp_do_update(const char *); From 19758b1149648c2438a930e21df81447f0fafb8f Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Sat, 24 Aug 2024 02:49:17 +0200 Subject: [PATCH 10/11] glob.h extern C the old fashioned way --- win32/glob.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/win32/glob.h b/win32/glob.h index f232c45f465e6..fd677f6d1d80f 100644 --- a/win32/glob.h +++ b/win32/glob.h @@ -42,6 +42,10 @@ #ifndef _GLOB_H_ #define _GLOB_H_ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef PHP_EXPORTS # define PHP_WIN_GLOB __declspec(dllexport) #else @@ -81,8 +85,11 @@ typedef struct { #define GLOB_ABORTED (-2) /* Unignored error. */ #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ -BEGIN_EXTERN_C() PHP_WIN_GLOB int glob(const char *, int, int (*)(const char *, int), glob_t *); PHP_WIN_GLOB void globfree(glob_t *); -END_EXTERN_C() + +#ifdef __cplusplus +} +#endif + #endif /* !_GLOB_H_ */ From 2ee1742338c1f059609986a473f76ab4e7198200 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Sat, 24 Aug 2024 03:24:56 +0200 Subject: [PATCH 11/11] Remove non-windows CIs --- .github/workflows/push.yml | 297 ------------------------------------- 1 file changed, 297 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 086c5cc0347bd..d9399e110541a 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -42,197 +42,6 @@ env: CC: ccache gcc CXX: ccache g++ jobs: - LINUX_X64: - if: github.repository == 'php/php-src' || github.event_name == 'pull_request' - services: - mysql: - image: mysql:8.3 - ports: - - 3306:3306 - env: - MYSQL_DATABASE: test - MYSQL_ROOT_PASSWORD: root - postgres: - image: postgres - ports: - - 5432:5432 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: test - firebird: - image: jacobalberty/firebird - ports: - - 3050:3050 - env: - ISC_PASSWORD: test - FIREBIRD_DATABASE: test.fdb - FIREBIRD_USER: test - FIREBIRD_PASSWORD: test - strategy: - fail-fast: false - matrix: - include: - - debug: false - zts: false - asan: false - - debug: true - zts: true - asan: true - name: "LINUX_X64_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}${{ matrix.asan && '_ASAN' || '' }}" - runs-on: ubuntu-${{ !matrix.asan && '22' || '20' }}.04 - container: - image: ${{ matrix.asan && 'ubuntu:23.04' || null }} - steps: - - name: git checkout - uses: actions/checkout@v4 - - name: apt - uses: ./.github/actions/apt-x64 - - name: LLVM 16 (ASAN-only) - if: ${{ matrix.asan }} - run: | - DEBIAN_FRONTEND=noninteractive sudo apt-get install -y lsb-release wget software-properties-common gnupg - wget https://apt.llvm.org/llvm.sh - chmod u+x llvm.sh - sudo ./llvm.sh 16 - - name: System info - run: | - echo "::group::Show host CPU info" - lscpu - echo "::endgroup::" - echo "::group::Show installed package versions" - dpkg -l - echo "::endgroup::" - - name: Create MSSQL container - if: ${{ !matrix.asan }} - uses: ./.github/actions/setup-mssql - - name: Setup Caddy server - uses: ./.github/actions/setup-caddy - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - # This duplicates the "job.name" expression above because - # GitHub has no way to query the job name (github.job is the - # job id, not the job name) - key: "LINUX_X64_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}${{ matrix.asan && '_ASAN' || '' }}-${{hashFiles('main/php_version.h')}}" - append-timestamp: false - save: ${{ github.event_name != 'pull_request' }} - - name: ./configure - uses: ./.github/actions/configure-x64 - with: - configurationParameters: >- - --${{ matrix.debug && 'enable' || 'disable' }}-debug - --${{ matrix.zts && 'enable' || 'disable' }}-zts - ${{ matrix.asan && 'CFLAGS="-fsanitize=undefined,address -DZEND_TRACK_ARENA_ALLOC" LDFLAGS="-fsanitize=undefined,address" CC=clang-16 CXX=clang++-16' || '' }} - skipSlow: ${{ matrix.asan }} - - name: make - run: make -j$(/usr/bin/nproc) >/dev/null - - name: make install - uses: ./.github/actions/install-linux - - name: Setup - if: ${{ !matrix.asan }} - uses: ./.github/actions/setup-x64 - - name: Test - if: matrix.asan == false - uses: ./.github/actions/test-linux - - name: Test Tracing JIT - uses: ./.github/actions/test-linux - with: - jitType: tracing - runTestsParameters: >- - -d zend_extension=opcache.so - -d opcache.enable_cli=1 - ${{ matrix.asan && '--asan -x' || '' }} - - name: Verify generated files are up to date - if: ${{ !matrix.asan }} - uses: ./.github/actions/verify-generated-files - LINUX_X32: - if: github.repository == 'php/php-src' || github.event_name == 'pull_request' - name: LINUX_X32_DEBUG_ZTS - runs-on: ubuntu-latest - container: - image: ubuntu:20.04 - env: - MYSQL_TEST_HOST: mysql - PDO_MYSQL_TEST_DSN: mysql:host=mysql;dbname=test - PDO_MYSQL_TEST_HOST: mysql - services: - mysql: - image: mysql:8.3 - ports: - - 3306:3306 - env: - MYSQL_DATABASE: test - MYSQL_ROOT_PASSWORD: root - steps: - - name: git checkout - uses: actions/checkout@v4 - - name: apt - uses: ./.github/actions/apt-x32 - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: "${{github.job}}-${{hashFiles('main/php_version.h')}}" - append-timestamp: false - - name: ./configure - uses: ./.github/actions/configure-x32 - with: - configurationParameters: >- - --enable-debug - --enable-zts - - name: make - run: make -j$(/usr/bin/nproc) >/dev/null - - name: make install - uses: ./.github/actions/install-linux-x32 - - name: Test Tracing JIT - uses: ./.github/actions/test-linux - with: - jitType: tracing - runTestsParameters: >- - -d zend_extension=opcache.so - -d opcache.enable_cli=1 - MACOS_DEBUG_NTS: - if: github.repository == 'php/php-src' || github.event_name == 'pull_request' - strategy: - fail-fast: false - matrix: - include: - - os: 13 - arch: X64 - - os: 14 - arch: ARM64 - name: MACOS_${{ matrix.arch }}_DEBUG_NTS - runs-on: macos-${{ matrix.os }} - steps: - - name: git checkout - uses: actions/checkout@v4 - - name: brew - uses: ./.github/actions/brew - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: "${{github.job}}-${{matrix.os}}-${{hashFiles('main/php_version.h')}}" - append-timestamp: false - save: ${{ github.event_name != 'pull_request' }} - - name: ./configure - uses: ./.github/actions/configure-macos - with: - configurationParameters: --enable-debug --disable-zts - - name: make - run: |- - export PATH="$(brew --prefix)/opt/bison/bin:$PATH" - make -j$(sysctl -n hw.logicalcpu) >/dev/null - - name: make install - run: sudo make install - - name: Test Tracing JIT - uses: ./.github/actions/test-macos - with: - jitType: tracing - runTestsParameters: >- - -d zend_extension=opcache.so - -d opcache.enable_cli=1 - - name: Verify generated files are up to date - uses: ./.github/actions/verify-generated-files WINDOWS: if: github.repository == 'php/php-src' || github.event_name == 'pull_request' name: WINDOWS_X64_ZTS @@ -259,109 +68,3 @@ jobs: run: .github/scripts/windows/build.bat - name: Test run: .github/scripts/windows/test.bat - BENCHMARKING: - name: BENCHMARKING - if: github.repository == 'php/php-src' || github.event_name == 'pull_request' - runs-on: ubuntu-22.04 - steps: - - name: git checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - # ASLR can cause a lot of noise due to missed sse opportunities for memcpy - # and other operations, so we disable it during benchmarking. - - name: Disable ASLR - run: echo 0 | sudo tee /proc/sys/kernel/randomize_va_space - - name: apt - run: | - set -x - sudo apt-get update - sudo apt-get install \ - bison \ - libgmp-dev \ - libonig-dev \ - libsqlite3-dev \ - openssl \ - re2c \ - valgrind - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: "${{github.job}}-${{hashFiles('main/php_version.h')}}" - append-timestamp: false - save: ${{ github.event_name != 'pull_request' }} - - name: ./configure - run: | - set -x - ./buildconf --force - ./configure \ - --disable-debug \ - --enable-mbstring \ - --enable-opcache \ - --enable-option-checking=fatal \ - --enable-sockets \ - --enable-werror \ - --prefix=/usr \ - --with-config-file-scan-dir=/etc/php.d \ - --with-gmp \ - --with-mysqli=mysqlnd \ - --with-openssl \ - --with-pdo-sqlite \ - --with-valgrind - - name: make - run: make -j$(/usr/bin/nproc) >/dev/null - - name: make install - run: | - set -x - sudo make install - sudo mkdir -p /etc/php.d - sudo chmod 777 /etc/php.d - echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini - echo zend_extension=opcache.so >> /etc/php.d/opcache.ini - echo opcache.enable=1 >> /etc/php.d/opcache.ini - echo opcache.enable_cli=1 >> /etc/php.d/opcache.ini - - name: Setup - run: | - git config --global user.name "Benchmark" - git config --global user.email "benchmark@php.net" - sudo service mysql start - mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS wordpress" - mysql -uroot -proot -e "CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'wordpress'; FLUSH PRIVILEGES;" - mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'wordpress'@'localhost' WITH GRANT OPTION;" - - name: git checkout benchmarking-data - uses: actions/checkout@v4 - with: - repository: php/benchmarking-data - ssh-key: ${{ secrets.BENCHMARKING_DATA_DEPLOY_KEY }} - path: benchmark/repos/data - - name: Benchmark - run: php benchmark/benchmark.php true - - name: Store result - if: github.event_name == 'push' - run: | - set -x - cd benchmark/repos/data - git pull --autostash - if [ -e ".git/MERGE_HEAD" ]; then - echo "Merging, can't proceed" - exit 1 - fi - git add . - if git diff --cached --quiet; then - exit 0 - fi - git commit -m "Add result for ${{ github.repository }}@${{ github.sha }}" - git push - - name: Show diff - if: github.event_name == 'pull_request' - run: |- - set -x - php benchmark/generate_diff.php \ - ${{ github.sha }} \ - $(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.sha }}) \ - > $GITHUB_STEP_SUMMARY - - uses: actions/upload-artifact@v4 - with: - name: profiles - path: ${{ github.workspace }}/benchmark/profiles - retention-days: 30