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

gh-90026: support XATTRs on Cygwin #105075

Merged
merged 2 commits into from
Nov 3, 2023
Merged

Conversation

philcerf
Copy link
Contributor

@philcerf philcerf commented May 30, 2023

As described in #90026 (comment) and following comments, CPython’s code for XATTRs seems to already support Cygwin… mostly.

Apart from the changes made by this PR (simply compiling the relevant code), there are however also some changes needed on the Cygwin side (I guess):

Namely, they don't export XATTR_SIZE_MAX and XATTR_LIST_MAX and so a build of CPython with this commit would fail right now.

I've asked at their mailing list to have them included in their cygwin/limits.h (which I think is the proper place - Linux defines them in linux/limits.h): https://cygwin.com/pipermail/cygwin/2023-May/253750.html

Right now, he newest Version of CPython in Cygwin is 3.9.9... so unless I can get this change backported, they won't be affected by this (well and even if, ... it would be some more "motivation" to set the missing defines, I guess ;-) ).

I could of course also check whether the symbols are defined, as in:

#if defined(HAVE_SYS_XATTR_H)
#  if defined(__linux__) && !defined(__FreeBSD_kernel__) && !defined(__GNU__)
#    define USE_XATTRS
#    include <linux/limits.h>  // Needed for XATTR_SIZE_MAX on musl libc.
#  endif
#  if defined(__CYGWIN__)
#    include <cygwin/limits.h>  // Needed for XATTR_SIZE_MAX and XATTR_LIST_MAX.
#    if defined(XATTR_SIZE_MAX) && defined(XATTR_LIST_MAX)
#      define USE_XATTRS
#    endif
#  endif
#endif

I found that to be a bit ugly and overkill,... but if Python developers like it more... I wouldn’t mind to adapt my commit.

Thanks

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@cpython-cla-bot
Copy link

cpython-cla-bot bot commented May 30, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@philcerf
Copy link
Contributor Author

For the records:

I've submitted a patch against Cygwin-newlib at https://sourceware.org/pipermail/newlib/2023/020347.html which - to my best knowledge - should set the (hopefully correct) XATTR_*_MAX values.

@philcerf philcerf marked this pull request as ready for review May 30, 2023 11:51
@arhadthedev arhadthedev changed the title gh-90026: support XATTRs on Cygwin (#90026) gh-90026: support XATTRs on Cygwin May 30, 2023
@philcerf
Copy link
Contributor Author

philcerf commented May 30, 2023

Updated commit also changes the documentation in os.rst to indicate that this is then also available on Cygwin.

What I didn't know (Python experts please help ;-) ) was, whether there is a way how you encode that this will be only available with 3.13 (on Cygwin) and not 3.3 (as on Linux). I've grepped a bit but found no obvious way.

@philcerf
Copy link
Contributor Author

Just for the records:

The commit that exports the necessary symbols in Cygwin has just been merged.

So future versions of Cygwin’s cygwin/limits.h should provide XATTR_NAME_MAX, XATTR_SIZE_MAX and XATTR_LIST_MAX for CPython to use on that platform.

Would be awesome if this could be reviewed and still make it into 3.13 at least (not sure if a backport would be feasible - guess it’s probably not important enough ^^).

@iritkatriel
Copy link
Member

Sorry I don't know anything about Cygwin and I'm working on a Mac.

@philcerf
Copy link
Contributor Author

philcerf commented Jul 2, 2023

Maybe one should also adapt:

cpython/Doc/library/os.rst

Lines 3741 to 3742 in 8571b27

Linux extended attributes
~~~~~~~~~~~~~~~~~~~~~~~~~

OTOH, these functions are still "defined" by Linux (FreeBSD and others use different syscalls)... and Cygwin just mimics them. So it may also be justified to let the section named as is.

@philcerf
Copy link
Contributor Author

Anything I can do to get that reviewed? :-)

@philcerf
Copy link
Contributor Author

Rebased on master because of changes made meanwhile to posixmodule.c.

But, TBH, I'm not really sure whether it's worth keeping this MR open, as it seems impossible to get even such an extremely simple change reviewed :-(

Doc/library/os.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philcerf The code looks reasonable to me. I'm not a Cygwin user though.

@encukou Would you be able to give this a look? Thanks. Discourse discussion

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with adding the #ifdef change -- it's a few lines clearly identified as Cygwin-only.
But I'm less sure about the docs update. It suggests that XATTRs will continue to work on Cygwin, but we have no tests to ensure this.
Would you be OK merging without the docs change?

You could also find wording for the docs that doesn't say this strongly that XATTRs are Linux specific -- but IMO it'd again be better to add that to a dedicated “CPython on Cygwin” page (outside CPython).

I'll post more about process on the Discourse discussion.

Doc/library/os.rst Outdated Show resolved Hide resolved
@philcerf
Copy link
Contributor Author

philcerf commented Nov 2, 2023

I'd be okay with a commit without any docs changes (@JelleZijlstra would that be also okay for you, since you've proposed adding the minimum Cygwin version).

May make even sense, cause I guess we don't document all other things that work or don't work with Cygwin - and I think that is reasonable as Cygwin is a compatibility layer, so what they support from the API is purely their business.

I had only added it previously, as strictly speaking Cygwin is a POSIX compatibility layer, whereas the API used for the XATTR is Linux specific.

@JelleZijlstra
Copy link
Member

I'd be okay with a commit without any docs changes (@JelleZijlstra would that be also okay for you, since you've proposed adding the minimum Cygwin version).

Yes, that's fine with me. If we document it, we should mention the CPython version when the change was made, but Petr's suggestion to omit it from the public docs also makes sense.

(Minor feedback: It's generally better to avoid force pushing. We'll squash merge anyway when we merge the PR, and it's easier to follow the review history if there are no force pushes.)

@philcerf
Copy link
Contributor Author

philcerf commented Nov 2, 2023

No idea why that one test failed.

Edit: Ah, now the tests ran through.

@encukou encukou merged commit 7810b69 into python:main Nov 3, 2023
30 checks passed
@encukou
Copy link
Member

encukou commented Nov 3, 2023

Thank you for the contribution!

@philcerf
Copy link
Contributor Author

philcerf commented Nov 3, 2023

Thanks for merging.

Is it feasible to get this backported? Though it's really not that important, if too much of an effort.

@JelleZijlstra
Copy link
Member

I think this counts as a new feature, which we don't backport. However, if you're building from source, you can obviously apply the patch yourself.

aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
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.

7 participants