Skip to content

Commit 1ea427e

Browse files
committed
Adjust code to deal with compile warnings
Recent Python versions return 'const char *' to PyUnicode_asUTF8. This can give compile errors (I was using Ubuntu 20.04's default build env). Some code changes had been made to case to 'char *', but it's dangerous to discard the const and apparently insufficient to address the warning. Update the code to make use 'const char *' variables where relevant. The warnings go away. Functionality is unaffected.
1 parent ddeae8f commit 1ea427e

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
lines changed

src/pyconstraint.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,25 @@ PyObject *_ped_Constraint_richcompare(_ped_Constraint *a, PyObject *b, int op) {
9595

9696
PyObject *_ped_Constraint_str(_ped_Constraint *self) {
9797
char *ret = NULL;
98-
char *start_align = NULL, *end_align = NULL;
99-
char *start_range = NULL, *end_range = NULL;
98+
const char *start_align = NULL, *end_align = NULL;
99+
const char *start_range = NULL, *end_range = NULL;
100100

101-
start_align = (char *) PyUnicode_AsUTF8(_ped_Alignment_Type_obj.tp_repr(self->start_align));
101+
start_align = PyUnicode_AsUTF8(_ped_Alignment_Type_obj.tp_repr(self->start_align));
102102
if (start_align == NULL) {
103103
return NULL;
104104
}
105105

106-
end_align = (char *) PyUnicode_AsUTF8(_ped_Alignment_Type_obj.tp_repr(self->end_align));
106+
end_align = PyUnicode_AsUTF8(_ped_Alignment_Type_obj.tp_repr(self->end_align));
107107
if (end_align == NULL) {
108108
return NULL;
109109
}
110110

111-
start_range = (char *) PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->start_range));
111+
start_range = PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->start_range));
112112
if (start_range == NULL) {
113113
return NULL;
114114
}
115115

116-
end_range = (char *) PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->end_range));
116+
end_range = PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->end_range));
117117
if (end_range == NULL) {
118118
return NULL;
119119
}

src/pydevice.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ PyObject *_ped_Device_richcompare(_ped_Device *a, PyObject *b, int op) {
186186

187187
PyObject *_ped_Device_str(_ped_Device *self) {
188188
char *ret = NULL;
189-
char *hw_geom = NULL, *bios_geom = NULL;
189+
const char *hw_geom = NULL, *bios_geom = NULL;
190190

191-
hw_geom = (char *) PyUnicode_AsUTF8(_ped_CHSGeometry_Type_obj.tp_repr(self->hw_geom));
191+
hw_geom = PyUnicode_AsUTF8(_ped_CHSGeometry_Type_obj.tp_repr(self->hw_geom));
192192
if (hw_geom == NULL) {
193193
return NULL;
194194
}
195195

196-
bios_geom = (char *) PyUnicode_AsUTF8(_ped_CHSGeometry_Type_obj.tp_repr(self->bios_geom));
196+
bios_geom = PyUnicode_AsUTF8(_ped_CHSGeometry_Type_obj.tp_repr(self->bios_geom));
197197
if (bios_geom == NULL) {
198198
return NULL;
199199
}

src/pydisk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ PyObject *_ped_Partition_richcompare(_ped_Partition *a, PyObject *b, int op) {
9898

9999
PyObject *_ped_Partition_str(_ped_Partition *self) {
100100
char *ret = NULL;
101-
char *disk = NULL, *fs_type = NULL, *geom = NULL;
101+
const char *disk = NULL, *fs_type = NULL, *geom = NULL;
102102

103103
disk = (char *) PyUnicode_AsUTF8(_ped_Disk_Type_obj.tp_repr(self->disk));
104104
if (disk == NULL) {
@@ -345,7 +345,7 @@ PyObject *_ped_Disk_richcompare(_ped_Disk *a, PyObject *b, int op) {
345345

346346
PyObject *_ped_Disk_str(_ped_Disk *self) {
347347
char *ret = NULL;
348-
char *dev = NULL, *type = NULL;
348+
const char *dev = NULL, *type = NULL;
349349

350350
dev = (char *) PyUnicode_AsUTF8(_ped_Device_Type_obj.tp_repr(self->dev));
351351
if (dev == NULL) {

src/pyfilesys.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,14 @@ PyObject *_ped_FileSystem_richcompare(_ped_FileSystem *a, PyObject *b, int op) {
171171

172172
PyObject *_ped_FileSystem_str(_ped_FileSystem *self) {
173173
char *ret = NULL;
174-
char *type = NULL, *geom = NULL;
174+
const char *type = NULL, *geom = NULL;
175175

176-
type = (char *) PyUnicode_AsUTF8(_ped_FileSystem_Type_obj.tp_repr(self->type));
176+
type = PyUnicode_AsUTF8(_ped_FileSystem_Type_obj.tp_repr(self->type));
177177
if (type == NULL) {
178178
return NULL;
179179
}
180180

181-
geom = (char *) PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->geom));
181+
geom = PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->geom));
182182
if (geom == NULL) {
183183
return NULL;
184184
}

src/pygeom.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ PyObject *_ped_Geometry_richcompare(_ped_Geometry *a, PyObject *b, int op) {
8686

8787
PyObject *_ped_Geometry_str(_ped_Geometry *self) {
8888
char *ret = NULL;
89-
char *dev = NULL;
89+
const char *dev = NULL;
9090

91-
dev = (char *) PyUnicode_AsUTF8(_ped_Device_Type_obj.tp_repr(self->dev));
91+
dev = PyUnicode_AsUTF8(_ped_Device_Type_obj.tp_repr(self->dev));
9292
if (dev == NULL) {
9393
return NULL;
9494
}

src/pytimer.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,21 @@ int _ped_Timer_set(_ped_Timer *self, PyObject *value, void *closure) {
164164
return -1;
165165
}
166166
} else if (!strcmp(member, "state_name")) {
167-
self->state_name = (char *) PyUnicode_AsUTF8(value);
167+
const char *state_name = PyUnicode_AsUTF8(value);
168168
if (PyErr_Occurred()) {
169169
return -1;
170170
}
171171
/* self->state_name now points to the internal buffer of a PyUnicode obj
172172
* which may be freed when its refcount drops to zero, so strdup it.
173173
*/
174-
if (self->state_name) {
175-
self->state_name = strdup(self->state_name);
174+
if (state_name) {
175+
self->state_name = strdup(state_name);
176176
if (!self->state_name) {
177177
PyErr_NoMemory();
178178
return -2;
179179
}
180+
} else {
181+
self->state_name = NULL;
180182
}
181183
} else {
182184
PyErr_Format(PyExc_AttributeError, "_ped.Timer object has no attribute %s", member);

0 commit comments

Comments
 (0)