diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ast.c | 3 | ||||
-rw-r--r-- | Python/getcopyright.c | 2 | ||||
-rw-r--r-- | Python/marshal.c | 24 | ||||
-rw-r--r-- | Python/pytime.c | 45 |
4 files changed, 58 insertions, 16 deletions
diff --git a/Python/ast.c b/Python/ast.c index c56564279b..0f93098712 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -3796,6 +3796,9 @@ parsestr(struct compiling *c, const node *n, int *bytesmode) quote = *++s; *bytesmode = 1; } + else if (quote == 'u' || quote == 'U') { + quote = *++s; + } else if (quote == 'r' || quote == 'R') { quote = *++s; rawmode = 1; diff --git a/Python/getcopyright.c b/Python/getcopyright.c index d1e2578747..d83c6da1a2 100644 --- a/Python/getcopyright.c +++ b/Python/getcopyright.c @@ -19,5 +19,5 @@ All Rights Reserved."; const char * Py_GetCopyright(void) { - return cprt; + return cprt; } diff --git a/Python/marshal.c b/Python/marshal.c index 98bbbaff6b..b94e8d8611 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -409,11 +409,12 @@ w_object(PyObject *v, WFILE *p) else if (PyObject_CheckBuffer(v)) { /* Write unknown buffer-style objects as a string */ char *s; - PyBufferProcs *pb = v->ob_type->tp_as_buffer; Py_buffer view; - if ((*pb->bf_getbuffer)(v, &view, PyBUF_SIMPLE) != 0) { + if (PyObject_GetBuffer(v, &view, PyBUF_SIMPLE) != 0) { w_byte(TYPE_UNKNOWN, p); + p->depth--; p->error = WFERR_UNMARSHALLABLE; + return; } w_byte(TYPE_STRING, p); n = view.len; @@ -425,8 +426,7 @@ w_object(PyObject *v, WFILE *p) } w_long((long)n, p); w_string(s, (int)n, p); - if (pb->bf_releasebuffer != NULL) - (*pb->bf_releasebuffer)(v, &view); + PyBuffer_Release(&view); } else { w_byte(TYPE_UNKNOWN, p); @@ -1239,7 +1239,6 @@ PyObject * PyMarshal_WriteObjectToString(PyObject *x, int version) { WFILE wf; - PyObject *res = NULL; wf.fp = NULL; wf.readable = NULL; @@ -1273,12 +1272,7 @@ PyMarshal_WriteObjectToString(PyObject *x, int version) :"object too deeply nested to marshal"); return NULL; } - if (wf.str != NULL) { - /* XXX Quick hack -- need to do this differently */ - res = PyBytes_FromObject(wf.str); - Py_DECREF(wf.str); - } - return res; + return wf.str; } /* And an interface for Python programs... */ @@ -1390,7 +1384,7 @@ marshal_loads(PyObject *self, PyObject *args) char *s; Py_ssize_t n; PyObject* result; - if (!PyArg_ParseTuple(args, "s*:loads", &p)) + if (!PyArg_ParseTuple(args, "y*:loads", &p)) return NULL; s = p.buf; n = p.len; @@ -1406,10 +1400,10 @@ marshal_loads(PyObject *self, PyObject *args) } PyDoc_STRVAR(loads_doc, -"loads(string)\n\ +"loads(bytes)\n\ \n\ -Convert the string to a value. If no valid value is found, raise\n\ -EOFError, ValueError or TypeError. Extra characters in the string are\n\ +Convert the bytes object to a value. If no valid value is found, raise\n\ +EOFError, ValueError or TypeError. Extra characters in the input are\n\ ignored."); static PyMethodDef marshal_methods[] = { diff --git a/Python/pytime.c b/Python/pytime.c index bec1c713e6..d23ce75b43 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -70,6 +70,51 @@ _PyTime_gettimeofday(_PyTime_timeval *tp) #endif /* MS_WINDOWS */ } +int +_PyTime_ObjectToTimespec(PyObject *obj, time_t *sec, long *nsec) +{ + if (PyFloat_Check(obj)) { + double d, intpart, floatpart, err; + + d = PyFloat_AsDouble(obj); + floatpart = modf(d, &intpart); + if (floatpart < 0) { + floatpart = 1.0 + floatpart; + intpart -= 1.0; + } + + *sec = (time_t)intpart; + err = intpart - (double)*sec; + if (err <= -1.0 || err >= 1.0) + goto overflow; + + floatpart *= 1e9; + *nsec = (long)floatpart; + return 0; + } + else { +#if defined(HAVE_LONG_LONG) && SIZEOF_TIME_T == SIZEOF_LONG_LONG + *sec = PyLong_AsLongLong(obj); +#else + assert(sizeof(time_t) <= sizeof(long)); + *sec = PyLong_AsLong(obj); +#endif + if (*sec == -1 && PyErr_Occurred()) { + if (PyErr_ExceptionMatches(PyExc_OverflowError)) + goto overflow; + else + return -1; + } + *nsec = 0; + return 0; + } + +overflow: + PyErr_SetString(PyExc_OverflowError, + "timestamp out of range for platform time_t"); + return -1; +} + void _PyTime_Init() { |