From 2a33949ef7070216491667f04fc060acdba17611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 20 Sep 2026 10:54:49 -0400 Subject: [PATCH 1/4] lib/re: fix doc unit of `Regex::compile` on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error message on an unbalanced bracket (used in a doc unit) depends on the libc: "Unmatched [" with the GNU libc and "brackets ([ ]) not balanced" on macOS. Let's check only for the shared open bracket. Signed-off-by: Alexis Laferrière --- lib/core/re.nit | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/core/re.nit b/lib/core/re.nit index 50b325a894..b035c111b2 100644 --- a/lib/core/re.nit +++ b/lib/core/re.nit @@ -126,7 +126,7 @@ end # A regular expression pattern # -# Used as a `Pattern` on intances of `Text` to call `has`, `search_all`, `replace`, etc. +# Used as a `Pattern` on instances of `Text` to call `has`, `search_all`, `replace`, etc. # # Example: # @@ -155,7 +155,7 @@ class Regex # Optimize `self` for `String::has` and `is_in`, but do not support searches # - # If `true`, `self` cannont be used with `String::search_all`, `String::replace` + # If `true`, `self` cannot be used with `String::search_all`, `String::replace` # or `String::split`. var optimize_has = false is writable @@ -202,7 +202,9 @@ class Regex # should call it to check for errors. # # assert "ab".to_re.compile == null - # assert "[ab".to_re.compile.message.has_prefix("Unmatched [") + # + # # Errors on "Unmatched [" or "brackets ([ ]) not balanced". + # assert "[ab".to_re.compile.message.has("[") fun compile: nullable Error do var cflags = 0 From 2d10b426c64c47e4367206c843b67bb55d0d207e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 20 Sep 2026 11:28:54 -0400 Subject: [PATCH 2/4] lib/re: support `\s` and `\w` in `Regex` on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The regex library on Apple platforms needs `REG_ENHANCED` to support the the shortcuts `\s`, `\S`, `\w` and `\W`. The GNU libc accepts these shortcuts by default. This was seen in `lib/markdown2` which relies on these shortcuts and where 70 tests were failing on macOS, plus it could break the nitunit program. Intro `Regex::enhanced` to pass the flag when the platform defines it, enabled by default. Signed-off-by: Alexis Laferrière --- lib/core/re.nit | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/core/re.nit b/lib/core/re.nit index b035c111b2..d84fce2712 100644 --- a/lib/core/re.nit +++ b/lib/core/re.nit @@ -86,6 +86,15 @@ private fun flag_icase: Int `{ return REG_ICASE; `} private fun flag_nosub: Int `{ return REG_NOSUB; `} private fun flag_newline: Int `{ return REG_NEWLINE; `} +# Flag activating the enhanced features on macOS, 0 on other platforms +private fun flag_enhanced: Int `{ +#ifdef REG_ENHANCED + return REG_ENHANCED; +#else + return 0; +#endif +`} + # Flags for `NativeRegex::regexec` private fun flag_notbol: Int `{ return REG_NOTBOL; `} @@ -135,6 +144,13 @@ end # assert "aabbbbaaaaba".has(re) # assert "aabbbbaaaaba".replace(re, "+") == "a+aa+" # assert "aabbbbaaaaba".split(re) == ["a", "aa", ""] +# +# The shortcuts `\s`, `\S`, `\w` and `\W` are supported on all platforms: +# +# assert "ab, \ncd".replace("\\s".to_re, "_") == "ab,__cd" +# assert "ab, \ncd".replace("\\S".to_re, "_") == "___ \n__" +# assert "ab, \ncd".replace("\\w".to_re, "_") == "__, \n__" +# assert "ab, \ncd".replace("\\W".to_re, "_") == "ab___cd" class Regex super Finalizable super Pattern @@ -150,6 +166,13 @@ class Regex # character to be used as literal. var extended = true is writable + # Activate the enhanced features of the regex library of macOS (the default) + # + # It is needed on macOS to support the shortcuts `\s`, `\S`, `\w` and `\W`. + # If `false` on macOS, only the POSIX syntax is accepted. + # This has no effect on other platforms, the GNU libc always accepts these shortcuts. + var enhanced = true is writable + # Ignore case when matching letters var ignore_case = false is writable @@ -209,6 +232,7 @@ class Regex do var cflags = 0 if extended then cflags |= flag_extended + if enhanced then cflags |= flag_enhanced if ignore_case then cflags |= flag_icase if optimize_has then cflags |= flag_nosub if newline then cflags |= flag_newline From a4366b1ea33ffa26909cd4cc3035c279b5417c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 20 Sep 2026 12:10:58 -0400 Subject: [PATCH 3/4] lib/binary: update imported header path for macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Apple platforms we need to import `endian.h` from `sys/`. Signed-off-by: Alexis Laferrière --- lib/binary/binary.nit | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/binary/binary.nit b/lib/binary/binary.nit index 8b39d31e5c..e1b234c1aa 100644 --- a/lib/binary/binary.nit +++ b/lib/binary/binary.nit @@ -42,7 +42,12 @@ module binary in "C" `{ #include - #include + + #ifdef __APPLE__ + #include + #else + #include + #endif // Android compatibility #ifndef be32toh From 70ed601fb7ac274d51c8e9a271e3b466fdfef7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 20 Sep 2026 12:11:10 -0400 Subject: [PATCH 4/4] lib/gmp: use pkg-config to find the library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On macOS, Homebrew installs GMP outside of the default search paths of the C compiler, so `gmp.h` was not found with only `-lgmp`. Using pkg-config should find it reliably on all platforms. Signed-off-by: Alexis Laferrière --- lib/gmp/native_gmp.nit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gmp/native_gmp.nit b/lib/gmp/native_gmp.nit index 8c8b86a631..958e836cfc 100644 --- a/lib/gmp/native_gmp.nit +++ b/lib/gmp/native_gmp.nit @@ -13,7 +13,7 @@ # limitations under the License. # Low-level GMP features -module native_gmp is ldflags("-lgmp") +module native_gmp is pkgconfig("gmp") in "C header" `{ #include