summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c26
-rw-r--r--Python/thread.c60
2 files changed, 84 insertions, 2 deletions
diff --git a/Python/import.c b/Python/import.c
index 4159a8ece6..5360d57c51 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1198,6 +1198,7 @@ parse_source_module(PyObject *pathname, FILE *fp)
/* Helper to open a bytecode file for writing in exclusive mode */
+#ifndef MS_WINDOWS
static FILE *
open_exclusive(char *filename, mode_t mode)
{
@@ -1228,6 +1229,7 @@ open_exclusive(char *filename, mode_t mode)
return fopen(filename, "wb");
#endif
}
+#endif
/* Write a compiled module to a file, placing the time of last
@@ -1250,7 +1252,12 @@ write_compiled_module(PyCodeObject *co, PyObject *cpathname,
S_IWUSR | S_IWGRP | S_IWOTH);
PyObject *dirbytes;
#endif
- PyObject *cpathbytes, *dirname;
+#ifdef MS_WINDOWS
+ int fd;
+#else
+ PyObject *cpathbytes;
+#endif
+ PyObject *dirname;
Py_UNICODE *dirsep;
int res, ok;
@@ -1294,6 +1301,16 @@ write_compiled_module(PyCodeObject *co, PyObject *cpathname,
}
Py_DECREF(dirname);
+#ifdef MS_WINDOWS
+ (void)DeleteFileW(PyUnicode_AS_UNICODE(cpathname));
+ fd = _wopen(PyUnicode_AS_UNICODE(cpathname),
+ O_EXCL | O_CREAT | O_WRONLY | O_TRUNC | O_BINARY,
+ mode);
+ if (0 <= fd)
+ fp = fdopen(fd, "wb");
+ else
+ fp = NULL;
+#else
cpathbytes = PyUnicode_EncodeFSDefault(cpathname);
if (cpathbytes == NULL) {
PyErr_Clear();
@@ -1301,11 +1318,14 @@ write_compiled_module(PyCodeObject *co, PyObject *cpathname,
}
fp = open_exclusive(PyBytes_AS_STRING(cpathbytes), mode);
+#endif
if (fp == NULL) {
if (Py_VerboseFlag)
PySys_FormatStderr(
"# can't create %R\n", cpathname);
+#ifndef MS_WINDOWS
Py_DECREF(cpathbytes);
+#endif
return;
}
PyMarshal_WriteLongToFile(pyc_magic, fp, Py_MARSHAL_VERSION);
@@ -1321,11 +1341,13 @@ write_compiled_module(PyCodeObject *co, PyObject *cpathname,
(void)DeleteFileW(PyUnicode_AS_UNICODE(cpathname));
#else
(void) unlink(PyBytes_AS_STRING(cpathbytes));
-#endif
Py_DECREF(cpathbytes);
+#endif
return;
}
+#ifndef MS_WINDOWS
Py_DECREF(cpathbytes);
+#endif
/* Now write the true mtime */
fseek(fp, 4L, 0);
assert(mtime < LONG_MAX);
diff --git a/Python/thread.c b/Python/thread.c
index d224046e64..1f15a22e2f 100644
--- a/Python/thread.c
+++ b/Python/thread.c
@@ -100,6 +100,7 @@ static size_t _pythread_stacksize = 0;
#endif
#ifdef SOLARIS_THREADS
+#define PYTHREAD_NAME "solaris"
#include "thread_solaris.h"
#endif
@@ -115,6 +116,7 @@ static size_t _pythread_stacksize = 0;
#endif
#ifdef _POSIX_THREADS
+#define PYTHREAD_NAME "pthread"
#include "thread_pthread.h"
#endif
@@ -124,14 +126,17 @@ static size_t _pythread_stacksize = 0;
#endif
#ifdef NT_THREADS
+#define PYTHREAD_NAME "nt"
#include "thread_nt.h"
#endif
#ifdef OS2_THREADS
+#define PYTHREAD_NAME "os2"
#include "thread_os2.h"
#endif
#ifdef PLAN9_THREADS
+#define PYTHREAD_NAME "plan9"
#include "thread_plan9.h"
#endif
@@ -409,3 +414,58 @@ PyThread_ReInitTLS(void)
}
#endif /* Py_HAVE_NATIVE_TLS */
+
+PyObject*
+_PyThread_Info(void)
+{
+ PyObject *info, *value;
+ int ret;
+#if (defined(_POSIX_THREADS) && defined(HAVE_CONFSTR) \
+ && defined(_CS_GNU_LIBPTHREAD_VERSION))
+ char buffer[255];
+ int len;
+#endif
+
+ info = PyDict_New();
+ if (info == NULL)
+ return NULL;
+
+ value = PyUnicode_FromString(PYTHREAD_NAME);
+ ret = PyDict_SetItemString(info, "name", value);
+ Py_DECREF(value);
+ if (ret)
+ goto error;
+
+#ifdef _POSIX_THREADS
+#ifdef USE_SEMAPHORES
+ value = PyUnicode_FromString("semaphore");
+#else
+ value = PyUnicode_FromString("mutex+cond");
+#endif
+ if (value == NULL)
+ return NULL;
+ ret = PyDict_SetItemString(info, "lock_implementation", value);
+ Py_DECREF(value);
+ if (ret)
+ goto error;
+
+#if defined(HAVE_CONFSTR) && defined(_CS_GNU_LIBPTHREAD_VERSION)
+ len = confstr(_CS_GNU_LIBPTHREAD_VERSION, buffer, sizeof(buffer));
+ if (0 < len && len < sizeof(buffer)) {
+ value = PyUnicode_DecodeFSDefaultAndSize(buffer, len-1);
+ if (value == NULL)
+ goto error;
+ ret = PyDict_SetItemString(info, "pthread_version", value);
+ Py_DECREF(value);
+ if (ret)
+ goto error;
+ }
+#endif
+#endif
+
+ return info;
+
+error:
+ Py_DECREF(info);
+ return NULL;
+}