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