diff --git a/src/pyconstraint.c b/src/pyconstraint.c index 7845eab..8a8ce0a 100644 --- a/src/pyconstraint.c +++ b/src/pyconstraint.c @@ -95,25 +95,25 @@ PyObject *_ped_Constraint_richcompare(_ped_Constraint *a, PyObject *b, int op) { PyObject *_ped_Constraint_str(_ped_Constraint *self) { char *ret = NULL; - char *start_align = NULL, *end_align = NULL; - char *start_range = NULL, *end_range = NULL; + const char *start_align = NULL, *end_align = NULL; + const char *start_range = NULL, *end_range = NULL; - start_align = (char *) PyUnicode_AsUTF8(_ped_Alignment_Type_obj.tp_repr(self->start_align)); + start_align = PyUnicode_AsUTF8(_ped_Alignment_Type_obj.tp_repr(self->start_align)); if (start_align == NULL) { return NULL; } - end_align = (char *) PyUnicode_AsUTF8(_ped_Alignment_Type_obj.tp_repr(self->end_align)); + end_align = PyUnicode_AsUTF8(_ped_Alignment_Type_obj.tp_repr(self->end_align)); if (end_align == NULL) { return NULL; } - start_range = (char *) PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->start_range)); + start_range = PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->start_range)); if (start_range == NULL) { return NULL; } - end_range = (char *) PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->end_range)); + end_range = PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->end_range)); if (end_range == NULL) { return NULL; } diff --git a/src/pydevice.c b/src/pydevice.c index 20f492e..6c09d08 100644 --- a/src/pydevice.c +++ b/src/pydevice.c @@ -186,14 +186,14 @@ PyObject *_ped_Device_richcompare(_ped_Device *a, PyObject *b, int op) { PyObject *_ped_Device_str(_ped_Device *self) { char *ret = NULL; - char *hw_geom = NULL, *bios_geom = NULL; + const char *hw_geom = NULL, *bios_geom = NULL; - hw_geom = (char *) PyUnicode_AsUTF8(_ped_CHSGeometry_Type_obj.tp_repr(self->hw_geom)); + hw_geom = PyUnicode_AsUTF8(_ped_CHSGeometry_Type_obj.tp_repr(self->hw_geom)); if (hw_geom == NULL) { return NULL; } - bios_geom = (char *) PyUnicode_AsUTF8(_ped_CHSGeometry_Type_obj.tp_repr(self->bios_geom)); + bios_geom = PyUnicode_AsUTF8(_ped_CHSGeometry_Type_obj.tp_repr(self->bios_geom)); if (bios_geom == NULL) { return NULL; } diff --git a/src/pydisk.c b/src/pydisk.c index 0b21141..49c5184 100644 --- a/src/pydisk.c +++ b/src/pydisk.c @@ -98,7 +98,7 @@ PyObject *_ped_Partition_richcompare(_ped_Partition *a, PyObject *b, int op) { PyObject *_ped_Partition_str(_ped_Partition *self) { char *ret = NULL; - char *disk = NULL, *fs_type = NULL, *geom = NULL; + const char *disk = NULL, *fs_type = NULL, *geom = NULL; disk = (char *) PyUnicode_AsUTF8(_ped_Disk_Type_obj.tp_repr(self->disk)); if (disk == NULL) { @@ -346,7 +346,7 @@ PyObject *_ped_Disk_richcompare(_ped_Disk *a, PyObject *b, int op) { PyObject *_ped_Disk_str(_ped_Disk *self) { char *ret = NULL; - char *dev = NULL, *type = NULL; + const char *dev = NULL, *type = NULL; dev = (char *) PyUnicode_AsUTF8(_ped_Device_Type_obj.tp_repr(self->dev)); if (dev == NULL) { diff --git a/src/pyfilesys.c b/src/pyfilesys.c index 53abd90..637a61d 100644 --- a/src/pyfilesys.c +++ b/src/pyfilesys.c @@ -171,14 +171,14 @@ PyObject *_ped_FileSystem_richcompare(_ped_FileSystem *a, PyObject *b, int op) { PyObject *_ped_FileSystem_str(_ped_FileSystem *self) { char *ret = NULL; - char *type = NULL, *geom = NULL; + const char *type = NULL, *geom = NULL; - type = (char *) PyUnicode_AsUTF8(_ped_FileSystem_Type_obj.tp_repr(self->type)); + type = PyUnicode_AsUTF8(_ped_FileSystem_Type_obj.tp_repr(self->type)); if (type == NULL) { return NULL; } - geom = (char *) PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->geom)); + geom = PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->geom)); if (geom == NULL) { return NULL; } diff --git a/src/pygeom.c b/src/pygeom.c index 811e6f5..a4263c0 100644 --- a/src/pygeom.c +++ b/src/pygeom.c @@ -86,9 +86,9 @@ PyObject *_ped_Geometry_richcompare(_ped_Geometry *a, PyObject *b, int op) { PyObject *_ped_Geometry_str(_ped_Geometry *self) { char *ret = NULL; - char *dev = NULL; + const char *dev = NULL; - dev = (char *) PyUnicode_AsUTF8(_ped_Device_Type_obj.tp_repr(self->dev)); + dev = PyUnicode_AsUTF8(_ped_Device_Type_obj.tp_repr(self->dev)); if (dev == NULL) { return NULL; } diff --git a/src/pytimer.c b/src/pytimer.c index e3e9863..4f7f325 100644 --- a/src/pytimer.c +++ b/src/pytimer.c @@ -188,19 +188,21 @@ int _ped_Timer_set(_ped_Timer *self, PyObject *value, void *closure) { return -1; } } else if (!strcmp(member, "state_name")) { - self->state_name = (char *) PyUnicode_AsUTF8(value); + const char *state_name = PyUnicode_AsUTF8(value); if (PyErr_Occurred()) { return -1; } /* self->state_name now points to the internal buffer of a PyUnicode obj * which may be freed when its refcount drops to zero, so strdup it. */ - if (self->state_name) { - self->state_name = strdup(self->state_name); + if (state_name) { + self->state_name = strdup(state_name); if (!self->state_name) { PyErr_NoMemory(); return -2; } + } else { + self->state_name = NULL; } } else { PyErr_Format(PyExc_AttributeError, "_ped.Timer object has no attribute %s", member);