diff options
author | Georg Brandl <georg@python.org> | 2012-03-17 16:58:12 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2012-03-17 16:58:12 +0100 |
commit | ffd4830f6ab0942a463772a01a91f051bfa2d376 (patch) | |
tree | 14d5f982ed3d51197f0dd69370d3f6002aec8e1e /Doc/includes/noddy2.c | |
parent | 206a0cc1b0f2545eef212be6210b4bf7008815ba (diff) | |
parent | 5d6d9423be73e8c6f3f18fa3e006573fc5836236 (diff) | |
download | cpython-ffd4830f6ab0942a463772a01a91f051bfa2d376.tar.gz |
merge with 3.2
Diffstat (limited to 'Doc/includes/noddy2.c')
-rw-r--r-- | Doc/includes/noddy2.c | 50 |
1 files changed, 16 insertions, 34 deletions
diff --git a/Doc/includes/noddy2.c b/Doc/includes/noddy2.c index 9b8eafb560..964155845f 100644 --- a/Doc/includes/noddy2.c +++ b/Doc/includes/noddy2.c @@ -24,18 +24,16 @@ Noddy_new(PyTypeObject *type, PyObject *args, PyObject *kwds) self = (Noddy *)type->tp_alloc(type, 0); if (self != NULL) { self->first = PyUnicode_FromString(""); - if (self->first == NULL) - { + if (self->first == NULL) { Py_DECREF(self); return NULL; - } - + } + self->last = PyUnicode_FromString(""); - if (self->last == NULL) - { + if (self->last == NULL) { Py_DECREF(self); return NULL; - } + } self->number = 0; } @@ -50,10 +48,10 @@ Noddy_init(Noddy *self, PyObject *args, PyObject *kwds) static char *kwlist[] = {"first", "last", "number", NULL}; - if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist, - &first, &last, + if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist, + &first, &last, &self->number)) - return -1; + return -1; if (first) { tmp = self->first; @@ -86,15 +84,6 @@ static PyMemberDef Noddy_members[] = { static PyObject * Noddy_name(Noddy* self) { - static PyObject *format = NULL; - PyObject *args, *result; - - if (format == NULL) { - format = PyUnicode_FromString("%s %s"); - if (format == NULL) - return NULL; - } - if (self->first == NULL) { PyErr_SetString(PyExc_AttributeError, "first"); return NULL; @@ -105,14 +94,7 @@ Noddy_name(Noddy* self) return NULL; } - args = Py_BuildValue("OO", self->first, self->last); - if (args == NULL) - return NULL; - - result = PyUnicode_Format(format, args); - Py_DECREF(args); - - return result; + return PyUnicode_FromFormat("%S %S", self->first, self->last); } static PyMethodDef Noddy_methods[] = { @@ -145,12 +127,12 @@ static PyTypeObject NoddyType = { Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ "Noddy objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ Noddy_methods, /* tp_methods */ Noddy_members, /* tp_members */ 0, /* tp_getset */ @@ -173,7 +155,7 @@ static PyModuleDef noddy2module = { }; PyMODINIT_FUNC -PyInit_noddy2(void) +PyInit_noddy2(void) { PyObject* m; |