Mercurial > hgrepos > Python > libs > ConfigMix
annotate configmix/_speedups.c @ 613:d9e0c93b2838
Changelog
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 12 Jan 2022 01:12:34 +0100 |
| parents | f797f798edfb |
| children | 7e480a32d9d5 |
| 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; |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
28 PyObject *EMPTY_FILTER; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
29 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
|
30 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
|
31 PyObject *QUOTE_MAP; |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
32 PyObject *MISSING; |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
33 PyObject *MARKER; |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
34 PyObject *STARTTOK; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
35 PyObject *ENDTOK; |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
36 PyObject *REF_NAMESPACE; |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
37 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
38 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
39 |
|
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
|
40 static PyObject * _fast_getvar_s(PyObject *, PyObject *, PyObject *, struct speedups_state *, int*); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
41 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
42 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
43 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
44 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
45 _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
|
46 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
47 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
|
48 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
|
49 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
|
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 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
57 else { |
|
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 >= 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
|
59 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
|
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 >= 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
|
63 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
|
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 PyErr_SetString(PyExc_ValueError, "invalid base-16 literal"); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
67 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
|
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 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
70 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
71 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
72 *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
|
73 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
|
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 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
77 #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
|
78 |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
79 static |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
80 void |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
81 _raise_utf8_encode_error(PyObject *s, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
82 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
|
83 const char *reason) |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
84 { |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
85 /* |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
86 * 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
|
87 */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
88 PyObject *errobj = PyObject_CallFunction( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
89 PyExc_UnicodeEncodeError, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
90 "sOnns", |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
91 "utf-8", |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
92 s, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
93 start, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
94 end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
95 reason); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
96 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
97 if (errobj == NULL) { |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
98 /* cannot do anything here */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
99 return; |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
100 } |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
101 /* 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
|
102 //Py_INCREF(PyExc_UnicodeEncodeError); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
103 //PyErr_Restore(PyExc_UnicodeEncodeError, errobj, NULL); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
104 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
105 PyErr_SetObject(PyExc_UnicodeEncodeError, errobj); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
106 Py_DECREF(errobj); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
107 } |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
108 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
109 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
110 /* |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
111 * 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
|
112 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
113 * Disclaimer |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
114 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
115 * 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
|
116 * 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
|
117 * 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
|
118 * 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
|
119 * 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
|
120 * 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
|
121 * 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
|
122 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
123 * 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
|
124 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
125 * 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
|
126 * 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
|
127 * 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
|
128 * 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
|
129 * remains attached. |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
130 */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
131 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
132 #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
|
133 #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
|
134 #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
|
135 #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
|
136 #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
|
137 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
138 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
139 /* |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
140 * 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
|
141 * 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
|
142 * 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
|
143 * (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
|
144 * 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
|
145 */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
146 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
|
147 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
148 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
149 static |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
150 Py_ssize_t |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
151 _convert_ucs4_to_utf8( |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
152 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
|
153 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
|
154 int strict, |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
155 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
|
156 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
|
157 ) |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
158 { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
159 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
|
160 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
|
161 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
162 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
|
163 unsigned char *target = targetStart; |
|
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 if (strict) { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
166 /* 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
|
167 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
|
168 _raise_utf8_encode_error( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
169 ch_obj, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
170 1, ch_obj_end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
171 "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
|
172 return -1; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
173 } |
|
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 /* |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
176 * Figure out how many bytes the result will require. Turn any |
| 556 | 177 * 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
|
178 */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
179 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
|
180 bytesToWrite = 1; |
| 565 | 181 } |
| 182 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
|
183 bytesToWrite = 2; |
| 565 | 184 } |
| 185 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
|
186 bytesToWrite = 3; |
| 565 | 187 } |
| 188 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
|
189 bytesToWrite = 4; |
| 565 | 190 } |
| 191 else { | |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
192 _raise_utf8_encode_error( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
193 ch_obj, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
194 1, ch_obj_end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
195 "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
|
196 return -1; |
|
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 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
199 target += bytesToWrite; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
200 if (target > targetEnd) { |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
201 _raise_utf8_encode_error( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
202 ch_obj, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
203 1, ch_obj_end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
204 "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
|
205 return -1; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
206 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
213 return bytesToWrite; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
214 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
215 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
216 |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
217 /* |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
218 * 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
|
219 */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
220 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
221 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
222 static |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
223 PyObject * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
224 _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
|
225 { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
226 Py_UCS4 c; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
227 unsigned char buf[6]; |
|
555
b7434a34a1f4
- FIX: Memory-leak with the "filters" local variable
Franz Glasner <fzglas.hg@dom66.de>
parents:
554
diff
changeset
|
228 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
|
229 PyObject *u; |
|
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 (_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
|
232 return NULL; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
233 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
234 /* 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
|
235 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
|
236 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
|
237 return NULL; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
238 } |
|
555
b7434a34a1f4
- FIX: Memory-leak with the "filters" local variable
Franz Glasner <fzglas.hg@dom66.de>
parents:
554
diff
changeset
|
239 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
|
240 if (u == NULL) { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
241 return NULL; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
242 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
243 return u; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
244 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
245 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
246 #else |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
247 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
248 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
249 PyObject * |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
250 _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
|
251 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
252 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
|
253 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
|
254 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
264 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
|
265 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
266 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
267 #endif /* Py_LIMITED_API */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
268 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
269 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
270 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
271 PyObject * |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
272 _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
|
273 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
285 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
|
286 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
|
287 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
|
288 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
289 } |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
290 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
291 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
|
292 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
|
293 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
294 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
|
295 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
|
296 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
|
297 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
298 if (find == -1) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
299 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
|
300 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
301 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
308 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
309 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
|
310 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
|
311 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
|
312 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
313 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
|
314 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
|
315 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
|
316 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 } |
|
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 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
|
323 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
|
324 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
|
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 /* |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
327 * 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
|
328 * 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
|
329 */ |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
330 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
|
331 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
332 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
|
333 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
|
334 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
|
335 if (pb_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
|
336 PyErr_SetString(PyExc_ValueError, "unknown quote syntax string"); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
337 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
|
338 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 if (pb_len < 9) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
343 PyErr_SetString(PyExc_ValueError, "quote syntax: length too small"); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
344 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
|
345 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
346 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
|
347 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
|
348 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
|
349 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 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
|
354 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
355 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
|
356 break; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
357 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
|
358 if (pb_len < 5) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
359 PyErr_SetString(PyExc_ValueError, "quote syntax: length too small"); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
360 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
|
361 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
362 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
|
363 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
|
364 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
|
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 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
|
367 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
|
368 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
|
369 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
|
370 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
371 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
|
372 break; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
373 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
|
374 if (pb_len < 3) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
375 PyErr_SetString(PyExc_ValueError, "quote syntax: length too small"); |
|
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 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
|
379 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
|
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 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
|
383 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
|
384 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
|
385 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
|
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 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
|
388 break; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
389 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
390 default: |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
391 PyErr_SetString(PyExc_ValueError, "unknown quote syntax string"); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
392 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
|
393 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
394 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
395 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
400 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
|
401 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
|
402 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
|
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 error: |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
405 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
|
406 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
|
407 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
|
408 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
409 |
|
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 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
412 PyObject * |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
413 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
|
414 { |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
415 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
|
416 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
417 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
418 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
419 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
420 PyObject * |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
421 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
|
422 { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
423 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
429 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
|
430 if (s_len < 0) { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
431 return NULL; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
432 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
433 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
|
434 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
|
435 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
436 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
|
437 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
|
438 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
|
439 switch (c) { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
440 case 0x25: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
441 case 0x2e: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
442 case 0x3a: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
443 case 0x23: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
444 case 0x7c: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
445 case 0x22: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
446 case 0x27: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
447 case 0x7b: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
448 case 0x7d: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
449 case 0x5b: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
450 case 0x5d: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
451 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
|
452 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
|
453 break; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
454 default: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
455 /* VOID */ |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
456 ; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
457 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
458 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
459 if (!need_quoting) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
460 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
|
461 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
462 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
|
463 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
|
464 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
|
465 return NULL; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
466 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
467 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
|
468 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
469 |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
470 |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
471 static |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
472 PyObject * |
|
602
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
473 _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
|
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 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
|
476 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
|
477 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
|
478 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
|
479 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
|
480 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
|
481 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
|
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 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
|
484 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
|
485 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
|
486 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
487 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
|
488 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
|
489 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
490 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
491 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
|
492 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
|
493 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
|
494 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
|
495 return NULL; |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
496 } |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
497 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
502 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
|
503 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
|
504 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
|
505 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
506 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
|
507 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
|
508 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
|
509 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
510 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
|
511 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
|
512 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
|
513 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
|
514 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
|
515 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
516 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
|
517 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
518 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
519 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
|
520 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
|
521 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
522 error: |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
523 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
|
524 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
|
525 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
|
526 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
527 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
528 |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
529 static |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
530 PyObject * |
|
602
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
531 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
|
532 { |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
533 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
|
534 } |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
535 |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
536 |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
537 static |
|
a2fff0d93d83
Split up fast_pathstr2path into internal implementation and a simple wrapper
Franz Glasner <fzglas.hg@dom66.de>
parents:
601
diff
changeset
|
538 PyObject * |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
539 _fast_split_filters(PyObject *varname, PyObject *self, struct speedups_state *sstate) |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
540 { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
541 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
|
542 Py_ssize_t sep; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
543 PyObject *res = NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
544 PyObject *filters = NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
545 PyObject *name = NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
546 PyObject *tmp; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
547 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
548 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
|
549 if (varname_len < 0) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
550 return NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
551 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
552 if (varname_len == 0) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
553 sep = -1; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
554 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
555 else { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
556 sep = PyUnicode_FindChar(varname, '|', 0, varname_len, 1); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
557 if (sep == -2) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
558 return NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
559 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
560 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
561 if (sep == -1) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
562 res = PyTuple_New(2); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
563 if (res == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
564 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
565 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
566 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
|
567 filters = PyList_New(0); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
568 if (filters == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
569 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
570 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
571 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
|
572 return res; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
573 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
574 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
|
575 if (name == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
576 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
577 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
578 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
579 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
|
580 if (filters == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
581 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
582 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
583 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
|
584 if (tmp == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
585 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
586 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
587 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
|
588 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
589 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
|
590 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
|
591 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
592 res = PyTuple_New(2); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
593 if (res == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
594 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
595 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
596 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
|
597 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
|
598 filters = PyList_New(0); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
599 if (filters == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
600 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
601 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
602 PyTuple_SetItem(res, 1, filters); /* steals */ |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
603 filters = NULL; |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
604 return res; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
605 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
606 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
607 if (sstate == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
608 sstate = PyModule_GetState(self); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
609 if (sstate == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
610 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
|
611 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
612 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
613 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
614 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
615 tmp = PyUnicode_Split(filters, sstate->FILTER_SEPARATOR, -1); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
616 if (tmp == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
617 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
618 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
619 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
|
620 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
621 res = PyTuple_New(2); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
622 if (res == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
623 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
624 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
625 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
|
626 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
|
627 return res; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
628 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
629 error: |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
630 Py_XDECREF(res); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
631 Py_XDECREF(filters); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
632 Py_XDECREF(name); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
633 return NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
634 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
635 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
636 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
637 static |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
638 PyObject * |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
639 fast_split_filters(PyObject *self, PyObject *varname) |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
640 { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
641 return _fast_split_filters(varname, self, NULL); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
642 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
643 |
|
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 static |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
646 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
|
647 _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
|
648 { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
649 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
|
650 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
|
651 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
|
652 PyObject *o1; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
653 PyObject *o2; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
654 |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
655 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
|
656 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
|
657 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
658 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
659 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
|
660 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
|
661 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
662 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
663 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
|
664 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
|
665 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
|
666 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
667 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
668 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
|
669 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
|
670 return res; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
671 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
672 |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
673 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
|
674 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
|
675 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
676 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
677 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
|
678 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
|
679 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
|
680 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
681 } |
|
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
|
682 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
|
683 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
|
684 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
|
685 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
|
686 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
687 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
688 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
|
689 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
|
690 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
|
691 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
|
692 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
|
693 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
694 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
695 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
|
696 return res; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
697 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
698 |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
699 |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
700 static |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
701 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
|
702 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
|
703 { |
|
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
|
704 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
|
705 } |
|
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
|
706 |
|
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
|
707 |
|
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
|
708 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
|
709 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
|
710 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
|
711 { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
712 PyObject *config; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
713 PyObject *s; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
714 PyObject *cache; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
715 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
716 Py_ssize_t s_len; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
717 Py_ssize_t idx; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
718 Py_ssize_t i, j; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
719 PyObject *parts = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
720 Py_ssize_t parts_len; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
721 PyObject *res_parts = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
722 PyObject *res = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
723 PyObject *tmp; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
724 PyObject *pb; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
725 Py_ssize_t pb_len; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
726 PyObject *varname = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
727 PyObject *varvalue = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
728 PyObject *filters = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
729 int cacheable; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
730 int use_cache = 1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
731 int first_part_is_empty; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
732 PyObject *err_type; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
733 PyObject *err_value; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
734 PyObject *err_tb; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
735 struct speedups_state *sstate; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
736 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
737 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
|
738 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
739 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
740 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
|
741 if (s_len < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
742 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
743 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
744 if (s_len < 4) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
745 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
746 return Py_NewRef(s); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
747 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
748 sstate = PyModule_GetState(self); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
749 if (sstate == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
750 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
|
751 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
752 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
753 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
754 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
|
755 if (idx < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
756 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
757 return Py_NewRef(s); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
758 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
759 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
760 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
|
761 if (res != NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
762 if (res == sstate->MISSING) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
763 return PyErr_Format( |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
764 PyExc_KeyError, |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
765 "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
|
766 s); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
767 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
768 else { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
769 return Py_NewRef(res); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
770 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
771 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
772 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
773 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
|
774 if (parts == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
775 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
776 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
777 parts_len = PyList_Size(parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
778 if (parts_len < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
779 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
780 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
781 res_parts = PyList_New(1); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
782 if (res_parts == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
783 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
784 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
785 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
786 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
|
787 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
788 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
789 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
790 /* |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
791 * 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
|
792 * an interpolation token. |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
793 */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
794 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
|
795 /* 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
|
796 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
|
797 tmp = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
798 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
799 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
|
800 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
|
801 pb_len = PyUnicode_GetLength(pb); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
802 if (pb_len < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
803 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
804 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
805 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
|
806 if (idx < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
807 /* |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
808 * 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
|
809 * 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
|
810 */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
811 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
|
812 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
813 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
814 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
|
815 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
816 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
817 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
|
818 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
|
819 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
820 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
821 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
|
822 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
|
823 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
824 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
825 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
826 break; /* the for-loop */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
827 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
828 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
829 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
|
830 if (varname == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
831 goto error; |
|
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 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
834 tmp = _fast_split_filters(varname, NULL, sstate); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
835 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
836 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
837 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
838 if (PyTuple_Size(tmp) != 2) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
839 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
|
840 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
841 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
842 } |
| 562 | 843 py_clear_ref(&varname); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
844 /* Unpack the result tuple */ |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
845 /* borrowed -- cannot fail -- need ownership */ |
|
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
846 varname = Py_NewRef(PyTuple_GetItem(tmp, 0)); |
|
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
847 /* 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
|
848 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
|
849 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
850 |
|
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
|
851 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
|
852 if (varvalue == NULL) { |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
853 if (PyErr_ExceptionMatches(PyExc_KeyError)) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
854 cacheable = 1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
855 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
|
856 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
857 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
|
858 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
859 else { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
860 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
|
861 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
862 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
|
863 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
864 else { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
865 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
|
866 /* this does NOT steal */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
867 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
|
868 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
|
869 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
870 } |
|
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 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
873 else { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
874 /* other exception/error than KeyError */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
875 goto error; |
|
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 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
878 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
879 if (!cacheable) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
880 use_cache = 0; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
881 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
882 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
883 py_clear_ref(&varname); |
|
554
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 tmp = PyObject_CallMethod( |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
886 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
|
887 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
888 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
889 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
890 py_clear_ref(&varvalue); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
891 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
892 py_clear_ref(&filters); |
|
555
b7434a34a1f4
- FIX: Memory-leak with the "filters" local variable
Franz Glasner <fzglas.hg@dom66.de>
parents:
554
diff
changeset
|
893 |
|
554
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 * 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
|
896 * 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
|
897 */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
898 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
|
899 res = varvalue; varvalue = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
900 goto success; /* break out early */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
901 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
902 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
|
903 tmp = PyObject_Str(varvalue); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
904 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
905 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
906 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
907 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
|
908 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
909 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
910 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
911 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
912 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
913 py_clear_ref(&varvalue); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
914 /* 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
|
915 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
|
916 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
917 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
918 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
919 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
|
920 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
921 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
922 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
923 py_clear_ref(&tmp); |
|
554
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 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
926 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
|
927 if (res == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
928 goto error; |
|
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 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
931 success: |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
932 Py_DECREF(parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
933 Py_DECREF(res_parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
934 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
935 if (use_cache) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
936 PyDict_SetItem(cache, s, res); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
937 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
|
938 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
939 return res; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
940 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
941 error: |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
942 Py_XDECREF(varname); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
943 Py_XDECREF(varvalue); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
944 Py_XDECREF(filters); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
945 Py_XDECREF(parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
946 Py_XDECREF(res_parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
947 Py_XDECREF(res); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
948 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
949 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
950 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
951 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
952 static |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
953 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
|
954 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
|
955 { |
|
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
|
956 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
|
957 PyObject *s; |
|
566
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
958 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
|
959 |
|
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
|
960 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
|
961 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
|
962 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
|
963 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
|
964 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
|
965 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
|
966 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
|
967 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
|
968 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
|
969 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
|
970 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
|
971 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
|
972 |
|
566
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
973 if (!PyArg_UnpackTuple(args, "s", 2, 3, &config, &s, &cache)) { |
|
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
|
974 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
|
975 } |
|
566
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
976 /* 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
|
977 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
|
978 cache = NULL; |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
979 } |
|
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
|
980 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
|
981 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
|
982 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
|
983 } |
|
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
|
984 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
|
985 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
|
986 } |
|
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
|
987 |
|
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
|
988 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
|
989 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
|
990 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
|
991 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
|
992 } |
|
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
|
993 |
|
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
|
994 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
|
995 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
|
996 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
|
997 } |
|
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
|
998 if (start == -1) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
999 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
|
1000 } |
|
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
|
1001 |
|
566
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1002 if (cache != NULL) { |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1003 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
|
1004 if (result != NULL) { |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1005 if (result == sstate->MISSING) { |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1006 return PyErr_Format( |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1007 PyExc_KeyError, |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1008 "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
|
1009 s); |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1010 } |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1011 else { |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1012 return Py_NewRef(result); |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1013 } |
|
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
|
1014 } |
|
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
|
1015 } |
|
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
|
1016 |
|
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
|
1017 result = PyList_New(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
|
1018 if (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
|
1019 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
|
1020 } |
|
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
|
1021 |
|
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
|
1022 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
|
1023 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
|
1024 |
|
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
|
1025 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
|
1026 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
|
1027 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
|
1028 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
|
1029 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
|
1030 } |
|
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
|
1031 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
|
1032 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
|
1033 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
|
1034 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1035 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
|
1036 } |
|
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
|
1037 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
|
1038 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
|
1039 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
|
1040 } |
|
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
|
1041 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
|
1042 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
|
1043 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
|
1044 } |
|
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
|
1045 |
|
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
|
1046 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
|
1047 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
|
1048 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
|
1049 } |
|
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
|
1050 |
|
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
|
1051 tmp = _fast_split_filters(varname, NULL, 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
|
1052 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
|
1053 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
|
1054 } |
|
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
|
1055 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
|
1056 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
|
1057 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
|
1058 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
|
1059 } |
| 562 | 1060 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
|
1061 /* Unpack the result tuple */ |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1062 /* borrowed -- cannot fail -- need ownership */ |
|
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1063 varname = Py_NewRef(PyTuple_GetItem(tmp, 0)); |
|
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1064 /* 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
|
1065 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
|
1066 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
|
1067 |
|
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
|
1068 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
|
1069 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1070 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
|
1071 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
|
1072 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
|
1073 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
|
1074 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1075 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
|
1076 } |
|
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 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
|
1078 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
|
1079 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1080 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
|
1081 } |
|
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 else { |
|
566
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1083 if (cache != NULL) { |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1084 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
|
1085 /* this does NOT steal */ |
|
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1086 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
|
1087 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
|
1088 } |
|
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
|
1089 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
|
1090 } |
|
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
|
1091 } |
|
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
|
1092 } |
|
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 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
|
1094 /* 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
|
1095 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
|
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 } |
|
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
|
1098 |
|
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 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
|
1100 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
|
1101 } |
|
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 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1103 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
|
1104 |
|
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 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
|
1106 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
|
1107 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
|
1108 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
|
1109 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1110 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
|
1111 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1112 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
|
1113 |
|
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
|
1114 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
|
1115 |
|
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 /* |
|
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 * 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
|
1118 * 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
|
1119 */ |
|
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
|
1120 if ((start == 0) && (rest == s_len)) { |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1121 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
|
1122 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
|
1123 } |
|
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
|
1124 |
|
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
|
1125 /* 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
|
1126 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
|
1127 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
|
1128 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
|
1129 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
|
1130 } |
|
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
|
1131 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
|
1132 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
|
1133 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
|
1134 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1135 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
|
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 |
|
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
|
1138 /* 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
|
1139 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
|
1140 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
|
1141 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
|
1142 } |
|
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
|
1143 } |
|
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
|
1144 |
|
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
|
1145 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
|
1146 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
|
1147 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
|
1148 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
|
1149 } |
|
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
|
1150 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
|
1151 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
|
1152 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
|
1153 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1154 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
|
1155 } |
|
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
|
1156 |
|
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
|
1157 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
|
1158 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
|
1159 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
|
1160 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1161 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
|
1162 |
|
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
|
1163 success: |
|
566
dc2e2384c8c7
fast_interpolate_variables(): allow omission of the cache variable.
Franz Glasner <fzglas.hg@dom66.de>
parents:
565
diff
changeset
|
1164 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
|
1165 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
|
1166 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
|
1167 } |
|
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
|
1168 } |
|
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
|
1169 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
|
1170 |
|
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
|
1171 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
|
1172 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
|
1173 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
|
1174 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
|
1175 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
|
1176 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
|
1177 } |
|
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
|
1178 |
|
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
|
1179 |
|
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
|
1180 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
|
1181 PyObject * |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1182 _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
|
1183 { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1184 PyObject *varvalue; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1185 PyObject *lookupfn = NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1186 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1187 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
|
1188 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
|
1189 if (lookupfn == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1190 goto error; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1191 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1192 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1193 else { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1194 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
|
1195 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
|
1196 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1197 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1198 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
|
1199 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
|
1200 if (lookupfn == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1201 goto error; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1202 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1203 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1204 else { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1205 /* lookup_varns */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1206 /* this is borrowed */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1207 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
|
1208 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
|
1209 goto error; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1210 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1211 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
|
1212 if (lookupfn == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1213 goto handle_possible_keyerror; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1214 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1215 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1216 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1217 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
|
1218 if (varvalue == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1219 goto handle_possible_keyerror; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1220 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1221 Py_DECREF(lookupfn); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1222 return varvalue; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1223 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1224 handle_possible_keyerror: |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1225 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
|
1226 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
|
1227 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
|
1228 /* fall through */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1229 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1230 else { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1231 PyErr_Clear(); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1232 Py_XDECREF(lookupfn); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1233 return Py_NewRef(default_); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1234 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1235 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1236 /* fall through */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1237 error: |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1238 Py_XDECREF(lookupfn); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1239 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1240 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1241 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1242 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1243 static |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1244 PyObject * |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1245 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
|
1246 { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1247 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
|
1248 PyObject *path; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1249 PyObject *config; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1250 PyObject *namespace = NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1251 PyObject *default_ = NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1252 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1253 struct speedups_state *sstate; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1254 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1255 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
|
1256 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1257 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1258 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1259 sstate = PyModule_GetState(self); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1260 if (sstate == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1261 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
|
1262 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1263 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1264 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
|
1265 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1266 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1267 |
|
610
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1268 static |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1269 PyObject * |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1270 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
|
1271 { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1272 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
|
1273 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1274 PyObject *config; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1275 PyObject *path; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1276 PyObject *namespace = NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1277 PyObject *default_ = NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1278 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1279 PyObject *res = NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1280 PyObject *tmp; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1281 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1282 struct speedups_state *sstate; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1283 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1284 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
|
1285 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1286 return NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1287 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1288 sstate = PyModule_GetState(self); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1289 if (sstate == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1290 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
|
1291 return NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1292 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1293 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1294 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
|
1295 if (tmp == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1296 goto handle_possible_keyerror; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1297 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1298 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
|
1299 if (res == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1300 py_clear_ref(&tmp); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1301 goto handle_possible_keyerror; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1302 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1303 py_clear_ref(&tmp); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1304 return res; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1305 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1306 handle_possible_keyerror: |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1307 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
|
1308 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
|
1309 /* fall through */ |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1310 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1311 else { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1312 PyErr_Clear(); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1313 return Py_NewRef(default_); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1314 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1315 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1316 /* fall through */ |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1317 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1318 error: |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1319 return NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1320 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1321 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1322 |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1323 /** |
| 605 | 1324 * 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
|
1325 */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1326 static |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1327 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
|
1328 _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
|
1329 { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1330 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
|
1331 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
|
1332 PyObject *splitted = NULL; |
|
610
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1333 PyObject *res; |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1334 PyObject *tmp1; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1335 PyObject *tmp2; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1336 |
|
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
|
1337 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
|
1338 if (splitted == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1339 goto error; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1340 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1341 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
|
1342 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
|
1343 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1344 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
|
1345 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
|
1346 if (tmp1 == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1347 goto error; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1348 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1349 tmp2 = _fast_getvarl(config, tmp1, NULL, default_, sstate); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1350 if (tmp2 == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1351 py_clear_ref(&tmp1); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1352 goto handle_possible_keyerror; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1353 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1354 py_clear_ref(&tmp1); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1355 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
|
1356 if (res == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1357 py_clear_ref(&tmp2); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1358 goto handle_possible_keyerror; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1359 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1360 py_clear_ref(&tmp2); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1361 /* no namespace -> cacheable */ |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1362 *cacheable = 1; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1363 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1364 else { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1365 tmp1 = PyTuple_New(1); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1366 if (tmp1 == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1367 goto error; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1368 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1369 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
|
1370 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
|
1371 if (tmp2 == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1372 py_clear_ref(&tmp1); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1373 goto handle_possible_keyerror; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1374 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1375 py_clear_ref(&tmp1); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1376 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
|
1377 if (res == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1378 py_clear_ref(&tmp2); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1379 goto handle_possible_keyerror; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1380 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1381 py_clear_ref(&tmp2); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1382 /* 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
|
1383 *cacheable = 0; |
|
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 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1386 /* 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
|
1387 Py_DECREF(splitted); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1388 return res; |
|
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 handle_possible_keyerror: |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1391 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
|
1392 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
|
1393 /* fall through */ |
|
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 else { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1396 PyErr_Clear(); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1397 Py_XDECREF(splitted); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1398 return Py_NewRef(default_); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1399 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1400 } |
|
610
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1401 /* fall through */ |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1402 |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1403 error: |
|
610
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1404 Py_XDECREF(splitted); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1405 return NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1406 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1407 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1408 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1409 static |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1410 PyObject * |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1411 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
|
1412 { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1413 PyObject *config; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1414 PyObject *varname; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1415 PyObject *default_; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1416 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1417 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
|
1418 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
|
1419 PyObject *splitted = NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1420 PyObject *res; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1421 PyObject *tmp1; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1422 struct speedups_state *sstate; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1423 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1424 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
|
1425 return NULL; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1426 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1427 |
|
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
|
1428 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
|
1429 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
|
1430 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
|
1431 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
|
1432 } |
|
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
|
1433 |
|
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
|
1434 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
|
1435 if (splitted == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1436 goto error; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1437 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1438 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
|
1439 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
|
1440 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1441 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
|
1442 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
|
1443 if (tmp1 == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1444 goto error; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1445 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1446 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
|
1447 if (res == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1448 py_clear_ref(&tmp1); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1449 goto error; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1450 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1451 py_clear_ref(&tmp1); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1452 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1453 else { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1454 tmp1 = PyTuple_New(1); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1455 if (tmp1 == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1456 goto error; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1457 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1458 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
|
1459 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
|
1460 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
|
1461 if (tmp1 == NULL) { |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1462 goto error; |
|
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 py_clear_ref(&tmp1); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1465 goto error; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1466 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1467 py_clear_ref(&tmp1); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1468 } |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1469 Py_DECREF(splitted); |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1470 return res; |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1471 |
|
764d4185c76a
C-implementations of Configuration.getvarl_s() and Configuration.getvar()
Franz Glasner <fzglas.hg@dom66.de>
parents:
609
diff
changeset
|
1472 error: |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1473 Py_XDECREF(splitted); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1474 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1475 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1476 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1477 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1478 static |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1479 PyObject * |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1480 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
|
1481 { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1482 PyObject *config; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1483 PyObject *varname; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1484 PyObject *default_; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1485 int cacheable; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1486 struct speedups_state *sstate; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1487 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1488 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
|
1489 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1490 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1491 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1492 sstate = PyModule_GetState(self); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1493 if (sstate == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1494 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
|
1495 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1496 } |
|
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
|
1497 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
|
1498 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1499 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1500 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1501 static |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1502 PyObject * |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1503 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
|
1504 { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1505 struct speedups_state *sstate; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1506 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1507 sstate = PyModule_GetState(self); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1508 if (sstate == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1509 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
|
1510 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1511 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1512 if (sstate->MISSING != NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1513 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
|
1514 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1515 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1516 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
|
1517 Py_RETURN_NONE; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1518 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1519 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1520 |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1521 static |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1522 PyObject * |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1523 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
|
1524 { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1525 struct speedups_state *sstate; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1526 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1527 sstate = PyModule_GetState(self); |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1528 if (sstate == NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1529 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
|
1530 return NULL; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1531 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1532 if (sstate->MARKER != NULL) { |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1533 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
|
1534 return NULL; |
|
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 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
|
1537 Py_RETURN_NONE; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1538 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1539 |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1540 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1541 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
|
1542 {"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
|
1543 {"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
|
1544 {"fast_pathstr2path", fast_pathstr2path, METH_O, PyDoc_STR("C-implementation of configmix.pathstr2path")}, |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1545 {"_fast_split_filters", fast_split_filters, METH_O, 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
|
1546 {"_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
|
1547 {"_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
|
1548 {"_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
|
1549 {"_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
|
1550 {"_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
|
1551 {"_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
|
1552 {"_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
|
1553 {"_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
|
1554 {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
|
1555 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1556 |
|
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
|
1557 #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
|
1558 #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
|
1559 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1560 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1561 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1562 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1563 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
|
1564 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1565 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
|
1566 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1567 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
|
1568 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
|
1569 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
|
1570 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1571 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1572 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
|
1573 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
|
1574 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
|
1575 #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
|
1576 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
|
1577 #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
|
1578 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1579 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
|
1580 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
|
1581 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
|
1582 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1583 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
|
1584 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1585 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
|
1586 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
|
1587 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
|
1588 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1589 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
|
1590 |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1591 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
|
1592 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
|
1593 return -1; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1594 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1595 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
|
1596 |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1597 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
|
1598 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
|
1599 return -1; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1600 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1601 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
|
1602 |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1603 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
|
1604 if (sstate->EMPTY_FILTER == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1605 return -1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1606 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1607 PyUnicode_InternInPlace(&(sstate->EMPTY_FILTER)); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1608 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1609 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
|
1610 if (sstate->NONE_FILTER == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1611 return -1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1612 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1613 PyUnicode_InternInPlace(&(sstate->NONE_FILTER)); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1614 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1615 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
|
1616 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
|
1617 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
|
1618 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1619 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
|
1620 |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1621 sstate->QUOTE_MAP = Py_BuildValue( |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1622 "{IsIsIsIsIsIsIsIsIsIsIs}", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1623 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
|
1624 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
|
1625 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
|
1626 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
|
1627 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
|
1628 0x22, "%x22", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1629 0x27, "%x27", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1630 0x7b, "%x7b", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1631 0x7d, "%x7d", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1632 0x5b, "%x5b", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1633 0x5d, "%x5d"); |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1634 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
|
1635 return -1; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1636 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1637 |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1638 sstate->STARTTOK = PyUnicode_FromStringAndSize("{{", 2); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1639 if (sstate->STARTTOK == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1640 return -1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1641 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1642 PyUnicode_InternInPlace(&(sstate->STARTTOK)); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1643 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1644 sstate->ENDTOK = PyUnicode_FromStringAndSize("}}", 2); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1645 if (sstate->ENDTOK == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1646 return -1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1647 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1648 PyUnicode_InternInPlace(&(sstate->ENDTOK)); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1649 |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1650 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
|
1651 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
|
1652 return -1; |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1653 } |
|
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1654 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
|
1655 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1656 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
|
1657 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1658 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1659 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1660 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1661 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1662 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
|
1663 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1664 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
|
1665 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1666 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
|
1667 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
|
1668 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
|
1669 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
|
1670 Py_VISIT(sstate->FILTER_SEPARATOR); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1671 Py_VISIT(sstate->EMPTY_FILTER); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1672 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
|
1673 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
|
1674 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
|
1675 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
|
1676 Py_VISIT(sstate->MARKER); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1677 Py_VISIT(sstate->STARTTOK); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1678 Py_VISIT(sstate->ENDTOK); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1679 Py_VISIT(sstate->REF_NAMESPACE); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1680 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1681 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
|
1682 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1683 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1684 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1685 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1686 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1687 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
|
1688 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1689 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
|
1690 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1691 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
|
1692 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
|
1693 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
|
1694 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
|
1695 Py_CLEAR(sstate->FILTER_SEPARATOR); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1696 Py_CLEAR(sstate->EMPTY_FILTER); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1697 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
|
1698 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
|
1699 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
|
1700 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
|
1701 Py_CLEAR(sstate->MARKER); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1702 Py_CLEAR(sstate->STARTTOK); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1703 Py_CLEAR(sstate->ENDTOK); |
|
603
e55a42144ba9
C-implementations for Configuration.getvarl() and Configuration.getvar_s()
Franz Glasner <fzglas.hg@dom66.de>
parents:
602
diff
changeset
|
1704 Py_CLEAR(sstate->REF_NAMESPACE); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1705 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1706 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
|
1707 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1708 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1709 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1710 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
|
1711 {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
|
1712 {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
|
1713 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1714 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1715 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1716 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
|
1717 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
|
1718 "_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
|
1719 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
|
1720 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
|
1721 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
|
1722 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
|
1723 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
|
1724 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
|
1725 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
|
1726 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1727 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1728 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1729 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
|
1730 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
|
1731 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1732 /* |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1733 * 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
|
1734 * 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
|
1735 */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1736 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
|
1737 } |
