@@ -168,11 +168,6 @@ typedef struct {
168168
169169 PyObject * uint128_max ;
170170
171- PyObject * reserved_ncs ;
172- PyObject * rfc_4122 ;
173- PyObject * reserved_microsoft ;
174- PyObject * reserved_future ;
175-
176171 PyObject * random_func ;
177172 PyObject * random_size_int ;
178173 PyObject * time_func ;
@@ -1045,6 +1040,19 @@ Uuid_get_hex(PyObject *o, void *closure)
10451040 return PyUnicode_FromStringAndSize (hex , 32 );
10461041}
10471042
1043+ static PyObject *
1044+ get_variant_marker (uuid_state * state , const char * name )
1045+ {
1046+ PyObject * mod = PyImport_ImportModule ("uuid" );
1047+ if (mod == NULL ) {
1048+ return NULL ;
1049+ }
1050+
1051+ PyObject * ret = PyObject_GetAttrString (mod , name );
1052+ Py_DECREF (mod );
1053+ return ret ;
1054+ }
1055+
10481056static PyObject *
10491057Uuid_get_variant (PyObject * o , void * closure )
10501058{
@@ -1056,23 +1064,23 @@ Uuid_get_variant(PyObject *o, void *closure)
10561064 // xxx - three high bits of variant_byte are unknown
10571065 if (!(variant_byte & 0x80 )) { // & 0b1000_0000
10581066 // 0xx - RESERVED_NCS
1059- return Py_NewRef (state -> reserved_ncs );
1067+ return get_variant_marker (state , "RESERVED_NCS" );
10601068 }
10611069
10621070 // 1xx -- we know that high bit must be 1
10631071 if (!(variant_byte & 0x40 )) { // & 0b0100_0000
10641072 // 10x - RFC_4122
1065- return Py_NewRef (state -> rfc_4122 );
1073+ return get_variant_marker (state , "RFC_4122" );
10661074 }
10671075
10681076 // 11x -- we know that two high bits are 1
10691077 if (!(variant_byte & 0x20 )) { // & 0b0010_0000
10701078 // 110 - RESERVED_MICROSOFT
1071- return Py_NewRef (state -> reserved_microsoft );
1079+ return get_variant_marker (state , "RESERVED_MICROSOFT" );
10721080 }
10731081
10741082 // 111 -- we know that all three high bits are 1 - RESERVED_FUTURE
1075- return Py_NewRef (state -> reserved_future );
1083+ return get_variant_marker (state , "RESERVED_FUTURE" );
10761084}
10771085
10781086static int
@@ -1693,10 +1701,6 @@ module_traverse(PyObject *mod, visitproc visit, void *arg)
16931701 Py_VISIT (state -> UuidType );
16941702 Py_VISIT (state -> safe_uuid );
16951703 Py_VISIT (state -> uint128_max );
1696- Py_VISIT (state -> reserved_ncs );
1697- Py_VISIT (state -> rfc_4122 );
1698- Py_VISIT (state -> reserved_microsoft );
1699- Py_VISIT (state -> reserved_future );
17001704 Py_VISIT (state -> random_func );
17011705 Py_VISIT (state -> time_func );
17021706 Py_VISIT (state -> random_size_int );
@@ -1711,10 +1715,6 @@ module_clear(PyObject *mod)
17111715 Py_CLEAR (state -> UuidType );
17121716 Py_CLEAR (state -> safe_uuid );
17131717 Py_CLEAR (state -> uint128_max );
1714- Py_CLEAR (state -> reserved_ncs );
1715- Py_CLEAR (state -> rfc_4122 );
1716- Py_CLEAR (state -> reserved_microsoft );
1717- Py_CLEAR (state -> reserved_future );
17181718 Py_CLEAR (state -> random_func );
17191719 Py_CLEAR (state -> time_func );
17201720 Py_CLEAR (state -> random_size_int );
@@ -1799,26 +1799,6 @@ uuid_exec(PyObject *module)
17991799 goto fail ;
18001800 }
18011801
1802- state -> reserved_ncs = PyObject_GetAttrString (uuid_mod , "RESERVED_NCS" );
1803- if (state -> reserved_ncs == NULL ) {
1804- goto fail ;
1805- }
1806-
1807- state -> rfc_4122 = PyObject_GetAttrString (uuid_mod , "RFC_4122" );
1808- if (state -> rfc_4122 == NULL ) {
1809- goto fail ;
1810- }
1811-
1812- state -> reserved_microsoft = PyObject_GetAttrString (uuid_mod , "RESERVED_MICROSOFT" );
1813- if (state -> reserved_microsoft == NULL ) {
1814- goto fail ;
1815- }
1816-
1817- state -> reserved_future = PyObject_GetAttrString (uuid_mod , "RESERVED_FUTURE" );
1818- if (state -> reserved_future == NULL ) {
1819- goto fail ;
1820- }
1821-
18221802 state -> last_timestamp_v7 = 0 ;
18231803 state -> last_timestamp_v7_init = 0 ;
18241804 state -> last_counter_v7 = 0 ;
0 commit comments