@@ -92,7 +92,10 @@ static PyMemberDef DB_members[] = {
9292
9393/* forward declaration */
9494static PyTypeObject UCD_Type ;
95- #define UCD_Check (o ) Py_IS_TYPE(o, &UCD_Type)
95+
96+ // Check if self is an instance of UCD_Type.
97+ // Return 0 if self is NULL (when the PyCapsule C API is used).
98+ #define UCD_Check (self , ucd_type ) (self != NULL && Py_IS_TYPE(self, ucd_type))
9699
97100static PyObject *
98101new_previous_version (const char * name , const change_record * (* getrecord )(Py_UCS4 ),
@@ -135,7 +138,7 @@ unicodedata_UCD_decimal_impl(PyObject *self, int chr,
135138 long rc ;
136139 Py_UCS4 c = (Py_UCS4 )chr ;
137140
138- if (self && UCD_Check (self )) {
141+ if (UCD_Check (self , & UCD_Type )) {
139142 const change_record * old = get_old_record (self , c );
140143 if (old -> category_changed == 0 ) {
141144 /* unassigned */
@@ -223,7 +226,7 @@ unicodedata_UCD_numeric_impl(PyObject *self, int chr,
223226 double rc ;
224227 Py_UCS4 c = (Py_UCS4 )chr ;
225228
226- if (self && UCD_Check (self )) {
229+ if (UCD_Check (self , & UCD_Type )) {
227230 const change_record * old = get_old_record (self , c );
228231 if (old -> category_changed == 0 ) {
229232 /* unassigned */
@@ -268,7 +271,7 @@ unicodedata_UCD_category_impl(PyObject *self, int chr)
268271 int index ;
269272 Py_UCS4 c = (Py_UCS4 )chr ;
270273 index = (int ) _getrecord_ex (c )-> category ;
271- if (self && UCD_Check (self )) {
274+ if (UCD_Check (self , & UCD_Type )) {
272275 const change_record * old = get_old_record (self , c );
273276 if (old -> category_changed != 0xFF )
274277 index = old -> category_changed ;
@@ -295,7 +298,7 @@ unicodedata_UCD_bidirectional_impl(PyObject *self, int chr)
295298 int index ;
296299 Py_UCS4 c = (Py_UCS4 )chr ;
297300 index = (int ) _getrecord_ex (c )-> bidirectional ;
298- if (self && UCD_Check (self )) {
301+ if (UCD_Check (self , & UCD_Type )) {
299302 const change_record * old = get_old_record (self , c );
300303 if (old -> category_changed == 0 )
301304 index = 0 ; /* unassigned */
@@ -324,7 +327,7 @@ unicodedata_UCD_combining_impl(PyObject *self, int chr)
324327 int index ;
325328 Py_UCS4 c = (Py_UCS4 )chr ;
326329 index = (int ) _getrecord_ex (c )-> combining ;
327- if (self && UCD_Check (self )) {
330+ if (UCD_Check (self , & UCD_Type )) {
328331 const change_record * old = get_old_record (self , c );
329332 if (old -> category_changed == 0 )
330333 index = 0 ; /* unassigned */
@@ -352,7 +355,7 @@ unicodedata_UCD_mirrored_impl(PyObject *self, int chr)
352355 int index ;
353356 Py_UCS4 c = (Py_UCS4 )chr ;
354357 index = (int ) _getrecord_ex (c )-> mirrored ;
355- if (self && UCD_Check (self )) {
358+ if (UCD_Check (self , & UCD_Type )) {
356359 const change_record * old = get_old_record (self , c );
357360 if (old -> category_changed == 0 )
358361 index = 0 ; /* unassigned */
@@ -379,7 +382,7 @@ unicodedata_UCD_east_asian_width_impl(PyObject *self, int chr)
379382 int index ;
380383 Py_UCS4 c = (Py_UCS4 )chr ;
381384 index = (int ) _getrecord_ex (c )-> east_asian_width ;
382- if (self && UCD_Check (self )) {
385+ if (UCD_Check (self , & UCD_Type )) {
383386 const change_record * old = get_old_record (self , c );
384387 if (old -> category_changed == 0 )
385388 index = 0 ; /* unassigned */
@@ -413,7 +416,7 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr)
413416
414417 code = (int )c ;
415418
416- if (self && UCD_Check (self )) {
419+ if (UCD_Check (self , & UCD_Type )) {
417420 const change_record * old = get_old_record (self , c );
418421 if (old -> category_changed == 0 )
419422 return PyUnicode_FromString ("" ); /* unassigned */
@@ -460,7 +463,7 @@ get_decomp_record(PyObject *self, Py_UCS4 code, int *index, int *prefix, int *co
460463{
461464 if (code >= 0x110000 ) {
462465 * index = 0 ;
463- } else if (self && UCD_Check (self ) &&
466+ } else if (UCD_Check (self , & UCD_Type ) &&
464467 get_old_record (self , code )-> category_changed == 0 ) {
465468 /* unassigned in old version */
466469 * index = 0 ;
@@ -558,7 +561,7 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
558561 continue ;
559562 }
560563 /* normalization changes */
561- if (self && UCD_Check (self )) {
564+ if (UCD_Check (self , & UCD_Type )) {
562565 Py_UCS4 value = ((PreviousDBVersion * )self )-> normalization (code );
563566 if (value != 0 ) {
564567 stack [stackptr ++ ] = value ;
@@ -799,7 +802,7 @@ is_normalized_quickcheck(PyObject *self, PyObject *input,
799802{
800803 /* An older version of the database is requested, quickchecks must be
801804 disabled. */
802- if (self && UCD_Check (self ))
805+ if (UCD_Check (self , & UCD_Type ))
803806 return NO ;
804807
805808 Py_ssize_t i , len ;
@@ -1066,7 +1069,7 @@ _getucname(PyObject *self, Py_UCS4 code, char* buffer, int buflen,
10661069 if (!with_alias_and_seq && (IS_ALIAS (code ) || IS_NAMED_SEQ (code )))
10671070 return 0 ;
10681071
1069- if (self && UCD_Check (self )) {
1072+ if (UCD_Check (self , & UCD_Type )) {
10701073 /* in 3.2.0 there are no aliases and named sequences */
10711074 const change_record * old ;
10721075 if (IS_ALIAS (code ) || IS_NAMED_SEQ (code ))
0 commit comments