Changeset 388 for python/vendor/current/Modules/pyexpat.c
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Modules/pyexpat.c
r2 r388 246 246 used right after `flag_error()` is called. */ 247 247 static void 248 noop_character_data_handler(void *userData, const XML_Char *data, int len) 248 noop_character_data_handler(void *userData, const XML_Char *data, int len) 249 249 { 250 250 /* Do nothing. */ … … 262 262 getcode(enum HandlerTypes slot, char* func_name, int lineno) 263 263 { 264 PyObject *code = NULL;265 PyObject *name = NULL;266 PyObject *nulltuple = NULL;267 PyObject *filename = NULL;268 269 264 if (handler_info[slot].tb_code == NULL) { 270 code = PyString_FromString("");271 if (code == NULL)272 goto failed;273 name = PyString_FromString(func_name);274 if (name == NULL)275 goto failed;276 nulltuple = PyTuple_New(0);277 if (nulltuple == NULL)278 goto failed;279 filename = PyString_FromString(__FILE__);280 265 handler_info[slot].tb_code = 281 PyCode_New(0, /* argcount */ 282 0, /* nlocals */ 283 0, /* stacksize */ 284 0, /* flags */ 285 code, /* code */ 286 nulltuple, /* consts */ 287 nulltuple, /* names */ 288 nulltuple, /* varnames */ 289 #if PYTHON_API_VERSION >= 1010 290 nulltuple, /* freevars */ 291 nulltuple, /* cellvars */ 292 #endif 293 filename, /* filename */ 294 name, /* name */ 295 lineno, /* firstlineno */ 296 code /* lnotab */ 297 ); 298 if (handler_info[slot].tb_code == NULL) 299 goto failed; 300 Py_DECREF(code); 301 Py_DECREF(nulltuple); 302 Py_DECREF(filename); 303 Py_DECREF(name); 266 PyCode_NewEmpty(__FILE__, func_name, lineno); 304 267 } 305 268 return handler_info[slot].tb_code; 306 failed:307 Py_XDECREF(code);308 Py_XDECREF(name);309 return NULL;310 269 } 311 270 … … 316 275 int result = 0; 317 276 if (!tstate->use_tracing || tstate->tracing) 318 277 return 0; 319 278 if (tstate->c_profilefunc != NULL) { 320 321 322 323 324 325 326 327 279 tstate->tracing++; 280 result = tstate->c_profilefunc(tstate->c_profileobj, 281 f, code , val); 282 tstate->use_tracing = ((tstate->c_tracefunc != NULL) 283 || (tstate->c_profilefunc != NULL)); 284 tstate->tracing--; 285 if (result) 286 return result; 328 287 } 329 288 if (tstate->c_tracefunc != NULL) { 330 331 332 333 334 335 336 } 289 tstate->tracing++; 290 result = tstate->c_tracefunc(tstate->c_traceobj, 291 f, code , val); 292 tstate->use_tracing = ((tstate->c_tracefunc != NULL) 293 || (tstate->c_profilefunc != NULL)); 294 tstate->tracing--; 295 } 337 296 return result; 338 297 } … … 345 304 346 305 if (tstate->c_tracefunc == NULL) 347 306 return 0; 348 307 349 308 PyErr_Fetch(&type, &value, &traceback); 350 309 if (value == NULL) { 351 352 310 value = Py_None; 311 Py_INCREF(value); 353 312 } 354 313 #if PY_VERSION_HEX < 0x02040000 … … 358 317 #endif 359 318 if (arg == NULL) { 360 361 319 PyErr_Restore(type, value, traceback); 320 return 0; 362 321 } 363 322 err = trace_frame(tstate, f, PyTrace_EXCEPTION, arg); 364 323 Py_DECREF(arg); 365 324 if (err == 0) 366 325 PyErr_Restore(type, value, traceback); 367 326 else { 368 369 370 327 Py_XDECREF(type); 328 Py_XDECREF(value); 329 Py_XDECREF(traceback); 371 330 } 372 331 return err; … … 384 343 if (c == NULL) 385 344 return NULL; 386 345 387 346 f = PyFrame_New(tstate, c, PyEval_GetGlobals(), NULL); 388 347 if (f == NULL) … … 391 350 #ifdef FIX_TRACE 392 351 if (trace_frame(tstate, f, PyTrace_CALL, Py_None) < 0) { 393 352 return NULL; 394 353 } 395 354 #endif 396 355 res = PyEval_CallObject(func, args); 397 356 if (res == NULL) { 398 399 357 if (tstate->curexc_traceback == NULL) 358 PyTraceBack_Here(f); 400 359 XML_StopParser(self->itself, XML_FALSE); 401 360 #ifdef FIX_TRACE 402 403 404 361 if (trace_frame_exc(tstate, f) < 0) { 362 return NULL; 363 } 405 364 } 406 365 else { 407 408 409 410 366 if (trace_frame(tstate, f, PyTrace_RETURN, res) < 0) { 367 Py_XDECREF(res); 368 res = NULL; 369 } 411 370 } 412 371 #else … … 433 392 /* result can be NULL if the unicode conversion failed. */ 434 393 if (!result) 435 394 return result; 436 395 if (!self->intern) 437 396 return result; 438 397 value = PyDict_GetItem(self->intern, result); 439 398 if (!value) { 440 399 if (PyDict_SetItem(self->intern, result, result) == 0) 441 400 return result; 442 401 else … … 457 416 PyObject *temp; 458 417 418 if (!have_handler(self, CharacterData)) 419 return -1; 420 459 421 args = PyTuple_New(1); 460 422 if (args == NULL) 461 423 return -1; 462 424 #ifdef Py_USING_UNICODE 463 temp = (self->returns_unicode 464 ? conv_string_len_to_unicode(buffer, len) 425 temp = (self->returns_unicode 426 ? conv_string_len_to_unicode(buffer, len) 465 427 : conv_string_len_to_utf8(buffer, len)); 466 428 #else … … 504 466 505 467 static void 506 my_CharacterDataHandler(void *userData, const XML_Char *data, int len) 468 my_CharacterDataHandler(void *userData, const XML_Char *data, int len) 507 469 { 508 470 xmlparseobject *self = (xmlparseobject *) userData; … … 644 606 645 607 #define VOID_HANDLER(NAME, PARAMS, PARAM_FORMAT) \ 646 647 608 RC_HANDLER(void, NAME, PARAMS, ;, PARAM_FORMAT, ;, ;,\ 609 (xmlparseobject *)userData) 648 610 649 611 #define INT_HANDLER(NAME, PARAMS, PARAM_FORMAT)\ 650 651 652 612 RC_HANDLER(int, NAME, PARAMS, int rc=0;, PARAM_FORMAT, \ 613 rc = PyInt_AsLong(rv);, rc, \ 614 (xmlparseobject *)userData) 653 615 654 616 VOID_HANDLER(EndElement, … … 823 785 824 786 VOID_HANDLER(NotationDecl, 825 826 827 828 829 787 (void *userData, 788 const XML_Char *notationName, 789 const XML_Char *base, 790 const XML_Char *systemId, 791 const XML_Char *publicId), 830 792 ("(NNNN)", 831 832 793 string_intern(self, notationName), string_intern(self, base), 794 string_intern(self, systemId), string_intern(self, publicId))) 833 795 834 796 VOID_HANDLER(StartNamespaceDecl, 835 836 837 797 (void *userData, 798 const XML_Char *prefix, 799 const XML_Char *uri), 838 800 ("(NN)", 839 801 string_intern(self, prefix), string_intern(self, uri))) 840 802 841 803 VOID_HANDLER(EndNamespaceDecl, 842 843 804 (void *userData, 805 const XML_Char *prefix), 844 806 ("(N)", string_intern(self, prefix))) 845 807 … … 850 812 VOID_HANDLER(StartCdataSection, 851 813 (void *userData), 852 814 ("()")) 853 815 854 816 VOID_HANDLER(EndCdataSection, 855 817 (void *userData), 856 818 ("()")) 857 819 858 820 #ifndef Py_USING_UNICODE 859 821 VOID_HANDLER(Default, 860 861 822 (void *userData, const XML_Char *s, int len), 823 ("(N)", conv_string_len_to_utf8(s,len))) 862 824 863 825 VOID_HANDLER(DefaultHandlerExpand, 864 865 826 (void *userData, const XML_Char *s, int len), 827 ("(N)", conv_string_len_to_utf8(s,len))) 866 828 #else 867 829 VOID_HANDLER(Default, 868 869 870 871 830 (void *userData, const XML_Char *s, int len), 831 ("(N)", (self->returns_unicode 832 ? conv_string_len_to_unicode(s,len) 833 : conv_string_len_to_utf8(s,len)))) 872 834 873 835 VOID_HANDLER(DefaultHandlerExpand, 874 875 876 877 836 (void *userData, const XML_Char *s, int len), 837 ("(N)", (self->returns_unicode 838 ? conv_string_len_to_unicode(s,len) 839 : conv_string_len_to_utf8(s,len)))) 878 840 #endif 879 841 880 842 INT_HANDLER(NotStandalone, 881 882 843 (void *userData), 844 ("()")) 883 845 884 846 RC_HANDLER(int, ExternalEntityRef, 885 886 887 888 889 890 847 (XML_Parser parser, 848 const XML_Char *context, 849 const XML_Char *base, 850 const XML_Char *systemId, 851 const XML_Char *publicId), 852 int rc=0;, 891 853 ("(O&NNN)", 892 893 894 895 854 STRING_CONV_FUNC,context, string_intern(self, base), 855 string_intern(self, systemId), string_intern(self, publicId)), 856 rc = PyInt_AsLong(rv);, rc, 857 XML_GetUserData(parser)) 896 858 897 859 /* XXX UnknownEncodingHandler */ … … 1001 963 { 1002 964 int rv = 1; 1003 FILE *fp;1004 965 PyObject *readmethod = NULL; 1005 966 1006 if (PyFile_Check(f)) { 1007 fp = PyFile_AsFile(f); 1008 } 1009 else { 1010 fp = NULL; 1011 readmethod = PyObject_GetAttrString(f, "read"); 1012 if (readmethod == NULL) { 1013 PyErr_Clear(); 1014 PyErr_SetString(PyExc_TypeError, 1015 "argument must have 'read' attribute"); 1016 return NULL; 1017 } 967 readmethod = PyObject_GetAttrString(f, "read"); 968 if (readmethod == NULL) { 969 PyErr_SetString(PyExc_TypeError, 970 "argument must have 'read' attribute"); 971 return NULL; 972 1018 973 } 1019 974 for (;;) { … … 1025 980 } 1026 981 1027 if (fp) { 1028 bytes_read = fread(buf, sizeof(char), BUF_SIZE, fp); 1029 if (bytes_read < 0) { 1030 PyErr_SetFromErrno(PyExc_IOError); 1031 return NULL; 1032 } 1033 } 1034 else { 1035 bytes_read = readinst(buf, BUF_SIZE, readmethod); 1036 if (bytes_read < 0) { 1037 Py_DECREF(readmethod); 1038 return NULL; 1039 } 1040 } 982 bytes_read = readinst(buf, BUF_SIZE, readmethod); 983 if (bytes_read < 0) { 984 Py_XDECREF(readmethod); 985 return NULL; 986 } 987 1041 988 rv = XML_ParseBuffer(self->itself, bytes_read, bytes_read == 0); 1042 989 if (PyErr_Occurred()) { … … 1064 1011 return NULL; 1065 1012 if (!XML_SetBase(self->itself, base)) { 1066 1013 return PyErr_NoMemory(); 1067 1014 } 1068 1015 Py_INCREF(Py_None); … … 1155 1102 new_parser->ns_prefixes = self->ns_prefixes; 1156 1103 new_parser->itself = XML_ExternalEntityParserCreate(self->itself, context, 1157 1104 encoding); 1158 1105 new_parser->handlers = 0; 1159 1106 new_parser->intern = self->intern; … … 1228 1175 { 1229 1176 PyObject *flagobj = NULL; 1230 XML_Bool flag = XML_TRUE;1177 int flag = 1; 1231 1178 enum XML_Error rc; 1232 if (!PyArg_ UnpackTuple(args, "UseForeignDTD", 0, 1, &flagobj))1179 if (!PyArg_ParseTuple(args, "|O:UseForeignDTD", &flagobj)) 1233 1180 return NULL; 1234 if (flagobj != NULL) 1235 flag = PyObject_IsTrue(flagobj) ? XML_TRUE : XML_FALSE; 1236 rc = XML_UseForeignDTD(self->itself, flag); 1181 if (flagobj != NULL) { 1182 flag = PyObject_IsTrue(flagobj); 1183 if (flag < 0) 1184 return NULL; 1185 } 1186 rc = XML_UseForeignDTD(self->itself, flag ? XML_TRUE : XML_FALSE); 1237 1187 if (rc != XML_ERROR_NONE) { 1238 1188 return set_error(self, rc); … … 1244 1194 1245 1195 static struct PyMethodDef xmlparse_methods[] = { 1246 {"Parse", 1247 METH_VARARGS,xmlparse_Parse__doc__},1196 {"Parse", (PyCFunction)xmlparse_Parse, 1197 METH_VARARGS, xmlparse_Parse__doc__}, 1248 1198 {"ParseFile", (PyCFunction)xmlparse_ParseFile, 1249 METH_O,xmlparse_ParseFile__doc__},1199 METH_O, xmlparse_ParseFile__doc__}, 1250 1200 {"SetBase", (PyCFunction)xmlparse_SetBase, 1251 1201 METH_VARARGS, xmlparse_SetBase__doc__}, 1252 1202 {"GetBase", (PyCFunction)xmlparse_GetBase, 1253 1203 METH_NOARGS, xmlparse_GetBase__doc__}, 1254 1204 {"ExternalEntityParserCreate", (PyCFunction)xmlparse_ExternalEntityParserCreate, 1255 1205 METH_VARARGS, xmlparse_ExternalEntityParserCreate__doc__}, 1256 1206 {"SetParamEntityParsing", (PyCFunction)xmlparse_SetParamEntityParsing, 1257 1207 METH_VARARGS, xmlparse_SetParamEntityParsing__doc__}, 1258 1208 {"GetInputContext", (PyCFunction)xmlparse_GetInputContext, 1259 1209 METH_NOARGS, xmlparse_GetInputContext__doc__}, 1260 1210 #if XML_COMBINED_VERSION >= 19505 1261 1211 {"UseForeignDTD", (PyCFunction)xmlparse_UseForeignDTD, 1262 1263 #endif 1264 {NULL, NULL}/* sentinel */1212 METH_VARARGS, xmlparse_UseForeignDTD__doc__}, 1213 #endif 1214 {NULL, NULL} /* sentinel */ 1265 1215 }; 1266 1216 … … 1282 1232 int i; 1283 1233 for (i = 0; i < 256; i++) { 1284 1234 template_buffer[i] = i; 1285 1235 } 1286 1236 template_buffer[256] = 0; … … 1301 1251 1302 1252 if (_u_string == NULL) 1303 return result; 1253 return result; 1254 1255 if (PyUnicode_GET_SIZE(_u_string) != 256) { 1256 Py_DECREF(_u_string); 1257 PyErr_SetString(PyExc_ValueError, 1258 "multi-byte encodings are not supported"); 1259 return result; 1260 } 1304 1261 1305 1262 for (i = 0; i < 256; i++) { 1306 1307 1308 1309 1310 1311 1263 /* Stupid to access directly, but fast */ 1264 Py_UNICODE c = _u_string->str[i]; 1265 if (c == Py_UNICODE_REPLACEMENT_CHARACTER) 1266 info->map[i] = -1; 1267 else 1268 info->map[i] = c; 1312 1269 } 1313 1270 info->data = NULL; … … 1356 1313 self->itself = XML_ParserCreate(encoding); 1357 1314 } 1315 #if ((XML_MAJOR_VERSION >= 2) && (XML_MINOR_VERSION >= 1)) || defined(XML_HAS_SET_HASH_SALT) 1316 /* This feature was added upstream in libexpat 2.1.0. Our expat copy 1317 * has a backport of this feature where we also define XML_HAS_SET_HASH_SALT 1318 * to indicate that we can still use it. */ 1319 XML_SetHashSalt(self->itself, 1320 (unsigned long)_Py_HashSecret.prefix); 1321 #endif 1358 1322 self->intern = intern; 1359 1323 Py_XINCREF(self->intern); … … 1510 1474 } 1511 1475 1512 #define APPEND(list, str) 1513 do { 1514 PyObject *o = PyString_FromString(str); 1515 if (o != NULL) 1516 PyList_Append(list, o);\1517 Py_XDECREF(o); 1476 #define APPEND(list, str) \ 1477 do { \ 1478 PyObject *o = PyString_FromString(str); \ 1479 if (o != NULL) \ 1480 PyList_Append(list, o); \ 1481 Py_XDECREF(o); \ 1518 1482 } while (0) 1519 1483 … … 1521 1485 int i; 1522 1486 PyObject *rc = PyList_New(0); 1523 1524 1487 if (!rc) 1488 return NULL; 1525 1489 for (i = 0; handler_info[i].name != NULL; i++) { 1526 1490 PyObject *o = get_handler_name(&handler_info[i]); … … 1596 1560 } 1597 1561 if (strcmp(name, "buffer_text") == 0) { 1598 if (PyObject_IsTrue(v)) { 1562 int b = PyObject_IsTrue(v); 1563 if (b < 0) 1564 return -1; 1565 if (b) { 1599 1566 if (self->buffer == NULL) { 1600 1567 self->buffer = malloc(self->buffer_size); … … 1615 1582 } 1616 1583 if (strcmp(name, "namespace_prefixes") == 0) { 1617 i f (PyObject_IsTrue(v))1618 self->ns_prefixes = 1;1619 else1620 self->ns_prefixes = 0;1584 int b = PyObject_IsTrue(v); 1585 if (b < 0) 1586 return -1; 1587 self->ns_prefixes = b; 1621 1588 XML_SetReturnNSTriplet(self->itself, self->ns_prefixes); 1622 1589 return 0; 1623 1590 } 1624 1591 if (strcmp(name, "ordered_attributes") == 0) { 1625 i f (PyObject_IsTrue(v))1626 self->ordered_attributes = 1;1627 else1628 self->ordered_attributes = 0;1592 int b = PyObject_IsTrue(v); 1593 if (b < 0) 1594 return -1; 1595 self->ordered_attributes = b; 1629 1596 return 0; 1630 1597 } 1631 1598 if (strcmp(name, "returns_unicode") == 0) { 1632 if (PyObject_IsTrue(v)) { 1599 int b = PyObject_IsTrue(v); 1600 if (b < 0) 1601 return -1; 1633 1602 #ifndef Py_USING_UNICODE 1603 if (b) { 1634 1604 PyErr_SetString(PyExc_ValueError, 1635 1605 "Unicode support not available"); 1636 1606 return -1; 1637 #else 1638 self->returns_unicode = 1; 1639 #endif 1640 } 1641 else 1642 self->returns_unicode = 0; 1607 } 1608 #endif 1609 self->returns_unicode = b; 1643 1610 return 0; 1644 1611 } 1645 1612 if (strcmp(name, "specified_attributes") == 0) { 1646 i f (PyObject_IsTrue(v))1647 self->specified_attributes = 1;1648 else1649 self->specified_attributes = 0;1613 int b = PyObject_IsTrue(v); 1614 if (b < 0) 1615 return -1; 1616 self->specified_attributes = b; 1650 1617 return 0; 1651 1618 } … … 1654 1621 long new_buffer_size; 1655 1622 if (!PyInt_Check(v)) { 1656 1657 1623 PyErr_SetString(PyExc_TypeError, "buffer_size must be an integer"); 1624 return -1; 1658 1625 } 1659 1626 … … 1661 1628 /* trivial case -- no change */ 1662 1629 if (new_buffer_size == self->buffer_size) { 1663 1630 return 0; 1664 1631 } 1665 1632 1666 1633 if (new_buffer_size <= 0) { 1667 1668 1634 PyErr_SetString(PyExc_ValueError, "buffer_size must be greater than zero"); 1635 return -1; 1669 1636 } 1670 1637 1671 1638 /* check maximum */ 1672 1639 if (new_buffer_size > INT_MAX) { 1673 1674 1675 1676 return -1; 1640 char errmsg[100]; 1641 sprintf(errmsg, "buffer_size must not be greater than %i", INT_MAX); 1642 PyErr_SetString(PyExc_ValueError, errmsg); 1643 return -1; 1677 1644 } 1678 1645 1679 1646 if (self->buffer != NULL) { 1680 1681 1682 1683 1684 1685 1647 /* there is already a buffer */ 1648 if (self->buffer_used != 0) { 1649 flush_character_buffer(self); 1650 } 1651 /* free existing buffer */ 1652 free(self->buffer); 1686 1653 } 1687 1654 self->buffer = malloc(new_buffer_size); 1688 1655 if (self->buffer == NULL) { 1689 1690 1691 } 1656 PyErr_NoMemory(); 1657 return -1; 1658 } 1692 1659 self->buffer_size = new_buffer_size; 1693 1660 return 0; … … 1732 1699 1733 1700 static PyTypeObject Xmlparsetype = { 1734 1735 "pyexpat.xmlparser",/*tp_name*/1736 1737 0,/*tp_itemsize*/1738 1739 (destructor)xmlparse_dealloc,/*tp_dealloc*/1740 (printfunc)0,/*tp_print*/1741 (getattrfunc)xmlparse_getattr,/*tp_getattr*/1742 (setattrfunc)xmlparse_setattr,/*tp_setattr*/1743 (cmpfunc)0,/*tp_compare*/1744 (reprfunc)0,/*tp_repr*/1745 0,/*tp_as_number*/1746 0,/*tp_as_sequence*/1747 0,/*tp_as_mapping*/1748 (hashfunc)0,/*tp_hash*/1749 (ternaryfunc)0,/*tp_call*/1750 (reprfunc)0,/*tp_str*/1751 0,/* tp_getattro */1752 0,/* tp_setattro */1753 0,/* tp_as_buffer */1701 PyVarObject_HEAD_INIT(NULL, 0) 1702 "pyexpat.xmlparser", /*tp_name*/ 1703 sizeof(xmlparseobject) + PyGC_HEAD_SIZE,/*tp_basicsize*/ 1704 0, /*tp_itemsize*/ 1705 /* methods */ 1706 (destructor)xmlparse_dealloc, /*tp_dealloc*/ 1707 (printfunc)0, /*tp_print*/ 1708 (getattrfunc)xmlparse_getattr, /*tp_getattr*/ 1709 (setattrfunc)xmlparse_setattr, /*tp_setattr*/ 1710 (cmpfunc)0, /*tp_compare*/ 1711 (reprfunc)0, /*tp_repr*/ 1712 0, /*tp_as_number*/ 1713 0, /*tp_as_sequence*/ 1714 0, /*tp_as_mapping*/ 1715 (hashfunc)0, /*tp_hash*/ 1716 (ternaryfunc)0, /*tp_call*/ 1717 (reprfunc)0, /*tp_str*/ 1718 0, /* tp_getattro */ 1719 0, /* tp_setattro */ 1720 0, /* tp_as_buffer */ 1754 1721 #ifdef Py_TPFLAGS_HAVE_GC 1755 1722 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 1756 1723 #else 1757 1758 #endif 1759 1724 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /*tp_flags*/ 1725 #endif 1726 Xmlparsetype__doc__, /* tp_doc - Documentation string */ 1760 1727 #ifdef WITH_CYCLE_GC 1761 (traverseproc)xmlparse_traverse,/* tp_traverse */1762 (inquiry)xmlparse_clear/* tp_clear */1728 (traverseproc)xmlparse_traverse, /* tp_traverse */ 1729 (inquiry)xmlparse_clear /* tp_clear */ 1763 1730 #else 1764 1731 0, 0 1765 1732 #endif 1766 1733 }; … … 1797 1764 Not passing anything means that a new dictionary is used. */ 1798 1765 if (intern == Py_None) 1799 1766 intern = NULL; 1800 1767 else if (intern == NULL) { 1801 1802 1803 1804 1768 intern = PyDict_New(); 1769 if (!intern) 1770 return NULL; 1771 intern_decref = 1; 1805 1772 } 1806 1773 else if (!PyDict_Check(intern)) { 1807 1808 1774 PyErr_SetString(PyExc_TypeError, "intern must be a dictionary"); 1775 return NULL; 1809 1776 } 1810 1777 1811 1778 result = newxmlparseobject(encoding, namespace_separator, intern); 1812 1779 if (intern_decref) { 1813 1780 Py_DECREF(intern); 1814 1781 } 1815 1782 return result; … … 1833 1800 1834 1801 static struct PyMethodDef pyexpat_methods[] = { 1835 {"ParserCreate", 1802 {"ParserCreate", (PyCFunction)pyexpat_ParserCreate, 1836 1803 METH_VARARGS|METH_KEYWORDS, pyexpat_ParserCreate__doc__}, 1837 {"ErrorString", 1838 METH_VARARGS, 1839 1840 {NULL, (PyCFunction)NULL, 0, NULL}/* sentinel */1804 {"ErrorString", (PyCFunction)pyexpat_ErrorString, 1805 METH_VARARGS, pyexpat_ErrorString__doc__}, 1806 1807 {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ 1841 1808 }; 1842 1809 … … 1845 1812 PyDoc_STRVAR(pyexpat_module_documentation, 1846 1813 "Python wrapper for Expat parser."); 1847 1848 /* Return a Python string that represents the version number without the1849 * extra cruft added by revision control, even if the right options were1850 * given to the "cvs export" command to make it not include the extra1851 * cruft.1852 */1853 static PyObject *1854 get_version_string(void)1855 {1856 static char *rcsid = "$Revision: 64048 $";1857 char *rev = rcsid;1858 int i = 0;1859 1860 while (!isdigit(Py_CHARMASK(*rev)))1861 ++rev;1862 while (rev[i] != ' ' && rev[i] != '\0')1863 ++i;1864 1865 return PyString_FromStringAndSize(rev, i);1866 }1867 1814 1868 1815 /* Initialization function for the module */ … … 1895 1842 PyObject *model_module; 1896 1843 PyObject *sys_modules; 1844 PyObject *version; 1897 1845 static struct PyExpat_CAPI capi; 1898 1846 PyObject* capi_object; … … 1910 1858 pyexpat_module_documentation); 1911 1859 if (m == NULL) 1912 1860 return; 1913 1861 1914 1862 /* Add some symbolic constants to the module */ … … 1926 1874 PyModule_AddObject(m, "XMLParserType", (PyObject *) &Xmlparsetype); 1927 1875 1928 PyModule_AddObject(m, "__version__", get_version_string()); 1876 version = PyString_FromString(PY_VERSION); 1877 if (!version) 1878 return; 1879 PyModule_AddObject(m, "__version__", version); 1929 1880 PyModule_AddStringConstant(m, "EXPAT_VERSION", 1930 1881 (char *) XML_ExpatVersion()); … … 1969 1920 /* Don't core dump later! */ 1970 1921 return; 1971 1922 1972 1923 #if XML_COMBINED_VERSION > 19505 1973 1924 { … … 2094 2045 capi.SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler; 2095 2046 capi.SetUserData = XML_SetUserData; 2096 2097 /* export as cobject*/2098 capi_object = PyC Object_FromVoidPtr(&capi, NULL);2047 2048 /* export using capsule */ 2049 capi_object = PyCapsule_New(&capi, PyExpat_CAPSULE_NAME, NULL); 2099 2050 if (capi_object) 2100 2051 PyModule_AddObject(m, "expat_CAPI", capi_object); … … 2109 2060 for (; handler_info[i].name != NULL; i++) { 2110 2061 if (initial) 2111 2112 2062 self->handlers[i] = NULL; 2063 else { 2113 2064 temp = self->handlers[i]; 2114 2065 self->handlers[i] = NULL; 2115 2066 Py_XDECREF(temp); 2116 2067 handler_info[i].setter(self->itself, NULL); 2117 2068 } 2118 2069 }
Note:
See TracChangeset
for help on using the changeset viewer.