Show More
@@ -1,8 +1,6 b'' | |||||
1 | # Files that just need to be migrated to the formatter. |
|
1 | # Files that just need to be migrated to the formatter. | |
2 | # Do not add new files here! |
|
2 | # Do not add new files here! | |
3 | mercurial/cext/base85.c |
|
3 | mercurial/cext/base85.c | |
4 | mercurial/cext/charencode.c |
|
|||
5 | mercurial/cext/charencode.h |
|
|||
6 | mercurial/cext/dirs.c |
|
4 | mercurial/cext/dirs.c | |
7 | mercurial/cext/manifest.c |
|
5 | mercurial/cext/manifest.c | |
8 | mercurial/cext/mpatch.c |
|
6 | mercurial/cext/mpatch.c |
@@ -151,9 +151,8 b' PyObject *isasciistr(PyObject *self, PyO' | |||||
151 | Py_RETURN_TRUE; |
|
151 | Py_RETURN_TRUE; | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | static inline PyObject *_asciitransform(PyObject *str_obj, |
|
154 | static inline PyObject * | |
155 | const char table[128], |
|
155 | _asciitransform(PyObject *str_obj, const char table[128], PyObject *fallback_fn) | |
156 | PyObject *fallback_fn) |
|
|||
157 | { |
|
156 | { | |
158 | char *str, *newstr; |
|
157 | char *str, *newstr; | |
159 | Py_ssize_t i, len; |
|
158 | Py_ssize_t i, len; | |
@@ -173,12 +172,12 b' static inline PyObject *_asciitransform(' | |||||
173 | char c = str[i]; |
|
172 | char c = str[i]; | |
174 | if (c & 0x80) { |
|
173 | if (c & 0x80) { | |
175 | if (fallback_fn != NULL) { |
|
174 | if (fallback_fn != NULL) { | |
176 |
ret = PyObject_CallFunctionObjArgs( |
|
175 | ret = PyObject_CallFunctionObjArgs( | |
177 |
|
|
176 | fallback_fn, str_obj, NULL); | |
178 | } else { |
|
177 | } else { | |
179 | PyObject *err = PyUnicodeDecodeError_Create( |
|
178 | PyObject *err = PyUnicodeDecodeError_Create( | |
180 |
|
|
179 | "ascii", str, len, i, (i + 1), | |
181 |
|
|
180 | "unexpected code byte"); | |
182 | PyErr_SetObject(PyExc_UnicodeDecodeError, err); |
|
181 | PyErr_SetObject(PyExc_UnicodeDecodeError, err); | |
183 | Py_XDECREF(err); |
|
182 | Py_XDECREF(err); | |
184 | } |
|
183 | } | |
@@ -220,10 +219,9 b' PyObject *make_file_foldmap(PyObject *se' | |||||
220 | Py_ssize_t pos = 0; |
|
219 | Py_ssize_t pos = 0; | |
221 | const char *table; |
|
220 | const char *table; | |
222 |
|
221 | |||
223 | if (!PyArg_ParseTuple(args, "O!O!O!:make_file_foldmap", |
|
222 | if (!PyArg_ParseTuple(args, "O!O!O!:make_file_foldmap", &PyDict_Type, | |
224 | &PyDict_Type, &dmap, |
|
223 | &dmap, &PyInt_Type, &spec_obj, &PyFunction_Type, | |
225 | &PyInt_Type, &spec_obj, |
|
224 | &normcase_fallback)) | |
226 | &PyFunction_Type, &normcase_fallback)) |
|
|||
227 | goto quit; |
|
225 | goto quit; | |
228 |
|
226 | |||
229 | spec = (int)PyInt_AS_LONG(spec_obj); |
|
227 | spec = (int)PyInt_AS_LONG(spec_obj); | |
@@ -251,7 +249,7 b' PyObject *make_file_foldmap(PyObject *se' | |||||
251 | while (PyDict_Next(dmap, &pos, &k, &v)) { |
|
249 | while (PyDict_Next(dmap, &pos, &k, &v)) { | |
252 | if (!dirstate_tuple_check(v)) { |
|
250 | if (!dirstate_tuple_check(v)) { | |
253 | PyErr_SetString(PyExc_TypeError, |
|
251 | PyErr_SetString(PyExc_TypeError, | |
254 |
|
|
252 | "expected a dirstate tuple"); | |
255 | goto quit; |
|
253 | goto quit; | |
256 | } |
|
254 | } | |
257 |
|
255 | |||
@@ -260,10 +258,10 b' PyObject *make_file_foldmap(PyObject *se' | |||||
260 | PyObject *normed; |
|
258 | PyObject *normed; | |
261 | if (table != NULL) { |
|
259 | if (table != NULL) { | |
262 | normed = _asciitransform(k, table, |
|
260 | normed = _asciitransform(k, table, | |
263 |
|
|
261 | normcase_fallback); | |
264 | } else { |
|
262 | } else { | |
265 | normed = PyObject_CallFunctionObjArgs( |
|
263 | normed = PyObject_CallFunctionObjArgs( | |
266 |
|
|
264 | normcase_fallback, k, NULL); | |
267 | } |
|
265 | } | |
268 |
|
266 | |||
269 | if (normed == NULL) |
|
267 | if (normed == NULL) | |
@@ -292,13 +290,13 b' static Py_ssize_t jsonescapelen(const ch' | |||||
292 | char c = buf[i]; |
|
290 | char c = buf[i]; | |
293 | if (c & 0x80) { |
|
291 | if (c & 0x80) { | |
294 | PyErr_SetString(PyExc_ValueError, |
|
292 | PyErr_SetString(PyExc_ValueError, | |
295 |
|
|
293 | "cannot process non-ascii str"); | |
296 | return -1; |
|
294 | return -1; | |
297 | } |
|
295 | } | |
298 | esclen += jsonparanoidlentable[(unsigned char)c]; |
|
296 | esclen += jsonparanoidlentable[(unsigned char)c]; | |
299 | if (esclen < 0) { |
|
297 | if (esclen < 0) { | |
300 | PyErr_SetString(PyExc_MemoryError, |
|
298 | PyErr_SetString(PyExc_MemoryError, | |
301 |
|
|
299 | "overflow in jsonescapelen"); | |
302 | return -1; |
|
300 | return -1; | |
303 | } |
|
301 | } | |
304 | } |
|
302 | } | |
@@ -308,7 +306,7 b' static Py_ssize_t jsonescapelen(const ch' | |||||
308 | esclen += jsonlentable[(unsigned char)c]; |
|
306 | esclen += jsonlentable[(unsigned char)c]; | |
309 | if (esclen < 0) { |
|
307 | if (esclen < 0) { | |
310 | PyErr_SetString(PyExc_MemoryError, |
|
308 | PyErr_SetString(PyExc_MemoryError, | |
311 |
|
|
309 | "overflow in jsonescapelen"); | |
312 | return -1; |
|
310 | return -1; | |
313 | } |
|
311 | } | |
314 | } |
|
312 | } | |
@@ -336,17 +334,17 b' static char jsonescapechar2(char c)' | |||||
336 | case '\\': |
|
334 | case '\\': | |
337 | return '\\'; |
|
335 | return '\\'; | |
338 | } |
|
336 | } | |
339 |
return '\0'; |
|
337 | return '\0'; /* should not happen */ | |
340 | } |
|
338 | } | |
341 |
|
339 | |||
342 | /* convert 'origbuf' to JSON-escaped form 'escbuf'; 'origbuf' should only |
|
340 | /* convert 'origbuf' to JSON-escaped form 'escbuf'; 'origbuf' should only | |
343 | include characters mappable by json(paranoid)lentable */ |
|
341 | include characters mappable by json(paranoid)lentable */ | |
344 | static void encodejsonescape(char *escbuf, Py_ssize_t esclen, |
|
342 | static void encodejsonescape(char *escbuf, Py_ssize_t esclen, | |
345 |
|
|
343 | const char *origbuf, Py_ssize_t origlen, | |
346 | bool paranoid) |
|
344 | bool paranoid) | |
347 | { |
|
345 | { | |
348 | const uint8_t *lentable = |
|
346 | const uint8_t *lentable = | |
349 |
|
|
347 | (paranoid) ? jsonparanoidlentable : jsonlentable; | |
350 | Py_ssize_t i, j; |
|
348 | Py_ssize_t i, j; | |
351 |
|
349 | |||
352 | for (i = 0, j = 0; i < origlen; i++) { |
|
350 | for (i = 0, j = 0; i < origlen; i++) { | |
@@ -377,15 +375,15 b' PyObject *jsonescapeu8fast(PyObject *sel' | |||||
377 | const char *origbuf; |
|
375 | const char *origbuf; | |
378 | Py_ssize_t origlen, esclen; |
|
376 | Py_ssize_t origlen, esclen; | |
379 | int paranoid; |
|
377 | int paranoid; | |
380 | if (!PyArg_ParseTuple(args, "O!i:jsonescapeu8fast", |
|
378 | if (!PyArg_ParseTuple(args, "O!i:jsonescapeu8fast", &PyBytes_Type, | |
381 |
|
|
379 | &origstr, ¶noid)) | |
382 | return NULL; |
|
380 | return NULL; | |
383 |
|
381 | |||
384 | origbuf = PyBytes_AS_STRING(origstr); |
|
382 | origbuf = PyBytes_AS_STRING(origstr); | |
385 | origlen = PyBytes_GET_SIZE(origstr); |
|
383 | origlen = PyBytes_GET_SIZE(origstr); | |
386 | esclen = jsonescapelen(origbuf, origlen, paranoid); |
|
384 | esclen = jsonescapelen(origbuf, origlen, paranoid); | |
387 | if (esclen < 0) |
|
385 | if (esclen < 0) | |
388 |
return NULL; |
|
386 | return NULL; /* unsupported char found or overflow */ | |
389 | if (origlen == esclen) { |
|
387 | if (origlen == esclen) { | |
390 | Py_INCREF(origstr); |
|
388 | Py_INCREF(origstr); | |
391 | return origstr; |
|
389 | return origstr; | |
@@ -395,7 +393,7 b' PyObject *jsonescapeu8fast(PyObject *sel' | |||||
395 | if (!escstr) |
|
393 | if (!escstr) | |
396 | return NULL; |
|
394 | return NULL; | |
397 | encodejsonescape(PyBytes_AS_STRING(escstr), esclen, origbuf, origlen, |
|
395 | encodejsonescape(PyBytes_AS_STRING(escstr), esclen, origbuf, origlen, | |
398 | paranoid); |
|
396 | paranoid); | |
399 |
|
397 | |||
400 | return escstr; |
|
398 | return escstr; | |
401 | } |
|
399 | } |
General Comments 0
You need to be logged in to leave comments.
Login now