-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update OpenBSD glob implementation for Windows #16948
base: master
Are you sure you want to change the base?
Conversation
MSVC error there is misleading, it's missing |
41594b5
to
affa4a7
Compare
affa4a7
to
48fbd32
Compare
See #16986.
Might be best, unless that would be a PITA when pulling in further updates. |
For now I imported reallocarray. I don't think glob changes much, so future changes from OpenBSD should be easy to reconcile even if we do convert to ZendMM in the future. Now, to figure out what's broken... |
The usage of win32/glob.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/win32/glob.c b/win32/glob.c
index 0923d49efa..36c1c58f1c 100644
--- a/win32/glob.c
+++ b/win32/glob.c
@@ -702,7 +702,7 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
/* Find end of next segment, copy tentatively to pathend. */
q = pathend;
p = pattern;
- while (*p != EOS && *p != SEP) {
+ while (*p != EOS && !IS_SLASH(*p)) {
if (ismeta(*p))
anymeta = 1;
if (q+1 > pathend_last)
@@ -713,7 +713,7 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
if (!anymeta) { /* No expansion, do next segment. */
pathend = q;
pattern = p;
- while (*pattern == SEP) {
+ while (IS_SLASH(*pattern)) {
if (pathend+1 > pathend_last)
return (1);
*pathend++ = *pattern++; Likely the |
Thanks for trying to catch these. I was going to set up a Windows build environment over the weekend to avoid CI driven development, but didn't have any time and my Windows PC (basically used for games nowadays) seems a bit cooked. |
I'm happy to help with this (less platform specific behavior is always nice). I think this also needs e42aae1, and should be good then. |
I'm also considering porting |
From OpenBSD, dependency of newer versions of glob.
We're considering making this used as a glob implementation on POSIX as well, but first, we should rebase it from the latest version of OpenBSD. This also adds a new internal header (charclass.h) for glob. See conversation in phpGH-15564. Co-authored-by: Christoph M. Becker <[email protected]>
d43cf62
to
3aafb04
Compare
Just noticed that |
Would it just be a matter of making it use the PHP VCWD functions? glob seems abstracted enough internally we can probably change i.e. |
Looking at VCWD, I'm not sure if it'd solve it; the diff --git a/win32/glob.c b/win32/glob.c
index f1e75de7344..6435d8f17d2 100644
--- a/win32/glob.c
+++ b/win32/glob.c
@@ -1041,7 +1041,7 @@ g_opendir(Char *str, glob_t *pglob)
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
return((*pglob->gl_opendir)(buf));
- return(opendir(buf));
+ return(VCWD_OPENDIR(buf));
}
static int
@@ -1053,7 +1053,7 @@ 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(VCWD_LSTAT(buf, sb));
}
static int
@@ -1065,7 +1065,7 @@ 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(VCWD_STAT(buf, sb));
}
static Char * |
I wouldn't worry about UTF-8 and long path support right now (i.e. for the update). There are already a couple of things that are not supported, e.g.
Anyway, I tried globbing for ü.txt, and that failed with the old version, but worked with the new, probably because of I shall also check other clients of |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for taking care of this.
I'm not a massive fan of adding a new file for reallocarray()
but that's not really a problem.
Left some minor comments
win32/glob.c
Outdated
(c = qpatnext[1]) != RBRACKET) { | ||
(c = qpatnext[1]) != RBRACKET) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent changed from tab to spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, this how OpenBSD indented it (same for the ones you mentioned below). I can change this to match PHP style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to keep this file as close to the original as possible, to make backports from upstream easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind doing the indentation changes if that's how we do it; the file doesn't change too much and in the future we can probably look at backporting individual patches. I just did a blanket import since it looks like we had almost 20 years of changes to deal with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to keep this file as close to the original as possible, to make backports from upstream easier.
Well, I suppose if we can backport the indent issues I'm fine with that too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't worry that much about diverging from upstream as we might want to do some changes into it eventually. It would be however useful to track the version that it is based on so we can from time to time review changes in the upstream and backport it to our implementation.
win32/glob.c
Outdated
((pglob->gl_flags & GLOB_NOMAGIC) && | ||
!(pglob->gl_flags & GLOB_MAGCHAR))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto indent changes
win32/glob.c
Outdated
pathbuf, pathbuf+PATH_MAX-1, | ||
pattern, pattern_last, pglob, limitp)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
win32/glob.c
Outdated
pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || | ||
(S_ISLNK(sb.st_mode) && | ||
(g_stat(pathbuf, &sb, pglob) == 0) && | ||
S_ISDIR(sb.st_mode)))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent changes
win32/glob.c
Outdated
pathend_last, pattern, p, pattern_last, | ||
pglob, limitp)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
win32/glob.c
Outdated
pglob->gl_flags & GLOB_ERR) | ||
pglob->gl_flags & GLOB_ERR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
win32/glob.c
Outdated
restpattern, restpattern_last, pglob, limitp); | ||
restpattern, restpattern_last, pglob, limitp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice first step. Except that reallocarray placement, it looks good to me. It would be good to wait for @cmb69 to do his testing though.
main/reallocarray.c
Outdated
@@ -0,0 +1,59 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should not be in main but in win32. I don't think we will want to use it in this format if glob is made common. In such case we should probably look to introducing something in zend_alloc that would respect memory_limit at some point. I know that the libc glob does not do that but it would be good thing to do eventually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imported reallocarray there since it's consistent with other imported utility functions like strlcpy, and we'll need it when we use this glob on not-Windows. ZendMM conversion would render this moot though.
OpenBSD uses tabs for indentation, but four spaces to align i.e. continuations of lines. In PHP, we apparently just use tabs, so do that for code bodies and function declarations.
Matches the style of glob before, OpenBSD must have changed this to match their convention, but this is closer to PHP convention.
I've cleaned up the indentation stuff and did try to fix some things to match PHP house style. Let me know if I missed something. If we want to do ZendMM conversion, should that be done in another PR or in this PR? Latter would mean we do even more stuff in this PR, but we can avoid having to import reallocarray just to get rid of it in a ZendMM conversion. |
As it's just temporary, it should be fine to chuck static php_reallocarray to glob.c and then in the future PR do the Zend MM conversion and get rid of it. You can just add a comment that it's a temp thing. |
We only need it on Windows, and we want to convert this file to ZendMM later anyways, which has its own equivalent. This also reverts commit a26e92e.
It looks fine to me now. It's all win32 so let's wait for @cmb69 to give it a green light. |
Bumping again, but to recap on what might still need to be done if this is to be merged:
|
I am happy to progress as is if @cmb69 is OK with it :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good as is, and there is still plenty of time to PHP 8.5.0alpha1 for additional checking.
# ifndef PATH_MAX | ||
# define PATH_MAX MAXPATHLEN | ||
# endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep an eye on this; AFAIK PATH_MAX
is not defined on Windows, so it will be defined here (what we want).
We're considering making this used as a glob implementation on POSIX as well, but first, we should rebase it from the latest version of OpenBSD.
This also adds a new internal header (charclass.h) for glob.
See conversation in GH-15564.