Mercurial > hgrepos > Python > libs > ConfigMix
annotate configmix/_speedups.c @ 705:0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
This allows using filter chains in filter-only expansions also.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 15 Aug 2023 09:34:49 +0200 |
| parents | 457ef358c1a0 |
| children | 10fbc23b4dba |
| rev | line source |
|---|---|
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1 /* -*- coding: utf-8 -*- */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
2 /* |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
3 * Speedups for configmix. |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
4 * |
|
593
f454889e41fa
Adjust copyright year (the end) to 2022
Franz Glasner <fzglas.hg@dom66.de>
parents:
566
diff
changeset
|
5 * :Copyright: (c) 2021-2022, Franz Glasner. All rights reserved. |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
6 * :License: BSD-3-Clause. See LICENSE.txt for details. |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
7 */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
8 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
9 #define PY_SSIZE_T_CLEAN |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
10 #include "Python.h" |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
11 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
12 #include "_py_helper.h" |
|
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
13 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
14 |
|
609
9ad860d6ddc9
Change the external visible (and ELF-interposable) variable "_id" to "_configmix_speedups_id".
Franz Glasner <fzglas.hg@dom66.de>
parents:
605
diff
changeset
|
15 const char _configmix_speedups_id[] = "@(#)configmix._speedups $Header$"; |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
16 static const char release[] = "|VCSRevision|"; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
17 static const char date[] = "|VCSJustDate|"; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
18 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
19 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
20 /* |
| 612 | 21 * Module state holds some pre-created objects |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
22 */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
23 struct speedups_state { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
24 PyObject *DOT; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
25 PyObject *QUOTE; |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
26 PyObject *NS_SEPARATOR; |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
27 PyObject *FILTER_SEPARATOR; |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
28 PyObject *FILTER_SEPARATOR_REV; |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
29 PyObject *EMPTY_FILTER; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
30 PyObject *NONE_FILTER; |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
31 PyObject *EMPTY_STR; |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
32 PyObject *QUOTE_MAP; |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
33 PyObject *MISSING; |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
34 PyObject *MARKER; |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
35 PyObject *STARTTOK; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
36 PyObject *ENDTOK; |
|
703
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
37 PyObject *ENDTOK_FILTER; |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
38 PyObject *REF_NAMESPACE; |
|
637
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
39 PyObject *DEL_VALUE; |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
40 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
41 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
42 |
|
614
7e480a32d9d5
Prototype declaration with paremeter names
Franz Glasner <fzglas.hg@dom66.de>
parents:
612
diff
changeset
|
43 static PyObject * _fast_getvar_s(PyObject *config, PyObject *varname, PyObject *default_, struct speedups_state *sstate, int *cacheable); |
|
704
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
44 static PyObject * _fast_interpolate_variables(PyObject *self, PyObject *config, PyObject *s, PyObject *cache); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
45 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
46 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
47 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
48 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
49 _hex2ucs4(PyObject *s, Py_ssize_t end, Py_UCS4 *result) |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
50 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
51 Py_ssize_t i; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
52 Py_UCS4 c; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
53 Py_UCS4 r = 0; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
54 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
55 for (i=1; i < end; i++) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
56 r *= 16; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
57 c = PyUnicode_ReadChar(s, i); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
58 if ((c >= 48) && (c <= 57)) { /* 0 - 9 */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
59 r += (c - 48); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
60 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
61 else { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
62 if ((c >= 97) && (c <= 102)) { /* a - f */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
63 r += (c - 87); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
64 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
65 else { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
66 if ((c >= 65) && (c <= 70)) { /* A - F */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
67 r += (c - 55); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
68 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
69 else { |
|
630
33264c660fca
Exception formatting: more into into some exception error messages
Franz Glasner <fzglas.hg@dom66.de>
parents:
627
diff
changeset
|
70 PyErr_Format(PyExc_ValueError, "invalid base-16 literal: %c", (int)c); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
71 return -1; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
72 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
73 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
74 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
75 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
76 *result = r; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
77 return 0; /* success */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
78 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
79 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
80 |
|
656
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
81 static |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
82 int |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
83 _dec2num(PyObject *s, Py_ssize_t start, Py_ssize_t end, Py_ssize_t *result) |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
84 { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
85 Py_ssize_t i; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
86 Py_UCS4 c; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
87 Py_ssize_t r = 0; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
88 int sign = 0; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
89 |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
90 for (i=start; i<=end; i++) { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
91 /* Overflow error check */ |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
92 if (r > 3275) { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
93 PyErr_SetString(PyExc_OverflowError, "index too large"); |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
94 return -1; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
95 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
96 r *= 10; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
97 c = PyUnicode_ReadChar(s, i); |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
98 if ((c >= 48) && (c <= 57)) { /* 0 - 9 */ |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
99 r += (c - 48); |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
100 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
101 else { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
102 if (i == start) { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
103 /* check for number sign (but only at the first index) */ |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
104 if (c == 0x2d) { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
105 sign = -1; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
106 continue; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
107 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
108 else { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
109 if (c == 0x2b) { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
110 sign = 1; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
111 continue; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
112 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
113 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
114 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
115 PyErr_Format(PyExc_ValueError, "invalid base-10 literal: %c", (int)c); |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
116 return -1; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
117 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
118 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
119 if (sign >= 0) { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
120 *result = r; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
121 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
122 else { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
123 *result = -r; |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
124 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
125 return 0; /* success */ |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
126 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
127 |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
128 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
129 #if defined(Py_LIMITED_API) |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
130 |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
131 static |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
132 void |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
133 _raise_utf8_encode_error(PyObject *s, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
134 Py_ssize_t start, Py_ssize_t end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
135 const char *reason) |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
136 { |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
137 /* |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
138 * See also: https://docs.python.org/3/c-api/exceptions.html#unicode-exception-objects |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
139 */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
140 PyObject *errobj = PyObject_CallFunction( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
141 PyExc_UnicodeEncodeError, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
142 "sOnns", |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
143 "utf-8", |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
144 s, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
145 start, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
146 end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
147 reason); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
148 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
149 if (errobj == NULL) { |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
150 /* cannot do anything here */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
151 return; |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
152 } |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
153 /* Make PyExc_UnicodeEncodeError owned because PyErr_Restore steals */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
154 //Py_INCREF(PyExc_UnicodeEncodeError); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
155 //PyErr_Restore(PyExc_UnicodeEncodeError, errobj, NULL); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
156 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
157 PyErr_SetObject(PyExc_UnicodeEncodeError, errobj); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
158 Py_DECREF(errobj); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
159 } |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
160 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
161 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
162 /* |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
163 * Copyright 2001-2004 Unicode, Inc. |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
164 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
165 * Disclaimer |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
166 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
167 * This source code is provided as is by Unicode, Inc. No claims are |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
168 * made as to fitness for any particular purpose. No warranties of any |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
169 * kind are expressed or implied. The recipient agrees to determine |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
170 * applicability of information provided. If this file has been |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
171 * purchased on magnetic or optical media from Unicode, Inc., the |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
172 * sole remedy for any claim will be exchange of defective media |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
173 * within 90 days of receipt. |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
174 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
175 * Limitations on Rights to Redistribute This Code |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
176 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
177 * Unicode, Inc. hereby grants the right to freely use the information |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
178 * supplied in this file in the creation of products supporting the |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
179 * Unicode Standard, and to make copies of this file in any form |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
180 * for internal or external distribution as long as this notice |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
181 * remains attached. |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
182 */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
183 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
184 #define UNI_MAX_LEGAL_UTF32 (Py_UCS4)0x0010FFFF |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
185 #define UNI_SUR_HIGH_START (Py_UCS4)0xD800 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
186 #define UNI_SUR_HIGH_END (Py_UCS4)0xDBFF |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
187 #define UNI_SUR_LOW_START (Py_UCS4)0xDC00 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
188 #define UNI_SUR_LOW_END (Py_UCS4)0xDFFF |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
189 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
190 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
191 /* |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
192 * Once the bits are split out into bytes of UTF-8, this is a mask OR-ed |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
193 * into the first byte, depending on how many bytes follow. There are |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
194 * as many entries in this table as there are UTF-8 sequence types. |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
195 * (I.e., one byte sequence, two byte... etc.). Remember that sequencs |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
196 * for *legal* UTF-8 will be 4 or fewer bytes total. |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
197 */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
198 static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
199 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
200 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
201 static |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
202 Py_ssize_t |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
203 _convert_ucs4_to_utf8( |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
204 Py_UCS4 ch, |
|
564
44e18fbf7741
Refactor: signature of _convert_ucs4_to_utf8(): change order of args
Franz Glasner <fzglas.hg@dom66.de>
parents:
562
diff
changeset
|
205 unsigned char *targetStart, unsigned char *targetEnd, |
|
44e18fbf7741
Refactor: signature of _convert_ucs4_to_utf8(): change order of args
Franz Glasner <fzglas.hg@dom66.de>
parents:
562
diff
changeset
|
206 int strict, |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
207 PyObject *ch_obj, /* for error messages: the string where ch comes from */ |
|
564
44e18fbf7741
Refactor: signature of _convert_ucs4_to_utf8(): change order of args
Franz Glasner <fzglas.hg@dom66.de>
parents:
562
diff
changeset
|
208 Py_ssize_t ch_obj_end /* effective length of ch_obj (error reporting) */ |
|
44e18fbf7741
Refactor: signature of _convert_ucs4_to_utf8(): change order of args
Franz Glasner <fzglas.hg@dom66.de>
parents:
562
diff
changeset
|
209 ) |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
210 { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
211 const Py_UCS4 byteMask = 0xBF; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
212 const Py_UCS4 byteMark = 0x80; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
213 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
214 Py_ssize_t bytesToWrite = 0; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
215 unsigned char *target = targetStart; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
216 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
217 if (strict) { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
218 /* UTF-16 surrogate values are illegal */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
219 if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) { |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
220 _raise_utf8_encode_error( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
221 ch_obj, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
222 1, ch_obj_end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
223 "surrogate values are illegal in UCS4"); |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
224 return -1; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
225 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
226 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
227 /* |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
228 * Figure out how many bytes the result will require. Turn any |
| 556 | 229 * illegally large UTF32 things (> Plane 17) into errors (exceptions). |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
230 */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
231 if (ch < (Py_UCS4)0x80) { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
232 bytesToWrite = 1; |
| 565 | 233 } |
| 234 else if (ch < (Py_UCS4)0x800) { | |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
235 bytesToWrite = 2; |
| 565 | 236 } |
| 237 else if (ch < (Py_UCS4)0x10000) { | |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
238 bytesToWrite = 3; |
| 565 | 239 } |
| 240 else if (ch <= UNI_MAX_LEGAL_UTF32) { | |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
241 bytesToWrite = 4; |
| 565 | 242 } |
| 243 else { | |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
244 _raise_utf8_encode_error( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
245 ch_obj, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
246 1, ch_obj_end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
247 "max Unicode codepoint value exceeded"); |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
248 return -1; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
249 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
250 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
251 target += bytesToWrite; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
252 if (target > targetEnd) { |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
253 _raise_utf8_encode_error( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
254 ch_obj, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
255 1, ch_obj_end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
256 "temporary target buffer exhausted"); |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
257 return -1; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
258 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
259 switch (bytesToWrite) { /* note: everything falls through. */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
260 case 4: *--target = (unsigned char)((ch | byteMark) & byteMask); ch >>= 6; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
261 case 3: *--target = (unsigned char)((ch | byteMark) & byteMask); ch >>= 6; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
262 case 2: *--target = (unsigned char)((ch | byteMark) & byteMask); ch >>= 6; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
263 case 1: *--target = (unsigned char) (ch | firstByteMark[bytesToWrite]); |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
264 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
265 return bytesToWrite; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
266 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
267 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
268 |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
269 /* |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
270 * End of Copyright 2001-2004 Unicode, Inc. |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
271 */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
272 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
273 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
274 static |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
275 PyObject * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
276 _hex2string(PyObject *s, Py_ssize_t end) |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
277 { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
278 Py_UCS4 c; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
279 unsigned char buf[6]; |
|
555
b7434a34a1f4
- FIX: Memory-leak with the "filters" local variable
Franz Glasner <fzglas.hg@dom66.de>
parents:
554
diff
changeset
|
280 Py_ssize_t bytes_written; |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
281 PyObject *u; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
282 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
283 if (_hex2ucs4(s, end, &c) != 0) |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
284 return NULL; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
285 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
286 /* Replace the combination PyUniode_New/PyUnicode_WriteChar */ |
|
564
44e18fbf7741
Refactor: signature of _convert_ucs4_to_utf8(): change order of args
Franz Glasner <fzglas.hg@dom66.de>
parents:
562
diff
changeset
|
287 bytes_written = _convert_ucs4_to_utf8(c, buf, &(buf[6]), 1, s, end+1); |
|
555
b7434a34a1f4
- FIX: Memory-leak with the "filters" local variable
Franz Glasner <fzglas.hg@dom66.de>
parents:
554
diff
changeset
|
288 if (bytes_written < 0) { |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
289 return NULL; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
290 } |
|
555
b7434a34a1f4
- FIX: Memory-leak with the "filters" local variable
Franz Glasner <fzglas.hg@dom66.de>
parents:
554
diff
changeset
|
291 u = PyUnicode_FromStringAndSize((const char *)buf, bytes_written); |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
292 if (u == NULL) { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
293 return NULL; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
294 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
295 return u; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
296 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
297 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
298 #else |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
299 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
300 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
301 PyObject * |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
302 _hex2string(PyObject *s, Py_ssize_t end) |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
303 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
304 Py_UCS4 c; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
305 PyObject *u = NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
306 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
307 if (_hex2ucs4(s, end, &c) != 0) |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
308 return NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
309 u = PyUnicode_New(1, c); /* ARGH: not in the stable API */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
310 if (u == NULL) |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
311 return NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
312 if (PyUnicode_WriteChar(u, 0, c) != 0) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
313 Py_DECREF(u); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
314 return NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
315 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
316 return u; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
317 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
318 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
319 #endif /* Py_LIMITED_API */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
320 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
321 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
322 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
323 PyObject * |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
324 _fast_unquote(PyObject *s, Py_ssize_t s_len, PyObject *self, struct speedups_state *sstate) |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
325 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
326 Py_ssize_t find; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
327 Py_ssize_t parts_len; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
328 PyObject *res; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
329 PyObject *res_parts = NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
330 PyObject *parts = NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
331 PyObject *o; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
332 PyObject *pb; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
333 Py_ssize_t pb_len; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
334 Py_ssize_t i; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
335 Py_UCS4 c; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
336 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
337 if (s_len < 0) { |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
338 s_len = PyUnicode_GetLength(s); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
339 if (s_len < 0) { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
340 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
341 } |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
342 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
343 if (s_len == 0) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
344 return Py_NewRef(s); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
345 } |
|
656
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
346 if (s_len > 2) { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
347 /* Check for ~NNN~ syntax */ |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
348 c = PyUnicode_ReadChar(s, 0); |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
349 if (c == 0x7e) { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
350 c = PyUnicode_ReadChar(s, s_len - 1); |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
351 if (c == 0x7e) { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
352 if (_dec2num(s, 1, s_len - 2, &i) == 0) { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
353 return PyLong_FromSsize_t(i); |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
354 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
355 PyErr_Clear(); |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
356 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
357 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
358 } |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
359 find = PyUnicode_FindChar(s, '%', 0, s_len, 1); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
360 if (find == -2) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
361 return NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
362 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
363 if (find == -1) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
364 return Py_NewRef(s); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
365 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
366 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
367 if (sstate == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
368 sstate = PyModule_GetState(self); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
369 if (sstate == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
370 PyErr_SetString(PyExc_RuntimeError, "no module state available"); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
371 return NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
372 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
373 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
374 parts = PyUnicode_Split(s, sstate->QUOTE, -1); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
375 if (parts == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
376 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
377 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
378 parts_len = PyList_Size(parts); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
379 if (parts_len < 0) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
380 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
381 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
382 res_parts = PyTuple_New((parts_len-1)*2 + 1); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
383 if (res_parts == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
384 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
385 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
386 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
387 o = PyList_GetItem(parts, 0); /* borrowed */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
388 if (o == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
389 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
390 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
391 /* |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
392 * The first item may be also the empty string if `s' starts with |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
393 * a quoted character. |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
394 */ |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
395 PyTuple_SetItem(res_parts, 0, Py_NewRef(o)); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
396 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
397 for (i=1; i<parts_len; i++) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
398 pb = PyList_GetItem(parts, i); /* borrowed */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
399 pb_len = PyUnicode_GetLength(pb); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
400 if (pb_len < 1) { |
|
630
33264c660fca
Exception formatting: more into into some exception error messages
Franz Glasner <fzglas.hg@dom66.de>
parents:
627
diff
changeset
|
401 PyErr_Format(PyExc_ValueError, "quote syntax: length too small: %U", pb); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
402 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
403 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
404 c = PyUnicode_ReadChar(pb, 0); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
405 switch (c) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
406 case 0x55: /* U */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
407 if (pb_len < 9) { |
|
630
33264c660fca
Exception formatting: more into into some exception error messages
Franz Glasner <fzglas.hg@dom66.de>
parents:
627
diff
changeset
|
408 PyErr_Format(PyExc_ValueError, "quote syntax: length too small: %U", pb); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
409 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
410 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
411 o = _hex2string(pb, 9); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
412 if (o == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
413 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
414 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
415 PyTuple_SetItem(res_parts, (i-1)*2 + 1, o); /* steals */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
416 o = PyUnicode_Substring(pb, 9, pb_len); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
417 if (o == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
418 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
419 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
420 PyTuple_SetItem(res_parts, i*2, o); /* steals */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
421 break; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
422 case 0x75: /* u */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
423 if (pb_len < 5) { |
|
630
33264c660fca
Exception formatting: more into into some exception error messages
Franz Glasner <fzglas.hg@dom66.de>
parents:
627
diff
changeset
|
424 PyErr_Format(PyExc_ValueError, "quote syntax: length too small: %U", pb); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
425 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
426 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
427 o = _hex2string(pb, 5); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
428 if (o == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
429 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
430 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
431 PyTuple_SetItem(res_parts, (i-1)*2 + 1, o); /* steals */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
432 o = PyUnicode_Substring(pb, 5, pb_len); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
433 if (o == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
434 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
435 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
436 PyTuple_SetItem(res_parts, i*2, o); /* steals */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
437 break; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
438 case 0x78: /* x */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
439 if (pb_len < 3) { |
|
630
33264c660fca
Exception formatting: more into into some exception error messages
Franz Glasner <fzglas.hg@dom66.de>
parents:
627
diff
changeset
|
440 PyErr_Format(PyExc_ValueError, "quote syntax: length too small: %U", pb); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
441 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
442 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
443 o = _hex2string(pb, 3); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
444 if (o == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
445 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
446 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
447 PyTuple_SetItem(res_parts, (i-1)*2 + 1, o); /* steals */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
448 o = PyUnicode_Substring(pb, 3, pb_len); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
449 if (o == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
450 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
451 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
452 PyTuple_SetItem(res_parts, i*2, o); /* steals */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
453 break; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
454 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
455 default: |
|
630
33264c660fca
Exception formatting: more into into some exception error messages
Franz Glasner <fzglas.hg@dom66.de>
parents:
627
diff
changeset
|
456 PyErr_Format(PyExc_ValueError, "quote syntax: length too small: %U", pb); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
457 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
458 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
459 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
460 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
461 res = PyUnicode_Join(sstate->EMPTY_STR, res_parts); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
462 if (res == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
463 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
464 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
465 Py_DECREF(parts); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
466 Py_DECREF(res_parts); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
467 return res; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
468 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
469 error: |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
470 Py_XDECREF(res_parts); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
471 Py_XDECREF(parts); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
472 return NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
473 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
474 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
475 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
476 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
477 PyObject * |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
478 fast_unquote(PyObject *self, PyObject *s) |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
479 { |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
480 return _fast_unquote(s, -1, self, NULL); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
481 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
482 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
483 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
484 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
485 PyObject * |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
486 fast_quote(PyObject *self, PyObject *s) |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
487 { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
488 Py_ssize_t s_len; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
489 Py_ssize_t i; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
490 Py_UCS4 c; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
491 int need_quoting; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
492 struct speedups_state *sstate; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
493 |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
494 s_len = PyUnicode_GetLength(s); |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
495 if (s_len < 0) { |
|
656
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
496 if (PyObject_IsInstance(s, (PyObject *)&PyLong_Type)) { |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
497 PyErr_Clear(); |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
498 return PyUnicode_FromFormat("~%S~", s); |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
499 } |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
500 PyErr_SetString(PyExc_TypeError, "given object has no len()"); |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
501 return NULL; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
502 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
503 if (s_len == 0) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
504 return Py_NewRef(s); |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
505 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
506 need_quoting = 0; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
507 for (i=0; i<s_len; i++) { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
508 c = PyUnicode_ReadChar(s, i); /* type already checked */ |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
509 switch (c) { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
510 case 0x25: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
511 case 0x2e: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
512 case 0x3a: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
513 case 0x23: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
514 case 0x7c: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
515 case 0x22: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
516 case 0x27: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
517 case 0x7b: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
518 case 0x7d: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
519 case 0x5b: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
520 case 0x5d: |
|
656
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
521 case 0x7e: |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
522 need_quoting = 1; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
523 i = s_len; /* break the for-loop */ |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
524 break; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
525 default: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
526 /* VOID */ |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
527 ; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
528 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
529 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
530 if (!need_quoting) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
531 return Py_NewRef(s); |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
532 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
533 sstate = PyModule_GetState(self); |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
534 if (sstate == NULL) { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
535 PyErr_SetString(PyExc_RuntimeError, "no module state available"); |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
536 return NULL; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
537 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
538 return PyUnicode_Translate(s, sstate->QUOTE_MAP, "strict"); |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
539 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
540 |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
541 |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
542 static |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
543 PyObject * |
|
602
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
544 _fast_pathstr2path(PyObject *varname, PyObject *self, struct speedups_state *sstate) |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
545 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
546 Py_ssize_t varname_len; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
547 PyObject *parts = NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
548 Py_ssize_t parts_len; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
549 PyObject *res = NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
550 Py_ssize_t i; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
551 PyObject *o; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
552 PyObject *u; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
553 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
554 varname_len = PyUnicode_GetLength(varname); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
555 if (varname_len < 0) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
556 return NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
557 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
558 if (varname_len == 0) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
559 return PyTuple_New(0); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
560 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
561 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
562 if (sstate == NULL) { |
|
602
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
563 sstate = PyModule_GetState(self); |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
564 if (sstate == NULL) { |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
565 PyErr_SetString(PyExc_RuntimeError, "no module state available"); |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
566 return NULL; |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
567 } |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
568 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
569 parts = PyUnicode_Split(varname, sstate->DOT, -1); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
570 if (parts == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
571 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
572 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
573 parts_len = PyList_Size(parts); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
574 if (parts_len < 0) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
575 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
576 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
577 res = PyTuple_New(parts_len); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
578 if (res == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
579 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
580 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
581 for (i=0; i < parts_len; i++) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
582 o = PyList_GetItem(parts, i); /* borrowed */ |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
583 u = _fast_unquote(o, -1, NULL, sstate); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
584 if (u == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
585 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
586 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
587 PyTuple_SetItem(res, i, u); /* steals */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
588 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
589 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
590 Py_DECREF(parts); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
591 return res; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
592 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
593 error: |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
594 Py_XDECREF(parts); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
595 Py_XDECREF(res); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
596 return NULL; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
597 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
598 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
599 |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
600 static |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
601 PyObject * |
|
602
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
602 fast_pathstr2path(PyObject *self, PyObject *varname) |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
603 { |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
604 return _fast_pathstr2path(varname, self, NULL); |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
605 } |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
606 |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
607 |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
608 static |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
609 PyObject * |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
610 _fast_split_filters(PyObject *varname, PyObject *self, Py_ssize_t direction, struct speedups_state *sstate) |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
611 { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
612 Py_ssize_t varname_len; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
613 Py_ssize_t sep; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
614 PyObject *res = NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
615 PyObject *filters = NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
616 PyObject *name = NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
617 PyObject *tmp; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
618 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
619 varname_len = PyUnicode_GetLength(varname); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
620 if (varname_len < 0) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
621 return NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
622 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
623 if (varname_len == 0) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
624 sep = -1; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
625 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
626 else { |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
627 sep = PyUnicode_FindChar(varname, '|', 0, varname_len, (int)direction); |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
628 if (sep == -2) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
629 return NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
630 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
631 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
632 if (sep == -1) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
633 res = PyTuple_New(2); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
634 if (res == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
635 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
636 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
637 PyTuple_SetItem(res, 0, Py_NewRef(varname)); /* steals */ |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
638 filters = PyList_New(0); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
639 if (filters == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
640 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
641 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
642 PyTuple_SetItem(res, 1, filters); /* steals */ |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
643 return res; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
644 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
645 name = PyUnicode_Substring(varname, 0, sep); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
646 if (name == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
647 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
648 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
649 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
650 filters = PyUnicode_Substring(varname, sep+1, varname_len); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
651 if (filters == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
652 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
653 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
654 tmp = PyObject_CallMethod(filters, "strip", NULL); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
655 if (tmp == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
656 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
657 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
658 py_transfer_owned(&filters, &tmp); |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
659 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
660 if (PyObject_Not(filters)) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
661 py_clear_ref(&filters); |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
662 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
663 res = PyTuple_New(2); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
664 if (res == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
665 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
666 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
667 PyTuple_SetItem(res, 0, name); /* steals */ |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
668 name = NULL; /* no ownership any more */ |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
669 filters = PyList_New(0); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
670 if (filters == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
671 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
672 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
673 PyTuple_SetItem(res, 1, filters); /* steals */ |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
674 filters = NULL; |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
675 return res; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
676 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
677 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
678 if (sstate == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
679 sstate = PyModule_GetState(self); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
680 if (sstate == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
681 PyErr_SetString(PyExc_RuntimeError, "no module state available"); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
682 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
683 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
684 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
685 |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
686 if (direction == 1) { |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
687 tmp = PyUnicode_Split(filters, sstate->FILTER_SEPARATOR, -1); |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
688 } |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
689 else { |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
690 tmp = PyUnicode_Split(filters, sstate->FILTER_SEPARATOR_REV, -1); |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
691 } |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
692 if (tmp == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
693 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
694 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
695 py_transfer_owned(&filters, &tmp); |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
696 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
697 res = PyTuple_New(2); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
698 if (res == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
699 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
700 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
701 PyTuple_SetItem(res, 0, name); /* steals -- ownership changed */ |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
702 PyTuple_SetItem(res, 1, filters); /* steals -- ownership changed */ |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
703 return res; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
704 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
705 error: |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
706 Py_XDECREF(res); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
707 Py_XDECREF(filters); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
708 Py_XDECREF(name); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
709 return NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
710 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
711 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
712 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
713 static |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
714 PyObject * |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
715 fast_split_filters(PyObject *self, PyObject *args) |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
716 { |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
717 PyObject *varname; |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
718 PyObject *direction_obj; |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
719 Py_ssize_t direction; |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
720 |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
721 if (!PyArg_UnpackTuple(args, "fast_split_filters", 2, 2, &varname, &direction_obj)) { |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
722 return NULL; |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
723 } |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
724 direction = PyNumber_AsSsize_t(direction_obj, PyExc_OverflowError); |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
725 if (direction == -1) { |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
726 if (PyErr_Occurred()) { |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
727 return NULL; |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
728 } |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
729 } |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
730 if ((direction == 1) || (direction == -1)) { |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
731 return _fast_split_filters(varname, self, direction, NULL); |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
732 } |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
733 else { |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
734 PyErr_SetString(PyExc_ValueError, "`direction' must be -1 or +1"); |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
735 return NULL; |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
736 } |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
737 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
738 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
739 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
740 static |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
741 PyObject * |
|
611
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
742 _fast_split_ns(PyObject *varname, PyObject *self, struct speedups_state *sstate) |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
743 { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
744 PyObject *res = NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
745 Py_ssize_t ns_idx; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
746 Py_ssize_t varname_len; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
747 PyObject *o1; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
748 PyObject *o2; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
749 |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
750 varname_len = PyUnicode_GetLength(varname); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
751 if (varname_len < 0) { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
752 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
753 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
754 ns_idx = PyUnicode_FindChar(varname, ':', 0, varname_len, 1); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
755 if (ns_idx == -2) { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
756 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
757 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
758 if (ns_idx == -1) { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
759 res = PyTuple_New(2); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
760 if (res == NULL) { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
761 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
762 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
763 PyTuple_SetItem(res, 0, Py_NewRef(Py_None)); /* steals */ |
|
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
764 PyTuple_SetItem(res, 1, Py_NewRef(varname)); /* steals */ |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
765 return res; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
766 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
767 |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
768 res = PyTuple_New(2); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
769 if (res == NULL) { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
770 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
771 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
772 o1 = PyUnicode_Substring(varname, 0, ns_idx); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
773 if (o1 == NULL) { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
774 Py_DECREF(res); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
775 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
776 } |
|
611
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
777 o2 = _fast_unquote(o1, ns_idx, self, sstate); |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
778 if (o2 == NULL) { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
779 Py_DECREF(o1); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
780 Py_DECREF(res); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
781 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
782 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
783 Py_DECREF(o1); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
784 PyTuple_SetItem(res, 0, o2); /* steals */ |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
785 o1 = PyUnicode_Substring(varname, ns_idx+1, varname_len); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
786 if (o1 == NULL) { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
787 Py_DECREF(res); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
788 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
789 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
790 PyTuple_SetItem(res, 1, o1); /* steals */ |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
791 return res; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
792 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
793 |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
794 |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
795 static |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
796 PyObject * |
|
611
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
797 fast_split_ns(PyObject *self, PyObject *varname) |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
798 { |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
799 return _fast_split_ns(varname, self, NULL); |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
800 } |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
801 |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
802 |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
803 static |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
804 PyObject * |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
805 fast_interpolate_variables_old(PyObject *self, PyObject *args) |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
806 { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
807 PyObject *config; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
808 PyObject *s; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
809 PyObject *cache; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
810 |
|
637
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
811 int cmp; |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
812 Py_ssize_t s_len; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
813 Py_ssize_t idx; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
814 Py_ssize_t i, j; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
815 PyObject *parts = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
816 Py_ssize_t parts_len; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
817 PyObject *res_parts = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
818 PyObject *res = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
819 PyObject *tmp; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
820 PyObject *pb; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
821 Py_ssize_t pb_len; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
822 PyObject *varname = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
823 PyObject *varvalue = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
824 PyObject *filters = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
825 int cacheable; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
826 int use_cache = 1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
827 int first_part_is_empty; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
828 PyObject *err_type; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
829 PyObject *err_value; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
830 PyObject *err_tb; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
831 struct speedups_state *sstate; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
832 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
833 if (!PyArg_UnpackTuple(args, "s", 3, 3, &config, &s, &cache)) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
834 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
835 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
836 s_len = PyUnicode_GetLength(s); /* also an implicit type check */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
837 if (s_len < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
838 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
839 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
840 if (s_len < 4) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
841 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
842 return Py_NewRef(s); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
843 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
844 sstate = PyModule_GetState(self); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
845 if (sstate == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
846 PyErr_SetString(PyExc_RuntimeError, "no module state available"); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
847 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
848 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
849 |
|
637
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
850 cmp = PyUnicode_Compare(s, sstate->DEL_VALUE); |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
851 if ((cmp < 0) && PyErr_Occurred()) { |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
852 return NULL; |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
853 } |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
854 if (cmp == 0) { |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
855 return Py_NewRef(s); |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
856 } |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
857 |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
858 idx = PyUnicode_Find(s, sstate->STARTTOK, 0, s_len, 1); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
859 if (idx < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
860 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
861 return Py_NewRef(s); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
862 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
863 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
864 res = PyDict_GetItem(cache, s); /* borrowed */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
865 if (res != NULL) { |
|
618
8dc514bd3d5e
Use py_object_is when comparing to MISSING
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
614
diff
changeset
|
866 if (py_object_is(res, sstate->MISSING)) { |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
867 return PyErr_Format( |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
868 PyExc_KeyError, |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
869 "Cannot interpolate variables in string %R (cached)", |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
870 s); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
871 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
872 else { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
873 return Py_NewRef(res); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
874 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
875 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
876 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
877 parts = PyUnicode_Split(s, sstate->STARTTOK, -1); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
878 if (parts == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
879 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
880 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
881 parts_len = PyList_Size(parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
882 if (parts_len < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
883 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
884 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
885 res_parts = PyList_New(1); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
886 if (res_parts == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
887 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
888 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
889 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
890 tmp = PyList_GetItem(parts, 0); /* borrowed */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
891 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
892 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
893 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
894 /* |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
895 * The first item may be also the empty string if `s' starts with |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
896 * an interpolation token. |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
897 */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
898 first_part_is_empty = PyObject_Not(tmp); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
899 /* steals -- cannot fail here -- NOTE: tmp is currently borrowed */ |
|
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
900 PyList_SetItem(res_parts, 0, Py_NewRef(tmp)); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
901 tmp = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
902 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
903 for (i=1; i<parts_len; i++) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
904 pb = PyList_GetItem(parts, i); /* borrowed */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
905 pb_len = PyUnicode_GetLength(pb); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
906 if (pb_len < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
907 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
908 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
909 idx = PyUnicode_Find(pb, sstate->ENDTOK, 0, pb_len, 1); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
910 if (idx < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
911 /* |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
912 * Behave similar to the pure-Python version: copy the complete |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
913 * rest as-is. Also include the start tokens! |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
914 */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
915 if (PyList_Append(res_parts, sstate->STARTTOK) < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
916 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
917 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
918 if (PyList_Append(res_parts, pb) < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
919 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
920 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
921 for (j=i+1; j<parts_len; j++) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
922 if (PyList_Append(res_parts, sstate->STARTTOK) < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
923 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
924 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
925 pb = PyList_GetItem(parts, j); /* borrowed */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
926 if (PyList_Append(res_parts, pb) < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
927 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
928 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
929 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
930 break; /* the for-loop */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
931 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
932 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
933 varname = PyUnicode_Substring(pb, 0, idx); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
934 if (varname == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
935 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
936 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
937 |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
938 tmp = _fast_split_filters(varname, NULL, 1, sstate); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
939 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
940 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
941 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
942 if (PyTuple_Size(tmp) != 2) { |
|
703
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
943 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
944 PyErr_SetString(PyExc_TypeError, "tuple of size 2 expected"); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
945 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
946 } |
| 562 | 947 py_clear_ref(&varname); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
948 /* Unpack the result tuple */ |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
949 /* borrowed -- cannot fail -- need ownership */ |
|
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
950 varname = Py_NewRef(PyTuple_GetItem(tmp, 0)); |
|
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
951 /* borrowed -- cannot fail -- want ownership */ |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
952 filters = Py_NewRef(PyTuple_GetItem(tmp, 1)); |
|
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
953 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
954 |
|
611
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
955 varvalue = _fast_getvar_s(config, varname, NULL, sstate, &cacheable); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
956 if (varvalue == NULL) { |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
957 if (PyErr_ExceptionMatches(PyExc_KeyError)) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
958 cacheable = 1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
959 if (PySequence_Contains(filters, sstate->NONE_FILTER) == 1) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
960 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
961 varvalue = Py_NewRef(Py_None); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
962 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
963 else { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
964 if (PySequence_Contains(filters, sstate->EMPTY_FILTER) == 1) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
965 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
966 varvalue = Py_NewRef(sstate->EMPTY_STR); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
967 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
968 else { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
969 PyErr_Fetch(&err_type, &err_value, &err_tb); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
970 /* this does NOT steal */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
971 PyDict_SetItem(cache, s, sstate->MISSING); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
972 PyErr_Restore(err_type, err_value, err_tb); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
973 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
974 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
975 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
976 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
977 else { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
978 /* other exception/error than KeyError */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
979 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
980 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
981 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
982 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
983 if (!cacheable) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
984 use_cache = 0; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
985 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
986 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
987 py_clear_ref(&varname); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
988 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
989 tmp = PyObject_CallMethod( |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
990 config, "_apply_filters", "OO", filters, varvalue); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
991 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
992 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
993 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
994 py_clear_ref(&varvalue); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
995 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
996 py_clear_ref(&filters); |
|
555
b7434a34a1f4
- FIX: Memory-leak with the "filters" local variable
Franz Glasner <fzglas.hg@dom66.de>
parents:
554
diff
changeset
|
997 |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
998 /* |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
999 * Dont apply and type conversions to the variable value if |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1000 * the whole `s` is just one expansion |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1001 */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1002 if (first_part_is_empty && (i == 1) && (pb_len == s_len - 2) && (idx == pb_len - 2)) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1003 res = varvalue; varvalue = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1004 goto success; /* break out early */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1005 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1006 if (py_object_isnot(varvalue, Py_None)) { |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1007 tmp = PyObject_Str(varvalue); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1008 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1009 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1010 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1011 if (PyList_Append(res_parts, tmp) < 0) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1012 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1013 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1014 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1015 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1016 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1017 py_clear_ref(&varvalue); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1018 /* append the rest of the string */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1019 tmp = PyUnicode_Substring(pb, idx+2, pb_len); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1020 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1021 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1022 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1023 if (PyList_Append(res_parts, tmp) < 0) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1024 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1025 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1026 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1027 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1028 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1029 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1030 res = PyUnicode_Join(sstate->EMPTY_STR, res_parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1031 if (res == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1032 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1033 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1034 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1035 success: |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1036 Py_DECREF(parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1037 Py_DECREF(res_parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1038 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1039 if (use_cache) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1040 PyDict_SetItem(cache, s, res); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1041 PyErr_Clear(); /* clear any possible cache-related error */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1042 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1043 return res; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1044 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1045 error: |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1046 Py_XDECREF(varname); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1047 Py_XDECREF(varvalue); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1048 Py_XDECREF(filters); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1049 Py_XDECREF(parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1050 Py_XDECREF(res_parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1051 Py_XDECREF(res); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1052 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1053 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1054 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1055 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1056 static |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1057 PyObject * |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1058 fast_interpolate_variables(PyObject *self, PyObject *args) |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1059 { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1060 PyObject *config; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1061 PyObject *s; |
|
566
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1062 PyObject *cache = NULL; |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1063 |
|
704
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1064 if (!PyArg_UnpackTuple(args, "s", 2, 3, &config, &s, &cache)) { |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1065 return NULL; |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1066 } |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1067 return _fast_interpolate_variables(self, config, s, cache); |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1068 } |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1069 |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1070 |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1071 static |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1072 PyObject * |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1073 _fast_interpolate_variables(PyObject *self, PyObject *config, PyObject *s, PyObject *cache) |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1074 { |
|
637
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1075 int cmp; |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1076 Py_ssize_t s_len; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1077 Py_ssize_t start, rest, end; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1078 PyObject *tmp; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1079 PyObject *result = NULL; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1080 PyObject *varname = NULL; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1081 PyObject *varvalue = NULL; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1082 PyObject *filters = NULL; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1083 PyObject *err_type; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1084 PyObject *err_value; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1085 PyObject *err_tb; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1086 int use_cache, cacheable; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1087 struct speedups_state *sstate; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1088 |
|
566
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1089 /* Disable caching if the cache param is given as None */ |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1090 if ((cache != NULL) && py_object_is(cache, Py_None)) { |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1091 cache = NULL; |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1092 } |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1093 s_len = PyUnicode_GetLength(s); /* also an implicit type check */ |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1094 if (s_len < 0) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1095 return NULL; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1096 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1097 if (s_len < 4) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1098 return Py_NewRef(s); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1099 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1100 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1101 sstate = PyModule_GetState(self); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1102 if (sstate == NULL) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1103 PyErr_SetString(PyExc_RuntimeError, "no module state available"); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1104 return NULL; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1105 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1106 |
|
637
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1107 cmp = PyUnicode_Compare(s, sstate->DEL_VALUE); |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1108 if ((cmp < 0) && PyErr_Occurred()) { |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1109 return NULL; |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1110 } |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1111 if (cmp == 0) { |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1112 return Py_NewRef(s); |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1113 } |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1114 |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1115 start = PyUnicode_Find(s, sstate->STARTTOK, 0, s_len, 1); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1116 if (start == -2) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1117 return NULL; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1118 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1119 if (start == -1) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1120 return Py_NewRef(s); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1121 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1122 |
|
566
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1123 if (cache != NULL) { |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1124 result = PyDict_GetItem(cache, s); /* borrowed */ |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1125 if (result != NULL) { |
|
618
8dc514bd3d5e
Use py_object_is when comparing to MISSING
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
614
diff
changeset
|
1126 if (py_object_is(result, sstate->MISSING)) { |
|
566
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1127 return PyErr_Format( |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1128 PyExc_KeyError, |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1129 "Cannot interpolate variables in string %R (cached)", |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1130 s); |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1131 } |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1132 else { |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1133 return Py_NewRef(result); |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1134 } |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1135 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1136 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1137 |
|
704
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1138 /* Check for {{| ... |}} */ |
|
703
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1139 if ((s_len >= 6) |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1140 && (start == 0) |
|
704
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1141 && (PyUnicode_ReadChar(s, 2) == 0x7c /* `|' */)) { |
|
703
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1142 end = PyUnicode_Find(s, sstate->ENDTOK_FILTER, start+3, s_len, 1); |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1143 if (end == -2) { |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1144 return NULL; |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1145 } |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1146 if (end != (s_len - 3)) { |
|
704
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1147 PyErr_SetString(PyExc_ValueError, "`{{|' global filter interpolation must end with `|}}'"); |
|
703
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1148 return NULL; |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1149 } |
|
704
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1150 /* |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1151 * Handle {{| ... |filters, ... |}} : |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1152 * split and recurse and apply filters |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1153 */ |
|
703
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1154 tmp = PyUnicode_Substring(s, 3, s_len-3); |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1155 if (tmp == NULL) { |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1156 return NULL; |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1157 } |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
1158 filters = _fast_split_filters(tmp, NULL, -1, sstate); |
|
703
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1159 if (filters == NULL) { |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1160 py_clear_ref(&tmp); |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1161 return NULL; |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1162 } |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1163 if (PyTuple_Size(filters) != 2) { |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1164 py_clear_ref(&tmp); |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1165 PyErr_SetString(PyExc_TypeError, "tuple of size 2 expected"); |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1166 goto error; |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1167 } |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1168 py_transfer_owned(&tmp, &filters); |
|
704
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1169 /* Unpack the result tuple */ |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1170 /* borrowed -- cannot fail -- need ownership */ |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1171 varname = Py_NewRef(PyTuple_GetItem(tmp, 0)); |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1172 /* borrowed -- cannot fail -- need ownership */ |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1173 filters = Py_NewRef(PyTuple_GetItem(tmp, 1)); |
|
703
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1174 py_clear_ref(&tmp); |
|
704
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1175 |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1176 varvalue = _fast_interpolate_variables(self, config, varname, cache); |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1177 if (varvalue == NULL) { |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1178 if (PyErr_ExceptionMatches(PyExc_KeyError)) { |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1179 if (PySequence_Contains(filters, sstate->NONE_FILTER) == 1) { |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1180 PyErr_Clear(); |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1181 varvalue = Py_NewRef(Py_None); |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1182 } |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1183 else { |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1184 if (PySequence_Contains(filters, sstate->EMPTY_FILTER) == 1) { |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1185 PyErr_Clear(); |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1186 varvalue = Py_NewRef(sstate->EMPTY_STR); |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1187 } |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1188 else { |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1189 goto error; |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1190 } |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1191 } |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1192 } |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1193 else { |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1194 /* other exception/error than KeyError */ |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1195 goto error; |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1196 } |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1197 } |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1198 py_clear_ref(&varname); |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1199 result = PyObject_CallMethod( |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1200 config, "_apply_filters", "OO", filters, varvalue); |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1201 if (result == NULL) { |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1202 goto error; |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1203 } |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1204 py_clear_ref(&varvalue); |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1205 py_clear_ref(&filters); |
|
457ef358c1a0
filter-only expansions also implemented in the C extension.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
703
diff
changeset
|
1206 return result; |
|
703
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1207 } |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1208 |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1209 result = PyList_New(0); |
| 627 | 1210 if (result == NULL) { |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1211 return NULL; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1212 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1213 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1214 rest = 0; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1215 use_cache = 1; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1216 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1217 while (start != -1) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1218 if (rest < start) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1219 tmp = PyUnicode_Substring(s, rest, start); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1220 if (tmp == NULL) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1221 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1222 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1223 if (PyList_Append(result, tmp) < 0) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1224 py_clear_ref(&tmp); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1225 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1226 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1227 py_clear_ref(&tmp); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1228 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1229 end = PyUnicode_Find(s, sstate->ENDTOK, start+2, s_len, 1); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1230 if (end == -2) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1231 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1232 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1233 if (end == -1) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1234 rest = start; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1235 break; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1236 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1237 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1238 varname = PyUnicode_Substring(s, start+2, end); /* 2 == len(STARTTOK) */ |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1239 if (varname == NULL) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1240 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1241 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1242 |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
1243 tmp = _fast_split_filters(varname, NULL, 1, sstate); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1244 if (tmp == NULL) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1245 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1246 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1247 if (PyTuple_Size(tmp) != 2) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1248 PyErr_SetString(PyExc_TypeError, "tuple of size 2 expected"); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1249 py_clear_ref(&tmp); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1250 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1251 } |
| 562 | 1252 py_clear_ref(&varname); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1253 /* Unpack the result tuple */ |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1254 /* borrowed -- cannot fail -- need ownership */ |
|
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1255 varname = Py_NewRef(PyTuple_GetItem(tmp, 0)); |
|
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1256 /* borrowed -- cannot fail -- need ownership */ |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1257 filters = Py_NewRef(PyTuple_GetItem(tmp, 1)); |
|
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1258 py_clear_ref(&tmp); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1259 |
|
611
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
1260 varvalue = _fast_getvar_s(config, varname, NULL, sstate, &cacheable); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1261 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1262 if (varvalue == NULL) { |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1263 if (PyErr_ExceptionMatches(PyExc_KeyError)) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1264 cacheable = 1; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1265 if (PySequence_Contains(filters, sstate->NONE_FILTER) == 1) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1266 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1267 varvalue = Py_NewRef(Py_None); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1268 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1269 else { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1270 if (PySequence_Contains(filters, sstate->EMPTY_FILTER) == 1) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1271 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1272 varvalue = Py_NewRef(sstate->EMPTY_STR); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1273 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1274 else { |
|
566
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1275 if (cache != NULL) { |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1276 PyErr_Fetch(&err_type, &err_value, &err_tb); |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1277 /* this does NOT steal */ |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1278 PyDict_SetItem(cache, s, sstate->MISSING); |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1279 PyErr_Restore(err_type, err_value, err_tb); |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1280 } |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1281 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1282 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1283 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1284 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1285 else { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1286 /* other exception/error than KeyError */ |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1287 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1288 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1289 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1290 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1291 if (!cacheable) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1292 use_cache = 0; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1293 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1294 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1295 py_clear_ref(&varname); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1296 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1297 tmp = PyObject_CallMethod( |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1298 config, "_apply_filters", "OO", filters, varvalue); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1299 if (tmp == NULL) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1300 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1301 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1302 py_transfer_owned(&varvalue, &tmp); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1303 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1304 py_clear_ref(&filters); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1305 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1306 rest = end + 2; /* 2 == len(ENDTOK) */ |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1307 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1308 /* |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1309 * Dont apply and type conversions to the variable value if |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1310 * the whole `s` is just one expansion |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1311 */ |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1312 if ((start == 0) && (rest == s_len)) { |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1313 py_transfer_owned(&result, &varvalue); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1314 goto success; /* break out early */ |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1315 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1316 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1317 /* Handle None like the empty string */ |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1318 if (py_object_isnot(varvalue, Py_None)) { |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1319 tmp = PyObject_Str(varvalue); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1320 if (tmp == NULL) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1321 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1322 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1323 if (PyList_Append(result, tmp) < 0) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1324 py_clear_ref(&tmp); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1325 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1326 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1327 py_clear_ref(&tmp); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1328 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1329 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1330 /* don't re-evaluate because `self.getvar_s()` expands already */ |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1331 start = PyUnicode_Find(s, sstate->STARTTOK, rest, s_len, 1); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1332 if (start == -2) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1333 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1334 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1335 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1336 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1337 if (rest < s_len) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1338 tmp = PyUnicode_Substring(s, rest, s_len); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1339 if (tmp == NULL) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1340 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1341 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1342 if (PyList_Append(result, tmp) < 0) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1343 py_clear_ref(&tmp); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1344 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1345 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1346 py_clear_ref(&tmp); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1347 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1348 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1349 tmp = PyUnicode_Join(sstate->EMPTY_STR, result); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1350 if (tmp == NULL) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1351 goto error; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1352 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1353 py_transfer_owned(&result, &tmp); |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1354 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1355 success: |
|
566
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1356 if (use_cache && (cache != NULL)) { |
|
558
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1357 if (PyDict_SetItem(cache, s, result) < 0) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1358 PyErr_Clear(); /* clear any cache-related error */ |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1359 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1360 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1361 return result; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1362 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1363 error: |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1364 Py_XDECREF(varname); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1365 Py_XDECREF(varvalue); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1366 Py_XDECREF(filters); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1367 Py_XDECREF(result); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1368 return NULL; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1369 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1370 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1371 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1372 static |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1373 PyObject * |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1374 _fast_getvarl(PyObject *config, PyObject *path, PyObject *namespace, PyObject *default_, struct speedups_state *sstate) |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1375 { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1376 PyObject *varvalue; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1377 PyObject *lookupfn = NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1378 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1379 if ((namespace == NULL) || PyObject_Not(namespace)) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1380 lookupfn = PyObject_GetAttrString(config, "_lookupvar"); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1381 if (lookupfn == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1382 goto error; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1383 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1384 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1385 else { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1386 int ns_equals_ref = PyUnicode_Compare(namespace, sstate->REF_NAMESPACE); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1387 if ((ns_equals_ref < 0) && PyErr_Occurred()) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1388 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1389 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1390 if (ns_equals_ref == 0) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1391 lookupfn = PyObject_GetAttrString(config, "_lookupref"); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1392 if (lookupfn == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1393 goto error; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1394 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1395 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1396 else { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1397 /* lookup_varns */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1398 /* this is borrowed */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1399 PyObject *cfg_vars_mod = PyImport_AddModule("configmix.variables"); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1400 if (cfg_vars_mod == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1401 goto error; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1402 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1403 lookupfn = PyObject_CallMethod(cfg_vars_mod, "lookup_varns", "O", namespace); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1404 if (lookupfn == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1405 goto handle_possible_keyerror; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1406 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1407 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1408 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1409 varvalue = PyObject_CallObject(lookupfn, path); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1410 if (varvalue == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1411 goto handle_possible_keyerror; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1412 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1413 Py_DECREF(lookupfn); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1414 return varvalue; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1415 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1416 handle_possible_keyerror: |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1417 if (PyErr_ExceptionMatches(PyExc_KeyError)) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1418 if ((default_ == NULL) || py_object_is(default_, sstate->MARKER)) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1419 PyErr_Format(PyExc_KeyError, "Variable %R not found", path); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1420 /* fall through */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1421 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1422 else { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1423 PyErr_Clear(); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1424 Py_XDECREF(lookupfn); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1425 return Py_NewRef(default_); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1426 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1427 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1428 /* fall through */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1429 error: |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1430 Py_XDECREF(lookupfn); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1431 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1432 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1433 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1434 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1435 static |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1436 PyObject * |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1437 fast_getvarl(PyObject *self, PyObject *args, PyObject *kwds) |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1438 { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1439 static char *kwlist[] = {"config", "path", "namespace", "default", NULL}; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1440 PyObject *path; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1441 PyObject *config; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1442 PyObject *namespace = NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1443 PyObject *default_ = NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1444 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1445 struct speedups_state *sstate; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1446 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1447 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO!|$OO", kwlist, &config, &PyTuple_Type, &path, &namespace, &default_)) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1448 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1449 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1450 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1451 sstate = PyModule_GetState(self); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1452 if (sstate == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1453 PyErr_SetString(PyExc_RuntimeError, "no module state available"); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1454 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1455 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1456 return _fast_getvarl(config, path, namespace, default_, sstate); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1457 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1458 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1459 |
|
610
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1460 static |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1461 PyObject * |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1462 fast_getvarl_s(PyObject *self, PyObject *args, PyObject *kwds) |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1463 { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1464 static char *kwlist[] = {"config", "path", "namespace", "default", NULL}; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1465 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1466 PyObject *config; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1467 PyObject *path; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1468 PyObject *namespace = NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1469 PyObject *default_ = NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1470 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1471 PyObject *res = NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1472 PyObject *tmp; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1473 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1474 struct speedups_state *sstate; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1475 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1476 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO!|$OO", kwlist, &config, &PyTuple_Type, &path, &namespace, &default_)) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1477 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1478 return NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1479 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1480 sstate = PyModule_GetState(self); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1481 if (sstate == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1482 PyErr_SetString(PyExc_RuntimeError, "no module state available"); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1483 return NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1484 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1485 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1486 tmp = _fast_getvarl(config, path, namespace, NULL, sstate); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1487 if (tmp == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1488 goto handle_possible_keyerror; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1489 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1490 res = PyObject_CallMethod(config, "substitute_variables_in_obj", "O", tmp); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1491 if (res == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1492 py_clear_ref(&tmp); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1493 goto handle_possible_keyerror; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1494 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1495 py_clear_ref(&tmp); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1496 return res; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1497 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1498 handle_possible_keyerror: |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1499 if (PyErr_ExceptionMatches(PyExc_KeyError)) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1500 if ((default_ == NULL) || py_object_is(default_, sstate->MARKER)) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1501 /* fall through */ |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1502 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1503 else { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1504 PyErr_Clear(); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1505 return Py_NewRef(default_); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1506 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1507 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1508 /* fall through */ |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1509 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1510 error: |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1511 return NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1512 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1513 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1514 |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1515 /** |
| 605 | 1516 * Combination of py_getvar_s and _py_getvar_s_with_cache_info |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1517 */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1518 static |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1519 PyObject * |
|
611
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
1520 _fast_getvar_s(PyObject *config, PyObject *varname, PyObject *default_, struct speedups_state *sstate, int *cacheable) |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1521 { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1522 PyObject *varname_b; /* always borrowed */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1523 PyObject *namespace_b; /* always borrowed */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1524 PyObject *splitted = NULL; |
|
610
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1525 PyObject *res; |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1526 PyObject *tmp1; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1527 PyObject *tmp2; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1528 |
|
611
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
1529 splitted = _fast_split_ns(varname, NULL, sstate); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1530 if (splitted == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1531 goto error; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1532 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1533 namespace_b = PyTuple_GetItem(splitted, 0); /* borrowed */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1534 varname_b = PyTuple_GetItem(splitted, 1); /* borrowed */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1535 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1536 if (PyObject_Not(namespace_b)) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1537 tmp1 = _fast_pathstr2path(varname_b, NULL, sstate); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1538 if (tmp1 == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1539 goto error; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1540 } |
|
622
8d2d5d54ff3c
FIX: Handle KeyErrors in fast_getvar_s() properly within its function frame
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
618
diff
changeset
|
1541 tmp2 = _fast_getvarl(config, tmp1, NULL, NULL, sstate); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1542 if (tmp2 == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1543 py_clear_ref(&tmp1); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1544 goto handle_possible_keyerror; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1545 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1546 py_clear_ref(&tmp1); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1547 res = PyObject_CallMethod(config, "substitute_variables_in_obj", "O", tmp2); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1548 if (res == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1549 py_clear_ref(&tmp2); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1550 goto handle_possible_keyerror; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1551 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1552 py_clear_ref(&tmp2); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1553 /* no namespace -> cacheable */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1554 *cacheable = 1; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1555 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1556 else { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1557 tmp1 = PyTuple_New(1); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1558 if (tmp1 == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1559 goto error; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1560 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1561 PyTuple_SetItem(tmp1, 0, Py_NewRef(varname_b)); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1562 tmp2 = _fast_getvarl(config, tmp1, namespace_b, NULL, sstate); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1563 if (tmp2 == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1564 py_clear_ref(&tmp1); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1565 goto handle_possible_keyerror; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1566 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1567 py_clear_ref(&tmp1); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1568 res = PyObject_CallMethod(config, "substitute_variables_in_obj", "O", tmp2); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1569 if (res == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1570 py_clear_ref(&tmp2); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1571 goto handle_possible_keyerror; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1572 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1573 py_clear_ref(&tmp2); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1574 /* results from namespaced lookups are currently not cacheable */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1575 *cacheable = 0; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1576 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1577 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1578 /* free splitted last because of using borrowed refs from it */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1579 Py_DECREF(splitted); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1580 return res; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1581 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1582 handle_possible_keyerror: |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1583 if (PyErr_ExceptionMatches(PyExc_KeyError)) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1584 if ((default_ == NULL) || py_object_is(default_, sstate->MARKER)) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1585 /* fall through */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1586 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1587 else { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1588 PyErr_Clear(); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1589 Py_XDECREF(splitted); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1590 return Py_NewRef(default_); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1591 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1592 } |
|
610
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1593 /* fall through */ |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1594 |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1595 error: |
|
610
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1596 Py_XDECREF(splitted); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1597 return NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1598 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1599 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1600 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1601 static |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1602 PyObject * |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1603 fast_getvar(PyObject *self, PyObject *args) |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1604 { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1605 PyObject *config; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1606 PyObject *varname; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1607 PyObject *default_; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1608 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1609 PyObject *varname_b; /* always borrowed */ |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1610 PyObject *namespace_b; /* always borrowed */ |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1611 PyObject *splitted = NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1612 PyObject *res; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1613 PyObject *tmp1; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1614 struct speedups_state *sstate; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1615 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1616 if (!PyArg_UnpackTuple(args, "config", 3, 3, &config, &varname, &default_)) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1617 return NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1618 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1619 |
|
611
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
1620 sstate = PyModule_GetState(self); |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
1621 if (sstate == NULL) { |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
1622 PyErr_SetString(PyExc_RuntimeError, "no module state available"); |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
1623 return NULL; |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
1624 } |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
1625 |
|
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
1626 splitted = _fast_split_ns(varname, NULL, sstate); |
|
610
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1627 if (splitted == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1628 goto error; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1629 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1630 namespace_b = PyTuple_GetItem(splitted, 0); /* borrowed */ |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1631 varname_b = PyTuple_GetItem(splitted, 1); /* borrowed */ |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1632 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1633 if (PyObject_Not(namespace_b)) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1634 tmp1 = _fast_pathstr2path(varname_b, NULL, sstate); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1635 if (tmp1 == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1636 goto error; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1637 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1638 res = _fast_getvarl(config, tmp1, NULL, default_, sstate); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1639 if (res == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1640 py_clear_ref(&tmp1); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1641 goto error; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1642 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1643 py_clear_ref(&tmp1); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1644 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1645 else { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1646 tmp1 = PyTuple_New(1); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1647 if (tmp1 == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1648 goto error; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1649 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1650 PyTuple_SetItem(tmp1, 0, Py_NewRef(varname_b)); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1651 res = _fast_getvarl(config, tmp1, namespace_b, default_, sstate); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1652 if (res == NULL) {tmp1 = _fast_pathstr2path(varname_b, NULL, sstate); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1653 if (tmp1 == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1654 goto error; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1655 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1656 py_clear_ref(&tmp1); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1657 goto error; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1658 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1659 py_clear_ref(&tmp1); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1660 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1661 Py_DECREF(splitted); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1662 return res; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1663 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1664 error: |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1665 Py_XDECREF(splitted); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1666 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1667 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1668 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1669 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1670 static |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1671 PyObject * |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1672 fast_getvar_s(PyObject *self, PyObject *args) |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1673 { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1674 PyObject *config; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1675 PyObject *varname; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1676 PyObject *default_; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1677 int cacheable; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1678 struct speedups_state *sstate; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1679 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1680 if (!PyArg_UnpackTuple(args, "config", 3, 3, &config, &varname, &default_)) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1681 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1682 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1683 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1684 sstate = PyModule_GetState(self); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1685 if (sstate == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1686 PyErr_SetString(PyExc_RuntimeError, "no module state available"); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1687 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1688 } |
|
611
db5a20f18030
Provide an internal version of fast_split_ns() to use an already module state available
Franz Glasner <fzglas.hg@dom66.de>
parents:
610
diff
changeset
|
1689 return _fast_getvar_s(config, varname, default_, sstate, &cacheable); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1690 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1691 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1692 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1693 static |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1694 PyObject * |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1695 sync_MISSING(PyObject *self, PyObject *missing) |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1696 { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1697 struct speedups_state *sstate; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1698 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1699 sstate = PyModule_GetState(self); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1700 if (sstate == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1701 PyErr_SetString(PyExc_RuntimeError, "no module state available"); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1702 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1703 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1704 if (sstate->MISSING != NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1705 PyErr_SetString(PyExc_RuntimeError, "_MISSING already set"); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1706 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1707 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1708 sstate->MISSING = Py_NewRef(missing); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1709 Py_RETURN_NONE; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1710 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1711 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1712 |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1713 static |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1714 PyObject * |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1715 sync_MARKER(PyObject *self, PyObject *marker) |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1716 { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1717 struct speedups_state *sstate; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1718 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1719 sstate = PyModule_GetState(self); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1720 if (sstate == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1721 PyErr_SetString(PyExc_RuntimeError, "no module state available"); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1722 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1723 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1724 if (sstate->MARKER != NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1725 PyErr_SetString(PyExc_RuntimeError, "_MARKER already set"); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1726 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1727 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1728 sstate->MARKER = Py_NewRef(marker); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1729 Py_RETURN_NONE; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1730 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1731 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1732 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1733 static struct PyMethodDef speedups_methods[] = { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1734 {"fast_unquote", fast_unquote, METH_O, PyDoc_STR("C-implementation of configmix.unquote")}, |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1735 {"fast_quote", fast_quote, METH_O, PyDoc_STR("C-implementation of configmix.quote")}, |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1736 {"fast_pathstr2path", fast_pathstr2path, METH_O, PyDoc_STR("C-implementation of configmix.pathstr2path")}, |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
1737 {"_fast_split_filters", fast_split_filters, METH_VARARGS, PyDoc_STR("C-implementation of configmix.config._split_filters")}, |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1738 {"_fast_split_ns", fast_split_ns, METH_O, PyDoc_STR("C-implementation of configmix.config._split_ns")}, |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1739 {"_fast_interpolate_variables", fast_interpolate_variables, METH_VARARGS, PyDoc_STR("C-implementation of configmix.config.Configuration.interpolate_variables")}, |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1740 {"_fast_getvarl", (PyCFunction)fast_getvarl, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("C-Implementation of configmix.config.Configuration.getvarl")}, |
|
610
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1741 {"_fast_getvarl_s", (PyCFunction)fast_getvarl_s, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("C-Implementation of configmix.config.Configuration.getvarl_s")}, |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1742 {"_fast_getvar", fast_getvar, METH_VARARGS, PyDoc_STR("C-Implementation of configmix.config.Configuration.getvar")}, |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1743 {"_fast_getvar_s", fast_getvar_s, METH_VARARGS, PyDoc_STR("C-Implementation of configmix.config.Configuration.getvar_s")}, |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1744 {"_sync_MISSING", sync_MISSING, METH_O, PyDoc_STR("Internal function to easily sync the _MISSING object with configmix.config")}, |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1745 {"_sync_MARKER", sync_MARKER, METH_O, PyDoc_STR("Internal function to easily sync the _MARKER object with configmix.config")}, |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1746 {NULL, NULL, 0, NULL} |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1747 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1748 |
|
547
1cbe8b0f2b78
Put the value of Py_LIMITED_API into the module dict when the C-extension is compiled against the stable API
Franz Glasner <fzglas.hg@dom66.de>
parents:
545
diff
changeset
|
1749 #define STRINGIFY(s) #s |
|
1cbe8b0f2b78
Put the value of Py_LIMITED_API into the module dict when the C-extension is compiled against the stable API
Franz Glasner <fzglas.hg@dom66.de>
parents:
545
diff
changeset
|
1750 #define XSTRINGIFY(s) STRINGIFY(s) |
|
1cbe8b0f2b78
Put the value of Py_LIMITED_API into the module dict when the C-extension is compiled against the stable API
Franz Glasner <fzglas.hg@dom66.de>
parents:
545
diff
changeset
|
1751 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1752 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1753 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1754 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1755 speedups_exec(PyObject *module) |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1756 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1757 struct speedups_state *sstate = PyModule_GetState(module); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1758 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1759 if (sstate == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1760 PyErr_SetString(PyExc_ImportError, "no module state available yet"); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1761 return -1; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1762 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1763 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1764 PyModule_AddStringConstant(module, "__release__", release); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1765 PyModule_AddStringConstant(module, "__date__", date); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1766 PyModule_AddStringConstant(module, "__author__", "Franz Glasner"); |
|
547
1cbe8b0f2b78
Put the value of Py_LIMITED_API into the module dict when the C-extension is compiled against the stable API
Franz Glasner <fzglas.hg@dom66.de>
parents:
545
diff
changeset
|
1767 #if defined(Py_LIMITED_API) |
|
1cbe8b0f2b78
Put the value of Py_LIMITED_API into the module dict when the C-extension is compiled against the stable API
Franz Glasner <fzglas.hg@dom66.de>
parents:
545
diff
changeset
|
1768 PyModule_AddStringConstant(module, "Py_LIMITED_API", XSTRINGIFY(Py_LIMITED_API)); |
|
1cbe8b0f2b78
Put the value of Py_LIMITED_API into the module dict when the C-extension is compiled against the stable API
Franz Glasner <fzglas.hg@dom66.de>
parents:
545
diff
changeset
|
1769 #endif |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1770 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1771 sstate->DOT = PyUnicode_FromStringAndSize(".", 1); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1772 if (sstate->DOT == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1773 return -1; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1774 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1775 PyUnicode_InternInPlace(&(sstate->DOT)); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1776 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1777 sstate->QUOTE = PyUnicode_FromStringAndSize("%", 1); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1778 if (sstate->QUOTE == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1779 return -1; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1780 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1781 PyUnicode_InternInPlace(&(sstate->QUOTE)); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1782 |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1783 sstate->NS_SEPARATOR = PyUnicode_FromStringAndSize(":", 1); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1784 if (sstate->NS_SEPARATOR == NULL) { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1785 return -1; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1786 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1787 PyUnicode_InternInPlace(&(sstate->NS_SEPARATOR)); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1788 |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1789 sstate->FILTER_SEPARATOR = PyUnicode_FromStringAndSize("|", 1); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1790 if (sstate->FILTER_SEPARATOR == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1791 return -1; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1792 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1793 PyUnicode_InternInPlace(&(sstate->FILTER_SEPARATOR)); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1794 |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
1795 sstate->FILTER_SEPARATOR_REV = PyUnicode_FromStringAndSize(",", 1); |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
1796 if (sstate->FILTER_SEPARATOR_REV == NULL) { |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
1797 return -1; |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
1798 } |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
1799 PyUnicode_InternInPlace(&(sstate->FILTER_SEPARATOR_REV)); |
|
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
1800 |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1801 sstate->EMPTY_FILTER = PyUnicode_FromStringAndSize("Empty", 5); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1802 if (sstate->EMPTY_FILTER == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1803 return -1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1804 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1805 PyUnicode_InternInPlace(&(sstate->EMPTY_FILTER)); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1806 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1807 sstate->NONE_FILTER = PyUnicode_FromStringAndSize("None", 4); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1808 if (sstate->NONE_FILTER == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1809 return -1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1810 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1811 PyUnicode_InternInPlace(&(sstate->NONE_FILTER)); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1812 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1813 sstate->EMPTY_STR = PyUnicode_FromStringAndSize("", 0); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1814 if (sstate->EMPTY_STR == NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1815 return -1; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1816 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1817 PyUnicode_InternInPlace(&(sstate->EMPTY_STR)); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1818 |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1819 sstate->QUOTE_MAP = Py_BuildValue( |
|
656
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
1820 "{IsIsIsIsIsIsIsIsIsIsIsIs}", |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1821 0x25, "%x25", /* QUOTE: % */ |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1822 0x2e, "%x2e", /* DOT: . */ |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1823 0x3a, "%x3a", /* NS_SEPARATOR: : */ |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1824 0x23, "%x23", /* COMMENT/anchor: # */ |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1825 0x7c, "%x7c", /* FILTER_SEPARATOR: | */ |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1826 0x22, "%x22", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1827 0x27, "%x27", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1828 0x7b, "%x7b", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1829 0x7d, "%x7d", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1830 0x5b, "%x5b", |
|
656
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
1831 0x5d, "%x5d", |
|
2b1c7a68f913
Enable indexed access to lists in the configuration using an access path string representation like "~NNN~"
Franz Glasner <fzglas.hg@dom66.de>
parents:
639
diff
changeset
|
1832 0x7e, "%x7e"); /* tilde ~ */ |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1833 if (sstate->QUOTE_MAP == NULL) { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1834 return -1; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1835 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1836 |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1837 sstate->STARTTOK = PyUnicode_FromStringAndSize("{{", 2); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1838 if (sstate->STARTTOK == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1839 return -1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1840 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1841 PyUnicode_InternInPlace(&(sstate->STARTTOK)); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1842 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1843 sstate->ENDTOK = PyUnicode_FromStringAndSize("}}", 2); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1844 if (sstate->ENDTOK == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1845 return -1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1846 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1847 PyUnicode_InternInPlace(&(sstate->ENDTOK)); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1848 |
|
703
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1849 sstate->ENDTOK_FILTER = PyUnicode_FromStringAndSize("|}}", 3); |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1850 if (sstate->ENDTOK_FILTER == NULL) { |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1851 return -1; |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1852 } |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1853 PyUnicode_InternInPlace(&(sstate->ENDTOK_FILTER)); |
|
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1854 |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1855 sstate->REF_NAMESPACE = PyUnicode_FromStringAndSize("ref", 3); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1856 if (sstate->REF_NAMESPACE == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1857 return -1; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1858 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1859 PyUnicode_InternInPlace(&(sstate->REF_NAMESPACE)); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1860 |
|
639
999cfca55d25
FIX: {{::DEL::}} has 11 chars instead of 3
Franz Glasner <fzglas.hg@dom66.de>
parents:
637
diff
changeset
|
1861 sstate->DEL_VALUE = PyUnicode_FromStringAndSize("{{::DEL::}}", 11); |
|
637
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1862 if (sstate->DEL_VALUE == NULL) { |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1863 return -1; |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1864 } |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1865 PyUnicode_InternInPlace(&(sstate->DEL_VALUE)); |
|
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1866 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1867 return 0; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1868 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1869 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1870 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1871 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1872 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1873 speeeupds_traverse(PyObject *module, visitproc visit, void *arg) |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1874 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1875 struct speedups_state *sstate = PyModule_GetState(module); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1876 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1877 if (sstate != NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1878 Py_VISIT(sstate->DOT); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1879 Py_VISIT(sstate->QUOTE); |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1880 Py_VISIT(sstate->NS_SEPARATOR); |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1881 Py_VISIT(sstate->FILTER_SEPARATOR); |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
1882 Py_VISIT(sstate->FILTER_SEPARATOR_REV); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1883 Py_VISIT(sstate->EMPTY_FILTER); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1884 Py_VISIT(sstate->NONE_FILTER); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1885 Py_VISIT(sstate->EMPTY_STR); |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1886 Py_VISIT(sstate->QUOTE_MAP); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1887 Py_VISIT(sstate->MISSING); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1888 Py_VISIT(sstate->MARKER); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1889 Py_VISIT(sstate->STARTTOK); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1890 Py_VISIT(sstate->ENDTOK); |
|
703
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1891 Py_VISIT(sstate->ENDTOK_FILTER); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1892 Py_VISIT(sstate->REF_NAMESPACE); |
|
637
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1893 Py_VISIT(sstate->DEL_VALUE); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1894 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1895 return 0; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1896 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1897 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1898 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1899 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1900 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1901 speedups_clear(PyObject *module) |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1902 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1903 struct speedups_state *sstate = PyModule_GetState(module); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1904 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1905 if (sstate != NULL) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1906 Py_CLEAR(sstate->DOT); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1907 Py_CLEAR(sstate->QUOTE); |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1908 Py_CLEAR(sstate->NS_SEPARATOR); |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1909 Py_CLEAR(sstate->FILTER_SEPARATOR); |
|
705
0485a033c95d
FIX: Parsing a filter chain for the new filter-only expansions: parse them backwards and use "," as filter-chain separator here.
Franz Glasner <fzglas.hg@dom66.de>
parents:
704
diff
changeset
|
1910 Py_CLEAR(sstate->FILTER_SEPARATOR_REV); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1911 Py_CLEAR(sstate->EMPTY_FILTER); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1912 Py_CLEAR(sstate->NONE_FILTER); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1913 Py_CLEAR(sstate->EMPTY_STR); |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1914 Py_CLEAR(sstate->QUOTE_MAP); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1915 Py_CLEAR(sstate->MISSING); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1916 Py_CLEAR(sstate->MARKER); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1917 Py_CLEAR(sstate->STARTTOK); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1918 Py_CLEAR(sstate->ENDTOK); |
|
703
193a616e0b3c
Begin implementation of filter-only expansions (recursive with respect to expansion)
Franz Glasner <fzglas.hg@dom66.de>
parents:
656
diff
changeset
|
1919 Py_CLEAR(sstate->ENDTOK_FILTER); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1920 Py_CLEAR(sstate->REF_NAMESPACE); |
|
637
4499e9b4855d
The ``{{::DEL::}}`` is not subject to interpolation any more.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
630
diff
changeset
|
1921 Py_CLEAR(sstate->DEL_VALUE); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1922 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1923 return 0; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1924 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1925 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1926 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1927 static struct PyModuleDef_Slot speedups_slots[] = { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1928 {Py_mod_exec, speedups_exec}, |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1929 {0, NULL} |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1930 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1931 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1932 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1933 static struct PyModuleDef speedups_def = { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1934 PyModuleDef_HEAD_INIT, /* m_base */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1935 "_speedups", /* m_name (relative) */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1936 PyDoc_STR("Speedups for configmix"), /* m_doc */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1937 sizeof(struct speedups_state), /* m_size */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1938 speedups_methods, /* m_methods */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1939 speedups_slots, /* m_slots */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1940 speeeupds_traverse, /* m_traverse */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1941 speedups_clear, /* m_clear */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1942 NULL /* m_free */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1943 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1944 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1945 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1946 PyMODINIT_FUNC |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1947 PyInit__speedups(void) |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1948 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1949 /* |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1950 * Use multi-phase extension module initialization (PEP 489). |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1951 * This is Python 3.5+. |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1952 */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1953 return PyModuleDef_Init(&speedups_def); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1954 } |
