summaryrefslogtreecommitdiffstats
path: root/Modules/datetimemodule.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/datetimemodule.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/datetimemodule.c')
-rw-r--r--Modules/datetimemodule.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 6b44fe5..8a6fae2 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1073,10 +1073,10 @@ append_keyword_tzinfo(PyObject *repr, PyObject *tzinfo)
static PyObject *
format_ctime(PyDateTime_Date *date, int hours, int minutes, int seconds)
{
- static char *DayNames[] = {
+ static const char *DayNames[] = {
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
};
- static char *MonthNames[] = {
+ static const char *MonthNames[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
@@ -1891,7 +1891,7 @@ delta_new(PyTypeObject *type, PyObject *args, PyObject *kw)
PyObject *y = NULL; /* temp sum of microseconds */
double leftover_us = 0.0;
- static char *keywords[] = {
+ static const char *keywords[] = {
"days", "seconds", "microseconds", "milliseconds",
"minutes", "hours", "weeks", NULL
};
@@ -2194,7 +2194,7 @@ static PyGetSetDef date_getset[] = {
/* Constructors. */
-static char *date_kws[] = {"year", "month", "day", NULL};
+static const char *date_kws[] = {"year", "month", "day", NULL};
static PyObject *
date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
@@ -2406,7 +2406,7 @@ static PyObject *
date_repr(PyDateTime_Date *self)
{
char buffer[1028];
- char *typename;
+ const char *typename;
typename = self->ob_type->tp_name;
PyOS_snprintf(buffer, sizeof(buffer), "%s(%d, %d, %d)",
@@ -2448,7 +2448,7 @@ date_strftime(PyDateTime_Date *self, PyObject *args, PyObject *kw)
PyObject *result;
PyObject *format;
PyObject *tuple;
- static char *keywords[] = {"format", NULL};
+ static const char *keywords[] = {"format", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kw, "O!:strftime", keywords,
&PyString_Type, &format))
@@ -3028,7 +3028,7 @@ static PyGetSetDef time_getset[] = {
* Constructors.
*/
-static char *time_kws[] = {"hour", "minute", "second", "microsecond",
+static const char *time_kws[] = {"hour", "minute", "second", "microsecond",
"tzinfo", NULL};
static PyObject *
@@ -3133,7 +3133,7 @@ static PyObject *
time_repr(PyDateTime_Time *self)
{
char buffer[100];
- char *typename = self->ob_type->tp_name;
+ const char *typename = self->ob_type->tp_name;
int h = TIME_GET_HOUR(self);
int m = TIME_GET_MINUTE(self);
int s = TIME_GET_SECOND(self);
@@ -3196,7 +3196,7 @@ time_strftime(PyDateTime_Time *self, PyObject *args, PyObject *kw)
PyObject *result;
PyObject *format;
PyObject *tuple;
- static char *keywords[] = {"format", NULL};
+ static const char *keywords[] = {"format", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kw, "O!:strftime", keywords,
&PyString_Type, &format))
@@ -3548,7 +3548,7 @@ static PyGetSetDef datetime_getset[] = {
* Constructors.
*/
-static char *datetime_kws[] = {
+static const char *datetime_kws[] = {
"year", "month", "day", "hour", "minute", "second",
"microsecond", "tzinfo", NULL
};
@@ -3729,7 +3729,7 @@ datetime_now(PyObject *cls, PyObject *args, PyObject *kw)
{
PyObject *self;
PyObject *tzinfo = Py_None;
- static char *keywords[] = {"tz", NULL};
+ static const char *keywords[] = {"tz", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kw, "|O:now", keywords,
&tzinfo))
@@ -3765,7 +3765,7 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
PyObject *self;
double timestamp;
PyObject *tzinfo = Py_None;
- static char *keywords[] = {"timestamp", "tz", NULL};
+ static const char *keywords[] = {"timestamp", "tz", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kw, "d|O:fromtimestamp",
keywords, &timestamp, &tzinfo))
@@ -3843,7 +3843,7 @@ datetime_strptime(PyObject *cls, PyObject *args)
static PyObject *
datetime_combine(PyObject *cls, PyObject *args, PyObject *kw)
{
- static char *keywords[] = {"date", "time", NULL};
+ static const char *keywords[] = {"date", "time", NULL};
PyObject *date;
PyObject *time;
PyObject *result = NULL;
@@ -4027,7 +4027,7 @@ static PyObject *
datetime_repr(PyDateTime_DateTime *self)
{
char buffer[1000];
- char *typename = self->ob_type->tp_name;
+ const char *typename = self->ob_type->tp_name;
PyObject *baserepr;
if (DATE_GET_MICROSECOND(self)) {
@@ -4070,7 +4070,7 @@ static PyObject *
datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
{
char sep = 'T';
- static char *keywords[] = {"sep", NULL};
+ static const char *keywords[] = {"sep", NULL};
char buffer[100];
char *cp;
PyObject *result;
@@ -4261,7 +4261,7 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
int offset, none;
PyObject *tzinfo;
- static char *keywords[] = {"tz", NULL};
+ static const char *keywords[] = {"tz", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kw, "O!:astimezone", keywords,
&PyDateTime_TZInfoType, &tzinfo))