Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu fixes #86

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/pyconstraint.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/pydevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pydisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -345,7 +345,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) {
Expand Down
6 changes: 3 additions & 3 deletions src/pyfilesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pygeom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions src/pytimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,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);
Expand Down
14 changes: 7 additions & 7 deletions tests/baseclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setUp(self):
self.temp_prefix = "temp-device-"
(self.fd, self.path) = tempfile.mkstemp(prefix=self.temp_prefix)
self.f = os.fdopen(self.fd)
self.f.seek(140000)
self.f.seek(1400000)
os.write(self.fd, b"0")

def removeTempDevice(self):
Expand Down Expand Up @@ -68,11 +68,11 @@ def setUp(self):
self.temp_prefix = "temp-device-"
(self.fd, self.path,) = tempfile.mkstemp(prefix=self.temp_prefix)
self.f = os.fdopen(self.fd)
self.f.seek(140000)
self.f.seek(1400000)
iawells marked this conversation as resolved.
Show resolved Hide resolved
os.write(self.fd, b"0")
self.f.close()

os.system("mke2fs -F -q %s" % (self.path,))
assert(os.system("mke2fs -F -q %s" % (self.path,)) == 0)

self._device = _ped.device_get(self.path)
self._geometry = _ped.Geometry(self._device, 0, self._device.length - 1)
Expand Down Expand Up @@ -137,7 +137,7 @@ def closest(self, sector, a, b):
class RequiresLabeledDevice(RequiresDevice):
def setUp(self):
RequiresDevice.setUp(self)
os.system("parted -s %s mklabel msdos" % (self.path,))
assert(os.system("parted -s %s mklabel msdos" % (self.path,)) == 0)

# Base class for any test case that requires a _ped.Disk or parted.Disk.
class RequiresDisk(RequiresDevice):
Expand All @@ -161,15 +161,15 @@ def setUp(self):
self.mountpoint = None

def mkfs(self):
os.system("mkfs.ext2 -F -q %s" % self.path)
assert(os.system("mkfs.ext2 -F -q %s" % self.path) == 0)

def doMount(self):
self.mountpoint = tempfile.mkdtemp()
os.system("mount -o loop %s %s" % (self.path, self.mountpoint))
assert(os.system("mount -o loop %s %s" % (self.path, self.mountpoint)) == 0)

def removeMountpoint(self):
if self.mountpoint and os.path.exists(self.mountpoint):
os.system("umount %s" % self.mountpoint)
assert(os.system("umount %s" % self.mountpoint) == 0)
os.rmdir(self.mountpoint)

# Base class for any test case that requires a _ped.Partition.
Expand Down
16 changes: 8 additions & 8 deletions tests/test__ped_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def runTest(self):
class UnitFormatCustomByteTestCase(RequiresDevice):
def setUp(self):
RequiresDevice.setUp(self)
pr = "%f" % (47.0 / self._device.unit_get_size(_ped.UNIT_PERCENT),)
pr = "%.2f" % (47.0 / self._device.unit_get_size(_ped.UNIT_PERCENT),)
self.pairs = [(_ped.UNIT_SECTOR, '0s',),
(_ped.UNIT_BYTE, '47B',),
(_ped.UNIT_KILOBYTE, '0.05kB',),
Expand All @@ -253,7 +253,7 @@ def setUp(self):
(_ped.UNIT_COMPACT, '47.0B',),
(_ped.UNIT_CYLINDER, '0cyl',),
(_ped.UNIT_CHS, '0,0,0',),
(_ped.UNIT_PERCENT, pr[:4] + "%",),
(_ped.UNIT_PERCENT, pr + "%",),
(_ped.UNIT_KIBIBYTE, '0.05kiB',),
(_ped.UNIT_MEBIBYTE, '0.00MiB',),
(_ped.UNIT_GIBIBYTE, '0.00GiB',),
Expand All @@ -267,7 +267,7 @@ def runTest(self):
class UnitFormatByteTestCase(RequiresDevice):
def setUp(self):
RequiresDevice.setUp(self)
pr = "%f" % (47.0 / self._device.unit_get_size(_ped.UNIT_PERCENT),)
pr = "%.2f" % (47.0 / self._device.unit_get_size(_ped.UNIT_PERCENT),)
self._initialDefault = _ped.unit_get_default()
self.pairs = [(_ped.UNIT_SECTOR, '0s',),
(_ped.UNIT_BYTE, '47B',),
Expand All @@ -278,7 +278,7 @@ def setUp(self):
(_ped.UNIT_COMPACT, '47.0B',),
(_ped.UNIT_CYLINDER, '0cyl',),
(_ped.UNIT_CHS, '0,0,0',),
(_ped.UNIT_PERCENT, pr[:4] + "%",),
(_ped.UNIT_PERCENT, pr + "%",),
(_ped.UNIT_KIBIBYTE, '0.05kiB',),
(_ped.UNIT_MEBIBYTE, '0.00MiB',),
(_ped.UNIT_GIBIBYTE, '0.00GiB',),
Expand All @@ -298,7 +298,7 @@ def setUp(self):
RequiresDevice.setUp(self)
sector_size = self._device.sector_size
size = self._device.unit_get_size(_ped.UNIT_PERCENT)
pr = "%f" % ((47.0 * sector_size) / size,)
pr = "%.2f" % ((47.0 * sector_size) / size,)
self.pairs = [(_ped.UNIT_SECTOR, '47s',),
(_ped.UNIT_BYTE, '24064B',),
(_ped.UNIT_KILOBYTE, '24.1kB',),
Expand All @@ -308,7 +308,7 @@ def setUp(self):
(_ped.UNIT_COMPACT, '24.1kB',),
(_ped.UNIT_CYLINDER, '0cyl',),
(_ped.UNIT_CHS, '0,1,15',),
(_ped.UNIT_PERCENT, pr[:4] + "%",),
(_ped.UNIT_PERCENT, pr + "%",),
(_ped.UNIT_KIBIBYTE, '23.5kiB',),
(_ped.UNIT_MEBIBYTE, '0.02MiB',),
(_ped.UNIT_GIBIBYTE, '0.00GiB',),
Expand All @@ -324,7 +324,7 @@ def setUp(self):
RequiresDevice.setUp(self)
sector_size = self._device.sector_size
size = self._device.unit_get_size(_ped.UNIT_PERCENT)
pr = "%f" % ((47.0 * sector_size) / size,)
pr = "%.2f" % ((47.0 * sector_size) / size,)
self._initialDefault = _ped.unit_get_default()
self.pairs = [(_ped.UNIT_SECTOR, '47s',),
(_ped.UNIT_BYTE, '24064B',),
Expand All @@ -335,7 +335,7 @@ def setUp(self):
(_ped.UNIT_COMPACT, '24.1kB',),
(_ped.UNIT_CYLINDER, '0cyl',),
(_ped.UNIT_CHS, '0,1,15',),
(_ped.UNIT_PERCENT, pr[:4] + "%",),
(_ped.UNIT_PERCENT, pr + "%",),
(_ped.UNIT_KIBIBYTE, '23.5kiB',),
(_ped.UNIT_MEBIBYTE, '0.02MiB',),
(_ped.UNIT_GIBIBYTE, '0.00GiB',),
Expand Down