]> granicus.if.org Git - python/commitdiff
Use macro versions instead of function versions when we already know the type.
authorNeal Norwitz <nnorwitz@gmail.com>
Mon, 20 Mar 2006 01:53:23 +0000 (01:53 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Mon, 20 Mar 2006 01:53:23 +0000 (01:53 +0000)
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.

Modules/stropmodule.c
Objects/classobject.c
Objects/frameobject.c
Objects/stringobject.c
Parser/tokenizer.c
Python/import.c
Python/traceback.c

index cffef3af3a6d11295251601125d7eb2d77cc6368..2f671b6ac2a038acc0a1c973b15103e0269b3329 100644 (file)
@@ -942,7 +942,7 @@ strop_translate(PyObject *self, PyObject *args)
        }
 
        table = table1;
-       inlen = PyString_Size(input_obj);
+       inlen = PyString_GET_SIZE(input_obj);
        result = PyString_FromStringAndSize((char *)NULL, inlen);
        if (result == NULL)
                return NULL;
index 037252d06a4ba187bcec2a90c6da76fe80f9038c..f3e636a1b36e01dfdb81693d2d8bcc378958e858 100644 (file)
@@ -388,15 +388,15 @@ class_str(PyClassObject *op)
                Py_INCREF(name);
                return name;
        }
-       m = PyString_Size(mod);
-       n = PyString_Size(name);
+       m = PyString_GET_SIZE(mod);
+       n = PyString_GET_SIZE(name);
        res = PyString_FromStringAndSize((char *)NULL, m+1+n);
        if (res != NULL) {
-               char *s = PyString_AsString(res);
-               memcpy(s, PyString_AsString(mod), m);
+               char *s = PyString_AS_STRING(res);
+               memcpy(s, PyString_AS_STRING(mod), m);
                s += m;
                *s++ = '.';
-               memcpy(s, PyString_AsString(name), n);
+               memcpy(s, PyString_AS_STRING(name), n);
        }
        return res;
 }
index 6e3f29784dda08c5a5155c6ceab64e4a964cdc4f..8aa33771801b776f9912923291b451c7450c3011 100644 (file)
@@ -749,7 +749,7 @@ PyFrame_FastToLocals(PyFrameObject *f)
                return;
        PyErr_Fetch(&error_type, &error_value, &error_traceback);
        fast = f->f_localsplus;
-       j = PyTuple_Size(map);
+       j = PyTuple_GET_SIZE(map);
        if (j > f->f_nlocals)
                j = f->f_nlocals;
        if (f->f_nlocals)
@@ -787,7 +787,7 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear)
                return;
        PyErr_Fetch(&error_type, &error_value, &error_traceback);
        fast = f->f_localsplus;
-       j = PyTuple_Size(map);
+       j = PyTuple_GET_SIZE(map);
        if (j > f->f_nlocals)
                j = f->f_nlocals;
        if (f->f_nlocals)
index d23c97332ed8b0981e7390e6990b28f3c44d2ae2..e3a0197a8b50b933b661d48b256e4357024ec0f5 100644 (file)
@@ -569,8 +569,9 @@ PyObject *PyString_DecodeEscape(const char *s,
                                if (!w) goto failed;
 
                                /* Append bytes to output buffer. */
-                               r = PyString_AsString(w);
-                               rn = PyString_Size(w);
+                               assert(PyString_Check(w));
+                               r = PyString_AS_STRING(w);
+                               rn = PyString_GET_SIZE(w);
                                memcpy(p, r, rn);
                                p += rn;
                                Py_DECREF(w);
@@ -2314,12 +2315,12 @@ string_translate(PyStringObject *self, PyObject *args)
        }
 
        table = table1;
-       inlen = PyString_Size(input_obj);
+       inlen = PyString_GET_SIZE(input_obj);
        result = PyString_FromStringAndSize((char *)NULL, inlen);
        if (result == NULL)
                return NULL;
        output_start = output = PyString_AsString(result);
-       input = PyString_AsString(input_obj);
+       input = PyString_AS_STRING(input_obj);
 
        if (dellen == 0) {
                /* If no deletions are required, use faster code */
index 3c8258832e7519cace80e80755ff1181795cf0a9..b0d9b80c3274fb0784d78cf464f396a03c573833 100644 (file)
@@ -711,7 +711,9 @@ tok_stdin_decode(struct tok_state *tok, char **inp)
        if (utf8 == NULL)
                goto error_clear;
 
-       converted = new_string(PyString_AsString(utf8), PyString_Size(utf8));
+       assert(PyString_Check(utf8));
+       converted = new_string(PyString_AS_STRING(utf8),
+                              PyString_GET_SIZE(utf8));
        Py_DECREF(utf8);
        if (converted == NULL)
                goto error_nomem;
index 73051a2060ebdf88eabe7ccdaf774289baf19d3e..e58dbd5a1b94472b0924622f20a47bc4010625c0 100644 (file)
@@ -1216,12 +1216,12 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
 #endif
                if (!PyString_Check(v))
                        continue;
-               len = PyString_Size(v);
+               len = PyString_GET_SIZE(v);
                if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) {
                        Py_XDECREF(copy);
                        continue; /* Too long */
                }
-               strcpy(buf, PyString_AsString(v));
+               strcpy(buf, PyString_AS_STRING(v));
                if (strlen(buf) != len) {
                        Py_XDECREF(copy);
                        continue; /* v contains '\0' */
index 6c11cf527457f9aa9102468f92ececd2471bf88d..567f23d99032a13ea10f079e2d4a62fec7b46c62 100644 (file)
@@ -165,7 +165,7 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name)
                                }
                                if (PyString_Check(v)) {
                                        size_t len;
-                                       len = PyString_Size(v);
+                                       len = PyString_GET_SIZE(v);
                                        if (len + 1 + taillen >= MAXPATHLEN)
                                                continue; /* Too long */
                                        strcpy(namebuf, PyString_AsString(v));