GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-29176 Use tmpfile() in curses module by tiran · Pull Request #235 · python/cpython

bpo-29176 Use tmpfile() in curses module #235

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.

Sign up for GitHub

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

Merged
vstinner merged 1 commit into python:master from tiran:bpo29176_curses_tmpfile
Mar 2, 2017

Uh oh!

There was an error while loading. Please reload this page.

Merged

bpo-29176 Use tmpfile() in curses module #235

Changes from all commits
Commits
Show all changes
1 commit
Select commit
8353365
bpo-29176 Use tmpfile() in curses module
tiran Feb 22, 2017
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

52 changes: 15 additions & 37 deletions 52 Modules/_cursesmodule.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1720,22 +1720,14 @@ PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *stream)
{
/* We have to simulate this by writing to a temporary FILE*,
then reading back, then writing to the argument stream. */
char fn[100];
int fd = -1;
FILE *fp = NULL;
FILE *fp;
PyObject *res = NULL;

strcpy(fn, "/tmp/py.curses.putwin.XXXXXX");
fd = mkstemp(fn);
if (fd < 0)
return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
if (_Py_set_inheritable(fd, 0, NULL) < 0)
goto exit;
fp = fdopen(fd, "wb+");
if (fp == NULL) {
PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
fp = tmpfile();
if (fp == NULL)
return PyErr_SetFromErrno(PyExc_OSError);
if (_Py_set_inheritable(fileno(fp), 0, NULL) < 0)
goto exit;
}
res = PyCursesCheckERR(putwin(self->win, fp), "putwin");
if (res == NULL)
goto exit;
Expand All @@ -1754,11 +1746,7 @@ PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *stream)
}

exit:
if (fp != NULL)
fclose(fp);
else if (fd != -1)
close(fd);
remove(fn);
fclose(fp);
return res;
}

Expand Down Expand Up @@ -2278,9 +2266,7 @@ PyCurses_UngetMouse(PyObject *self, PyObject *args)
static PyObject *
PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
{
char fn[100];
int fd = -1;
FILE *fp = NULL;
FILE *fp;
PyObject *data;
size_t datalen;
WINDOW *win;
Expand All @@ -2289,17 +2275,13 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)

PyCursesInitialised;

strcpy(fn, "/tmp/py.curses.getwin.XXXXXX");
fd = mkstemp(fn);
if (fd < 0)
return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
if (_Py_set_inheritable(fd, 0, NULL) < 0)
goto error;
fp = fdopen(fd, "wb+");
if (fp == NULL) {
PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
fp = tmpfile();
if (fp == NULL)
return PyErr_SetFromErrno(PyExc_OSError);

if (_Py_set_inheritable(fileno(fp), 0, NULL) < 0)
goto error;
}


data = _PyObject_CallMethodId(stream, &PyId_read, NULL);
if (data == NULL)
Expand All @@ -2314,7 +2296,7 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
datalen = PyBytes_GET_SIZE(data);
if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) {
Py_DECREF(data);
PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
PyErr_SetFromErrno(PyExc_OSError);
goto error;
}
Py_DECREF(data);
Expand All @@ -2328,11 +2310,7 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
res = PyCursesWindow_New(win, NULL);

error:
if (fp != NULL)
fclose(fp);
else if (fd != -1)
close(fd);
remove(fn);
fclose(fp);
return res;
}

Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.