comparison configmix/_speedups.c @ 703:193a616e0b3c

Begin implementation of filter-only expansions (recursive with respect to expansion)
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 14 Aug 2023 09:31:27 +0200
parents 2b1c7a68f913
children 457ef358c1a0
comparison
equal deleted inserted replaced
702:58dc57bed012 703:193a616e0b3c
31 PyObject *QUOTE_MAP; 31 PyObject *QUOTE_MAP;
32 PyObject *MISSING; 32 PyObject *MISSING;
33 PyObject *MARKER; 33 PyObject *MARKER;
34 PyObject *STARTTOK; 34 PyObject *STARTTOK;
35 PyObject *ENDTOK; 35 PyObject *ENDTOK;
36 PyObject *ENDTOK_FILTER;
36 PyObject *REF_NAMESPACE; 37 PyObject *REF_NAMESPACE;
37 PyObject *DEL_VALUE; 38 PyObject *DEL_VALUE;
38 }; 39 };
39 40
40 41
911 tmp = _fast_split_filters(varname, NULL, sstate); 912 tmp = _fast_split_filters(varname, NULL, sstate);
912 if (tmp == NULL) { 913 if (tmp == NULL) {
913 goto error; 914 goto error;
914 } 915 }
915 if (PyTuple_Size(tmp) != 2) { 916 if (PyTuple_Size(tmp) != 2) {
917 py_clear_ref(&tmp);
916 PyErr_SetString(PyExc_TypeError, "tuple of size 2 expected"); 918 PyErr_SetString(PyExc_TypeError, "tuple of size 2 expected");
917 py_clear_ref(&tmp);
918 goto error; 919 goto error;
919 } 920 }
920 py_clear_ref(&varname); 921 py_clear_ref(&varname);
921 /* Unpack the result tuple */ 922 /* Unpack the result tuple */
922 /* borrowed -- cannot fail -- need ownership */ 923 /* borrowed -- cannot fail -- need ownership */
1096 } 1097 }
1097 else { 1098 else {
1098 return Py_NewRef(result); 1099 return Py_NewRef(result);
1099 } 1100 }
1100 } 1101 }
1102 }
1103
1104 if ((s_len >= 6)
1105 && (start == 0)
1106 && (PyUnicode_ReadChar(s, 2) == 0x7c /* | */)) {
1107 end = PyUnicode_Find(s, sstate->ENDTOK_FILTER, start+3, s_len, 1);
1108 if (end == -2) {
1109 return NULL;
1110 }
1111 if (end != (s_len - 3)) {
1112 PyErr_SetString(PyExc_ValueError, "XXX") ; /*`{{|' global filter interpolation must end with `|}}'"); */
1113 return NULL;
1114 }
1115 tmp = PyUnicode_Substring(s, 3, s_len-3);
1116 if (tmp == NULL) {
1117 return NULL;
1118 }
1119 filters = _fast_split_filters(tmp, NULL, sstate);
1120 if (filters == NULL) {
1121 py_clear_ref(&tmp);
1122 return NULL;
1123 }
1124 if (PyTuple_Size(filters) != 2) {
1125 py_clear_ref(&tmp);
1126 PyErr_SetString(PyExc_TypeError, "tuple of size 2 expected");
1127 goto error;
1128 }
1129 py_transfer_owned(&tmp, &filters);
1130
1131 /* XXX TBD */
1132 py_clear_ref(&tmp);
1133 PyErr_SetString(PyExc_KeyError, "ERRRRRRR in C");
1134 return NULL;
1101 } 1135 }
1102 1136
1103 result = PyList_New(0); 1137 result = PyList_New(0);
1104 if (result == NULL) { 1138 if (result == NULL) {
1105 return NULL; 1139 return NULL;
1732 if (sstate->ENDTOK == NULL) { 1766 if (sstate->ENDTOK == NULL) {
1733 return -1; 1767 return -1;
1734 } 1768 }
1735 PyUnicode_InternInPlace(&(sstate->ENDTOK)); 1769 PyUnicode_InternInPlace(&(sstate->ENDTOK));
1736 1770
1771 sstate->ENDTOK_FILTER = PyUnicode_FromStringAndSize("|}}", 3);
1772 if (sstate->ENDTOK_FILTER == NULL) {
1773 return -1;
1774 }
1775 PyUnicode_InternInPlace(&(sstate->ENDTOK_FILTER));
1776
1737 sstate->REF_NAMESPACE = PyUnicode_FromStringAndSize("ref", 3); 1777 sstate->REF_NAMESPACE = PyUnicode_FromStringAndSize("ref", 3);
1738 if (sstate->REF_NAMESPACE == NULL) { 1778 if (sstate->REF_NAMESPACE == NULL) {
1739 return -1; 1779 return -1;
1740 } 1780 }
1741 PyUnicode_InternInPlace(&(sstate->REF_NAMESPACE)); 1781 PyUnicode_InternInPlace(&(sstate->REF_NAMESPACE));
1767 Py_VISIT(sstate->QUOTE_MAP); 1807 Py_VISIT(sstate->QUOTE_MAP);
1768 Py_VISIT(sstate->MISSING); 1808 Py_VISIT(sstate->MISSING);
1769 Py_VISIT(sstate->MARKER); 1809 Py_VISIT(sstate->MARKER);
1770 Py_VISIT(sstate->STARTTOK); 1810 Py_VISIT(sstate->STARTTOK);
1771 Py_VISIT(sstate->ENDTOK); 1811 Py_VISIT(sstate->ENDTOK);
1812 Py_VISIT(sstate->ENDTOK_FILTER);
1772 Py_VISIT(sstate->REF_NAMESPACE); 1813 Py_VISIT(sstate->REF_NAMESPACE);
1773 Py_VISIT(sstate->DEL_VALUE); 1814 Py_VISIT(sstate->DEL_VALUE);
1774 } 1815 }
1775 return 0; 1816 return 0;
1776 } 1817 }
1793 Py_CLEAR(sstate->QUOTE_MAP); 1834 Py_CLEAR(sstate->QUOTE_MAP);
1794 Py_CLEAR(sstate->MISSING); 1835 Py_CLEAR(sstate->MISSING);
1795 Py_CLEAR(sstate->MARKER); 1836 Py_CLEAR(sstate->MARKER);
1796 Py_CLEAR(sstate->STARTTOK); 1837 Py_CLEAR(sstate->STARTTOK);
1797 Py_CLEAR(sstate->ENDTOK); 1838 Py_CLEAR(sstate->ENDTOK);
1839 Py_CLEAR(sstate->ENDTOK_FILTER);
1798 Py_CLEAR(sstate->REF_NAMESPACE); 1840 Py_CLEAR(sstate->REF_NAMESPACE);
1799 Py_CLEAR(sstate->DEL_VALUE); 1841 Py_CLEAR(sstate->DEL_VALUE);
1800 } 1842 }
1801 return 0; 1843 return 0;
1802 } 1844 }