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

add &CORE::chdir (properly) #22362

Merged
merged 2 commits into from
Jul 2, 2024
Merged

add &CORE::chdir (properly) #22362

merged 2 commits into from
Jul 2, 2024

Conversation

mauke
Copy link
Contributor

@mauke mauke commented Jun 30, 2024

Previously, CORE::chdir was not "ampable", i.e. it could not be called
through a coderef or with a sigil: &CORE::chdir($dir);

The only thing allowed was to make a compile-time alias, whose calls
would then be inlined to chdir again:

BEGIN { *foo = \&CORE::chdir; }
foo ".";  # actually does chdir "."

However, this was broken if the function call used parentheses, in which
case chdir would always try to use its argument as a filehandle, not the
name of a directory:

BEGIN { *foo = \&CORE::chdir; }
foo(".");
# Triggers a warning:
# chdir() on unopened filehandle . at file line 2.

This commit fixes the problem and makes chdir fully "ampable", so
&CORE::chdir() no longer triggers the &CORE::chdir cannot be called directly error.

pp_sys.c Show resolved Hide resolved
mauke added 2 commits July 1, 2024 10:04
Previously, CORE::chdir was not "ampable", i.e. it could not be called
through a coderef or with a sigil: &CORE::chdir($dir);

The only thing allowed was to make a compile-time alias, whose calls
would then be inlined to chdir again:

    BEGIN { *foo = \&CORE::chdir; }
    foo ".";  # actually does chdir "."

However, this was broken if the function call used parentheses, in which
case chdir would always try to use its argument as a filehandle, not the
name of a directory:

    BEGIN { *foo = \&CORE::chdir; }
    foo(".");
    # Triggers a warning:
    # chdir() on unopened filehandle . at file line 2.

This commit fixes the problem and makes chdir fully "ampable", so
&CORE::chdir() no longer triggers the "&CORE::chdir cannot be called
directly" error.
@mauke mauke force-pushed the ampersand-core-chdir branch from 14975c8 to 12d0a0c Compare July 1, 2024 08:04
@tonycoz
Copy link
Contributor

tonycoz commented Jul 2, 2024

The three different chdir() PRs seem to me like they'd conflict with each other.

@mauke
Copy link
Contributor Author

mauke commented Jul 2, 2024

The three different chdir() PRs seem to me like they'd conflict with each other.

True, but they're all mine, so I know how to resolve/rebase things. I just wanted the PRs to be independently reviewable at first.

@mauke mauke merged commit 521cc3f into Perl:blead Jul 2, 2024
29 checks passed
@mauke mauke deleted the ampersand-core-chdir branch July 2, 2024 04:38
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.

2 participants