Skip to content

Enable -DPERL_USE_SAFE_PUTENV in older versions of Perl on darwin.#69

Merged
bingos merged 1 commit into
bingos:masterfrom
shogo82148:fix-issue68
Apr 10, 2026
Merged

Enable -DPERL_USE_SAFE_PUTENV in older versions of Perl on darwin.#69
bingos merged 1 commit into
bingos:masterfrom
shogo82148:fix-issue68

Conversation

@shogo82148
Copy link
Copy Markdown
Contributor

-DPERL_USE_SAFE_PUTENV was removed in Perl 5.37.1, but it is still required for older versions of Perl on darwin.

Made the following changes to hints/darwin.sh:

--- hints/darwin.sh.old	2026-03-22 00:12:35
+++ hints/darwin.sh	2026-03-22 00:13:13
@@ -526,6 +526,26 @@
 # makefile in the same place.  Since Darwin uses GNU make, this dodges
 # the problem.
 firstmakefile=GNUmakefile;
+
+# >= 5.23.6 and <= 5.37.0 have a problem with setenv() in atfork handlers on Darwin,
+# so enable -DPERL_USE_SAFE_PUTENV, ref. https://github.com/Perl/perl5/commit/e3962106e93fa80bf960e71ac7c7727e7e15eee8
+# This behavior became the default after version 5.37.0, ref. https://github.com/Perl/perl5/commit/ae6b6b71cdbfb3fb6e1192178fa1e530a2f07ece
+if [ "$perl_revision" -eq 5 ] && \
+   { [ "$perl_version" -gt 23 ] || \
+     { [ "$perl_version" -eq 23 ] && [ "$perl_subversion" -ge 6 ]; }; } && \
+   { [ "$perl_version" -lt 37 ] || \
+     { [ "$perl_version" -eq 37 ] && [ "$perl_subversion" -le 0 ]; }; }
+then
+  # Parts of the system call setenv(), in particular in an atfork handler.
+  # This causes problems when the child tries to clean up environ[], so
+  # let libc manage environ[].
+  cat >> config.over <<'EOOVER'
+if test "$d_unsetenv" = "$define" -a \
+    `expr "$ccflags" : '.*-DPERL_USE_SAFE_PUTENV'` -eq 0; then
+        ccflags="$ccflags -DPERL_USE_SAFE_PUTENV"
+fi
+EOOVER
+fi

 # if you use a newer toolchain before OS X 10.9 these functions may be
 # incorrectly detected, so disable them

fixes #68

-DPERL_USE_SAFE_PUTENV was removed in Perl 5.37.1,
but it is still required for older versions of Perl on darwin.

Made the following changes to hints/darwin.sh:

```diff
--- hints/darwin.sh.old	2026-03-22 00:12:35
+++ hints/darwin.sh	2026-03-22 00:13:13
@@ -526,6 +526,26 @@
 # makefile in the same place.  Since Darwin uses GNU make, this dodges
 # the problem.
 firstmakefile=GNUmakefile;
+
+# >= 5.23.6 and <= 5.37.0 have a problem with setenv() in atfork handlers on Darwin,
+# so enable -DPERL_USE_SAFE_PUTENV, ref. Perl/perl5@e396210
+# This behavior became the default after version 5.37.0, ref. Perl/perl5@ae6b6b7
+if [ "$perl_revision" -eq 5 ] && \
+   { [ "$perl_version" -gt 23 ] || \
+     { [ "$perl_version" -eq 23 ] && [ "$perl_subversion" -ge 6 ]; }; } && \
+   { [ "$perl_version" -lt 37 ] || \
+     { [ "$perl_version" -eq 37 ] && [ "$perl_subversion" -le 0 ]; }; }
+then
+  # Parts of the system call setenv(), in particular in an atfork handler.
+  # This causes problems when the child tries to clean up environ[], so
+  # let libc manage environ[].
+  cat >> config.over <<'EOOVER'
+if test "$d_unsetenv" = "$define" -a \
+    `expr "$ccflags" : '.*-DPERL_USE_SAFE_PUTENV'` -eq 0; then
+        ccflags="$ccflags -DPERL_USE_SAFE_PUTENV"
+fi
+EOOVER
+fi

 # if you use a newer toolchain before OS X 10.9 these functions may be
 # incorrectly detected, so disable them
```

fixes bingos#68
@bingos bingos merged commit cf6b265 into bingos:master Apr 10, 2026
178 of 186 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build Perl 5.36.3 on Darwin fails

2 participants