Skip to content

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

Closed

Description

@tiran
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']

    Activity

    1. tiran commented on Oct 23, 2007

      @tiran
      MemberAuthor

      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.

    2. added
      docsDocumentation in the Doc dir
      performancePerformance or resource usage
      on Oct 23, 2007
    3. loewis commented on Oct 23, 2007

      loewismannequin
      Mannequin

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

    4. gvanrossum commented on Oct 23, 2007

      @gvanrossum
      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.)

    5. tiran commented on Oct 23, 2007

      @tiran
      MemberAuthor

      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.

    6. loewis commented on Oct 24, 2007

      loewismannequin
      Mannequin

      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.

    7. tiran commented on Oct 25, 2007

      @tiran
      MemberAuthor

      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.

    8. loewis commented on Oct 25, 2007

      loewismannequin
      Mannequin

      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

    9. changed the title [-]Remove os.tmpnam() and os.tempnam() [patch][/-] [+]Remove os.tmpnam() and os.tempnam()[/+] on Oct 25, 2007
    10. gvanrossum commented on Oct 25, 2007

      @gvanrossum
      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.

    11. tiran commented on Oct 25, 2007

      @tiran
      MemberAuthor

      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

    12. gvanrossum commented on Oct 25, 2007

      @gvanrossum
      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.

    13. gvanrossum commented on Oct 25, 2007

      @gvanrossum
      Member

      Committed revision 58657.

      Thanks!

    14. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      docsDocumentation in the Doc dirextension-modulesC modules in the Modules dirperformancePerformance or resource usage

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions