@@ -92,7 +92,10 @@ static PyMemberDef DB_members[] = {
92
92
93
93
/* forward declaration */
94
94
static 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))
96
99
97
100
static PyObject *
98
101
new_previous_version (const char * name , const change_record * (* getrecord )(Py_UCS4 ),
@@ -135,7 +138,7 @@ unicodedata_UCD_decimal_impl(PyObject *self, int chr,
135
138
long rc ;
136
139
Py_UCS4 c = (Py_UCS4 )chr ;
137
140
138
- if (self && UCD_Check (self )) {
141
+ if (UCD_Check (self , & UCD_Type )) {
139
142
const change_record * old = get_old_record (self , c );
140
143
if (old -> category_changed == 0 ) {
141
144
/* unassigned */
@@ -223,7 +226,7 @@ unicodedata_UCD_numeric_impl(PyObject *self, int chr,
223
226
double rc ;
224
227
Py_UCS4 c = (Py_UCS4 )chr ;
225
228
226
- if (self && UCD_Check (self )) {
229
+ if (UCD_Check (self , & UCD_Type )) {
227
230
const change_record * old = get_old_record (self , c );
228
231
if (old -> category_changed == 0 ) {
229
232
/* unassigned */
@@ -268,7 +271,7 @@ unicodedata_UCD_category_impl(PyObject *self, int chr)
268
271
int index ;
269
272
Py_UCS4 c = (Py_UCS4 )chr ;
270
273
index = (int ) _getrecord_ex (c )-> category ;
271
- if (self && UCD_Check (self )) {
274
+ if (UCD_Check (self , & UCD_Type )) {
272
275
const change_record * old = get_old_record (self , c );
273
276
if (old -> category_changed != 0xFF )
274
277
index = old -> category_changed ;
@@ -295,7 +298,7 @@ unicodedata_UCD_bidirectional_impl(PyObject *self, int chr)
295
298
int index ;
296
299
Py_UCS4 c = (Py_UCS4 )chr ;
297
300
index = (int ) _getrecord_ex (c )-> bidirectional ;
298
- if (self && UCD_Check (self )) {
301
+ if (UCD_Check (self , & UCD_Type )) {
299
302
const change_record * old = get_old_record (self , c );
300
303
if (old -> category_changed == 0 )
301
304
index = 0 ; /* unassigned */
@@ -324,7 +327,7 @@ unicodedata_UCD_combining_impl(PyObject *self, int chr)
324
327
int index ;
325
328
Py_UCS4 c = (Py_UCS4 )chr ;
326
329
index = (int ) _getrecord_ex (c )-> combining ;
327
- if (self && UCD_Check (self )) {
330
+ if (UCD_Check (self , & UCD_Type )) {
328
331
const change_record * old = get_old_record (self , c );
329
332
if (old -> category_changed == 0 )
330
333
index = 0 ; /* unassigned */
@@ -352,7 +355,7 @@ unicodedata_UCD_mirrored_impl(PyObject *self, int chr)
352
355
int index ;
353
356
Py_UCS4 c = (Py_UCS4 )chr ;
354
357
index = (int ) _getrecord_ex (c )-> mirrored ;
355
- if (self && UCD_Check (self )) {
358
+ if (UCD_Check (self , & UCD_Type )) {
356
359
const change_record * old = get_old_record (self , c );
357
360
if (old -> category_changed == 0 )
358
361
index = 0 ; /* unassigned */
@@ -379,7 +382,7 @@ unicodedata_UCD_east_asian_width_impl(PyObject *self, int chr)
379
382
int index ;
380
383
Py_UCS4 c = (Py_UCS4 )chr ;
381
384
index = (int ) _getrecord_ex (c )-> east_asian_width ;
382
- if (self && UCD_Check (self )) {
385
+ if (UCD_Check (self , & UCD_Type )) {
383
386
const change_record * old = get_old_record (self , c );
384
387
if (old -> category_changed == 0 )
385
388
index = 0 ; /* unassigned */
@@ -413,7 +416,7 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr)
413
416
414
417
code = (int )c ;
415
418
416
- if (self && UCD_Check (self )) {
419
+ if (UCD_Check (self , & UCD_Type )) {
417
420
const change_record * old = get_old_record (self , c );
418
421
if (old -> category_changed == 0 )
419
422
return PyUnicode_FromString ("" ); /* unassigned */
@@ -460,7 +463,7 @@ get_decomp_record(PyObject *self, Py_UCS4 code, int *index, int *prefix, int *co
460
463
{
461
464
if (code >= 0x110000 ) {
462
465
* index = 0 ;
463
- } else if (self && UCD_Check (self ) &&
466
+ } else if (UCD_Check (self , & UCD_Type ) &&
464
467
get_old_record (self , code )-> category_changed == 0 ) {
465
468
/* unassigned in old version */
466
469
* index = 0 ;
@@ -558,7 +561,7 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
558
561
continue ;
559
562
}
560
563
/* normalization changes */
561
- if (self && UCD_Check (self )) {
564
+ if (UCD_Check (self , & UCD_Type )) {
562
565
Py_UCS4 value = ((PreviousDBVersion * )self )-> normalization (code );
563
566
if (value != 0 ) {
564
567
stack [stackptr ++ ] = value ;
@@ -799,7 +802,7 @@ is_normalized_quickcheck(PyObject *self, PyObject *input,
799
802
{
800
803
/* An older version of the database is requested, quickchecks must be
801
804
disabled. */
802
- if (self && UCD_Check (self ))
805
+ if (UCD_Check (self , & UCD_Type ))
803
806
return NO ;
804
807
805
808
Py_ssize_t i , len ;
@@ -1066,7 +1069,7 @@ _getucname(PyObject *self, Py_UCS4 code, char* buffer, int buflen,
1066
1069
if (!with_alias_and_seq && (IS_ALIAS (code ) || IS_NAMED_SEQ (code )))
1067
1070
return 0 ;
1068
1071
1069
- if (self && UCD_Check (self )) {
1072
+ if (UCD_Check (self , & UCD_Type )) {
1070
1073
/* in 3.2.0 there are no aliases and named sequences */
1071
1074
const change_record * old ;
1072
1075
if (IS_ALIAS (code ) || IS_NAMED_SEQ (code ))
0 commit comments