Skip to content

Commit ac3157d

Browse files
author
neal.norwitz
committed
Use macro versions instead of function versions when we already know the type.
This will hopefully get rid of some Coverity warnings, be a hint to developers, and be marginally faster. Some asserts were added when the type is currently known, but depends on values from another function. git-svn-id: http://svn.python.org/projects/python/trunk@43145 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent c192e7f commit ac3157d

7 files changed

Lines changed: 19 additions & 16 deletions

File tree

Modules/stropmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ strop_translate(PyObject *self, PyObject *args)
942942
}
943943

944944
table = table1;
945-
inlen = PyString_Size(input_obj);
945+
inlen = PyString_GET_SIZE(input_obj);
946946
result = PyString_FromStringAndSize((char *)NULL, inlen);
947947
if (result == NULL)
948948
return NULL;

Objects/classobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,15 @@ class_str(PyClassObject *op)
388388
Py_INCREF(name);
389389
return name;
390390
}
391-
m = PyString_Size(mod);
392-
n = PyString_Size(name);
391+
m = PyString_GET_SIZE(mod);
392+
n = PyString_GET_SIZE(name);
393393
res = PyString_FromStringAndSize((char *)NULL, m+1+n);
394394
if (res != NULL) {
395-
char *s = PyString_AsString(res);
396-
memcpy(s, PyString_AsString(mod), m);
395+
char *s = PyString_AS_STRING(res);
396+
memcpy(s, PyString_AS_STRING(mod), m);
397397
s += m;
398398
*s++ = '.';
399-
memcpy(s, PyString_AsString(name), n);
399+
memcpy(s, PyString_AS_STRING(name), n);
400400
}
401401
return res;
402402
}

Objects/frameobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ PyFrame_FastToLocals(PyFrameObject *f)
749749
return;
750750
PyErr_Fetch(&error_type, &error_value, &error_traceback);
751751
fast = f->f_localsplus;
752-
j = PyTuple_Size(map);
752+
j = PyTuple_GET_SIZE(map);
753753
if (j > f->f_nlocals)
754754
j = f->f_nlocals;
755755
if (f->f_nlocals)
@@ -787,7 +787,7 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear)
787787
return;
788788
PyErr_Fetch(&error_type, &error_value, &error_traceback);
789789
fast = f->f_localsplus;
790-
j = PyTuple_Size(map);
790+
j = PyTuple_GET_SIZE(map);
791791
if (j > f->f_nlocals)
792792
j = f->f_nlocals;
793793
if (f->f_nlocals)

Objects/stringobject.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,9 @@ PyObject *PyString_DecodeEscape(const char *s,
569569
if (!w) goto failed;
570570

571571
/* Append bytes to output buffer. */
572-
r = PyString_AsString(w);
573-
rn = PyString_Size(w);
572+
assert(PyString_Check(w));
573+
r = PyString_AS_STRING(w);
574+
rn = PyString_GET_SIZE(w);
574575
memcpy(p, r, rn);
575576
p += rn;
576577
Py_DECREF(w);
@@ -2314,12 +2315,12 @@ string_translate(PyStringObject *self, PyObject *args)
23142315
}
23152316

23162317
table = table1;
2317-
inlen = PyString_Size(input_obj);
2318+
inlen = PyString_GET_SIZE(input_obj);
23182319
result = PyString_FromStringAndSize((char *)NULL, inlen);
23192320
if (result == NULL)
23202321
return NULL;
23212322
output_start = output = PyString_AsString(result);
2322-
input = PyString_AsString(input_obj);
2323+
input = PyString_AS_STRING(input_obj);
23232324

23242325
if (dellen == 0) {
23252326
/* If no deletions are required, use faster code */

Parser/tokenizer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,9 @@ tok_stdin_decode(struct tok_state *tok, char **inp)
711711
if (utf8 == NULL)
712712
goto error_clear;
713713

714-
converted = new_string(PyString_AsString(utf8), PyString_Size(utf8));
714+
assert(PyString_Check(utf8));
715+
converted = new_string(PyString_AS_STRING(utf8),
716+
PyString_GET_SIZE(utf8));
715717
Py_DECREF(utf8);
716718
if (converted == NULL)
717719
goto error_nomem;

Python/import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,12 +1216,12 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
12161216
#endif
12171217
if (!PyString_Check(v))
12181218
continue;
1219-
len = PyString_Size(v);
1219+
len = PyString_GET_SIZE(v);
12201220
if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) {
12211221
Py_XDECREF(copy);
12221222
continue; /* Too long */
12231223
}
1224-
strcpy(buf, PyString_AsString(v));
1224+
strcpy(buf, PyString_AS_STRING(v));
12251225
if (strlen(buf) != len) {
12261226
Py_XDECREF(copy);
12271227
continue; /* v contains '\0' */

Python/traceback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name)
165165
}
166166
if (PyString_Check(v)) {
167167
size_t len;
168-
len = PyString_Size(v);
168+
len = PyString_GET_SIZE(v);
169169
if (len + 1 + taillen >= MAXPATHLEN)
170170
continue; /* Too long */
171171
strcpy(namebuf, PyString_AsString(v));

0 commit comments

Comments
 (0)