diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2005-12-10 18:50:16 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2005-12-10 18:50:16 (GMT) |
commit | af68c874a6803b4e90b616077a602c0593719a1d (patch) | |
tree | c7361b29cf629171b4da8e51cfd1074f67d814a7 /Include/object.h | |
parent | aaa2f1dea706daf2a5f431d97a3e3120dba652d2 (diff) | |
download | cpython-af68c874a6803b4e90b616077a602c0593719a1d.zip cpython-af68c874a6803b4e90b616077a602c0593719a1d.tar.gz cpython-af68c874a6803b4e90b616077a602c0593719a1d.tar.bz2 |
Add const to several API functions that take char *.
In C++, it's an error to pass a string literal to a char* function
without a const_cast(). Rather than require every C++ extension
module to put a cast around string literals, fix the API to state the
const-ness.
I focused on parts of the API where people usually pass literals:
PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type
slots, etc. Predictably, there were a large set of functions that
needed to be fixed as a result of these changes. The most pervasive
change was to make the keyword args list passed to
PyArg_ParseTupleAndKewords() to be a const char *kwlist[].
One cast was required as a result of the changes: A type object
mallocs the memory for its tp_doc slot and later frees it.
PyTypeObject says that tp_doc is const char *; but if the type was
created by type_new(), we know it is safe to cast to char *.
Diffstat (limited to 'Include/object.h')
-rw-r--r-- | Include/object.h | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Include/object.h b/Include/object.h index 15fee96..ed6f3d1 100644 --- a/Include/object.h +++ b/Include/object.h @@ -225,9 +225,9 @@ typedef struct { typedef void (*freefunc)(void *); typedef void (*destructor)(PyObject *); typedef int (*printfunc)(PyObject *, FILE *, int); -typedef PyObject *(*getattrfunc)(PyObject *, char *); +typedef PyObject *(*getattrfunc)(PyObject *, const char *); typedef PyObject *(*getattrofunc)(PyObject *, PyObject *); -typedef int (*setattrfunc)(PyObject *, char *, PyObject *); +typedef int (*setattrfunc)(PyObject *, const char *, PyObject *); typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *); typedef int (*cmpfunc)(PyObject *, PyObject *); typedef PyObject *(*reprfunc)(PyObject *); @@ -243,7 +243,7 @@ typedef PyObject *(*allocfunc)(struct _typeobject *, int); typedef struct _typeobject { PyObject_VAR_HEAD - char *tp_name; /* For printing, in format "<module>.<name>" */ + const char *tp_name; /* For printing, in format "<module>.<name>" */ int tp_basicsize, tp_itemsize; /* For allocation */ /* Methods to implement standard operations */ @@ -275,7 +275,7 @@ typedef struct _typeobject { /* Flags to define presence of optional/expanded features */ long tp_flags; - char *tp_doc; /* Documentation string */ + const char *tp_doc; /* Documentation string */ /* Assigned meaning in release 2.0 */ /* call function for all accessible objects */ @@ -379,9 +379,9 @@ PyAPI_FUNC(PyObject *) PyObject_Unicode(PyObject *); PyAPI_FUNC(int) PyObject_Compare(PyObject *, PyObject *); PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int); PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int); -PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, char *); -PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, char *, PyObject *); -PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, char *); +PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *); +PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, const char *, PyObject *); +PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *); PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *); PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *); PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *); |