|
1 | | -// UUID accelerator base type. |
| 1 | +/* |
| 2 | + * Python UUID module: |
| 3 | + * - wraps libuuid or Windows rpcrt4.dll. |
| 4 | + * - implements fast version of the uuid.py:UUID class. |
| 5 | + * - re-implements uuid4() and uuid7() functions with improved performance |
| 6 | + * by virtue of them being implemented in C and better entropy fetching |
| 7 | + * strategy. |
| 8 | + * |
| 9 | + * DCE compatible Universally Unique Identifier library. |
| 10 | + */ |
2 | 11 |
|
3 | 12 | #ifndef Py_BUILD_CORE_BUILTIN |
4 | 13 | # define Py_BUILD_CORE_MODULE 1 |
@@ -137,6 +146,8 @@ typedef struct uuidobject { |
137 | 146 | // Bytes 8-9: clock_seq_and_variant (16 bits) |
138 | 147 | // Bytes 10-15: node (48 bits) |
139 | 148 | // |
| 149 | +// Note that the time attributes are only relevant to versions 1, 6 and 7. |
| 150 | +// |
140 | 151 | // Version field is located in byte 6; most significant 4 bits: |
141 | 152 | // |
142 | 153 | // Variant field is located in byte 8; most significant variable bits: |
@@ -486,8 +497,7 @@ _uuid_UUID___init___impl(uuidobject *self, PyObject *hex, Py_buffer *bytes, |
486 | 497 | if (validated == NULL) { |
487 | 498 | return -1; |
488 | 499 | } |
489 | | - Py_CLEAR(self->is_safe); |
490 | | - self->is_safe = validated; // reuse reference |
| 500 | + Py_XSETREF(self->is_safe, validated); |
491 | 501 | } |
492 | 502 |
|
493 | 503 | return 0; |
@@ -734,12 +744,12 @@ extract_field( |
734 | 744 | int overflow; |
735 | 745 | uint64_t value = PyLong_AsLongLongAndOverflow(field, &overflow); |
736 | 746 | if (overflow || (value == (uint64_t)-1 && PyErr_Occurred())) { |
737 | | - PyErr_Format(PyExc_ValueError, "%s", error_msg); |
| 747 | + PyErr_SetString(PyExc_ValueError, error_msg); |
738 | 748 | goto fail; |
739 | 749 | } |
740 | 750 |
|
741 | 751 | if (value > max_value) { |
742 | | - PyErr_Format(PyExc_ValueError, "%s", error_msg); |
| 752 | + PyErr_SetString(PyExc_ValueError, error_msg); |
743 | 753 | goto fail; |
744 | 754 | } |
745 | 755 |
|
@@ -767,14 +777,16 @@ from_fields(uuidobject *self, PyObject *fields) |
767 | 777 | return -1; |
768 | 778 | } |
769 | 779 |
|
770 | | - #define EXTRACT_FIELD(field_num, max_value, error_msg, type, name) \ |
| 780 | +# define EXTRACT_FIELD(field_num, max_value, error_msg, type, name) \ |
771 | 781 | type name; \ |
772 | | - uint64_t name##_extracted; \ |
773 | | - if (extract_field(fields, field_num, max_value, error_msg, \ |
774 | | - &(name##_extracted)) < 0) { \ |
775 | | - return -1; \ |
776 | | - } \ |
777 | | - name = (type)name##_extracted; |
| 782 | + do { \ |
| 783 | + uint64_t name##_extracted; \ |
| 784 | + if (extract_field(fields, field_num, max_value, error_msg, \ |
| 785 | + &(name##_extracted)) < 0) { \ |
| 786 | + return -1; \ |
| 787 | + } \ |
| 788 | + name = (type)name##_extracted; \ |
| 789 | + } while(0) |
778 | 790 |
|
779 | 791 | EXTRACT_FIELD( |
780 | 792 | 0, (1ULL << 32) - 1, "field 1 out of range (need a 32-bit value)", |
|
0 commit comments