Compare commits
4 Commits
550e4673be
...
35cacce525
Author | SHA1 | Date |
---|---|---|
Andre Delfino | 35cacce525 | |
pxinwr | d5dcb65317 | |
Victor Stinner | a82f63f5af | |
Victor Stinner | ca06440207 |
|
@ -1174,7 +1174,9 @@ functions.
|
|||
| | to ``'a'``. |
|
||||
+--------------+---------------------------------------------+
|
||||
| *format* | Use the specified format string for the |
|
||||
| | handler. |
|
||||
| | handler. Defaults to attributes |
|
||||
| | ``levelname``, ``name`` and ``message`` |
|
||||
| | separated by colons. |
|
||||
+--------------+---------------------------------------------+
|
||||
| *datefmt* | Use the specified date/time format, as |
|
||||
| | accepted by :func:`time.strftime`. |
|
||||
|
|
|
@ -95,10 +95,6 @@ PyAPI_FUNC(FILE *) _Py_wfopen(
|
|||
const wchar_t *path,
|
||||
const wchar_t *mode);
|
||||
|
||||
PyAPI_FUNC(FILE*) _Py_fopen(
|
||||
const char *pathname,
|
||||
const char *mode);
|
||||
|
||||
PyAPI_FUNC(FILE*) _Py_fopen_obj(
|
||||
PyObject *path,
|
||||
const char *mode);
|
||||
|
|
|
@ -44,6 +44,7 @@ PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(PyObject *), PyObject *);
|
|||
PyAPI_FUNC(void) _Py_RestoreSignals(void);
|
||||
|
||||
PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
|
||||
PyAPI_FUNC(int) _Py_FdIsInteractive(FILE *fp, PyObject *filename);
|
||||
|
||||
PyAPI_FUNC(void) _Py_SetProgramFullPath(const wchar_t *);
|
||||
|
||||
|
|
|
@ -13,6 +13,11 @@ PyAPI_FUNC(int) PyRun_AnyFileExFlags(
|
|||
const char *filename, /* decoded from the filesystem encoding */
|
||||
int closeit,
|
||||
PyCompilerFlags *flags);
|
||||
PyAPI_FUNC(int) _PyRun_AnyFileObject(
|
||||
FILE *fp,
|
||||
PyObject *filename,
|
||||
int closeit,
|
||||
PyCompilerFlags *flags);
|
||||
PyAPI_FUNC(int) PyRun_SimpleFileExFlags(
|
||||
FILE *fp,
|
||||
const char *filename, /* decoded from the filesystem encoding */
|
||||
|
@ -30,6 +35,10 @@ PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
|
|||
FILE *fp,
|
||||
const char *filename, /* decoded from the filesystem encoding */
|
||||
PyCompilerFlags *flags);
|
||||
PyAPI_FUNC(int) _PyRun_InteractiveLoopObject(
|
||||
FILE *fp,
|
||||
PyObject *filename,
|
||||
PyCompilerFlags *flags);
|
||||
|
||||
|
||||
PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
Remove the private :c:func:`_Py_fopen` function which is no longer needed.
|
||||
Use :c:func:`_Py_wfopen` or :c:func:`_Py_fopen_obj` instead. Patch by Victor
|
||||
Stinner.
|
|
@ -0,0 +1 @@
|
|||
Define THREAD_STACK_SIZE for VxWorks.
|
|
@ -313,17 +313,8 @@ pymain_run_file(const PyConfig *config, PyCompilerFlags *cf)
|
|||
}
|
||||
FILE *fp = _Py_wfopen(filename, L"rb");
|
||||
if (fp == NULL) {
|
||||
char *cfilename_buffer;
|
||||
const char *cfilename;
|
||||
int err = errno;
|
||||
cfilename_buffer = _Py_EncodeLocaleRaw(filename, NULL);
|
||||
if (cfilename_buffer != NULL)
|
||||
cfilename = cfilename_buffer;
|
||||
else
|
||||
cfilename = "<unprintable file name>";
|
||||
fprintf(stderr, "%ls: can't open file '%s': [Errno %d] %s\n",
|
||||
config->program_name, cfilename, err, strerror(err));
|
||||
PyMem_RawFree(cfilename_buffer);
|
||||
fprintf(stderr, "%ls: can't open file '%ls': [Errno %d] %s\n",
|
||||
config->program_name, filename, errno, strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
@ -353,25 +344,15 @@ pymain_run_file(const PyConfig *config, PyCompilerFlags *cf)
|
|||
return pymain_exit_err_print();
|
||||
}
|
||||
|
||||
PyObject *unicode, *bytes = NULL;
|
||||
const char *filename_str;
|
||||
|
||||
unicode = PyUnicode_FromWideChar(filename, wcslen(filename));
|
||||
if (unicode != NULL) {
|
||||
bytes = PyUnicode_EncodeFSDefault(unicode);
|
||||
Py_DECREF(unicode);
|
||||
}
|
||||
if (bytes != NULL) {
|
||||
filename_str = PyBytes_AsString(bytes);
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
filename_str = "<filename encoding error>";
|
||||
PyObject *filename_obj = PyUnicode_FromWideChar(filename, -1);
|
||||
if (filename_obj == NULL) {
|
||||
PyErr_Print();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* PyRun_AnyFileExFlags(closeit=1) calls fclose(fp) before running code */
|
||||
int run = PyRun_AnyFileExFlags(fp, filename_str, 1, cf);
|
||||
Py_XDECREF(bytes);
|
||||
int run = _PyRun_AnyFileObject(fp, filename_obj, 1, cf);
|
||||
Py_XDECREF(filename_obj);
|
||||
return (run != 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -1455,33 +1455,6 @@ _Py_wfopen(const wchar_t *path, const wchar_t *mode)
|
|||
return f;
|
||||
}
|
||||
|
||||
/* Wrapper to fopen().
|
||||
|
||||
The file descriptor is created non-inheritable.
|
||||
|
||||
If interrupted by a signal, fail with EINTR. */
|
||||
FILE*
|
||||
_Py_fopen(const char *pathname, const char *mode)
|
||||
{
|
||||
PyObject *pathname_obj = PyUnicode_DecodeFSDefault(pathname);
|
||||
if (pathname_obj == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (PySys_Audit("open", "Osi", pathname_obj, mode, 0) < 0) {
|
||||
Py_DECREF(pathname_obj);
|
||||
return NULL;
|
||||
}
|
||||
Py_DECREF(pathname_obj);
|
||||
|
||||
FILE *f = fopen(pathname, mode);
|
||||
if (f == NULL)
|
||||
return NULL;
|
||||
if (make_non_inheritable(fileno(f)) < 0) {
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/* Open a file. Call _wfopen() on Windows, or encode the path to the filesystem
|
||||
encoding and call fopen() otherwise.
|
||||
|
|
|
@ -2739,6 +2739,21 @@ Py_FdIsInteractive(FILE *fp, const char *filename)
|
|||
}
|
||||
|
||||
|
||||
int
|
||||
_Py_FdIsInteractive(FILE *fp, PyObject *filename)
|
||||
{
|
||||
if (isatty((int)fileno(fp))) {
|
||||
return 1;
|
||||
}
|
||||
if (!Py_InteractiveFlag) {
|
||||
return 0;
|
||||
}
|
||||
return (filename == NULL) ||
|
||||
(PyUnicode_CompareWithASCIIString(filename, "<stdin>") == 0) ||
|
||||
(PyUnicode_CompareWithASCIIString(filename, "???") == 0);
|
||||
}
|
||||
|
||||
|
||||
/* Wrappers around sigaction() or signal(). */
|
||||
|
||||
PyOS_sighandler_t
|
||||
|
|
|
@ -67,44 +67,69 @@ static PyObject* pyrun_file(FILE *fp, PyObject *filename, int start,
|
|||
PyCompilerFlags *flags);
|
||||
|
||||
|
||||
int
|
||||
_PyRun_AnyFileObject(FILE *fp, PyObject *filename, int closeit,
|
||||
PyCompilerFlags *flags)
|
||||
{
|
||||
int decref_filename = 0;
|
||||
if (filename == NULL) {
|
||||
filename = PyUnicode_FromString("???");
|
||||
if (filename == NULL) {
|
||||
PyErr_Print();
|
||||
return -1;
|
||||
}
|
||||
decref_filename = 1;
|
||||
}
|
||||
|
||||
int res;
|
||||
if (_Py_FdIsInteractive(fp, filename)) {
|
||||
res = _PyRun_InteractiveLoopObject(fp, filename, flags);
|
||||
if (closeit) {
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
else {
|
||||
res = _PyRun_SimpleFileObject(fp, filename, closeit, flags);
|
||||
}
|
||||
|
||||
if (decref_filename) {
|
||||
Py_DECREF(filename);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/* Parse input from a file and execute it */
|
||||
int
|
||||
PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit,
|
||||
PyCompilerFlags *flags)
|
||||
{
|
||||
if (filename == NULL)
|
||||
filename = "???";
|
||||
if (Py_FdIsInteractive(fp, filename)) {
|
||||
int err = PyRun_InteractiveLoopFlags(fp, filename, flags);
|
||||
if (closeit)
|
||||
fclose(fp);
|
||||
return err;
|
||||
PyObject *filename_obj;
|
||||
if (filename != NULL) {
|
||||
filename_obj = PyUnicode_DecodeFSDefault(filename);
|
||||
if (filename_obj == NULL) {
|
||||
PyErr_Print();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
return PyRun_SimpleFileExFlags(fp, filename, closeit, flags);
|
||||
else {
|
||||
filename_obj = NULL;
|
||||
}
|
||||
int res = _PyRun_AnyFileObject(fp, filename_obj, closeit, flags);
|
||||
Py_XDECREF(filename_obj);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
PyRun_InteractiveLoopFlags(FILE *fp, const char *filename_str, PyCompilerFlags *flags)
|
||||
_PyRun_InteractiveLoopObject(FILE *fp, PyObject *filename, PyCompilerFlags *flags)
|
||||
{
|
||||
PyObject *filename, *v;
|
||||
int ret, err;
|
||||
PyCompilerFlags local_flags = _PyCompilerFlags_INIT;
|
||||
int nomem_count = 0;
|
||||
#ifdef Py_REF_DEBUG
|
||||
int show_ref_count = _Py_GetConfig()->show_ref_count;
|
||||
#endif
|
||||
|
||||
filename = PyUnicode_DecodeFSDefault(filename_str);
|
||||
if (filename == NULL) {
|
||||
PyErr_Print();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flags == NULL) {
|
||||
flags = &local_flags;
|
||||
}
|
||||
v = _PySys_GetObjectId(&PyId_ps1);
|
||||
|
||||
PyObject *v = _PySys_GetObjectId(&PyId_ps1);
|
||||
if (v == NULL) {
|
||||
_PySys_SetObjectId(&PyId_ps1, v = PyUnicode_FromString(">>> "));
|
||||
Py_XDECREF(v);
|
||||
|
@ -114,7 +139,13 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename_str, PyCompilerFlags *
|
|||
_PySys_SetObjectId(&PyId_ps2, v = PyUnicode_FromString("... "));
|
||||
Py_XDECREF(v);
|
||||
}
|
||||
err = 0;
|
||||
|
||||
#ifdef Py_REF_DEBUG
|
||||
int show_ref_count = _Py_GetConfig()->show_ref_count;
|
||||
#endif
|
||||
int err = 0;
|
||||
int ret;
|
||||
int nomem_count = 0;
|
||||
do {
|
||||
ret = PyRun_InteractiveOneObjectEx(fp, filename, flags);
|
||||
if (ret == -1 && PyErr_Occurred()) {
|
||||
|
@ -141,10 +172,26 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename_str, PyCompilerFlags *
|
|||
}
|
||||
#endif
|
||||
} while (ret != E_EOF);
|
||||
Py_DECREF(filename);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)
|
||||
{
|
||||
PyObject *filename_obj = PyUnicode_DecodeFSDefault(filename);
|
||||
if (filename_obj == NULL) {
|
||||
PyErr_Print();
|
||||
return -1;
|
||||
}
|
||||
|
||||
int err = _PyRun_InteractiveLoopObject(fp, filename_obj, flags);
|
||||
Py_DECREF(filename_obj);
|
||||
return err;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* A PyRun_InteractiveOneObject() auxiliary function that does not print the
|
||||
* error on failure. */
|
||||
static int
|
||||
|
|
|
@ -62,6 +62,10 @@
|
|||
# define THREAD_STACK_SIZE 0x800000
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__VXWORKS__) && defined(THREAD_STACK_SIZE) && THREAD_STACK_SIZE == 0
|
||||
#undef THREAD_STACK_SIZE
|
||||
#define THREAD_STACK_SIZE 0x100000
|
||||
#endif
|
||||
/* for safety, ensure a viable minimum stacksize */
|
||||
#define THREAD_STACK_MIN 0x8000 /* 32 KiB */
|
||||
#else /* !_POSIX_THREAD_ATTR_STACKSIZE */
|
||||
|
|
Loading…
Reference in New Issue