summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2007-12-19 02:37:44 (GMT)
committerChristian Heimes <christian@cheimes.de>2007-12-19 02:37:44 (GMT)
commite93237dfcc4ee4feee62adafb4e7899487ca864b (patch)
treeb78abc265e7fb10639492f62e4ffd0ce1bcc67af /Objects/stringobject.c
parentd586559c31b77938b514cec99f2f8b431a34dff5 (diff)
downloadcpython-e93237dfcc4ee4feee62adafb4e7899487ca864b.zip
cpython-e93237dfcc4ee4feee62adafb4e7899487ca864b.tar.gz
cpython-e93237dfcc4ee4feee62adafb4e7899487ca864b.tar.bz2
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r--Objects/stringobject.c128
1 files changed, 64 insertions, 64 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 2c8c989..21f59ac 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -421,7 +421,7 @@ PyObject *PyString_AsDecodedString(PyObject *str,
if (!PyString_Check(v)) {
PyErr_Format(PyExc_TypeError,
"decoder did not return a string object (type=%.400s)",
- Py_Type(v)->tp_name);
+ Py_TYPE(v)->tp_name);
Py_DECREF(v);
goto onError;
}
@@ -501,7 +501,7 @@ PyObject *PyString_AsEncodedString(PyObject *str,
if (!PyString_Check(v)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a string object (type=%.400s)",
- Py_Type(v)->tp_name);
+ Py_TYPE(v)->tp_name);
Py_DECREF(v);
goto onError;
}
@@ -521,7 +521,7 @@ string_dealloc(PyObject *op)
case SSTATE_INTERNED_MORTAL:
/* revive dead object temporarily for DelItem */
- Py_Refcnt(op) = 3;
+ Py_REFCNT(op) = 3;
if (PyDict_DelItem(interned, op) != 0)
Py_FatalError(
"deletion of interned string failed");
@@ -533,7 +533,7 @@ string_dealloc(PyObject *op)
default:
Py_FatalError("Inconsistent interned string state.");
}
- Py_Type(op)->tp_free(op);
+ Py_TYPE(op)->tp_free(op);
}
/* Unescape a backslash-escaped string. If unicode is non-zero,
@@ -719,7 +719,7 @@ PyString_Size(register PyObject *op)
{
if (!PyString_Check(op))
return string_getsize(op);
- return Py_Size(op);
+ return Py_SIZE(op);
}
/*const*/ char *
@@ -752,7 +752,7 @@ PyString_AsStringAndSize(register PyObject *obj,
{
PyErr_Format(PyExc_TypeError,
"expected string or Unicode object, "
- "%.200s found", Py_Type(obj)->tp_name);
+ "%.200s found", Py_TYPE(obj)->tp_name);
return -1;
}
}
@@ -807,7 +807,7 @@ string_print(PyStringObject *op, FILE *fp, int flags)
}
if (flags & Py_PRINT_RAW) {
char *data = op->ob_sval;
- Py_ssize_t size = Py_Size(op);
+ Py_ssize_t size = Py_SIZE(op);
Py_BEGIN_ALLOW_THREADS
while (size > INT_MAX) {
/* Very long strings cannot be written atomically.
@@ -830,11 +830,11 @@ string_print(PyStringObject *op, FILE *fp, int flags)
/* figure out which quote to use; single is preferred */
quote = '\'';
- if (memchr(op->ob_sval, '\'', Py_Size(op)) &&
- !memchr(op->ob_sval, '"', Py_Size(op)))
+ if (memchr(op->ob_sval, '\'', Py_SIZE(op)) &&
+ !memchr(op->ob_sval, '"', Py_SIZE(op)))
quote = '"';
- str_len = Py_Size(op);
+ str_len = Py_SIZE(op);
Py_BEGIN_ALLOW_THREADS
fputc(quote, fp);
for (i = 0; i < str_len; i++) {
@@ -864,9 +864,9 @@ PyObject *
PyString_Repr(PyObject *obj, int smartquotes)
{
register PyStringObject* op = (PyStringObject*) obj;
- size_t newsize = 2 + 4 * Py_Size(op);
+ size_t newsize = 2 + 4 * Py_SIZE(op);
PyObject *v;
- if (newsize > PY_SSIZE_T_MAX || newsize / 4 != Py_Size(op)) {
+ if (newsize > PY_SSIZE_T_MAX || newsize / 4 != Py_SIZE(op)) {
PyErr_SetString(PyExc_OverflowError,
"string is too large to make repr");
return NULL;
@@ -884,13 +884,13 @@ PyString_Repr(PyObject *obj, int smartquotes)
/* figure out which quote to use; single is preferred */
quote = '\'';
if (smartquotes &&
- memchr(op->ob_sval, '\'', Py_Size(op)) &&
- !memchr(op->ob_sval, '"', Py_Size(op)))
+ memchr(op->ob_sval, '\'', Py_SIZE(op)) &&
+ !memchr(op->ob_sval, '"', Py_SIZE(op)))
quote = '"';
p = PyString_AS_STRING(v);
*p++ = quote;
- for (i = 0; i < Py_Size(op); i++) {
+ for (i = 0; i < Py_SIZE(op); i++) {
/* There's at least enough room for a hex escape
and a closing quote. */
assert(newsize - (p - PyString_AS_STRING(v)) >= 5);
@@ -939,14 +939,14 @@ string_str(PyObject *s)
else {
/* Subtype -- return genuine string with the same value. */
PyStringObject *t = (PyStringObject *) s;
- return PyString_FromStringAndSize(t->ob_sval, Py_Size(t));
+ return PyString_FromStringAndSize(t->ob_sval, Py_SIZE(t));
}
}
static Py_ssize_t
string_length(PyStringObject *a)
{
- return Py_Size(a);
+ return Py_SIZE(a);
}
static PyObject *
@@ -961,21 +961,21 @@ string_concat(register PyStringObject *a, register PyObject *bb)
#endif
PyErr_Format(PyExc_TypeError,
"cannot concatenate 'str' and '%.200s' objects",
- Py_Type(bb)->tp_name);
+ Py_TYPE(bb)->tp_name);
return NULL;
}
#define b ((PyStringObject *)bb)
/* Optimize cases with empty left or right operand */
- if ((Py_Size(a) == 0 || Py_Size(b) == 0) &&
+ if ((Py_SIZE(a) == 0 || Py_SIZE(b) == 0) &&
PyString_CheckExact(a) && PyString_CheckExact(b)) {
- if (Py_Size(a) == 0) {
+ if (Py_SIZE(a) == 0) {
Py_INCREF(bb);
return bb;
}
Py_INCREF(a);
return (PyObject *)a;
}
- size = Py_Size(a) + Py_Size(b);
+ size = Py_SIZE(a) + Py_SIZE(b);
if (size < 0) {
PyErr_SetString(PyExc_OverflowError,
"strings are too large to concat");
@@ -989,8 +989,8 @@ string_concat(register PyStringObject *a, register PyObject *bb)
PyObject_INIT_VAR(op, &PyString_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
- Py_MEMCPY(op->ob_sval, a->ob_sval, Py_Size(a));
- Py_MEMCPY(op->ob_sval + Py_Size(a), b->ob_sval, Py_Size(b));
+ Py_MEMCPY(op->ob_sval, a->ob_sval, Py_SIZE(a));
+ Py_MEMCPY(op->ob_sval + Py_SIZE(a), b->ob_sval, Py_SIZE(b));
op->ob_sval[size] = '\0';
return (PyObject *) op;
#undef b
@@ -1009,13 +1009,13 @@ string_repeat(register PyStringObject *a, register Py_ssize_t n)
/* watch out for overflows: the size can overflow int,
* and the # of bytes needed can overflow size_t
*/
- size = Py_Size(a) * n;
- if (n && size / n != Py_Size(a)) {
+ size = Py_SIZE(a) * n;
+ if (n && size / n != Py_SIZE(a)) {
PyErr_SetString(PyExc_OverflowError,
"repeated string is too long");
return NULL;
}
- if (size == Py_Size(a) && PyString_CheckExact(a)) {
+ if (size == Py_SIZE(a) && PyString_CheckExact(a)) {
Py_INCREF(a);
return (PyObject *)a;
}
@@ -1033,14 +1033,14 @@ string_repeat(register PyStringObject *a, register Py_ssize_t n)
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
op->ob_sval[size] = '\0';
- if (Py_Size(a) == 1 && n > 0) {
+ if (Py_SIZE(a) == 1 && n > 0) {
memset(op->ob_sval, a->ob_sval[0] , n);
return (PyObject *) op;
}
i = 0;
if (i < size) {
- Py_MEMCPY(op->ob_sval, a->ob_sval, Py_Size(a));
- i = Py_Size(a);
+ Py_MEMCPY(op->ob_sval, a->ob_sval, Py_SIZE(a));
+ i = Py_SIZE(a);
}
while (i < size) {
j = (i <= size-i) ? i : size-i;
@@ -1061,9 +1061,9 @@ string_slice(register PyStringObject *a, register Py_ssize_t i,
i = 0;
if (j < 0)
j = 0; /* Avoid signed/unsigned bug in next line */
- if (j > Py_Size(a))
- j = Py_Size(a);
- if (i == 0 && j == Py_Size(a) && PyString_CheckExact(a)) {
+ if (j > Py_SIZE(a))
+ j = Py_SIZE(a);
+ if (i == 0 && j == Py_SIZE(a) && PyString_CheckExact(a)) {
/* It's the same as a */
Py_INCREF(a);
return (PyObject *)a;
@@ -1084,7 +1084,7 @@ string_contains(PyObject *str_obj, PyObject *sub_obj)
if (!PyString_Check(sub_obj)) {
PyErr_Format(PyExc_TypeError,
"'in <string>' requires string as left operand, "
- "not %.200s", Py_Type(sub_obj)->tp_name);
+ "not %.200s", Py_TYPE(sub_obj)->tp_name);
return -1;
}
}
@@ -1097,7 +1097,7 @@ string_item(PyStringObject *a, register Py_ssize_t i)
{
char pchar;
PyObject *v;
- if (i < 0 || i >= Py_Size(a)) {
+ if (i < 0 || i >= Py_SIZE(a)) {
PyErr_SetString(PyExc_IndexError, "string index out of range");
return NULL;
}
@@ -1140,16 +1140,16 @@ string_richcompare(PyStringObject *a, PyStringObject *b, int op)
if (op == Py_EQ) {
/* Supporting Py_NE here as well does not save
much time, since Py_NE is rarely used. */
- if (Py_Size(a) == Py_Size(b)
+ if (Py_SIZE(a) == Py_SIZE(b)
&& (a->ob_sval[0] == b->ob_sval[0]
- && memcmp(a->ob_sval, b->ob_sval, Py_Size(a)) == 0)) {
+ && memcmp(a->ob_sval, b->ob_sval, Py_SIZE(a)) == 0)) {
result = Py_True;
} else {
result = Py_False;
}
goto out;
}
- len_a = Py_Size(a); len_b = Py_Size(b);
+ len_a = Py_SIZE(a); len_b = Py_SIZE(b);
min_len = (len_a < len_b) ? len_a : len_b;
if (min_len > 0) {
c = Py_CHARMASK(*a->ob_sval) - Py_CHARMASK(*b->ob_sval);
@@ -1181,9 +1181,9 @@ _PyString_Eq(PyObject *o1, PyObject *o2)
{
PyStringObject *a = (PyStringObject*) o1;
PyStringObject *b = (PyStringObject*) o2;
- return Py_Size(a) == Py_Size(b)
+ return Py_SIZE(a) == Py_SIZE(b)
&& *a->ob_sval == *b->ob_sval
- && memcmp(a->ob_sval, b->ob_sval, Py_Size(a)) == 0;
+ && memcmp(a->ob_sval, b->ob_sval, Py_SIZE(a)) == 0;
}
static long
@@ -1195,12 +1195,12 @@ string_hash(PyStringObject *a)
if (a->ob_shash != -1)
return a->ob_shash;
- len = Py_Size(a);
+ len = Py_SIZE(a);
p = (unsigned char *) a->ob_sval;
x = *p << 7;
while (--len >= 0)
x = (1000003*x) ^ *p++;
- x ^= Py_Size(a);
+ x ^= Py_SIZE(a);
if (x == -1)
x = -2;
a->ob_shash = x;
@@ -1264,7 +1264,7 @@ string_subscript(PyStringObject* self, PyObject* item)
else {
PyErr_Format(PyExc_TypeError,
"string indices must be integers, not %.200s",
- Py_Type(item)->tp_name);
+ Py_TYPE(item)->tp_name);
return NULL;
}
}
@@ -1278,7 +1278,7 @@ string_buffer_getreadbuf(PyStringObject *self, Py_ssize_t index, const void **pt
return -1;
}
*ptr = (void *)self->ob_sval;
- return Py_Size(self);
+ return Py_SIZE(self);
}
static Py_ssize_t
@@ -1293,7 +1293,7 @@ static Py_ssize_t
string_buffer_getsegcount(PyStringObject *self, Py_ssize_t *lenp)
{
if ( lenp )
- *lenp = Py_Size(self);
+ *lenp = Py_SIZE(self);
return 1;
}
@@ -1306,7 +1306,7 @@ string_buffer_getcharbuf(PyStringObject *self, Py_ssize_t index, const char **pt
return -1;
}
*ptr = self->ob_sval;
- return Py_Size(self);
+ return Py_SIZE(self);
}
static PySequenceMethods string_as_sequence = {
@@ -1395,7 +1395,7 @@ static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
count++; }
/* Always force the list to the expected size. */
-#define FIX_PREALLOC_SIZE(list) Py_Size(list) = count
+#define FIX_PREALLOC_SIZE(list) Py_SIZE(list) = count
#define SKIP_SPACE(s, i, len) { while (i<len && isspace(Py_CHARMASK(s[i]))) i++; }
#define SKIP_NONSPACE(s, i, len) { while (i<len && !isspace(Py_CHARMASK(s[i]))) i++; }
@@ -1841,7 +1841,7 @@ string_join(PyStringObject *self, PyObject *orig)
PyErr_Format(PyExc_TypeError,
"sequence item %zd: expected string,"
" %.80s found",
- i, Py_Type(item)->tp_name);
+ i, Py_TYPE(item)->tp_name);
Py_DECREF(seq);
return NULL;
}
@@ -3312,7 +3312,7 @@ string_encode(PyStringObject *self, PyObject *args)
PyErr_Format(PyExc_TypeError,
"encoder did not return a string/unicode object "
"(type=%.400s)",
- Py_Type(v)->tp_name);
+ Py_TYPE(v)->tp_name);
Py_DECREF(v);
return NULL;
}
@@ -3349,7 +3349,7 @@ string_decode(PyStringObject *self, PyObject *args)
PyErr_Format(PyExc_TypeError,
"decoder did not return a string/unicode object "
"(type=%.400s)",
- Py_Type(v)->tp_name);
+ Py_TYPE(v)->tp_name);
Py_DECREF(v);
return NULL;
}
@@ -3907,7 +3907,7 @@ string_splitlines(PyStringObject *self, PyObject *args)
static PyObject *
string_getnewargs(PyStringObject *v)
{
- return Py_BuildValue("(s#)", v->ob_sval, Py_Size(v));
+ return Py_BuildValue("(s#)", v->ob_sval, Py_SIZE(v));
}
@@ -4170,7 +4170,7 @@ _PyString_Resize(PyObject **pv, Py_ssize_t newsize)
register PyObject *v;
register PyStringObject *sv;
v = *pv;
- if (!PyString_Check(v) || Py_Refcnt(v) != 1 || newsize < 0 ||
+ if (!PyString_Check(v) || Py_REFCNT(v) != 1 || newsize < 0 ||
PyString_CHECK_INTERNED(v)) {
*pv = 0;
Py_DECREF(v);
@@ -4189,7 +4189,7 @@ _PyString_Resize(PyObject **pv, Py_ssize_t newsize)
}
_Py_NewReference(*pv);
sv = (PyStringObject *) *pv;
- Py_Size(sv) = newsize;
+ Py_SIZE(sv) = newsize;
sv->ob_sval[newsize] = '\0';
sv->ob_shash = -1; /* invalidate cached hash value */
return 0;
@@ -4237,7 +4237,7 @@ formatfloat(char *buf, size_t buflen, int flags,
x = PyFloat_AsDouble(v);
if (x == -1.0 && PyErr_Occurred()) {
PyErr_Format(PyExc_TypeError, "float argument required, "
- "not %.200s", Py_Type(v)->tp_name);
+ "not %.200s", Py_TYPE(v)->tp_name);
return -1;
}
if (prec < 0)
@@ -4311,15 +4311,15 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
switch (type) {
case 'd':
case 'u':
- result = Py_Type(val)->tp_str(val);
+ result = Py_TYPE(val)->tp_str(val);
break;
case 'o':
- result = Py_Type(val)->tp_as_number->nb_oct(val);
+ result = Py_TYPE(val)->tp_as_number->nb_oct(val);
break;
case 'x':
case 'X':
numnondigits = 2;
- result = Py_Type(val)->tp_as_number->nb_hex(val);
+ result = Py_TYPE(val)->tp_as_number->nb_hex(val);
break;
default:
assert(!"'type' not in [duoxX]");
@@ -4334,7 +4334,7 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
}
/* To modify the string in-place, there can only be one reference. */
- if (Py_Refcnt(result) != 1) {
+ if (Py_REFCNT(result) != 1) {
PyErr_BadInternalCall();
return NULL;
}
@@ -4434,7 +4434,7 @@ formatint(char *buf, size_t buflen, int flags,
x = PyInt_AsLong(v);
if (x == -1 && PyErr_Occurred()) {
PyErr_Format(PyExc_TypeError, "int argument required, not %.200s",
- Py_Type(v)->tp_name);
+ Py_TYPE(v)->tp_name);
return -1;
}
if (x < 0 && type == 'u') {
@@ -4551,7 +4551,7 @@ PyString_Format(PyObject *format, PyObject *args)
arglen = -1;
argidx = -2;
}
- if (Py_Type(args)->tp_as_mapping && !PyTuple_Check(args) &&
+ if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) &&
!PyObject_TypeCheck(args, &PyBaseString_Type))
dict = args;
while (--fmtcnt >= 0) {
@@ -5018,7 +5018,7 @@ PyString_InternInPlace(PyObject **p)
}
/* The two references in interned are not counted by refcnt.
The string deallocator will take care of this */
- Py_Refcnt(s) -= 2;
+ Py_REFCNT(s) -= 2;
PyString_CHECK_INTERNED(s) = SSTATE_INTERNED_MORTAL;
}
@@ -5085,12 +5085,12 @@ void _Py_ReleaseInternedStrings(void)
/* XXX Shouldn't happen */
break;
case SSTATE_INTERNED_IMMORTAL:
- Py_Refcnt(s) += 1;
- immortal_size += Py_Size(s);
+ Py_REFCNT(s) += 1;
+ immortal_size += Py_SIZE(s);
break;
case SSTATE_INTERNED_MORTAL:
- Py_Refcnt(s) += 2;
- mortal_size += Py_Size(s);
+ Py_REFCNT(s) += 2;
+ mortal_size += Py_SIZE(s);
break;
default:
Py_FatalError("Inconsistent interned string state.");