summaryrefslogtreecommitdiffstats
path: root/Modules/cPickle.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2005-12-10 18:50:16 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2005-12-10 18:50:16 (GMT)
commitaf68c874a6803b4e90b616077a602c0593719a1d (patch)
treec7361b29cf629171b4da8e51cfd1074f67d814a7 /Modules/cPickle.c
parentaaa2f1dea706daf2a5f431d97a3e3120dba652d2 (diff)
downloadcpython-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 'Modules/cPickle.c')
-rw-r--r--Modules/cPickle.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index 6af99ba..865541f 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -339,7 +339,7 @@ typedef struct Picklerobject {
int fast; /* Fast mode doesn't save in memo, don't use if circ ref */
int nesting;
- int (*write_func)(struct Picklerobject *, char *, int);
+ int (*write_func)(struct Picklerobject *, const char *, int);
char *write_buf;
int buf_size;
PyObject *dispatch_table;
@@ -417,7 +417,7 @@ cPickle_ErrFormat(PyObject *ErrType, char *stringformat, char *format, ...)
}
static int
-write_file(Picklerobject *self, char *s, int n)
+write_file(Picklerobject *self, const char *s, int n)
{
size_t nbyteswritten;
@@ -437,7 +437,7 @@ write_file(Picklerobject *self, char *s, int n)
}
static int
-write_cStringIO(Picklerobject *self, char *s, int n)
+write_cStringIO(Picklerobject *self, const char *s, int n)
{
if (s == NULL) {
return 0;
@@ -451,14 +451,14 @@ write_cStringIO(Picklerobject *self, char *s, int n)
}
static int
-write_none(Picklerobject *self, char *s, int n)
+write_none(Picklerobject *self, const char *s, int n)
{
if (s == NULL) return 0;
return n;
}
static int
-write_other(Picklerobject *self, char *s, int n)
+write_other(Picklerobject *self, const char *s, int n)
{
PyObject *py_str = 0, *junk = 0;
@@ -669,7 +669,7 @@ readline_other(Unpicklerobject *self, char **s)
* The caller is responsible for free()'ing the return value.
*/
static char *
-pystrndup(char *s, int n)
+pystrndup(const char *s, int n)
{
char *r = (char *)malloc(n+1);
if (r == NULL)
@@ -945,7 +945,7 @@ save_none(Picklerobject *self, PyObject *args)
static int
save_bool(Picklerobject *self, PyObject *args)
{
- static char *buf[2] = {FALSE, TRUE};
+ static const char *buf[2] = {FALSE, TRUE};
static char len[2] = {sizeof(FALSE)-1, sizeof(TRUE)-1};
long l = PyInt_AS_LONG((PyIntObject *)args);
@@ -2858,7 +2858,7 @@ newPicklerobject(PyObject *file, int proto)
static PyObject *
get_Pickler(PyObject *self, PyObject *args, PyObject *kwds)
{
- static char *kwlist[] = {"file", "protocol", NULL};
+ static const char *kwlist[] = {"file", "protocol", NULL};
PyObject *file = NULL;
int proto = 0;
@@ -5378,7 +5378,7 @@ Unpickler_setattr(Unpicklerobject *self, char *name, PyObject *value)
static PyObject *
cpm_dump(PyObject *self, PyObject *args, PyObject *kwds)
{
- static char *kwlist[] = {"obj", "file", "protocol", NULL};
+ static const char *kwlist[] = {"obj", "file", "protocol", NULL};
PyObject *ob, *file, *res = NULL;
Picklerobject *pickler = 0;
int proto = 0;
@@ -5407,7 +5407,7 @@ cpm_dump(PyObject *self, PyObject *args, PyObject *kwds)
static PyObject *
cpm_dumps(PyObject *self, PyObject *args, PyObject *kwds)
{
- static char *kwlist[] = {"obj", "protocol", NULL};
+ static const char *kwlist[] = {"obj", "protocol", NULL};
PyObject *ob, *file = 0, *res = NULL;
Picklerobject *pickler = 0;
int proto = 0;