From 459f2d304e64d475c9c84fcbc0e3a70c781b85c2 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 27 May 2011 07:53:28 -0500 Subject: remove unused string WILFE attribute --- Python/marshal.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'Python/marshal.c') diff --git a/Python/marshal.c b/Python/marshal.c index 73d4f374cd..f66b765b7d 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -60,7 +60,6 @@ typedef struct { PyObject *str; char *ptr; char *end; - PyObject *strings; /* dict on marshal, list on unmarshal */ int version; } WFILE; @@ -444,7 +443,6 @@ PyMarshal_WriteLongToFile(long x, FILE *fp, int version) wf.fp = fp; wf.error = WFERR_OK; wf.depth = 0; - wf.strings = NULL; wf.version = version; w_long(x, &wf); } @@ -456,10 +454,8 @@ PyMarshal_WriteObjectToFile(PyObject *x, FILE *fp, int version) wf.fp = fp; wf.error = WFERR_OK; wf.depth = 0; - wf.strings = (version > 0) ? PyDict_New() : NULL; wf.version = version; w_object(x, &wf); - Py_XDECREF(wf.strings); } typedef WFILE RFILE; /* Same struct with different invariants */ @@ -1041,7 +1037,6 @@ PyMarshal_ReadShortFromFile(FILE *fp) RFILE rf; assert(fp); rf.fp = fp; - rf.strings = NULL; rf.end = rf.ptr = NULL; return r_short(&rf); } @@ -1051,7 +1046,6 @@ PyMarshal_ReadLongFromFile(FILE *fp) { RFILE rf; rf.fp = fp; - rf.strings = NULL; rf.ptr = rf.end = NULL; return r_long(&rf); } @@ -1112,11 +1106,9 @@ PyMarshal_ReadObjectFromFile(FILE *fp) RFILE rf; PyObject *result; rf.fp = fp; - rf.strings = PyList_New(0); rf.depth = 0; rf.ptr = rf.end = NULL; result = r_object(&rf); - Py_DECREF(rf.strings); return result; } @@ -1128,10 +1120,8 @@ PyMarshal_ReadObjectFromString(char *str, Py_ssize_t len) rf.fp = NULL; rf.ptr = str; rf.end = str + len; - rf.strings = PyList_New(0); rf.depth = 0; result = r_object(&rf); - Py_DECREF(rf.strings); return result; } @@ -1150,9 +1140,7 @@ PyMarshal_WriteObjectToString(PyObject *x, int version) wf.error = WFERR_OK; wf.depth = 0; wf.version = version; - wf.strings = (version > 0) ? PyDict_New() : NULL; w_object(x, &wf); - Py_XDECREF(wf.strings); if (wf.str != NULL) { char *base = PyBytes_AS_STRING((PyBytesObject *)wf.str); if (wf.ptr - base > PY_SSIZE_T_MAX) { @@ -1242,10 +1230,8 @@ marshal_load(PyObject *self, PyObject *f) Py_DECREF(data); return NULL; } - rf.strings = PyList_New(0); rf.depth = 0; result = read_object(&rf); - Py_DECREF(rf.strings); Py_DECREF(data); return result; } @@ -1298,10 +1284,8 @@ marshal_loads(PyObject *self, PyObject *args) rf.fp = NULL; rf.ptr = s; rf.end = s + n; - rf.strings = PyList_New(0); rf.depth = 0; result = read_object(&rf); - Py_DECREF(rf.strings); PyBuffer_Release(&p); return result; } -- cgit v1.2.1 From 69ae509ca8e95a2fb717c6a12117e9e77bd44306 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 27 May 2011 09:08:01 -0500 Subject: try to use the same str object for all code filenames when compiling or unmarshalling (#12190) This should reduce memory usage. --- Python/marshal.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Python/marshal.c') diff --git a/Python/marshal.c b/Python/marshal.c index f66b765b7d..7b327ade01 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -58,6 +58,7 @@ typedef struct { int depth; /* If fp == NULL, the following are valid: */ PyObject *str; + PyObject *current_filename; char *ptr; char *end; int version; @@ -976,6 +977,18 @@ r_object(RFILE *p) filename = r_object(p); if (filename == NULL) goto code_error; + if (PyUnicode_CheckExact(filename)) { + if (p->current_filename != NULL) { + if (!PyUnicode_Compare(filename, p->current_filename)) { + Py_DECREF(filename); + Py_INCREF(p->current_filename); + filename = p->current_filename; + } + } + else { + p->current_filename = filename; + } + } name = r_object(p); if (name == NULL) goto code_error; @@ -1037,6 +1050,7 @@ PyMarshal_ReadShortFromFile(FILE *fp) RFILE rf; assert(fp); rf.fp = fp; + rf.current_filename = NULL; rf.end = rf.ptr = NULL; return r_short(&rf); } @@ -1046,6 +1060,7 @@ PyMarshal_ReadLongFromFile(FILE *fp) { RFILE rf; rf.fp = fp; + rf.current_filename = NULL; rf.ptr = rf.end = NULL; return r_long(&rf); } @@ -1106,6 +1121,7 @@ PyMarshal_ReadObjectFromFile(FILE *fp) RFILE rf; PyObject *result; rf.fp = fp; + rf.current_filename = NULL; rf.depth = 0; rf.ptr = rf.end = NULL; result = r_object(&rf); @@ -1118,6 +1134,7 @@ PyMarshal_ReadObjectFromString(char *str, Py_ssize_t len) RFILE rf; PyObject *result; rf.fp = NULL; + rf.current_filename = NULL; rf.ptr = str; rf.end = str + len; rf.depth = 0; @@ -1214,6 +1231,7 @@ marshal_load(PyObject *self, PyObject *f) if (data == NULL) return NULL; rf.fp = NULL; + rf.current_filename = NULL; if (PyBytes_Check(data)) { rf.ptr = PyBytes_AS_STRING(data); rf.end = rf.ptr + PyBytes_GET_SIZE(data); @@ -1282,6 +1300,7 @@ marshal_loads(PyObject *self, PyObject *args) s = p.buf; n = p.len; rf.fp = NULL; + rf.current_filename = NULL; rf.ptr = s; rf.end = s + n; rf.depth = 0; -- cgit v1.2.1 From 635eaf2d0553df0712a7a9b332d1917f0aed4789 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sat, 2 Jul 2011 17:19:51 +0100 Subject: Removed breaking typo accidentally introduced during merge with 3.2. --- Python/marshal.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'Python/marshal.c') diff --git a/Python/marshal.c b/Python/marshal.c index b8d06ad286..c749bb3357 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -1320,8 +1320,6 @@ marshal_load(PyObject *self, PyObject *f) { PyObject *data, *result; RFILE rf; - char *p; - int n; /* * Make a call to the read method, but read zero bytes. @@ -1338,12 +1336,10 @@ marshal_load(PyObject *self, PyObject *f) result = NULL; } else { - rf.strings = PyList_New(0); rf.depth = 0; rf.fp = NULL; rf.readable = f; result = read_object(&rf); - Py_DECREF(rf.strings); } Py_DECREF(data); return result; -- cgit v1.2.1 From 7533dccc560e295a63f029bde94d9679e3c7200e Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sat, 2 Jul 2011 18:42:21 +0100 Subject: Correct uninitialized data problem in marshal code. --- Python/marshal.c | 1 + 1 file changed, 1 insertion(+) (limited to 'Python/marshal.c') diff --git a/Python/marshal.c b/Python/marshal.c index c749bb3357..35fcd3afb3 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -1339,6 +1339,7 @@ marshal_load(PyObject *self, PyObject *f) rf.depth = 0; rf.fp = NULL; rf.readable = f; + rf.current_filename = NULL; result = read_object(&rf); } Py_DECREF(data); -- cgit v1.2.1 From d1d013c01c268d869597b35cbcd8b5d7c5baf2ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Wed, 28 Sep 2011 07:41:54 +0200 Subject: Implement PEP 393. --- Python/marshal.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'Python/marshal.c') diff --git a/Python/marshal.c b/Python/marshal.c index edf0366c9a..31fe66b08f 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -311,9 +311,7 @@ w_object(PyObject *v, WFILE *p) } else if (PyUnicode_CheckExact(v)) { PyObject *utf8; - utf8 = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(v), - PyUnicode_GET_SIZE(v), - "surrogatepass"); + utf8 = PyUnicode_AsEncodedString(v, "utf8", "surrogatepass"); if (utf8 == NULL) { p->depth--; p->error = WFERR_UNMARSHALLABLE; -- cgit v1.2.1 From dcacb24f386ae1b107462181af42b6826ec15fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 9 Oct 2011 10:38:36 +0200 Subject: =?UTF-8?q?Add=20API=20for=20static=20strings,=20primarily=20good?= =?UTF-8?q?=20for=20identifiers.=20Thanks=20to=20Konrad=20Sch=C3=B6bel=20a?= =?UTF-8?q?nd=20Jasper=20Schulz=20for=20helping=20with=20the=20mass-editin?= =?UTF-8?q?g.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Python/marshal.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Python/marshal.c') diff --git a/Python/marshal.c b/Python/marshal.c index 31fe66b08f..b8288d0c1a 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -480,7 +480,9 @@ r_string(char *s, int n, RFILE *p) } } else { - PyObject *data = PyObject_CallMethod(p->readable, "read", "i", n); + _Py_identifier(read); + + PyObject *data = _PyObject_CallMethodId(p->readable, &PyId_read, "i", n); read = 0; if (data != NULL) { if (!PyBytes_Check(data)) { @@ -1290,12 +1292,14 @@ marshal_dump(PyObject *self, PyObject *args) int version = Py_MARSHAL_VERSION; PyObject *s; PyObject *res; + _Py_identifier(write); + if (!PyArg_ParseTuple(args, "OO|i:dump", &x, &f, &version)) return NULL; s = PyMarshal_WriteObjectToString(x, version); if (s == NULL) return NULL; - res = PyObject_CallMethod(f, "write", "O", s); + res = _PyObject_CallMethodId(f, &PyId_write, "O", s); Py_DECREF(s); return res; } @@ -1317,6 +1321,7 @@ static PyObject * marshal_load(PyObject *self, PyObject *f) { PyObject *data, *result; + _Py_identifier(read); RFILE rf; /* @@ -1324,7 +1329,7 @@ marshal_load(PyObject *self, PyObject *f) * This is to ensure that the object passed in at least * has a read method which returns bytes. */ - data = PyObject_CallMethod(f, "read", "i", 0); + data = _PyObject_CallMethodId(f, &PyId_read, "i", 0); if (data == NULL) return NULL; if (!PyBytes_Check(data)) { -- cgit v1.2.1 From f5ad3b280b43227eb0e3fa63d89490a58ba9c28b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 14 Oct 2011 10:20:37 +0200 Subject: Rename _Py_identifier to _Py_IDENTIFIER. --- Python/marshal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Python/marshal.c') diff --git a/Python/marshal.c b/Python/marshal.c index b8288d0c1a..98bbbaff6b 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -480,7 +480,7 @@ r_string(char *s, int n, RFILE *p) } } else { - _Py_identifier(read); + _Py_IDENTIFIER(read); PyObject *data = _PyObject_CallMethodId(p->readable, &PyId_read, "i", n); read = 0; @@ -1292,7 +1292,7 @@ marshal_dump(PyObject *self, PyObject *args) int version = Py_MARSHAL_VERSION; PyObject *s; PyObject *res; - _Py_identifier(write); + _Py_IDENTIFIER(write); if (!PyArg_ParseTuple(args, "OO|i:dump", &x, &f, &version)) return NULL; @@ -1321,7 +1321,7 @@ static PyObject * marshal_load(PyObject *self, PyObject *f) { PyObject *data, *result; - _Py_identifier(read); + _Py_IDENTIFIER(read); RFILE rf; /* -- cgit v1.2.1 From dc87ffd3df0f0a831b58372ce6f9307cf5da356b Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Fri, 2 Mar 2012 18:22:23 +0100 Subject: Simplify code in marshal.c. --- Python/marshal.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'Python/marshal.c') diff --git a/Python/marshal.c b/Python/marshal.c index 17353b2d58..77824d4129 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -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... */ -- cgit v1.2.1 From e6c9b39d545078a63a70200e6c1cf03ac4df9d14 Mon Sep 17 00:00:00 2001 From: "Martin v. L?wis" Date: Sat, 28 Jul 2012 19:44:05 +0200 Subject: Issue #15466: Stop using TYPE_INT64 in marshal, to make importlib.h (and other byte code files) equal between 32-bit and 64-bit systems. --- Python/marshal.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'Python/marshal.c') diff --git a/Python/marshal.c b/Python/marshal.c index b94e8d8611..6d52a840ce 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -31,6 +31,9 @@ #define TYPE_STOPITER 'S' #define TYPE_ELLIPSIS '.' #define TYPE_INT 'i' +/* TYPE_INT64 is deprecated. It is not + generated anymore, and support for reading it + will be removed in Python 3.4. */ #define TYPE_INT64 'I' #define TYPE_FLOAT 'f' #define TYPE_BINARY_FLOAT 'g' @@ -121,15 +124,6 @@ w_long(long x, WFILE *p) w_byte((char)((x>>24) & 0xff), p); } -#if SIZEOF_LONG > 4 -static void -w_long64(long x, WFILE *p) -{ - w_long(x, p); - w_long(x>>32, p); -} -#endif - /* We assume that Python longs are stored internally in base some power of 2**15; for the sake of portability we'll always read and write them in base exactly 2**15. */ @@ -219,8 +213,8 @@ w_object(PyObject *v, WFILE *p) #if SIZEOF_LONG > 4 long y = Py_ARITHMETIC_RIGHT_SHIFT(long, x, 31); if (y && y != -1) { - w_byte(TYPE_INT64, p); - w_long64(x, p); + /* Too large for TYPE_INT */ + w_PyLong((PyLongObject*)v, p); } else #endif -- cgit v1.2.1