[Python-checkins] r56193 - python/branches/cpy_merge/Modules/_picklemodule.c
alexandre.vassalotti
python-checkins at python.org
Sun Jul 8 20:53:53 CEST 2007
Author: alexandre.vassalotti
Date: Sun Jul 8 20:53:53 2007
New Revision: 56193
Modified:
python/branches/cpy_merge/Modules/_picklemodule.c
Log:
Fix the indentation of macros.
Annotate PdataType.
Move the INIT_STR to the top of the module.
Modified: python/branches/cpy_merge/Modules/_picklemodule.c
==============================================================================
--- python/branches/cpy_merge/Modules/_picklemodule.c (original)
+++ python/branches/cpy_merge/Modules/_picklemodule.c Sun Jul 8 20:53:53 2007
@@ -118,12 +118,26 @@
/* For looking up name pairs in copy_reg._extension_registry. */
static PyObject *two_tuple;
-static PyObject *__class___str, *__getinitargs___str, *__dict___str,
- *__getstate___str, *__setstate___str, *__name___str, *__reduce___str,
+#define INIT_STR(S) \
+ if (!(S##_str = PyString_InternFromString(#S))) \
+ return -1;
+
+static PyObject \
+ *__class___str,
+ *__getinitargs___str,
+ *__dict___str,
+ *__getstate___str,
+ *__setstate___str,
+ *__name___str,
+ *__reduce___str,
*__reduce_ex___str,
- *write_str, *append_str,
- *read_str, *readline_str, *__main___str,
- *copy_reg_str, *dispatch_table_str;
+ *write_str,
+ *append_str,
+ *read_str,
+ *readline_str,
+ *__main___str,
+ *copy_reg_str,
+ *dispatch_table_str;
/*************************************************************************
Internal Data type for pickle data. */
@@ -131,7 +145,7 @@
typedef struct {
PyObject_HEAD
int length; /* number of initial slots in data currently used */
- int size; /* number of slots in data allocated */
+ int size; /* number of slots in data allocated */
PyObject **data;
} Pdata;
@@ -150,9 +164,12 @@
}
static PyTypeObject PdataType = {
- PyObject_HEAD_INIT(NULL) 0, "pickle.Pdata", sizeof(Pdata), 0,
- (destructor) Pdata_dealloc,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0L, 0L, 0L, 0L, ""
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "_pickle.Pdata", /*tp_name*/
+ sizeof(Pdata), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ (destructor) Pdata_dealloc, /*tp_dealloc*/
};
#define Pdata_Check(O) ((O)->ob_type == &PdataType)
@@ -233,14 +250,14 @@
* must be an lvalue holding PyObject*. On stack underflow, UnpicklingError
* is raised and V is set to NULL. D and V may be evaluated several times.
*/
-#define PDATA_POP(D, V) { \
- if ((D)->length) \
- (V) = (D)->data[--((D)->length)]; \
- else { \
- PyErr_SetString(UnpicklingError, "bad pickle data"); \
- (V) = NULL; \
- } \
-}
+#define PDATA_POP(D, V) { \
+ if ((D)->length) \
+ (V) = (D)->data[--((D)->length)]; \
+ else { \
+ PyErr_SetString(UnpicklingError, "bad pickle data"); \
+ (V) = NULL; \
+ } \
+ }
/* PDATA_PUSH and PDATA_APPEND both push rvalue PyObject* O on to Pdata*
* D. If the Pdata stack can't be grown to hold the new value, both
@@ -254,17 +271,17 @@
#define PDATA_PUSH(D, O, ER) { \
if (((Pdata*)(D))->length == ((Pdata*)(D))->size && \
Pdata_grow((Pdata*)(D)) < 0) { \
- Py_DECREF(O); \
- return ER; \
+ Py_DECREF(O); \
+ return ER; \
} \
((Pdata*)(D))->data[((Pdata*)(D))->length++] = (O); \
-}
+ }
/* Push O on stack D, pushing a new reference. */
#define PDATA_APPEND(D, O, ER) { \
if (((Pdata*)(D))->length == ((Pdata*)(D))->size && \
Pdata_grow((Pdata*)(D)) < 0) \
- return ER; \
+ return ER; \
Py_INCREF(O); \
((Pdata*)(D))->data[((Pdata*)(D))->length++] = (O); \
}
@@ -305,22 +322,22 @@
/*************************************************************************/
-#define ARG_TUP(self, o) { \
- if (self->arg || (self->arg=PyTuple_New(1))) { \
- Py_XDECREF(PyTuple_GET_ITEM(self->arg,0)); \
- PyTuple_SET_ITEM(self->arg,0,o); \
- } \
- else { \
- Py_DECREF(o); \
- } \
-}
+#define ARG_TUP(self, o) { \
+ if (self->arg || (self->arg=PyTuple_New(1))) { \
+ Py_XDECREF(PyTuple_GET_ITEM(self->arg,0)); \
+ PyTuple_SET_ITEM(self->arg,0,o); \
+ } \
+ else { \
+ Py_DECREF(o); \
+ } \
+ }
#define FREE_ARG_TUP(self) { \
- if (self->arg->ob_refcnt > 1) { \
- Py_DECREF(self->arg); \
- self->arg=NULL; \
- } \
- }
+ if (self->arg->ob_refcnt > 1) { \
+ Py_DECREF(self->arg); \
+ self->arg=NULL; \
+ } \
+ }
typedef struct Picklerobject {
PyObject_HEAD
@@ -338,7 +355,7 @@
/* bool, true if proto > 0 */
int bin;
- int fast; /* Fast mode doesn't save in memo, don't use if circ ref */
+ int fast; /* Fast mode doesn't save in memo, don't use if circ ref */
int nesting;
int (*write_func) (struct Picklerobject *, const char *, Py_ssize_t);
char *write_buf;
@@ -434,9 +451,9 @@
return -1;
}
- Py_BEGIN_ALLOW_THREADS
- nbyteswritten = fwrite(s, sizeof(char), n, self->fp);
- Py_END_ALLOW_THREADS
+ Py_BEGIN_ALLOW_THREADS;
+ nbyteswritten = fwrite(s, sizeof(char), n, self->fp);
+ Py_END_ALLOW_THREADS;
if (nbyteswritten != (size_t) n) {
PyErr_SetFromErrno(PyExc_IOError);
@@ -5269,7 +5286,7 @@
static PyTypeObject Unpicklertype = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size */
- "pickle.Unpickler", /*tp_name */
+ "_pickle.Unpickler", /*tp_name */
sizeof(Unpicklerobject), /*tp_basicsize */
0,
(destructor) Unpickler_dealloc, /* tp_dealloc */
@@ -5339,8 +5356,6 @@
{
PyObject *copy_reg, *t, *r;
-#define INIT_STR(S) if (!( S ## _str=PyString_InternFromString(#S))) return -1;
-
if (PyType_Ready(&Unpicklertype) < 0)
return -1;
if (PyType_Ready(&Picklertype) < 0)
@@ -5433,9 +5448,8 @@
return -1;
Py_DECREF(r);
- if (!
- (UnpickleableError =
- PyErr_NewException("pickle.UnpickleableError", PicklingError, t)))
+ if (!(UnpickleableError = PyErr_NewException("pickle.UnpickleableError",
+ PicklingError, t)))
return -1;
Py_DECREF(t);
More information about the Python-checkins
mailing list