Ticket #67: _syckmodule.diff
| File _syckmodule.diff, 7.7 KB (added by xi, 6 years ago) |
|---|
-
_syckmodule.c
old new 1029 1029 static SYMID 1030 1030 PySyckParser_node_handler(SyckParser *parser, SyckNode *node) 1031 1031 { 1032 PyGILState_STATE gs;1033 1034 1032 PySyckParserObject *self = (PySyckParserObject *)parser->bonus; 1035 1033 1036 1034 SYMID index; … … 1042 1040 if (self->halt) 1043 1041 return -1; 1044 1042 1045 gs = PyGILState_Ensure();1046 1047 1043 switch (node->kind) { 1048 1044 1049 1045 case syck_str_kind: … … 1104 1100 Py_DECREF(object); 1105 1101 1106 1102 index = PyList_GET_SIZE(self->symbols); 1107 PyGILState_Release(gs);1108 1103 return index; 1109 1104 1110 1105 error: 1111 1106 Py_XDECREF(object); 1112 PyGILState_Release(gs);1113 1107 self->halt = 1; 1114 1108 return -1; 1115 1109 } … … 1117 1111 static void 1118 1112 PySyckParser_error_handler(SyckParser *parser, char *str) 1119 1113 { 1120 PyGILState_STATE gs;1121 1122 1114 PySyckParserObject *self = (PySyckParserObject *)parser->bonus; 1123 1115 PyObject *value; 1124 1116 1125 1117 if (self->halt) return; 1126 1118 1127 gs = PyGILState_Ensure();1128 1129 1119 self->halt = 1; 1130 1120 1131 1121 value = Py_BuildValue("(sii)", str, … … 1134 1124 PyErr_SetObject(PySyck_Error, value); 1135 1125 } 1136 1126 1137 PyGILState_Release(gs);1138 1127 } 1139 1128 1140 1129 SyckNode * 1141 1130 PySyckParser_bad_anchor_handler(SyckParser *parser, char *anchor) 1142 1131 { 1143 PyGILState_STATE gs;1144 1145 1132 PySyckParserObject *self = (PySyckParserObject *)parser->bonus; 1146 1133 1147 1134 if (!self->halt) { 1148 gs = PyGILState_Ensure();1149 1150 1135 self->halt = 1; 1151 1136 PyErr_SetString(PyExc_TypeError, "recursive anchors are not implemented"); 1152 1153 PyGILState_Release(gs);1154 1137 } 1155 1138 1156 1139 return syck_alloc_str(); … … 1159 1142 static long 1160 1143 PySyckParser_read_handler(char *buf, SyckIoFile *file, long max_size, long skip) 1161 1144 { 1162 PyGILState_STATE gs;1163 1164 1145 PySyckParserObject *self = (PySyckParserObject *)file->ptr; 1165 1146 1166 1147 PyObject *value; … … 1176 1157 1177 1158 max_size -= skip; 1178 1159 1179 gs = PyGILState_Ensure();1180 1181 1160 value = PyObject_CallMethod(self->source, "read", "(i)", max_size); 1182 1161 if (!value) { 1183 1162 self->halt = 1; 1184 1163 1185 PyGILState_Release(gs);1186 1187 1164 return skip; 1188 1165 } 1189 1166 … … 1192 1169 PyErr_SetString(PyExc_TypeError, "file-like object should return a string"); 1193 1170 self->halt = 1; 1194 1171 1195 PyGILState_Release(gs);1196 1197 1172 return skip; 1198 1173 } 1199 1174 … … 1202 1177 if (!length) { 1203 1178 Py_DECREF(value); 1204 1179 1205 PyGILState_Release(gs);1206 1207 1180 return skip; 1208 1181 } 1209 1182 … … 1212 1185 PyErr_SetString(PyExc_ValueError, "read returns an overly long string"); 1213 1186 self->halt = 1; 1214 1187 1215 PyGILState_Release(gs);1216 1217 1188 return skip; 1218 1189 } 1219 1190 … … 1223 1194 1224 1195 Py_DECREF(value); 1225 1196 1226 PyGILState_Release(gs);1227 1228 1197 return length; 1229 1198 } 1230 1199 … … 1305 1274 } 1306 1275 1307 1276 self->parsing = 1; 1308 Py_BEGIN_ALLOW_THREADS1309 1277 index = syck_parse(self->parser)-1; 1310 Py_END_ALLOW_THREADS1311 1278 self->parsing = 0; 1312 1279 1313 1280 if (self->halt || self->parser->eof) { … … 1589 1556 static void 1590 1557 PySyckEmitter_node_handler(SyckEmitter *emitter, st_data_t id) 1591 1558 { 1592 PyGILState_STATE gs;1593 1594 1559 PySyckEmitterObject *self = (PySyckEmitterObject *)emitter->bonus; 1595 1560 1596 1561 PySyckNodeObject *node; … … 1604 1569 1605 1570 if (self->halt) return; 1606 1571 1607 gs = PyGILState_Ensure();1608 1609 1572 node = (PySyckNodeObject *)PyList_GetItem(self->symbols, id); 1610 1573 if (!node) { 1611 1574 PyErr_SetString(PyExc_RuntimeError, "unknown data id"); 1612 1575 self->halt = 1; 1613 PyGILState_Release(gs);1614 1576 return; 1615 1577 } 1616 1578 … … 1618 1580 tag = PyString_AsString(node->tag); 1619 1581 if (!tag) { 1620 1582 self->halt = 1; 1621 PyGILState_Release(gs);1622 1583 return; 1623 1584 } 1624 1585 } … … 1630 1591 if (!PyList_Check(node->value)) { 1631 1592 PyErr_SetString(PyExc_TypeError, "value of _syck.Seq must be a list"); 1632 1593 self->halt = 1; 1633 PyGILState_Release(gs);1634 1594 return; 1635 1595 } 1636 1596 l = PyList_GET_SIZE(node->value); … … 1639 1599 if ((index = PyDict_GetItem(self->nodes, item))) { 1640 1600 syck_emit_item(emitter, PyInt_AS_LONG(index)); 1641 1601 if (self->halt) { 1642 PyGILState_Release(gs);1643 1602 return; 1644 1603 } 1645 1604 } 1646 1605 else { 1647 1606 PyErr_SetString(PyExc_RuntimeError, "sequence item is not marked"); 1648 1607 self->halt = 1; 1649 PyGILState_Release(gs);1650 1608 return; 1651 1609 } 1652 1610 } … … 1665 1623 PyErr_SetString(PyExc_TypeError, 1666 1624 "value of _syck.Map must be a list of pairs or a dictionary"); 1667 1625 self->halt = 1; 1668 PyGILState_Release(gs);1669 1626 return; 1670 1627 } 1671 1628 for (j = 0; j < 2; j++) { … … 1673 1630 if ((index = PyDict_GetItem(self->nodes, item))) { 1674 1631 syck_emit_item(emitter, PyInt_AS_LONG(index)); 1675 1632 if (self->halt) { 1676 PyGILState_Release(gs);1677 1633 return; 1678 1634 } 1679 1635 } 1680 1636 else { 1681 1637 PyErr_SetString(PyExc_RuntimeError, "mapping item is not marked"); 1682 1638 self->halt = 1; 1683 PyGILState_Release(gs);1684 1639 return; 1685 1640 } 1686 1641 } … … 1694 1649 if ((index = PyDict_GetItem(self->nodes, item))) { 1695 1650 syck_emit_item(emitter, PyInt_AS_LONG(index)); 1696 1651 if (self->halt) { 1697 PyGILState_Release(gs);1698 1652 return; 1699 1653 } 1700 1654 } 1701 1655 else { 1702 1656 PyErr_SetString(PyExc_RuntimeError, "mapping item is not marked"); 1703 1657 self->halt = 1; 1704 PyGILState_Release(gs);1705 1658 return; 1706 1659 } 1707 1660 } … … 1711 1664 PyErr_SetString(PyExc_TypeError, 1712 1665 "value of _syck.Map must be a list of pairs or a dictionary"); 1713 1666 self->halt = 1; 1714 PyGILState_Release(gs);1715 1667 return; 1716 1668 } 1717 1669 … … 1721 1673 else if (PyObject_TypeCheck((PyObject *)node, &PySyckScalar_Type)) { 1722 1674 if (PyString_AsStringAndSize(node->value, &str, &len) < 0) { 1723 1675 self->halt = 1; 1724 PyGILState_Release(gs);1725 1676 return; 1726 1677 } 1727 1678 syck_emit_scalar(emitter, tag, ((PySyckScalarObject *)node)->style, … … 1733 1684 else { 1734 1685 PyErr_SetString(PyExc_TypeError, "Node instance is required"); 1735 1686 self->halt = 1; 1736 PyGILState_Release(gs);1737 1687 return; 1738 1688 } 1739 PyGILState_Release(gs);1740 1689 } 1741 1690 1742 1691 static void 1743 1692 PySyckEmitter_write_handler(SyckEmitter *emitter, char *buf, long len) 1744 1693 { 1745 PyGILState_STATE gs;1746 1747 1694 PySyckEmitterObject *self = (PySyckEmitterObject *)emitter->bonus; 1748 1695 1749 gs = PyGILState_Ensure();1750 1751 1696 if (!PyObject_CallMethod(self->output, "write", "(s#)", buf, len)) 1752 1697 self->halt = 1; 1753 1754 PyGILState_Release(gs);1755 1698 } 1756 1699 1757 1700 static int … … 2011 1954 return NULL; 2012 1955 } 2013 1956 2014 Py_BEGIN_ALLOW_THREADS2015 1957 syck_emit(self->emitter, 0); 2016 1958 syck_emitter_flush(self->emitter, 0); 2017 Py_END_ALLOW_THREADS2018 1959 2019 1960 syck_free_emitter(self->emitter); 2020 1961 self->emitter = NULL; … … 2138 2079 { 2139 2080 PyObject *m; 2140 2081 2141 PyEval_InitThreads(); /* Fix segfault for Python 2.3 */2142 2143 2082 if (PyType_Ready(&PySyckNode_Type) < 0) 2144 2083 return; 2145 2084 if (PyType_Ready(&PySyckScalar_Type) < 0)
