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

Python/import.c still references fstat even with DONT_HAVE_FSTAT/!HAVE_FSTAT #56291

Closed
joshtriplett mannequin opened this issue May 15, 2011 · 16 comments
Closed

Python/import.c still references fstat even with DONT_HAVE_FSTAT/!HAVE_FSTAT #56291

joshtriplett mannequin opened this issue May 15, 2011 · 16 comments
Labels
build The build process and cross-build

Comments

@joshtriplett
Copy link
Mannequin

joshtriplett mannequin commented May 15, 2011

BPO 12082
Nosy @brettcannon, @ncoghlan, @pitrou, @vstinner, @giampaolo, @ericsnowcurrently, @akheron
Superseder
  • bpo-23753: Drop HAVE_FSTAT: require fstat() to compile/use Python
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2015-04-09.13:20:48.312>
    created_at = <Date 2011-05-15.23:45:18.448>
    labels = ['build']
    title = 'Python/import.c still references fstat even with DONT_HAVE_FSTAT/!HAVE_FSTAT'
    updated_at = <Date 2015-04-09.13:20:48.311>
    user = 'https://bugs.python.org/joshtriplett'

    bugs.python.org fields:

    activity = <Date 2015-04-09.13:20:48.311>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-04-09.13:20:48.312>
    closer = 'r.david.murray'
    components = ['Build']
    creation = <Date 2011-05-15.23:45:18.448>
    creator = 'joshtriplett'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 12082
    keywords = []
    message_count = 16.0
    messages = ['136055', '136065', '136937', '136943', '137059', '137296', '137319', '137323', '137324', '137358', '137364', '137365', '175269', '175418', '175464', '189582']
    nosy_count = 9.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'pitrou', 'vstinner', 'joshtriplett', 'giampaolo.rodola', 'eric.snow', 'petri.lehtinen', 'chromatix']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '23753'
    type = 'compile error'
    url = 'https://bugs.python.org/issue12082'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4']

    @joshtriplett
    Copy link
    Mannequin Author

    joshtriplett mannequin commented May 15, 2011

    Even if pyconfig.h defines DONT_HAVE_STAT and DONT_HAVE_FSTAT (which prevents the definitions of HAVE_STAT and HAVE_FSTAT), Python still references fstat in Python/import.c, along with struct stat and constants like S_IXUSR. I ran into this when attempting to compile Python for an embedded platform, which has some basic file operations but does not have stat. (I will likely end up faking fstat for now, but I'd rather not have to do so.)

    @joshtriplett joshtriplett mannequin added build The build process and cross-build labels May 15, 2011
    @vstinner
    Copy link
    Member

    Oh, so it's possible to not have the fstat() syscall. I asked me the question when I modified import.c (and other files related to importing a module).

    @akheron
    Copy link
    Member

    akheron commented May 26, 2011

    Should the .pyc/.pyo file writing be disabled altogether if stat() and/or fstat() is not available. In this case, there's no way to check mtimes, right?

    @vstinner
    Copy link
    Member

    Does your filesystem store the modification time? Why don't you have/want fstat()? Do you have stat() or a similar function?

    @joshtriplett
    Copy link
    Mannequin Author

    joshtriplett mannequin commented May 27, 2011

    GRUB's filesystem drivers don't support reading mtime. And no, no form of stat() function exists, f or otherwise.

    On a related note, without HAVE_STAT, import.c can't import package modules at all, since it uses stat to check in advance for a directory. In the spirit of Python's usual "try it and see if it works" approach, why not just try opening foo/init.py, and if that doesn't work try opening foo.py?

    @vstinner
    Copy link
    Member

    Should the .pyc/.pyo file writing be disabled altogether
    if stat() and/or fstat() is not available.

    If we cannot get the file modification time, .pyc/.pyo writing must be disabled. If your OS/libc/filesystem doesn't have fstat(), you don't have file modification, so no .pyc/.pyo write.

    @akheron
    Copy link
    Member

    akheron commented May 30, 2011

    STINNER Victor wrote:

    If we cannot get the file modification time, .pyc/.pyo writing must be disabled. If your OS/libc/filesystem doesn't have fstat(), you don't have file modification, so no .pyc/.pyo write.

    Should I go on and write a patch? Any hints on how this code path (of
    not writing .pyc/.pyo because of missing stat() and fstat()) could be
    tested?

    @joshtriplett
    Copy link
    Mannequin Author

    joshtriplett mannequin commented May 30, 2011

    Given that GRUB doesn't support writing to filesystems at all, I already have to set Py_DontWriteBytecodeFlag, so disabling .pyc/.pyo entirely would work fine for my use case.

    @vstinner
    Copy link
    Member

    Should I go on and write a patch?

    Yes please, write a patch, I will review it.

    To emulate a system without stat or fstat, you may use:
    #define fstat dont_have_fstat
    #define stat dont_have_stat

    The link will fail if the code still refer to fstat() or stat().

    @akheron
    Copy link
    Member

    akheron commented May 31, 2011

    I tried to compile Python 3.3 (from default branch) with DONT_HAVE_FSTAT and DONT_HAVE_STAT. It seems to depend even more heavily on stat() being available, in other files than Python/import.c.

    With 2.7, it was quite easy to disable the .pyc/.pyo writing in the absence of fstat(), but the NullImporter needs to be able to check for a directory. In addition, the build process fails when trying to run "setup.py build", because distutils cannot be imported. And it cannot be imported because it's a package, and packages (directories) cannot be detected without having stat().

    So... Unless we have another way to check for a directory, I'm not sure whether it will be possible to compile Python at all without stat().

    @joshtriplett
    Copy link
    Mannequin Author

    joshtriplett mannequin commented May 31, 2011

    Rather than checking for a directory, how about just opening foo/init.py, and if that fails opening foo.py?

    @akheron
    Copy link
    Member

    akheron commented May 31, 2011

    The NullImporter is documented to raise ImportError on directories, not directories containing __init__.py:

    http://docs.python.org/library/imp.html#imp.NullImporter
    

    Checking for __init__.py{,c,o} seems doable to me without having stat().

    @pitrou
    Copy link
    Member

    pitrou commented Nov 10, 2012

    My vote is for won't fix. Systems without stat() or fstat() are clearly broken from Python's point of view; at the very least, they aren't POSIX-compliant.

    @akheron
    Copy link
    Member

    akheron commented Nov 12, 2012

    Should the defines be removed then, because they're kind of false promises for the user.

    @chromatix
    Copy link
    Mannequin

    chromatix mannequin commented Nov 12, 2012

    Actually many people try to compile python on an environment with freestanding C library, so this can be a specific case of that. Is there any issue or thread where compiling python with freestanding headers is discussed? As this relates to that.

    Shall you remove the defines, please put instructions in the source code to let user know how they can provide their self-invented fstat function to the code.

    @pitrou
    Copy link
    Member

    pitrou commented May 19, 2013

    For those of you who are concerned with this issue, could you explain your use case on the following discussion thread: http://mail.python.org/pipermail/python-dev/2013-May/126285.html ?

    I would personally like to remove HAVE_FSTAT and make Python unconditionally use fstat(). It will make the code quite simpler in some places.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    build The build process and cross-build
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants