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

Remove os.tmpnam() and os.tempnam() #45659

Closed
tiran opened this issue Oct 23, 2007 · 11 comments
Closed

Remove os.tmpnam() and os.tempnam() #45659

tiran opened this issue Oct 23, 2007 · 11 comments
Labels
docs Documentation in the Doc dir extension-modules C modules in the Modules dir performance Performance or resource usage

Comments

@tiran
Copy link
Member

tiran commented Oct 23, 2007

BPO 1318
Nosy @gvanrossum, @loewis, @tiran
Files
  • py3k_remove_os_tmpnam.patch
  • py3k_remove_os_tmp.patch
  • 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 2007-10-25.23:19:02.061>
    created_at = <Date 2007-10-23.21:22:21.333>
    labels = ['extension-modules', 'docs', 'performance']
    title = 'Remove os.tmpnam() and os.tempnam()'
    updated_at = <Date 2007-10-25.23:19:02.059>
    user = 'https://github.com/tiran'

    bugs.python.org fields:

    activity = <Date 2007-10-25.23:19:02.059>
    actor = 'gvanrossum'
    assignee = 'none'
    closed = True
    closed_date = <Date 2007-10-25.23:19:02.061>
    closer = 'gvanrossum'
    components = ['Documentation', 'Extension Modules']
    creation = <Date 2007-10-23.21:22:21.333>
    creator = 'christian.heimes'
    dependencies = []
    files = ['8599', '8612']
    hgrepos = []
    issue_num = 1318
    keywords = ['patch']
    message_count = 11.0
    messages = ['56693', '56694', '56695', '56697', '56700', '56738', '56750', '56756', '56758', '56760', '56762']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'loewis', 'christian.heimes']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = 'resource usage'
    url = 'https://bugs.python.org/issue1318'
    versions = ['Python 3.0']

    @tiran
    Copy link
    Member Author

    tiran commented Oct 23, 2007

    I couldn't stand the compiler warnings any more. :)

    The patch removes os.tmpnam() and os.tempnam() from the posix module. It
    also updates the docs and tests. TMP_MAX is kept for the tempfile
    module. I haven't figured out how to remove the defines from pyconfig.h.
    I guess they are always added by autoconf/automake.

    @tiran tiran added docs Documentation in the Doc dir extension-modules C modules in the Modules dir performance Performance or resource usage labels Oct 23, 2007
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Oct 23, 2007

    -1. First, they are linker warnings, not compiler warnings (I suppose),
    plus they are meaningless in the context of Python.

    @gvanrossum
    Copy link
    Member

    Martin, why do we need to keep these when we already have tempfile.py?
    I don't see that they solve any particular POSIX compatibility
    requirement. And they *are* unsafe. (Admitted, sometimes there's no
    alternative -- even tempfile.py still provides unsafe APIs by necessity.)

    @tiran
    Copy link
    Member Author

    tiran commented Oct 23, 2007

    First, you are right. It's not a compiler but a linker warning.

    I don't see the point in keeping the methods. They are dangerous to use,
    warned upon for a long time and they have a sane replacement that does a
    far better job.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Oct 24, 2007

    Removing them because there is a replacement already is a better reason
    than removing them because they give (bogus) warnings, so I'm -0 now.

    As you say, tempfile is not any better from a security point of view in
    the cases where tmpnam or tempnam would be used (e.g. if you want a
    child process create a file whose name you specify).

    Whether the tempfile.py implementation is actually better than the one
    in the C library, I cannot tell (hence the -0: I don't know whether
    tempfile.py or the C library wrapper should be removed). One issue I
    just noticed is that tempfile.mkstemp promise of not inheriting the file
    descriptor is bogus in the presence of threads and race conditions.

    If the rationale for the patch is to eliminate duplication, then
    os.tmpfile should be removed as well.

    @tiran
    Copy link
    Member Author

    tiran commented Oct 25, 2007

    os.tmpfile() is the only method that has no duplicate in tempfile. I
    chose to keep it for this very reason. But you made good point, too.
    What do you think about renaming tmpfile to _tmpfile and make it
    available from the tempfile module as tempfile.tmpfile()?

    I totally agree with your opinion on tmpnam and tempnam. As far as I
    know it's impossible to prevent a child process from doing something
    harmful. The child must be mature enough to do the right think and open
    a file with the correct flags.

    The promise of tempfile.mkstemp is also bogus for every OS except
    Windows. IIRC only Windows supports O_NOINHERIT.

    Let me rephrase the rational for my patch: I want to remove duplicate
    code to have just but one implementation to create a temporary file
    (name). I want the one implementation be under our control and not
    depend on some possible broken or stupid C library like Windows where
    tmpnam may create the temporary files in C:\. I want an unified way to
    get the TEMP dir independent of the API.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Oct 25, 2007

    os.tmpfile() is the only method that has no duplicate in tempfile.

    Why do you say that? tempfile.mkstemp() does essentially the same
    as os.tmpfile().

    The promise of tempfile.mkstemp is also bogus for every OS except
    Windows. IIRC only Windows supports O_NOINHERIT.

    Please read the code. It tries to set the CLOEXEC flag on Unix,
    which should work on most systems.

    Let me rephrase the rational for my patch: I want to remove duplicate
    code to have just but one implementation to create a temporary file
    (name). I want the one implementation be under our control and not
    depend on some possible broken or stupid C library like Windows where
    tmpnam may create the temporary files in C:\. I want an unified way to
    get the TEMP dir independent of the API.

    As I said, I agree with most of this rationale, except that I'm
    uncertain whether it is good to trade a stupid C library for a
    stupid Python implementation.

    With this rationale, again, I think tmpfile should be removed as
    well.

    Regards,
    Martin

    @loewis loewis mannequin changed the title Remove os.tmpnam() and os.tempnam() [patch] Remove os.tmpnam() and os.tempnam() Oct 25, 2007
    @gvanrossum
    Copy link
    Member

    Christian can you revise your patch to also remove os.tmpfile per
    Martin's request? Make sure unit tests and docs are fixed too.

    @tiran
    Copy link
    Member Author

    tiran commented Oct 25, 2007

    Guido van Rossum wrote:

    Christian can you revise your patch to also remove os.tmpfile per
    Martin's request? Make sure unit tests and docs are fixed too.

    I can do that for you. But I still believe that os.tmpfile() works
    different than tempfile.mkstemp(). The former returns a file descriptor
    of a file w/o directory entry and the later a file in tempfile.tempdir.

    Christian

    @gvanrossum
    Copy link
    Member

    2007/10/25, Christian Heimes <report@bugs.python.org>:

    I can do that for you. But I still believe that os.tmpfile() works
    different than tempfile.mkstemp(). The former returns a file descriptor
    of a file w/o directory entry and the later a file in tempfile.tempdir.

    True. But tempfile.TemporaryFile() returns a temp file without a name.

    @gvanrossum
    Copy link
    Member

    Committed revision 58657.

    Thanks!

    @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
    docs Documentation in the Doc dir extension-modules C modules in the Modules dir performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants