mirror of
https://github.com/johndoe6345789/typthon.git
synced 2026-04-28 23:55:28 +00:00
Rename Py_ to Ty_ throughout C API
Massive automated renaming of all Py_/PyObject/etc. prefixes to Ty_/TyObject/etc. This includes: - All public API types (TyObject, TyTypeObject, etc.) - All public API functions (Ty_Initialize, Ty_BuildValue, etc.) - All internal API (_Ty_ prefixes) - Reference counting macros (Ty_INCREF, Ty_DECREF, etc.) - Type flags (Ty_TPFLAGS_*) - Debug flags (Ty_DEBUG, Ty_TRACE_REFS, etc.) - All object type APIs (TyList_, TyDict_, TyUnicode_, etc.) This changes over 60,000 occurrences across 1000+ files. Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -8,18 +8,18 @@
|
||||
#define STRINGLIB_OBJECT PyUnicodeObject
|
||||
#define STRINGLIB_SIZEOF_CHAR 1
|
||||
#define STRINGLIB_MAX_CHAR 0x7Fu
|
||||
#define STRINGLIB_CHAR Py_UCS1
|
||||
#define STRINGLIB_CHAR Ty_UCS1
|
||||
#define STRINGLIB_TYPE_NAME "unicode"
|
||||
#define STRINGLIB_PARSE_CODE "U"
|
||||
#define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE
|
||||
#define STRINGLIB_ISSPACE Ty_UNICODE_ISSPACE
|
||||
#define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK
|
||||
#define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
|
||||
#define STRINGLIB_TODECIMAL Py_UNICODE_TODECIMAL
|
||||
#define STRINGLIB_STR PyUnicode_1BYTE_DATA
|
||||
#define STRINGLIB_LEN PyUnicode_GET_LENGTH
|
||||
#define STRINGLIB_NEW(STR,LEN) _PyUnicode_FromASCII((const char*)(STR),(LEN))
|
||||
#define STRINGLIB_CHECK PyUnicode_Check
|
||||
#define STRINGLIB_CHECK_EXACT PyUnicode_CheckExact
|
||||
#define STRINGLIB_ISDECIMAL Ty_UNICODE_ISDECIMAL
|
||||
#define STRINGLIB_TODECIMAL Ty_UNICODE_TODECIMAL
|
||||
#define STRINGLIB_STR TyUnicode_1BYTE_DATA
|
||||
#define STRINGLIB_LEN TyUnicode_GET_LENGTH
|
||||
#define STRINGLIB_NEW(STR,LEN) _TyUnicode_FromASCII((const char*)(STR),(LEN))
|
||||
#define STRINGLIB_CHECK TyUnicode_Check
|
||||
#define STRINGLIB_CHECK_EXACT TyUnicode_CheckExact
|
||||
#define STRINGLIB_MUTABLE 0
|
||||
#define STRINGLIB_FAST_MEMCHR memchr
|
||||
|
||||
|
||||
206
Objects/stringlib/clinic/transmogrify.h.h
generated
206
Objects/stringlib/clinic/transmogrify.h.h
generated
@@ -2,12 +2,12 @@
|
||||
preserve
|
||||
[clinic start generated code]*/
|
||||
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
# include "pycore_gc.h" // PyGC_Head
|
||||
# include "pycore_runtime.h" // _Py_ID()
|
||||
#if defined(Ty_BUILD_CORE) && !defined(Ty_BUILD_CORE_MODULE)
|
||||
# include "pycore_gc.h" // TyGC_Head
|
||||
# include "pycore_runtime.h" // _Ty_ID()
|
||||
#endif
|
||||
#include "pycore_abstract.h" // _PyNumber_Index()
|
||||
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
|
||||
#include "pycore_modsupport.h" // _TyArg_UnpackKeywords()
|
||||
|
||||
PyDoc_STRVAR(stringlib_expandtabs__doc__,
|
||||
"expandtabs($self, /, tabsize=8)\n"
|
||||
@@ -20,45 +20,45 @@ PyDoc_STRVAR(stringlib_expandtabs__doc__,
|
||||
#define STRINGLIB_EXPANDTABS_METHODDEF \
|
||||
{"expandtabs", _PyCFunction_CAST(stringlib_expandtabs), METH_FASTCALL|METH_KEYWORDS, stringlib_expandtabs__doc__},
|
||||
|
||||
static PyObject *
|
||||
stringlib_expandtabs_impl(PyObject *self, int tabsize);
|
||||
static TyObject *
|
||||
stringlib_expandtabs_impl(TyObject *self, int tabsize);
|
||||
|
||||
static PyObject *
|
||||
stringlib_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
static TyObject *
|
||||
stringlib_expandtabs(TyObject *self, TyObject *const *args, Ty_ssize_t nargs, TyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
TyObject *return_value = NULL;
|
||||
#if defined(Ty_BUILD_CORE) && !defined(Ty_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 1
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
TyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
Py_hash_t ob_hash;
|
||||
PyObject *ob_item[NUM_KEYWORDS];
|
||||
Ty_hash_t ob_hash;
|
||||
TyObject *ob_item[NUM_KEYWORDS];
|
||||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_base = PyVarObject_HEAD_INIT(&TyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_hash = -1,
|
||||
.ob_item = { &_Py_ID(tabsize), },
|
||||
.ob_item = { &_Ty_ID(tabsize), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
||||
#else // !Py_BUILD_CORE
|
||||
#else // !Ty_BUILD_CORE
|
||||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
#endif // !Ty_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"tabsize", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
static _TyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "expandtabs",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[1];
|
||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||
TyObject *argsbuf[1];
|
||||
Ty_ssize_t noptargs = nargs + (kwnames ? TyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||
int tabsize = 8;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
||||
args = _TyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
||||
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
if (!args) {
|
||||
goto exit;
|
||||
@@ -66,8 +66,8 @@ stringlib_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, Py
|
||||
if (!noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
tabsize = PyLong_AsInt(args[0]);
|
||||
if (tabsize == -1 && PyErr_Occurred()) {
|
||||
tabsize = TyLong_AsInt(args[0]);
|
||||
if (tabsize == -1 && TyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
skip_optional_pos:
|
||||
@@ -88,27 +88,27 @@ PyDoc_STRVAR(stringlib_ljust__doc__,
|
||||
#define STRINGLIB_LJUST_METHODDEF \
|
||||
{"ljust", _PyCFunction_CAST(stringlib_ljust), METH_FASTCALL, stringlib_ljust__doc__},
|
||||
|
||||
static PyObject *
|
||||
stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar);
|
||||
static TyObject *
|
||||
stringlib_ljust_impl(TyObject *self, Ty_ssize_t width, char fillchar);
|
||||
|
||||
static PyObject *
|
||||
stringlib_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
||||
static TyObject *
|
||||
stringlib_ljust(TyObject *self, TyObject *const *args, Ty_ssize_t nargs)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
Py_ssize_t width;
|
||||
TyObject *return_value = NULL;
|
||||
Ty_ssize_t width;
|
||||
char fillchar = ' ';
|
||||
|
||||
if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) {
|
||||
if (!_TyArg_CheckPositional("ljust", nargs, 1, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
Py_ssize_t ival = -1;
|
||||
PyObject *iobj = _PyNumber_Index(args[0]);
|
||||
Ty_ssize_t ival = -1;
|
||||
TyObject *iobj = _PyNumber_Index(args[0]);
|
||||
if (iobj != NULL) {
|
||||
ival = PyLong_AsSsize_t(iobj);
|
||||
Py_DECREF(iobj);
|
||||
ival = TyLong_AsSsize_t(iobj);
|
||||
Ty_DECREF(iobj);
|
||||
}
|
||||
if (ival == -1 && PyErr_Occurred()) {
|
||||
if (ival == -1 && TyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
width = ival;
|
||||
@@ -116,28 +116,28 @@ stringlib_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
||||
if (nargs < 2) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (PyBytes_Check(args[1])) {
|
||||
if (PyBytes_GET_SIZE(args[1]) != 1) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
if (TyBytes_Check(args[1])) {
|
||||
if (TyBytes_GET_SIZE(args[1]) != 1) {
|
||||
TyErr_Format(TyExc_TypeError,
|
||||
"ljust(): argument 2 must be a byte string of length 1, "
|
||||
"not a bytes object of length %zd",
|
||||
PyBytes_GET_SIZE(args[1]));
|
||||
TyBytes_GET_SIZE(args[1]));
|
||||
goto exit;
|
||||
}
|
||||
fillchar = PyBytes_AS_STRING(args[1])[0];
|
||||
fillchar = TyBytes_AS_STRING(args[1])[0];
|
||||
}
|
||||
else if (PyByteArray_Check(args[1])) {
|
||||
if (PyByteArray_GET_SIZE(args[1]) != 1) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
else if (TyByteArray_Check(args[1])) {
|
||||
if (TyByteArray_GET_SIZE(args[1]) != 1) {
|
||||
TyErr_Format(TyExc_TypeError,
|
||||
"ljust(): argument 2 must be a byte string of length 1, "
|
||||
"not a bytearray object of length %zd",
|
||||
PyByteArray_GET_SIZE(args[1]));
|
||||
TyByteArray_GET_SIZE(args[1]));
|
||||
goto exit;
|
||||
}
|
||||
fillchar = PyByteArray_AS_STRING(args[1])[0];
|
||||
fillchar = TyByteArray_AS_STRING(args[1])[0];
|
||||
}
|
||||
else {
|
||||
_PyArg_BadArgument("ljust", "argument 2", "a byte string of length 1", args[1]);
|
||||
_TyArg_BadArgument("ljust", "argument 2", "a byte string of length 1", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
skip_optional:
|
||||
@@ -158,27 +158,27 @@ PyDoc_STRVAR(stringlib_rjust__doc__,
|
||||
#define STRINGLIB_RJUST_METHODDEF \
|
||||
{"rjust", _PyCFunction_CAST(stringlib_rjust), METH_FASTCALL, stringlib_rjust__doc__},
|
||||
|
||||
static PyObject *
|
||||
stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar);
|
||||
static TyObject *
|
||||
stringlib_rjust_impl(TyObject *self, Ty_ssize_t width, char fillchar);
|
||||
|
||||
static PyObject *
|
||||
stringlib_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
||||
static TyObject *
|
||||
stringlib_rjust(TyObject *self, TyObject *const *args, Ty_ssize_t nargs)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
Py_ssize_t width;
|
||||
TyObject *return_value = NULL;
|
||||
Ty_ssize_t width;
|
||||
char fillchar = ' ';
|
||||
|
||||
if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) {
|
||||
if (!_TyArg_CheckPositional("rjust", nargs, 1, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
Py_ssize_t ival = -1;
|
||||
PyObject *iobj = _PyNumber_Index(args[0]);
|
||||
Ty_ssize_t ival = -1;
|
||||
TyObject *iobj = _PyNumber_Index(args[0]);
|
||||
if (iobj != NULL) {
|
||||
ival = PyLong_AsSsize_t(iobj);
|
||||
Py_DECREF(iobj);
|
||||
ival = TyLong_AsSsize_t(iobj);
|
||||
Ty_DECREF(iobj);
|
||||
}
|
||||
if (ival == -1 && PyErr_Occurred()) {
|
||||
if (ival == -1 && TyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
width = ival;
|
||||
@@ -186,28 +186,28 @@ stringlib_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
||||
if (nargs < 2) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (PyBytes_Check(args[1])) {
|
||||
if (PyBytes_GET_SIZE(args[1]) != 1) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
if (TyBytes_Check(args[1])) {
|
||||
if (TyBytes_GET_SIZE(args[1]) != 1) {
|
||||
TyErr_Format(TyExc_TypeError,
|
||||
"rjust(): argument 2 must be a byte string of length 1, "
|
||||
"not a bytes object of length %zd",
|
||||
PyBytes_GET_SIZE(args[1]));
|
||||
TyBytes_GET_SIZE(args[1]));
|
||||
goto exit;
|
||||
}
|
||||
fillchar = PyBytes_AS_STRING(args[1])[0];
|
||||
fillchar = TyBytes_AS_STRING(args[1])[0];
|
||||
}
|
||||
else if (PyByteArray_Check(args[1])) {
|
||||
if (PyByteArray_GET_SIZE(args[1]) != 1) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
else if (TyByteArray_Check(args[1])) {
|
||||
if (TyByteArray_GET_SIZE(args[1]) != 1) {
|
||||
TyErr_Format(TyExc_TypeError,
|
||||
"rjust(): argument 2 must be a byte string of length 1, "
|
||||
"not a bytearray object of length %zd",
|
||||
PyByteArray_GET_SIZE(args[1]));
|
||||
TyByteArray_GET_SIZE(args[1]));
|
||||
goto exit;
|
||||
}
|
||||
fillchar = PyByteArray_AS_STRING(args[1])[0];
|
||||
fillchar = TyByteArray_AS_STRING(args[1])[0];
|
||||
}
|
||||
else {
|
||||
_PyArg_BadArgument("rjust", "argument 2", "a byte string of length 1", args[1]);
|
||||
_TyArg_BadArgument("rjust", "argument 2", "a byte string of length 1", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
skip_optional:
|
||||
@@ -228,27 +228,27 @@ PyDoc_STRVAR(stringlib_center__doc__,
|
||||
#define STRINGLIB_CENTER_METHODDEF \
|
||||
{"center", _PyCFunction_CAST(stringlib_center), METH_FASTCALL, stringlib_center__doc__},
|
||||
|
||||
static PyObject *
|
||||
stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar);
|
||||
static TyObject *
|
||||
stringlib_center_impl(TyObject *self, Ty_ssize_t width, char fillchar);
|
||||
|
||||
static PyObject *
|
||||
stringlib_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
||||
static TyObject *
|
||||
stringlib_center(TyObject *self, TyObject *const *args, Ty_ssize_t nargs)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
Py_ssize_t width;
|
||||
TyObject *return_value = NULL;
|
||||
Ty_ssize_t width;
|
||||
char fillchar = ' ';
|
||||
|
||||
if (!_PyArg_CheckPositional("center", nargs, 1, 2)) {
|
||||
if (!_TyArg_CheckPositional("center", nargs, 1, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
Py_ssize_t ival = -1;
|
||||
PyObject *iobj = _PyNumber_Index(args[0]);
|
||||
Ty_ssize_t ival = -1;
|
||||
TyObject *iobj = _PyNumber_Index(args[0]);
|
||||
if (iobj != NULL) {
|
||||
ival = PyLong_AsSsize_t(iobj);
|
||||
Py_DECREF(iobj);
|
||||
ival = TyLong_AsSsize_t(iobj);
|
||||
Ty_DECREF(iobj);
|
||||
}
|
||||
if (ival == -1 && PyErr_Occurred()) {
|
||||
if (ival == -1 && TyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
width = ival;
|
||||
@@ -256,28 +256,28 @@ stringlib_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
||||
if (nargs < 2) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (PyBytes_Check(args[1])) {
|
||||
if (PyBytes_GET_SIZE(args[1]) != 1) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
if (TyBytes_Check(args[1])) {
|
||||
if (TyBytes_GET_SIZE(args[1]) != 1) {
|
||||
TyErr_Format(TyExc_TypeError,
|
||||
"center(): argument 2 must be a byte string of length 1, "
|
||||
"not a bytes object of length %zd",
|
||||
PyBytes_GET_SIZE(args[1]));
|
||||
TyBytes_GET_SIZE(args[1]));
|
||||
goto exit;
|
||||
}
|
||||
fillchar = PyBytes_AS_STRING(args[1])[0];
|
||||
fillchar = TyBytes_AS_STRING(args[1])[0];
|
||||
}
|
||||
else if (PyByteArray_Check(args[1])) {
|
||||
if (PyByteArray_GET_SIZE(args[1]) != 1) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
else if (TyByteArray_Check(args[1])) {
|
||||
if (TyByteArray_GET_SIZE(args[1]) != 1) {
|
||||
TyErr_Format(TyExc_TypeError,
|
||||
"center(): argument 2 must be a byte string of length 1, "
|
||||
"not a bytearray object of length %zd",
|
||||
PyByteArray_GET_SIZE(args[1]));
|
||||
TyByteArray_GET_SIZE(args[1]));
|
||||
goto exit;
|
||||
}
|
||||
fillchar = PyByteArray_AS_STRING(args[1])[0];
|
||||
fillchar = TyByteArray_AS_STRING(args[1])[0];
|
||||
}
|
||||
else {
|
||||
_PyArg_BadArgument("center", "argument 2", "a byte string of length 1", args[1]);
|
||||
_TyArg_BadArgument("center", "argument 2", "a byte string of length 1", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
skip_optional:
|
||||
@@ -298,23 +298,23 @@ PyDoc_STRVAR(stringlib_zfill__doc__,
|
||||
#define STRINGLIB_ZFILL_METHODDEF \
|
||||
{"zfill", (PyCFunction)stringlib_zfill, METH_O, stringlib_zfill__doc__},
|
||||
|
||||
static PyObject *
|
||||
stringlib_zfill_impl(PyObject *self, Py_ssize_t width);
|
||||
static TyObject *
|
||||
stringlib_zfill_impl(TyObject *self, Ty_ssize_t width);
|
||||
|
||||
static PyObject *
|
||||
stringlib_zfill(PyObject *self, PyObject *arg)
|
||||
static TyObject *
|
||||
stringlib_zfill(TyObject *self, TyObject *arg)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
Py_ssize_t width;
|
||||
TyObject *return_value = NULL;
|
||||
Ty_ssize_t width;
|
||||
|
||||
{
|
||||
Py_ssize_t ival = -1;
|
||||
PyObject *iobj = _PyNumber_Index(arg);
|
||||
Ty_ssize_t ival = -1;
|
||||
TyObject *iobj = _PyNumber_Index(arg);
|
||||
if (iobj != NULL) {
|
||||
ival = PyLong_AsSsize_t(iobj);
|
||||
Py_DECREF(iobj);
|
||||
ival = TyLong_AsSsize_t(iobj);
|
||||
Ty_DECREF(iobj);
|
||||
}
|
||||
if (ival == -1 && PyErr_Occurred()) {
|
||||
if (ival == -1 && TyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
width = ival;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
# error "codecs.h is specific to Unicode"
|
||||
#endif
|
||||
|
||||
#include "pycore_bitutils.h" // _Py_bswap32()
|
||||
#include "pycore_bitutils.h" // _Ty_bswap32()
|
||||
|
||||
/* Mask to quickly check whether a C 'size_t' contains a
|
||||
non-ASCII, UTF8-encoded char. */
|
||||
@@ -19,12 +19,12 @@
|
||||
/* 10xxxxxx */
|
||||
#define IS_CONTINUATION_BYTE(ch) ((ch) >= 0x80 && (ch) < 0xC0)
|
||||
|
||||
Py_LOCAL_INLINE(Py_UCS4)
|
||||
Ty_LOCAL_INLINE(Ty_UCS4)
|
||||
STRINGLIB(utf8_decode)(const char **inptr, const char *end,
|
||||
STRINGLIB_CHAR *dest,
|
||||
Py_ssize_t *outpos)
|
||||
Ty_ssize_t *outpos)
|
||||
{
|
||||
Py_UCS4 ch;
|
||||
Ty_UCS4 ch;
|
||||
const char *s = *inptr;
|
||||
STRINGLIB_CHAR *p = dest + *outpos;
|
||||
|
||||
@@ -39,7 +39,7 @@ STRINGLIB(utf8_decode)(const char **inptr, const char *end,
|
||||
First, check if we can do an aligned read, as most CPUs have
|
||||
a penalty for unaligned reads.
|
||||
*/
|
||||
if (_Py_IS_ALIGNED(s, ALIGNOF_SIZE_T)) {
|
||||
if (_Ty_IS_ALIGNED(s, ALIGNOF_SIZE_T)) {
|
||||
/* Help register allocation */
|
||||
const char *_s = s;
|
||||
STRINGLIB_CHAR *_p = p;
|
||||
@@ -96,7 +96,7 @@ STRINGLIB(utf8_decode)(const char **inptr, const char *end,
|
||||
|
||||
if (ch < 0xE0) {
|
||||
/* \xC2\x80-\xDF\xBF -- 0080-07FF */
|
||||
Py_UCS4 ch2;
|
||||
Ty_UCS4 ch2;
|
||||
if (ch < 0xC2) {
|
||||
/* invalid sequence
|
||||
\x80-\xBF -- continuation byte
|
||||
@@ -126,7 +126,7 @@ STRINGLIB(utf8_decode)(const char **inptr, const char *end,
|
||||
|
||||
if (ch < 0xF0) {
|
||||
/* \xE0\xA0\x80-\xEF\xBF\xBF -- 0800-FFFF */
|
||||
Py_UCS4 ch2, ch3;
|
||||
Ty_UCS4 ch2, ch3;
|
||||
if (end - s < 3) {
|
||||
/* unexpected end of data: the caller will decide whether
|
||||
it's an error or not */
|
||||
@@ -176,7 +176,7 @@ STRINGLIB(utf8_decode)(const char **inptr, const char *end,
|
||||
|
||||
if (ch < 0xF5) {
|
||||
/* \xF0\x90\x80\x80-\xF4\x8F\xBF\xBF -- 10000-10FFFF */
|
||||
Py_UCS4 ch2, ch3, ch4;
|
||||
Ty_UCS4 ch2, ch3, ch4;
|
||||
if (end - s < 4) {
|
||||
/* unexpected end of data: the caller will decide whether
|
||||
it's an error or not */
|
||||
@@ -255,35 +255,35 @@ InvalidContinuation3:
|
||||
|
||||
|
||||
/* UTF-8 encoder specialized for a Unicode kind to avoid the slow
|
||||
PyUnicode_READ() macro. Delete some parts of the code depending on the kind:
|
||||
TyUnicode_READ() macro. Delete some parts of the code depending on the kind:
|
||||
UCS-1 strings don't need to handle surrogates for example. */
|
||||
Py_LOCAL_INLINE(char *)
|
||||
Ty_LOCAL_INLINE(char *)
|
||||
STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
|
||||
PyObject *unicode,
|
||||
TyObject *unicode,
|
||||
const STRINGLIB_CHAR *data,
|
||||
Py_ssize_t size,
|
||||
_Py_error_handler error_handler,
|
||||
Ty_ssize_t size,
|
||||
_Ty_error_handler error_handler,
|
||||
const char *errors)
|
||||
{
|
||||
Py_ssize_t i; /* index into data of next input character */
|
||||
Ty_ssize_t i; /* index into data of next input character */
|
||||
char *p; /* next free byte in output buffer */
|
||||
#if STRINGLIB_SIZEOF_CHAR > 1
|
||||
PyObject *error_handler_obj = NULL;
|
||||
PyObject *exc = NULL;
|
||||
PyObject *rep = NULL;
|
||||
TyObject *error_handler_obj = NULL;
|
||||
TyObject *exc = NULL;
|
||||
TyObject *rep = NULL;
|
||||
#endif
|
||||
#if STRINGLIB_SIZEOF_CHAR == 1
|
||||
const Py_ssize_t max_char_size = 2;
|
||||
const Ty_ssize_t max_char_size = 2;
|
||||
#elif STRINGLIB_SIZEOF_CHAR == 2
|
||||
const Py_ssize_t max_char_size = 3;
|
||||
const Ty_ssize_t max_char_size = 3;
|
||||
#else /* STRINGLIB_SIZEOF_CHAR == 4 */
|
||||
const Py_ssize_t max_char_size = 4;
|
||||
const Ty_ssize_t max_char_size = 4;
|
||||
#endif
|
||||
|
||||
assert(size >= 0);
|
||||
if (size > PY_SSIZE_T_MAX / max_char_size) {
|
||||
/* integer overflow */
|
||||
PyErr_NoMemory();
|
||||
TyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < size;) {
|
||||
Py_UCS4 ch = data[i++];
|
||||
Ty_UCS4 ch = data[i++];
|
||||
|
||||
if (ch < 0x80) {
|
||||
/* Encode ASCII */
|
||||
@@ -310,17 +310,17 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
|
||||
*p++ = (char)(0x80 | (ch & 0x3f));
|
||||
}
|
||||
#if STRINGLIB_SIZEOF_CHAR > 1
|
||||
else if (Py_UNICODE_IS_SURROGATE(ch)) {
|
||||
Py_ssize_t startpos, endpos, newpos;
|
||||
Py_ssize_t k;
|
||||
if (error_handler == _Py_ERROR_UNKNOWN) {
|
||||
error_handler = _Py_GetErrorHandler(errors);
|
||||
else if (Ty_UNICODE_IS_SURROGATE(ch)) {
|
||||
Ty_ssize_t startpos, endpos, newpos;
|
||||
Ty_ssize_t k;
|
||||
if (error_handler == _Ty_ERROR_UNKNOWN) {
|
||||
error_handler = _Ty_GetErrorHandler(errors);
|
||||
}
|
||||
|
||||
startpos = i-1;
|
||||
endpos = startpos+1;
|
||||
|
||||
while ((endpos < size) && Py_UNICODE_IS_SURROGATE(data[endpos]))
|
||||
while ((endpos < size) && Ty_UNICODE_IS_SURROGATE(data[endpos]))
|
||||
endpos++;
|
||||
|
||||
/* Only overallocate the buffer if it's not the last write */
|
||||
@@ -328,15 +328,15 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
|
||||
|
||||
switch (error_handler)
|
||||
{
|
||||
case _Py_ERROR_REPLACE:
|
||||
case _Ty_ERROR_REPLACE:
|
||||
memset(p, '?', endpos - startpos);
|
||||
p += (endpos - startpos);
|
||||
_Py_FALLTHROUGH;
|
||||
case _Py_ERROR_IGNORE:
|
||||
_Ty_FALLTHROUGH;
|
||||
case _Ty_ERROR_IGNORE:
|
||||
i += (endpos - startpos - 1);
|
||||
break;
|
||||
|
||||
case _Py_ERROR_SURROGATEPASS:
|
||||
case _Ty_ERROR_SURROGATEPASS:
|
||||
for (k=startpos; k<endpos; k++) {
|
||||
ch = data[k];
|
||||
*p++ = (char)(0xe0 | (ch >> 12));
|
||||
@@ -346,7 +346,7 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
|
||||
i += (endpos - startpos - 1);
|
||||
break;
|
||||
|
||||
case _Py_ERROR_BACKSLASHREPLACE:
|
||||
case _Ty_ERROR_BACKSLASHREPLACE:
|
||||
/* subtract preallocated bytes */
|
||||
writer->min_size -= max_char_size * (endpos - startpos);
|
||||
p = backslashreplace(writer, p,
|
||||
@@ -356,7 +356,7 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
|
||||
i += (endpos - startpos - 1);
|
||||
break;
|
||||
|
||||
case _Py_ERROR_XMLCHARREFREPLACE:
|
||||
case _Ty_ERROR_XMLCHARREFREPLACE:
|
||||
/* subtract preallocated bytes */
|
||||
writer->min_size -= max_char_size * (endpos - startpos);
|
||||
p = xmlcharrefreplace(writer, p,
|
||||
@@ -366,7 +366,7 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
|
||||
i += (endpos - startpos - 1);
|
||||
break;
|
||||
|
||||
case _Py_ERROR_SURROGATEESCAPE:
|
||||
case _Ty_ERROR_SURROGATEESCAPE:
|
||||
for (k=startpos; k<endpos; k++) {
|
||||
ch = data[k];
|
||||
if (!(0xDC80 <= ch && ch <= 0xDCFF))
|
||||
@@ -379,7 +379,7 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
|
||||
}
|
||||
startpos = k;
|
||||
assert(startpos < endpos);
|
||||
_Py_FALLTHROUGH;
|
||||
_Ty_FALLTHROUGH;
|
||||
default:
|
||||
rep = unicode_encode_call_errorhandler(
|
||||
errors, &error_handler_obj, "utf-8", "surrogates not allowed",
|
||||
@@ -401,14 +401,14 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
|
||||
writer->overallocate = (newpos < size);
|
||||
}
|
||||
|
||||
if (PyBytes_Check(rep)) {
|
||||
if (TyBytes_Check(rep)) {
|
||||
p = _PyBytesWriter_WriteBytes(writer, p,
|
||||
PyBytes_AS_STRING(rep),
|
||||
PyBytes_GET_SIZE(rep));
|
||||
TyBytes_AS_STRING(rep),
|
||||
TyBytes_GET_SIZE(rep));
|
||||
}
|
||||
else {
|
||||
/* rep is unicode */
|
||||
if (!PyUnicode_IS_ASCII(rep)) {
|
||||
if (!TyUnicode_IS_ASCII(rep)) {
|
||||
raise_encode_exception(&exc, "utf-8", unicode,
|
||||
startpos, endpos,
|
||||
"surrogates not allowed");
|
||||
@@ -416,13 +416,13 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
|
||||
}
|
||||
|
||||
p = _PyBytesWriter_WriteBytes(writer, p,
|
||||
PyUnicode_DATA(rep),
|
||||
PyUnicode_GET_LENGTH(rep));
|
||||
TyUnicode_DATA(rep),
|
||||
TyUnicode_GET_LENGTH(rep));
|
||||
}
|
||||
|
||||
if (p == NULL)
|
||||
goto error;
|
||||
Py_CLEAR(rep);
|
||||
Ty_CLEAR(rep);
|
||||
|
||||
i = newpos;
|
||||
}
|
||||
@@ -455,16 +455,16 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
|
||||
}
|
||||
|
||||
#if STRINGLIB_SIZEOF_CHAR > 1
|
||||
Py_XDECREF(error_handler_obj);
|
||||
Py_XDECREF(exc);
|
||||
Ty_XDECREF(error_handler_obj);
|
||||
Ty_XDECREF(exc);
|
||||
#endif
|
||||
return p;
|
||||
|
||||
#if STRINGLIB_SIZEOF_CHAR > 1
|
||||
error:
|
||||
Py_XDECREF(rep);
|
||||
Py_XDECREF(error_handler_obj);
|
||||
Py_XDECREF(exc);
|
||||
Ty_XDECREF(rep);
|
||||
Ty_XDECREF(error_handler_obj);
|
||||
Ty_XDECREF(exc);
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
@@ -497,12 +497,12 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
|
||||
#define SWAB(value) ((((value) >> 8) & STRIPPED_MASK) | \
|
||||
(((value) & STRIPPED_MASK) << 8))
|
||||
|
||||
Py_LOCAL_INLINE(Py_UCS4)
|
||||
Ty_LOCAL_INLINE(Ty_UCS4)
|
||||
STRINGLIB(utf16_decode)(const unsigned char **inptr, const unsigned char *e,
|
||||
STRINGLIB_CHAR *dest, Py_ssize_t *outpos,
|
||||
STRINGLIB_CHAR *dest, Ty_ssize_t *outpos,
|
||||
int native_ordering)
|
||||
{
|
||||
Py_UCS4 ch;
|
||||
Ty_UCS4 ch;
|
||||
const unsigned char *q = *inptr;
|
||||
STRINGLIB_CHAR *p = dest + *outpos;
|
||||
/* Offsets from q for retrieving byte pairs in the right order. */
|
||||
@@ -514,10 +514,10 @@ STRINGLIB(utf16_decode)(const unsigned char **inptr, const unsigned char *e,
|
||||
--e;
|
||||
|
||||
while (q < e) {
|
||||
Py_UCS4 ch2;
|
||||
Ty_UCS4 ch2;
|
||||
/* First check for possible aligned read of a C 'long'. Unaligned
|
||||
reads are more expensive, better to defer to another iteration. */
|
||||
if (_Py_IS_ALIGNED(q, ALIGNOF_LONG)) {
|
||||
if (_Ty_IS_ALIGNED(q, ALIGNOF_LONG)) {
|
||||
/* Fast path for runs of in-range non-surrogate chars. */
|
||||
const unsigned char *_q = q;
|
||||
while (_q + SIZEOF_LONG <= e) {
|
||||
@@ -568,7 +568,7 @@ STRINGLIB(utf16_decode)(const unsigned char **inptr, const unsigned char *e,
|
||||
|
||||
ch = (q[ihi] << 8) | q[ilo];
|
||||
q += 2;
|
||||
if (!Py_UNICODE_IS_SURROGATE(ch)) {
|
||||
if (!Ty_UNICODE_IS_SURROGATE(ch)) {
|
||||
#if STRINGLIB_SIZEOF_CHAR < 2
|
||||
if (ch > STRINGLIB_MAX_CHAR)
|
||||
/* Out-of-range */
|
||||
@@ -579,15 +579,15 @@ STRINGLIB(utf16_decode)(const unsigned char **inptr, const unsigned char *e,
|
||||
}
|
||||
|
||||
/* UTF-16 code pair: */
|
||||
if (!Py_UNICODE_IS_HIGH_SURROGATE(ch))
|
||||
if (!Ty_UNICODE_IS_HIGH_SURROGATE(ch))
|
||||
goto IllegalEncoding;
|
||||
if (q >= e)
|
||||
goto UnexpectedEnd;
|
||||
ch2 = (q[ihi] << 8) | q[ilo];
|
||||
q += 2;
|
||||
if (!Py_UNICODE_IS_LOW_SURROGATE(ch2))
|
||||
if (!Ty_UNICODE_IS_LOW_SURROGATE(ch2))
|
||||
goto IllegalSurrogate;
|
||||
ch = Py_UNICODE_JOIN_SURROGATES(ch, ch2);
|
||||
ch = Ty_UNICODE_JOIN_SURROGATES(ch, ch2);
|
||||
#if STRINGLIB_SIZEOF_CHAR < 4
|
||||
/* Out-of-range */
|
||||
goto Return;
|
||||
@@ -617,9 +617,9 @@ IllegalSurrogate:
|
||||
|
||||
|
||||
#if STRINGLIB_MAX_CHAR >= 0x80
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
Ty_LOCAL_INLINE(Ty_ssize_t)
|
||||
STRINGLIB(utf16_encode)(const STRINGLIB_CHAR *in,
|
||||
Py_ssize_t len,
|
||||
Ty_ssize_t len,
|
||||
unsigned short **outptr,
|
||||
int native_ordering)
|
||||
{
|
||||
@@ -627,7 +627,7 @@ STRINGLIB(utf16_encode)(const STRINGLIB_CHAR *in,
|
||||
const STRINGLIB_CHAR *end = in + len;
|
||||
#if STRINGLIB_SIZEOF_CHAR == 1
|
||||
if (native_ordering) {
|
||||
const STRINGLIB_CHAR *unrolled_end = in + _Py_SIZE_ROUND_DOWN(len, 4);
|
||||
const STRINGLIB_CHAR *unrolled_end = in + _Ty_SIZE_ROUND_DOWN(len, 4);
|
||||
while (in < unrolled_end) {
|
||||
out[0] = in[0];
|
||||
out[1] = in[1];
|
||||
@@ -640,7 +640,7 @@ STRINGLIB(utf16_encode)(const STRINGLIB_CHAR *in,
|
||||
}
|
||||
} else {
|
||||
# define SWAB2(CH) ((CH) << 8) /* high byte is zero */
|
||||
const STRINGLIB_CHAR *unrolled_end = in + _Py_SIZE_ROUND_DOWN(len, 4);
|
||||
const STRINGLIB_CHAR *unrolled_end = in + _Ty_SIZE_ROUND_DOWN(len, 4);
|
||||
while (in < unrolled_end) {
|
||||
out[0] = SWAB2(in[0]);
|
||||
out[1] = SWAB2(in[1]);
|
||||
@@ -649,8 +649,8 @@ STRINGLIB(utf16_encode)(const STRINGLIB_CHAR *in,
|
||||
in += 4; out += 4;
|
||||
}
|
||||
while (in < end) {
|
||||
Py_UCS4 ch = *in++;
|
||||
*out++ = SWAB2((Py_UCS2)ch);
|
||||
Ty_UCS4 ch = *in++;
|
||||
*out++ = SWAB2((Ty_UCS2)ch);
|
||||
}
|
||||
#undef SWAB2
|
||||
}
|
||||
@@ -659,7 +659,7 @@ STRINGLIB(utf16_encode)(const STRINGLIB_CHAR *in,
|
||||
#else
|
||||
if (native_ordering) {
|
||||
#if STRINGLIB_MAX_CHAR < 0x10000
|
||||
const STRINGLIB_CHAR *unrolled_end = in + _Py_SIZE_ROUND_DOWN(len, 4);
|
||||
const STRINGLIB_CHAR *unrolled_end = in + _Ty_SIZE_ROUND_DOWN(len, 4);
|
||||
while (in < unrolled_end) {
|
||||
/* check if any character is a surrogate character */
|
||||
if (((in[0] ^ 0xd800) &
|
||||
@@ -675,7 +675,7 @@ STRINGLIB(utf16_encode)(const STRINGLIB_CHAR *in,
|
||||
}
|
||||
#endif
|
||||
while (in < end) {
|
||||
Py_UCS4 ch;
|
||||
Ty_UCS4 ch;
|
||||
ch = *in++;
|
||||
if (ch < 0xd800)
|
||||
*out++ = ch;
|
||||
@@ -684,8 +684,8 @@ STRINGLIB(utf16_encode)(const STRINGLIB_CHAR *in,
|
||||
goto fail;
|
||||
#if STRINGLIB_MAX_CHAR >= 0x10000
|
||||
else if (ch >= 0x10000) {
|
||||
out[0] = Py_UNICODE_HIGH_SURROGATE(ch);
|
||||
out[1] = Py_UNICODE_LOW_SURROGATE(ch);
|
||||
out[0] = Ty_UNICODE_HIGH_SURROGATE(ch);
|
||||
out[1] = Ty_UNICODE_LOW_SURROGATE(ch);
|
||||
out += 2;
|
||||
}
|
||||
#endif
|
||||
@@ -695,7 +695,7 @@ STRINGLIB(utf16_encode)(const STRINGLIB_CHAR *in,
|
||||
} else {
|
||||
#define SWAB2(CH) (((CH) << 8) | ((CH) >> 8))
|
||||
#if STRINGLIB_MAX_CHAR < 0x10000
|
||||
const STRINGLIB_CHAR *unrolled_end = in + _Py_SIZE_ROUND_DOWN(len, 4);
|
||||
const STRINGLIB_CHAR *unrolled_end = in + _Ty_SIZE_ROUND_DOWN(len, 4);
|
||||
while (in < unrolled_end) {
|
||||
/* check if any character is a surrogate character */
|
||||
if (((in[0] ^ 0xd800) &
|
||||
@@ -711,23 +711,23 @@ STRINGLIB(utf16_encode)(const STRINGLIB_CHAR *in,
|
||||
}
|
||||
#endif
|
||||
while (in < end) {
|
||||
Py_UCS4 ch = *in++;
|
||||
Ty_UCS4 ch = *in++;
|
||||
if (ch < 0xd800)
|
||||
*out++ = SWAB2((Py_UCS2)ch);
|
||||
*out++ = SWAB2((Ty_UCS2)ch);
|
||||
else if (ch < 0xe000)
|
||||
/* reject surrogate characters (U+D800-U+DFFF) */
|
||||
goto fail;
|
||||
#if STRINGLIB_MAX_CHAR >= 0x10000
|
||||
else if (ch >= 0x10000) {
|
||||
Py_UCS2 ch1 = Py_UNICODE_HIGH_SURROGATE(ch);
|
||||
Py_UCS2 ch2 = Py_UNICODE_LOW_SURROGATE(ch);
|
||||
Ty_UCS2 ch1 = Ty_UNICODE_HIGH_SURROGATE(ch);
|
||||
Ty_UCS2 ch2 = Ty_UNICODE_LOW_SURROGATE(ch);
|
||||
out[0] = SWAB2(ch1);
|
||||
out[1] = SWAB2(ch2);
|
||||
out += 2;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
*out++ = SWAB2((Py_UCS2)ch);
|
||||
*out++ = SWAB2((Ty_UCS2)ch);
|
||||
}
|
||||
#undef SWAB2
|
||||
}
|
||||
@@ -750,20 +750,20 @@ STRINGLIB(SWAB4)(STRINGLIB_CHAR ch)
|
||||
/* high bytes are zero */
|
||||
return ((word & 0x00FFu) << 24) | ((word & 0xFF00u) << 8);
|
||||
#else
|
||||
return _Py_bswap32(word);
|
||||
return _Ty_bswap32(word);
|
||||
#endif
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
Ty_LOCAL_INLINE(Ty_ssize_t)
|
||||
STRINGLIB(utf32_encode)(const STRINGLIB_CHAR *in,
|
||||
Py_ssize_t len,
|
||||
Ty_ssize_t len,
|
||||
uint32_t **outptr,
|
||||
int native_ordering)
|
||||
{
|
||||
uint32_t *out = *outptr;
|
||||
const STRINGLIB_CHAR *end = in + len;
|
||||
if (native_ordering) {
|
||||
const STRINGLIB_CHAR *unrolled_end = in + _Py_SIZE_ROUND_DOWN(len, 4);
|
||||
const STRINGLIB_CHAR *unrolled_end = in + _Ty_SIZE_ROUND_DOWN(len, 4);
|
||||
while (in < unrolled_end) {
|
||||
#if STRINGLIB_SIZEOF_CHAR > 1
|
||||
/* check if any character is a surrogate character */
|
||||
@@ -780,10 +780,10 @@ STRINGLIB(utf32_encode)(const STRINGLIB_CHAR *in,
|
||||
in += 4; out += 4;
|
||||
}
|
||||
while (in < end) {
|
||||
Py_UCS4 ch;
|
||||
Ty_UCS4 ch;
|
||||
ch = *in++;
|
||||
#if STRINGLIB_SIZEOF_CHAR > 1
|
||||
if (Py_UNICODE_IS_SURROGATE(ch)) {
|
||||
if (Ty_UNICODE_IS_SURROGATE(ch)) {
|
||||
/* reject surrogate characters (U+D800-U+DFFF) */
|
||||
goto fail;
|
||||
}
|
||||
@@ -791,7 +791,7 @@ STRINGLIB(utf32_encode)(const STRINGLIB_CHAR *in,
|
||||
*out++ = ch;
|
||||
}
|
||||
} else {
|
||||
const STRINGLIB_CHAR *unrolled_end = in + _Py_SIZE_ROUND_DOWN(len, 4);
|
||||
const STRINGLIB_CHAR *unrolled_end = in + _Ty_SIZE_ROUND_DOWN(len, 4);
|
||||
while (in < unrolled_end) {
|
||||
#if STRINGLIB_SIZEOF_CHAR > 1
|
||||
/* check if any character is a surrogate character */
|
||||
@@ -808,9 +808,9 @@ STRINGLIB(utf32_encode)(const STRINGLIB_CHAR *in,
|
||||
in += 4; out += 4;
|
||||
}
|
||||
while (in < end) {
|
||||
Py_UCS4 ch = *in++;
|
||||
Ty_UCS4 ch = *in++;
|
||||
#if STRINGLIB_SIZEOF_CHAR > 1
|
||||
if (Py_UNICODE_IS_SURROGATE(ch)) {
|
||||
if (Ty_UNICODE_IS_SURROGATE(ch)) {
|
||||
/* reject surrogate characters (U+D800-U+DFFF) */
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
// UCS1 strings: it's the same than asciilib_count().
|
||||
#if !STRINGLIB_IS_UNICODE || STRINGLIB_MAX_CHAR > 0x7Fu
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
STRINGLIB(count)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
|
||||
Py_ssize_t maxcount)
|
||||
Ty_LOCAL_INLINE(Ty_ssize_t)
|
||||
STRINGLIB(count)(const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sub, Ty_ssize_t sub_len,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
Py_ssize_t count;
|
||||
Ty_ssize_t count;
|
||||
|
||||
if (str_len < 0)
|
||||
return 0; /* start > len(str) */
|
||||
|
||||
@@ -4,113 +4,113 @@
|
||||
|
||||
#include "pycore_bytes_methods.h"
|
||||
|
||||
static PyObject*
|
||||
stringlib_isspace(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_isspace(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
return _Py_bytes_isspace(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
return _Ty_bytes_isspace(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
stringlib_isalpha(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_isalpha(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
return _Py_bytes_isalpha(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
return _Ty_bytes_isalpha(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
stringlib_isalnum(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_isalnum(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
return _Py_bytes_isalnum(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
return _Ty_bytes_isalnum(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
stringlib_isascii(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_isascii(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
return _Py_bytes_isascii(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
return _Ty_bytes_isascii(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
stringlib_isdigit(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_isdigit(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
return _Py_bytes_isdigit(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
return _Ty_bytes_isdigit(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
stringlib_islower(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_islower(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
return _Py_bytes_islower(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
return _Ty_bytes_islower(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
stringlib_isupper(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_isupper(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
return _Py_bytes_isupper(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
return _Ty_bytes_isupper(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
stringlib_istitle(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_istitle(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
return _Py_bytes_istitle(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
return _Ty_bytes_istitle(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
}
|
||||
|
||||
|
||||
/* functions that return a new object partially translated by ctype funcs: */
|
||||
|
||||
static PyObject*
|
||||
stringlib_lower(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_lower(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
PyObject* newobj;
|
||||
TyObject* newobj;
|
||||
newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
|
||||
if (!newobj)
|
||||
return NULL;
|
||||
_Py_bytes_lower(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
|
||||
_Ty_bytes_lower(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
|
||||
STRINGLIB_LEN(self));
|
||||
return newobj;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
stringlib_upper(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_upper(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
PyObject* newobj;
|
||||
TyObject* newobj;
|
||||
newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
|
||||
if (!newobj)
|
||||
return NULL;
|
||||
_Py_bytes_upper(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
|
||||
_Ty_bytes_upper(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
|
||||
STRINGLIB_LEN(self));
|
||||
return newobj;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
stringlib_title(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_title(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
PyObject* newobj;
|
||||
TyObject* newobj;
|
||||
newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
|
||||
if (!newobj)
|
||||
return NULL;
|
||||
_Py_bytes_title(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
|
||||
_Ty_bytes_title(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
|
||||
STRINGLIB_LEN(self));
|
||||
return newobj;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
stringlib_capitalize(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_capitalize(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
PyObject* newobj;
|
||||
TyObject* newobj;
|
||||
newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
|
||||
if (!newobj)
|
||||
return NULL;
|
||||
_Py_bytes_capitalize(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
|
||||
_Ty_bytes_capitalize(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
|
||||
STRINGLIB_LEN(self));
|
||||
return newobj;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
stringlib_swapcase(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
static TyObject*
|
||||
stringlib_swapcase(TyObject *self, TyObject *Ty_UNUSED(ignored))
|
||||
{
|
||||
PyObject* newobj;
|
||||
TyObject* newobj;
|
||||
newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
|
||||
if (!newobj)
|
||||
return NULL;
|
||||
_Py_bytes_swapcase(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
|
||||
_Ty_bytes_swapcase(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
|
||||
STRINGLIB_LEN(self));
|
||||
return newobj;
|
||||
}
|
||||
|
||||
@@ -3,20 +3,20 @@
|
||||
/* Return 1 if two unicode objects are equal, 0 if not.
|
||||
* unicode_eq() is called when the hash of two unicode objects is equal.
|
||||
*/
|
||||
Py_LOCAL_INLINE(int)
|
||||
unicode_eq(PyObject *str1, PyObject *str2)
|
||||
Ty_LOCAL_INLINE(int)
|
||||
unicode_eq(TyObject *str1, TyObject *str2)
|
||||
{
|
||||
Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
|
||||
if (PyUnicode_GET_LENGTH(str2) != len) {
|
||||
Ty_ssize_t len = TyUnicode_GET_LENGTH(str1);
|
||||
if (TyUnicode_GET_LENGTH(str2) != len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int kind = PyUnicode_KIND(str1);
|
||||
if (PyUnicode_KIND(str2) != kind) {
|
||||
int kind = TyUnicode_KIND(str1);
|
||||
if (TyUnicode_KIND(str2) != kind) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const void *data1 = PyUnicode_DATA(str1);
|
||||
const void *data2 = PyUnicode_DATA(str2);
|
||||
const void *data1 = TyUnicode_DATA(str1);
|
||||
const void *data2 = TyUnicode_DATA(str2);
|
||||
return (memcmp(data1, data2, len * kind) == 0);
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@
|
||||
# define MEMCHR_CUT_OFF 40
|
||||
#endif
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
STRINGLIB(find_char)(const STRINGLIB_CHAR* s, Py_ssize_t n, STRINGLIB_CHAR ch)
|
||||
Ty_LOCAL_INLINE(Ty_ssize_t)
|
||||
STRINGLIB(find_char)(const STRINGLIB_CHAR* s, Ty_ssize_t n, STRINGLIB_CHAR ch)
|
||||
{
|
||||
const STRINGLIB_CHAR *p, *e;
|
||||
|
||||
@@ -75,7 +75,7 @@ STRINGLIB(find_char)(const STRINGLIB_CHAR* s, Py_ssize_t n, STRINGLIB_CHAR ch)
|
||||
return -1;
|
||||
s1 = p;
|
||||
p = (const STRINGLIB_CHAR *)
|
||||
_Py_ALIGN_DOWN(candidate, sizeof(STRINGLIB_CHAR));
|
||||
_Ty_ALIGN_DOWN(candidate, sizeof(STRINGLIB_CHAR));
|
||||
if (*p == ch)
|
||||
return (p - s);
|
||||
/* False positive */
|
||||
@@ -112,8 +112,8 @@ STRINGLIB(find_char)(const STRINGLIB_CHAR* s, Py_ssize_t n, STRINGLIB_CHAR ch)
|
||||
#endif
|
||||
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
STRINGLIB(rfind_char)(const STRINGLIB_CHAR* s, Py_ssize_t n, STRINGLIB_CHAR ch)
|
||||
Ty_LOCAL_INLINE(Ty_ssize_t)
|
||||
STRINGLIB(rfind_char)(const STRINGLIB_CHAR* s, Ty_ssize_t n, STRINGLIB_CHAR ch)
|
||||
{
|
||||
const STRINGLIB_CHAR *p;
|
||||
#ifdef HAVE_MEMRCHR
|
||||
@@ -132,7 +132,7 @@ STRINGLIB(rfind_char)(const STRINGLIB_CHAR* s, Py_ssize_t n, STRINGLIB_CHAR ch)
|
||||
/* use memrchr if we can choose a needle without too many likely
|
||||
false positives */
|
||||
const STRINGLIB_CHAR *s1;
|
||||
Py_ssize_t n1;
|
||||
Ty_ssize_t n1;
|
||||
unsigned char needle = ch & 0xff;
|
||||
/* If looking for a multiple of 256, we'd have too
|
||||
many false positives looking for the '\0' byte in UCS2
|
||||
@@ -145,7 +145,7 @@ STRINGLIB(rfind_char)(const STRINGLIB_CHAR* s, Py_ssize_t n, STRINGLIB_CHAR ch)
|
||||
return -1;
|
||||
n1 = n;
|
||||
p = (const STRINGLIB_CHAR *)
|
||||
_Py_ALIGN_DOWN(candidate, sizeof(STRINGLIB_CHAR));
|
||||
_Ty_ALIGN_DOWN(candidate, sizeof(STRINGLIB_CHAR));
|
||||
n = p - s;
|
||||
if (*p == ch)
|
||||
return n;
|
||||
@@ -193,18 +193,18 @@ STRINGLIB(rfind_char)(const STRINGLIB_CHAR* s, Py_ssize_t n, STRINGLIB_CHAR ch)
|
||||
# define LOG_LINEUP()
|
||||
#endif
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
STRINGLIB(_lex_search)(const STRINGLIB_CHAR *needle, Py_ssize_t len_needle,
|
||||
Py_ssize_t *return_period, int invert_alphabet)
|
||||
Ty_LOCAL_INLINE(Ty_ssize_t)
|
||||
STRINGLIB(_lex_search)(const STRINGLIB_CHAR *needle, Ty_ssize_t len_needle,
|
||||
Ty_ssize_t *return_period, int invert_alphabet)
|
||||
{
|
||||
/* Do a lexicographic search. Essentially this:
|
||||
>>> max(needle[i:] for i in range(len(needle)+1))
|
||||
Also find the period of the right half. */
|
||||
Py_ssize_t max_suffix = 0;
|
||||
Py_ssize_t candidate = 1;
|
||||
Py_ssize_t k = 0;
|
||||
Ty_ssize_t max_suffix = 0;
|
||||
Ty_ssize_t candidate = 1;
|
||||
Ty_ssize_t k = 0;
|
||||
// The period of the right half.
|
||||
Py_ssize_t period = 1;
|
||||
Ty_ssize_t period = 1;
|
||||
|
||||
while (candidate + k < len_needle) {
|
||||
// each loop increases candidate + k + max_suffix
|
||||
@@ -245,10 +245,10 @@ STRINGLIB(_lex_search)(const STRINGLIB_CHAR *needle, Py_ssize_t len_needle,
|
||||
return max_suffix;
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
Ty_LOCAL_INLINE(Ty_ssize_t)
|
||||
STRINGLIB(_factorize)(const STRINGLIB_CHAR *needle,
|
||||
Py_ssize_t len_needle,
|
||||
Py_ssize_t *return_period)
|
||||
Ty_ssize_t len_needle,
|
||||
Ty_ssize_t *return_period)
|
||||
{
|
||||
/* Do a "critical factorization", making it so that:
|
||||
>>> needle = (left := needle[:cut]) + (right := needle[cut:])
|
||||
@@ -282,7 +282,7 @@ STRINGLIB(_factorize)(const STRINGLIB_CHAR *needle,
|
||||
The length of this minimal repetition is 7, which is indeed the
|
||||
period of the original string. */
|
||||
|
||||
Py_ssize_t cut1, period1, cut2, period2, cut, period;
|
||||
Ty_ssize_t cut1, period1, cut2, period2, cut, period;
|
||||
cut1 = STRINGLIB(_lex_search)(needle, len_needle, &period1, 0);
|
||||
cut2 = STRINGLIB(_lex_search)(needle, len_needle, &period2, 1);
|
||||
|
||||
@@ -314,17 +314,17 @@ STRINGLIB(_factorize)(const STRINGLIB_CHAR *needle,
|
||||
|
||||
typedef struct STRINGLIB(_pre) {
|
||||
const STRINGLIB_CHAR *needle;
|
||||
Py_ssize_t len_needle;
|
||||
Py_ssize_t cut;
|
||||
Py_ssize_t period;
|
||||
Py_ssize_t gap;
|
||||
Ty_ssize_t len_needle;
|
||||
Ty_ssize_t cut;
|
||||
Ty_ssize_t period;
|
||||
Ty_ssize_t gap;
|
||||
int is_periodic;
|
||||
SHIFT_TYPE table[TABLE_SIZE];
|
||||
} STRINGLIB(prework);
|
||||
|
||||
|
||||
static void
|
||||
STRINGLIB(_preprocess)(const STRINGLIB_CHAR *needle, Py_ssize_t len_needle,
|
||||
STRINGLIB(_preprocess)(const STRINGLIB_CHAR *needle, Ty_ssize_t len_needle,
|
||||
STRINGLIB(prework) *p)
|
||||
{
|
||||
p->needle = needle;
|
||||
@@ -340,13 +340,13 @@ STRINGLIB(_preprocess)(const STRINGLIB_CHAR *needle, Py_ssize_t len_needle,
|
||||
}
|
||||
else {
|
||||
// A lower bound on the period
|
||||
p->period = Py_MAX(p->cut, len_needle - p->cut) + 1;
|
||||
p->period = Ty_MAX(p->cut, len_needle - p->cut) + 1;
|
||||
}
|
||||
// The gap between the last character and the previous
|
||||
// occurrence of an equivalent character (modulo TABLE_SIZE)
|
||||
p->gap = len_needle;
|
||||
STRINGLIB_CHAR last = needle[len_needle - 1] & TABLE_MASK;
|
||||
for (Py_ssize_t i = len_needle - 2; i >= 0; i--) {
|
||||
for (Ty_ssize_t i = len_needle - 2; i >= 0; i--) {
|
||||
STRINGLIB_CHAR x = needle[i] & TABLE_MASK;
|
||||
if (x == last) {
|
||||
p->gap = len_needle - 1 - i;
|
||||
@@ -354,27 +354,27 @@ STRINGLIB(_preprocess)(const STRINGLIB_CHAR *needle, Py_ssize_t len_needle,
|
||||
}
|
||||
}
|
||||
// Fill up a compressed Boyer-Moore "Bad Character" table
|
||||
Py_ssize_t not_found_shift = Py_MIN(len_needle, MAX_SHIFT);
|
||||
for (Py_ssize_t i = 0; i < (Py_ssize_t)TABLE_SIZE; i++) {
|
||||
p->table[i] = Py_SAFE_DOWNCAST(not_found_shift,
|
||||
Py_ssize_t, SHIFT_TYPE);
|
||||
Ty_ssize_t not_found_shift = Ty_MIN(len_needle, MAX_SHIFT);
|
||||
for (Ty_ssize_t i = 0; i < (Ty_ssize_t)TABLE_SIZE; i++) {
|
||||
p->table[i] = Ty_SAFE_DOWNCAST(not_found_shift,
|
||||
Ty_ssize_t, SHIFT_TYPE);
|
||||
}
|
||||
for (Py_ssize_t i = len_needle - not_found_shift; i < len_needle; i++) {
|
||||
SHIFT_TYPE shift = Py_SAFE_DOWNCAST(len_needle - 1 - i,
|
||||
Py_ssize_t, SHIFT_TYPE);
|
||||
for (Ty_ssize_t i = len_needle - not_found_shift; i < len_needle; i++) {
|
||||
SHIFT_TYPE shift = Ty_SAFE_DOWNCAST(len_needle - 1 - i,
|
||||
Ty_ssize_t, SHIFT_TYPE);
|
||||
p->table[needle[i] & TABLE_MASK] = shift;
|
||||
}
|
||||
}
|
||||
|
||||
static Py_ssize_t
|
||||
STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
|
||||
static Ty_ssize_t
|
||||
STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Ty_ssize_t len_haystack,
|
||||
STRINGLIB(prework) *p)
|
||||
{
|
||||
// Crochemore and Perrin's (1991) Two-Way algorithm.
|
||||
// See http://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260
|
||||
const Py_ssize_t len_needle = p->len_needle;
|
||||
const Py_ssize_t cut = p->cut;
|
||||
Py_ssize_t period = p->period;
|
||||
const Ty_ssize_t len_needle = p->len_needle;
|
||||
const Ty_ssize_t cut = p->cut;
|
||||
Ty_ssize_t period = p->period;
|
||||
const STRINGLIB_CHAR *const needle = p->needle;
|
||||
const STRINGLIB_CHAR *window_last = haystack + len_needle - 1;
|
||||
const STRINGLIB_CHAR *const haystack_end = haystack + len_haystack;
|
||||
@@ -382,17 +382,17 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
|
||||
const STRINGLIB_CHAR *window;
|
||||
LOG("===== Two-way: \"%s\" in \"%s\". =====\n", needle, haystack);
|
||||
|
||||
Py_ssize_t gap = p->gap;
|
||||
Py_ssize_t gap_jump_end = Py_MIN(len_needle, cut + gap);
|
||||
Ty_ssize_t gap = p->gap;
|
||||
Ty_ssize_t gap_jump_end = Ty_MIN(len_needle, cut + gap);
|
||||
if (p->is_periodic) {
|
||||
LOG("Needle is periodic.\n");
|
||||
Py_ssize_t memory = 0;
|
||||
Ty_ssize_t memory = 0;
|
||||
periodicwindowloop:
|
||||
while (window_last < haystack_end) {
|
||||
assert(memory == 0);
|
||||
for (;;) {
|
||||
LOG_LINEUP();
|
||||
Py_ssize_t shift = table[(*window_last) & TABLE_MASK];
|
||||
Ty_ssize_t shift = table[(*window_last) & TABLE_MASK];
|
||||
window_last += shift;
|
||||
if (shift == 0) {
|
||||
break;
|
||||
@@ -406,7 +406,7 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
|
||||
window = window_last - len_needle + 1;
|
||||
assert((window[len_needle - 1] & TABLE_MASK) ==
|
||||
(needle[len_needle - 1] & TABLE_MASK));
|
||||
Py_ssize_t i = Py_MAX(cut, memory);
|
||||
Ty_ssize_t i = Ty_MAX(cut, memory);
|
||||
for (; i < len_needle; i++) {
|
||||
if (needle[i] != window[i]) {
|
||||
if (i < gap_jump_end) {
|
||||
@@ -431,16 +431,16 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
|
||||
if (window_last >= haystack_end) {
|
||||
return -1;
|
||||
}
|
||||
Py_ssize_t shift = table[(*window_last) & TABLE_MASK];
|
||||
Ty_ssize_t shift = table[(*window_last) & TABLE_MASK];
|
||||
if (shift) {
|
||||
// A mismatch has been identified to the right
|
||||
// of where i will next start, so we can jump
|
||||
// at least as far as if the mismatch occurred
|
||||
// on the first comparison.
|
||||
Py_ssize_t mem_jump = Py_MAX(cut, memory) - cut + 1;
|
||||
Ty_ssize_t mem_jump = Ty_MAX(cut, memory) - cut + 1;
|
||||
LOG("Skip with Memory.\n");
|
||||
memory = 0;
|
||||
window_last += Py_MAX(shift, mem_jump);
|
||||
window_last += Ty_MAX(shift, mem_jump);
|
||||
goto periodicwindowloop;
|
||||
}
|
||||
goto no_shift;
|
||||
@@ -451,13 +451,13 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
|
||||
}
|
||||
}
|
||||
else {
|
||||
period = Py_MAX(gap, period);
|
||||
period = Ty_MAX(gap, period);
|
||||
LOG("Needle is not periodic.\n");
|
||||
windowloop:
|
||||
while (window_last < haystack_end) {
|
||||
for (;;) {
|
||||
LOG_LINEUP();
|
||||
Py_ssize_t shift = table[(*window_last) & TABLE_MASK];
|
||||
Ty_ssize_t shift = table[(*window_last) & TABLE_MASK];
|
||||
window_last += shift;
|
||||
if (shift == 0) {
|
||||
break;
|
||||
@@ -470,7 +470,7 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
|
||||
window = window_last - len_needle + 1;
|
||||
assert((window[len_needle - 1] & TABLE_MASK) ==
|
||||
(needle[len_needle - 1] & TABLE_MASK));
|
||||
Py_ssize_t i = cut;
|
||||
Ty_ssize_t i = cut;
|
||||
for (; i < len_needle; i++) {
|
||||
if (needle[i] != window[i]) {
|
||||
if (i < gap_jump_end) {
|
||||
@@ -486,7 +486,7 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
|
||||
goto windowloop;
|
||||
}
|
||||
}
|
||||
for (Py_ssize_t i = 0; i < cut; i++) {
|
||||
for (Ty_ssize_t i = 0; i < cut; i++) {
|
||||
if (needle[i] != window[i]) {
|
||||
LOG("Left half does not match.\n");
|
||||
window_last += period;
|
||||
@@ -502,11 +502,11 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
|
||||
}
|
||||
|
||||
|
||||
static Py_ssize_t
|
||||
static Ty_ssize_t
|
||||
STRINGLIB(_two_way_find)(const STRINGLIB_CHAR *haystack,
|
||||
Py_ssize_t len_haystack,
|
||||
Ty_ssize_t len_haystack,
|
||||
const STRINGLIB_CHAR *needle,
|
||||
Py_ssize_t len_needle)
|
||||
Ty_ssize_t len_needle)
|
||||
{
|
||||
LOG("###### Finding \"%s\" in \"%s\".\n", needle, haystack);
|
||||
STRINGLIB(prework) p;
|
||||
@@ -515,19 +515,19 @@ STRINGLIB(_two_way_find)(const STRINGLIB_CHAR *haystack,
|
||||
}
|
||||
|
||||
|
||||
static Py_ssize_t
|
||||
static Ty_ssize_t
|
||||
STRINGLIB(_two_way_count)(const STRINGLIB_CHAR *haystack,
|
||||
Py_ssize_t len_haystack,
|
||||
Ty_ssize_t len_haystack,
|
||||
const STRINGLIB_CHAR *needle,
|
||||
Py_ssize_t len_needle,
|
||||
Py_ssize_t maxcount)
|
||||
Ty_ssize_t len_needle,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
LOG("###### Counting \"%s\" in \"%s\".\n", needle, haystack);
|
||||
STRINGLIB(prework) p;
|
||||
STRINGLIB(_preprocess)(needle, len_needle, &p);
|
||||
Py_ssize_t index = 0, count = 0;
|
||||
Ty_ssize_t index = 0, count = 0;
|
||||
while (1) {
|
||||
Py_ssize_t result;
|
||||
Ty_ssize_t result;
|
||||
result = STRINGLIB(_two_way)(haystack + index,
|
||||
len_haystack - index, &p);
|
||||
if (result == -1) {
|
||||
@@ -553,19 +553,19 @@ STRINGLIB(_two_way_count)(const STRINGLIB_CHAR *haystack,
|
||||
#undef LOG_STRING
|
||||
#undef LOG_LINEUP
|
||||
|
||||
static inline Py_ssize_t
|
||||
STRINGLIB(default_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
|
||||
const STRINGLIB_CHAR* p, Py_ssize_t m,
|
||||
Py_ssize_t maxcount, int mode)
|
||||
static inline Ty_ssize_t
|
||||
STRINGLIB(default_find)(const STRINGLIB_CHAR* s, Ty_ssize_t n,
|
||||
const STRINGLIB_CHAR* p, Ty_ssize_t m,
|
||||
Ty_ssize_t maxcount, int mode)
|
||||
{
|
||||
const Py_ssize_t w = n - m;
|
||||
Py_ssize_t mlast = m - 1, count = 0;
|
||||
Py_ssize_t gap = mlast;
|
||||
const Ty_ssize_t w = n - m;
|
||||
Ty_ssize_t mlast = m - 1, count = 0;
|
||||
Ty_ssize_t gap = mlast;
|
||||
const STRINGLIB_CHAR last = p[mlast];
|
||||
const STRINGLIB_CHAR *const ss = &s[mlast];
|
||||
|
||||
unsigned long mask = 0;
|
||||
for (Py_ssize_t i = 0; i < mlast; i++) {
|
||||
for (Ty_ssize_t i = 0; i < mlast; i++) {
|
||||
STRINGLIB_BLOOM_ADD(mask, p[i]);
|
||||
if (p[i] == last) {
|
||||
gap = mlast - i - 1;
|
||||
@@ -573,10 +573,10 @@ STRINGLIB(default_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
|
||||
}
|
||||
STRINGLIB_BLOOM_ADD(mask, last);
|
||||
|
||||
for (Py_ssize_t i = 0; i <= w; i++) {
|
||||
for (Ty_ssize_t i = 0; i <= w; i++) {
|
||||
if (ss[i] == last) {
|
||||
/* candidate match */
|
||||
Py_ssize_t j;
|
||||
Ty_ssize_t j;
|
||||
for (j = 0; j < mlast; j++) {
|
||||
if (s[i+j] != p[j]) {
|
||||
break;
|
||||
@@ -613,20 +613,20 @@ STRINGLIB(default_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
|
||||
}
|
||||
|
||||
|
||||
static Py_ssize_t
|
||||
STRINGLIB(adaptive_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
|
||||
const STRINGLIB_CHAR* p, Py_ssize_t m,
|
||||
Py_ssize_t maxcount, int mode)
|
||||
static Ty_ssize_t
|
||||
STRINGLIB(adaptive_find)(const STRINGLIB_CHAR* s, Ty_ssize_t n,
|
||||
const STRINGLIB_CHAR* p, Ty_ssize_t m,
|
||||
Ty_ssize_t maxcount, int mode)
|
||||
{
|
||||
const Py_ssize_t w = n - m;
|
||||
Py_ssize_t mlast = m - 1, count = 0;
|
||||
Py_ssize_t gap = mlast;
|
||||
Py_ssize_t hits = 0, res;
|
||||
const Ty_ssize_t w = n - m;
|
||||
Ty_ssize_t mlast = m - 1, count = 0;
|
||||
Ty_ssize_t gap = mlast;
|
||||
Ty_ssize_t hits = 0, res;
|
||||
const STRINGLIB_CHAR last = p[mlast];
|
||||
const STRINGLIB_CHAR *const ss = &s[mlast];
|
||||
|
||||
unsigned long mask = 0;
|
||||
for (Py_ssize_t i = 0; i < mlast; i++) {
|
||||
for (Ty_ssize_t i = 0; i < mlast; i++) {
|
||||
STRINGLIB_BLOOM_ADD(mask, p[i]);
|
||||
if (p[i] == last) {
|
||||
gap = mlast - i - 1;
|
||||
@@ -634,10 +634,10 @@ STRINGLIB(adaptive_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
|
||||
}
|
||||
STRINGLIB_BLOOM_ADD(mask, last);
|
||||
|
||||
for (Py_ssize_t i = 0; i <= w; i++) {
|
||||
for (Ty_ssize_t i = 0; i <= w; i++) {
|
||||
if (ss[i] == last) {
|
||||
/* candidate match */
|
||||
Py_ssize_t j;
|
||||
Ty_ssize_t j;
|
||||
for (j = 0; j < mlast; j++) {
|
||||
if (s[i+j] != p[j]) {
|
||||
break;
|
||||
@@ -686,14 +686,14 @@ STRINGLIB(adaptive_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
|
||||
}
|
||||
|
||||
|
||||
static Py_ssize_t
|
||||
STRINGLIB(default_rfind)(const STRINGLIB_CHAR* s, Py_ssize_t n,
|
||||
const STRINGLIB_CHAR* p, Py_ssize_t m,
|
||||
Py_ssize_t maxcount, int mode)
|
||||
static Ty_ssize_t
|
||||
STRINGLIB(default_rfind)(const STRINGLIB_CHAR* s, Ty_ssize_t n,
|
||||
const STRINGLIB_CHAR* p, Ty_ssize_t m,
|
||||
Ty_ssize_t maxcount, int mode)
|
||||
{
|
||||
/* create compressed boyer-moore delta 1 table */
|
||||
unsigned long mask = 0;
|
||||
Py_ssize_t i, j, mlast = m - 1, skip = m - 1, w = n - m;
|
||||
Ty_ssize_t i, j, mlast = m - 1, skip = m - 1, w = n - m;
|
||||
|
||||
/* process pattern[0] outside the loop */
|
||||
STRINGLIB_BLOOM_ADD(mask, p[0]);
|
||||
@@ -736,11 +736,11 @@ STRINGLIB(default_rfind)(const STRINGLIB_CHAR* s, Py_ssize_t n,
|
||||
}
|
||||
|
||||
|
||||
static inline Py_ssize_t
|
||||
STRINGLIB(count_char)(const STRINGLIB_CHAR *s, Py_ssize_t n,
|
||||
const STRINGLIB_CHAR p0, Py_ssize_t maxcount)
|
||||
static inline Ty_ssize_t
|
||||
STRINGLIB(count_char)(const STRINGLIB_CHAR *s, Ty_ssize_t n,
|
||||
const STRINGLIB_CHAR p0, Ty_ssize_t maxcount)
|
||||
{
|
||||
Py_ssize_t i, count = 0;
|
||||
Ty_ssize_t i, count = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
if (s[i] == p0) {
|
||||
count++;
|
||||
@@ -753,14 +753,14 @@ STRINGLIB(count_char)(const STRINGLIB_CHAR *s, Py_ssize_t n,
|
||||
}
|
||||
|
||||
|
||||
static inline Py_ssize_t
|
||||
STRINGLIB(count_char_no_maxcount)(const STRINGLIB_CHAR *s, Py_ssize_t n,
|
||||
static inline Ty_ssize_t
|
||||
STRINGLIB(count_char_no_maxcount)(const STRINGLIB_CHAR *s, Ty_ssize_t n,
|
||||
const STRINGLIB_CHAR p0)
|
||||
/* A specialized function of count_char that does not cut off at a maximum.
|
||||
As a result, the compiler is able to vectorize the loop. */
|
||||
{
|
||||
Py_ssize_t count = 0;
|
||||
for (Py_ssize_t i = 0; i < n; i++) {
|
||||
Ty_ssize_t count = 0;
|
||||
for (Ty_ssize_t i = 0; i < n; i++) {
|
||||
if (s[i] == p0) {
|
||||
count++;
|
||||
}
|
||||
@@ -769,10 +769,10 @@ STRINGLIB(count_char_no_maxcount)(const STRINGLIB_CHAR *s, Py_ssize_t n,
|
||||
}
|
||||
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
FASTSEARCH(const STRINGLIB_CHAR* s, Py_ssize_t n,
|
||||
const STRINGLIB_CHAR* p, Py_ssize_t m,
|
||||
Py_ssize_t maxcount, int mode)
|
||||
Ty_LOCAL_INLINE(Ty_ssize_t)
|
||||
FASTSEARCH(const STRINGLIB_CHAR* s, Ty_ssize_t n,
|
||||
const STRINGLIB_CHAR* p, Ty_ssize_t m,
|
||||
Ty_ssize_t maxcount, int mode)
|
||||
{
|
||||
if (n < m || (mode == FAST_COUNT && maxcount == 0)) {
|
||||
return -1;
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
#error must include "stringlib/fastsearch.h" before including this module
|
||||
#endif
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
STRINGLIB(find)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
|
||||
Py_ssize_t offset)
|
||||
Ty_LOCAL_INLINE(Ty_ssize_t)
|
||||
STRINGLIB(find)(const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sub, Ty_ssize_t sub_len,
|
||||
Ty_ssize_t offset)
|
||||
{
|
||||
Py_ssize_t pos;
|
||||
Ty_ssize_t pos;
|
||||
|
||||
assert(str_len >= 0);
|
||||
if (sub_len == 0)
|
||||
@@ -23,12 +23,12 @@ STRINGLIB(find)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
return pos;
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
STRINGLIB(rfind)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
|
||||
Py_ssize_t offset)
|
||||
Ty_LOCAL_INLINE(Ty_ssize_t)
|
||||
STRINGLIB(rfind)(const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sub, Ty_ssize_t sub_len,
|
||||
Ty_ssize_t offset)
|
||||
{
|
||||
Py_ssize_t pos;
|
||||
Ty_ssize_t pos;
|
||||
|
||||
assert(str_len >= 0);
|
||||
if (sub_len == 0)
|
||||
@@ -42,26 +42,26 @@ STRINGLIB(rfind)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
return pos;
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
STRINGLIB(find_slice)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
|
||||
Py_ssize_t start, Py_ssize_t end)
|
||||
Ty_LOCAL_INLINE(Ty_ssize_t)
|
||||
STRINGLIB(find_slice)(const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sub, Ty_ssize_t sub_len,
|
||||
Ty_ssize_t start, Ty_ssize_t end)
|
||||
{
|
||||
return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(Py_ssize_t)
|
||||
STRINGLIB(rfind_slice)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
|
||||
Py_ssize_t start, Py_ssize_t end)
|
||||
Ty_LOCAL_INLINE(Ty_ssize_t)
|
||||
STRINGLIB(rfind_slice)(const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sub, Ty_ssize_t sub_len,
|
||||
Ty_ssize_t start, Ty_ssize_t end)
|
||||
{
|
||||
return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start);
|
||||
}
|
||||
|
||||
#ifdef STRINGLIB_WANT_CONTAINS_OBJ
|
||||
|
||||
Py_LOCAL_INLINE(int)
|
||||
STRINGLIB(contains_obj)(PyObject* str, PyObject* sub)
|
||||
Ty_LOCAL_INLINE(int)
|
||||
STRINGLIB(contains_obj)(TyObject* str, TyObject* sub)
|
||||
{
|
||||
return STRINGLIB(find)(
|
||||
STRINGLIB_STR(str), STRINGLIB_LEN(str),
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
|
||||
#if STRINGLIB_SIZEOF_CHAR == 1
|
||||
|
||||
Py_LOCAL_INLINE(Py_UCS4)
|
||||
Ty_LOCAL_INLINE(Ty_UCS4)
|
||||
STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end)
|
||||
{
|
||||
const unsigned char *p = (const unsigned char *) begin;
|
||||
const unsigned char *_end = (const unsigned char *)end;
|
||||
|
||||
while (p < _end) {
|
||||
if (_Py_IS_ALIGNED(p, ALIGNOF_SIZE_T)) {
|
||||
if (_Ty_IS_ALIGNED(p, ALIGNOF_SIZE_T)) {
|
||||
/* Help register allocation */
|
||||
const unsigned char *_p = p;
|
||||
while (_p + SIZEOF_SIZE_T <= _end) {
|
||||
@@ -56,23 +56,23 @@ STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end)
|
||||
#define MAX_CHAR_UCS2 0xffff
|
||||
#define MAX_CHAR_UCS4 0x10ffff
|
||||
|
||||
Py_LOCAL_INLINE(Py_UCS4)
|
||||
Ty_LOCAL_INLINE(Ty_UCS4)
|
||||
STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end)
|
||||
{
|
||||
#if STRINGLIB_SIZEOF_CHAR == 2
|
||||
const Py_UCS4 mask_limit = MASK_UCS1;
|
||||
const Py_UCS4 max_char_limit = MAX_CHAR_UCS2;
|
||||
const Ty_UCS4 mask_limit = MASK_UCS1;
|
||||
const Ty_UCS4 max_char_limit = MAX_CHAR_UCS2;
|
||||
#elif STRINGLIB_SIZEOF_CHAR == 4
|
||||
const Py_UCS4 mask_limit = MASK_UCS2;
|
||||
const Py_UCS4 max_char_limit = MAX_CHAR_UCS4;
|
||||
const Ty_UCS4 mask_limit = MASK_UCS2;
|
||||
const Ty_UCS4 max_char_limit = MAX_CHAR_UCS4;
|
||||
#else
|
||||
#error Invalid STRINGLIB_SIZEOF_CHAR (must be 1, 2 or 4)
|
||||
#endif
|
||||
Py_UCS4 mask;
|
||||
Py_ssize_t n = end - begin;
|
||||
Ty_UCS4 mask;
|
||||
Ty_ssize_t n = end - begin;
|
||||
const STRINGLIB_CHAR *p = begin;
|
||||
const STRINGLIB_CHAR *unrolled_end = begin + _Py_SIZE_ROUND_DOWN(n, 4);
|
||||
Py_UCS4 max_char;
|
||||
const STRINGLIB_CHAR *unrolled_end = begin + _Ty_SIZE_ROUND_DOWN(n, 4);
|
||||
Ty_UCS4 max_char;
|
||||
|
||||
max_char = MAX_CHAR_ASCII;
|
||||
mask = MASK_ASCII;
|
||||
|
||||
@@ -4,20 +4,20 @@
|
||||
#error join.h only compatible with byte-wise strings
|
||||
#endif
|
||||
|
||||
Py_LOCAL_INLINE(PyObject *)
|
||||
STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
|
||||
Ty_LOCAL_INLINE(TyObject *)
|
||||
STRINGLIB(bytes_join)(TyObject *sep, TyObject *iterable)
|
||||
{
|
||||
const char *sepstr = STRINGLIB_STR(sep);
|
||||
Py_ssize_t seplen = STRINGLIB_LEN(sep);
|
||||
PyObject *res = NULL;
|
||||
Ty_ssize_t seplen = STRINGLIB_LEN(sep);
|
||||
TyObject *res = NULL;
|
||||
char *p;
|
||||
Py_ssize_t seqlen = 0;
|
||||
Py_ssize_t sz = 0;
|
||||
Py_ssize_t i, nbufs;
|
||||
PyObject *seq, *item;
|
||||
Py_buffer *buffers = NULL;
|
||||
Ty_ssize_t seqlen = 0;
|
||||
Ty_ssize_t sz = 0;
|
||||
Ty_ssize_t i, nbufs;
|
||||
TyObject *seq, *item;
|
||||
Ty_buffer *buffers = NULL;
|
||||
#define NB_STATIC_BUFFERS 10
|
||||
Py_buffer static_buffers[NB_STATIC_BUFFERS];
|
||||
Ty_buffer static_buffers[NB_STATIC_BUFFERS];
|
||||
#define GIL_THRESHOLD 1048576
|
||||
int drop_gil = 1;
|
||||
PyThreadState *save = NULL;
|
||||
@@ -29,24 +29,24 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
|
||||
|
||||
seqlen = PySequence_Fast_GET_SIZE(seq);
|
||||
if (seqlen == 0) {
|
||||
Py_DECREF(seq);
|
||||
Ty_DECREF(seq);
|
||||
return STRINGLIB_NEW(NULL, 0);
|
||||
}
|
||||
#if !STRINGLIB_MUTABLE
|
||||
if (seqlen == 1) {
|
||||
item = PySequence_Fast_GET_ITEM(seq, 0);
|
||||
if (STRINGLIB_CHECK_EXACT(item)) {
|
||||
Py_INCREF(item);
|
||||
Py_DECREF(seq);
|
||||
Ty_INCREF(item);
|
||||
Ty_DECREF(seq);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (seqlen > NB_STATIC_BUFFERS) {
|
||||
buffers = PyMem_NEW(Py_buffer, seqlen);
|
||||
buffers = TyMem_NEW(Ty_buffer, seqlen);
|
||||
if (buffers == NULL) {
|
||||
Py_DECREF(seq);
|
||||
PyErr_NoMemory();
|
||||
Ty_DECREF(seq);
|
||||
TyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -59,20 +59,20 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
|
||||
* bytes-like.
|
||||
*/
|
||||
for (i = 0, nbufs = 0; i < seqlen; i++) {
|
||||
Py_ssize_t itemlen;
|
||||
Ty_ssize_t itemlen;
|
||||
item = PySequence_Fast_GET_ITEM(seq, i);
|
||||
if (PyBytes_CheckExact(item)) {
|
||||
if (TyBytes_CheckExact(item)) {
|
||||
/* Fast path. */
|
||||
buffers[i].obj = Py_NewRef(item);
|
||||
buffers[i].buf = PyBytes_AS_STRING(item);
|
||||
buffers[i].len = PyBytes_GET_SIZE(item);
|
||||
buffers[i].obj = Ty_NewRef(item);
|
||||
buffers[i].buf = TyBytes_AS_STRING(item);
|
||||
buffers[i].len = TyBytes_GET_SIZE(item);
|
||||
}
|
||||
else {
|
||||
if (PyObject_GetBuffer(item, &buffers[i], PyBUF_SIMPLE) != 0) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
TyErr_Format(TyExc_TypeError,
|
||||
"sequence item %zd: expected a bytes-like object, "
|
||||
"%.80s found",
|
||||
i, Py_TYPE(item)->tp_name);
|
||||
i, Ty_TYPE(item)->tp_name);
|
||||
goto error;
|
||||
}
|
||||
/* If the backing objects are mutable, then dropping the GIL
|
||||
@@ -86,21 +86,21 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
|
||||
nbufs = i + 1; /* for error cleanup */
|
||||
itemlen = buffers[i].len;
|
||||
if (itemlen > PY_SSIZE_T_MAX - sz) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
TyErr_SetString(TyExc_OverflowError,
|
||||
"join() result is too long");
|
||||
goto error;
|
||||
}
|
||||
sz += itemlen;
|
||||
if (i != 0) {
|
||||
if (seplen > PY_SSIZE_T_MAX - sz) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
TyErr_SetString(TyExc_OverflowError,
|
||||
"join() result is too long");
|
||||
goto error;
|
||||
}
|
||||
sz += seplen;
|
||||
}
|
||||
if (seqlen != PySequence_Fast_GET_SIZE(seq)) {
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
TyErr_SetString(TyExc_RuntimeError,
|
||||
"sequence changed size during iteration");
|
||||
goto error;
|
||||
}
|
||||
@@ -117,12 +117,12 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
|
||||
drop_gil = 0; /* Benefits are likely outweighed by the overheads */
|
||||
}
|
||||
if (drop_gil) {
|
||||
save = PyEval_SaveThread();
|
||||
save = TyEval_SaveThread();
|
||||
}
|
||||
if (!seplen) {
|
||||
/* fast path */
|
||||
for (i = 0; i < nbufs; i++) {
|
||||
Py_ssize_t n = buffers[i].len;
|
||||
Ty_ssize_t n = buffers[i].len;
|
||||
char *q = buffers[i].buf;
|
||||
memcpy(p, q, n);
|
||||
p += n;
|
||||
@@ -130,7 +130,7 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < nbufs; i++) {
|
||||
Py_ssize_t n;
|
||||
Ty_ssize_t n;
|
||||
char *q;
|
||||
if (i) {
|
||||
memcpy(p, sepstr, seplen);
|
||||
@@ -143,18 +143,18 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
|
||||
}
|
||||
}
|
||||
if (drop_gil) {
|
||||
PyEval_RestoreThread(save);
|
||||
TyEval_RestoreThread(save);
|
||||
}
|
||||
goto done;
|
||||
|
||||
error:
|
||||
res = NULL;
|
||||
done:
|
||||
Py_DECREF(seq);
|
||||
Ty_DECREF(seq);
|
||||
for (i = 0; i < nbufs; i++)
|
||||
PyBuffer_Release(&buffers[i]);
|
||||
if (buffers != static_buffers)
|
||||
PyMem_Free(buffers);
|
||||
TyMem_Free(buffers);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/* _PyUnicode_InsertThousandsGrouping() helper functions */
|
||||
/* _TyUnicode_InsertThousandsGrouping() helper functions */
|
||||
|
||||
typedef struct {
|
||||
const char *grouping;
|
||||
char previous;
|
||||
Py_ssize_t i; /* Where we're currently pointing in grouping. */
|
||||
Ty_ssize_t i; /* Where we're currently pointing in grouping. */
|
||||
} GroupGenerator;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ GroupGenerator_init(GroupGenerator *self, const char *grouping)
|
||||
|
||||
|
||||
/* Returns the next grouping, or 0 to signify end. */
|
||||
static Py_ssize_t
|
||||
static Ty_ssize_t
|
||||
GroupGenerator_next(GroupGenerator *self)
|
||||
{
|
||||
/* Note that we don't really do much error checking here. If a
|
||||
@@ -34,7 +34,7 @@ GroupGenerator_next(GroupGenerator *self)
|
||||
char ch = self->grouping[self->i];
|
||||
self->previous = ch;
|
||||
self->i++;
|
||||
return (Py_ssize_t)ch;
|
||||
return (Ty_ssize_t)ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,17 +43,17 @@ GroupGenerator_next(GroupGenerator *self)
|
||||
/* Fill in some digits, leading zeros, and thousands separator. All
|
||||
are optional, depending on when we're called. */
|
||||
static void
|
||||
InsertThousandsGrouping_fill(_PyUnicodeWriter *writer, Py_ssize_t *buffer_pos,
|
||||
PyObject *digits, Py_ssize_t *digits_pos,
|
||||
Py_ssize_t n_chars, Py_ssize_t n_zeros,
|
||||
PyObject *thousands_sep, Py_ssize_t thousands_sep_len,
|
||||
Py_UCS4 *maxchar, int forward)
|
||||
InsertThousandsGrouping_fill(_PyUnicodeWriter *writer, Ty_ssize_t *buffer_pos,
|
||||
TyObject *digits, Ty_ssize_t *digits_pos,
|
||||
Ty_ssize_t n_chars, Ty_ssize_t n_zeros,
|
||||
TyObject *thousands_sep, Ty_ssize_t thousands_sep_len,
|
||||
Ty_UCS4 *maxchar, int forward)
|
||||
{
|
||||
if (!writer) {
|
||||
/* if maxchar > 127, maxchar is already set */
|
||||
if (*maxchar == 127 && thousands_sep) {
|
||||
Py_UCS4 maxchar2 = PyUnicode_MAX_CHAR_VALUE(thousands_sep);
|
||||
*maxchar = Py_MAX(*maxchar, maxchar2);
|
||||
Ty_UCS4 maxchar2 = TyUnicode_MAX_CHAR_VALUE(thousands_sep);
|
||||
*maxchar = Ty_MAX(*maxchar, maxchar2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ InsertThousandsGrouping_fill(_PyUnicodeWriter *writer, Py_ssize_t *buffer_pos,
|
||||
*buffer_pos -= thousands_sep_len;
|
||||
}
|
||||
/* Copy the thousands_sep chars into the buffer. */
|
||||
_PyUnicode_FastCopyCharacters(writer->buffer, *buffer_pos,
|
||||
_TyUnicode_FastCopyCharacters(writer->buffer, *buffer_pos,
|
||||
thousands_sep, 0,
|
||||
thousands_sep_len);
|
||||
if (forward) {
|
||||
@@ -75,7 +75,7 @@ InsertThousandsGrouping_fill(_PyUnicodeWriter *writer, Py_ssize_t *buffer_pos,
|
||||
*buffer_pos -= n_chars;
|
||||
*digits_pos -= n_chars;
|
||||
}
|
||||
_PyUnicode_FastCopyCharacters(writer->buffer, *buffer_pos,
|
||||
_TyUnicode_FastCopyCharacters(writer->buffer, *buffer_pos,
|
||||
digits, *digits_pos,
|
||||
n_chars);
|
||||
if (forward) {
|
||||
@@ -87,8 +87,8 @@ InsertThousandsGrouping_fill(_PyUnicodeWriter *writer, Py_ssize_t *buffer_pos,
|
||||
if (!forward) {
|
||||
*buffer_pos -= n_zeros;
|
||||
}
|
||||
int kind = PyUnicode_KIND(writer->buffer);
|
||||
void *data = PyUnicode_DATA(writer->buffer);
|
||||
int kind = TyUnicode_KIND(writer->buffer);
|
||||
void *data = TyUnicode_DATA(writer->buffer);
|
||||
unicode_fill(kind, data, '0', *buffer_pos, n_zeros);
|
||||
if (forward) {
|
||||
*buffer_pos += n_zeros;
|
||||
|
||||
@@ -9,21 +9,21 @@
|
||||
#endif
|
||||
|
||||
|
||||
Py_LOCAL_INLINE(PyObject*)
|
||||
STRINGLIB(partition)(PyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
PyObject* sep_obj,
|
||||
const STRINGLIB_CHAR* sep, Py_ssize_t sep_len)
|
||||
Ty_LOCAL_INLINE(TyObject*)
|
||||
STRINGLIB(partition)(TyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
TyObject* sep_obj,
|
||||
const STRINGLIB_CHAR* sep, Ty_ssize_t sep_len)
|
||||
{
|
||||
PyObject* out;
|
||||
Py_ssize_t pos;
|
||||
TyObject* out;
|
||||
Ty_ssize_t pos;
|
||||
|
||||
if (sep_len == 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "empty separator");
|
||||
TyErr_SetString(TyExc_ValueError, "empty separator");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out = PyTuple_New(3);
|
||||
out = TyTuple_New(3);
|
||||
if (!out)
|
||||
return NULL;
|
||||
|
||||
@@ -31,56 +31,56 @@ STRINGLIB(partition)(PyObject* str_obj,
|
||||
|
||||
if (pos < 0) {
|
||||
#if STRINGLIB_MUTABLE
|
||||
PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, str_len));
|
||||
PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0));
|
||||
PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(NULL, 0));
|
||||
TyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, str_len));
|
||||
TyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0));
|
||||
TyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(NULL, 0));
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
Py_DECREF(out);
|
||||
if (TyErr_Occurred()) {
|
||||
Ty_DECREF(out);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
Py_INCREF(str_obj);
|
||||
PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj);
|
||||
PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY();
|
||||
Ty_INCREF(str_obj);
|
||||
TyTuple_SET_ITEM(out, 0, (TyObject*) str_obj);
|
||||
TyObject *empty = (TyObject*)STRINGLIB_GET_EMPTY();
|
||||
assert(empty != NULL);
|
||||
Py_INCREF(empty);
|
||||
PyTuple_SET_ITEM(out, 1, empty);
|
||||
Py_INCREF(empty);
|
||||
PyTuple_SET_ITEM(out, 2, empty);
|
||||
Ty_INCREF(empty);
|
||||
TyTuple_SET_ITEM(out, 1, empty);
|
||||
Ty_INCREF(empty);
|
||||
TyTuple_SET_ITEM(out, 2, empty);
|
||||
#endif
|
||||
return out;
|
||||
}
|
||||
|
||||
PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos));
|
||||
Py_INCREF(sep_obj);
|
||||
PyTuple_SET_ITEM(out, 1, sep_obj);
|
||||
TyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos));
|
||||
Ty_INCREF(sep_obj);
|
||||
TyTuple_SET_ITEM(out, 1, sep_obj);
|
||||
pos += sep_len;
|
||||
PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos));
|
||||
TyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos));
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
Py_DECREF(out);
|
||||
if (TyErr_Occurred()) {
|
||||
Ty_DECREF(out);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(PyObject*)
|
||||
STRINGLIB(rpartition)(PyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
PyObject* sep_obj,
|
||||
const STRINGLIB_CHAR* sep, Py_ssize_t sep_len)
|
||||
Ty_LOCAL_INLINE(TyObject*)
|
||||
STRINGLIB(rpartition)(TyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
TyObject* sep_obj,
|
||||
const STRINGLIB_CHAR* sep, Ty_ssize_t sep_len)
|
||||
{
|
||||
PyObject* out;
|
||||
Py_ssize_t pos;
|
||||
TyObject* out;
|
||||
Ty_ssize_t pos;
|
||||
|
||||
if (sep_len == 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "empty separator");
|
||||
TyErr_SetString(TyExc_ValueError, "empty separator");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out = PyTuple_New(3);
|
||||
out = TyTuple_New(3);
|
||||
if (!out)
|
||||
return NULL;
|
||||
|
||||
@@ -88,35 +88,35 @@ STRINGLIB(rpartition)(PyObject* str_obj,
|
||||
|
||||
if (pos < 0) {
|
||||
#if STRINGLIB_MUTABLE
|
||||
PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(NULL, 0));
|
||||
PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0));
|
||||
PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str, str_len));
|
||||
TyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(NULL, 0));
|
||||
TyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0));
|
||||
TyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str, str_len));
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
Py_DECREF(out);
|
||||
if (TyErr_Occurred()) {
|
||||
Ty_DECREF(out);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY();
|
||||
TyObject *empty = (TyObject*)STRINGLIB_GET_EMPTY();
|
||||
assert(empty != NULL);
|
||||
Py_INCREF(empty);
|
||||
PyTuple_SET_ITEM(out, 0, empty);
|
||||
Py_INCREF(empty);
|
||||
PyTuple_SET_ITEM(out, 1, empty);
|
||||
Py_INCREF(str_obj);
|
||||
PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj);
|
||||
Ty_INCREF(empty);
|
||||
TyTuple_SET_ITEM(out, 0, empty);
|
||||
Ty_INCREF(empty);
|
||||
TyTuple_SET_ITEM(out, 1, empty);
|
||||
Ty_INCREF(str_obj);
|
||||
TyTuple_SET_ITEM(out, 2, (TyObject*) str_obj);
|
||||
#endif
|
||||
return out;
|
||||
}
|
||||
|
||||
PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos));
|
||||
Py_INCREF(sep_obj);
|
||||
PyTuple_SET_ITEM(out, 1, sep_obj);
|
||||
TyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos));
|
||||
Ty_INCREF(sep_obj);
|
||||
TyTuple_SET_ITEM(out, 1, sep_obj);
|
||||
pos += sep_len;
|
||||
PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos));
|
||||
TyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos));
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
Py_DECREF(out);
|
||||
if (TyErr_Occurred()) {
|
||||
Ty_DECREF(out);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#error must include "stringlib/fastsearch.h" before including this module
|
||||
#endif
|
||||
|
||||
Py_LOCAL_INLINE(void)
|
||||
Ty_LOCAL_INLINE(void)
|
||||
STRINGLIB(replace_1char_inplace)(STRINGLIB_CHAR* s, STRINGLIB_CHAR* end,
|
||||
Py_UCS4 u1, Py_UCS4 u2, Py_ssize_t maxcount)
|
||||
Ty_UCS4 u1, Ty_UCS4 u2, Ty_ssize_t maxcount)
|
||||
{
|
||||
*s = u2;
|
||||
while (--maxcount && ++s != end) {
|
||||
@@ -35,7 +35,7 @@ STRINGLIB(replace_1char_inplace)(STRINGLIB_CHAR* s, STRINGLIB_CHAR* end,
|
||||
if (s == NULL)
|
||||
return;
|
||||
#else
|
||||
Py_ssize_t i;
|
||||
Ty_ssize_t i;
|
||||
STRINGLIB_CHAR ch1 = (STRINGLIB_CHAR) u1;
|
||||
s++;
|
||||
i = FASTSEARCH(s, end - s, &ch1, 1, 0, FAST_SEARCH);
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
|
||||
|
||||
static void
|
||||
STRINGLIB(repr)(PyObject *unicode, Py_UCS4 quote,
|
||||
STRINGLIB(repr)(TyObject *unicode, Ty_UCS4 quote,
|
||||
STRINGLIB_CHAR *odata)
|
||||
{
|
||||
Py_ssize_t isize = PyUnicode_GET_LENGTH(unicode);
|
||||
const void *idata = PyUnicode_DATA(unicode);
|
||||
int ikind = PyUnicode_KIND(unicode);
|
||||
Ty_ssize_t isize = TyUnicode_GET_LENGTH(unicode);
|
||||
const void *idata = TyUnicode_DATA(unicode);
|
||||
int ikind = TyUnicode_KIND(unicode);
|
||||
|
||||
*odata++ = quote;
|
||||
for (Py_ssize_t i = 0; i < isize; i++) {
|
||||
Py_UCS4 ch = PyUnicode_READ(ikind, idata, i);
|
||||
for (Ty_ssize_t i = 0; i < isize; i++) {
|
||||
Ty_UCS4 ch = TyUnicode_READ(ikind, idata, i);
|
||||
|
||||
/* Escape quotes and backslashes */
|
||||
if ((ch == quote) || (ch == '\\')) {
|
||||
@@ -42,8 +42,8 @@ STRINGLIB(repr)(PyObject *unicode, Py_UCS4 quote,
|
||||
else if (ch < ' ' || ch == 0x7F) {
|
||||
*odata++ = '\\';
|
||||
*odata++ = 'x';
|
||||
*odata++ = Py_hexdigits[(ch >> 4) & 0x000F];
|
||||
*odata++ = Py_hexdigits[ch & 0x000F];
|
||||
*odata++ = Ty_hexdigits[(ch >> 4) & 0x000F];
|
||||
*odata++ = Ty_hexdigits[ch & 0x000F];
|
||||
}
|
||||
|
||||
/* Copy ASCII characters as-is */
|
||||
@@ -56,33 +56,33 @@ STRINGLIB(repr)(PyObject *unicode, Py_UCS4 quote,
|
||||
/* Map Unicode whitespace and control characters
|
||||
(categories Z* and C* except ASCII space)
|
||||
*/
|
||||
if (!Py_UNICODE_ISPRINTABLE(ch)) {
|
||||
if (!Ty_UNICODE_ISPRINTABLE(ch)) {
|
||||
*odata++ = '\\';
|
||||
/* Map 8-bit characters to '\xhh' */
|
||||
if (ch <= 0xff) {
|
||||
*odata++ = 'x';
|
||||
*odata++ = Py_hexdigits[(ch >> 4) & 0x000F];
|
||||
*odata++ = Py_hexdigits[ch & 0x000F];
|
||||
*odata++ = Ty_hexdigits[(ch >> 4) & 0x000F];
|
||||
*odata++ = Ty_hexdigits[ch & 0x000F];
|
||||
}
|
||||
/* Map 16-bit characters to '\uxxxx' */
|
||||
else if (ch <= 0xffff) {
|
||||
*odata++ = 'u';
|
||||
*odata++ = Py_hexdigits[(ch >> 12) & 0xF];
|
||||
*odata++ = Py_hexdigits[(ch >> 8) & 0xF];
|
||||
*odata++ = Py_hexdigits[(ch >> 4) & 0xF];
|
||||
*odata++ = Py_hexdigits[ch & 0xF];
|
||||
*odata++ = Ty_hexdigits[(ch >> 12) & 0xF];
|
||||
*odata++ = Ty_hexdigits[(ch >> 8) & 0xF];
|
||||
*odata++ = Ty_hexdigits[(ch >> 4) & 0xF];
|
||||
*odata++ = Ty_hexdigits[ch & 0xF];
|
||||
}
|
||||
/* Map 21-bit characters to '\U00xxxxxx' */
|
||||
else {
|
||||
*odata++ = 'U';
|
||||
*odata++ = Py_hexdigits[(ch >> 28) & 0xF];
|
||||
*odata++ = Py_hexdigits[(ch >> 24) & 0xF];
|
||||
*odata++ = Py_hexdigits[(ch >> 20) & 0xF];
|
||||
*odata++ = Py_hexdigits[(ch >> 16) & 0xF];
|
||||
*odata++ = Py_hexdigits[(ch >> 12) & 0xF];
|
||||
*odata++ = Py_hexdigits[(ch >> 8) & 0xF];
|
||||
*odata++ = Py_hexdigits[(ch >> 4) & 0xF];
|
||||
*odata++ = Py_hexdigits[ch & 0xF];
|
||||
*odata++ = Ty_hexdigits[(ch >> 28) & 0xF];
|
||||
*odata++ = Ty_hexdigits[(ch >> 24) & 0xF];
|
||||
*odata++ = Ty_hexdigits[(ch >> 20) & 0xF];
|
||||
*odata++ = Ty_hexdigits[(ch >> 16) & 0xF];
|
||||
*odata++ = Ty_hexdigits[(ch >> 12) & 0xF];
|
||||
*odata++ = Ty_hexdigits[(ch >> 8) & 0xF];
|
||||
*odata++ = Ty_hexdigits[(ch >> 4) & 0xF];
|
||||
*odata++ = Ty_hexdigits[ch & 0xF];
|
||||
}
|
||||
}
|
||||
/* Copy characters as-is */
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
(right) - (left)); \
|
||||
if (sub == NULL) \
|
||||
goto onError; \
|
||||
if (PyList_Append(list, sub)) { \
|
||||
Py_DECREF(sub); \
|
||||
if (TyList_Append(list, sub)) { \
|
||||
Ty_DECREF(sub); \
|
||||
goto onError; \
|
||||
} \
|
||||
else \
|
||||
Py_DECREF(sub);
|
||||
Ty_DECREF(sub);
|
||||
|
||||
#define SPLIT_ADD(data, left, right) { \
|
||||
sub = STRINGLIB_NEW((data) + (left), \
|
||||
@@ -35,29 +35,29 @@
|
||||
if (sub == NULL) \
|
||||
goto onError; \
|
||||
if (count < MAX_PREALLOC) { \
|
||||
PyList_SET_ITEM(list, count, sub); \
|
||||
TyList_SET_ITEM(list, count, sub); \
|
||||
} else { \
|
||||
if (PyList_Append(list, sub)) { \
|
||||
Py_DECREF(sub); \
|
||||
if (TyList_Append(list, sub)) { \
|
||||
Ty_DECREF(sub); \
|
||||
goto onError; \
|
||||
} \
|
||||
else \
|
||||
Py_DECREF(sub); \
|
||||
Ty_DECREF(sub); \
|
||||
} \
|
||||
count++; }
|
||||
|
||||
|
||||
/* Always force the list to the expected size. */
|
||||
#define FIX_PREALLOC_SIZE(list) Py_SET_SIZE(list, count)
|
||||
#define FIX_PREALLOC_SIZE(list) Ty_SET_SIZE(list, count)
|
||||
|
||||
Py_LOCAL_INLINE(PyObject *)
|
||||
STRINGLIB(split_whitespace)(PyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
Py_ssize_t maxcount)
|
||||
Ty_LOCAL_INLINE(TyObject *)
|
||||
STRINGLIB(split_whitespace)(TyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
Py_ssize_t i, j, count=0;
|
||||
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
|
||||
PyObject *sub;
|
||||
Ty_ssize_t i, j, count=0;
|
||||
TyObject *list = TyList_New(PREALLOC_SIZE(maxcount));
|
||||
TyObject *sub;
|
||||
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
@@ -73,8 +73,8 @@ STRINGLIB(split_whitespace)(PyObject* str_obj,
|
||||
#if !STRINGLIB_MUTABLE
|
||||
if (j == 0 && i == str_len && STRINGLIB_CHECK_EXACT(str_obj)) {
|
||||
/* No whitespace in str_obj, so just use it as list[0] */
|
||||
Py_INCREF(str_obj);
|
||||
PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
|
||||
Ty_INCREF(str_obj);
|
||||
TyList_SET_ITEM(list, 0, (TyObject *)str_obj);
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
@@ -94,19 +94,19 @@ STRINGLIB(split_whitespace)(PyObject* str_obj,
|
||||
return list;
|
||||
|
||||
onError:
|
||||
Py_DECREF(list);
|
||||
Ty_DECREF(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(PyObject *)
|
||||
STRINGLIB(split_char)(PyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
Ty_LOCAL_INLINE(TyObject *)
|
||||
STRINGLIB(split_char)(TyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
const STRINGLIB_CHAR ch,
|
||||
Py_ssize_t maxcount)
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
Py_ssize_t i, j, count=0;
|
||||
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
|
||||
PyObject *sub;
|
||||
Ty_ssize_t i, j, count=0;
|
||||
TyObject *list = TyList_New(PREALLOC_SIZE(maxcount));
|
||||
TyObject *sub;
|
||||
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
@@ -125,8 +125,8 @@ STRINGLIB(split_char)(PyObject* str_obj,
|
||||
#if !STRINGLIB_MUTABLE
|
||||
if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
|
||||
/* ch not in str_obj, so just use str_obj as list[0] */
|
||||
Py_INCREF(str_obj);
|
||||
PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
|
||||
Ty_INCREF(str_obj);
|
||||
TyList_SET_ITEM(list, 0, (TyObject *)str_obj);
|
||||
count++;
|
||||
} else
|
||||
#endif
|
||||
@@ -137,27 +137,27 @@ STRINGLIB(split_char)(PyObject* str_obj,
|
||||
return list;
|
||||
|
||||
onError:
|
||||
Py_DECREF(list);
|
||||
Ty_DECREF(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(PyObject *)
|
||||
STRINGLIB(split)(PyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sep, Py_ssize_t sep_len,
|
||||
Py_ssize_t maxcount)
|
||||
Ty_LOCAL_INLINE(TyObject *)
|
||||
STRINGLIB(split)(TyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sep, Ty_ssize_t sep_len,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
Py_ssize_t i, j, pos, count=0;
|
||||
PyObject *list, *sub;
|
||||
Ty_ssize_t i, j, pos, count=0;
|
||||
TyObject *list, *sub;
|
||||
|
||||
if (sep_len == 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "empty separator");
|
||||
TyErr_SetString(TyExc_ValueError, "empty separator");
|
||||
return NULL;
|
||||
}
|
||||
else if (sep_len == 1)
|
||||
return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
|
||||
|
||||
list = PyList_New(PREALLOC_SIZE(maxcount));
|
||||
list = TyList_New(PREALLOC_SIZE(maxcount));
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
|
||||
@@ -173,8 +173,8 @@ STRINGLIB(split)(PyObject* str_obj,
|
||||
#if !STRINGLIB_MUTABLE
|
||||
if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
|
||||
/* No match in str_obj, so just use it as list[0] */
|
||||
Py_INCREF(str_obj);
|
||||
PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
|
||||
Ty_INCREF(str_obj);
|
||||
TyList_SET_ITEM(list, 0, (TyObject *)str_obj);
|
||||
count++;
|
||||
} else
|
||||
#endif
|
||||
@@ -185,18 +185,18 @@ STRINGLIB(split)(PyObject* str_obj,
|
||||
return list;
|
||||
|
||||
onError:
|
||||
Py_DECREF(list);
|
||||
Ty_DECREF(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(PyObject *)
|
||||
STRINGLIB(rsplit_whitespace)(PyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
Py_ssize_t maxcount)
|
||||
Ty_LOCAL_INLINE(TyObject *)
|
||||
STRINGLIB(rsplit_whitespace)(TyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
Py_ssize_t i, j, count=0;
|
||||
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
|
||||
PyObject *sub;
|
||||
Ty_ssize_t i, j, count=0;
|
||||
TyObject *list = TyList_New(PREALLOC_SIZE(maxcount));
|
||||
TyObject *sub;
|
||||
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
@@ -212,8 +212,8 @@ STRINGLIB(rsplit_whitespace)(PyObject* str_obj,
|
||||
#if !STRINGLIB_MUTABLE
|
||||
if (j == str_len - 1 && i < 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
|
||||
/* No whitespace in str_obj, so just use it as list[0] */
|
||||
Py_INCREF(str_obj);
|
||||
PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
|
||||
Ty_INCREF(str_obj);
|
||||
TyList_SET_ITEM(list, 0, (TyObject *)str_obj);
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
@@ -230,24 +230,24 @@ STRINGLIB(rsplit_whitespace)(PyObject* str_obj,
|
||||
SPLIT_ADD(str, 0, i + 1);
|
||||
}
|
||||
FIX_PREALLOC_SIZE(list);
|
||||
if (PyList_Reverse(list) < 0)
|
||||
if (TyList_Reverse(list) < 0)
|
||||
goto onError;
|
||||
return list;
|
||||
|
||||
onError:
|
||||
Py_DECREF(list);
|
||||
Ty_DECREF(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(PyObject *)
|
||||
STRINGLIB(rsplit_char)(PyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
Ty_LOCAL_INLINE(TyObject *)
|
||||
STRINGLIB(rsplit_char)(TyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
const STRINGLIB_CHAR ch,
|
||||
Py_ssize_t maxcount)
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
Py_ssize_t i, j, count=0;
|
||||
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
|
||||
PyObject *sub;
|
||||
Ty_ssize_t i, j, count=0;
|
||||
TyObject *list = TyList_New(PREALLOC_SIZE(maxcount));
|
||||
TyObject *sub;
|
||||
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
@@ -265,8 +265,8 @@ STRINGLIB(rsplit_char)(PyObject* str_obj,
|
||||
#if !STRINGLIB_MUTABLE
|
||||
if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
|
||||
/* ch not in str_obj, so just use str_obj as list[0] */
|
||||
Py_INCREF(str_obj);
|
||||
PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
|
||||
Ty_INCREF(str_obj);
|
||||
TyList_SET_ITEM(list, 0, (TyObject *)str_obj);
|
||||
count++;
|
||||
} else
|
||||
#endif
|
||||
@@ -274,32 +274,32 @@ STRINGLIB(rsplit_char)(PyObject* str_obj,
|
||||
SPLIT_ADD(str, 0, j + 1);
|
||||
}
|
||||
FIX_PREALLOC_SIZE(list);
|
||||
if (PyList_Reverse(list) < 0)
|
||||
if (TyList_Reverse(list) < 0)
|
||||
goto onError;
|
||||
return list;
|
||||
|
||||
onError:
|
||||
Py_DECREF(list);
|
||||
Ty_DECREF(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(PyObject *)
|
||||
STRINGLIB(rsplit)(PyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sep, Py_ssize_t sep_len,
|
||||
Py_ssize_t maxcount)
|
||||
Ty_LOCAL_INLINE(TyObject *)
|
||||
STRINGLIB(rsplit)(TyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
const STRINGLIB_CHAR* sep, Ty_ssize_t sep_len,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
Py_ssize_t j, pos, count=0;
|
||||
PyObject *list, *sub;
|
||||
Ty_ssize_t j, pos, count=0;
|
||||
TyObject *list, *sub;
|
||||
|
||||
if (sep_len == 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "empty separator");
|
||||
TyErr_SetString(TyExc_ValueError, "empty separator");
|
||||
return NULL;
|
||||
}
|
||||
else if (sep_len == 1)
|
||||
return STRINGLIB(rsplit_char)(str_obj, str, str_len, sep[0], maxcount);
|
||||
|
||||
list = PyList_New(PREALLOC_SIZE(maxcount));
|
||||
list = TyList_New(PREALLOC_SIZE(maxcount));
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
|
||||
@@ -314,8 +314,8 @@ STRINGLIB(rsplit)(PyObject* str_obj,
|
||||
#if !STRINGLIB_MUTABLE
|
||||
if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
|
||||
/* No match in str_obj, so just use it as list[0] */
|
||||
Py_INCREF(str_obj);
|
||||
PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
|
||||
Ty_INCREF(str_obj);
|
||||
TyList_SET_ITEM(list, 0, (TyObject *)str_obj);
|
||||
count++;
|
||||
} else
|
||||
#endif
|
||||
@@ -323,38 +323,38 @@ STRINGLIB(rsplit)(PyObject* str_obj,
|
||||
SPLIT_ADD(str, 0, j);
|
||||
}
|
||||
FIX_PREALLOC_SIZE(list);
|
||||
if (PyList_Reverse(list) < 0)
|
||||
if (TyList_Reverse(list) < 0)
|
||||
goto onError;
|
||||
return list;
|
||||
|
||||
onError:
|
||||
Py_DECREF(list);
|
||||
Ty_DECREF(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(PyObject *)
|
||||
STRINGLIB(splitlines)(PyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||
Ty_LOCAL_INLINE(TyObject *)
|
||||
STRINGLIB(splitlines)(TyObject* str_obj,
|
||||
const STRINGLIB_CHAR* str, Ty_ssize_t str_len,
|
||||
int keepends)
|
||||
{
|
||||
/* This does not use the preallocated list because splitlines is
|
||||
usually run with hundreds of newlines. The overhead of
|
||||
switching between PyList_SET_ITEM and append causes about a
|
||||
switching between TyList_SET_ITEM and append causes about a
|
||||
2-3% slowdown for that common case. A smarter implementation
|
||||
could move the if check out, so the SET_ITEMs are done first
|
||||
and the appends only done when the prealloc buffer is full.
|
||||
That's too much work for little gain.*/
|
||||
|
||||
Py_ssize_t i;
|
||||
Py_ssize_t j;
|
||||
PyObject *list = PyList_New(0);
|
||||
PyObject *sub;
|
||||
Ty_ssize_t i;
|
||||
Ty_ssize_t j;
|
||||
TyObject *list = TyList_New(0);
|
||||
TyObject *sub;
|
||||
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
|
||||
for (i = j = 0; i < str_len; ) {
|
||||
Py_ssize_t eol;
|
||||
Ty_ssize_t eol;
|
||||
|
||||
/* Find a line and append it */
|
||||
while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
|
||||
@@ -373,7 +373,7 @@ STRINGLIB(splitlines)(PyObject* str_obj,
|
||||
#if !STRINGLIB_MUTABLE
|
||||
if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) {
|
||||
/* No linebreak in str_obj, so just use it as list[0] */
|
||||
if (PyList_Append(list, str_obj))
|
||||
if (TyList_Append(list, str_obj))
|
||||
goto onError;
|
||||
break;
|
||||
}
|
||||
@@ -384,7 +384,7 @@ STRINGLIB(splitlines)(PyObject* str_obj,
|
||||
return list;
|
||||
|
||||
onError:
|
||||
Py_DECREF(list);
|
||||
Ty_DECREF(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,15 +13,15 @@
|
||||
#define STRINGLIB_CHAR char
|
||||
#define STRINGLIB_TYPE_NAME "string"
|
||||
#define STRINGLIB_PARSE_CODE "S"
|
||||
#define STRINGLIB_ISSPACE Py_ISSPACE
|
||||
#define STRINGLIB_ISSPACE Ty_ISSPACE
|
||||
#define STRINGLIB_ISLINEBREAK(x) ((x == '\n') || (x == '\r'))
|
||||
#define STRINGLIB_ISDECIMAL(x) ((x >= '0') && (x <= '9'))
|
||||
#define STRINGLIB_TODECIMAL(x) (STRINGLIB_ISDECIMAL(x) ? (x - '0') : -1)
|
||||
#define STRINGLIB_STR PyBytes_AS_STRING
|
||||
#define STRINGLIB_LEN PyBytes_GET_SIZE
|
||||
#define STRINGLIB_NEW PyBytes_FromStringAndSize
|
||||
#define STRINGLIB_CHECK PyBytes_Check
|
||||
#define STRINGLIB_CHECK_EXACT PyBytes_CheckExact
|
||||
#define STRINGLIB_STR TyBytes_AS_STRING
|
||||
#define STRINGLIB_LEN TyBytes_GET_SIZE
|
||||
#define STRINGLIB_NEW TyBytes_FromStringAndSize
|
||||
#define STRINGLIB_CHECK TyBytes_Check
|
||||
#define STRINGLIB_CHECK_EXACT TyBytes_CheckExact
|
||||
#define STRINGLIB_TOSTR PyObject_Str
|
||||
#define STRINGLIB_TOASCII PyObject_Repr
|
||||
#define STRINGLIB_FAST_MEMCHR memchr
|
||||
|
||||
@@ -6,18 +6,18 @@
|
||||
shared code in bytes_methods.c to cut down on duplicate code bloat. */
|
||||
|
||||
/*[clinic input]
|
||||
class B "PyObject *" "&PyType_Type"
|
||||
class B "TyObject *" "&TyType_Type"
|
||||
[clinic start generated code]*/
|
||||
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=2935558188d97c76]*/
|
||||
|
||||
#include "clinic/transmogrify.h.h"
|
||||
|
||||
static inline PyObject *
|
||||
return_self(PyObject *self)
|
||||
static inline TyObject *
|
||||
return_self(TyObject *self)
|
||||
{
|
||||
#if !STRINGLIB_MUTABLE
|
||||
if (STRINGLIB_CHECK_EXACT(self)) {
|
||||
return Py_NewRef(self);
|
||||
return Ty_NewRef(self);
|
||||
}
|
||||
#endif
|
||||
return STRINGLIB_NEW(STRINGLIB_STR(self), STRINGLIB_LEN(self));
|
||||
@@ -33,14 +33,14 @@ Return a copy where all tab characters are expanded using spaces.
|
||||
If tabsize is not given, a tab size of 8 characters is assumed.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
stringlib_expandtabs_impl(PyObject *self, int tabsize)
|
||||
static TyObject *
|
||||
stringlib_expandtabs_impl(TyObject *self, int tabsize)
|
||||
/*[clinic end generated code: output=069cb7fae72e4c2b input=3c6d3b12aa3ccbea]*/
|
||||
{
|
||||
const char *e, *p;
|
||||
char *q;
|
||||
Py_ssize_t i, j;
|
||||
PyObject *u;
|
||||
Ty_ssize_t i, j;
|
||||
TyObject *u;
|
||||
|
||||
/* First pass: determine size of output string */
|
||||
i = j = 0;
|
||||
@@ -48,7 +48,7 @@ stringlib_expandtabs_impl(PyObject *self, int tabsize)
|
||||
for (p = STRINGLIB_STR(self); p < e; p++) {
|
||||
if (*p == '\t') {
|
||||
if (tabsize > 0) {
|
||||
Py_ssize_t incr = tabsize - (j % tabsize);
|
||||
Ty_ssize_t incr = tabsize - (j % tabsize);
|
||||
if (j > PY_SSIZE_T_MAX - incr)
|
||||
goto overflow;
|
||||
j += incr;
|
||||
@@ -97,14 +97,14 @@ stringlib_expandtabs_impl(PyObject *self, int tabsize)
|
||||
|
||||
return u;
|
||||
overflow:
|
||||
PyErr_SetString(PyExc_OverflowError, "result too long");
|
||||
TyErr_SetString(TyExc_OverflowError, "result too long");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline PyObject *
|
||||
pad(PyObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
|
||||
static inline TyObject *
|
||||
pad(TyObject *self, Ty_ssize_t left, Ty_ssize_t right, char fill)
|
||||
{
|
||||
PyObject *u;
|
||||
TyObject *u;
|
||||
|
||||
if (left < 0)
|
||||
left = 0;
|
||||
@@ -133,7 +133,7 @@ pad(PyObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
|
||||
/*[clinic input]
|
||||
B.ljust as stringlib_ljust
|
||||
|
||||
width: Py_ssize_t
|
||||
width: Ty_ssize_t
|
||||
fillchar: char = b' '
|
||||
/
|
||||
|
||||
@@ -142,8 +142,8 @@ Return a left-justified string of length width.
|
||||
Padding is done using the specified fill character.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar)
|
||||
static TyObject *
|
||||
stringlib_ljust_impl(TyObject *self, Ty_ssize_t width, char fillchar)
|
||||
/*[clinic end generated code: output=c79ca173c5ff8337 input=eff2d014bc7d80df]*/
|
||||
{
|
||||
if (STRINGLIB_LEN(self) >= width) {
|
||||
@@ -157,7 +157,7 @@ stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar)
|
||||
/*[clinic input]
|
||||
B.rjust as stringlib_rjust
|
||||
|
||||
width: Py_ssize_t
|
||||
width: Ty_ssize_t
|
||||
fillchar: char = b' '
|
||||
/
|
||||
|
||||
@@ -166,8 +166,8 @@ Return a right-justified string of length width.
|
||||
Padding is done using the specified fill character.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar)
|
||||
static TyObject *
|
||||
stringlib_rjust_impl(TyObject *self, Ty_ssize_t width, char fillchar)
|
||||
/*[clinic end generated code: output=7df5d728a5439570 input=218b0bd31308955d]*/
|
||||
{
|
||||
if (STRINGLIB_LEN(self) >= width) {
|
||||
@@ -181,7 +181,7 @@ stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar)
|
||||
/*[clinic input]
|
||||
B.center as stringlib_center
|
||||
|
||||
width: Py_ssize_t
|
||||
width: Ty_ssize_t
|
||||
fillchar: char = b' '
|
||||
/
|
||||
|
||||
@@ -190,11 +190,11 @@ Return a centered string of length width.
|
||||
Padding is done using the specified fill character.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar)
|
||||
static TyObject *
|
||||
stringlib_center_impl(TyObject *self, Ty_ssize_t width, char fillchar)
|
||||
/*[clinic end generated code: output=d8da2e055288b4c2 input=3776fd278765d89b]*/
|
||||
{
|
||||
Py_ssize_t marg, left;
|
||||
Ty_ssize_t marg, left;
|
||||
|
||||
if (STRINGLIB_LEN(self) >= width) {
|
||||
return return_self(self);
|
||||
@@ -209,7 +209,7 @@ stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar)
|
||||
/*[clinic input]
|
||||
B.zfill as stringlib_zfill
|
||||
|
||||
width: Py_ssize_t
|
||||
width: Ty_ssize_t
|
||||
/
|
||||
|
||||
Pad a numeric string with zeros on the left, to fill a field of the given width.
|
||||
@@ -217,12 +217,12 @@ Pad a numeric string with zeros on the left, to fill a field of the given width.
|
||||
The original string is never truncated.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
stringlib_zfill_impl(PyObject *self, Py_ssize_t width)
|
||||
static TyObject *
|
||||
stringlib_zfill_impl(TyObject *self, Ty_ssize_t width)
|
||||
/*[clinic end generated code: output=0b3c684a7f1b2319 input=2da6d7b8e9bcb19a]*/
|
||||
{
|
||||
Py_ssize_t fill;
|
||||
PyObject *s;
|
||||
Ty_ssize_t fill;
|
||||
TyObject *s;
|
||||
char *p;
|
||||
|
||||
if (STRINGLIB_LEN(self) >= width) {
|
||||
@@ -253,11 +253,11 @@ stringlib_zfill_impl(PyObject *self, Py_ssize_t width)
|
||||
((char *)memchr((const void *)(target), c, target_len))
|
||||
|
||||
|
||||
static Py_ssize_t
|
||||
countchar(const char *target, Py_ssize_t target_len, char c,
|
||||
Py_ssize_t maxcount)
|
||||
static Ty_ssize_t
|
||||
countchar(const char *target, Ty_ssize_t target_len, char c,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
Py_ssize_t count = 0;
|
||||
Ty_ssize_t count = 0;
|
||||
const char *start = target;
|
||||
const char *end = target + target_len;
|
||||
|
||||
@@ -274,16 +274,16 @@ countchar(const char *target, Py_ssize_t target_len, char c,
|
||||
/* Algorithms for different cases of string replacement */
|
||||
|
||||
/* len(self)>=1, from="", len(to)>=1, maxcount>=1 */
|
||||
static PyObject *
|
||||
stringlib_replace_interleave(PyObject *self,
|
||||
const char *to_s, Py_ssize_t to_len,
|
||||
Py_ssize_t maxcount)
|
||||
static TyObject *
|
||||
stringlib_replace_interleave(TyObject *self,
|
||||
const char *to_s, Ty_ssize_t to_len,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
const char *self_s;
|
||||
char *result_s;
|
||||
Py_ssize_t self_len, result_len;
|
||||
Py_ssize_t count, i;
|
||||
PyObject *result;
|
||||
Ty_ssize_t self_len, result_len;
|
||||
Ty_ssize_t count, i;
|
||||
TyObject *result;
|
||||
|
||||
self_len = STRINGLIB_LEN(self);
|
||||
|
||||
@@ -301,7 +301,7 @@ stringlib_replace_interleave(PyObject *self,
|
||||
/* result_len = count * to_len + self_len; */
|
||||
assert(count > 0);
|
||||
if (to_len > (PY_SSIZE_T_MAX - self_len) / count) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
TyErr_SetString(TyExc_OverflowError,
|
||||
"replace bytes is too long");
|
||||
return NULL;
|
||||
}
|
||||
@@ -345,15 +345,15 @@ stringlib_replace_interleave(PyObject *self,
|
||||
|
||||
/* Special case for deleting a single character */
|
||||
/* len(self)>=1, len(from)==1, to="", maxcount>=1 */
|
||||
static PyObject *
|
||||
stringlib_replace_delete_single_character(PyObject *self,
|
||||
char from_c, Py_ssize_t maxcount)
|
||||
static TyObject *
|
||||
stringlib_replace_delete_single_character(TyObject *self,
|
||||
char from_c, Ty_ssize_t maxcount)
|
||||
{
|
||||
const char *self_s, *start, *next, *end;
|
||||
char *result_s;
|
||||
Py_ssize_t self_len, result_len;
|
||||
Py_ssize_t count;
|
||||
PyObject *result;
|
||||
Ty_ssize_t self_len, result_len;
|
||||
Ty_ssize_t count;
|
||||
TyObject *result;
|
||||
|
||||
self_len = STRINGLIB_LEN(self);
|
||||
self_s = STRINGLIB_STR(self);
|
||||
@@ -389,16 +389,16 @@ stringlib_replace_delete_single_character(PyObject *self,
|
||||
|
||||
/* len(self)>=1, len(from)>=2, to="", maxcount>=1 */
|
||||
|
||||
static PyObject *
|
||||
stringlib_replace_delete_substring(PyObject *self,
|
||||
const char *from_s, Py_ssize_t from_len,
|
||||
Py_ssize_t maxcount)
|
||||
static TyObject *
|
||||
stringlib_replace_delete_substring(TyObject *self,
|
||||
const char *from_s, Ty_ssize_t from_len,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
const char *self_s, *start, *next, *end;
|
||||
char *result_s;
|
||||
Py_ssize_t self_len, result_len;
|
||||
Py_ssize_t count, offset;
|
||||
PyObject *result;
|
||||
Ty_ssize_t self_len, result_len;
|
||||
Ty_ssize_t count, offset;
|
||||
TyObject *result;
|
||||
|
||||
self_len = STRINGLIB_LEN(self);
|
||||
self_s = STRINGLIB_STR(self);
|
||||
@@ -441,15 +441,15 @@ stringlib_replace_delete_substring(PyObject *self,
|
||||
}
|
||||
|
||||
/* len(self)>=1, len(from)==len(to)==1, maxcount>=1 */
|
||||
static PyObject *
|
||||
stringlib_replace_single_character_in_place(PyObject *self,
|
||||
static TyObject *
|
||||
stringlib_replace_single_character_in_place(TyObject *self,
|
||||
char from_c, char to_c,
|
||||
Py_ssize_t maxcount)
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
const char *self_s, *end;
|
||||
char *result_s, *start, *next;
|
||||
Py_ssize_t self_len;
|
||||
PyObject *result;
|
||||
Ty_ssize_t self_len;
|
||||
TyObject *result;
|
||||
|
||||
/* The result string will be the same size */
|
||||
self_s = STRINGLIB_STR(self);
|
||||
@@ -488,16 +488,16 @@ stringlib_replace_single_character_in_place(PyObject *self,
|
||||
}
|
||||
|
||||
/* len(self)>=1, len(from)==len(to)>=2, maxcount>=1 */
|
||||
static PyObject *
|
||||
stringlib_replace_substring_in_place(PyObject *self,
|
||||
const char *from_s, Py_ssize_t from_len,
|
||||
const char *to_s, Py_ssize_t to_len,
|
||||
Py_ssize_t maxcount)
|
||||
static TyObject *
|
||||
stringlib_replace_substring_in_place(TyObject *self,
|
||||
const char *from_s, Ty_ssize_t from_len,
|
||||
const char *to_s, Ty_ssize_t to_len,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
const char *self_s, *end;
|
||||
char *result_s, *start;
|
||||
Py_ssize_t self_len, offset;
|
||||
PyObject *result;
|
||||
Ty_ssize_t self_len, offset;
|
||||
TyObject *result;
|
||||
|
||||
/* The result bytes will be the same size */
|
||||
|
||||
@@ -540,17 +540,17 @@ stringlib_replace_substring_in_place(PyObject *self,
|
||||
}
|
||||
|
||||
/* len(self)>=1, len(from)==1, len(to)>=2, maxcount>=1 */
|
||||
static PyObject *
|
||||
stringlib_replace_single_character(PyObject *self,
|
||||
static TyObject *
|
||||
stringlib_replace_single_character(TyObject *self,
|
||||
char from_c,
|
||||
const char *to_s, Py_ssize_t to_len,
|
||||
Py_ssize_t maxcount)
|
||||
const char *to_s, Ty_ssize_t to_len,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
const char *self_s, *start, *next, *end;
|
||||
char *result_s;
|
||||
Py_ssize_t self_len, result_len;
|
||||
Py_ssize_t count;
|
||||
PyObject *result;
|
||||
Ty_ssize_t self_len, result_len;
|
||||
Ty_ssize_t count;
|
||||
TyObject *result;
|
||||
|
||||
self_s = STRINGLIB_STR(self);
|
||||
self_len = STRINGLIB_LEN(self);
|
||||
@@ -565,7 +565,7 @@ stringlib_replace_single_character(PyObject *self,
|
||||
/* result_len = self_len + count * (to_len-1) */
|
||||
assert(count > 0);
|
||||
if (to_len - 1 > (PY_SSIZE_T_MAX - self_len) / count) {
|
||||
PyErr_SetString(PyExc_OverflowError, "replace bytes is too long");
|
||||
TyErr_SetString(TyExc_OverflowError, "replace bytes is too long");
|
||||
return NULL;
|
||||
}
|
||||
result_len = self_len + count * (to_len - 1);
|
||||
@@ -604,17 +604,17 @@ stringlib_replace_single_character(PyObject *self,
|
||||
}
|
||||
|
||||
/* len(self)>=1, len(from)>=2, len(to)>=2, maxcount>=1 */
|
||||
static PyObject *
|
||||
stringlib_replace_substring(PyObject *self,
|
||||
const char *from_s, Py_ssize_t from_len,
|
||||
const char *to_s, Py_ssize_t to_len,
|
||||
Py_ssize_t maxcount)
|
||||
static TyObject *
|
||||
stringlib_replace_substring(TyObject *self,
|
||||
const char *from_s, Ty_ssize_t from_len,
|
||||
const char *to_s, Ty_ssize_t to_len,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
const char *self_s, *start, *next, *end;
|
||||
char *result_s;
|
||||
Py_ssize_t self_len, result_len;
|
||||
Py_ssize_t count, offset;
|
||||
PyObject *result;
|
||||
Ty_ssize_t self_len, result_len;
|
||||
Ty_ssize_t count, offset;
|
||||
TyObject *result;
|
||||
|
||||
self_s = STRINGLIB_STR(self);
|
||||
self_len = STRINGLIB_LEN(self);
|
||||
@@ -632,7 +632,7 @@ stringlib_replace_substring(PyObject *self,
|
||||
/* result_len = self_len + count * (to_len-from_len) */
|
||||
assert(count > 0);
|
||||
if (to_len - from_len > (PY_SSIZE_T_MAX - self_len) / count) {
|
||||
PyErr_SetString(PyExc_OverflowError, "replace bytes is too long");
|
||||
TyErr_SetString(TyExc_OverflowError, "replace bytes is too long");
|
||||
return NULL;
|
||||
}
|
||||
result_len = self_len + count * (to_len - from_len);
|
||||
@@ -673,11 +673,11 @@ stringlib_replace_substring(PyObject *self,
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
stringlib_replace(PyObject *self,
|
||||
const char *from_s, Py_ssize_t from_len,
|
||||
const char *to_s, Py_ssize_t to_len,
|
||||
Py_ssize_t maxcount)
|
||||
static TyObject *
|
||||
stringlib_replace(TyObject *self,
|
||||
const char *from_s, Ty_ssize_t from_len,
|
||||
const char *to_s, Ty_ssize_t to_len,
|
||||
Ty_ssize_t maxcount)
|
||||
{
|
||||
if (STRINGLIB_LEN(self) < from_len) {
|
||||
/* nothing to do; return the original bytes */
|
||||
|
||||
@@ -8,18 +8,18 @@
|
||||
#define STRINGLIB_OBJECT PyUnicodeObject
|
||||
#define STRINGLIB_SIZEOF_CHAR 1
|
||||
#define STRINGLIB_MAX_CHAR 0xFFu
|
||||
#define STRINGLIB_CHAR Py_UCS1
|
||||
#define STRINGLIB_CHAR Ty_UCS1
|
||||
#define STRINGLIB_TYPE_NAME "unicode"
|
||||
#define STRINGLIB_PARSE_CODE "U"
|
||||
#define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE
|
||||
#define STRINGLIB_ISSPACE Ty_UNICODE_ISSPACE
|
||||
#define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK
|
||||
#define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
|
||||
#define STRINGLIB_TODECIMAL Py_UNICODE_TODECIMAL
|
||||
#define STRINGLIB_STR PyUnicode_1BYTE_DATA
|
||||
#define STRINGLIB_LEN PyUnicode_GET_LENGTH
|
||||
#define STRINGLIB_NEW _PyUnicode_FromUCS1
|
||||
#define STRINGLIB_CHECK PyUnicode_Check
|
||||
#define STRINGLIB_CHECK_EXACT PyUnicode_CheckExact
|
||||
#define STRINGLIB_ISDECIMAL Ty_UNICODE_ISDECIMAL
|
||||
#define STRINGLIB_TODECIMAL Ty_UNICODE_TODECIMAL
|
||||
#define STRINGLIB_STR TyUnicode_1BYTE_DATA
|
||||
#define STRINGLIB_LEN TyUnicode_GET_LENGTH
|
||||
#define STRINGLIB_NEW _TyUnicode_FromUCS1
|
||||
#define STRINGLIB_CHECK TyUnicode_Check
|
||||
#define STRINGLIB_CHECK_EXACT TyUnicode_CheckExact
|
||||
#define STRINGLIB_FAST_MEMCHR memchr
|
||||
#define STRINGLIB_MUTABLE 0
|
||||
|
||||
|
||||
@@ -8,22 +8,22 @@
|
||||
#define STRINGLIB_OBJECT PyUnicodeObject
|
||||
#define STRINGLIB_SIZEOF_CHAR 2
|
||||
#define STRINGLIB_MAX_CHAR 0xFFFFu
|
||||
#define STRINGLIB_CHAR Py_UCS2
|
||||
#define STRINGLIB_CHAR Ty_UCS2
|
||||
#define STRINGLIB_TYPE_NAME "unicode"
|
||||
#define STRINGLIB_PARSE_CODE "U"
|
||||
#define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE
|
||||
#define STRINGLIB_ISSPACE Ty_UNICODE_ISSPACE
|
||||
#define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK
|
||||
#define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
|
||||
#define STRINGLIB_TODECIMAL Py_UNICODE_TODECIMAL
|
||||
#define STRINGLIB_STR PyUnicode_2BYTE_DATA
|
||||
#define STRINGLIB_LEN PyUnicode_GET_LENGTH
|
||||
#define STRINGLIB_NEW _PyUnicode_FromUCS2
|
||||
#define STRINGLIB_CHECK PyUnicode_Check
|
||||
#define STRINGLIB_CHECK_EXACT PyUnicode_CheckExact
|
||||
#define STRINGLIB_ISDECIMAL Ty_UNICODE_ISDECIMAL
|
||||
#define STRINGLIB_TODECIMAL Ty_UNICODE_TODECIMAL
|
||||
#define STRINGLIB_STR TyUnicode_2BYTE_DATA
|
||||
#define STRINGLIB_LEN TyUnicode_GET_LENGTH
|
||||
#define STRINGLIB_NEW _TyUnicode_FromUCS2
|
||||
#define STRINGLIB_CHECK TyUnicode_Check
|
||||
#define STRINGLIB_CHECK_EXACT TyUnicode_CheckExact
|
||||
#define STRINGLIB_MUTABLE 0
|
||||
#if SIZEOF_WCHAR_T == 2
|
||||
#define STRINGLIB_FAST_MEMCHR(s, c, n) \
|
||||
(Py_UCS2 *)wmemchr((const wchar_t *)(s), c, n)
|
||||
(Ty_UCS2 *)wmemchr((const wchar_t *)(s), c, n)
|
||||
#endif
|
||||
|
||||
#define STRINGLIB_TOSTR PyObject_Str
|
||||
|
||||
@@ -8,22 +8,22 @@
|
||||
#define STRINGLIB_OBJECT PyUnicodeObject
|
||||
#define STRINGLIB_SIZEOF_CHAR 4
|
||||
#define STRINGLIB_MAX_CHAR 0x10FFFFu
|
||||
#define STRINGLIB_CHAR Py_UCS4
|
||||
#define STRINGLIB_CHAR Ty_UCS4
|
||||
#define STRINGLIB_TYPE_NAME "unicode"
|
||||
#define STRINGLIB_PARSE_CODE "U"
|
||||
#define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE
|
||||
#define STRINGLIB_ISSPACE Ty_UNICODE_ISSPACE
|
||||
#define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK
|
||||
#define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
|
||||
#define STRINGLIB_TODECIMAL Py_UNICODE_TODECIMAL
|
||||
#define STRINGLIB_STR PyUnicode_4BYTE_DATA
|
||||
#define STRINGLIB_LEN PyUnicode_GET_LENGTH
|
||||
#define STRINGLIB_NEW _PyUnicode_FromUCS4
|
||||
#define STRINGLIB_CHECK PyUnicode_Check
|
||||
#define STRINGLIB_CHECK_EXACT PyUnicode_CheckExact
|
||||
#define STRINGLIB_ISDECIMAL Ty_UNICODE_ISDECIMAL
|
||||
#define STRINGLIB_TODECIMAL Ty_UNICODE_TODECIMAL
|
||||
#define STRINGLIB_STR TyUnicode_4BYTE_DATA
|
||||
#define STRINGLIB_LEN TyUnicode_GET_LENGTH
|
||||
#define STRINGLIB_NEW _TyUnicode_FromUCS4
|
||||
#define STRINGLIB_CHECK TyUnicode_Check
|
||||
#define STRINGLIB_CHECK_EXACT TyUnicode_CheckExact
|
||||
#define STRINGLIB_MUTABLE 0
|
||||
#if SIZEOF_WCHAR_T == 4
|
||||
#define STRINGLIB_FAST_MEMCHR(s, c, n) \
|
||||
(Py_UCS4 *)wmemchr((const wchar_t *)(s), c, n)
|
||||
(Ty_UCS4 *)wmemchr((const wchar_t *)(s), c, n)
|
||||
#endif
|
||||
|
||||
#define STRINGLIB_TOSTR PyObject_Str
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
unicode_format.h -- implementation of str.format().
|
||||
*/
|
||||
|
||||
#include "pycore_complexobject.h" // _PyComplex_FormatAdvancedWriter()
|
||||
#include "pycore_floatobject.h" // _PyFloat_FormatAdvancedWriter()
|
||||
#include "pycore_complexobject.h" // _TyComplex_FormatAdvancedWriter()
|
||||
#include "pycore_floatobject.h" // _TyFloat_FormatAdvancedWriter()
|
||||
|
||||
/************************************************************************/
|
||||
/*********** Global data structures and forward declarations *********/
|
||||
@@ -14,8 +14,8 @@
|
||||
unicode pointers.
|
||||
*/
|
||||
typedef struct {
|
||||
PyObject *str; /* borrowed reference */
|
||||
Py_ssize_t start, end;
|
||||
TyObject *str; /* borrowed reference */
|
||||
Ty_ssize_t start, end;
|
||||
} SubString;
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ typedef struct {
|
||||
|
||||
|
||||
/* forward declaration for recursion */
|
||||
static PyObject *
|
||||
build_string(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
static TyObject *
|
||||
build_string(SubString *input, TyObject *args, TyObject *kwargs,
|
||||
int recursion_depth, AutoNumber *auto_number);
|
||||
|
||||
|
||||
@@ -51,8 +51,8 @@ AutoNumber_Init(AutoNumber *auto_number)
|
||||
}
|
||||
|
||||
/* fill in a SubString from a pointer and length */
|
||||
Py_LOCAL_INLINE(void)
|
||||
SubString_init(SubString *str, PyObject *s, Py_ssize_t start, Py_ssize_t end)
|
||||
Ty_LOCAL_INLINE(void)
|
||||
SubString_init(SubString *str, TyObject *s, Ty_ssize_t start, Ty_ssize_t end)
|
||||
{
|
||||
str->str = s;
|
||||
str->start = start;
|
||||
@@ -60,20 +60,20 @@ SubString_init(SubString *str, PyObject *s, Py_ssize_t start, Py_ssize_t end)
|
||||
}
|
||||
|
||||
/* return a new string. if str->str is NULL, return None */
|
||||
Py_LOCAL_INLINE(PyObject *)
|
||||
Ty_LOCAL_INLINE(TyObject *)
|
||||
SubString_new_object(SubString *str)
|
||||
{
|
||||
if (str->str == NULL)
|
||||
Py_RETURN_NONE;
|
||||
return PyUnicode_Substring(str->str, str->start, str->end);
|
||||
Ty_RETURN_NONE;
|
||||
return TyUnicode_Substring(str->str, str->start, str->end);
|
||||
}
|
||||
|
||||
/* return a new string. if str->str is NULL, return a new empty string */
|
||||
Py_LOCAL_INLINE(PyObject *)
|
||||
Ty_LOCAL_INLINE(TyObject *)
|
||||
SubString_new_object_or_empty(SubString *str)
|
||||
{
|
||||
if (str->str == NULL) {
|
||||
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
return Ty_GetConstant(Ty_CONSTANT_EMPTY_STR);
|
||||
}
|
||||
return SubString_new_object(str);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ autonumber_state_error(AutoNumberState state, int field_name_is_empty)
|
||||
{
|
||||
if (state == ANS_MANUAL) {
|
||||
if (field_name_is_empty) {
|
||||
PyErr_SetString(PyExc_ValueError, "cannot switch from "
|
||||
TyErr_SetString(TyExc_ValueError, "cannot switch from "
|
||||
"manual field specification to "
|
||||
"automatic field numbering");
|
||||
return 1;
|
||||
@@ -94,7 +94,7 @@ autonumber_state_error(AutoNumberState state, int field_name_is_empty)
|
||||
}
|
||||
else {
|
||||
if (!field_name_is_empty) {
|
||||
PyErr_SetString(PyExc_ValueError, "cannot switch from "
|
||||
TyErr_SetString(TyExc_ValueError, "cannot switch from "
|
||||
"automatic field numbering to "
|
||||
"manual field specification");
|
||||
return 1;
|
||||
@@ -108,19 +108,19 @@ autonumber_state_error(AutoNumberState state, int field_name_is_empty)
|
||||
/*********** Format string parsing -- integers and identifiers *********/
|
||||
/************************************************************************/
|
||||
|
||||
static Py_ssize_t
|
||||
static Ty_ssize_t
|
||||
get_integer(const SubString *str)
|
||||
{
|
||||
Py_ssize_t accumulator = 0;
|
||||
Py_ssize_t digitval;
|
||||
Py_ssize_t i;
|
||||
Ty_ssize_t accumulator = 0;
|
||||
Ty_ssize_t digitval;
|
||||
Ty_ssize_t i;
|
||||
|
||||
/* empty string is an error */
|
||||
if (str->start >= str->end)
|
||||
return -1;
|
||||
|
||||
for (i = str->start; i < str->end; i++) {
|
||||
digitval = Py_UNICODE_TODECIMAL(PyUnicode_READ_CHAR(str->str, i));
|
||||
digitval = Ty_UNICODE_TODECIMAL(TyUnicode_READ_CHAR(str->str, i));
|
||||
if (digitval < 0)
|
||||
return -1;
|
||||
/*
|
||||
@@ -130,7 +130,7 @@ get_integer(const SubString *str)
|
||||
accumulator > (PY_SSIZE_T_MAX - digitval) / 10.
|
||||
*/
|
||||
if (accumulator > (PY_SSIZE_T_MAX - digitval) / 10) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
TyErr_Format(TyExc_ValueError,
|
||||
"Too many decimal digits in format string");
|
||||
return -1;
|
||||
}
|
||||
@@ -144,48 +144,48 @@ get_integer(const SubString *str)
|
||||
/************************************************************************/
|
||||
|
||||
/* do the equivalent of obj.name */
|
||||
static PyObject *
|
||||
getattr(PyObject *obj, SubString *name)
|
||||
static TyObject *
|
||||
getattr(TyObject *obj, SubString *name)
|
||||
{
|
||||
PyObject *newobj;
|
||||
PyObject *str = SubString_new_object(name);
|
||||
TyObject *newobj;
|
||||
TyObject *str = SubString_new_object(name);
|
||||
if (str == NULL)
|
||||
return NULL;
|
||||
newobj = PyObject_GetAttr(obj, str);
|
||||
Py_DECREF(str);
|
||||
Ty_DECREF(str);
|
||||
return newobj;
|
||||
}
|
||||
|
||||
/* do the equivalent of obj[idx], where obj is a sequence */
|
||||
static PyObject *
|
||||
getitem_sequence(PyObject *obj, Py_ssize_t idx)
|
||||
static TyObject *
|
||||
getitem_sequence(TyObject *obj, Ty_ssize_t idx)
|
||||
{
|
||||
return PySequence_GetItem(obj, idx);
|
||||
}
|
||||
|
||||
/* do the equivalent of obj[idx], where obj is not a sequence */
|
||||
static PyObject *
|
||||
getitem_idx(PyObject *obj, Py_ssize_t idx)
|
||||
static TyObject *
|
||||
getitem_idx(TyObject *obj, Ty_ssize_t idx)
|
||||
{
|
||||
PyObject *newobj;
|
||||
PyObject *idx_obj = PyLong_FromSsize_t(idx);
|
||||
TyObject *newobj;
|
||||
TyObject *idx_obj = TyLong_FromSsize_t(idx);
|
||||
if (idx_obj == NULL)
|
||||
return NULL;
|
||||
newobj = PyObject_GetItem(obj, idx_obj);
|
||||
Py_DECREF(idx_obj);
|
||||
Ty_DECREF(idx_obj);
|
||||
return newobj;
|
||||
}
|
||||
|
||||
/* do the equivalent of obj[name] */
|
||||
static PyObject *
|
||||
getitem_str(PyObject *obj, SubString *name)
|
||||
static TyObject *
|
||||
getitem_str(TyObject *obj, SubString *name)
|
||||
{
|
||||
PyObject *newobj;
|
||||
PyObject *str = SubString_new_object(name);
|
||||
TyObject *newobj;
|
||||
TyObject *str = SubString_new_object(name);
|
||||
if (str == NULL)
|
||||
return NULL;
|
||||
newobj = PyObject_GetItem(obj, str);
|
||||
Py_DECREF(str);
|
||||
Ty_DECREF(str);
|
||||
return newobj;
|
||||
}
|
||||
|
||||
@@ -196,13 +196,13 @@ typedef struct {
|
||||
SubString str;
|
||||
|
||||
/* index to where we are inside field_name */
|
||||
Py_ssize_t index;
|
||||
Ty_ssize_t index;
|
||||
} FieldNameIterator;
|
||||
|
||||
|
||||
static int
|
||||
FieldNameIterator_init(FieldNameIterator *self, PyObject *s,
|
||||
Py_ssize_t start, Py_ssize_t end)
|
||||
FieldNameIterator_init(FieldNameIterator *self, TyObject *s,
|
||||
Ty_ssize_t start, Ty_ssize_t end)
|
||||
{
|
||||
SubString_init(&self->str, s, start, end);
|
||||
self->index = start;
|
||||
@@ -212,14 +212,14 @@ FieldNameIterator_init(FieldNameIterator *self, PyObject *s,
|
||||
static int
|
||||
_FieldNameIterator_attr(FieldNameIterator *self, SubString *name)
|
||||
{
|
||||
Py_UCS4 c;
|
||||
Ty_UCS4 c;
|
||||
|
||||
name->str = self->str.str;
|
||||
name->start = self->index;
|
||||
|
||||
/* return everything until '.' or '[' */
|
||||
while (self->index < self->str.end) {
|
||||
c = PyUnicode_READ_CHAR(self->str.str, self->index++);
|
||||
c = TyUnicode_READ_CHAR(self->str.str, self->index++);
|
||||
switch (c) {
|
||||
case '[':
|
||||
case '.':
|
||||
@@ -240,14 +240,14 @@ static int
|
||||
_FieldNameIterator_item(FieldNameIterator *self, SubString *name)
|
||||
{
|
||||
int bracket_seen = 0;
|
||||
Py_UCS4 c;
|
||||
Ty_UCS4 c;
|
||||
|
||||
name->str = self->str.str;
|
||||
name->start = self->index;
|
||||
|
||||
/* return everything until ']' */
|
||||
while (self->index < self->str.end) {
|
||||
c = PyUnicode_READ_CHAR(self->str.str, self->index++);
|
||||
c = TyUnicode_READ_CHAR(self->str.str, self->index++);
|
||||
switch (c) {
|
||||
case ']':
|
||||
bracket_seen = 1;
|
||||
@@ -259,7 +259,7 @@ _FieldNameIterator_item(FieldNameIterator *self, SubString *name)
|
||||
}
|
||||
/* make sure we ended with a ']' */
|
||||
if (!bracket_seen) {
|
||||
PyErr_SetString(PyExc_ValueError, "Missing ']' in format string");
|
||||
TyErr_SetString(TyExc_ValueError, "Missing ']' in format string");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -272,13 +272,13 @@ _FieldNameIterator_item(FieldNameIterator *self, SubString *name)
|
||||
/* returns 0 on error, 1 on non-error termination, and 2 if it returns a value */
|
||||
static int
|
||||
FieldNameIterator_next(FieldNameIterator *self, int *is_attribute,
|
||||
Py_ssize_t *name_idx, SubString *name)
|
||||
Ty_ssize_t *name_idx, SubString *name)
|
||||
{
|
||||
/* check at end of input */
|
||||
if (self->index >= self->str.end)
|
||||
return 1;
|
||||
|
||||
switch (PyUnicode_READ_CHAR(self->str.str, self->index++)) {
|
||||
switch (TyUnicode_READ_CHAR(self->str.str, self->index++)) {
|
||||
case '.':
|
||||
*is_attribute = 1;
|
||||
if (_FieldNameIterator_attr(self, name) == 0)
|
||||
@@ -290,19 +290,19 @@ FieldNameIterator_next(FieldNameIterator *self, int *is_attribute,
|
||||
if (_FieldNameIterator_item(self, name) == 0)
|
||||
return 0;
|
||||
*name_idx = get_integer(name);
|
||||
if (*name_idx == -1 && PyErr_Occurred())
|
||||
if (*name_idx == -1 && TyErr_Occurred())
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
/* Invalid character follows ']' */
|
||||
PyErr_SetString(PyExc_ValueError, "Only '.' or '[' may "
|
||||
TyErr_SetString(TyExc_ValueError, "Only '.' or '[' may "
|
||||
"follow ']' in format field specifier");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* empty string is an error */
|
||||
if (name->start == name->end) {
|
||||
PyErr_SetString(PyExc_ValueError, "Empty attribute in format string");
|
||||
TyErr_SetString(TyExc_ValueError, "Empty attribute in format string");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -317,18 +317,18 @@ FieldNameIterator_next(FieldNameIterator *self, int *is_attribute,
|
||||
'rest' is an iterator to return the rest
|
||||
*/
|
||||
static int
|
||||
field_name_split(PyObject *str, Py_ssize_t start, Py_ssize_t end, SubString *first,
|
||||
Py_ssize_t *first_idx, FieldNameIterator *rest,
|
||||
field_name_split(TyObject *str, Ty_ssize_t start, Ty_ssize_t end, SubString *first,
|
||||
Ty_ssize_t *first_idx, FieldNameIterator *rest,
|
||||
AutoNumber *auto_number)
|
||||
{
|
||||
Py_UCS4 c;
|
||||
Py_ssize_t i = start;
|
||||
Ty_UCS4 c;
|
||||
Ty_ssize_t i = start;
|
||||
int field_name_is_empty;
|
||||
int using_numeric_index;
|
||||
|
||||
/* find the part up until the first '.' or '[' */
|
||||
while (i < end) {
|
||||
switch (c = PyUnicode_READ_CHAR(str, i++)) {
|
||||
switch (c = TyUnicode_READ_CHAR(str, i++)) {
|
||||
case '[':
|
||||
case '.':
|
||||
/* backup so that we this character is available to the
|
||||
@@ -347,7 +347,7 @@ field_name_split(PyObject *str, Py_ssize_t start, Py_ssize_t end, SubString *fir
|
||||
|
||||
/* see if "first" is an integer, in which case it's used as an index */
|
||||
*first_idx = get_integer(first);
|
||||
if (*first_idx == -1 && PyErr_Occurred())
|
||||
if (*first_idx == -1 && TyErr_Occurred())
|
||||
return 0;
|
||||
|
||||
field_name_is_empty = first->start >= first->end;
|
||||
@@ -393,16 +393,16 @@ field_name_split(PyObject *str, Py_ssize_t start, Py_ssize_t end, SubString *fir
|
||||
format_spec. It handles getindex and getattr lookups and consumes
|
||||
the entire input string.
|
||||
*/
|
||||
static PyObject *
|
||||
get_field_object(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
static TyObject *
|
||||
get_field_object(SubString *input, TyObject *args, TyObject *kwargs,
|
||||
AutoNumber *auto_number)
|
||||
{
|
||||
PyObject *obj = NULL;
|
||||
TyObject *obj = NULL;
|
||||
int ok;
|
||||
int is_attribute;
|
||||
SubString name;
|
||||
SubString first;
|
||||
Py_ssize_t index;
|
||||
Ty_ssize_t index;
|
||||
FieldNameIterator rest;
|
||||
|
||||
if (!field_name_split(input->str, input->start, input->end, &first,
|
||||
@@ -412,20 +412,20 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
|
||||
if (index == -1) {
|
||||
/* look up in kwargs */
|
||||
PyObject *key = SubString_new_object(&first);
|
||||
TyObject *key = SubString_new_object(&first);
|
||||
if (key == NULL) {
|
||||
goto error;
|
||||
}
|
||||
if (kwargs == NULL) {
|
||||
PyErr_SetObject(PyExc_KeyError, key);
|
||||
Py_DECREF(key);
|
||||
TyErr_SetObject(TyExc_KeyError, key);
|
||||
Ty_DECREF(key);
|
||||
goto error;
|
||||
}
|
||||
/* Use PyObject_GetItem instead of PyDict_GetItem because this
|
||||
/* Use PyObject_GetItem instead of TyDict_GetItem because this
|
||||
code is no longer just used with kwargs. It might be passed
|
||||
a non-dict when called through format_map. */
|
||||
obj = PyObject_GetItem(kwargs, key);
|
||||
Py_DECREF(key);
|
||||
Ty_DECREF(key);
|
||||
if (obj == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@@ -436,7 +436,7 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
used with format_map(), where positional arguments are not
|
||||
allowed. */
|
||||
if (args == NULL) {
|
||||
PyErr_SetString(PyExc_ValueError, "Format string contains "
|
||||
TyErr_SetString(TyExc_ValueError, "Format string contains "
|
||||
"positional fields");
|
||||
goto error;
|
||||
}
|
||||
@@ -444,7 +444,7 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
/* look up in args */
|
||||
obj = PySequence_GetItem(args, index);
|
||||
if (obj == NULL) {
|
||||
PyErr_Format(PyExc_IndexError,
|
||||
TyErr_Format(TyExc_IndexError,
|
||||
"Replacement index %zd out of range for positional "
|
||||
"args tuple",
|
||||
index);
|
||||
@@ -455,7 +455,7 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
/* iterate over the rest of the field_name */
|
||||
while ((ok = FieldNameIterator_next(&rest, &is_attribute, &index,
|
||||
&name)) == 2) {
|
||||
PyObject *tmp;
|
||||
TyObject *tmp;
|
||||
|
||||
if (is_attribute)
|
||||
/* getattr lookup "." */
|
||||
@@ -474,13 +474,13 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
goto error;
|
||||
|
||||
/* assign to obj */
|
||||
Py_SETREF(obj, tmp);
|
||||
Ty_SETREF(obj, tmp);
|
||||
}
|
||||
/* end of iterator, this is the non-error case */
|
||||
if (ok == 1)
|
||||
return obj;
|
||||
error:
|
||||
Py_XDECREF(obj);
|
||||
Ty_XDECREF(obj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -497,24 +497,24 @@ error:
|
||||
appends to the output.
|
||||
*/
|
||||
static int
|
||||
render_field(PyObject *fieldobj, SubString *format_spec, _PyUnicodeWriter *writer)
|
||||
render_field(TyObject *fieldobj, SubString *format_spec, _PyUnicodeWriter *writer)
|
||||
{
|
||||
int ok = 0;
|
||||
PyObject *result = NULL;
|
||||
PyObject *format_spec_object = NULL;
|
||||
int (*formatter) (_PyUnicodeWriter*, PyObject *, PyObject *, Py_ssize_t, Py_ssize_t) = NULL;
|
||||
TyObject *result = NULL;
|
||||
TyObject *format_spec_object = NULL;
|
||||
int (*formatter) (_PyUnicodeWriter*, TyObject *, TyObject *, Ty_ssize_t, Ty_ssize_t) = NULL;
|
||||
int err;
|
||||
|
||||
/* If we know the type exactly, skip the lookup of __format__ and just
|
||||
call the formatter directly. */
|
||||
if (PyUnicode_CheckExact(fieldobj))
|
||||
formatter = _PyUnicode_FormatAdvancedWriter;
|
||||
else if (PyLong_CheckExact(fieldobj))
|
||||
formatter = _PyLong_FormatAdvancedWriter;
|
||||
else if (PyFloat_CheckExact(fieldobj))
|
||||
formatter = _PyFloat_FormatAdvancedWriter;
|
||||
else if (PyComplex_CheckExact(fieldobj))
|
||||
formatter = _PyComplex_FormatAdvancedWriter;
|
||||
if (TyUnicode_CheckExact(fieldobj))
|
||||
formatter = _TyUnicode_FormatAdvancedWriter;
|
||||
else if (TyLong_CheckExact(fieldobj))
|
||||
formatter = _TyLong_FormatAdvancedWriter;
|
||||
else if (TyFloat_CheckExact(fieldobj))
|
||||
formatter = _TyFloat_FormatAdvancedWriter;
|
||||
else if (TyComplex_CheckExact(fieldobj))
|
||||
formatter = _TyComplex_FormatAdvancedWriter;
|
||||
|
||||
if (formatter) {
|
||||
/* we know exactly which formatter will be called when __format__ is
|
||||
@@ -527,11 +527,11 @@ render_field(PyObject *fieldobj, SubString *format_spec, _PyUnicodeWriter *write
|
||||
/* We need to create an object out of the pointers we have, because
|
||||
__format__ takes a string/unicode object for format_spec. */
|
||||
if (format_spec->str)
|
||||
format_spec_object = PyUnicode_Substring(format_spec->str,
|
||||
format_spec_object = TyUnicode_Substring(format_spec->str,
|
||||
format_spec->start,
|
||||
format_spec->end);
|
||||
else
|
||||
format_spec_object = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
format_spec_object = Ty_GetConstant(Ty_CONSTANT_EMPTY_STR);
|
||||
if (format_spec_object == NULL)
|
||||
goto done;
|
||||
|
||||
@@ -545,20 +545,20 @@ render_field(PyObject *fieldobj, SubString *format_spec, _PyUnicodeWriter *write
|
||||
ok = 1;
|
||||
|
||||
done:
|
||||
Py_XDECREF(format_spec_object);
|
||||
Py_XDECREF(result);
|
||||
Ty_XDECREF(format_spec_object);
|
||||
Ty_XDECREF(result);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_field(SubString *str, SubString *field_name, SubString *format_spec,
|
||||
int *format_spec_needs_expanding, Py_UCS4 *conversion)
|
||||
int *format_spec_needs_expanding, Ty_UCS4 *conversion)
|
||||
{
|
||||
/* Note this function works if the field name is zero length,
|
||||
which is good. Zero length field names are handled later, in
|
||||
field_name_split. */
|
||||
|
||||
Py_UCS4 c = 0;
|
||||
Ty_UCS4 c = 0;
|
||||
|
||||
/* initialize these, as they may be empty */
|
||||
*conversion = '\0';
|
||||
@@ -569,13 +569,13 @@ parse_field(SubString *str, SubString *field_name, SubString *format_spec,
|
||||
field_name->str = str->str;
|
||||
field_name->start = str->start;
|
||||
while (str->start < str->end) {
|
||||
switch ((c = PyUnicode_READ_CHAR(str->str, str->start++))) {
|
||||
switch ((c = TyUnicode_READ_CHAR(str->str, str->start++))) {
|
||||
case '{':
|
||||
PyErr_SetString(PyExc_ValueError, "unexpected '{' in field name");
|
||||
TyErr_SetString(TyExc_ValueError, "unexpected '{' in field name");
|
||||
return 0;
|
||||
case '[':
|
||||
for (; str->start < str->end; str->start++)
|
||||
if (PyUnicode_READ_CHAR(str->str, str->start) == ']')
|
||||
if (TyUnicode_READ_CHAR(str->str, str->start) == ']')
|
||||
break;
|
||||
continue;
|
||||
case '}':
|
||||
@@ -590,7 +590,7 @@ parse_field(SubString *str, SubString *field_name, SubString *format_spec,
|
||||
|
||||
field_name->end = str->start - 1;
|
||||
if (c == '!' || c == ':') {
|
||||
Py_ssize_t count;
|
||||
Ty_ssize_t count;
|
||||
/* we have a format specifier and/or a conversion */
|
||||
/* don't include the last character */
|
||||
|
||||
@@ -598,19 +598,19 @@ parse_field(SubString *str, SubString *field_name, SubString *format_spec,
|
||||
if (c == '!') {
|
||||
/* there must be another character present */
|
||||
if (str->start >= str->end) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
TyErr_SetString(TyExc_ValueError,
|
||||
"end of string while looking for conversion "
|
||||
"specifier");
|
||||
return 0;
|
||||
}
|
||||
*conversion = PyUnicode_READ_CHAR(str->str, str->start++);
|
||||
*conversion = TyUnicode_READ_CHAR(str->str, str->start++);
|
||||
|
||||
if (str->start < str->end) {
|
||||
c = PyUnicode_READ_CHAR(str->str, str->start++);
|
||||
c = TyUnicode_READ_CHAR(str->str, str->start++);
|
||||
if (c == '}')
|
||||
return 1;
|
||||
if (c != ':') {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
TyErr_SetString(TyExc_ValueError,
|
||||
"expected ':' after conversion specifier");
|
||||
return 0;
|
||||
}
|
||||
@@ -620,7 +620,7 @@ parse_field(SubString *str, SubString *field_name, SubString *format_spec,
|
||||
format_spec->start = str->start;
|
||||
count = 1;
|
||||
while (str->start < str->end) {
|
||||
switch ((c = PyUnicode_READ_CHAR(str->str, str->start++))) {
|
||||
switch ((c = TyUnicode_READ_CHAR(str->str, str->start++))) {
|
||||
case '{':
|
||||
*format_spec_needs_expanding = 1;
|
||||
count++;
|
||||
@@ -637,11 +637,11 @@ parse_field(SubString *str, SubString *field_name, SubString *format_spec,
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_ValueError, "unmatched '{' in format spec");
|
||||
TyErr_SetString(TyExc_ValueError, "unmatched '{' in format spec");
|
||||
return 0;
|
||||
}
|
||||
else if (c != '}') {
|
||||
PyErr_SetString(PyExc_ValueError, "expected '}' before end of string");
|
||||
TyErr_SetString(TyExc_ValueError, "expected '}' before end of string");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -662,8 +662,8 @@ typedef struct {
|
||||
} MarkupIterator;
|
||||
|
||||
static int
|
||||
MarkupIterator_init(MarkupIterator *self, PyObject *str,
|
||||
Py_ssize_t start, Py_ssize_t end)
|
||||
MarkupIterator_init(MarkupIterator *self, TyObject *str,
|
||||
Ty_ssize_t start, Ty_ssize_t end)
|
||||
{
|
||||
SubString_init(&self->str, str, start, end);
|
||||
return 1;
|
||||
@@ -674,13 +674,13 @@ MarkupIterator_init(MarkupIterator *self, PyObject *str,
|
||||
static int
|
||||
MarkupIterator_next(MarkupIterator *self, SubString *literal,
|
||||
int *field_present, SubString *field_name,
|
||||
SubString *format_spec, Py_UCS4 *conversion,
|
||||
SubString *format_spec, Ty_UCS4 *conversion,
|
||||
int *format_spec_needs_expanding)
|
||||
{
|
||||
int at_end;
|
||||
Py_UCS4 c = 0;
|
||||
Py_ssize_t start;
|
||||
Py_ssize_t len;
|
||||
Ty_UCS4 c = 0;
|
||||
Ty_ssize_t start;
|
||||
Ty_ssize_t len;
|
||||
int markup_follows = 0;
|
||||
|
||||
/* initialize all of the output variables */
|
||||
@@ -706,7 +706,7 @@ MarkupIterator_next(MarkupIterator *self, SubString *literal,
|
||||
through, we'll return the rest of the literal, skipping past
|
||||
the second consecutive brace. */
|
||||
while (self->str.start < self->str.end) {
|
||||
switch (c = PyUnicode_READ_CHAR(self->str.str, self->str.start++)) {
|
||||
switch (c = TyUnicode_READ_CHAR(self->str.str, self->str.start++)) {
|
||||
case '{':
|
||||
case '}':
|
||||
markup_follows = 1;
|
||||
@@ -721,19 +721,19 @@ MarkupIterator_next(MarkupIterator *self, SubString *literal,
|
||||
len = self->str.start - start;
|
||||
|
||||
if ((c == '}') && (at_end ||
|
||||
(c != PyUnicode_READ_CHAR(self->str.str,
|
||||
(c != TyUnicode_READ_CHAR(self->str.str,
|
||||
self->str.start)))) {
|
||||
PyErr_SetString(PyExc_ValueError, "Single '}' encountered "
|
||||
TyErr_SetString(TyExc_ValueError, "Single '}' encountered "
|
||||
"in format string");
|
||||
return 0;
|
||||
}
|
||||
if (at_end && c == '{') {
|
||||
PyErr_SetString(PyExc_ValueError, "Single '{' encountered "
|
||||
TyErr_SetString(TyExc_ValueError, "Single '{' encountered "
|
||||
"in format string");
|
||||
return 0;
|
||||
}
|
||||
if (!at_end) {
|
||||
if (c == PyUnicode_READ_CHAR(self->str.str, self->str.start)) {
|
||||
if (c == TyUnicode_READ_CHAR(self->str.str, self->str.start)) {
|
||||
/* escaped } or {, skip it in the input. there is no
|
||||
markup object following us, just this literal text */
|
||||
self->str.start++;
|
||||
@@ -761,8 +761,8 @@ MarkupIterator_next(MarkupIterator *self, SubString *literal,
|
||||
|
||||
|
||||
/* do the !r or !s conversion on obj */
|
||||
static PyObject *
|
||||
do_conversion(PyObject *obj, Py_UCS4 conversion)
|
||||
static TyObject *
|
||||
do_conversion(TyObject *obj, Ty_UCS4 conversion)
|
||||
{
|
||||
/* XXX in pre-3.0, do we need to convert this to unicode, since it
|
||||
might have returned a string? */
|
||||
@@ -778,11 +778,11 @@ do_conversion(PyObject *obj, Py_UCS4 conversion)
|
||||
/* It's the ASCII subrange; casting to char is safe
|
||||
(assuming the execution character set is an ASCII
|
||||
superset). */
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
TyErr_Format(TyExc_ValueError,
|
||||
"Unknown conversion specifier %c",
|
||||
(char)conversion);
|
||||
} else
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
TyErr_Format(TyExc_ValueError,
|
||||
"Unknown conversion specifier \\x%x",
|
||||
(unsigned int)conversion);
|
||||
return NULL;
|
||||
@@ -804,12 +804,12 @@ do_conversion(PyObject *obj, Py_UCS4 conversion)
|
||||
|
||||
static int
|
||||
output_markup(SubString *field_name, SubString *format_spec,
|
||||
int format_spec_needs_expanding, Py_UCS4 conversion,
|
||||
_PyUnicodeWriter *writer, PyObject *args, PyObject *kwargs,
|
||||
int format_spec_needs_expanding, Ty_UCS4 conversion,
|
||||
_PyUnicodeWriter *writer, TyObject *args, TyObject *kwargs,
|
||||
int recursion_depth, AutoNumber *auto_number)
|
||||
{
|
||||
PyObject *tmp = NULL;
|
||||
PyObject *fieldobj = NULL;
|
||||
TyObject *tmp = NULL;
|
||||
TyObject *fieldobj = NULL;
|
||||
SubString expanded_format_spec;
|
||||
SubString *actual_format_spec;
|
||||
int result = 0;
|
||||
@@ -825,7 +825,7 @@ output_markup(SubString *field_name, SubString *format_spec,
|
||||
goto done;
|
||||
|
||||
/* do the assignment, transferring ownership: fieldobj = tmp */
|
||||
Py_SETREF(fieldobj, tmp);
|
||||
Ty_SETREF(fieldobj, tmp);
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
@@ -839,7 +839,7 @@ output_markup(SubString *field_name, SubString *format_spec,
|
||||
/* note that in the case we're expanding the format string,
|
||||
tmp must be kept around until after the call to
|
||||
render_field. */
|
||||
SubString_init(&expanded_format_spec, tmp, 0, PyUnicode_GET_LENGTH(tmp));
|
||||
SubString_init(&expanded_format_spec, tmp, 0, TyUnicode_GET_LENGTH(tmp));
|
||||
actual_format_spec = &expanded_format_spec;
|
||||
}
|
||||
else
|
||||
@@ -851,8 +851,8 @@ output_markup(SubString *field_name, SubString *format_spec,
|
||||
result = 1;
|
||||
|
||||
done:
|
||||
Py_XDECREF(fieldobj);
|
||||
Py_XDECREF(tmp);
|
||||
Ty_XDECREF(fieldobj);
|
||||
Ty_XDECREF(tmp);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -864,7 +864,7 @@ done:
|
||||
and to perform the markup to the output.
|
||||
*/
|
||||
static int
|
||||
do_markup(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
do_markup(SubString *input, TyObject *args, TyObject *kwargs,
|
||||
_PyUnicodeWriter *writer, int recursion_depth, AutoNumber *auto_number)
|
||||
{
|
||||
MarkupIterator iter;
|
||||
@@ -874,7 +874,7 @@ do_markup(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
SubString literal;
|
||||
SubString field_name;
|
||||
SubString format_spec;
|
||||
Py_UCS4 conversion;
|
||||
Ty_UCS4 conversion;
|
||||
|
||||
MarkupIterator_init(&iter, input->str, input->start, input->end);
|
||||
while ((result = MarkupIterator_next(&iter, &literal, &field_present,
|
||||
@@ -906,22 +906,22 @@ do_markup(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
build_string allocates the output string and then
|
||||
calls do_markup to do the heavy lifting.
|
||||
*/
|
||||
static PyObject *
|
||||
build_string(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
static TyObject *
|
||||
build_string(SubString *input, TyObject *args, TyObject *kwargs,
|
||||
int recursion_depth, AutoNumber *auto_number)
|
||||
{
|
||||
_PyUnicodeWriter writer;
|
||||
|
||||
/* check the recursion level */
|
||||
if (recursion_depth <= 0) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
TyErr_SetString(TyExc_ValueError,
|
||||
"Max string recursion exceeded");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_PyUnicodeWriter_Init(&writer);
|
||||
writer.overallocate = 1;
|
||||
writer.min_length = PyUnicode_GET_LENGTH(input->str) + 100;
|
||||
writer.min_length = TyUnicode_GET_LENGTH(input->str) + 100;
|
||||
|
||||
if (!do_markup(input, args, kwargs, &writer, recursion_depth,
|
||||
auto_number)) {
|
||||
@@ -937,8 +937,8 @@ build_string(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
/************************************************************************/
|
||||
|
||||
/* this is the main entry point */
|
||||
static PyObject *
|
||||
do_string_format(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
static TyObject *
|
||||
do_string_format(TyObject *self, TyObject *args, TyObject *kwargs)
|
||||
{
|
||||
SubString input;
|
||||
|
||||
@@ -950,12 +950,12 @@ do_string_format(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
|
||||
AutoNumber auto_number;
|
||||
AutoNumber_Init(&auto_number);
|
||||
SubString_init(&input, self, 0, PyUnicode_GET_LENGTH(self));
|
||||
SubString_init(&input, self, 0, TyUnicode_GET_LENGTH(self));
|
||||
return build_string(&input, args, kwargs, recursion_depth, &auto_number);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
do_string_format_map(PyObject *self, PyObject *obj)
|
||||
static TyObject *
|
||||
do_string_format_map(TyObject *self, TyObject *obj)
|
||||
{
|
||||
return do_string_format(self, NULL, obj);
|
||||
}
|
||||
@@ -972,15 +972,15 @@ do_string_format_map(PyObject *self, PyObject *obj)
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject *str;
|
||||
TyObject *str;
|
||||
MarkupIterator it_markup;
|
||||
} formatteriterobject;
|
||||
|
||||
static void
|
||||
formatteriter_dealloc(PyObject *op)
|
||||
formatteriter_dealloc(TyObject *op)
|
||||
{
|
||||
formatteriterobject *it = (formatteriterobject*)op;
|
||||
Py_XDECREF(it->str);
|
||||
Ty_XDECREF(it->str);
|
||||
PyObject_Free(it);
|
||||
}
|
||||
|
||||
@@ -992,14 +992,14 @@ formatteriter_dealloc(PyObject *op)
|
||||
format_spec is the string after the ':'. mibht be None
|
||||
conversion is either None, or the string after the '!'
|
||||
*/
|
||||
static PyObject *
|
||||
formatteriter_next(PyObject *op)
|
||||
static TyObject *
|
||||
formatteriter_next(TyObject *op)
|
||||
{
|
||||
formatteriterobject *it = (formatteriterobject*)op;
|
||||
SubString literal;
|
||||
SubString field_name;
|
||||
SubString format_spec;
|
||||
Py_UCS4 conversion;
|
||||
Ty_UCS4 conversion;
|
||||
int format_spec_needs_expanding;
|
||||
int field_present;
|
||||
int result = MarkupIterator_next(&it->it_markup, &literal, &field_present,
|
||||
@@ -1013,11 +1013,11 @@ formatteriter_next(PyObject *op)
|
||||
/* if 0, error has already been set, if 1, iterator is empty */
|
||||
return NULL;
|
||||
else {
|
||||
PyObject *literal_str = NULL;
|
||||
PyObject *field_name_str = NULL;
|
||||
PyObject *format_spec_str = NULL;
|
||||
PyObject *conversion_str = NULL;
|
||||
PyObject *tuple = NULL;
|
||||
TyObject *literal_str = NULL;
|
||||
TyObject *field_name_str = NULL;
|
||||
TyObject *format_spec_str = NULL;
|
||||
TyObject *conversion_str = NULL;
|
||||
TyObject *tuple = NULL;
|
||||
|
||||
literal_str = SubString_new_object(&literal);
|
||||
if (literal_str == NULL)
|
||||
@@ -1039,31 +1039,31 @@ formatteriter_next(PyObject *op)
|
||||
otherwise create a one length string with the conversion
|
||||
character */
|
||||
if (conversion == '\0') {
|
||||
conversion_str = Py_NewRef(Py_None);
|
||||
conversion_str = Ty_NewRef(Ty_None);
|
||||
}
|
||||
else
|
||||
conversion_str = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND,
|
||||
conversion_str = TyUnicode_FromKindAndData(TyUnicode_4BYTE_KIND,
|
||||
&conversion, 1);
|
||||
if (conversion_str == NULL)
|
||||
goto done;
|
||||
|
||||
tuple = PyTuple_Pack(4, literal_str, field_name_str, format_spec_str,
|
||||
tuple = TyTuple_Pack(4, literal_str, field_name_str, format_spec_str,
|
||||
conversion_str);
|
||||
done:
|
||||
Py_XDECREF(literal_str);
|
||||
Py_XDECREF(field_name_str);
|
||||
Py_XDECREF(format_spec_str);
|
||||
Py_XDECREF(conversion_str);
|
||||
Ty_XDECREF(literal_str);
|
||||
Ty_XDECREF(field_name_str);
|
||||
Ty_XDECREF(format_spec_str);
|
||||
Ty_XDECREF(conversion_str);
|
||||
return tuple;
|
||||
}
|
||||
}
|
||||
|
||||
static PyMethodDef formatteriter_methods[] = {
|
||||
static TyMethodDef formatteriter_methods[] = {
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyTypeObject PyFormatterIter_Type = {
|
||||
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
||||
static TyTypeObject PyFormatterIter_Type = {
|
||||
PyVarObject_HEAD_INIT(&TyType_Type, 0)
|
||||
"formatteriterator", /* tp_name */
|
||||
sizeof(formatteriterobject), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
@@ -1083,7 +1083,7 @@ static PyTypeObject PyFormatterIter_Type = {
|
||||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
Ty_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
0, /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
@@ -1099,13 +1099,13 @@ static PyTypeObject PyFormatterIter_Type = {
|
||||
string.Formatter.vformat. it parses a string and returns tuples
|
||||
describing the parsed elements. It's a wrapper around
|
||||
stringlib/string_format.h's MarkupIterator */
|
||||
static PyObject *
|
||||
formatter_parser(PyObject *Py_UNUSED(module), PyObject *self)
|
||||
static TyObject *
|
||||
formatter_parser(TyObject *Ty_UNUSED(module), TyObject *self)
|
||||
{
|
||||
formatteriterobject *it;
|
||||
|
||||
if (!PyUnicode_Check(self)) {
|
||||
PyErr_Format(PyExc_TypeError, "expected str, got %s", Py_TYPE(self)->tp_name);
|
||||
if (!TyUnicode_Check(self)) {
|
||||
TyErr_Format(TyExc_TypeError, "expected str, got %s", Ty_TYPE(self)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1114,11 +1114,11 @@ formatter_parser(PyObject *Py_UNUSED(module), PyObject *self)
|
||||
return NULL;
|
||||
|
||||
/* take ownership, give the object to the iterator */
|
||||
it->str = Py_NewRef(self);
|
||||
it->str = Ty_NewRef(self);
|
||||
|
||||
/* initialize the contained MarkupIterator */
|
||||
MarkupIterator_init(&it->it_markup, (PyObject*)self, 0, PyUnicode_GET_LENGTH(self));
|
||||
return (PyObject *)it;
|
||||
MarkupIterator_init(&it->it_markup, (TyObject*)self, 0, TyUnicode_GET_LENGTH(self));
|
||||
return (TyObject *)it;
|
||||
}
|
||||
|
||||
|
||||
@@ -1133,15 +1133,15 @@ formatter_parser(PyObject *Py_UNUSED(module), PyObject *self)
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject *str;
|
||||
TyObject *str;
|
||||
FieldNameIterator it_field;
|
||||
} fieldnameiterobject;
|
||||
|
||||
static void
|
||||
fieldnameiter_dealloc(PyObject *op)
|
||||
fieldnameiter_dealloc(TyObject *op)
|
||||
{
|
||||
fieldnameiterobject *it = (fieldnameiterobject*)op;
|
||||
Py_XDECREF(it->str);
|
||||
Ty_XDECREF(it->str);
|
||||
PyObject_Free(it);
|
||||
}
|
||||
|
||||
@@ -1151,13 +1151,13 @@ fieldnameiter_dealloc(PyObject *op)
|
||||
false if we used index syntax (e.g., '[foo]')
|
||||
value is an integer or string
|
||||
*/
|
||||
static PyObject *
|
||||
fieldnameiter_next(PyObject *op)
|
||||
static TyObject *
|
||||
fieldnameiter_next(TyObject *op)
|
||||
{
|
||||
fieldnameiterobject *it = (fieldnameiterobject*)op;
|
||||
int result;
|
||||
int is_attr;
|
||||
Py_ssize_t idx;
|
||||
Ty_ssize_t idx;
|
||||
SubString name;
|
||||
|
||||
result = FieldNameIterator_next(&it->it_field, &is_attr,
|
||||
@@ -1166,38 +1166,38 @@ fieldnameiter_next(PyObject *op)
|
||||
/* if 0, error has already been set, if 1, iterator is empty */
|
||||
return NULL;
|
||||
else {
|
||||
PyObject* result = NULL;
|
||||
PyObject* is_attr_obj = NULL;
|
||||
PyObject* obj = NULL;
|
||||
TyObject* result = NULL;
|
||||
TyObject* is_attr_obj = NULL;
|
||||
TyObject* obj = NULL;
|
||||
|
||||
is_attr_obj = PyBool_FromLong(is_attr);
|
||||
is_attr_obj = TyBool_FromLong(is_attr);
|
||||
if (is_attr_obj == NULL)
|
||||
goto done;
|
||||
|
||||
/* either an integer or a string */
|
||||
if (idx != -1)
|
||||
obj = PyLong_FromSsize_t(idx);
|
||||
obj = TyLong_FromSsize_t(idx);
|
||||
else
|
||||
obj = SubString_new_object(&name);
|
||||
if (obj == NULL)
|
||||
goto done;
|
||||
|
||||
/* return a tuple of values */
|
||||
result = PyTuple_Pack(2, is_attr_obj, obj);
|
||||
result = TyTuple_Pack(2, is_attr_obj, obj);
|
||||
|
||||
done:
|
||||
Py_XDECREF(is_attr_obj);
|
||||
Py_XDECREF(obj);
|
||||
Ty_XDECREF(is_attr_obj);
|
||||
Ty_XDECREF(obj);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
static PyMethodDef fieldnameiter_methods[] = {
|
||||
static TyMethodDef fieldnameiter_methods[] = {
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyTypeObject PyFieldNameIter_Type = {
|
||||
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
||||
static TyTypeObject PyFieldNameIter_Type = {
|
||||
PyVarObject_HEAD_INIT(&TyType_Type, 0)
|
||||
"fieldnameiterator", /* tp_name */
|
||||
sizeof(fieldnameiterobject), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
@@ -1217,7 +1217,7 @@ static PyTypeObject PyFieldNameIter_Type = {
|
||||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
Ty_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
0, /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
@@ -1235,18 +1235,18 @@ static PyTypeObject PyFieldNameIter_Type = {
|
||||
name. it's a wrapper around stringlib/string_format.h's
|
||||
field_name_split. The iterator it returns is a
|
||||
FieldNameIterator */
|
||||
static PyObject *
|
||||
formatter_field_name_split(PyObject *Py_UNUSED(module), PyObject *self)
|
||||
static TyObject *
|
||||
formatter_field_name_split(TyObject *Ty_UNUSED(module), TyObject *self)
|
||||
{
|
||||
SubString first;
|
||||
Py_ssize_t first_idx;
|
||||
Ty_ssize_t first_idx;
|
||||
fieldnameiterobject *it;
|
||||
|
||||
PyObject *first_obj = NULL;
|
||||
PyObject *result = NULL;
|
||||
TyObject *first_obj = NULL;
|
||||
TyObject *result = NULL;
|
||||
|
||||
if (!PyUnicode_Check(self)) {
|
||||
PyErr_Format(PyExc_TypeError, "expected str, got %s", Py_TYPE(self)->tp_name);
|
||||
if (!TyUnicode_Check(self)) {
|
||||
TyErr_Format(TyExc_TypeError, "expected str, got %s", Ty_TYPE(self)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1256,17 +1256,17 @@ formatter_field_name_split(PyObject *Py_UNUSED(module), PyObject *self)
|
||||
|
||||
/* take ownership, give the object to the iterator. this is
|
||||
just to keep the field_name alive */
|
||||
it->str = Py_NewRef(self);
|
||||
it->str = Ty_NewRef(self);
|
||||
|
||||
/* Pass in auto_number = NULL. We'll return an empty string for
|
||||
first_obj in that case. */
|
||||
if (!field_name_split((PyObject*)self, 0, PyUnicode_GET_LENGTH(self),
|
||||
if (!field_name_split((TyObject*)self, 0, TyUnicode_GET_LENGTH(self),
|
||||
&first, &first_idx, &it->it_field, NULL))
|
||||
goto done;
|
||||
|
||||
/* first becomes an integer, if possible; else a string */
|
||||
if (first_idx != -1)
|
||||
first_obj = PyLong_FromSsize_t(first_idx);
|
||||
first_obj = TyLong_FromSsize_t(first_idx);
|
||||
else
|
||||
/* convert "first" into a string object */
|
||||
first_obj = SubString_new_object(&first);
|
||||
@@ -1274,10 +1274,10 @@ formatter_field_name_split(PyObject *Py_UNUSED(module), PyObject *self)
|
||||
goto done;
|
||||
|
||||
/* return a tuple of values */
|
||||
result = PyTuple_Pack(2, first_obj, it);
|
||||
result = TyTuple_Pack(2, first_obj, it);
|
||||
|
||||
done:
|
||||
Py_XDECREF(it);
|
||||
Py_XDECREF(first_obj);
|
||||
Ty_XDECREF(it);
|
||||
Ty_XDECREF(first_obj);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user