Mailing List Archive

Internals::getcwd(was Re: PSC #037 - 2021-09-10)
On Mon, Sep 13, 2021 at 09:36:26AM +1000, Tony Cook wrote:
> On Sun, Sep 12, 2021 at 08:17:10PM +0100, Paul "LeoNerd" Evans wrote:
> > PSC #037 - 2021-09-10
> >
> > Regarding eventually getting rid of the `Internals::getcwd()` function,
> > we observed that `dist/PathTools/Cwd.pm` currently uses it, but nothing
> > else on CPAN appears to. This should be an easy candidate to get moved
> > into a new builtins-namespace; possibly by also adding a deprecation
> > warning to the existing function.
>
> It can be renamed or removed with impunity.
>
> From the 5.30.0 delta:
>
> Perl now exposes POSIX C<getcwd> as C<Internals::getcwd()> if
> available. This is intended for use by C<Cwd.pm> during bootstrapping
> and may be removed or changed without notice. This fixes some
> bootstrapping issues while building perl in a directory where some
> ancestor directory isn't readable.
> L<[GH #16903]|https://github.com/Perl/perl5/issues/16903>.
>
> It's only used during bootstrapping for miniperl (though the code
> could better reflect that), so it is not needed in future releases on
> CPAN.

So like this?

commit 0d4de636c4a178583469ed7d50030baf9062ef3f (nwc10/Internals-getcwd-only-for-miniperl, Internals-getcwd-only-for-miniperl)
Author: Nicholas Clark <nick@ccl4.org>
Date: Mon Sep 13 09:08:31 2021 +0000

Only expose Internals::getcwd() in miniperl

It's only used during bootstrapping for miniperl when the XS version of Cwd
is not yet available, and only needed on platforms that don't already
provide their own builtin for getcwd().

It was added in v5.30.0 with the clear warning that
[it] may be removed or changed without notice

and is not used by any code on CPAN. (Cwd references it, but won't use it
once installed as it will have already found an XS implementation (platform
specific or generic).

diff --git a/universal.c b/universal.c
index 8dd693aa10..9558504317 100644
--- a/universal.c
+++ b/universal.c
@@ -1,3 +1,4 @@
+#line 2 "universal.c"
/* universal.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
@@ -1065,7 +1066,7 @@ XS(XS_re_regexp_pattern)
NOT_REACHED; /* NOTREACHED */
}

-#ifdef HAS_GETCWD
+#if defined(HAS_GETCWD) && defined(PERL_IS_MINIPERL)

XS(XS_Internals_getcwd)
{
@@ -1273,7 +1274,7 @@ static const struct xsub_details these_details[] = {
{"re::regnames", XS_re_regnames, ";$", 0 },
{"re::regnames_count", XS_re_regnames_count, "", 0 },
{"re::regexp_pattern", XS_re_regexp_pattern, "$", 0 },
-#ifdef HAS_GETCWD
+#if defined(HAS_GETCWD) && defined(PERL_IS_MINIPERL)
{"Internals::getcwd", XS_Internals_getcwd, "", 0 },
#endif
{"Tie::Hash::NamedCapture::_tie_it", XS_NamedCapture_tie_it, NULL, 0 },


(plus a supporting cast of diffs to Makefile.SH and t/io/getcwd.t)

https://github.com/Perl/perl5/pull/19122

Nicholas Clark