summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2011-06-05 06:05:19 (GMT)
committerGregory P. Smith <greg@krypto.org>2011-06-05 06:05:19 (GMT)
commitd64b2bae9b4d1b761cd16f75e3fe3e9c19533b3e (patch)
treecac5baf3e31b67e39cb9b69d982958cc9419db06 /Modules
parentb6471db8a76416b2eb49fe9b02c6f9f9a6502b4d (diff)
parente13e662244b4915e933eb2c84bc50705f99f5c4a (diff)
downloadcpython-d64b2bae9b4d1b761cd16f75e3fe3e9c19533b3e.zip
cpython-d64b2bae9b4d1b761cd16f75e3fe3e9c19533b3e.tar.gz
cpython-d64b2bae9b4d1b761cd16f75e3fe3e9c19533b3e.tar.bz2
merge heads.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/_iomodule.c3
-rw-r--r--Modules/_io/_iomodule.h1
-rw-r--r--Modules/_io/bufferedio.c53
-rw-r--r--Modules/_io/fileio.c39
-rw-r--r--Modules/_io/iobase.c8
-rw-r--r--Modules/_io/textio.c9
-rw-r--r--Modules/_posixsubprocess.c4
-rw-r--r--Modules/_sqlite/connection.c2
-rw-r--r--Modules/_ssl.c67
-rw-r--r--Modules/_threadmodule.c2
-rw-r--r--Modules/cjkcodecs/_codecs_hk.c93
-rw-r--r--Modules/cjkcodecs/_codecs_jp.c10
-rw-r--r--Modules/cjkcodecs/multibytecodec.c22
-rw-r--r--Modules/faulthandler.c11
-rw-r--r--Modules/parsermodule.c5
-rw-r--r--Modules/posixmodule.c51
-rw-r--r--Modules/pyexpat.c21
-rw-r--r--Modules/signalmodule.c9
-rw-r--r--Modules/socketmodule.c9
-rw-r--r--Modules/zipimport.c2
20 files changed, 288 insertions, 133 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
index 44bdac6..6f5bd48 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -36,6 +36,7 @@ PyObject *_PyIO_str_nl;
PyObject *_PyIO_str_read;
PyObject *_PyIO_str_read1;
PyObject *_PyIO_str_readable;
+PyObject *_PyIO_str_readall;
PyObject *_PyIO_str_readinto;
PyObject *_PyIO_str_readline;
PyObject *_PyIO_str_reset;
@@ -767,6 +768,8 @@ PyInit__io(void)
goto fail;
if (!(_PyIO_str_readable = PyUnicode_InternFromString("readable")))
goto fail;
+ if (!(_PyIO_str_readall = PyUnicode_InternFromString("readall")))
+ goto fail;
if (!(_PyIO_str_readinto = PyUnicode_InternFromString("readinto")))
goto fail;
if (!(_PyIO_str_readline = PyUnicode_InternFromString("readline")))
diff --git a/Modules/_io/_iomodule.h b/Modules/_io/_iomodule.h
index 925e4f2..9174bdd 100644
--- a/Modules/_io/_iomodule.h
+++ b/Modules/_io/_iomodule.h
@@ -155,6 +155,7 @@ extern PyObject *_PyIO_str_nl;
extern PyObject *_PyIO_str_read;
extern PyObject *_PyIO_str_read1;
extern PyObject *_PyIO_str_readable;
+extern PyObject *_PyIO_str_readall;
extern PyObject *_PyIO_str_readinto;
extern PyObject *_PyIO_str_readline;
extern PyObject *_PyIO_str_reset;
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 3b8b7e9..cdaa36e 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -589,7 +589,7 @@ _bufferedreader_reset_buf(buffered *self);
static void
_bufferedwriter_reset_buf(buffered *self);
static PyObject *
-_bufferedreader_peek_unlocked(buffered *self, Py_ssize_t);
+_bufferedreader_peek_unlocked(buffered *self);
static PyObject *
_bufferedreader_read_all(buffered *self);
static PyObject *
@@ -797,7 +797,7 @@ buffered_peek(buffered *self, PyObject *args)
goto end;
Py_CLEAR(res);
}
- res = _bufferedreader_peek_unlocked(self, n);
+ res = _bufferedreader_peek_unlocked(self);
end:
LEAVE_BUFFERED(self)
@@ -1407,32 +1407,57 @@ static PyObject *
_bufferedreader_read_all(buffered *self)
{
Py_ssize_t current_size;
- PyObject *res, *data = NULL;
- PyObject *chunks = PyList_New(0);
-
- if (chunks == NULL)
- return NULL;
+ PyObject *res, *data = NULL, *chunk, *chunks;
/* First copy what we have in the current buffer. */
current_size = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t);
if (current_size) {
data = PyBytes_FromStringAndSize(
self->buffer + self->pos, current_size);
- if (data == NULL) {
- Py_DECREF(chunks);
+ if (data == NULL)
return NULL;
- }
}
_bufferedreader_reset_buf(self);
/* We're going past the buffer's bounds, flush it */
if (self->writable) {
res = _bufferedwriter_flush_unlocked(self, 1);
- if (res == NULL) {
- Py_DECREF(chunks);
+ if (res == NULL)
return NULL;
- }
Py_CLEAR(res);
}
+
+ if (PyObject_HasAttr(self->raw, _PyIO_str_readall)) {
+ chunk = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_readall, NULL);
+ if (chunk == NULL)
+ return NULL;
+ if (chunk != Py_None && !PyBytes_Check(chunk)) {
+ Py_XDECREF(data);
+ Py_DECREF(chunk);
+ PyErr_SetString(PyExc_TypeError, "readall() should return bytes");
+ return NULL;
+ }
+ if (chunk == Py_None) {
+ if (current_size == 0)
+ return chunk;
+ else {
+ Py_DECREF(chunk);
+ return data;
+ }
+ }
+ else if (current_size) {
+ PyBytes_Concat(&data, chunk);
+ Py_DECREF(chunk);
+ if (data == NULL)
+ return NULL;
+ return data;
+ } else
+ return chunk;
+ }
+
+ chunks = PyList_New(0);
+ if (chunks == NULL)
+ return NULL;
+
while (1) {
if (data) {
if (PyList_Append(chunks, data) < 0) {
@@ -1586,7 +1611,7 @@ error:
}
static PyObject *
-_bufferedreader_peek_unlocked(buffered *self, Py_ssize_t n)
+_bufferedreader_peek_unlocked(buffered *self)
{
Py_ssize_t have, r;
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 1aa5ee9..b3b9e44 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -547,14 +547,14 @@ fileio_readinto(fileio *self, PyObject *args)
}
static size_t
-new_buffersize(fileio *self, size_t currentsize)
+new_buffersize(fileio *self, size_t currentsize
+#ifdef HAVE_FSTAT
+ , off_t pos, off_t end
+#endif
+ )
{
#ifdef HAVE_FSTAT
- off_t pos, end;
- struct stat st;
- if (fstat(self->fd, &st) == 0) {
- end = st.st_size;
- pos = lseek(self->fd, 0L, SEEK_CUR);
+ if (end != (off_t)-1) {
/* Files claiming a size smaller than SMALLCHUNK may
actually be streaming pseudo-files. In this case, we
apply the more aggressive algorithm below.
@@ -579,10 +579,17 @@ new_buffersize(fileio *self, size_t currentsize)
static PyObject *
fileio_readall(fileio *self)
{
+#ifdef HAVE_FSTAT
+ struct stat st;
+ off_t pos, end;
+#endif
PyObject *result;
Py_ssize_t total = 0;
int n;
+ size_t newsize;
+ if (self->fd < 0)
+ return err_closed();
if (!_PyVerify_fd(self->fd))
return PyErr_SetFromErrno(PyExc_IOError);
@@ -590,8 +597,23 @@ fileio_readall(fileio *self)
if (result == NULL)
return NULL;
+#ifdef HAVE_FSTAT
+#if defined(MS_WIN64) || defined(MS_WINDOWS)
+ pos = _lseeki64(self->fd, 0L, SEEK_CUR);
+#else
+ pos = lseek(self->fd, 0L, SEEK_CUR);
+#endif
+ if (fstat(self->fd, &st) == 0)
+ end = st.st_size;
+ else
+ end = (off_t)-1;
+#endif
while (1) {
- size_t newsize = new_buffersize(self, total);
+#ifdef HAVE_FSTAT
+ newsize = new_buffersize(self, total, pos, end);
+#else
+ newsize = new_buffersize(self, total);
+#endif
if (newsize > PY_SSIZE_T_MAX || newsize <= 0) {
PyErr_SetString(PyExc_OverflowError,
"unbounded read returned more bytes "
@@ -630,6 +652,9 @@ fileio_readall(fileio *self)
return NULL;
}
total += n;
+#ifdef HAVE_FSTAT
+ pos += n;
+#endif
}
if (PyBytes_GET_SIZE(result) > total) {
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index ec7a242..f06f562 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -815,6 +815,14 @@ rawiobase_readall(PyObject *self, PyObject *args)
Py_DECREF(chunks);
return NULL;
}
+ if (data == Py_None) {
+ if (PyList_GET_SIZE(chunks) == 0) {
+ Py_DECREF(chunks);
+ return data;
+ }
+ Py_DECREF(data);
+ break;
+ }
if (!PyBytes_Check(data)) {
Py_DECREF(chunks);
Py_DECREF(data);
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 35bd922..70d062b 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -1513,8 +1513,13 @@ textiowrapper_read(textio *self, PyObject *args)
PyObject *decoded;
if (bytes == NULL)
goto fail;
- decoded = PyObject_CallMethodObjArgs(self->decoder, _PyIO_str_decode,
- bytes, Py_True, NULL);
+
+ if (Py_TYPE(self->decoder) == &PyIncrementalNewlineDecoder_Type)
+ decoded = _PyIncrementalNewlineDecoder_decode(self->decoder,
+ bytes, 1);
+ else
+ decoded = PyObject_CallMethodObjArgs(
+ self->decoder, _PyIO_str_decode, bytes, Py_True, NULL);
Py_DECREF(bytes);
if (decoded == NULL)
goto fail;
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c
index bf10cbb..af0d971 100644
--- a/Modules/_posixsubprocess.c
+++ b/Modules/_posixsubprocess.c
@@ -1,7 +1,7 @@
/* Authors: Gregory P. Smith & Jeffrey Yasskin */
#include "Python.h"
-#ifdef HAVE_PIPE2
-#define _GNU_SOURCE
+#if defined(HAVE_PIPE2) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
#endif
#include <unistd.h>
#include <fcntl.h>
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 76d635a..3c83c7c 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -200,11 +200,13 @@ void pysqlite_do_all_statements(pysqlite_Connection* self, int action, int reset
weakref = PyList_GetItem(self->statements, i);
statement = PyWeakref_GetObject(weakref);
if (statement != Py_None) {
+ Py_INCREF(statement);
if (action == ACTION_RESET) {
(void)pysqlite_statement_reset((pysqlite_Statement*)statement);
} else {
(void)pysqlite_statement_finalize((pysqlite_Statement*)statement);
}
+ Py_DECREF(statement);
}
}
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index dc11fc8..3f631e3 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1887,6 +1887,69 @@ Mix string into the OpenSSL PRNG state. entropy (a float) is a lower\n\
bound on the entropy contained in string. See RFC 1750.");
static PyObject *
+PySSL_RAND(int len, int pseudo)
+{
+ int ok;
+ PyObject *bytes;
+ unsigned long err;
+ const char *errstr;
+ PyObject *v;
+
+ bytes = PyBytes_FromStringAndSize(NULL, len);
+ if (bytes == NULL)
+ return NULL;
+ if (pseudo) {
+ ok = RAND_pseudo_bytes((unsigned char*)PyBytes_AS_STRING(bytes), len);
+ if (ok == 0 || ok == 1)
+ return Py_BuildValue("NO", bytes, ok == 1 ? Py_True : Py_False);
+ }
+ else {
+ ok = RAND_bytes((unsigned char*)PyBytes_AS_STRING(bytes), len);
+ if (ok == 1)
+ return bytes;
+ }
+ Py_DECREF(bytes);
+
+ err = ERR_get_error();
+ errstr = ERR_reason_error_string(err);
+ v = Py_BuildValue("(ks)", err, errstr);
+ if (v != NULL) {
+ PyErr_SetObject(PySSLErrorObject, v);
+ Py_DECREF(v);
+ }
+ return NULL;
+}
+
+static PyObject *
+PySSL_RAND_bytes(PyObject *self, PyObject *args)
+{
+ int len;
+ if (!PyArg_ParseTuple(args, "i:RAND_bytes", &len))
+ return NULL;
+ return PySSL_RAND(len, 0);
+}
+
+PyDoc_STRVAR(PySSL_RAND_bytes_doc,
+"RAND_bytes(n) -> bytes\n\
+\n\
+Generate n cryptographically strong pseudo-random bytes.");
+
+static PyObject *
+PySSL_RAND_pseudo_bytes(PyObject *self, PyObject *args)
+{
+ int len;
+ if (!PyArg_ParseTuple(args, "i:RAND_pseudo_bytes", &len))
+ return NULL;
+ return PySSL_RAND(len, 1);
+}
+
+PyDoc_STRVAR(PySSL_RAND_pseudo_bytes_doc,
+"RAND_pseudo_bytes(n) -> (bytes, is_cryptographic)\n\
+\n\
+Generate n pseudo-random bytes. is_cryptographic is True if the bytes\
+generated are cryptographically strong.");
+
+static PyObject *
PySSL_RAND_status(PyObject *self)
{
return PyLong_FromLong(RAND_status());
@@ -1939,6 +2002,10 @@ static PyMethodDef PySSL_methods[] = {
#ifdef HAVE_OPENSSL_RAND
{"RAND_add", PySSL_RAND_add, METH_VARARGS,
PySSL_RAND_add_doc},
+ {"RAND_bytes", PySSL_RAND_bytes, METH_VARARGS,
+ PySSL_RAND_bytes_doc},
+ {"RAND_pseudo_bytes", PySSL_RAND_pseudo_bytes, METH_VARARGS,
+ PySSL_RAND_pseudo_bytes_doc},
{"RAND_egd", PySSL_RAND_egd, METH_VARARGS,
PySSL_RAND_egd_doc},
{"RAND_status", (PyCFunction)PySSL_RAND_status, METH_NOARGS,
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 8881427..6e39ca0 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -1098,7 +1098,7 @@ thread_PyThread_exit_thread(PyObject *self)
PyDoc_STRVAR(exit_doc,
"exit()\n\
-(PyThread_exit_thread() is an obsolete synonym)\n\
+(exit_thread() is an obsolete synonym)\n\
\n\
This is synonymous to ``raise SystemExit''. It will cause the current\n\
thread to exit silently unless the exception is caught.");
diff --git a/Modules/cjkcodecs/_codecs_hk.c b/Modules/cjkcodecs/_codecs_hk.c
index aaf103d..558a42f 100644
--- a/Modules/cjkcodecs/_codecs_hk.c
+++ b/Modules/cjkcodecs/_codecs_hk.c
@@ -115,55 +115,56 @@ DECODER(big5hkscs)
REQUIRE_INBUF(2)
- if (0xc6 <= c && c <= 0xc8 && (c >= 0xc7 || IN2 >= 0xa1))
- goto hkscsdec;
+ if (0xc6 > c || c > 0xc8 || (c < 0xc7 && IN2 < 0xa1)) {
+ TRYMAP_DEC(big5, **outbuf, c, IN2) {
+ NEXT(2, 1)
+ continue;
+ }
+ }
+
+ TRYMAP_DEC(big5hkscs, decoded, c, IN2)
+ {
+ int s = BH2S(c, IN2);
+ const unsigned char *hintbase;
+
+ assert(0x87 <= c && c <= 0xfe);
+ assert(0x40 <= IN2 && IN2 <= 0xfe);
+
+ if (BH2S(0x87, 0x40) <= s && s <= BH2S(0xa0, 0xfe)) {
+ hintbase = big5hkscs_phint_0;
+ s -= BH2S(0x87, 0x40);
+ }
+ else if (BH2S(0xc6,0xa1) <= s && s <= BH2S(0xc8,0xfe)){
+ hintbase = big5hkscs_phint_12130;
+ s -= BH2S(0xc6, 0xa1);
+ }
+ else if (BH2S(0xf9,0xd6) <= s && s <= BH2S(0xfe,0xfe)){
+ hintbase = big5hkscs_phint_21924;
+ s -= BH2S(0xf9, 0xd6);
+ }
+ else
+ return MBERR_INTERNAL;
- TRYMAP_DEC(big5, **outbuf, c, IN2) {
- NEXT(2, 1)
+ if (hintbase[s >> 3] & (1 << (s & 7))) {
+ WRITEUCS4(decoded | 0x20000)
+ NEXT_IN(2)
+ }
+ else {
+ OUT1(decoded)
+ NEXT(2, 1)
+ }
+ continue;
}
- else
-hkscsdec: TRYMAP_DEC(big5hkscs, decoded, c, IN2) {
- int s = BH2S(c, IN2);
- const unsigned char *hintbase;
-
- assert(0x87 <= c && c <= 0xfe);
- assert(0x40 <= IN2 && IN2 <= 0xfe);
-
- if (BH2S(0x87, 0x40) <= s && s <= BH2S(0xa0, 0xfe)) {
- hintbase = big5hkscs_phint_0;
- s -= BH2S(0x87, 0x40);
- }
- else if (BH2S(0xc6,0xa1) <= s && s <= BH2S(0xc8,0xfe)){
- hintbase = big5hkscs_phint_12130;
- s -= BH2S(0xc6, 0xa1);
- }
- else if (BH2S(0xf9,0xd6) <= s && s <= BH2S(0xfe,0xfe)){
- hintbase = big5hkscs_phint_21924;
- s -= BH2S(0xf9, 0xd6);
- }
- else
- return MBERR_INTERNAL;
-
- if (hintbase[s >> 3] & (1 << (s & 7))) {
- WRITEUCS4(decoded | 0x20000)
- NEXT_IN(2)
- }
- else {
- OUT1(decoded)
- NEXT(2, 1)
- }
- }
- else {
- switch ((c << 8) | IN2) {
- case 0x8862: WRITE2(0x00ca, 0x0304); break;
- case 0x8864: WRITE2(0x00ca, 0x030c); break;
- case 0x88a3: WRITE2(0x00ea, 0x0304); break;
- case 0x88a5: WRITE2(0x00ea, 0x030c); break;
- default: return 2;
- }
-
- NEXT(2, 2) /* all decoded codepoints are pairs, above. */
+
+ switch ((c << 8) | IN2) {
+ case 0x8862: WRITE2(0x00ca, 0x0304); break;
+ case 0x8864: WRITE2(0x00ca, 0x030c); break;
+ case 0x88a3: WRITE2(0x00ea, 0x0304); break;
+ case 0x88a5: WRITE2(0x00ea, 0x030c); break;
+ default: return 2;
}
+
+ NEXT(2, 2) /* all decoded codepoints are pairs, above. */
}
return 0;
diff --git a/Modules/cjkcodecs/_codecs_jp.c b/Modules/cjkcodecs/_codecs_jp.c
index 901d3be..a05e01b 100644
--- a/Modules/cjkcodecs/_codecs_jp.c
+++ b/Modules/cjkcodecs/_codecs_jp.c
@@ -371,11 +371,11 @@ DECODER(euc_jp)
REQUIRE_OUTBUF(1)
- if (c < 0x80) {
- OUT1(c)
- NEXT(1, 1)
- continue;
- }
+ if (c < 0x80) {
+ OUT1(c)
+ NEXT(1, 1)
+ continue;
+ }
if (c == 0x8e) {
/* JIS X 0201 half-width katakana */
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index e137ff6..1b37845 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -479,7 +479,7 @@ multibytecodec_encode(MultibyteCodec *codec,
MultibyteEncodeBuffer buf;
Py_ssize_t finalsize, r = 0;
- if (datalen == 0)
+ if (datalen == 0 && !(flags & MBENC_RESET))
return PyBytes_FromStringAndSize(NULL, 0);
buf.excobj = NULL;
@@ -515,7 +515,7 @@ multibytecodec_encode(MultibyteCodec *codec,
break;
}
- if (codec->encreset != NULL)
+ if (codec->encreset != NULL && (flags & MBENC_RESET))
for (;;) {
Py_ssize_t outleft;
@@ -785,8 +785,8 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx,
inbuf_end = inbuf + datalen;
r = multibytecodec_encode(ctx->codec, &ctx->state,
- (const Py_UNICODE **)&inbuf,
- datalen, ctx->errors, final ? MBENC_FLUSH : 0);
+ (const Py_UNICODE **)&inbuf, datalen,
+ ctx->errors, final ? MBENC_FLUSH | MBENC_RESET : 0);
if (r == NULL) {
/* recover the original pending buffer */
if (origpending > 0)
@@ -901,11 +901,17 @@ mbiencoder_encode(MultibyteIncrementalEncoderObject *self,
static PyObject *
mbiencoder_reset(MultibyteIncrementalEncoderObject *self)
{
- if (self->codec->decreset != NULL &&
- self->codec->decreset(&self->state, self->codec->config) != 0)
- return NULL;
+ /* Longest output: 4 bytes (b'\x0F\x1F(B') with ISO 2022 */
+ unsigned char buffer[4], *outbuf;
+ Py_ssize_t r;
+ if (self->codec->encreset != NULL) {
+ outbuf = buffer;
+ r = self->codec->encreset(&self->state, self->codec->config,
+ &outbuf, sizeof(buffer));
+ if (r != 0)
+ return NULL;
+ }
self->pendingsize = 0;
-
Py_RETURN_NONE;
}
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index 72dbe1e..46c2c42 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -854,7 +854,7 @@ faulthandler_fatal_error_py(PyObject *self, PyObject *args)
}
#if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION)
-void*
+static void*
stack_overflow(void *min_sp, void *max_sp, size_t *depth)
{
/* allocate 4096 bytes on the stack at each call */
@@ -1005,9 +1005,10 @@ static int
faulthandler_env_options(void)
{
PyObject *xoptions, *key, *module, *res;
- int enable;
if (!Py_GETENV("PYTHONFAULTHANDLER")) {
+ int has_key;
+
xoptions = PySys_GetXOptions();
if (xoptions == NULL)
return -1;
@@ -1016,13 +1017,11 @@ faulthandler_env_options(void)
if (key == NULL)
return -1;
- enable = PyDict_Contains(xoptions, key);
+ has_key = PyDict_Contains(xoptions, key);
Py_DECREF(key);
- if (!enable)
+ if (!has_key)
return 0;
}
- else
- enable = 1;
module = PyImport_ImportModule("faulthandler");
if (module == NULL) {
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index e5b4e55..1ffa896 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -581,10 +581,11 @@ parser_do_parse(PyObject *args, PyObject *kw, char *argspec, int type)
if (res)
((PyST_Object *)res)->st_flags.cf_flags = flags & PyCF_MASK;
}
- else
+ else {
PyParser_SetError(&err);
+ PyParser_ClearError(&err);
+ }
}
- PyParser_ClearError(&err);
return (res);
}
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 9c19ed0..e529afd 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6547,6 +6547,31 @@ posix_pipe(PyObject *self, PyObject *noargs)
}
#endif /* HAVE_PIPE */
+#ifdef HAVE_PIPE2
+PyDoc_STRVAR(posix_pipe2__doc__,
+"pipe2(flags=0) -> (read_end, write_end)\n\n\
+Create a pipe with flags set atomically.\
+flags is optional and can be constructed by ORing together zero or more\n\
+of these values: O_NONBLOCK, O_CLOEXEC.\n\
+");
+
+static PyObject *
+posix_pipe2(PyObject *self, PyObject *args)
+{
+ int flags = 0;
+ int fds[2];
+ int res;
+
+ if (!PyArg_ParseTuple(args, "|i:pipe2", &flags))
+ return NULL;
+
+ res = pipe2(fds, flags);
+ if (res != 0)
+ return posix_error();
+ return Py_BuildValue("(ii)", fds[0], fds[1]);
+}
+#endif /* HAVE_PIPE2 */
+
#ifdef HAVE_WRITEV
PyDoc_STRVAR(posix_writev__doc__,
"writev(fd, buffers) -> byteswritten\n\n\
@@ -8495,6 +8520,9 @@ static PyObject *
device_encoding(PyObject *self, PyObject *args)
{
int fd;
+#if defined(MS_WINDOWS) || defined(MS_WIN64)
+ UINT cp;
+#endif
if (!PyArg_ParseTuple(args, "i:device_encoding", &fd))
return NULL;
if (!_PyVerify_fd(fd) || !isatty(fd)) {
@@ -8502,16 +8530,16 @@ device_encoding(PyObject *self, PyObject *args)
return Py_None;
}
#if defined(MS_WINDOWS) || defined(MS_WIN64)
- if (fd == 0) {
- char buf[100];
- sprintf(buf, "cp%d", GetConsoleCP());
- return PyUnicode_FromString(buf);
- }
- if (fd == 1 || fd == 2) {
- char buf[100];
- sprintf(buf, "cp%d", GetConsoleOutputCP());
- return PyUnicode_FromString(buf);
- }
+ if (fd == 0)
+ cp = GetConsoleCP();
+ else if (fd == 1 || fd == 2)
+ cp = GetConsoleOutputCP();
+ else
+ cp = 0;
+ /* GetConsoleCP() and GetConsoleOutputCP() return 0 if the application
+ has no console */
+ if (cp != 0)
+ return PyUnicode_FromFormat("cp%u", (unsigned int)cp);
#elif defined(CODESET)
{
char *codeset = nl_langinfo(CODESET);
@@ -9438,6 +9466,9 @@ static PyMethodDef posix_methods[] = {
#ifdef HAVE_PIPE
{"pipe", posix_pipe, METH_NOARGS, posix_pipe__doc__},
#endif
+#ifdef HAVE_PIPE2
+ {"pipe2", posix_pipe2, METH_VARARGS, posix_pipe2__doc__},
+#endif
#ifdef HAVE_MKFIFO
{"mkfifo", posix_mkfifo, METH_VARARGS, posix_mkfifo__doc__},
#endif
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 4ef09de..d923eeb 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1622,26 +1622,6 @@ static struct PyMethodDef pyexpat_methods[] = {
PyDoc_STRVAR(pyexpat_module_documentation,
"Python wrapper for Expat parser.");
-/* Return a Python string that represents the version number without the
- * extra cruft added by revision control, even if the right options were
- * given to the "cvs export" command to make it not include the extra
- * cruft.
- */
-static PyObject *
-get_version_string(void)
-{
- static char *rcsid = "$Revision$";
- char *rev = rcsid;
- int i = 0;
-
- while (!isdigit(Py_CHARMASK(*rev)))
- ++rev;
- while (rev[i] != ' ' && rev[i] != '\0')
- ++i;
-
- return PyUnicode_FromStringAndSize(rev, i);
-}
-
/* Initialization function for the module */
#ifndef MODULE_NAME
@@ -1718,7 +1698,6 @@ MODULE_INITFUNC(void)
Py_INCREF(&Xmlparsetype);
PyModule_AddObject(m, "XMLParserType", (PyObject *) &Xmlparsetype);
- PyModule_AddObject(m, "__version__", get_version_string());
PyModule_AddStringConstant(m, "EXPAT_VERSION",
(char *) XML_ExpatVersion());
{
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index ff65f04..6d27ab3 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -177,17 +177,18 @@ static void
trip_signal(int sig_num)
{
unsigned char byte;
+
Handlers[sig_num].tripped = 1;
+ if (wakeup_fd != -1) {
+ byte = (unsigned char)sig_num;
+ write(wakeup_fd, &byte, 1);
+ }
if (is_tripped)
return;
/* Set is_tripped after setting .tripped, as it gets
cleared in PyErr_CheckSignals() before .tripped. */
is_tripped = 1;
Py_AddPendingCall(checksignals_witharg, NULL);
- if (wakeup_fd != -1) {
- byte = (unsigned char)sig_num;
- write(wakeup_fd, &byte, 1);
- }
}
static void
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index a96ec06..ee3a511 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -2782,6 +2782,7 @@ sock_sendto(PySocketSockObject *s, PyObject *args)
PyErr_Format(PyExc_TypeError,
"sendto() takes 2 or 3 arguments (%d given)",
arglen);
+ return NULL;
}
if (PyErr_Occurred())
return NULL;
@@ -3144,7 +3145,7 @@ socket_gethostname(PyObject *self, PyObject *unused)
}
return PyErr_SetExcFromWindowsErr(PyExc_WindowsError, GetLastError());
}
- return PyUnicode_FromUnicode(buf, size);
+ return PyUnicode_FromUnicode(buf, size);
#else
char buf[1024];
int res;
@@ -4038,7 +4039,7 @@ socket_inet_ntop(PyObject *self, PyObject *args)
static PyObject *
socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
{
- static char* kwnames[] = {"host", "port", "family", "type", "proto",
+ static char* kwnames[] = {"host", "port", "family", "type", "proto",
"flags", 0};
struct addrinfo hints, *res;
struct addrinfo *res0 = NULL;
@@ -4053,7 +4054,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
family = socktype = protocol = flags = 0;
family = AF_UNSPEC;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|iiii:getaddrinfo",
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|iiii:getaddrinfo",
kwnames, &hobj, &pobj, &family, &socktype,
&protocol, &flags)) {
return NULL;
@@ -4289,7 +4290,7 @@ socket_if_nameindex(PyObject *self, PyObject *arg)
PyObject *list;
int i;
struct if_nameindex *ni;
-
+
ni = if_nameindex();
if (ni == NULL) {
PyErr_SetFromErrno(socket_error);
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index de89a76..a83bf8b 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -1196,7 +1196,7 @@ get_module_code(ZipImporter *self, PyObject *fullname,
int *p_ispackage, PyObject **p_modpath)
{
PyObject *code = NULL, *toc_entry, *subname;
- PyObject *path, *fullpath;
+ PyObject *path, *fullpath = NULL;
struct st_zip_searchorder *zso;
subname = get_subname(fullname);