| 1 |
#include "pyconfig.h" // Py_GIL_DISABLED |
| 2 |
#ifndef Py_GIL_DISABLED |
| 3 |
// Need limited C API 3.14 to test PyUnicode_Equal() |
| 4 |
# define Py_LIMITED_API 0x030e0000 |
| 5 |
#endif |
| 6 |
|
| 7 |
#include "parts.h" |
| 8 |
#include "util.h" |
| 9 |
|
| 10 |
#include <stddef.h> // ptrdiff_t |
| 11 |
#include <string.h> // memset() |
| 12 |
|
| 13 |
|
| 14 |
static PyObject * |
| 15 |
codec_incrementalencoder(PyObject *self, PyObject *args) |
| 16 |
{ |
| 17 |
const char *encoding, *errors = NULL; |
| 18 |
if (!PyArg_ParseTuple(args, "s|s:test_incrementalencoder", |
| 19 |
&encoding, &errors)) |
| 20 |
return NULL; |
| 21 |
return PyCodec_IncrementalEncoder(encoding, errors); |
| 22 |
} |
| 23 |
|
| 24 |
static PyObject * |
| 25 |
codec_incrementaldecoder(PyObject *self, PyObject *args) |
| 26 |
{ |
| 27 |
const char *encoding, *errors = NULL; |
| 28 |
if (!PyArg_ParseTuple(args, "s|s:test_incrementaldecoder", |
| 29 |
&encoding, &errors)) |
| 30 |
return NULL; |
| 31 |
return PyCodec_IncrementalDecoder(encoding, errors); |
| 32 |
} |
| 33 |
|
| 34 |
static PyObject * |
| 35 |
test_unicode_compare_with_ascii(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 36 |
{ |
| 37 |
PyObject *py_s = PyUnicode_FromStringAndSize("str\0", 4); |
| 38 |
int result; |
| 39 |
if (py_s == NULL) |
| 40 |
return NULL; |
| 41 |
result = PyUnicode_CompareWithASCIIString(py_s, "str"); |
| 42 |
Py_DECREF(py_s); |
| 43 |
if (!result) { |
| 44 |
PyErr_SetString(PyExc_AssertionError, "Python string ending in NULL " |
| 45 |
"should not compare equal to c string."); |
| 46 |
return NULL; |
| 47 |
} |
| 48 |
Py_RETURN_NONE; |
| 49 |
} |
| 50 |
|
| 51 |
static PyObject * |
| 52 |
test_widechar(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 53 |
{ |
| 54 |
#if defined(SIZEOF_WCHAR_T) && (SIZEOF_WCHAR_T == 4) |
| 55 |
const wchar_t wtext[2] = {(wchar_t)0x10ABCDu}; |
| 56 |
size_t wtextlen = 1; |
| 57 |
const wchar_t invalid[1] = {(wchar_t)0x110000u}; |
| 58 |
#else |
| 59 |
const wchar_t wtext[3] = {(wchar_t)0xDBEAu, (wchar_t)0xDFCDu}; |
| 60 |
size_t wtextlen = 2; |
| 61 |
#endif |
| 62 |
PyObject *wide, *utf8; |
| 63 |
|
| 64 |
wide = PyUnicode_FromWideChar(wtext, wtextlen); |
| 65 |
if (wide == NULL) |
| 66 |
return NULL; |
| 67 |
|
| 68 |
utf8 = PyUnicode_FromString("\xf4\x8a\xaf\x8d"); |
| 69 |
if (utf8 == NULL) { |
| 70 |
Py_DECREF(wide); |
| 71 |
return NULL; |
| 72 |
} |
| 73 |
|
| 74 |
if (PyUnicode_GetLength(wide) != PyUnicode_GetLength(utf8)) { |
| 75 |
Py_DECREF(wide); |
| 76 |
Py_DECREF(utf8); |
| 77 |
PyErr_SetString(PyExc_AssertionError, |
| 78 |
"test_widechar: " |
| 79 |
"wide string and utf8 string " |
| 80 |
"have different length"); |
| 81 |
return NULL; |
| 82 |
} |
| 83 |
if (PyUnicode_Compare(wide, utf8)) { |
| 84 |
Py_DECREF(wide); |
| 85 |
Py_DECREF(utf8); |
| 86 |
if (PyErr_Occurred()) |
| 87 |
return NULL; |
| 88 |
PyErr_SetString(PyExc_AssertionError, |
| 89 |
"test_widechar: " |
| 90 |
"wide string and utf8 string " |
| 91 |
"are different"); |
| 92 |
return NULL; |
| 93 |
} |
| 94 |
|
| 95 |
Py_DECREF(wide); |
| 96 |
Py_DECREF(utf8); |
| 97 |
|
| 98 |
#if defined(SIZEOF_WCHAR_T) && (SIZEOF_WCHAR_T == 4) |
| 99 |
wide = PyUnicode_FromWideChar(invalid, 1); |
| 100 |
if (wide == NULL) |
| 101 |
PyErr_Clear(); |
| 102 |
else { |
| 103 |
PyErr_SetString(PyExc_AssertionError, |
| 104 |
"test_widechar: " |
| 105 |
"PyUnicode_FromWideChar(L\"\\U00110000\", 1) didn't fail"); |
| 106 |
return NULL; |
| 107 |
} |
| 108 |
#endif |
| 109 |
Py_RETURN_NONE; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
static PyObject * |
| 114 |
unicode_copy(PyObject *unicode) |
| 115 |
{ |
| 116 |
if (!unicode) { |
| 117 |
return NULL; |
| 118 |
} |
| 119 |
if (!PyUnicode_Check(unicode)) { |
| 120 |
Py_INCREF(unicode); |
| 121 |
return unicode; |
| 122 |
} |
| 123 |
|
| 124 |
// Create a new string by encoding to UTF-8 and then decode from UTF-8 |
| 125 |
PyObject *utf8 = PyUnicode_AsUTF8String(unicode); |
| 126 |
if (!utf8) { |
| 127 |
return NULL; |
| 128 |
} |
| 129 |
|
| 130 |
PyObject *copy = PyUnicode_DecodeUTF8( |
| 131 |
PyBytes_AsString(utf8), |
| 132 |
PyBytes_Size(utf8), |
| 133 |
NULL); |
| 134 |
Py_DECREF(utf8); |
| 135 |
|
| 136 |
return copy; |
| 137 |
} |
| 138 |
|
| 139 |
/* Test PyUnicode_WriteChar() */ |
| 140 |
static PyObject * |
| 141 |
unicode_writechar(PyObject *self, PyObject *args) |
| 142 |
{ |
| 143 |
PyObject *to, *to_copy; |
| 144 |
Py_ssize_t index; |
| 145 |
unsigned int character; |
| 146 |
int result; |
| 147 |
|
| 148 |
if (!PyArg_ParseTuple(args, "OnI", &to, &index, &character)) { |
| 149 |
return NULL; |
| 150 |
} |
| 151 |
|
| 152 |
NULLABLE(to); |
| 153 |
if (!(to_copy = unicode_copy(to)) && to) { |
| 154 |
return NULL; |
| 155 |
} |
| 156 |
|
| 157 |
result = PyUnicode_WriteChar(to_copy, index, (Py_UCS4)character); |
| 158 |
if (result == -1 && PyErr_Occurred()) { |
| 159 |
Py_DECREF(to_copy); |
| 160 |
return NULL; |
| 161 |
} |
| 162 |
return Py_BuildValue("(Ni)", to_copy, result); |
| 163 |
} |
| 164 |
|
| 165 |
static void |
| 166 |
unicode_fill(PyObject *str, Py_ssize_t start, Py_ssize_t end, Py_UCS4 ch) |
| 167 |
{ |
| 168 |
assert(0 <= start); |
| 169 |
assert(end <= PyUnicode_GetLength(str)); |
| 170 |
for (Py_ssize_t i = start; i < end; i++) { |
| 171 |
int res = PyUnicode_WriteChar(str, i, ch); |
| 172 |
assert(res == 0); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
/* Test PyUnicode_Resize() */ |
| 178 |
static PyObject * |
| 179 |
unicode_resize(PyObject *self, PyObject *args) |
| 180 |
{ |
| 181 |
PyObject *obj, *copy; |
| 182 |
Py_ssize_t length; |
| 183 |
int result; |
| 184 |
|
| 185 |
if (!PyArg_ParseTuple(args, "On", &obj, &length)) { |
| 186 |
return NULL; |
| 187 |
} |
| 188 |
|
| 189 |
NULLABLE(obj); |
| 190 |
if (!(copy = unicode_copy(obj)) && obj) { |
| 191 |
return NULL; |
| 192 |
} |
| 193 |
result = PyUnicode_Resize(©, length); |
| 194 |
if (result == -1 && PyErr_Occurred()) { |
| 195 |
Py_XDECREF(copy); |
| 196 |
return NULL; |
| 197 |
} |
| 198 |
if (obj && PyUnicode_Check(obj) && length > PyUnicode_GetLength(obj)) { |
| 199 |
unicode_fill(copy, PyUnicode_GetLength(obj), length, 0U); |
| 200 |
} |
| 201 |
return Py_BuildValue("(Ni)", copy, result); |
| 202 |
} |
| 203 |
|
| 204 |
/* Test PyUnicode_Append() */ |
| 205 |
static PyObject * |
| 206 |
unicode_append(PyObject *self, PyObject *args) |
| 207 |
{ |
| 208 |
PyObject *left, *right, *left_copy; |
| 209 |
|
| 210 |
if (!PyArg_ParseTuple(args, "OO", &left, &right)) |
| 211 |
return NULL; |
| 212 |
|
| 213 |
NULLABLE(left); |
| 214 |
NULLABLE(right); |
| 215 |
if (!(left_copy = unicode_copy(left)) && left) { |
| 216 |
return NULL; |
| 217 |
} |
| 218 |
PyUnicode_Append(&left_copy, right); |
| 219 |
return left_copy; |
| 220 |
} |
| 221 |
|
| 222 |
/* Test PyUnicode_AppendAndDel() */ |
| 223 |
static PyObject * |
| 224 |
unicode_appendanddel(PyObject *self, PyObject *args) |
| 225 |
{ |
| 226 |
PyObject *left, *right, *left_copy; |
| 227 |
|
| 228 |
if (!PyArg_ParseTuple(args, "OO", &left, &right)) |
| 229 |
return NULL; |
| 230 |
|
| 231 |
NULLABLE(left); |
| 232 |
NULLABLE(right); |
| 233 |
if (!(left_copy = unicode_copy(left)) && left) { |
| 234 |
return NULL; |
| 235 |
} |
| 236 |
Py_XINCREF(right); |
| 237 |
PyUnicode_AppendAndDel(&left_copy, right); |
| 238 |
return left_copy; |
| 239 |
} |
| 240 |
|
| 241 |
/* Test PyUnicode_FromStringAndSize() */ |
| 242 |
static PyObject * |
| 243 |
unicode_fromstringandsize(PyObject *self, PyObject *args) |
| 244 |
{ |
| 245 |
const char *s; |
| 246 |
Py_ssize_t bsize; |
| 247 |
Py_ssize_t size = -100; |
| 248 |
|
| 249 |
if (!PyArg_ParseTuple(args, "z#|n", &s, &bsize, &size)) { |
| 250 |
return NULL; |
| 251 |
} |
| 252 |
|
| 253 |
if (size == -100) { |
| 254 |
size = bsize; |
| 255 |
} |
| 256 |
return PyUnicode_FromStringAndSize(s, size); |
| 257 |
} |
| 258 |
|
| 259 |
/* Test PyUnicode_FromString() */ |
| 260 |
static PyObject * |
| 261 |
unicode_fromstring(PyObject *self, PyObject *arg) |
| 262 |
{ |
| 263 |
const char *s; |
| 264 |
Py_ssize_t size; |
| 265 |
|
| 266 |
if (!PyArg_Parse(arg, "z#", &s, &size)) { |
| 267 |
return NULL; |
| 268 |
} |
| 269 |
return PyUnicode_FromString(s); |
| 270 |
} |
| 271 |
|
| 272 |
/* Test PyUnicode_Substring() */ |
| 273 |
static PyObject * |
| 274 |
unicode_substring(PyObject *self, PyObject *args) |
| 275 |
{ |
| 276 |
PyObject *str; |
| 277 |
Py_ssize_t start, end; |
| 278 |
|
| 279 |
if (!PyArg_ParseTuple(args, "Onn", &str, &start, &end)) { |
| 280 |
return NULL; |
| 281 |
} |
| 282 |
|
| 283 |
NULLABLE(str); |
| 284 |
return PyUnicode_Substring(str, start, end); |
| 285 |
} |
| 286 |
|
| 287 |
/* Test PyUnicode_GetLength() */ |
| 288 |
static PyObject * |
| 289 |
unicode_getlength(PyObject *self, PyObject *arg) |
| 290 |
{ |
| 291 |
NULLABLE(arg); |
| 292 |
RETURN_SIZE(PyUnicode_GetLength(arg)); |
| 293 |
} |
| 294 |
|
| 295 |
/* Test PyUnicode_ReadChar() */ |
| 296 |
static PyObject * |
| 297 |
unicode_readchar(PyObject *self, PyObject *args) |
| 298 |
{ |
| 299 |
PyObject *unicode; |
| 300 |
Py_ssize_t index; |
| 301 |
Py_UCS4 result; |
| 302 |
|
| 303 |
if (!PyArg_ParseTuple(args, "On", &unicode, &index)) { |
| 304 |
return NULL; |
| 305 |
} |
| 306 |
|
| 307 |
NULLABLE(unicode); |
| 308 |
result = PyUnicode_ReadChar(unicode, index); |
| 309 |
if (result == (Py_UCS4)-1) |
| 310 |
return NULL; |
| 311 |
return PyLong_FromUnsignedLong(result); |
| 312 |
} |
| 313 |
|
| 314 |
/* Test PyUnicode_FromEncodedObject() */ |
| 315 |
static PyObject * |
| 316 |
unicode_fromencodedobject(PyObject *self, PyObject *args) |
| 317 |
{ |
| 318 |
PyObject *obj; |
| 319 |
const char *encoding; |
| 320 |
const char *errors = NULL; |
| 321 |
|
| 322 |
if (!PyArg_ParseTuple(args, "Oz|z", &obj, &encoding, &errors)) { |
| 323 |
return NULL; |
| 324 |
} |
| 325 |
|
| 326 |
NULLABLE(obj); |
| 327 |
return PyUnicode_FromEncodedObject(obj, encoding, errors); |
| 328 |
} |
| 329 |
|
| 330 |
/* Test PyUnicode_FromObject() */ |
| 331 |
static PyObject * |
| 332 |
unicode_fromobject(PyObject *self, PyObject *arg) |
| 333 |
{ |
| 334 |
NULLABLE(arg); |
| 335 |
return PyUnicode_FromObject(arg); |
| 336 |
} |
| 337 |
|
| 338 |
/* Test PyUnicode_InternInPlace() */ |
| 339 |
static PyObject * |
| 340 |
unicode_interninplace(PyObject *self, PyObject *arg) |
| 341 |
{ |
| 342 |
NULLABLE(arg); |
| 343 |
Py_XINCREF(arg); |
| 344 |
PyUnicode_InternInPlace(&arg); |
| 345 |
return arg; |
| 346 |
} |
| 347 |
|
| 348 |
/* Test PyUnicode_InternFromString() */ |
| 349 |
static PyObject * |
| 350 |
unicode_internfromstring(PyObject *self, PyObject *arg) |
| 351 |
{ |
| 352 |
const char *s; |
| 353 |
Py_ssize_t size; |
| 354 |
|
| 355 |
if (!PyArg_Parse(arg, "z#", &s, &size)) { |
| 356 |
return NULL; |
| 357 |
} |
| 358 |
return PyUnicode_InternFromString(s); |
| 359 |
} |
| 360 |
|
| 361 |
/* Test PyUnicode_FromWideChar() */ |
| 362 |
static PyObject * |
| 363 |
unicode_fromwidechar(PyObject *self, PyObject *args) |
| 364 |
{ |
| 365 |
const char *s; |
| 366 |
Py_ssize_t bsize; |
| 367 |
Py_ssize_t size = -100; |
| 368 |
|
| 369 |
if (!PyArg_ParseTuple(args, "z#|n", &s, &bsize, &size)) { |
| 370 |
return NULL; |
| 371 |
} |
| 372 |
if (size == -100) { |
| 373 |
if (bsize % SIZEOF_WCHAR_T) { |
| 374 |
PyErr_SetString(PyExc_AssertionError, |
| 375 |
"invalid size in unicode_fromwidechar()"); |
| 376 |
return NULL; |
| 377 |
} |
| 378 |
size = bsize / SIZEOF_WCHAR_T; |
| 379 |
} |
| 380 |
return PyUnicode_FromWideChar((const wchar_t *)s, size); |
| 381 |
} |
| 382 |
|
| 383 |
/* Test PyUnicode_AsWideChar() */ |
| 384 |
static PyObject * |
| 385 |
unicode_aswidechar(PyObject *self, PyObject *args) |
| 386 |
{ |
| 387 |
PyObject *unicode, *result; |
| 388 |
Py_ssize_t buflen, size; |
| 389 |
wchar_t *buffer; |
| 390 |
|
| 391 |
if (!PyArg_ParseTuple(args, "On", &unicode, &buflen)) |
| 392 |
return NULL; |
| 393 |
NULLABLE(unicode); |
| 394 |
buffer = PyMem_New(wchar_t, buflen); |
| 395 |
if (buffer == NULL) |
| 396 |
return PyErr_NoMemory(); |
| 397 |
|
| 398 |
size = PyUnicode_AsWideChar(unicode, buffer, buflen); |
| 399 |
if (size == -1) { |
| 400 |
PyMem_Free(buffer); |
| 401 |
return NULL; |
| 402 |
} |
| 403 |
|
| 404 |
if (size < buflen) |
| 405 |
buflen = size + 1; |
| 406 |
else |
| 407 |
buflen = size; |
| 408 |
result = PyUnicode_FromWideChar(buffer, buflen); |
| 409 |
PyMem_Free(buffer); |
| 410 |
if (result == NULL) |
| 411 |
return NULL; |
| 412 |
|
| 413 |
return Py_BuildValue("(Nn)", result, size); |
| 414 |
} |
| 415 |
|
| 416 |
/* Test PyUnicode_AsWideCharString() with NULL as buffer */ |
| 417 |
static PyObject * |
| 418 |
unicode_aswidechar_null(PyObject *self, PyObject *args) |
| 419 |
{ |
| 420 |
PyObject *unicode; |
| 421 |
Py_ssize_t buflen; |
| 422 |
|
| 423 |
if (!PyArg_ParseTuple(args, "On", &unicode, &buflen)) |
| 424 |
return NULL; |
| 425 |
NULLABLE(unicode); |
| 426 |
RETURN_SIZE(PyUnicode_AsWideChar(unicode, NULL, buflen)); |
| 427 |
} |
| 428 |
|
| 429 |
/* Test PyUnicode_AsWideCharString() */ |
| 430 |
static PyObject * |
| 431 |
unicode_aswidecharstring(PyObject *self, PyObject *args) |
| 432 |
{ |
| 433 |
PyObject *unicode, *result; |
| 434 |
Py_ssize_t size = UNINITIALIZED_SIZE; |
| 435 |
wchar_t *buffer; |
| 436 |
|
| 437 |
if (!PyArg_ParseTuple(args, "O", &unicode)) |
| 438 |
return NULL; |
| 439 |
|
| 440 |
NULLABLE(unicode); |
| 441 |
buffer = PyUnicode_AsWideCharString(unicode, &size); |
| 442 |
if (buffer == NULL) { |
| 443 |
assert(size == UNINITIALIZED_SIZE); |
| 444 |
return NULL; |
| 445 |
} |
| 446 |
|
| 447 |
result = PyUnicode_FromWideChar(buffer, size + 1); |
| 448 |
PyMem_Free(buffer); |
| 449 |
if (result == NULL) |
| 450 |
return NULL; |
| 451 |
return Py_BuildValue("(Nn)", result, size); |
| 452 |
} |
| 453 |
|
| 454 |
/* Test PyUnicode_AsWideCharString() with NULL as the size address */ |
| 455 |
static PyObject * |
| 456 |
unicode_aswidecharstring_null(PyObject *self, PyObject *args) |
| 457 |
{ |
| 458 |
PyObject *unicode, *result; |
| 459 |
wchar_t *buffer; |
| 460 |
|
| 461 |
if (!PyArg_ParseTuple(args, "O", &unicode)) |
| 462 |
return NULL; |
| 463 |
|
| 464 |
NULLABLE(unicode); |
| 465 |
buffer = PyUnicode_AsWideCharString(unicode, NULL); |
| 466 |
if (buffer == NULL) |
| 467 |
return NULL; |
| 468 |
|
| 469 |
result = PyUnicode_FromWideChar(buffer, -1); |
| 470 |
PyMem_Free(buffer); |
| 471 |
if (result == NULL) |
| 472 |
return NULL; |
| 473 |
return result; |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
/* Test PyUnicode_FromOrdinal() */ |
| 478 |
static PyObject * |
| 479 |
unicode_fromordinal(PyObject *self, PyObject *args) |
| 480 |
{ |
| 481 |
int ordinal; |
| 482 |
|
| 483 |
if (!PyArg_ParseTuple(args, "i", &ordinal)) |
| 484 |
return NULL; |
| 485 |
|
| 486 |
return PyUnicode_FromOrdinal(ordinal); |
| 487 |
} |
| 488 |
|
| 489 |
/* Test PyUnicode_AsUTF8AndSize() */ |
| 490 |
static PyObject * |
| 491 |
unicode_asutf8andsize(PyObject *self, PyObject *args) |
| 492 |
{ |
| 493 |
PyObject *unicode; |
| 494 |
Py_ssize_t buflen; |
| 495 |
const char *s; |
| 496 |
Py_ssize_t size = UNINITIALIZED_SIZE; |
| 497 |
|
| 498 |
if (!PyArg_ParseTuple(args, "On", &unicode, &buflen)) |
| 499 |
return NULL; |
| 500 |
|
| 501 |
NULLABLE(unicode); |
| 502 |
s = PyUnicode_AsUTF8AndSize(unicode, &size); |
| 503 |
if (s == NULL) { |
| 504 |
assert(size == -1); |
| 505 |
return NULL; |
| 506 |
} |
| 507 |
|
| 508 |
return Py_BuildValue("(y#n)", s, buflen, size); |
| 509 |
} |
| 510 |
|
| 511 |
/* Test PyUnicode_AsUTF8AndSize() with NULL as the size address */ |
| 512 |
static PyObject * |
| 513 |
unicode_asutf8andsize_null(PyObject *self, PyObject *args) |
| 514 |
{ |
| 515 |
PyObject *unicode; |
| 516 |
Py_ssize_t buflen; |
| 517 |
const char *s; |
| 518 |
|
| 519 |
if (!PyArg_ParseTuple(args, "On", &unicode, &buflen)) |
| 520 |
return NULL; |
| 521 |
|
| 522 |
NULLABLE(unicode); |
| 523 |
s = PyUnicode_AsUTF8AndSize(unicode, NULL); |
| 524 |
if (s == NULL) |
| 525 |
return NULL; |
| 526 |
|
| 527 |
return PyBytes_FromStringAndSize(s, buflen); |
| 528 |
} |
| 529 |
|
| 530 |
/* Test PyUnicode_GetDefaultEncoding() */ |
| 531 |
static PyObject * |
| 532 |
unicode_getdefaultencoding(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 533 |
{ |
| 534 |
const char *s = PyUnicode_GetDefaultEncoding(); |
| 535 |
if (s == NULL) |
| 536 |
return NULL; |
| 537 |
|
| 538 |
return PyBytes_FromString(s); |
| 539 |
} |
| 540 |
|
| 541 |
/* Test PyUnicode_Decode() */ |
| 542 |
static PyObject * |
| 543 |
unicode_decode(PyObject *self, PyObject *args) |
| 544 |
{ |
| 545 |
const char *s; |
| 546 |
Py_ssize_t size; |
| 547 |
const char *encoding; |
| 548 |
const char *errors = NULL; |
| 549 |
|
| 550 |
if (!PyArg_ParseTuple(args, "y#z|z", &s, &size, &encoding, &errors)) |
| 551 |
return NULL; |
| 552 |
|
| 553 |
return PyUnicode_Decode(s, size, encoding, errors); |
| 554 |
} |
| 555 |
|
| 556 |
/* Test PyUnicode_AsEncodedString() */ |
| 557 |
static PyObject * |
| 558 |
unicode_asencodedstring(PyObject *self, PyObject *args) |
| 559 |
{ |
| 560 |
PyObject *unicode; |
| 561 |
const char *encoding; |
| 562 |
const char *errors = NULL; |
| 563 |
|
| 564 |
if (!PyArg_ParseTuple(args, "Oz|z", &unicode, &encoding, &errors)) |
| 565 |
return NULL; |
| 566 |
|
| 567 |
NULLABLE(unicode); |
| 568 |
return PyUnicode_AsEncodedString(unicode, encoding, errors); |
| 569 |
} |
| 570 |
|
| 571 |
/* Test PyUnicode_BuildEncodingMap() */ |
| 572 |
static PyObject * |
| 573 |
unicode_buildencodingmap(PyObject *self, PyObject *arg) |
| 574 |
{ |
| 575 |
NULLABLE(arg); |
| 576 |
return PyUnicode_BuildEncodingMap(arg); |
| 577 |
} |
| 578 |
|
| 579 |
/* Test PyUnicode_DecodeUTF7() */ |
| 580 |
static PyObject * |
| 581 |
unicode_decodeutf7(PyObject *self, PyObject *args) |
| 582 |
{ |
| 583 |
const char *data; |
| 584 |
Py_ssize_t size; |
| 585 |
const char *errors = NULL; |
| 586 |
|
| 587 |
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors)) |
| 588 |
return NULL; |
| 589 |
|
| 590 |
return PyUnicode_DecodeUTF7(data, size, errors); |
| 591 |
} |
| 592 |
|
| 593 |
/* Test PyUnicode_DecodeUTF7Stateful() */ |
| 594 |
static PyObject * |
| 595 |
unicode_decodeutf7stateful(PyObject *self, PyObject *args) |
| 596 |
{ |
| 597 |
const char *data; |
| 598 |
Py_ssize_t size; |
| 599 |
const char *errors = NULL; |
| 600 |
Py_ssize_t consumed = UNINITIALIZED_SIZE; |
| 601 |
PyObject *result; |
| 602 |
|
| 603 |
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors)) |
| 604 |
return NULL; |
| 605 |
|
| 606 |
result = PyUnicode_DecodeUTF7Stateful(data, size, errors, &consumed); |
| 607 |
if (!result) { |
| 608 |
assert(consumed == UNINITIALIZED_SIZE); |
| 609 |
return NULL; |
| 610 |
} |
| 611 |
return Py_BuildValue("(Nn)", result, consumed); |
| 612 |
} |
| 613 |
|
| 614 |
/* Test PyUnicode_DecodeUTF8() */ |
| 615 |
static PyObject * |
| 616 |
unicode_decodeutf8(PyObject *self, PyObject *args) |
| 617 |
{ |
| 618 |
const char *data; |
| 619 |
Py_ssize_t size; |
| 620 |
const char *errors = NULL; |
| 621 |
|
| 622 |
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors)) |
| 623 |
return NULL; |
| 624 |
|
| 625 |
return PyUnicode_DecodeUTF8(data, size, errors); |
| 626 |
} |
| 627 |
|
| 628 |
/* Test PyUnicode_DecodeUTF8Stateful() */ |
| 629 |
static PyObject * |
| 630 |
unicode_decodeutf8stateful(PyObject *self, PyObject *args) |
| 631 |
{ |
| 632 |
const char *data; |
| 633 |
Py_ssize_t size; |
| 634 |
const char *errors = NULL; |
| 635 |
Py_ssize_t consumed = UNINITIALIZED_SIZE; |
| 636 |
PyObject *result; |
| 637 |
|
| 638 |
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors)) |
| 639 |
return NULL; |
| 640 |
|
| 641 |
result = PyUnicode_DecodeUTF8Stateful(data, size, errors, &consumed); |
| 642 |
if (!result) { |
| 643 |
assert(consumed == UNINITIALIZED_SIZE); |
| 644 |
return NULL; |
| 645 |
} |
| 646 |
return Py_BuildValue("(Nn)", result, consumed); |
| 647 |
} |
| 648 |
|
| 649 |
/* Test PyUnicode_AsUTF8String() */ |
| 650 |
static PyObject * |
| 651 |
unicode_asutf8string(PyObject *self, PyObject *arg) |
| 652 |
{ |
| 653 |
NULLABLE(arg); |
| 654 |
return PyUnicode_AsUTF8String(arg); |
| 655 |
} |
| 656 |
|
| 657 |
/* Test PyUnicode_DecodeUTF32() */ |
| 658 |
static PyObject * |
| 659 |
unicode_decodeutf32(PyObject *self, PyObject *args) |
| 660 |
{ |
| 661 |
const char *data; |
| 662 |
Py_ssize_t size; |
| 663 |
const char *errors = NULL; |
| 664 |
int byteorder = UNINITIALIZED_INT; |
| 665 |
PyObject *result; |
| 666 |
|
| 667 |
if (!PyArg_ParseTuple(args, "iy#|z", &byteorder, &data, &size, &errors)) |
| 668 |
return NULL; |
| 669 |
|
| 670 |
result = PyUnicode_DecodeUTF32(data, size, errors, &byteorder); |
| 671 |
if (!result) { |
| 672 |
return NULL; |
| 673 |
} |
| 674 |
return Py_BuildValue("(iN)", byteorder, result); |
| 675 |
} |
| 676 |
|
| 677 |
/* Test PyUnicode_DecodeUTF32Stateful() */ |
| 678 |
static PyObject * |
| 679 |
unicode_decodeutf32stateful(PyObject *self, PyObject *args) |
| 680 |
{ |
| 681 |
const char *data; |
| 682 |
Py_ssize_t size; |
| 683 |
const char *errors = NULL; |
| 684 |
int byteorder = UNINITIALIZED_INT; |
| 685 |
Py_ssize_t consumed = UNINITIALIZED_SIZE; |
| 686 |
PyObject *result; |
| 687 |
|
| 688 |
if (!PyArg_ParseTuple(args, "iy#|z", &byteorder, &data, &size, &errors)) |
| 689 |
return NULL; |
| 690 |
|
| 691 |
result = PyUnicode_DecodeUTF32Stateful(data, size, errors, &byteorder, &consumed); |
| 692 |
if (!result) { |
| 693 |
assert(consumed == UNINITIALIZED_SIZE); |
| 694 |
return NULL; |
| 695 |
} |
| 696 |
return Py_BuildValue("(iNn)", byteorder, result, consumed); |
| 697 |
} |
| 698 |
|
| 699 |
/* Test PyUnicode_AsUTF32String() */ |
| 700 |
static PyObject * |
| 701 |
unicode_asutf32string(PyObject *self, PyObject *arg) |
| 702 |
{ |
| 703 |
NULLABLE(arg); |
| 704 |
return PyUnicode_AsUTF32String(arg); |
| 705 |
} |
| 706 |
|
| 707 |
/* Test PyUnicode_DecodeUTF16() */ |
| 708 |
static PyObject * |
| 709 |
unicode_decodeutf16(PyObject *self, PyObject *args) |
| 710 |
{ |
| 711 |
const char *data; |
| 712 |
Py_ssize_t size; |
| 713 |
const char *errors = NULL; |
| 714 |
int byteorder = UNINITIALIZED_INT; |
| 715 |
PyObject *result; |
| 716 |
|
| 717 |
if (!PyArg_ParseTuple(args, "iy#|z", &byteorder, &data, &size, &errors)) |
| 718 |
return NULL; |
| 719 |
|
| 720 |
result = PyUnicode_DecodeUTF16(data, size, errors, &byteorder); |
| 721 |
if (!result) { |
| 722 |
return NULL; |
| 723 |
} |
| 724 |
return Py_BuildValue("(iN)", byteorder, result); |
| 725 |
} |
| 726 |
|
| 727 |
/* Test PyUnicode_DecodeUTF16Stateful() */ |
| 728 |
static PyObject * |
| 729 |
unicode_decodeutf16stateful(PyObject *self, PyObject *args) |
| 730 |
{ |
| 731 |
const char *data; |
| 732 |
Py_ssize_t size; |
| 733 |
const char *errors = NULL; |
| 734 |
int byteorder = UNINITIALIZED_INT; |
| 735 |
Py_ssize_t consumed = UNINITIALIZED_SIZE; |
| 736 |
PyObject *result; |
| 737 |
|
| 738 |
if (!PyArg_ParseTuple(args, "iy#|z", &byteorder, &data, &size, &errors)) |
| 739 |
return NULL; |
| 740 |
|
| 741 |
result = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder, &consumed); |
| 742 |
if (!result) { |
| 743 |
assert(consumed == UNINITIALIZED_SIZE); |
| 744 |
return NULL; |
| 745 |
} |
| 746 |
return Py_BuildValue("(iNn)", byteorder, result, consumed); |
| 747 |
} |
| 748 |
|
| 749 |
/* Test PyUnicode_AsUTF16String() */ |
| 750 |
static PyObject * |
| 751 |
unicode_asutf16string(PyObject *self, PyObject *arg) |
| 752 |
{ |
| 753 |
NULLABLE(arg); |
| 754 |
return PyUnicode_AsUTF16String(arg); |
| 755 |
} |
| 756 |
|
| 757 |
/* Test PyUnicode_DecodeUnicodeEscape() */ |
| 758 |
static PyObject * |
| 759 |
unicode_decodeunicodeescape(PyObject *self, PyObject *args) |
| 760 |
{ |
| 761 |
const char *data; |
| 762 |
Py_ssize_t size; |
| 763 |
const char *errors = NULL; |
| 764 |
|
| 765 |
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors)) |
| 766 |
return NULL; |
| 767 |
|
| 768 |
return PyUnicode_DecodeUnicodeEscape(data, size, errors); |
| 769 |
} |
| 770 |
|
| 771 |
/* Test PyUnicode_AsUnicodeEscapeString() */ |
| 772 |
static PyObject * |
| 773 |
unicode_asunicodeescapestring(PyObject *self, PyObject *arg) |
| 774 |
{ |
| 775 |
NULLABLE(arg); |
| 776 |
return PyUnicode_AsUnicodeEscapeString(arg); |
| 777 |
} |
| 778 |
|
| 779 |
static PyObject * |
| 780 |
unicode_decoderawunicodeescape(PyObject *self, PyObject *args) |
| 781 |
{ |
| 782 |
const char *data; |
| 783 |
Py_ssize_t size; |
| 784 |
const char *errors = NULL; |
| 785 |
|
| 786 |
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors)) |
| 787 |
return NULL; |
| 788 |
|
| 789 |
return PyUnicode_DecodeRawUnicodeEscape(data, size, errors); |
| 790 |
} |
| 791 |
|
| 792 |
/* Test PyUnicode_AsRawUnicodeEscapeString() */ |
| 793 |
static PyObject * |
| 794 |
unicode_asrawunicodeescapestring(PyObject *self, PyObject *arg) |
| 795 |
{ |
| 796 |
NULLABLE(arg); |
| 797 |
return PyUnicode_AsRawUnicodeEscapeString(arg); |
| 798 |
} |
| 799 |
|
| 800 |
static PyObject * |
| 801 |
unicode_decodelatin1(PyObject *self, PyObject *args) |
| 802 |
{ |
| 803 |
const char *data; |
| 804 |
Py_ssize_t size; |
| 805 |
const char *errors = NULL; |
| 806 |
|
| 807 |
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors)) |
| 808 |
return NULL; |
| 809 |
|
| 810 |
return PyUnicode_DecodeLatin1(data, size, errors); |
| 811 |
} |
| 812 |
|
| 813 |
/* Test PyUnicode_AsLatin1String() */ |
| 814 |
static PyObject * |
| 815 |
unicode_aslatin1string(PyObject *self, PyObject *arg) |
| 816 |
{ |
| 817 |
NULLABLE(arg); |
| 818 |
return PyUnicode_AsLatin1String(arg); |
| 819 |
} |
| 820 |
|
| 821 |
/* Test PyUnicode_DecodeASCII() */ |
| 822 |
static PyObject * |
| 823 |
unicode_decodeascii(PyObject *self, PyObject *args) |
| 824 |
{ |
| 825 |
const char *data; |
| 826 |
Py_ssize_t size; |
| 827 |
const char *errors = NULL; |
| 828 |
|
| 829 |
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors)) |
| 830 |
return NULL; |
| 831 |
|
| 832 |
return PyUnicode_DecodeASCII(data, size, errors); |
| 833 |
} |
| 834 |
|
| 835 |
/* Test PyUnicode_AsASCIIString() */ |
| 836 |
static PyObject * |
| 837 |
unicode_asasciistring(PyObject *self, PyObject *arg) |
| 838 |
{ |
| 839 |
NULLABLE(arg); |
| 840 |
return PyUnicode_AsASCIIString(arg); |
| 841 |
} |
| 842 |
|
| 843 |
/* Test PyUnicode_DecodeCharmap() */ |
| 844 |
static PyObject * |
| 845 |
unicode_decodecharmap(PyObject *self, PyObject *args) |
| 846 |
{ |
| 847 |
const char *data; |
| 848 |
Py_ssize_t size; |
| 849 |
PyObject *mapping; |
| 850 |
const char *errors = NULL; |
| 851 |
|
| 852 |
if (!PyArg_ParseTuple(args, "y#O|z", &data, &size, &mapping, &errors)) |
| 853 |
return NULL; |
| 854 |
|
| 855 |
NULLABLE(mapping); |
| 856 |
return PyUnicode_DecodeCharmap(data, size, mapping, errors); |
| 857 |
} |
| 858 |
|
| 859 |
/* Test PyUnicode_AsCharmapString() */ |
| 860 |
static PyObject * |
| 861 |
unicode_ascharmapstring(PyObject *self, PyObject *args) |
| 862 |
{ |
| 863 |
PyObject *unicode; |
| 864 |
PyObject *mapping; |
| 865 |
|
| 866 |
if (!PyArg_ParseTuple(args, "OO", &unicode, &mapping)) |
| 867 |
return NULL; |
| 868 |
|
| 869 |
NULLABLE(unicode); |
| 870 |
NULLABLE(mapping); |
| 871 |
return PyUnicode_AsCharmapString(unicode, mapping); |
| 872 |
} |
| 873 |
|
| 874 |
#ifdef MS_WINDOWS |
| 875 |
|
| 876 |
/* Test PyUnicode_DecodeMBCS() */ |
| 877 |
static PyObject * |
| 878 |
unicode_decodembcs(PyObject *self, PyObject *args) |
| 879 |
{ |
| 880 |
const char *data; |
| 881 |
Py_ssize_t size; |
| 882 |
const char *errors = NULL; |
| 883 |
|
| 884 |
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors)) |
| 885 |
return NULL; |
| 886 |
|
| 887 |
return PyUnicode_DecodeMBCS(data, size, errors); |
| 888 |
} |
| 889 |
|
| 890 |
/* Test PyUnicode_DecodeMBCSStateful() */ |
| 891 |
static PyObject * |
| 892 |
unicode_decodembcsstateful(PyObject *self, PyObject *args) |
| 893 |
{ |
| 894 |
const char *data; |
| 895 |
Py_ssize_t size; |
| 896 |
const char *errors = NULL; |
| 897 |
Py_ssize_t consumed = UNINITIALIZED_SIZE; |
| 898 |
PyObject *result; |
| 899 |
|
| 900 |
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors)) |
| 901 |
return NULL; |
| 902 |
|
| 903 |
result = PyUnicode_DecodeMBCSStateful(data, size, errors, &consumed); |
| 904 |
if (!result) { |
| 905 |
assert(consumed == UNINITIALIZED_SIZE); |
| 906 |
return NULL; |
| 907 |
} |
| 908 |
return Py_BuildValue("(Nn)", result, consumed); |
| 909 |
} |
| 910 |
|
| 911 |
/* Test PyUnicode_DecodeCodePageStateful() */ |
| 912 |
static PyObject * |
| 913 |
unicode_decodecodepagestateful(PyObject *self, PyObject *args) |
| 914 |
{ |
| 915 |
int code_page; |
| 916 |
const char *data; |
| 917 |
Py_ssize_t size; |
| 918 |
const char *errors = NULL; |
| 919 |
Py_ssize_t consumed = UNINITIALIZED_SIZE; |
| 920 |
PyObject *result; |
| 921 |
|
| 922 |
if (!PyArg_ParseTuple(args, "iy#|z", &code_page, &data, &size, &errors)) |
| 923 |
return NULL; |
| 924 |
|
| 925 |
result = PyUnicode_DecodeCodePageStateful(code_page, data, size, errors, &consumed); |
| 926 |
if (!result) { |
| 927 |
assert(consumed == UNINITIALIZED_SIZE); |
| 928 |
return NULL; |
| 929 |
} |
| 930 |
return Py_BuildValue("(Nn)", result, consumed); |
| 931 |
} |
| 932 |
|
| 933 |
/* Test PyUnicode_AsMBCSString() */ |
| 934 |
static PyObject * |
| 935 |
unicode_asmbcsstring(PyObject *self, PyObject *arg) |
| 936 |
{ |
| 937 |
NULLABLE(arg); |
| 938 |
return PyUnicode_AsMBCSString(arg); |
| 939 |
} |
| 940 |
|
| 941 |
/* Test PyUnicode_EncodeCodePage() */ |
| 942 |
static PyObject * |
| 943 |
unicode_encodecodepage(PyObject *self, PyObject *args) |
| 944 |
{ |
| 945 |
int code_page; |
| 946 |
PyObject *unicode; |
| 947 |
const char *errors; |
| 948 |
|
| 949 |
if (!PyArg_ParseTuple(args, "iO|z", &code_page, &unicode, &errors)) |
| 950 |
return NULL; |
| 951 |
|
| 952 |
NULLABLE(unicode); |
| 953 |
return PyUnicode_EncodeCodePage(code_page, unicode, errors); |
| 954 |
} |
| 955 |
|
| 956 |
#endif /* MS_WINDOWS */ |
| 957 |
|
| 958 |
/* Test PyUnicode_DecodeLocaleAndSize() */ |
| 959 |
static PyObject * |
| 960 |
unicode_decodelocaleandsize(PyObject *self, PyObject *args) |
| 961 |
{ |
| 962 |
const char *data; |
| 963 |
Py_ssize_t size; |
| 964 |
const char *errors; |
| 965 |
|
| 966 |
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors)) |
| 967 |
return NULL; |
| 968 |
|
| 969 |
return PyUnicode_DecodeLocaleAndSize(data, size, errors); |
| 970 |
} |
| 971 |
|
| 972 |
/* Test PyUnicode_DecodeLocale() */ |
| 973 |
static PyObject * |
| 974 |
unicode_decodelocale(PyObject *self, PyObject *args) |
| 975 |
{ |
| 976 |
const char *data; |
| 977 |
Py_ssize_t size; |
| 978 |
const char *errors; |
| 979 |
|
| 980 |
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors)) |
| 981 |
return NULL; |
| 982 |
|
| 983 |
return PyUnicode_DecodeLocale(data, errors); |
| 984 |
} |
| 985 |
|
| 986 |
/* Test PyUnicode_EncodeLocale() */ |
| 987 |
static PyObject * |
| 988 |
unicode_encodelocale(PyObject *self, PyObject *args) |
| 989 |
{ |
| 990 |
PyObject *unicode; |
| 991 |
const char *errors; |
| 992 |
|
| 993 |
if (!PyArg_ParseTuple(args, "O|z", &unicode, &errors)) |
| 994 |
return NULL; |
| 995 |
|
| 996 |
NULLABLE(unicode); |
| 997 |
return PyUnicode_EncodeLocale(unicode, errors); |
| 998 |
} |
| 999 |
|
| 1000 |
/* Test PyUnicode_DecodeFSDefault() */ |
| 1001 |
static PyObject * |
| 1002 |
unicode_decodefsdefault(PyObject *self, PyObject *args) |
| 1003 |
{ |
| 1004 |
const char *data; |
| 1005 |
Py_ssize_t size; |
| 1006 |
|
| 1007 |
if (!PyArg_ParseTuple(args, "y#", &data, &size)) |
| 1008 |
return NULL; |
| 1009 |
|
| 1010 |
return PyUnicode_DecodeFSDefault(data); |
| 1011 |
} |
| 1012 |
|
| 1013 |
/* Test PyUnicode_DecodeFSDefaultAndSize() */ |
| 1014 |
static PyObject * |
| 1015 |
unicode_decodefsdefaultandsize(PyObject *self, PyObject *args) |
| 1016 |
{ |
| 1017 |
const char *data; |
| 1018 |
Py_ssize_t size; |
| 1019 |
|
| 1020 |
if (!PyArg_ParseTuple(args, "y#|n", &data, &size, &size)) |
| 1021 |
return NULL; |
| 1022 |
|
| 1023 |
return PyUnicode_DecodeFSDefaultAndSize(data, size); |
| 1024 |
} |
| 1025 |
|
| 1026 |
/* Test PyUnicode_EncodeFSDefault() */ |
| 1027 |
static PyObject * |
| 1028 |
unicode_encodefsdefault(PyObject *self, PyObject *arg) |
| 1029 |
{ |
| 1030 |
NULLABLE(arg); |
| 1031 |
return PyUnicode_EncodeFSDefault(arg); |
| 1032 |
} |
| 1033 |
|
| 1034 |
/* Test PyUnicode_Concat() */ |
| 1035 |
static PyObject * |
| 1036 |
unicode_concat(PyObject *self, PyObject *args) |
| 1037 |
{ |
| 1038 |
PyObject *left; |
| 1039 |
PyObject *right; |
| 1040 |
|
| 1041 |
if (!PyArg_ParseTuple(args, "OO", &left, &right)) |
| 1042 |
return NULL; |
| 1043 |
|
| 1044 |
NULLABLE(left); |
| 1045 |
NULLABLE(right); |
| 1046 |
return PyUnicode_Concat(left, right); |
| 1047 |
} |
| 1048 |
|
| 1049 |
/* Test PyUnicode_Split() */ |
| 1050 |
static PyObject * |
| 1051 |
unicode_split(PyObject *self, PyObject *args) |
| 1052 |
{ |
| 1053 |
PyObject *s; |
| 1054 |
PyObject *sep; |
| 1055 |
Py_ssize_t maxsplit = -1; |
| 1056 |
|
| 1057 |
if (!PyArg_ParseTuple(args, "OO|n", &s, &sep, &maxsplit)) |
| 1058 |
return NULL; |
| 1059 |
|
| 1060 |
NULLABLE(s); |
| 1061 |
NULLABLE(sep); |
| 1062 |
return PyUnicode_Split(s, sep, maxsplit); |
| 1063 |
} |
| 1064 |
|
| 1065 |
/* Test PyUnicode_RSplit() */ |
| 1066 |
static PyObject * |
| 1067 |
unicode_rsplit(PyObject *self, PyObject *args) |
| 1068 |
{ |
| 1069 |
PyObject *s; |
| 1070 |
PyObject *sep; |
| 1071 |
Py_ssize_t maxsplit = -1; |
| 1072 |
|
| 1073 |
if (!PyArg_ParseTuple(args, "OO|n", &s, &sep, &maxsplit)) |
| 1074 |
return NULL; |
| 1075 |
|
| 1076 |
NULLABLE(s); |
| 1077 |
NULLABLE(sep); |
| 1078 |
return PyUnicode_RSplit(s, sep, maxsplit); |
| 1079 |
} |
| 1080 |
|
| 1081 |
/* Test PyUnicode_Splitlines() */ |
| 1082 |
static PyObject * |
| 1083 |
unicode_splitlines(PyObject *self, PyObject *args) |
| 1084 |
{ |
| 1085 |
PyObject *s; |
| 1086 |
int keepends = 0; |
| 1087 |
|
| 1088 |
if (!PyArg_ParseTuple(args, "O|i", &s, &keepends)) |
| 1089 |
return NULL; |
| 1090 |
|
| 1091 |
NULLABLE(s); |
| 1092 |
return PyUnicode_Splitlines(s, keepends); |
| 1093 |
} |
| 1094 |
|
| 1095 |
/* Test PyUnicode_Partition() */ |
| 1096 |
static PyObject * |
| 1097 |
unicode_partition(PyObject *self, PyObject *args) |
| 1098 |
{ |
| 1099 |
PyObject *s; |
| 1100 |
PyObject *sep; |
| 1101 |
|
| 1102 |
if (!PyArg_ParseTuple(args, "OO", &s, &sep)) |
| 1103 |
return NULL; |
| 1104 |
|
| 1105 |
NULLABLE(s); |
| 1106 |
NULLABLE(sep); |
| 1107 |
return PyUnicode_Partition(s, sep); |
| 1108 |
} |
| 1109 |
|
| 1110 |
/* Test PyUnicode_RPartition() */ |
| 1111 |
static PyObject * |
| 1112 |
unicode_rpartition(PyObject *self, PyObject *args) |
| 1113 |
{ |
| 1114 |
PyObject *s; |
| 1115 |
PyObject *sep; |
| 1116 |
|
| 1117 |
if (!PyArg_ParseTuple(args, "OO", &s, &sep)) |
| 1118 |
return NULL; |
| 1119 |
|
| 1120 |
NULLABLE(s); |
| 1121 |
NULLABLE(sep); |
| 1122 |
return PyUnicode_RPartition(s, sep); |
| 1123 |
} |
| 1124 |
|
| 1125 |
/* Test PyUnicode_Translate() */ |
| 1126 |
static PyObject * |
| 1127 |
unicode_translate(PyObject *self, PyObject *args) |
| 1128 |
{ |
| 1129 |
PyObject *obj; |
| 1130 |
PyObject *table; |
| 1131 |
const char *errors = NULL; |
| 1132 |
|
| 1133 |
if (!PyArg_ParseTuple(args, "OO|z", &obj, &table, &errors)) |
| 1134 |
return NULL; |
| 1135 |
|
| 1136 |
NULLABLE(obj); |
| 1137 |
NULLABLE(table); |
| 1138 |
return PyUnicode_Translate(obj, table, errors); |
| 1139 |
} |
| 1140 |
|
| 1141 |
/* Test PyUnicode_Join() */ |
| 1142 |
static PyObject * |
| 1143 |
unicode_join(PyObject *self, PyObject *args) |
| 1144 |
{ |
| 1145 |
PyObject *sep; |
| 1146 |
PyObject *seq; |
| 1147 |
|
| 1148 |
if (!PyArg_ParseTuple(args, "OO", &sep, &seq)) |
| 1149 |
return NULL; |
| 1150 |
|
| 1151 |
NULLABLE(sep); |
| 1152 |
NULLABLE(seq); |
| 1153 |
return PyUnicode_Join(sep, seq); |
| 1154 |
} |
| 1155 |
|
| 1156 |
/* Test PyUnicode_Count() */ |
| 1157 |
static PyObject * |
| 1158 |
unicode_count(PyObject *self, PyObject *args) |
| 1159 |
{ |
| 1160 |
PyObject *str; |
| 1161 |
PyObject *substr; |
| 1162 |
Py_ssize_t start; |
| 1163 |
Py_ssize_t end; |
| 1164 |
|
| 1165 |
if (!PyArg_ParseTuple(args, "OOnn", &str, &substr, &start, &end)) |
| 1166 |
return NULL; |
| 1167 |
|
| 1168 |
NULLABLE(str); |
| 1169 |
NULLABLE(substr); |
| 1170 |
RETURN_SIZE(PyUnicode_Count(str, substr, start, end)); |
| 1171 |
} |
| 1172 |
|
| 1173 |
/* Test PyUnicode_Find() */ |
| 1174 |
static PyObject * |
| 1175 |
unicode_find(PyObject *self, PyObject *args) |
| 1176 |
{ |
| 1177 |
PyObject *str; |
| 1178 |
PyObject *substr; |
| 1179 |
Py_ssize_t start; |
| 1180 |
Py_ssize_t end; |
| 1181 |
int direction; |
| 1182 |
Py_ssize_t result; |
| 1183 |
|
| 1184 |
if (!PyArg_ParseTuple(args, "OOnni", &str, &substr, &start, &end, &direction)) |
| 1185 |
return NULL; |
| 1186 |
|
| 1187 |
NULLABLE(str); |
| 1188 |
NULLABLE(substr); |
| 1189 |
result = PyUnicode_Find(str, substr, start, end, direction); |
| 1190 |
if (result == -2) { |
| 1191 |
assert(PyErr_Occurred()); |
| 1192 |
return NULL; |
| 1193 |
} |
| 1194 |
assert(!PyErr_Occurred()); |
| 1195 |
return PyLong_FromSsize_t(result); |
| 1196 |
} |
| 1197 |
|
| 1198 |
/* Test PyUnicode_Tailmatch() */ |
| 1199 |
static PyObject * |
| 1200 |
unicode_tailmatch(PyObject *self, PyObject *args) |
| 1201 |
{ |
| 1202 |
PyObject *str; |
| 1203 |
PyObject *substr; |
| 1204 |
Py_ssize_t start; |
| 1205 |
Py_ssize_t end; |
| 1206 |
int direction; |
| 1207 |
|
| 1208 |
if (!PyArg_ParseTuple(args, "OOnni", &str, &substr, &start, &end, &direction)) |
| 1209 |
return NULL; |
| 1210 |
|
| 1211 |
NULLABLE(str); |
| 1212 |
NULLABLE(substr); |
| 1213 |
RETURN_SIZE(PyUnicode_Tailmatch(str, substr, start, end, direction)); |
| 1214 |
} |
| 1215 |
|
| 1216 |
/* Test PyUnicode_FindChar() */ |
| 1217 |
static PyObject * |
| 1218 |
unicode_findchar(PyObject *self, PyObject *args) |
| 1219 |
{ |
| 1220 |
PyObject *str; |
| 1221 |
int direction; |
| 1222 |
unsigned int ch; |
| 1223 |
Py_ssize_t result; |
| 1224 |
Py_ssize_t start, end; |
| 1225 |
|
| 1226 |
if (!PyArg_ParseTuple(args, "OInni:unicode_findchar", &str, &ch, |
| 1227 |
&start, &end, &direction)) { |
| 1228 |
return NULL; |
| 1229 |
} |
| 1230 |
NULLABLE(str); |
| 1231 |
result = PyUnicode_FindChar(str, (Py_UCS4)ch, start, end, direction); |
| 1232 |
if (result == -2) { |
| 1233 |
assert(PyErr_Occurred()); |
| 1234 |
return NULL; |
| 1235 |
} |
| 1236 |
assert(!PyErr_Occurred()); |
| 1237 |
return PyLong_FromSsize_t(result); |
| 1238 |
} |
| 1239 |
|
| 1240 |
/* Test PyUnicode_Replace() */ |
| 1241 |
static PyObject * |
| 1242 |
unicode_replace(PyObject *self, PyObject *args) |
| 1243 |
{ |
| 1244 |
PyObject *str; |
| 1245 |
PyObject *substr; |
| 1246 |
PyObject *replstr; |
| 1247 |
Py_ssize_t maxcount = -1; |
| 1248 |
|
| 1249 |
if (!PyArg_ParseTuple(args, "OOO|n", &str, &substr, &replstr, &maxcount)) |
| 1250 |
return NULL; |
| 1251 |
|
| 1252 |
NULLABLE(str); |
| 1253 |
NULLABLE(substr); |
| 1254 |
NULLABLE(replstr); |
| 1255 |
return PyUnicode_Replace(str, substr, replstr, maxcount); |
| 1256 |
} |
| 1257 |
|
| 1258 |
/* Test PyUnicode_Compare() */ |
| 1259 |
static PyObject * |
| 1260 |
unicode_compare(PyObject *self, PyObject *args) |
| 1261 |
{ |
| 1262 |
PyObject *left; |
| 1263 |
PyObject *right; |
| 1264 |
int result; |
| 1265 |
|
| 1266 |
if (!PyArg_ParseTuple(args, "OO", &left, &right)) |
| 1267 |
return NULL; |
| 1268 |
|
| 1269 |
NULLABLE(left); |
| 1270 |
NULLABLE(right); |
| 1271 |
result = PyUnicode_Compare(left, right); |
| 1272 |
if (result == -1 && PyErr_Occurred()) { |
| 1273 |
return NULL; |
| 1274 |
} |
| 1275 |
assert(!PyErr_Occurred()); |
| 1276 |
return PyLong_FromLong(result); |
| 1277 |
} |
| 1278 |
|
| 1279 |
/* Test PyUnicode_CompareWithASCIIString() */ |
| 1280 |
static PyObject * |
| 1281 |
unicode_comparewithasciistring(PyObject *self, PyObject *args) |
| 1282 |
{ |
| 1283 |
PyObject *left; |
| 1284 |
const char *right = NULL; |
| 1285 |
Py_ssize_t right_len; |
| 1286 |
int result; |
| 1287 |
|
| 1288 |
if (!PyArg_ParseTuple(args, "O|y#", &left, &right, &right_len)) |
| 1289 |
return NULL; |
| 1290 |
|
| 1291 |
NULLABLE(left); |
| 1292 |
result = PyUnicode_CompareWithASCIIString(left, right); |
| 1293 |
if (result == -1 && PyErr_Occurred()) { |
| 1294 |
return NULL; |
| 1295 |
} |
| 1296 |
return PyLong_FromLong(result); |
| 1297 |
} |
| 1298 |
|
| 1299 |
/* Test PyUnicode_EqualToUTF8() */ |
| 1300 |
static PyObject * |
| 1301 |
unicode_equaltoutf8(PyObject *self, PyObject *args) |
| 1302 |
{ |
| 1303 |
PyObject *left; |
| 1304 |
const char *right = NULL; |
| 1305 |
Py_ssize_t right_len; |
| 1306 |
int result; |
| 1307 |
|
| 1308 |
if (!PyArg_ParseTuple(args, "Oz#", &left, &right, &right_len)) { |
| 1309 |
return NULL; |
| 1310 |
} |
| 1311 |
|
| 1312 |
NULLABLE(left); |
| 1313 |
result = PyUnicode_EqualToUTF8(left, right); |
| 1314 |
assert(!PyErr_Occurred()); |
| 1315 |
return PyLong_FromLong(result); |
| 1316 |
} |
| 1317 |
|
| 1318 |
/* Test PyUnicode_EqualToUTF8AndSize() */ |
| 1319 |
static PyObject * |
| 1320 |
unicode_equaltoutf8andsize(PyObject *self, PyObject *args) |
| 1321 |
{ |
| 1322 |
PyObject *left; |
| 1323 |
const char *right = NULL; |
| 1324 |
Py_ssize_t right_len; |
| 1325 |
Py_ssize_t size = -100; |
| 1326 |
int result; |
| 1327 |
|
| 1328 |
if (!PyArg_ParseTuple(args, "Oz#|n", &left, &right, &right_len, &size)) { |
| 1329 |
return NULL; |
| 1330 |
} |
| 1331 |
|
| 1332 |
NULLABLE(left); |
| 1333 |
if (size == -100) { |
| 1334 |
size = right_len; |
| 1335 |
} |
| 1336 |
result = PyUnicode_EqualToUTF8AndSize(left, right, size); |
| 1337 |
assert(!PyErr_Occurred()); |
| 1338 |
return PyLong_FromLong(result); |
| 1339 |
} |
| 1340 |
|
| 1341 |
/* Test PyUnicode_RichCompare() */ |
| 1342 |
static PyObject * |
| 1343 |
unicode_richcompare(PyObject *self, PyObject *args) |
| 1344 |
{ |
| 1345 |
PyObject *left; |
| 1346 |
PyObject *right; |
| 1347 |
int op; |
| 1348 |
|
| 1349 |
if (!PyArg_ParseTuple(args, "OOi", &left, &right, &op)) |
| 1350 |
return NULL; |
| 1351 |
|
| 1352 |
NULLABLE(left); |
| 1353 |
NULLABLE(right); |
| 1354 |
return PyUnicode_RichCompare(left, right, op); |
| 1355 |
} |
| 1356 |
|
| 1357 |
/* Test PyUnicode_Format() */ |
| 1358 |
static PyObject * |
| 1359 |
unicode_format(PyObject *self, PyObject *args) |
| 1360 |
{ |
| 1361 |
PyObject *format; |
| 1362 |
PyObject *fargs; |
| 1363 |
|
| 1364 |
if (!PyArg_ParseTuple(args, "OO", &format, &fargs)) |
| 1365 |
return NULL; |
| 1366 |
|
| 1367 |
NULLABLE(format); |
| 1368 |
NULLABLE(fargs); |
| 1369 |
return PyUnicode_Format(format, fargs); |
| 1370 |
} |
| 1371 |
|
| 1372 |
/* Test PyUnicode_Contains() */ |
| 1373 |
static PyObject * |
| 1374 |
unicode_contains(PyObject *self, PyObject *args) |
| 1375 |
{ |
| 1376 |
PyObject *container; |
| 1377 |
PyObject *element; |
| 1378 |
|
| 1379 |
if (!PyArg_ParseTuple(args, "OO", &container, &element)) |
| 1380 |
return NULL; |
| 1381 |
|
| 1382 |
NULLABLE(container); |
| 1383 |
NULLABLE(element); |
| 1384 |
RETURN_INT(PyUnicode_Contains(container, element)); |
| 1385 |
} |
| 1386 |
|
| 1387 |
/* Test PyUnicode_IsIdentifier() */ |
| 1388 |
static PyObject * |
| 1389 |
unicode_isidentifier(PyObject *self, PyObject *arg) |
| 1390 |
{ |
| 1391 |
NULLABLE(arg); |
| 1392 |
RETURN_INT(PyUnicode_IsIdentifier(arg)); |
| 1393 |
} |
| 1394 |
|
| 1395 |
|
| 1396 |
static int |
| 1397 |
check_raised_systemerror(PyObject *result, char* msg) |
| 1398 |
{ |
| 1399 |
if (result) { |
| 1400 |
// no exception |
| 1401 |
PyErr_Format(PyExc_AssertionError, |
| 1402 |
"SystemError not raised: %s", |
| 1403 |
msg); |
| 1404 |
return 0; |
| 1405 |
} |
| 1406 |
if (PyErr_ExceptionMatches(PyExc_SystemError)) { |
| 1407 |
// expected exception |
| 1408 |
PyErr_Clear(); |
| 1409 |
return 1; |
| 1410 |
} |
| 1411 |
// unexpected exception |
| 1412 |
return 0; |
| 1413 |
} |
| 1414 |
|
| 1415 |
static PyObject * |
| 1416 |
test_string_from_format(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 1417 |
{ |
| 1418 |
PyObject *result; |
| 1419 |
PyObject *unicode = PyUnicode_FromString("None"); |
| 1420 |
|
| 1421 |
#define CHECK_FORMAT_2(FORMAT, EXPECTED, ARG1, ARG2) \ |
| 1422 |
result = PyUnicode_FromFormat(FORMAT, ARG1, ARG2); \ |
| 1423 |
if (EXPECTED == NULL) { \ |
| 1424 |
if (!check_raised_systemerror(result, FORMAT)) { \ |
| 1425 |
goto Fail; \ |
| 1426 |
} \ |
| 1427 |
} \ |
| 1428 |
else if (result == NULL) \ |
| 1429 |
return NULL; \ |
| 1430 |
else if (PyUnicode_CompareWithASCIIString(result, EXPECTED) != 0) { \ |
| 1431 |
PyObject *utf8 = PyUnicode_AsUTF8String(result); \ |
| 1432 |
PyErr_Format(PyExc_AssertionError, \ |
| 1433 |
"test_string_from_format: failed at \"%s\" " \ |
| 1434 |
"expected \"%s\" got \"%s\"", \ |
| 1435 |
FORMAT, EXPECTED, utf8); \ |
| 1436 |
Py_XDECREF(utf8); \ |
| 1437 |
goto Fail; \ |
| 1438 |
} \ |
| 1439 |
Py_XDECREF(result) |
| 1440 |
|
| 1441 |
#define CHECK_FORMAT_1(FORMAT, EXPECTED, ARG) \ |
| 1442 |
CHECK_FORMAT_2(FORMAT, EXPECTED, ARG, 0) |
| 1443 |
|
| 1444 |
#define CHECK_FORMAT_0(FORMAT, EXPECTED) \ |
| 1445 |
CHECK_FORMAT_2(FORMAT, EXPECTED, 0, 0) |
| 1446 |
|
| 1447 |
// Unrecognized |
| 1448 |
CHECK_FORMAT_2("%u %? %u", NULL, 1, 2); |
| 1449 |
|
| 1450 |
// "%%" (options are rejected) |
| 1451 |
CHECK_FORMAT_0( "%%", "%"); |
| 1452 |
CHECK_FORMAT_0( "%0%", NULL); |
| 1453 |
CHECK_FORMAT_0("%00%", NULL); |
| 1454 |
CHECK_FORMAT_0( "%2%", NULL); |
| 1455 |
CHECK_FORMAT_0("%02%", NULL); |
| 1456 |
CHECK_FORMAT_0("%.0%", NULL); |
| 1457 |
CHECK_FORMAT_0("%.2%", NULL); |
| 1458 |
|
| 1459 |
// "%c" |
| 1460 |
CHECK_FORMAT_1( "%c", "c", 'c'); |
| 1461 |
CHECK_FORMAT_1( "%0c", "c", 'c'); |
| 1462 |
CHECK_FORMAT_1("%00c", "c", 'c'); |
| 1463 |
CHECK_FORMAT_1( "%2c", NULL, 'c'); |
| 1464 |
CHECK_FORMAT_1("%02c", NULL, 'c'); |
| 1465 |
CHECK_FORMAT_1("%.0c", NULL, 'c'); |
| 1466 |
CHECK_FORMAT_1("%.2c", NULL, 'c'); |
| 1467 |
|
| 1468 |
// Integers |
| 1469 |
CHECK_FORMAT_1("%d", "123", (int)123); |
| 1470 |
CHECK_FORMAT_1("%i", "123", (int)123); |
| 1471 |
CHECK_FORMAT_1("%u", "123", (unsigned int)123); |
| 1472 |
CHECK_FORMAT_1("%x", "7b", (unsigned int)123); |
| 1473 |
CHECK_FORMAT_1("%X", "7B", (unsigned int)123); |
| 1474 |
CHECK_FORMAT_1("%o", "173", (unsigned int)123); |
| 1475 |
CHECK_FORMAT_1("%ld", "123", (long)123); |
| 1476 |
CHECK_FORMAT_1("%li", "123", (long)123); |
| 1477 |
CHECK_FORMAT_1("%lu", "123", (unsigned long)123); |
| 1478 |
CHECK_FORMAT_1("%lx", "7b", (unsigned long)123); |
| 1479 |
CHECK_FORMAT_1("%lX", "7B", (unsigned long)123); |
| 1480 |
CHECK_FORMAT_1("%lo", "173", (unsigned long)123); |
| 1481 |
CHECK_FORMAT_1("%lld", "123", (long long)123); |
| 1482 |
CHECK_FORMAT_1("%lli", "123", (long long)123); |
| 1483 |
CHECK_FORMAT_1("%llu", "123", (unsigned long long)123); |
| 1484 |
CHECK_FORMAT_1("%llx", "7b", (unsigned long long)123); |
| 1485 |
CHECK_FORMAT_1("%llX", "7B", (unsigned long long)123); |
| 1486 |
CHECK_FORMAT_1("%llo", "173", (unsigned long long)123); |
| 1487 |
CHECK_FORMAT_1("%zd", "123", (Py_ssize_t)123); |
| 1488 |
CHECK_FORMAT_1("%zi", "123", (Py_ssize_t)123); |
| 1489 |
CHECK_FORMAT_1("%zu", "123", (size_t)123); |
| 1490 |
CHECK_FORMAT_1("%zx", "7b", (size_t)123); |
| 1491 |
CHECK_FORMAT_1("%zX", "7B", (size_t)123); |
| 1492 |
CHECK_FORMAT_1("%zo", "173", (size_t)123); |
| 1493 |
CHECK_FORMAT_1("%td", "123", (ptrdiff_t)123); |
| 1494 |
CHECK_FORMAT_1("%ti", "123", (ptrdiff_t)123); |
| 1495 |
CHECK_FORMAT_1("%tu", "123", (ptrdiff_t)123); |
| 1496 |
CHECK_FORMAT_1("%tx", "7b", (ptrdiff_t)123); |
| 1497 |
CHECK_FORMAT_1("%tX", "7B", (ptrdiff_t)123); |
| 1498 |
CHECK_FORMAT_1("%to", "173", (ptrdiff_t)123); |
| 1499 |
CHECK_FORMAT_1("%jd", "123", (intmax_t)123); |
| 1500 |
CHECK_FORMAT_1("%ji", "123", (intmax_t)123); |
| 1501 |
CHECK_FORMAT_1("%ju", "123", (uintmax_t)123); |
| 1502 |
CHECK_FORMAT_1("%jx", "7b", (uintmax_t)123); |
| 1503 |
CHECK_FORMAT_1("%jX", "7B", (uintmax_t)123); |
| 1504 |
CHECK_FORMAT_1("%jo", "173", (uintmax_t)123); |
| 1505 |
|
| 1506 |
CHECK_FORMAT_1("%d", "-123", (int)-123); |
| 1507 |
CHECK_FORMAT_1("%i", "-123", (int)-123); |
| 1508 |
CHECK_FORMAT_1("%ld", "-123", (long)-123); |
| 1509 |
CHECK_FORMAT_1("%li", "-123", (long)-123); |
| 1510 |
CHECK_FORMAT_1("%lld", "-123", (long long)-123); |
| 1511 |
CHECK_FORMAT_1("%lli", "-123", (long long)-123); |
| 1512 |
CHECK_FORMAT_1("%zd", "-123", (Py_ssize_t)-123); |
| 1513 |
CHECK_FORMAT_1("%zi", "-123", (Py_ssize_t)-123); |
| 1514 |
CHECK_FORMAT_1("%td", "-123", (ptrdiff_t)-123); |
| 1515 |
CHECK_FORMAT_1("%ti", "-123", (ptrdiff_t)-123); |
| 1516 |
CHECK_FORMAT_1("%jd", "-123", (intmax_t)-123); |
| 1517 |
CHECK_FORMAT_1("%ji", "-123", (intmax_t)-123); |
| 1518 |
|
| 1519 |
// Integers: width < length |
| 1520 |
CHECK_FORMAT_1("%1d", "123", (int)123); |
| 1521 |
CHECK_FORMAT_1("%1i", "123", (int)123); |
| 1522 |
CHECK_FORMAT_1("%1u", "123", (unsigned int)123); |
| 1523 |
CHECK_FORMAT_1("%1ld", "123", (long)123); |
| 1524 |
CHECK_FORMAT_1("%1li", "123", (long)123); |
| 1525 |
CHECK_FORMAT_1("%1lu", "123", (unsigned long)123); |
| 1526 |
CHECK_FORMAT_1("%1lld", "123", (long long)123); |
| 1527 |
CHECK_FORMAT_1("%1lli", "123", (long long)123); |
| 1528 |
CHECK_FORMAT_1("%1llu", "123", (unsigned long long)123); |
| 1529 |
CHECK_FORMAT_1("%1zd", "123", (Py_ssize_t)123); |
| 1530 |
CHECK_FORMAT_1("%1zi", "123", (Py_ssize_t)123); |
| 1531 |
CHECK_FORMAT_1("%1zu", "123", (size_t)123); |
| 1532 |
CHECK_FORMAT_1("%1x", "7b", (int)123); |
| 1533 |
|
| 1534 |
CHECK_FORMAT_1("%1d", "-123", (int)-123); |
| 1535 |
CHECK_FORMAT_1("%1i", "-123", (int)-123); |
| 1536 |
CHECK_FORMAT_1("%1ld", "-123", (long)-123); |
| 1537 |
CHECK_FORMAT_1("%1li", "-123", (long)-123); |
| 1538 |
CHECK_FORMAT_1("%1lld", "-123", (long long)-123); |
| 1539 |
CHECK_FORMAT_1("%1lli", "-123", (long long)-123); |
| 1540 |
CHECK_FORMAT_1("%1zd", "-123", (Py_ssize_t)-123); |
| 1541 |
CHECK_FORMAT_1("%1zi", "-123", (Py_ssize_t)-123); |
| 1542 |
|
| 1543 |
// Integers: width > length |
| 1544 |
CHECK_FORMAT_1("%5d", " 123", (int)123); |
| 1545 |
CHECK_FORMAT_1("%5i", " 123", (int)123); |
| 1546 |
CHECK_FORMAT_1("%5u", " 123", (unsigned int)123); |
| 1547 |
CHECK_FORMAT_1("%5ld", " 123", (long)123); |
| 1548 |
CHECK_FORMAT_1("%5li", " 123", (long)123); |
| 1549 |
CHECK_FORMAT_1("%5lu", " 123", (unsigned long)123); |
| 1550 |
CHECK_FORMAT_1("%5lld", " 123", (long long)123); |
| 1551 |
CHECK_FORMAT_1("%5lli", " 123", (long long)123); |
| 1552 |
CHECK_FORMAT_1("%5llu", " 123", (unsigned long long)123); |
| 1553 |
CHECK_FORMAT_1("%5zd", " 123", (Py_ssize_t)123); |
| 1554 |
CHECK_FORMAT_1("%5zi", " 123", (Py_ssize_t)123); |
| 1555 |
CHECK_FORMAT_1("%5zu", " 123", (size_t)123); |
| 1556 |
CHECK_FORMAT_1("%5x", " 7b", (int)123); |
| 1557 |
|
| 1558 |
CHECK_FORMAT_1("%5d", " -123", (int)-123); |
| 1559 |
CHECK_FORMAT_1("%5i", " -123", (int)-123); |
| 1560 |
CHECK_FORMAT_1("%5ld", " -123", (long)-123); |
| 1561 |
CHECK_FORMAT_1("%5li", " -123", (long)-123); |
| 1562 |
CHECK_FORMAT_1("%5lld", " -123", (long long)-123); |
| 1563 |
CHECK_FORMAT_1("%5lli", " -123", (long long)-123); |
| 1564 |
CHECK_FORMAT_1("%5zd", " -123", (Py_ssize_t)-123); |
| 1565 |
CHECK_FORMAT_1("%5zi", " -123", (Py_ssize_t)-123); |
| 1566 |
|
| 1567 |
// Integers: width > length, 0-flag |
| 1568 |
CHECK_FORMAT_1("%05d", "00123", (int)123); |
| 1569 |
CHECK_FORMAT_1("%05i", "00123", (int)123); |
| 1570 |
CHECK_FORMAT_1("%05u", "00123", (unsigned int)123); |
| 1571 |
CHECK_FORMAT_1("%05ld", "00123", (long)123); |
| 1572 |
CHECK_FORMAT_1("%05li", "00123", (long)123); |
| 1573 |
CHECK_FORMAT_1("%05lu", "00123", (unsigned long)123); |
| 1574 |
CHECK_FORMAT_1("%05lld", "00123", (long long)123); |
| 1575 |
CHECK_FORMAT_1("%05lli", "00123", (long long)123); |
| 1576 |
CHECK_FORMAT_1("%05llu", "00123", (unsigned long long)123); |
| 1577 |
CHECK_FORMAT_1("%05zd", "00123", (Py_ssize_t)123); |
| 1578 |
CHECK_FORMAT_1("%05zi", "00123", (Py_ssize_t)123); |
| 1579 |
CHECK_FORMAT_1("%05zu", "00123", (size_t)123); |
| 1580 |
CHECK_FORMAT_1("%05x", "0007b", (int)123); |
| 1581 |
|
| 1582 |
CHECK_FORMAT_1("%05d", "-0123", (int)-123); |
| 1583 |
CHECK_FORMAT_1("%05i", "-0123", (int)-123); |
| 1584 |
CHECK_FORMAT_1("%05ld", "-0123", (long)-123); |
| 1585 |
CHECK_FORMAT_1("%05li", "-0123", (long)-123); |
| 1586 |
CHECK_FORMAT_1("%05lld", "-0123", (long long)-123); |
| 1587 |
CHECK_FORMAT_1("%05lli", "-0123", (long long)-123); |
| 1588 |
CHECK_FORMAT_1("%05zd", "-0123", (Py_ssize_t)-123); |
| 1589 |
CHECK_FORMAT_1("%05zi", "-0123", (Py_ssize_t)-123); |
| 1590 |
|
| 1591 |
// Integers: precision < length |
| 1592 |
CHECK_FORMAT_1("%.1d", "123", (int)123); |
| 1593 |
CHECK_FORMAT_1("%.1i", "123", (int)123); |
| 1594 |
CHECK_FORMAT_1("%.1u", "123", (unsigned int)123); |
| 1595 |
CHECK_FORMAT_1("%.1ld", "123", (long)123); |
| 1596 |
CHECK_FORMAT_1("%.1li", "123", (long)123); |
| 1597 |
CHECK_FORMAT_1("%.1lu", "123", (unsigned long)123); |
| 1598 |
CHECK_FORMAT_1("%.1lld", "123", (long long)123); |
| 1599 |
CHECK_FORMAT_1("%.1lli", "123", (long long)123); |
| 1600 |
CHECK_FORMAT_1("%.1llu", "123", (unsigned long long)123); |
| 1601 |
CHECK_FORMAT_1("%.1zd", "123", (Py_ssize_t)123); |
| 1602 |
CHECK_FORMAT_1("%.1zi", "123", (Py_ssize_t)123); |
| 1603 |
CHECK_FORMAT_1("%.1zu", "123", (size_t)123); |
| 1604 |
CHECK_FORMAT_1("%.1x", "7b", (int)123); |
| 1605 |
|
| 1606 |
CHECK_FORMAT_1("%.1d", "-123", (int)-123); |
| 1607 |
CHECK_FORMAT_1("%.1i", "-123", (int)-123); |
| 1608 |
CHECK_FORMAT_1("%.1ld", "-123", (long)-123); |
| 1609 |
CHECK_FORMAT_1("%.1li", "-123", (long)-123); |
| 1610 |
CHECK_FORMAT_1("%.1lld", "-123", (long long)-123); |
| 1611 |
CHECK_FORMAT_1("%.1lli", "-123", (long long)-123); |
| 1612 |
CHECK_FORMAT_1("%.1zd", "-123", (Py_ssize_t)-123); |
| 1613 |
CHECK_FORMAT_1("%.1zi", "-123", (Py_ssize_t)-123); |
| 1614 |
|
| 1615 |
// Integers: precision > length |
| 1616 |
CHECK_FORMAT_1("%.5d", "00123", (int)123); |
| 1617 |
CHECK_FORMAT_1("%.5i", "00123", (int)123); |
| 1618 |
CHECK_FORMAT_1("%.5u", "00123", (unsigned int)123); |
| 1619 |
CHECK_FORMAT_1("%.5ld", "00123", (long)123); |
| 1620 |
CHECK_FORMAT_1("%.5li", "00123", (long)123); |
| 1621 |
CHECK_FORMAT_1("%.5lu", "00123", (unsigned long)123); |
| 1622 |
CHECK_FORMAT_1("%.5lld", "00123", (long long)123); |
| 1623 |
CHECK_FORMAT_1("%.5lli", "00123", (long long)123); |
| 1624 |
CHECK_FORMAT_1("%.5llu", "00123", (unsigned long long)123); |
| 1625 |
CHECK_FORMAT_1("%.5zd", "00123", (Py_ssize_t)123); |
| 1626 |
CHECK_FORMAT_1("%.5zi", "00123", (Py_ssize_t)123); |
| 1627 |
CHECK_FORMAT_1("%.5zu", "00123", (size_t)123); |
| 1628 |
CHECK_FORMAT_1("%.5x", "0007b", (int)123); |
| 1629 |
|
| 1630 |
CHECK_FORMAT_1("%.5d", "-00123", (int)-123); |
| 1631 |
CHECK_FORMAT_1("%.5i", "-00123", (int)-123); |
| 1632 |
CHECK_FORMAT_1("%.5ld", "-00123", (long)-123); |
| 1633 |
CHECK_FORMAT_1("%.5li", "-00123", (long)-123); |
| 1634 |
CHECK_FORMAT_1("%.5lld", "-00123", (long long)-123); |
| 1635 |
CHECK_FORMAT_1("%.5lli", "-00123", (long long)-123); |
| 1636 |
CHECK_FORMAT_1("%.5zd", "-00123", (Py_ssize_t)-123); |
| 1637 |
CHECK_FORMAT_1("%.5zi", "-00123", (Py_ssize_t)-123); |
| 1638 |
|
| 1639 |
// Integers: width > precision > length |
| 1640 |
CHECK_FORMAT_1("%7.5d", " 00123", (int)123); |
| 1641 |
CHECK_FORMAT_1("%7.5i", " 00123", (int)123); |
| 1642 |
CHECK_FORMAT_1("%7.5u", " 00123", (unsigned int)123); |
| 1643 |
CHECK_FORMAT_1("%7.5ld", " 00123", (long)123); |
| 1644 |
CHECK_FORMAT_1("%7.5li", " 00123", (long)123); |
| 1645 |
CHECK_FORMAT_1("%7.5lu", " 00123", (unsigned long)123); |
| 1646 |
CHECK_FORMAT_1("%7.5lld", " 00123", (long long)123); |
| 1647 |
CHECK_FORMAT_1("%7.5lli", " 00123", (long long)123); |
| 1648 |
CHECK_FORMAT_1("%7.5llu", " 00123", (unsigned long long)123); |
| 1649 |
CHECK_FORMAT_1("%7.5zd", " 00123", (Py_ssize_t)123); |
| 1650 |
CHECK_FORMAT_1("%7.5zi", " 00123", (Py_ssize_t)123); |
| 1651 |
CHECK_FORMAT_1("%7.5zu", " 00123", (size_t)123); |
| 1652 |
CHECK_FORMAT_1("%7.5x", " 0007b", (int)123); |
| 1653 |
|
| 1654 |
CHECK_FORMAT_1("%7.5d", " -00123", (int)-123); |
| 1655 |
CHECK_FORMAT_1("%7.5i", " -00123", (int)-123); |
| 1656 |
CHECK_FORMAT_1("%7.5ld", " -00123", (long)-123); |
| 1657 |
CHECK_FORMAT_1("%7.5li", " -00123", (long)-123); |
| 1658 |
CHECK_FORMAT_1("%7.5lld", " -00123", (long long)-123); |
| 1659 |
CHECK_FORMAT_1("%7.5lli", " -00123", (long long)-123); |
| 1660 |
CHECK_FORMAT_1("%7.5zd", " -00123", (Py_ssize_t)-123); |
| 1661 |
CHECK_FORMAT_1("%7.5zi", " -00123", (Py_ssize_t)-123); |
| 1662 |
|
| 1663 |
// Integers: width > precision > length, 0-flag |
| 1664 |
CHECK_FORMAT_1("%07.5d", "0000123", (int)123); |
| 1665 |
CHECK_FORMAT_1("%07.5i", "0000123", (int)123); |
| 1666 |
CHECK_FORMAT_1("%07.5u", "0000123", (unsigned int)123); |
| 1667 |
CHECK_FORMAT_1("%07.5ld", "0000123", (long)123); |
| 1668 |
CHECK_FORMAT_1("%07.5li", "0000123", (long)123); |
| 1669 |
CHECK_FORMAT_1("%07.5lu", "0000123", (unsigned long)123); |
| 1670 |
CHECK_FORMAT_1("%07.5lld", "0000123", (long long)123); |
| 1671 |
CHECK_FORMAT_1("%07.5lli", "0000123", (long long)123); |
| 1672 |
CHECK_FORMAT_1("%07.5llu", "0000123", (unsigned long long)123); |
| 1673 |
CHECK_FORMAT_1("%07.5zd", "0000123", (Py_ssize_t)123); |
| 1674 |
CHECK_FORMAT_1("%07.5zi", "0000123", (Py_ssize_t)123); |
| 1675 |
CHECK_FORMAT_1("%07.5zu", "0000123", (size_t)123); |
| 1676 |
CHECK_FORMAT_1("%07.5x", "000007b", (int)123); |
| 1677 |
|
| 1678 |
CHECK_FORMAT_1("%07.5d", "-000123", (int)-123); |
| 1679 |
CHECK_FORMAT_1("%07.5i", "-000123", (int)-123); |
| 1680 |
CHECK_FORMAT_1("%07.5ld", "-000123", (long)-123); |
| 1681 |
CHECK_FORMAT_1("%07.5li", "-000123", (long)-123); |
| 1682 |
CHECK_FORMAT_1("%07.5lld", "-000123", (long long)-123); |
| 1683 |
CHECK_FORMAT_1("%07.5lli", "-000123", (long long)-123); |
| 1684 |
CHECK_FORMAT_1("%07.5zd", "-000123", (Py_ssize_t)-123); |
| 1685 |
CHECK_FORMAT_1("%07.5zi", "-000123", (Py_ssize_t)-123); |
| 1686 |
|
| 1687 |
// Integers: precision > width > length |
| 1688 |
CHECK_FORMAT_1("%5.7d", "0000123", (int)123); |
| 1689 |
CHECK_FORMAT_1("%5.7i", "0000123", (int)123); |
| 1690 |
CHECK_FORMAT_1("%5.7u", "0000123", (unsigned int)123); |
| 1691 |
CHECK_FORMAT_1("%5.7ld", "0000123", (long)123); |
| 1692 |
CHECK_FORMAT_1("%5.7li", "0000123", (long)123); |
| 1693 |
CHECK_FORMAT_1("%5.7lu", "0000123", (unsigned long)123); |
| 1694 |
CHECK_FORMAT_1("%5.7lld", "0000123", (long long)123); |
| 1695 |
CHECK_FORMAT_1("%5.7lli", "0000123", (long long)123); |
| 1696 |
CHECK_FORMAT_1("%5.7llu", "0000123", (unsigned long long)123); |
| 1697 |
CHECK_FORMAT_1("%5.7zd", "0000123", (Py_ssize_t)123); |
| 1698 |
CHECK_FORMAT_1("%5.7zi", "0000123", (Py_ssize_t)123); |
| 1699 |
CHECK_FORMAT_1("%5.7zu", "0000123", (size_t)123); |
| 1700 |
CHECK_FORMAT_1("%5.7x", "000007b", (int)123); |
| 1701 |
|
| 1702 |
CHECK_FORMAT_1("%5.7d", "-0000123", (int)-123); |
| 1703 |
CHECK_FORMAT_1("%5.7i", "-0000123", (int)-123); |
| 1704 |
CHECK_FORMAT_1("%5.7ld", "-0000123", (long)-123); |
| 1705 |
CHECK_FORMAT_1("%5.7li", "-0000123", (long)-123); |
| 1706 |
CHECK_FORMAT_1("%5.7lld", "-0000123", (long long)-123); |
| 1707 |
CHECK_FORMAT_1("%5.7lli", "-0000123", (long long)-123); |
| 1708 |
CHECK_FORMAT_1("%5.7zd", "-0000123", (Py_ssize_t)-123); |
| 1709 |
CHECK_FORMAT_1("%5.7zi", "-0000123", (Py_ssize_t)-123); |
| 1710 |
|
| 1711 |
// Integers: precision > width > length, 0-flag |
| 1712 |
CHECK_FORMAT_1("%05.7d", "0000123", (int)123); |
| 1713 |
CHECK_FORMAT_1("%05.7i", "0000123", (int)123); |
| 1714 |
CHECK_FORMAT_1("%05.7u", "0000123", (unsigned int)123); |
| 1715 |
CHECK_FORMAT_1("%05.7ld", "0000123", (long)123); |
| 1716 |
CHECK_FORMAT_1("%05.7li", "0000123", (long)123); |
| 1717 |
CHECK_FORMAT_1("%05.7lu", "0000123", (unsigned long)123); |
| 1718 |
CHECK_FORMAT_1("%05.7lld", "0000123", (long long)123); |
| 1719 |
CHECK_FORMAT_1("%05.7lli", "0000123", (long long)123); |
| 1720 |
CHECK_FORMAT_1("%05.7llu", "0000123", (unsigned long long)123); |
| 1721 |
CHECK_FORMAT_1("%05.7zd", "0000123", (Py_ssize_t)123); |
| 1722 |
CHECK_FORMAT_1("%05.7zi", "0000123", (Py_ssize_t)123); |
| 1723 |
CHECK_FORMAT_1("%05.7zu", "0000123", (size_t)123); |
| 1724 |
CHECK_FORMAT_1("%05.7x", "000007b", (int)123); |
| 1725 |
|
| 1726 |
CHECK_FORMAT_1("%05.7d", "-0000123", (int)-123); |
| 1727 |
CHECK_FORMAT_1("%05.7i", "-0000123", (int)-123); |
| 1728 |
CHECK_FORMAT_1("%05.7ld", "-0000123", (long)-123); |
| 1729 |
CHECK_FORMAT_1("%05.7li", "-0000123", (long)-123); |
| 1730 |
CHECK_FORMAT_1("%05.7lld", "-0000123", (long long)-123); |
| 1731 |
CHECK_FORMAT_1("%05.7lli", "-0000123", (long long)-123); |
| 1732 |
CHECK_FORMAT_1("%05.7zd", "-0000123", (Py_ssize_t)-123); |
| 1733 |
CHECK_FORMAT_1("%05.7zi", "-0000123", (Py_ssize_t)-123); |
| 1734 |
|
| 1735 |
// Integers: precision = 0, arg = 0 (empty string in C) |
| 1736 |
CHECK_FORMAT_1("%.0d", "0", (int)0); |
| 1737 |
CHECK_FORMAT_1("%.0i", "0", (int)0); |
| 1738 |
CHECK_FORMAT_1("%.0u", "0", (unsigned int)0); |
| 1739 |
CHECK_FORMAT_1("%.0ld", "0", (long)0); |
| 1740 |
CHECK_FORMAT_1("%.0li", "0", (long)0); |
| 1741 |
CHECK_FORMAT_1("%.0lu", "0", (unsigned long)0); |
| 1742 |
CHECK_FORMAT_1("%.0lld", "0", (long long)0); |
| 1743 |
CHECK_FORMAT_1("%.0lli", "0", (long long)0); |
| 1744 |
CHECK_FORMAT_1("%.0llu", "0", (unsigned long long)0); |
| 1745 |
CHECK_FORMAT_1("%.0zd", "0", (Py_ssize_t)0); |
| 1746 |
CHECK_FORMAT_1("%.0zi", "0", (Py_ssize_t)0); |
| 1747 |
CHECK_FORMAT_1("%.0zu", "0", (size_t)0); |
| 1748 |
CHECK_FORMAT_1("%.0x", "0", (int)0); |
| 1749 |
|
| 1750 |
// Strings |
| 1751 |
CHECK_FORMAT_1("%s", "None", "None"); |
| 1752 |
CHECK_FORMAT_1("%ls", "None", L"None"); |
| 1753 |
CHECK_FORMAT_1("%U", "None", unicode); |
| 1754 |
CHECK_FORMAT_1("%A", "None", Py_None); |
| 1755 |
CHECK_FORMAT_1("%S", "None", Py_None); |
| 1756 |
CHECK_FORMAT_1("%R", "None", Py_None); |
| 1757 |
CHECK_FORMAT_2("%V", "None", unicode, "ignored"); |
| 1758 |
CHECK_FORMAT_2("%V", "None", NULL, "None"); |
| 1759 |
CHECK_FORMAT_2("%lV", "None", NULL, L"None"); |
| 1760 |
|
| 1761 |
// Strings: width < length |
| 1762 |
CHECK_FORMAT_1("%1s", "None", "None"); |
| 1763 |
CHECK_FORMAT_1("%1ls", "None", L"None"); |
| 1764 |
CHECK_FORMAT_1("%1U", "None", unicode); |
| 1765 |
CHECK_FORMAT_1("%1A", "None", Py_None); |
| 1766 |
CHECK_FORMAT_1("%1S", "None", Py_None); |
| 1767 |
CHECK_FORMAT_1("%1R", "None", Py_None); |
| 1768 |
CHECK_FORMAT_2("%1V", "None", unicode, "ignored"); |
| 1769 |
CHECK_FORMAT_2("%1V", "None", NULL, "None"); |
| 1770 |
CHECK_FORMAT_2("%1lV", "None", NULL, L"None"); |
| 1771 |
|
| 1772 |
// Strings: width > length |
| 1773 |
CHECK_FORMAT_1("%5s", " None", "None"); |
| 1774 |
CHECK_FORMAT_1("%5ls", " None", L"None"); |
| 1775 |
CHECK_FORMAT_1("%5U", " None", unicode); |
| 1776 |
CHECK_FORMAT_1("%5A", " None", Py_None); |
| 1777 |
CHECK_FORMAT_1("%5S", " None", Py_None); |
| 1778 |
CHECK_FORMAT_1("%5R", " None", Py_None); |
| 1779 |
CHECK_FORMAT_2("%5V", " None", unicode, "ignored"); |
| 1780 |
CHECK_FORMAT_2("%5V", " None", NULL, "None"); |
| 1781 |
CHECK_FORMAT_2("%5lV", " None", NULL, L"None"); |
| 1782 |
|
| 1783 |
// Strings: precision < length |
| 1784 |
CHECK_FORMAT_1("%.1s", "N", "None"); |
| 1785 |
CHECK_FORMAT_1("%.1ls", "N", L"None"); |
| 1786 |
CHECK_FORMAT_1("%.1U", "N", unicode); |
| 1787 |
CHECK_FORMAT_1("%.1A", "N", Py_None); |
| 1788 |
CHECK_FORMAT_1("%.1S", "N", Py_None); |
| 1789 |
CHECK_FORMAT_1("%.1R", "N", Py_None); |
| 1790 |
CHECK_FORMAT_2("%.1V", "N", unicode, "ignored"); |
| 1791 |
CHECK_FORMAT_2("%.1V", "N", NULL, "None"); |
| 1792 |
CHECK_FORMAT_2("%.1lV", "N", NULL, L"None"); |
| 1793 |
|
| 1794 |
// Strings: precision > length |
| 1795 |
CHECK_FORMAT_1("%.5s", "None", "None"); |
| 1796 |
CHECK_FORMAT_1("%.5ls", "None", L"None"); |
| 1797 |
CHECK_FORMAT_1("%.5U", "None", unicode); |
| 1798 |
CHECK_FORMAT_1("%.5A", "None", Py_None); |
| 1799 |
CHECK_FORMAT_1("%.5S", "None", Py_None); |
| 1800 |
CHECK_FORMAT_1("%.5R", "None", Py_None); |
| 1801 |
CHECK_FORMAT_2("%.5V", "None", unicode, "ignored"); |
| 1802 |
CHECK_FORMAT_2("%.5V", "None", NULL, "None"); |
| 1803 |
CHECK_FORMAT_2("%.5lV", "None", NULL, L"None"); |
| 1804 |
|
| 1805 |
// Strings: precision < length, width > length |
| 1806 |
CHECK_FORMAT_1("%5.1s", " N", "None"); |
| 1807 |
CHECK_FORMAT_1("%5.1ls"," N", L"None"); |
| 1808 |
CHECK_FORMAT_1("%5.1U", " N", unicode); |
| 1809 |
CHECK_FORMAT_1("%5.1A", " N", Py_None); |
| 1810 |
CHECK_FORMAT_1("%5.1S", " N", Py_None); |
| 1811 |
CHECK_FORMAT_1("%5.1R", " N", Py_None); |
| 1812 |
CHECK_FORMAT_2("%5.1V", " N", unicode, "ignored"); |
| 1813 |
CHECK_FORMAT_2("%5.1V", " N", NULL, "None"); |
| 1814 |
CHECK_FORMAT_2("%5.1lV"," N", NULL, L"None"); |
| 1815 |
|
| 1816 |
// Strings: width < length, precision > length |
| 1817 |
CHECK_FORMAT_1("%1.5s", "None", "None"); |
| 1818 |
CHECK_FORMAT_1("%1.5ls", "None", L"None"); |
| 1819 |
CHECK_FORMAT_1("%1.5U", "None", unicode); |
| 1820 |
CHECK_FORMAT_1("%1.5A", "None", Py_None); |
| 1821 |
CHECK_FORMAT_1("%1.5S", "None", Py_None); |
| 1822 |
CHECK_FORMAT_1("%1.5R", "None", Py_None); |
| 1823 |
CHECK_FORMAT_2("%1.5V", "None", unicode, "ignored"); |
| 1824 |
CHECK_FORMAT_2("%1.5V", "None", NULL, "None"); |
| 1825 |
CHECK_FORMAT_2("%1.5lV", "None", NULL, L"None"); |
| 1826 |
|
| 1827 |
Py_XDECREF(unicode); |
| 1828 |
Py_RETURN_NONE; |
| 1829 |
|
| 1830 |
Fail: |
| 1831 |
Py_XDECREF(result); |
| 1832 |
Py_XDECREF(unicode); |
| 1833 |
return NULL; |
| 1834 |
|
| 1835 |
#undef CHECK_FORMAT_2 |
| 1836 |
#undef CHECK_FORMAT_1 |
| 1837 |
#undef CHECK_FORMAT_0 |
| 1838 |
} |
| 1839 |
|
| 1840 |
|
| 1841 |
/* Test PyUnicode_Equal() */ |
| 1842 |
static PyObject * |
| 1843 |
unicode_equal(PyObject *module, PyObject *args) |
| 1844 |
{ |
| 1845 |
PyObject *str1, *str2; |
| 1846 |
if (!PyArg_ParseTuple(args, "OO", &str1, &str2)) { |
| 1847 |
return NULL; |
| 1848 |
} |
| 1849 |
|
| 1850 |
NULLABLE(str1); |
| 1851 |
NULLABLE(str2); |
| 1852 |
RETURN_INT(PyUnicode_Equal(str1, str2)); |
| 1853 |
} |
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
static PyMethodDef TestMethods[] = { |
| 1858 |
{"codec_incrementalencoder", codec_incrementalencoder, METH_VARARGS}, |
| 1859 |
{"codec_incrementaldecoder", codec_incrementaldecoder, METH_VARARGS}, |
| 1860 |
{"test_unicode_compare_with_ascii", |
| 1861 |
test_unicode_compare_with_ascii, METH_NOARGS}, |
| 1862 |
{"test_string_from_format", test_string_from_format, METH_NOARGS}, |
| 1863 |
{"test_widechar", test_widechar, METH_NOARGS}, |
| 1864 |
{"unicode_writechar", unicode_writechar, METH_VARARGS}, |
| 1865 |
{"unicode_resize", unicode_resize, METH_VARARGS}, |
| 1866 |
{"unicode_append", unicode_append, METH_VARARGS}, |
| 1867 |
{"unicode_appendanddel", unicode_appendanddel, METH_VARARGS}, |
| 1868 |
{"unicode_fromstringandsize",unicode_fromstringandsize, METH_VARARGS}, |
| 1869 |
{"unicode_fromstring", unicode_fromstring, METH_O}, |
| 1870 |
{"unicode_substring", unicode_substring, METH_VARARGS}, |
| 1871 |
{"unicode_getlength", unicode_getlength, METH_O}, |
| 1872 |
{"unicode_readchar", unicode_readchar, METH_VARARGS}, |
| 1873 |
{"unicode_fromencodedobject",unicode_fromencodedobject, METH_VARARGS}, |
| 1874 |
{"unicode_fromobject", unicode_fromobject, METH_O}, |
| 1875 |
{"unicode_interninplace", unicode_interninplace, METH_O}, |
| 1876 |
{"unicode_internfromstring", unicode_internfromstring, METH_O}, |
| 1877 |
{"unicode_fromwidechar", unicode_fromwidechar, METH_VARARGS}, |
| 1878 |
{"unicode_aswidechar", unicode_aswidechar, METH_VARARGS}, |
| 1879 |
{"unicode_aswidechar_null", unicode_aswidechar_null, METH_VARARGS}, |
| 1880 |
{"unicode_aswidecharstring", unicode_aswidecharstring, METH_VARARGS}, |
| 1881 |
{"unicode_aswidecharstring_null",unicode_aswidecharstring_null,METH_VARARGS}, |
| 1882 |
{"unicode_fromordinal", unicode_fromordinal, METH_VARARGS}, |
| 1883 |
{"unicode_asutf8andsize", unicode_asutf8andsize, METH_VARARGS}, |
| 1884 |
{"unicode_asutf8andsize_null",unicode_asutf8andsize_null, METH_VARARGS}, |
| 1885 |
{"unicode_getdefaultencoding",unicode_getdefaultencoding, METH_NOARGS}, |
| 1886 |
{"unicode_decode", unicode_decode, METH_VARARGS}, |
| 1887 |
{"unicode_asencodedstring", unicode_asencodedstring, METH_VARARGS}, |
| 1888 |
{"unicode_buildencodingmap", unicode_buildencodingmap, METH_O}, |
| 1889 |
{"unicode_decodeutf7", unicode_decodeutf7, METH_VARARGS}, |
| 1890 |
{"unicode_decodeutf7stateful",unicode_decodeutf7stateful, METH_VARARGS}, |
| 1891 |
{"unicode_decodeutf8", unicode_decodeutf8, METH_VARARGS}, |
| 1892 |
{"unicode_decodeutf8stateful",unicode_decodeutf8stateful, METH_VARARGS}, |
| 1893 |
{"unicode_asutf8string", unicode_asutf8string, METH_O}, |
| 1894 |
{"unicode_decodeutf16", unicode_decodeutf16, METH_VARARGS}, |
| 1895 |
{"unicode_decodeutf16stateful",unicode_decodeutf16stateful, METH_VARARGS}, |
| 1896 |
{"unicode_asutf16string", unicode_asutf16string, METH_O}, |
| 1897 |
{"unicode_decodeutf32", unicode_decodeutf32, METH_VARARGS}, |
| 1898 |
{"unicode_decodeutf32stateful",unicode_decodeutf32stateful, METH_VARARGS}, |
| 1899 |
{"unicode_asutf32string", unicode_asutf32string, METH_O}, |
| 1900 |
{"unicode_decodeunicodeescape",unicode_decodeunicodeescape, METH_VARARGS}, |
| 1901 |
{"unicode_asunicodeescapestring",unicode_asunicodeescapestring,METH_O}, |
| 1902 |
{"unicode_decoderawunicodeescape",unicode_decoderawunicodeescape,METH_VARARGS}, |
| 1903 |
{"unicode_asrawunicodeescapestring",unicode_asrawunicodeescapestring,METH_O}, |
| 1904 |
{"unicode_decodelatin1", unicode_decodelatin1, METH_VARARGS}, |
| 1905 |
{"unicode_aslatin1string", unicode_aslatin1string, METH_O}, |
| 1906 |
{"unicode_decodeascii", unicode_decodeascii, METH_VARARGS}, |
| 1907 |
{"unicode_asasciistring", unicode_asasciistring, METH_O}, |
| 1908 |
{"unicode_decodecharmap", unicode_decodecharmap, METH_VARARGS}, |
| 1909 |
{"unicode_ascharmapstring", unicode_ascharmapstring, METH_VARARGS}, |
| 1910 |
#ifdef MS_WINDOWS |
| 1911 |
{"unicode_decodembcs", unicode_decodembcs, METH_VARARGS}, |
| 1912 |
{"unicode_decodembcsstateful",unicode_decodembcsstateful, METH_VARARGS}, |
| 1913 |
{"unicode_decodecodepagestateful",unicode_decodecodepagestateful,METH_VARARGS}, |
| 1914 |
{"unicode_asmbcsstring", unicode_asmbcsstring, METH_O}, |
| 1915 |
{"unicode_encodecodepage", unicode_encodecodepage, METH_VARARGS}, |
| 1916 |
#endif /* MS_WINDOWS */ |
| 1917 |
{"unicode_decodelocaleandsize",unicode_decodelocaleandsize, METH_VARARGS}, |
| 1918 |
{"unicode_decodelocale", unicode_decodelocale, METH_VARARGS}, |
| 1919 |
{"unicode_encodelocale", unicode_encodelocale, METH_VARARGS}, |
| 1920 |
{"unicode_decodefsdefault", unicode_decodefsdefault, METH_VARARGS}, |
| 1921 |
{"unicode_decodefsdefaultandsize",unicode_decodefsdefaultandsize,METH_VARARGS}, |
| 1922 |
{"unicode_encodefsdefault", unicode_encodefsdefault, METH_O}, |
| 1923 |
{"unicode_concat", unicode_concat, METH_VARARGS}, |
| 1924 |
{"unicode_splitlines", unicode_splitlines, METH_VARARGS}, |
| 1925 |
{"unicode_split", unicode_split, METH_VARARGS}, |
| 1926 |
{"unicode_rsplit", unicode_rsplit, METH_VARARGS}, |
| 1927 |
{"unicode_partition", unicode_partition, METH_VARARGS}, |
| 1928 |
{"unicode_rpartition", unicode_rpartition, METH_VARARGS}, |
| 1929 |
{"unicode_translate", unicode_translate, METH_VARARGS}, |
| 1930 |
{"unicode_join", unicode_join, METH_VARARGS}, |
| 1931 |
{"unicode_count", unicode_count, METH_VARARGS}, |
| 1932 |
{"unicode_tailmatch", unicode_tailmatch, METH_VARARGS}, |
| 1933 |
{"unicode_find", unicode_find, METH_VARARGS}, |
| 1934 |
{"unicode_findchar", unicode_findchar, METH_VARARGS}, |
| 1935 |
{"unicode_replace", unicode_replace, METH_VARARGS}, |
| 1936 |
{"unicode_compare", unicode_compare, METH_VARARGS}, |
| 1937 |
{"unicode_comparewithasciistring",unicode_comparewithasciistring,METH_VARARGS}, |
| 1938 |
{"unicode_equaltoutf8", unicode_equaltoutf8, METH_VARARGS}, |
| 1939 |
{"unicode_equaltoutf8andsize",unicode_equaltoutf8andsize, METH_VARARGS}, |
| 1940 |
{"unicode_richcompare", unicode_richcompare, METH_VARARGS}, |
| 1941 |
{"unicode_format", unicode_format, METH_VARARGS}, |
| 1942 |
{"unicode_contains", unicode_contains, METH_VARARGS}, |
| 1943 |
{"unicode_isidentifier", unicode_isidentifier, METH_O}, |
| 1944 |
{"unicode_equal", unicode_equal, METH_VARARGS}, |
| 1945 |
{NULL}, |
| 1946 |
}; |
| 1947 |
|
| 1948 |
int |
| 1949 |
_PyTestLimitedCAPI_Init_Unicode(PyObject *m) |
| 1950 |
{ |
| 1951 |
if (PyModule_AddFunctions(m, TestMethods) < 0) { |
| 1952 |
return -1; |
| 1953 |
} |
| 1954 |
|
| 1955 |
return 0; |
| 1956 |
} |