Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c98bd9d

Browse files
committedSep 21, 2020
keep the macro
1 parent c8c70e7 commit c98bd9d

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed
 

‎Modules/unicodedata.c

+18-13
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ static PyMemberDef DB_members[] = {
9292

9393
/* forward declaration */
9494
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)
96101

97102
static PyObject*
98103
new_previous_version(const char*name, const change_record* (*getrecord)(Py_UCS4),
@@ -135,7 +140,7 @@ unicodedata_UCD_decimal_impl(PyObject *self, int chr,
135140
long rc;
136141
Py_UCS4 c = (Py_UCS4)chr;
137142

138-
if (self && UCD_Check(self)) {
143+
if (UCD_Check(self, &UCD_Type)) {
139144
const change_record *old = get_old_record(self, c);
140145
if (old->category_changed == 0) {
141146
/* unassigned */
@@ -223,7 +228,7 @@ unicodedata_UCD_numeric_impl(PyObject *self, int chr,
223228
double rc;
224229
Py_UCS4 c = (Py_UCS4)chr;
225230

226-
if (self && UCD_Check(self)) {
231+
if (UCD_Check(self, &UCD_Type)) {
227232
const change_record *old = get_old_record(self, c);
228233
if (old->category_changed == 0) {
229234
/* unassigned */
@@ -268,7 +273,7 @@ unicodedata_UCD_category_impl(PyObject *self, int chr)
268273
int index;
269274
Py_UCS4 c = (Py_UCS4)chr;
270275
index = (int) _getrecord_ex(c)->category;
271-
if (self && UCD_Check(self)) {
276+
if (UCD_Check(self, &UCD_Type)) {
272277
const change_record *old = get_old_record(self, c);
273278
if (old->category_changed != 0xFF)
274279
index = old->category_changed;
@@ -295,7 +300,7 @@ unicodedata_UCD_bidirectional_impl(PyObject *self, int chr)
295300
int index;
296301
Py_UCS4 c = (Py_UCS4)chr;
297302
index = (int) _getrecord_ex(c)->bidirectional;
298-
if (self && UCD_Check(self)) {
303+
if (UCD_Check(self, &UCD_Type)) {
299304
const change_record *old = get_old_record(self, c);
300305
if (old->category_changed == 0)
301306
index = 0; /* unassigned */
@@ -324,7 +329,7 @@ unicodedata_UCD_combining_impl(PyObject *self, int chr)
324329
int index;
325330
Py_UCS4 c = (Py_UCS4)chr;
326331
index = (int) _getrecord_ex(c)->combining;
327-
if (self && UCD_Check(self)) {
332+
if (UCD_Check(self, &UCD_Type)) {
328333
const change_record *old = get_old_record(self, c);
329334
if (old->category_changed == 0)
330335
index = 0; /* unassigned */
@@ -352,7 +357,7 @@ unicodedata_UCD_mirrored_impl(PyObject *self, int chr)
352357
int index;
353358
Py_UCS4 c = (Py_UCS4)chr;
354359
index = (int) _getrecord_ex(c)->mirrored;
355-
if (self && UCD_Check(self)) {
360+
if (UCD_Check(self, &UCD_Type)) {
356361
const change_record *old = get_old_record(self, c);
357362
if (old->category_changed == 0)
358363
index = 0; /* unassigned */
@@ -379,7 +384,7 @@ unicodedata_UCD_east_asian_width_impl(PyObject *self, int chr)
379384
int index;
380385
Py_UCS4 c = (Py_UCS4)chr;
381386
index = (int) _getrecord_ex(c)->east_asian_width;
382-
if (self && UCD_Check(self)) {
387+
if (UCD_Check(self, &UCD_Type)) {
383388
const change_record *old = get_old_record(self, c);
384389
if (old->category_changed == 0)
385390
index = 0; /* unassigned */
@@ -413,7 +418,7 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr)
413418

414419
code = (int)c;
415420

416-
if (self && UCD_Check(self)) {
421+
if (UCD_Check(self, &UCD_Type)) {
417422
const change_record *old = get_old_record(self, c);
418423
if (old->category_changed == 0)
419424
return PyUnicode_FromString(""); /* unassigned */
@@ -460,7 +465,7 @@ get_decomp_record(PyObject *self, Py_UCS4 code, int *index, int *prefix, int *co
460465
{
461466
if (code >= 0x110000) {
462467
*index = 0;
463-
} else if (self && UCD_Check(self) &&
468+
} else if (UCD_Check(self, &UCD_Type) &&
464469
get_old_record(self, code)->category_changed==0) {
465470
/* unassigned in old version */
466471
*index = 0;
@@ -558,7 +563,7 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
558563
continue;
559564
}
560565
/* normalization changes */
561-
if (self && UCD_Check(self)) {
566+
if (UCD_Check(self, &UCD_Type)) {
562567
Py_UCS4 value = ((PreviousDBVersion*)self)->normalization(code);
563568
if (value != 0) {
564569
stack[stackptr++] = value;
@@ -799,7 +804,7 @@ is_normalized_quickcheck(PyObject *self, PyObject *input,
799804
{
800805
/* An older version of the database is requested, quickchecks must be
801806
disabled. */
802-
if (self && UCD_Check(self))
807+
if (UCD_Check(self, &UCD_Type))
803808
return NO;
804809

805810
Py_ssize_t i, len;
@@ -1066,7 +1071,7 @@ _getucname(PyObject *self, Py_UCS4 code, char* buffer, int buflen,
10661071
if (!with_alias_and_seq && (IS_ALIAS(code) || IS_NAMED_SEQ(code)))
10671072
return 0;
10681073

1069-
if (self && UCD_Check(self)) {
1074+
if (UCD_Check(self, &UCD_Type)) {
10701075
/* in 3.2.0 there are no aliases and named sequences */
10711076
const change_record *old;
10721077
if (IS_ALIAS(code) || IS_NAMED_SEQ(code))

0 commit comments

Comments
 (0)
Please sign in to comment.