Mercurial > cpython-lru_cache-weakref
comparison Python/Python-ast.c @ 46212:be18df634405 legacy-trunk
Make AST nodes pickleable.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Sun, 30 Mar 2008 20:20:39 +0000 |
| parents | 59d42e6d1885 |
| children | 4fe192d48960 |
comparison
equal
deleted
inserted
replaced
| 46207:59d42e6d1885 | 46212:be18df634405 |
|---|---|
| 418 cleanup: | 418 cleanup: |
| 419 Py_XDECREF(fields); | 419 Py_XDECREF(fields); |
| 420 return res; | 420 return res; |
| 421 } | 421 } |
| 422 | 422 |
| 423 /* Pickling support */ | |
| 424 static PyObject * | |
| 425 ast_type_reduce(PyObject *self, PyObject *unused) | |
| 426 { | |
| 427 PyObject *res; | |
| 428 PyObject *dict = PyObject_GetAttrString(self, "__dict__"); | |
| 429 if (dict == NULL) { | |
| 430 if (PyErr_ExceptionMatches(PyExc_AttributeError)) | |
| 431 PyErr_Clear(); | |
| 432 else | |
| 433 return NULL; | |
| 434 } | |
| 435 if (dict) { | |
| 436 res = Py_BuildValue("O()O", Py_TYPE(self), dict); | |
| 437 Py_DECREF(dict); | |
| 438 return res; | |
| 439 } | |
| 440 return Py_BuildValue("O()", Py_TYPE(self)); | |
| 441 } | |
| 442 | |
| 443 static PyMethodDef ast_type_methods[] = { | |
| 444 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, | |
| 445 {NULL} | |
| 446 }; | |
| 447 | |
| 423 static PyTypeObject AST_type = { | 448 static PyTypeObject AST_type = { |
| 424 PyVarObject_HEAD_INIT(&PyType_Type, 0) | 449 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 425 "AST", | 450 "_ast.AST", |
| 426 sizeof(PyObject), | 451 sizeof(PyObject), |
| 427 0, | 452 0, |
| 428 0, /* tp_dealloc */ | 453 0, /* tp_dealloc */ |
| 429 0, /* tp_print */ | 454 0, /* tp_print */ |
| 430 0, /* tp_getattr */ | 455 0, /* tp_getattr */ |
| 446 0, /* tp_clear */ | 471 0, /* tp_clear */ |
| 447 0, /* tp_richcompare */ | 472 0, /* tp_richcompare */ |
| 448 0, /* tp_weaklistoffset */ | 473 0, /* tp_weaklistoffset */ |
| 449 0, /* tp_iter */ | 474 0, /* tp_iter */ |
| 450 0, /* tp_iternext */ | 475 0, /* tp_iternext */ |
| 451 0, /* tp_methods */ | 476 ast_type_methods, /* tp_methods */ |
| 452 0, /* tp_members */ | 477 0, /* tp_members */ |
| 453 0, /* tp_getset */ | 478 0, /* tp_getset */ |
| 454 0, /* tp_base */ | 479 0, /* tp_base */ |
| 455 0, /* tp_dict */ | 480 0, /* tp_dict */ |
| 456 0, /* tp_descr_get */ | 481 0, /* tp_descr_get */ |
