Skip to content

Commit e51da7b

Browse files
committed
Use PyObject* in getters
1 parent 8a02c85 commit e51da7b

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

Modules/_uuidmodule.c

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -925,23 +925,25 @@ Uuid_dealloc(PyObject *obj)
925925

926926

927927
static PyObject *
928-
Uuid_get_int(uuidobject *self, void *closure)
928+
Uuid_get_int(PyObject *o, void *closure)
929929
{
930-
return get_int(self);
930+
return get_int((uuidobject *)o);
931931
}
932932

933933
static PyObject *
934-
Uuid_get_is_safe(uuidobject *self, void *closure)
934+
Uuid_get_is_safe(PyObject *o, void *closure)
935935
{
936+
uuidobject *self = (uuidobject *)o;
936937
if (self->is_safe == NULL) {
937938
Py_RETURN_NONE;
938939
}
939940
return Py_NewRef(self->is_safe);
940941
}
941942

942943
static PyObject *
943-
Uuid_get_hex(uuidobject *self, void *closure)
944+
Uuid_get_hex(PyObject *o, void *closure)
944945
{
946+
uuidobject *self = (uuidobject *)o;
945947
char hex[32];
946948
for (int i = 0; i < 16; i++) {
947949
byte_to_hex(self->bytes[i], &hex[i * 2]);
@@ -950,8 +952,9 @@ Uuid_get_hex(uuidobject *self, void *closure)
950952
}
951953

952954
static PyObject *
953-
Uuid_get_variant(uuidobject *self, void *closure)
955+
Uuid_get_variant(PyObject *o, void *closure)
954956
{
957+
uuidobject *self = (uuidobject *)o;
955958
uuid_state *state = get_uuid_state_by_cls(Py_TYPE(self));
956959

957960
uint8_t variant_byte = self->bytes[8];
@@ -997,8 +1000,9 @@ get_version(uuidobject *self)
9971000
}
9981001

9991002
static PyObject *
1000-
Uuid_get_version(uuidobject *self, void *closure)
1003+
Uuid_get_version(PyObject *o, void *closure)
10011004
{
1005+
uuidobject *self = (uuidobject *)o;
10021006
if (!is_rfc_4122(self)) {
10031007
Py_RETURN_NONE;
10041008
}
@@ -1052,38 +1056,45 @@ get_node(uuidobject *self)
10521056
}
10531057

10541058
static PyObject *
1055-
Uuid_get_time_low(uuidobject *self, void *closure)
1059+
Uuid_get_time_low(PyObject *o, void *closure)
10561060
{
1061+
uuidobject *self = (uuidobject *)o;
10571062
return PyLong_FromUnsignedLong(get_time_low(self));
10581063
}
10591064

10601065
static PyObject *
1061-
Uuid_get_time_mid(uuidobject *self, void *closure)
1066+
Uuid_get_time_mid(PyObject *o, void *closure)
10621067
{
1068+
uuidobject *self = (uuidobject *)o;
10631069
return PyLong_FromUnsignedLong(get_time_mid(self));
10641070
}
10651071

10661072
static PyObject *
1067-
Uuid_get_time_hi_version(uuidobject *self, void *closure)
1073+
Uuid_get_time_hi_version(PyObject *o, void *closure)
10681074
{
1075+
uuidobject *self = (uuidobject *)o;
10691076
return PyLong_FromUnsignedLong(get_time_hi_version(self));
10701077
}
10711078

10721079
static PyObject *
1073-
Uuid_get_clock_seq_hi_variant(uuidobject *self, void *closure)
1080+
Uuid_get_clock_seq_hi_variant(PyObject *o, void *closure)
10741081
{
1082+
uuidobject *self = (uuidobject *)o;
10751083
return PyLong_FromUnsignedLong(get_clock_seq_hi_variant(self));
10761084
}
10771085

10781086
static PyObject *
1079-
Uuid_get_clock_seq_low(uuidobject *self, void *closure)
1087+
Uuid_get_clock_seq_low(PyObject *o, void *closure)
10801088
{
1089+
uuidobject *self = (uuidobject *)o;
10811090
return PyLong_FromUnsignedLong(get_clock_seq_low(self));
10821091
}
10831092

10841093
static PyObject *
1085-
Uuid_get_time(uuidobject *self, void *closure)
1094+
Uuid_get_time(PyObject *o, void *closure)
10861095
{
1096+
uuidobject *self = (uuidobject *)o;
1097+
10871098
long version = get_version(self);
10881099

10891100
if (version == 6) {
@@ -1125,29 +1136,33 @@ Uuid_get_time(uuidobject *self, void *closure)
11251136
}
11261137

11271138
static PyObject *
1128-
Uuid_get_clock_seq(uuidobject *self, void *closure)
1139+
Uuid_get_clock_seq(PyObject *o, void *closure)
11291140
{
1141+
uuidobject *self = (uuidobject *)o;
11301142
// clock_seq_hi_variant (byte 8) & 0x3f, then clock_seq_low (byte 9)
11311143
uint16_t clock_seq = ((uint16_t)(get_clock_seq_hi_variant(self) & 0x3f) << 8) |
11321144
((uint16_t)get_clock_seq_low(self));
11331145
return PyLong_FromUnsignedLong(clock_seq);
11341146
}
11351147

11361148
static PyObject *
1137-
Uuid_get_node(uuidobject *self, void *closure)
1149+
Uuid_get_node(PyObject *o, void *closure)
11381150
{
1151+
uuidobject *self = (uuidobject *)o;
11391152
return PyLong_FromUnsignedLongLong(get_node(self));
11401153
}
11411154

11421155
static PyObject *
1143-
Uuid_get_bytes(uuidobject *self, void *closure)
1156+
Uuid_get_bytes(PyObject *o, void *closure)
11441157
{
1158+
uuidobject *self = (uuidobject *)o;
11451159
return PyBytes_FromStringAndSize((const char *)self->bytes, 16);
11461160
}
11471161

11481162
static PyObject *
1149-
Uuid_get_bytes_le(uuidobject *self, void *closure)
1163+
Uuid_get_bytes_le(PyObject *o, void *closure)
11501164
{
1165+
uuidobject *self = (uuidobject *)o;
11511166
// UUID fields in little-endian order need to be byte-swapped:
11521167
// - time_low (4 bytes) - reversed
11531168
// - time_mid (2 bytes) - reversed
@@ -1177,8 +1192,9 @@ Uuid_get_bytes_le(uuidobject *self, void *closure)
11771192
}
11781193

11791194
static PyObject *
1180-
Uuid_get_fields(uuidobject *self, void *closure)
1195+
Uuid_get_fields(PyObject *o, void *closure)
11811196
{
1197+
uuidobject *self = (uuidobject *)o;
11821198
uint32_t time_low = get_time_low(self);
11831199
uint16_t time_mid = get_time_mid(self);
11841200
uint16_t time_hi_version = get_time_hi_version(self);
@@ -1324,8 +1340,9 @@ Uuid_setattr(PyObject *self, PyObject *name, PyObject *value)
13241340
}
13251341

13261342
static PyObject *
1327-
Uuid_get_urn(uuidobject *self, void *closure)
1343+
Uuid_get_urn(PyObject *o, void *closure)
13281344
{
1345+
uuidobject *self = (uuidobject *)o;
13291346
PyObject *str_obj = Uuid_str((PyObject *)self);
13301347
if (str_obj == NULL) {
13311348
return NULL;
@@ -1337,9 +1354,9 @@ Uuid_get_urn(uuidobject *self, void *closure)
13371354
}
13381355

13391356
static Py_hash_t
1340-
Uuid_hash(PyObject *self)
1357+
Uuid_hash(PyObject *o)
13411358
{
1342-
uuidobject *uuid = (uuidobject *)self;
1359+
uuidobject *uuid = (uuidobject *)o;
13431360
if (uuid->cached_hash != -1) {
13441361
// UUIDs are very often used in dicts/sets, so it makes
13451362
// sense to cache the computed hash (like we do for str)
@@ -1387,30 +1404,28 @@ _uuid_UUID__from_int_impl(PyTypeObject *type, PyObject *value)
13871404
}
13881405

13891406
static PyGetSetDef Uuid_getset[] = {
1390-
{"int", (getter)Uuid_get_int, NULL, "UUID as a 128-bit integer", NULL},
1391-
{"is_safe", (getter)Uuid_get_is_safe, NULL, "UUID safety status", NULL},
1392-
{"fields", (getter)Uuid_get_fields, NULL, "UUID as a 6-tuple", NULL},
1393-
{"hex", (getter)Uuid_get_hex, NULL, "UUID as a 32-character hex string", NULL},
1394-
{"urn", (getter)Uuid_get_urn, NULL, "UUID as a URN", NULL},
1395-
{"variant", (getter)Uuid_get_variant, NULL, "UUID variant", NULL},
1396-
{"version", (getter)Uuid_get_version, NULL, "UUID version", NULL},
1397-
{"time_low", (getter)Uuid_get_time_low, NULL, "Time low field (32 bits)", NULL},
1398-
{"time_mid", (getter)Uuid_get_time_mid, NULL, "Time mid field (16 bits)", NULL},
1399-
{"bytes", (getter)Uuid_get_bytes, NULL, "UUID as a 16-byte string", NULL},
1400-
{"bytes_le", (getter)Uuid_get_bytes_le, NULL,
1407+
{"int", Uuid_get_int, NULL, "UUID as a 128-bit integer", NULL},
1408+
{"is_safe", Uuid_get_is_safe, NULL, "UUID safety status", NULL},
1409+
{"fields", Uuid_get_fields, NULL, "UUID as a 6-tuple", NULL},
1410+
{"hex", Uuid_get_hex, NULL, "UUID as a 32-character hex string", NULL},
1411+
{"urn", Uuid_get_urn, NULL, "UUID as a URN", NULL},
1412+
{"variant", Uuid_get_variant, NULL, "UUID variant", NULL},
1413+
{"version", Uuid_get_version, NULL, "UUID version", NULL},
1414+
{"time_low", Uuid_get_time_low, NULL, "Time low field (32 bits)", NULL},
1415+
{"time_mid", Uuid_get_time_mid, NULL, "Time mid field (16 bits)", NULL},
1416+
{"bytes", Uuid_get_bytes, NULL, "UUID as a 16-byte string", NULL},
1417+
{"bytes_le", Uuid_get_bytes_le, NULL,
14011418
"UUID as a 16-byte string in little-endian byte order", NULL},
1402-
{"time_hi_version", (getter)Uuid_get_time_hi_version, NULL,
1419+
{"time_hi_version", Uuid_get_time_hi_version, NULL,
14031420
"Time high and version field (16 bits)", NULL},
1404-
{"clock_seq_hi_variant", (getter)Uuid_get_clock_seq_hi_variant, NULL,
1421+
{"clock_seq_hi_variant", Uuid_get_clock_seq_hi_variant, NULL,
14051422
"Clock sequence high and variant field (8 bits)", NULL},
1406-
{"clock_seq_low", (getter)Uuid_get_clock_seq_low, NULL,
1423+
{"clock_seq_low", Uuid_get_clock_seq_low, NULL,
14071424
"Clock sequence low field (8 bits)", NULL},
1408-
{"time", (getter)Uuid_get_time, NULL,
1425+
{"time", Uuid_get_time, NULL,
14091426
"Time field (60 bits for v1/v6, 48 bits for v7)", NULL},
1410-
{"clock_seq", (getter)Uuid_get_clock_seq, NULL,
1411-
"Clock sequence field (14 bits)", NULL},
1412-
{"node", (getter)Uuid_get_node, NULL,
1413-
"Node field (48 bits)", NULL},
1427+
{"clock_seq", Uuid_get_clock_seq, NULL, "Clock sequence field (14 bits)", NULL},
1428+
{"node", Uuid_get_node, NULL, "Node field (48 bits)", NULL},
14141429
{NULL}
14151430
};
14161431

0 commit comments

Comments
 (0)