Skip to content
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

[build] Check if GLOB_PERIOD exists #2207

Merged
merged 5 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build/detect-fnm-extmatch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <fnmatch.h>

int main(void) {
int x = FNM_EXTMATCH;
return 0;
}
6 changes: 6 additions & 0 deletions build/detect-glob-period.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <glob.h>

int main(void) {
int x = GLOB_PERIOD;
return 0;
}
18 changes: 18 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,24 @@ echo_cpp() {
else
echo '/* #undef HAVE_PWENT */'
fi

# Check if non-POSIX GLOB_PERIOD is available
if cc_quiet build/detect-glob-period.c; then
echo '/* libc defines GLOB_PERIOD */'
else
# INVALID value that we can detect in code
# e.g. Android does not support this, but glibc and musl libc do
echo '#define GLOB_PERIOD 0'
fi

# Check if non-POSIX GLOB_PERIOD is available
if cc_quiet build/detect-fnm-extmatch.c; then
echo '/* libc defines FNM_EXTMATCH */'
else
# INVALID value that we can detect in code
# e.g. musl libc does not support this, but glibc does
echo '#define FNM_EXTMATCH 0'
fi
}

# Another way of working: set detected-config.mk ?
Expand Down
18 changes: 13 additions & 5 deletions doc/portability.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ These are some notes that supplement [INSTALL](INSTALL.html).

## Issues in the core of Oils

### GNU libc for extended globs
### libc - `FNM_EXTMATCH` is not in POSIX

For matching extended globs like `@(*.cc|*.h)`, Oils relies on GNU libc
support.
To match extended globs like `@(*.cc|*.h)`, OSH relies on `FNM_EXTMATCH` from
GNU libc.

- This is not a POSIX feature.
- It's also unlike bash, which has its own extended glob support.
This is unlike bash, which has its own extended glob library.

TODO: when using other libc, using this syntax should be an error.

### libc - `GLOB_PERIOD` is not in POSIX

To implement the bash feature `shopt -s dotglob`, OSH relies on `GLOB_PERIOD`,
which some libc's implement.

This is unlike bash, which has its own glob library.

TODO: `shopt -s dotglob` should give a warning when turned on.

### Atomic Assignments

The signal handler assumes that int and pointer assignments are atomic. This
Expand Down
1 change: 1 addition & 0 deletions pyext/libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ void initlibc(void) {
module = Py_InitModule("libc", methods);
if (module != NULL) {
PyModule_AddIntConstant(module, "GLOB_PERIOD", GLOB_PERIOD);
PyModule_AddIntConstant(module, "FNM_EXTMATCH", FNM_EXTMATCH);
PyModule_AddIntConstant(module, "FNM_CASEFOLD", FNM_CASEFOLD);
PyModule_AddIntConstant(module, "REG_ICASE", REG_ICASE);
PyModule_AddIntConstant(module, "REG_NEWLINE", REG_NEWLINE);
Expand Down
4 changes: 4 additions & 0 deletions pyext/libc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

class LibcTest(unittest.TestCase):

def testConstants(self):
print('GLOB_PERIOD %d' % libc.GLOB_PERIOD)
print('FNM_EXTMATCH %d' % libc.FNM_EXTMATCH)

def testFnmatch(self):

cases = [
Expand Down