Skip to content

Commit

Permalink
[configure] Check for GLOB_PERIOD and FNM_EXTMATCH (#2207)
Browse files Browse the repository at this point in the history
Document these issues in doc/portability.md.

We still need to do something with them.

---------

Co-authored-by: Andy C <[email protected]>
  • Loading branch information
Melkor333 and Andy C authored Jan 5, 2025
1 parent 3b861d6 commit 1aeec95
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
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

0 comments on commit 1aeec95

Please sign in to comment.