Changeset 34 for trunk/ext/_syckmodule.c
- Timestamp:
- 12/27/05 15:52:07 (7 years ago)
- File:
-
- 1 edited
-
trunk/ext/_syckmodule.c (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ext/_syckmodule.c
r25 r34 1030 1030 PySyckParser_node_handler(SyckParser *parser, SyckNode *node) 1031 1031 { 1032 PyGILState_STATE gs; 1033 1032 1034 PySyckParserObject *self = (PySyckParserObject *)parser->bonus; 1033 1035 … … 1040 1042 if (self->halt) 1041 1043 return -1; 1044 1045 gs = PyGILState_Ensure(); 1042 1046 1043 1047 switch (node->kind) { … … 1099 1103 1100 1104 index = PyList_GET_SIZE(self->symbols); 1105 PyGILState_Release(gs); 1101 1106 return index; 1102 1107 1103 1108 error: 1104 1109 Py_XDECREF(object); 1110 PyGILState_Release(gs); 1105 1111 self->halt = 1; 1106 1112 return -1; … … 1110 1116 PySyckParser_error_handler(SyckParser *parser, char *str) 1111 1117 { 1118 PyGILState_STATE gs; 1119 1112 1120 PySyckParserObject *self = (PySyckParserObject *)parser->bonus; 1113 1121 PyObject *value; 1114 1122 1115 1123 if (self->halt) return; 1124 1125 gs = PyGILState_Ensure(); 1116 1126 1117 1127 self->halt = 1; … … 1122 1132 PyErr_SetObject(PySyck_Error, value); 1123 1133 } 1134 1135 PyGILState_Release(gs); 1124 1136 } 1125 1137 … … 1127 1139 PySyckParser_bad_anchor_handler(SyckParser *parser, char *anchor) 1128 1140 { 1141 PyGILState_STATE gs; 1142 1129 1143 PySyckParserObject *self = (PySyckParserObject *)parser->bonus; 1130 1144 1131 1145 if (!self->halt) { 1146 gs = PyGILState_Ensure(); 1147 1132 1148 self->halt = 1; 1133 1149 PyErr_SetString(PyExc_TypeError, "recursive anchors are not implemented"); 1150 1151 PyGILState_Release(gs); 1134 1152 } 1135 1153 … … 1140 1158 PySyckParser_read_handler(char *buf, SyckIoFile *file, long max_size, long skip) 1141 1159 { 1160 PyGILState_STATE gs; 1161 1142 1162 PySyckParserObject *self = (PySyckParserObject *)file->ptr; 1143 1163 … … 1154 1174 1155 1175 max_size -= skip; 1176 1177 gs = PyGILState_Ensure(); 1156 1178 1157 1179 value = PyObject_CallMethod(self->source, "read", "(i)", max_size); 1158 1180 if (!value) { 1159 1181 self->halt = 1; 1182 1183 PyGILState_Release(gs); 1184 1160 1185 return skip; 1161 1186 } … … 1166 1191 self->halt = 1; 1167 1192 1193 PyGILState_Release(gs); 1194 1168 1195 return skip; 1169 1196 } … … 1173 1200 if (!length) { 1174 1201 Py_DECREF(value); 1202 1203 PyGILState_Release(gs); 1204 1175 1205 return skip; 1176 1206 } … … 1180 1210 PyErr_SetString(PyExc_ValueError, "read returns an overly long string"); 1181 1211 self->halt = 1; 1212 1213 PyGILState_Release(gs); 1214 1182 1215 return skip; 1183 1216 } … … 1188 1221 1189 1222 Py_DECREF(value); 1223 1224 PyGILState_Release(gs); 1190 1225 1191 1226 return length; … … 1269 1304 1270 1305 self->parsing = 1; 1306 Py_BEGIN_ALLOW_THREADS 1271 1307 index = syck_parse(self->parser)-1; 1308 Py_END_ALLOW_THREADS 1272 1309 self->parsing = 0; 1273 1310 … … 1550 1587 PySyckEmitter_node_handler(SyckEmitter *emitter, st_data_t id) 1551 1588 { 1589 PyGILState_STATE gs; 1590 1552 1591 PySyckEmitterObject *self = (PySyckEmitterObject *)emitter->bonus; 1553 1592 … … 1563 1602 if (self->halt) return; 1564 1603 1604 gs = PyGILState_Ensure(); 1605 1565 1606 node = (PySyckNodeObject *)PyList_GetItem(self->symbols, id); 1566 1607 if (!node) { 1567 1608 PyErr_SetString(PyExc_RuntimeError, "unknown data id"); 1568 1609 self->halt = 1; 1610 PyGILState_Release(gs); 1569 1611 return; 1570 1612 } … … 1574 1616 if (!tag) { 1575 1617 self->halt = 1; 1618 PyGILState_Release(gs); 1576 1619 return; 1577 1620 } … … 1585 1628 PyErr_SetString(PyExc_TypeError, "value of _syck.Seq must be a list"); 1586 1629 self->halt = 1; 1630 PyGILState_Release(gs); 1587 1631 return; 1588 1632 } … … 1592 1636 if ((index = PyDict_GetItem(self->nodes, item))) { 1593 1637 syck_emit_item(emitter, PyInt_AS_LONG(index)); 1594 if (self->halt) return; 1638 if (self->halt) { 1639 PyGILState_Release(gs); 1640 return; 1641 } 1595 1642 } 1596 1643 else { 1597 1644 PyErr_SetString(PyExc_RuntimeError, "sequence item is not marked"); 1598 1645 self->halt = 1; 1646 PyGILState_Release(gs); 1599 1647 return; 1600 1648 } … … 1615 1663 "value of _syck.Map must be a list of pairs or a dictionary"); 1616 1664 self->halt = 1; 1665 PyGILState_Release(gs); 1617 1666 return; 1618 1667 } … … 1621 1670 if ((index = PyDict_GetItem(self->nodes, item))) { 1622 1671 syck_emit_item(emitter, PyInt_AS_LONG(index)); 1623 if (self->halt) return; 1672 if (self->halt) { 1673 PyGILState_Release(gs); 1674 return; 1675 } 1624 1676 } 1625 1677 else { 1626 1678 PyErr_SetString(PyExc_RuntimeError, "mapping item is not marked"); 1627 1679 self->halt = 1; 1680 PyGILState_Release(gs); 1628 1681 return; 1629 1682 } … … 1638 1691 if ((index = PyDict_GetItem(self->nodes, item))) { 1639 1692 syck_emit_item(emitter, PyInt_AS_LONG(index)); 1640 if (self->halt) return; 1693 if (self->halt) { 1694 PyGILState_Release(gs); 1695 return; 1696 } 1641 1697 } 1642 1698 else { 1643 1699 PyErr_SetString(PyExc_RuntimeError, "mapping item is not marked"); 1644 1700 self->halt = 1; 1701 PyGILState_Release(gs); 1645 1702 return; 1646 1703 } … … 1652 1709 "value of _syck.Map must be a list of pairs or a dictionary"); 1653 1710 self->halt = 1; 1711 PyGILState_Release(gs); 1654 1712 return; 1655 1713 } … … 1661 1719 if (PyString_AsStringAndSize(node->value, &str, &len) < 0) { 1662 1720 self->halt = 1; 1721 PyGILState_Release(gs); 1663 1722 return; 1664 1723 } … … 1672 1731 PyErr_SetString(PyExc_TypeError, "Node instance is required"); 1673 1732 self->halt = 1; 1733 PyGILState_Release(gs); 1674 1734 return; 1675 1735 } 1676 } 1736 PyGILState_Release(gs); 1737 } 1738 1677 1739 static void 1678 1740 PySyckEmitter_write_handler(SyckEmitter *emitter, char *buf, long len) 1679 1741 { 1742 PyGILState_STATE gs; 1743 1680 1744 PySyckEmitterObject *self = (PySyckEmitterObject *)emitter->bonus; 1745 1746 gs = PyGILState_Ensure(); 1681 1747 1682 1748 if (!PyObject_CallMethod(self->output, "write", "(s#)", buf, len)) 1683 1749 self->halt = 1; 1750 1751 PyGILState_Release(gs); 1684 1752 } 1685 1753 … … 1941 2009 } 1942 2010 2011 Py_BEGIN_ALLOW_THREADS 1943 2012 syck_emit(self->emitter, 0); 1944 2013 syck_emitter_flush(self->emitter, 0); 2014 Py_END_ALLOW_THREADS 1945 2015 1946 2016 syck_free_emitter(self->emitter);
Note: See TracChangeset
for help on using the changeset viewer.
