Mercurial > hgrepos > Python > libs > ConfigMix
annotate configmix/_speedups.c @ 550:79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 02 Jan 2022 02:04:07 +0100 |
| parents | 84657447ab39 |
| children | 39e5d07d8dbc |
| 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 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
12 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
13 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
|
14 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
|
15 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
|
16 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
17 |
|
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 * 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
|
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 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
|
22 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
|
23 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
|
24 PyObject *NS_SEPARATOR; |
|
542
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 *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
|
26 PyObject *QUOTE_MAP; |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
27 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
28 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
29 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
30 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
31 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
32 _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
|
33 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
34 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
|
35 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
|
36 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
|
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 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
44 else { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
45 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
|
46 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
|
47 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
48 else { |
|
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 >= 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
|
50 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
|
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 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
|
54 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
|
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 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
57 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
58 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
59 *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
|
60 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
|
61 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
62 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
63 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
64 #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
|
65 |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
66 static |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
67 void |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
68 _raise_utf8_encode_error(PyObject *s, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
69 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
|
70 const char *reason) |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
71 { |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
72 /* |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
73 * 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
|
74 */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
75 PyObject *errobj = PyObject_CallFunction( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
76 PyExc_UnicodeEncodeError, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
77 "sOnns", |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
78 "utf-8", |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
79 s, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
80 start, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
81 end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
82 reason); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
83 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
84 if (errobj == NULL) { |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
85 /* cannot do anything here */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
86 return; |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
87 } |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
88 /* 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
|
89 //Py_INCREF(PyExc_UnicodeEncodeError); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
90 //PyErr_Restore(PyExc_UnicodeEncodeError, errobj, NULL); |
|
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 PyErr_SetObject(PyExc_UnicodeEncodeError, errobj); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
93 Py_DECREF(errobj); |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
94 } |
|
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 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
97 /* |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
98 * 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
|
99 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
100 * Disclaimer |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
101 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
102 * 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
|
103 * 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
|
104 * 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
|
105 * 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
|
106 * 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
|
107 * 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
|
108 * 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
|
109 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
110 * 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
|
111 * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
112 * 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
|
113 * 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
|
114 * 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
|
115 * 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
|
116 * remains attached. |
|
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 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
119 #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
|
120 #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
|
121 #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
|
122 #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
|
123 #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
|
124 |
|
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 * 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
|
128 * 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
|
129 * 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
|
130 * (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
|
131 * 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
|
132 */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
133 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
|
134 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
135 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
136 static |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
137 Py_ssize_t |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
138 _convert_ucs4_to_utf8( |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
139 Py_UCS4 ch, |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
140 PyObject *ch_obj, /* for error messages: the string where ch comes from */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
141 Py_ssize_t ch_obj_end, /* effective length of ch_obj (error reporting) */ |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
142 unsigned char *targetStart, unsigned char *targetEnd, |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
143 int strict) |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
144 { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
145 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
|
146 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
|
147 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
148 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
|
149 unsigned char *target = targetStart; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
150 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
151 if (strict) { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
152 /* 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
|
153 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
|
154 _raise_utf8_encode_error( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
155 ch_obj, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
156 1, ch_obj_end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
157 "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
|
158 return -1; |
|
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 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
161 /* |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
162 * Figure out how many bytes the result will require. Turn any |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
163 * illegally large UTF32 things (> Plane 17) into replacement chars. |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
164 */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
165 if (ch < (Py_UCS4)0x80) { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
166 bytesToWrite = 1; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
167 } 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
|
168 bytesToWrite = 2; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
169 } 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
|
170 bytesToWrite = 3; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
171 } 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
|
172 bytesToWrite = 4; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
173 } else { |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
174 _raise_utf8_encode_error( |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
175 ch_obj, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
176 1, ch_obj_end, |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
177 "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
|
178 return -1; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
179 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
180 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
181 target += bytesToWrite; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
182 if (target > targetEnd) { |
|
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 "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
|
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 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
195 return bytesToWrite; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
196 } |
|
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 |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
199 /* |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
200 * 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
|
201 */ |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
202 |
|
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
203 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
204 static |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
205 PyObject * |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
206 _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
|
207 { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
208 Py_UCS4 c; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
209 unsigned char buf[6]; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
210 Py_ssize_t buf_bytes; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
211 PyObject *u; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
212 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
213 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
|
214 return NULL; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
215 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
216 /* Replace the combination PyUniode_New/PyUnicode_WriteChar */ |
|
549
84657447ab39
FIX: Properly raise a UnicodeEncodeError from C
Franz Glasner <fzglas.hg@dom66.de>
parents:
547
diff
changeset
|
217 buf_bytes = _convert_ucs4_to_utf8(c, s, end+1, buf, &(buf[6]), 1); |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
218 if (buf_bytes < 0) { |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
219 return NULL; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
220 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
221 u = PyUnicode_FromStringAndSize((const char *)buf, buf_bytes); |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
222 if (u == NULL) { |
|
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 return u; |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
226 } |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
227 |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
228 #else |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
229 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
230 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
231 PyObject * |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
232 _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
|
233 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
234 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
|
235 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
|
236 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
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 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
|
247 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
248 |
|
545
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
249 #endif /* Py_LIMITED_API */ |
|
6501fe0e116c
Build the speedup C-extension against the stable API.
Franz Glasner <fzglas.hg@dom66.de>
parents:
544
diff
changeset
|
250 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
251 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
252 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
253 PyObject * |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
254 _fast_unquote(PyObject *self, PyObject *s, Py_ssize_t s_len, 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
|
255 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
267 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
|
268 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
|
269 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
|
270 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
271 } |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
272 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
273 if (s_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
|
274 Py_INCREF(s); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
275 return s; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
276 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
281 if (find == -1) { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
282 Py_INCREF(s); |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
283 return s; |
|
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 |
|
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 (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
|
287 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
|
288 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
|
289 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
|
290 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
|
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 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
|
294 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
|
295 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
|
296 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
297 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
|
298 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
|
299 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
|
300 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
301 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
|
302 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
|
303 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
|
304 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
305 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
310 /* |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
311 * 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
|
312 * 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
|
313 */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
314 Py_INCREF(o); /* because PyTuple_SetItem steals -- and o is borrowed */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
315 PyTuple_SetItem(res_parts, 0, o); |
|
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 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
331 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
|
332 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
|
333 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
|
334 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
335 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
|
336 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
|
337 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
|
338 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
|
339 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
340 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
|
341 break; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 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
|
346 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
347 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
|
348 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
|
349 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
|
350 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
351 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
|
352 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
|
353 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
|
354 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
|
355 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
356 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
|
357 break; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
358 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
|
359 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
|
360 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
|
361 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
|
362 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
367 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
|
368 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
|
369 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
|
370 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
|
371 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
372 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
|
373 break; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
374 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
375 default: |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
376 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
|
377 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
|
378 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
379 } |
|
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 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
|
382 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
|
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 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
|
386 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
|
387 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
|
388 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
389 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 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
|
391 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
|
392 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
|
393 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
394 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
395 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
396 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
397 PyObject * |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
398 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
|
399 { |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
400 return _fast_unquote(self, s, -1, 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
|
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 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
403 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
404 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
405 PyObject * |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
406 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
|
407 { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
408 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
|
409 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
|
410 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
|
411 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
|
412 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
|
413 |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
414 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
|
415 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
|
416 return NULL; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
417 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
418 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
|
419 Py_INCREF(s); |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
420 return s; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
421 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
422 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
|
423 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
|
424 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
|
425 switch (c) { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
426 case 0x25: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
427 case 0x2e: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
428 case 0x3a: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
429 case 0x23: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
430 case 0x7c: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
431 case 0x22: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
432 case 0x27: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
433 case 0x7b: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
434 case 0x7d: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
435 case 0x5b: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
436 case 0x5d: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
437 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
|
438 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
|
439 break; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
440 default: |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
441 /* VOID */ |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
442 ; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
443 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
444 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
445 if (!need_quoting) { |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
446 Py_INCREF(s); |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
447 return s; |
|
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 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
|
450 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
|
451 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
|
452 return NULL; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
453 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
454 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
|
455 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
456 |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
457 |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
458 static |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
459 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
|
460 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
|
461 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
462 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
|
463 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
|
464 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
|
465 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
|
466 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
|
467 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
|
468 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
|
469 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
|
470 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
471 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
|
472 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
|
473 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
|
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 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
|
476 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
|
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 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
|
480 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
|
481 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
482 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
483 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
|
484 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
|
485 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
|
486 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
|
487 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
488 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
|
489 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
|
490 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
|
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_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
|
493 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
|
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 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
|
497 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
|
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 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
|
501 o = PyList_GetItem(parts, i); /* borrowed */ |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
502 u = _fast_unquote(self, o, -1, 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
|
503 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
|
504 goto error; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
505 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
506 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
|
507 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
508 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
509 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
|
510 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
|
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 error: |
|
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_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
|
514 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
|
515 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
|
516 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
517 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
518 |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
519 static |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
520 PyObject * |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
521 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
|
522 { |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
523 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
|
524 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
|
525 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
|
526 PyObject *o1; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
527 PyObject *o2; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
528 |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
529 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
|
530 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
|
531 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
532 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
533 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
|
534 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
|
535 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
536 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
537 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
|
538 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
|
539 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
|
540 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
541 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
542 Py_INCREF(Py_None); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
543 PyTuple_SetItem(res, 0, Py_None); /* steals */ |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
544 Py_INCREF(varname); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
545 PyTuple_SetItem(res, 1, varname); /* steals */ |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
546 return res; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
547 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
548 |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
549 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
|
550 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
|
551 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
552 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
553 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
|
554 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
|
555 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
|
556 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
557 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
558 o2 = _fast_unquote(self, o1, ns_idx, NULL); |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
559 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
|
560 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
|
561 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
|
562 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
563 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
564 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
|
565 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
|
566 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
|
567 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
|
568 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
|
569 return NULL; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
570 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
571 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
|
572 return res; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
573 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
574 |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
575 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
576 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
|
577 {"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
|
578 {"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
|
579 {"fast_pathstr2path", fast_pathstr2path, METH_O, PyDoc_STR("C-implementation of configmix.pathstr2path")}, |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
580 {"_fast_split_ns", fast_split_ns, METH_O, PyDoc_STR("C-implementation of configmix.config._split_ns")}, |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
581 {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
|
582 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
583 |
|
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
|
584 #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
|
585 #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
|
586 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
587 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
588 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
589 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
590 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
|
591 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
592 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
|
593 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
594 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
|
595 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
|
596 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
|
597 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
598 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
599 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
|
600 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
|
601 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
|
602 #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
|
603 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
|
604 #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
|
605 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
606 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
|
607 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
|
608 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
|
609 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
610 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
|
611 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
612 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
|
613 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
|
614 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
|
615 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
616 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
|
617 |
|
543
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
618 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
|
619 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
|
620 return -1; |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
621 } |
|
491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
Franz Glasner <fzglas.hg@dom66.de>
parents:
542
diff
changeset
|
622 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
|
623 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
624 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
|
625 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
|
626 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
|
627 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
628 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
|
629 |
|
550
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
630 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
|
631 "{IsIsIsIsIsIsIsIsIsIsIs}", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
632 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
|
633 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
|
634 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
|
635 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
|
636 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
|
637 0x22, "%x22", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
638 0x27, "%x27", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
639 0x7b, "%x7b", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
640 0x7d, "%x7d", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
641 0x5b, "%x5b", |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
642 0x5d, "%x5d"); |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
643 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
|
644 return -1; |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
645 } |
|
79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
Franz Glasner <fzglas.hg@dom66.de>
parents:
549
diff
changeset
|
646 |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
647 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
|
648 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
649 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
650 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
651 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
652 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
653 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
|
654 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
655 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
|
656 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
657 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
|
658 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
|
659 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
|
660 Py_VISIT(sstate->NS_SEPARATOR); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
661 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
|
662 Py_VISIT(sstate->QUOTE_MAP); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
663 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
664 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
|
665 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
666 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
667 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
668 static |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
669 int |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
670 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
|
671 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
672 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
|
673 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
674 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
|
675 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
|
676 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
|
677 Py_CLEAR(sstate->NS_SEPARATOR); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
678 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
|
679 Py_CLEAR(sstate->QUOTE_MAP); |
|
542
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
680 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
681 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
|
682 } |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
683 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
684 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
685 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
|
686 {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
|
687 {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
|
688 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
689 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
690 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
691 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
|
692 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
|
693 "_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
|
694 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
|
695 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
|
696 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
|
697 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
|
698 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
|
699 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
|
700 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
|
701 }; |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
702 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
703 |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
704 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
|
705 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
|
706 { |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
707 /* |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
708 * 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
|
709 * 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
|
710 */ |
|
f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
711 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
|
712 } |
