Mercurial > hgrepos > Python > libs > ConfigMix
annotate configmix/_speedups.c @ 564:44e18fbf7741
Refactor: signature of _convert_ucs4_to_utf8(): change order of args
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 06 Jan 2022 22:36:37 +0100 |
| parents | f75c5b13a1d7 |
| children | 5c617d870bb8 |
| 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 * |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
5 * :Copyright: (c) 2021, Franz Glasner. All rights reserved. |
|
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 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
15 const char _id[] = "@(#)configmix._speedups $Header$"; |
|
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 /* |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
21 * Module state holds pre-created some objects |
|
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; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
33 PyObject *STARTTOK; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
34 PyObject *ENDTOK; |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
35 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
36 |
|
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 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
39 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
40 _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
|
41 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
52 else { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
53 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
|
54 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
|
55 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
56 else { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
57 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
|
58 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
|
59 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
60 else { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
61 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
|
62 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
|
63 } |
|
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 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
66 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
67 *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
|
68 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
|
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 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
72 #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
|
73 |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
74 static |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
75 void |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
76 _raise_utf8_encode_error(PyObject *s, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
77 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
|
78 const char *reason) |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
79 { |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
80 /* |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
81 * 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
|
82 */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
83 PyObject *errobj = PyObject_CallFunction( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
84 PyExc_UnicodeEncodeError, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
85 "sOnns", |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
86 "utf-8", |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
87 s, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
88 start, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
89 end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
90 reason); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
91 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
92 if (errobj == NULL) { |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
93 /* cannot do anything here */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
94 return; |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
95 } |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
96 /* 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
|
97 //Py_INCREF(PyExc_UnicodeEncodeError); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
98 //PyErr_Restore(PyExc_UnicodeEncodeError, errobj, NULL); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
99 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
100 PyErr_SetObject(PyExc_UnicodeEncodeError, errobj); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
101 Py_DECREF(errobj); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
102 } |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
103 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
104 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
105 /* |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
106 * 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
|
107 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
108 * Disclaimer |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
109 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
110 * 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
|
111 * 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
|
112 * 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
|
113 * 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
|
114 * 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
|
115 * 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
|
116 * 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
|
117 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
118 * 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
|
119 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
120 * 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
|
121 * 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
|
122 * 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
|
123 * 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
|
124 * remains attached. |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
125 */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
126 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
127 #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
|
128 #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
|
129 #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
|
130 #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
|
131 #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
|
132 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
133 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
134 /* |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
135 * 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
|
136 * 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
|
137 * 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
|
138 * (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
|
139 * 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
|
140 */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
141 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
|
142 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
143 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
144 static |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
145 Py_ssize_t |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
146 _convert_ucs4_to_utf8( |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
147 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
|
148 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
|
149 int strict, |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
150 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
|
151 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
|
152 ) |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
153 { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
154 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
|
155 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
|
156 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
157 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
|
158 unsigned char *target = targetStart; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
159 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
160 if (strict) { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
161 /* 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
|
162 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
|
163 _raise_utf8_encode_error( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
164 ch_obj, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
165 1, ch_obj_end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
166 "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
|
167 return -1; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
168 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
169 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
170 /* |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
171 * Figure out how many bytes the result will require. Turn any |
| 556 | 172 * 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
|
173 */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
174 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
|
175 bytesToWrite = 1; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
176 } else if (ch < (Py_UCS4)0x800) { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
177 bytesToWrite = 2; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
178 } else if (ch < (Py_UCS4)0x10000) { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
179 bytesToWrite = 3; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
180 } else if (ch <= UNI_MAX_LEGAL_UTF32) { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
181 bytesToWrite = 4; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
182 } else { |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
183 _raise_utf8_encode_error( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
184 ch_obj, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
185 1, ch_obj_end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
186 "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
|
187 return -1; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
188 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
189 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
190 target += bytesToWrite; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
191 if (target > targetEnd) { |
|
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 "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
|
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 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
204 return bytesToWrite; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
205 } |
|
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 |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
208 /* |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
209 * 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
|
210 */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
211 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
212 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
213 static |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
214 PyObject * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
215 _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
|
216 { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
217 Py_UCS4 c; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
218 unsigned char buf[6]; |
|
555
b7434a34a1f4
- FIX: Memory-leak with the "filters" local variable
Franz Glasner <fzglas.hg@dom66.de>
parents:
554
diff
changeset
|
219 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
|
220 PyObject *u; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
221 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
222 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
|
223 return NULL; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
224 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
225 /* 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
|
226 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
|
227 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
|
228 return NULL; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
229 } |
|
555
b7434a34a1f4
- FIX: Memory-leak with the "filters" local variable
Franz Glasner <fzglas.hg@dom66.de>
parents:
554
diff
changeset
|
230 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
|
231 if (u == NULL) { |
|
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 return u; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
235 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
236 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
237 #else |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
238 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
239 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
240 PyObject * |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
241 _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
|
242 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
243 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
|
244 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
|
245 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
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 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
|
256 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
257 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
258 #endif /* Py_LIMITED_API */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
259 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
260 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
261 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
262 PyObject * |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
263 _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
|
264 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
276 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
|
277 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
|
278 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
|
279 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
280 } |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
281 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
282 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
|
283 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
|
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 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
|
286 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
|
287 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
|
288 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
289 if (find == -1) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
290 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
|
291 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
292 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
299 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
300 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
|
301 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
|
302 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
|
303 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
304 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
|
305 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
|
306 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
|
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 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
|
309 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
|
310 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
|
311 } |
|
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 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
|
314 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
|
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 /* |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
318 * 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
|
319 * 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
|
320 */ |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
321 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
|
322 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
337 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
|
338 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
|
339 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
|
340 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
341 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
|
342 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
|
343 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
|
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 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
|
347 break; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 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
|
352 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
353 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
|
354 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
|
355 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
|
356 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
357 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
|
358 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
|
359 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
|
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 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
|
363 break; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
364 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
|
365 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
|
366 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
|
367 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
|
368 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
369 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
|
370 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
|
371 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
|
372 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
373 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
|
374 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
|
375 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
|
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 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
|
379 break; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
380 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
381 default: |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
382 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
|
383 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
|
384 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
385 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
386 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
387 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
|
388 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
|
389 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
390 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
391 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
|
392 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
|
393 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
|
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 error: |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
396 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
|
397 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
|
398 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
|
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 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
401 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
402 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
403 PyObject * |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
404 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
|
405 { |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
406 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
|
407 } |
|
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 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
411 PyObject * |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
412 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
|
413 { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
414 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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
420 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
|
421 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
|
422 return NULL; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
423 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
424 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
|
425 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
|
426 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
427 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
|
428 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
|
429 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
|
430 switch (c) { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
431 case 0x25: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
432 case 0x2e: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
433 case 0x3a: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
434 case 0x23: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
435 case 0x7c: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
436 case 0x22: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
437 case 0x27: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
438 case 0x7b: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
439 case 0x7d: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
440 case 0x5b: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
441 case 0x5d: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
442 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
|
443 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
|
444 break; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
445 default: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
446 /* VOID */ |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
447 ; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
448 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
449 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
450 if (!need_quoting) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
451 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
|
452 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
453 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
|
454 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
|
455 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
|
456 return NULL; |
|
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 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
|
459 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
460 |
|
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 static |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
463 PyObject * |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
464 fast_pathstr2path(PyObject *self, PyObject *varname) |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
465 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
466 Py_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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 struct speedups_state *sstate; |
|
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 if (!PyUnicode_Check(varname)) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
476 PyErr_SetString(PyExc_TypeError, "a (unicode) string type is expected"); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
477 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
|
478 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
479 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
|
480 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
|
481 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
|
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 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
|
484 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
|
485 } |
|
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 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
|
488 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
|
489 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
|
490 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
|
491 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
492 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
|
493 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
|
494 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
|
495 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
496 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
|
497 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
|
498 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
|
499 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
500 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
|
501 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
|
502 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
|
503 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
504 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
|
505 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
|
506 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
|
507 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
|
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 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
|
511 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
512 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
513 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
|
514 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
|
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 error: |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
517 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
|
518 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
|
519 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
|
520 } |
|
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 |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
523 static |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
524 PyObject * |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
525 _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
|
526 { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
527 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
|
528 Py_ssize_t sep; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
529 PyObject *res = NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
530 PyObject *filters = NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
531 PyObject *name = NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
532 PyObject *tmp; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
533 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
534 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
|
535 if (varname_len < 0) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
536 return NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
537 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
538 if (varname_len == 0) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
539 sep = -1; |
|
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 else { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
542 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
|
543 if (sep == -2) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
544 return NULL; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
545 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
546 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
547 if (sep == -1) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
548 res = PyTuple_New(2); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
549 if (res == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
550 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
551 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
552 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
|
553 filters = PyList_New(0); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
554 if (filters == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
555 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
556 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
557 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
|
558 return res; |
|
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 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
|
561 if (name == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
562 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
563 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
564 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
565 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
|
566 if (filters == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
567 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
568 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
569 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
|
570 if (tmp == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
571 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
572 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
573 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
|
574 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
575 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
|
576 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
|
577 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
578 res = PyTuple_New(2); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
579 if (res == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
580 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
581 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
582 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
|
583 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
|
584 filters = PyList_New(0); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
585 if (filters == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
586 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
587 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
588 PyTuple_SetItem(res, 1, filters); /* steals */ |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
589 filters = NULL; |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
590 return res; |
|
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 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
593 if (sstate == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
594 sstate = PyModule_GetState(self); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
595 if (sstate == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
596 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
|
597 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
598 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
599 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
600 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
601 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
|
602 if (tmp == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
603 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
604 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
605 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
|
606 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
607 res = PyTuple_New(2); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
608 if (res == NULL) { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
609 goto error; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
610 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
611 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
|
612 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
|
613 return res; |
|
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 error: |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
616 Py_XDECREF(res); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
617 Py_XDECREF(filters); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
618 Py_XDECREF(name); |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
619 return NULL; |
|
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 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
622 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
623 static |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
624 PyObject * |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
625 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
|
626 { |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
627 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
|
628 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
629 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
630 |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
631 static |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
632 PyObject * |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
633 fast_split_ns(PyObject *self, PyObject *varname) |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
634 { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
635 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
|
636 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
|
637 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
|
638 PyObject *o1; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
639 PyObject *o2; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
640 |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
641 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
|
642 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
|
643 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
644 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
645 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
|
646 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
|
647 return NULL; |
|
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 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
|
650 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
|
651 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
|
652 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
653 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
654 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
|
655 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
|
656 return res; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
657 } |
|
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 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
|
660 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
|
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 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
|
664 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
|
665 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
|
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 } |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
668 o2 = _fast_unquote(o1, ns_idx, self, NULL); |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
669 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
|
670 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
|
671 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
|
672 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
673 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
674 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
|
675 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
|
676 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
|
677 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
|
678 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
|
679 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
680 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
681 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
|
682 return res; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
683 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
684 |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
685 |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
686 static |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
687 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
|
688 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
|
689 { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
690 PyObject *config; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
691 PyObject *s; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
692 PyObject *cache; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
693 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
694 Py_ssize_t s_len; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
695 Py_ssize_t idx; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
696 Py_ssize_t i, j; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
697 PyObject *parts = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
698 Py_ssize_t parts_len; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
699 PyObject *res_parts = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
700 PyObject *res = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
701 PyObject *tmp; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
702 PyObject *tmp2; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
703 PyObject *pb; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
704 Py_ssize_t pb_len; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
705 PyObject *varname = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
706 PyObject *varvalue = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
707 PyObject *filters = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
708 int cacheable; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
709 int use_cache = 1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
710 int first_part_is_empty; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
711 PyObject *err_type; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
712 PyObject *err_value; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
713 PyObject *err_tb; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
714 struct speedups_state *sstate; |
|
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 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
|
717 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
718 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
719 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
|
720 if (s_len < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
721 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
722 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
723 if (s_len < 4) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
724 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
725 return Py_NewRef(s); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
726 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
727 sstate = PyModule_GetState(self); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
728 if (sstate == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
729 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
|
730 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
731 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
732 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
733 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
|
734 if (idx < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
735 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
736 return Py_NewRef(s); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
737 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
738 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
739 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
|
740 if (res != NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
741 if (res == sstate->MISSING) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
742 return PyErr_Format( |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
743 PyExc_KeyError, |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
744 "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
|
745 s); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
746 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
747 else { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
748 return Py_NewRef(res); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
749 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
750 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
751 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
752 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
|
753 if (parts == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
754 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
755 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
756 parts_len = PyList_Size(parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
757 if (parts_len < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
758 goto error; |
|
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_parts = PyList_New(1); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
761 if (res_parts == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
762 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
763 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
764 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
765 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
|
766 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
767 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
768 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
769 /* |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
770 * 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
|
771 * an interpolation token. |
|
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 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
|
774 /* 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
|
775 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
|
776 tmp = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
777 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
778 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
|
779 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
|
780 pb_len = PyUnicode_GetLength(pb); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
781 if (pb_len < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
782 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
783 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
784 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
|
785 if (idx < 0) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
786 /* |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
787 * 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
|
788 * 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
|
789 */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
790 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
|
791 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
792 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
793 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
|
794 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
795 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
796 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
|
797 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
|
798 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
799 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
800 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
|
801 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
|
802 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
803 } |
|
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 break; /* the for-loop */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
806 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
807 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
808 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
|
809 if (varname == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
810 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
811 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
812 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
813 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
|
814 if (tmp == NULL) { |
|
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 if (PyTuple_Size(tmp) != 2) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
818 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
|
819 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
820 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
821 } |
| 562 | 822 py_clear_ref(&varname); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
823 /* Unpack the result tuple */ |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
824 /* borrowed -- cannot fail -- need ownership */ |
|
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
825 varname = Py_NewRef(PyTuple_GetItem(tmp, 0)); |
|
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
826 /* 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
|
827 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
|
828 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
829 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
830 tmp = PyObject_CallMethod( |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
831 config, "_getvar_s_with_cache_info", "O", varname); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
832 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
833 if (PyErr_ExceptionMatches(PyExc_KeyError)) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
834 cacheable = 1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
835 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
|
836 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
837 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
|
838 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
839 else { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
840 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
|
841 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
842 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
|
843 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
844 else { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
845 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
|
846 /* this does NOT steal */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
847 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
|
848 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
|
849 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
850 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
851 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
852 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
853 else { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
854 /* other exception/error than KeyError */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
855 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
856 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
857 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
858 else { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
859 if (PyTuple_Size(tmp) != 2) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
860 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
861 PyErr_SetString(PyExc_TypeError, "tuple of size 2 expected"); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
862 goto error; |
|
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 /* unpack the result */ |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
865 /* borrowed -- cannot fail -- but want ownership */ |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
866 varvalue = Py_NewRef(PyTuple_GetItem(tmp, 0)); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
867 cacheable = PyObject_IsTrue(PyTuple_GetItem(tmp, 1)); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
868 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
869 } |
|
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 if (!cacheable) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
872 use_cache = 0; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
873 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
874 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
875 py_clear_ref(&varname); |
|
554
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 tmp = PyObject_CallMethod( |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
878 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
|
879 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
880 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
881 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
882 py_clear_ref(&varvalue); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
883 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
884 py_clear_ref(&filters); |
|
555
b7434a34a1f4
- FIX: Memory-leak with the "filters" local variable
Franz Glasner <fzglas.hg@dom66.de>
parents:
554
diff
changeset
|
885 |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
886 /* |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
887 * 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
|
888 * 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
|
889 */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
890 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
|
891 res = varvalue; varvalue = NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
892 goto success; /* break out early */ |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
893 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
894 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
|
895 tmp = PyObject_Str(varvalue); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
896 if (tmp == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
897 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
898 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
899 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
|
900 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
901 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
902 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
903 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
904 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
905 py_clear_ref(&varvalue); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
906 /* 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
|
907 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
|
908 if (tmp == NULL) { |
|
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 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
911 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
|
912 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
913 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
914 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
915 py_clear_ref(&tmp); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
916 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
917 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
918 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
|
919 if (res == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
920 goto error; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
921 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
922 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
923 success: |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
924 Py_DECREF(parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
925 Py_DECREF(res_parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
926 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
927 if (use_cache) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
928 PyDict_SetItem(cache, s, res); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
929 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
|
930 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
931 return res; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
932 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
933 error: |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
934 Py_XDECREF(varname); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
935 Py_XDECREF(varvalue); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
936 Py_XDECREF(filters); |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
937 Py_XDECREF(parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
938 Py_XDECREF(res_parts); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
939 Py_XDECREF(res); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
940 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
941 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
942 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
943 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
944 static |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
945 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
|
946 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
|
947 { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
948 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
|
949 PyObject *s; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
950 PyObject *cache; |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
951 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
952 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
|
953 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
|
954 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
|
955 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
|
956 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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 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
|
962 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
|
963 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
|
964 |
|
7a3c311991d7
An alternate C-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 if (!PyArg_UnpackTuple(args, "s", 3, 3, &config, &s, &cache)) { |
|
7a3c311991d7
An alternate C-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 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
|
967 } |
|
7a3c311991d7
An alternate C-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 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
|
969 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
|
970 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
|
971 } |
|
7a3c311991d7
An alternate C-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 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
|
973 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
|
974 } |
|
7a3c311991d7
An alternate C-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 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
976 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
|
977 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
|
978 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
|
979 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
|
980 } |
|
7a3c311991d7
An alternate C-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 |
|
7a3c311991d7
An alternate C-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 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
|
983 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
|
984 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
|
985 } |
|
7a3c311991d7
An alternate C-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 if (start == -1) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
987 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
|
988 } |
|
7a3c311991d7
An alternate C-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 |
|
7a3c311991d7
An alternate C-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 result = PyDict_GetItem(cache, s); /* borrowed */ |
|
7a3c311991d7
An alternate C-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 if (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
|
992 if (result == sstate->MISSING) { |
|
7a3c311991d7
An alternate C-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 return PyErr_Format( |
|
7a3c311991d7
An alternate C-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 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
|
995 "Cannot interpolate variables in string %R (cached)", |
|
7a3c311991d7
An alternate C-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 s); |
|
7a3c311991d7
An alternate C-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 else { |
|
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(result); |
|
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 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1002 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1003 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
|
1004 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
|
1005 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
|
1006 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1007 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1008 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
|
1009 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
|
1010 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1011 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
|
1012 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
|
1013 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
|
1014 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
|
1015 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
|
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 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
|
1018 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
|
1019 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
|
1020 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1021 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
|
1022 } |
|
7a3c311991d7
An alternate C-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 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
|
1024 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
|
1025 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
|
1026 } |
|
7a3c311991d7
An alternate C-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 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
|
1028 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
|
1029 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
|
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 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1032 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
|
1033 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
|
1034 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
|
1035 } |
|
7a3c311991d7
An alternate C-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 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
|
1038 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
|
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 (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
|
1042 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
|
1043 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
|
1044 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
|
1045 } |
| 562 | 1046 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
|
1047 /* Unpack the result tuple */ |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1048 /* borrowed -- cannot fail -- need ownership */ |
|
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1049 varname = Py_NewRef(PyTuple_GetItem(tmp, 0)); |
|
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1050 /* 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
|
1051 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
|
1052 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
|
1053 |
|
7a3c311991d7
An alternate C-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 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
|
1055 config, "_getvar_s_with_cache_info", "O", 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
|
1056 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
|
1057 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
|
1058 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
|
1059 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
|
1060 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1061 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
|
1062 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1063 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
|
1064 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
|
1065 PyErr_Clear(); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1066 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
|
1067 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1068 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
|
1069 PyErr_Fetch(&err_type, &err_value, &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
|
1070 /* this does NOT steal */ |
|
7a3c311991d7
An alternate C-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 PyDict_SetItem(cache, s, sstate->MISSING); |
|
7a3c311991d7
An alternate C-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 PyErr_Restore(err_type, err_value, 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
|
1073 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
|
1074 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1075 } |
|
7a3c311991d7
An alternate C-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 /* 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
|
1079 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
|
1080 } |
|
7a3c311991d7
An alternate C-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 { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1083 if (PyTuple_Size(tmp) != 2) { |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1084 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
|
1085 PyErr_SetString(PyExc_TypeError, "tuple of size 2 expected"); |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1086 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
|
1087 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1088 /* unpack the result */ |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1089 /* borrowed -- but want own */ |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1090 varvalue = Py_NewRef(PyTuple_GetItem(tmp, 0)); |
|
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
|
1091 cacheable = PyObject_IsTrue(PyTuple_GetItem(tmp, 1)); |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1092 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
|
1093 } |
|
7a3c311991d7
An alternate C-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 |
|
7a3c311991d7
An alternate C-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 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
|
1096 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
|
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 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1099 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
|
1100 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1101 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
|
1102 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
|
1103 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
|
1104 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
|
1105 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1106 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
|
1107 |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1108 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
|
1109 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1110 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
|
1111 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1112 /* |
|
7a3c311991d7
An alternate C-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 * 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
|
1114 * 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
|
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 if ((start == 0) && (rest == s_len)) { |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1117 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
|
1118 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
|
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 |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1121 /* 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
|
1122 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
|
1123 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
|
1124 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
|
1125 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
|
1126 } |
|
7a3c311991d7
An alternate C-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 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
|
1128 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
|
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 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1131 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
|
1132 } |
|
7a3c311991d7
An alternate C-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 |
|
7a3c311991d7
An alternate C-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 /* 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
|
1135 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
|
1136 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
|
1137 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
|
1138 } |
|
7a3c311991d7
An alternate C-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 } |
|
7a3c311991d7
An alternate C-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 |
|
7a3c311991d7
An alternate C-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 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
|
1142 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
|
1143 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
|
1144 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
|
1145 } |
|
7a3c311991d7
An alternate C-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 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
|
1147 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
|
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 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1150 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
|
1151 } |
|
7a3c311991d7
An alternate C-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 |
|
7a3c311991d7
An alternate C-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 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
|
1154 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
|
1155 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
|
1156 } |
|
560
81238ea2dbe3
Implement and use more helper functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
559
diff
changeset
|
1157 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
|
1158 |
|
7a3c311991d7
An alternate C-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 success: |
|
7a3c311991d7
An alternate C-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 if (use_cache) { |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1161 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
|
1162 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
|
1163 } |
|
7a3c311991d7
An alternate C-implementation of fast_interpolate_variables() that uses the algorithm of the pure-Python implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
557
diff
changeset
|
1164 } |
|
7a3c311991d7
An alternate C-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 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
|
1166 |
|
7a3c311991d7
An alternate C-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 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
|
1168 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
|
1169 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
|
1170 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
|
1171 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
|
1172 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
|
1173 } |
|
7a3c311991d7
An alternate C-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 |
|
7a3c311991d7
An alternate C-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 |
|
7a3c311991d7
An alternate C-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 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
|
1177 PyObject * |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1178 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
|
1179 { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1180 struct speedups_state *sstate; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1181 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1182 sstate = PyModule_GetState(self); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1183 if (sstate == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1184 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
|
1185 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1186 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1187 if (sstate->MISSING != NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1188 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
|
1189 return NULL; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1190 } |
|
559
bb160a1e67d7
A simple helper include file with some conveniente functions.
Franz Glasner <fzglas.hg@dom66.de>
parents:
558
diff
changeset
|
1191 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
|
1192 Py_RETURN_NONE; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1193 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1194 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1195 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1196 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
|
1197 {"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
|
1198 {"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
|
1199 {"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
|
1200 {"_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
|
1201 {"_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
|
1202 {"_fast_interpolate_variables", fast_interpolate_variables, METH_VARARGS, PyDoc_STR("C-implementation of configmix.config.Configuration.interpolate_variables")}, |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1203 {"_sync_MISSING", sync_MISSING, METH_O, PyDoc_STR("Internal function to easily sync the _MISSING object with configmix.config")}, |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1204 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1205 {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
|
1206 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1207 |
|
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
|
1208 #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
|
1209 #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
|
1210 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1211 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1212 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1213 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1214 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
|
1215 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1216 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
|
1217 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1218 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
|
1219 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
|
1220 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
|
1221 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1222 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1223 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
|
1224 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
|
1225 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
|
1226 #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
|
1227 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
|
1228 #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
|
1229 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1230 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
|
1231 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
|
1232 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
|
1233 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1234 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
|
1235 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1236 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
|
1237 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
|
1238 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
|
1239 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1240 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
|
1241 |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1242 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
|
1243 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
|
1244 return -1; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1245 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
1246 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
|
1247 |
|
552
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1248 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
|
1249 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
|
1250 return -1; |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1251 } |
|
39e5d07d8dbc
Provide a C implementation of configmix.config._split_filters.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
1252 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
|
1253 |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1254 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
|
1255 if (sstate->EMPTY_FILTER == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1256 return -1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1257 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1258 PyUnicode_InternInPlace(&(sstate->EMPTY_FILTER)); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1259 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1260 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
|
1261 if (sstate->NONE_FILTER == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1262 return -1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1263 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1264 PyUnicode_InternInPlace(&(sstate->NONE_FILTER)); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1265 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1266 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
|
1267 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
|
1268 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
|
1269 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1270 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
|
1271 |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1272 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
|
1273 "{IsIsIsIsIsIsIsIsIsIsIs}", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1274 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
|
1275 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
|
1276 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
|
1277 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
|
1278 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
|
1279 0x22, "%x22", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1280 0x27, "%x27", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1281 0x7b, "%x7b", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1282 0x7d, "%x7d", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1283 0x5b, "%x5b", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1284 0x5d, "%x5d"); |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1285 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
|
1286 return -1; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1287 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
1288 |
|
554
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1289 sstate->STARTTOK = PyUnicode_FromStringAndSize("{{", 2); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1290 if (sstate->STARTTOK == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1291 return -1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1292 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1293 PyUnicode_InternInPlace(&(sstate->STARTTOK)); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1294 |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1295 sstate->ENDTOK = PyUnicode_FromStringAndSize("}}", 2); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1296 if (sstate->ENDTOK == NULL) { |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1297 return -1; |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1298 } |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1299 PyUnicode_InternInPlace(&(sstate->ENDTOK)); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1300 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1301 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
|
1302 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1303 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1304 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1305 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1306 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1307 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
|
1308 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1309 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
|
1310 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1311 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
|
1312 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
|
1313 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
|
1314 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
|
1315 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
|
1316 Py_VISIT(sstate->EMPTY_FILTER); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1317 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
|
1318 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
|
1319 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
|
1320 Py_VISIT(sstate->MISSING); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1321 Py_VISIT(sstate->STARTTOK); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1322 Py_VISIT(sstate->ENDTOK); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1323 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1324 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
|
1325 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1326 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1327 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1328 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1329 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1330 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
|
1331 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1332 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
|
1333 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1334 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
|
1335 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
|
1336 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
|
1337 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
|
1338 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
|
1339 Py_CLEAR(sstate->EMPTY_FILTER); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1340 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
|
1341 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
|
1342 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
|
1343 Py_CLEAR(sstate->MISSING); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1344 Py_CLEAR(sstate->STARTTOK); |
|
36d7aa000435
Implement a C-version of Configuration.interpolate_variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
553
diff
changeset
|
1345 Py_CLEAR(sstate->ENDTOK); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1346 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1347 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
|
1348 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1349 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1350 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1351 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
|
1352 {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
|
1353 {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
|
1354 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1355 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1356 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1357 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
|
1358 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
|
1359 "_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
|
1360 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
|
1361 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
|
1362 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
|
1363 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
|
1364 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
|
1365 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
|
1366 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
|
1367 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1368 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1369 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1370 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
|
1371 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
|
1372 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1373 /* |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1374 * 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
|
1375 * 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
|
1376 */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1377 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
|
1378 } |
