Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5bd7c02

Browse files
committed
Avoid forward-declaring the methods array.
Rename unicodedata.db* to unicodedata.ucd*
1 parent f669436 commit 5bd7c02

5 files changed

Lines changed: 57 additions & 56 deletions

File tree

Doc/lib/libunicodedata.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ \section{\module{unicodedata} ---
131131
\versionadded{2.3}
132132
\end{datadesc}
133133

134-
\begin{datadesc}{db_3_2_0}
134+
\begin{datadesc}{ucd_3_2_0}
135135
This is an object that has the same methods as the entire
136136
module, but uses the Unicode database version 3.2 instead,
137137
for applications that require this specific version of

Include/ucnhash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ typedef struct {
1616
/* Get name for a given character code. Returns non-zero if
1717
success, zero if not. Does not set Python exceptions.
1818
If self is NULL, data come from the default version of the database.
19-
If it is not NULL, it should be a unicodedata.db_X_Y_Z object */
19+
If it is not NULL, it should be a unicodedata.ucd_X_Y_Z object */
2020
int (*getname)(PyObject *self, Py_UCS4 code, char* buffer, int buflen);
2121

2222
/* Get character code for a given name. Same error handling

Lib/encodings/idna.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This module implements the RFCs 3490 (IDNA) and 3491 (Nameprep)
22

33
import stringprep, re, codecs
4-
from unicodedata import db_3_2_0 as unicodedata
4+
from unicodedata import ucd_3_2_0 as unicodedata
55

66
# IDNA section 3.1
77
dots = re.compile(u"[\u002E\u3002\uFF0E\uFF61]")

Lib/stringprep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
and mappings, for which a mapping function is provided.
66
"""
77

8-
from unicodedata import db_3_2_0 as unicodedata
8+
from unicodedata import ucd_3_2_0 as unicodedata
99

1010
assert unicodedata.unidata_version == '3.2.0'
1111

Modules/unicodedata.c

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -70,67 +70,20 @@ typedef struct previous_version {
7070

7171
#define get_old_record(self, v) ((((PreviousDBVersion*)self)->getrecord)(v))
7272

73-
/* Forward declaration */
74-
static PyMethodDef unicodedata_functions[];
75-
7673
static PyMemberDef DB_members[] = {
7774
{"unidata_version", T_STRING, offsetof(PreviousDBVersion, name), READONLY},
7875
{NULL}
7976
};
8077

81-
static PyTypeObject Xxo_Type = {
82-
/* The ob_type field must be initialized in the module init function
83-
* to be portable to Windows without using C++. */
84-
PyObject_HEAD_INIT(NULL)
85-
0, /*ob_size*/
86-
"unicodedata.DB", /*tp_name*/
87-
sizeof(PreviousDBVersion), /*tp_basicsize*/
88-
0, /*tp_itemsize*/
89-
/* methods */
90-
(destructor)PyObject_Del, /*tp_dealloc*/
91-
0, /*tp_print*/
92-
0, /*tp_getattr*/
93-
0, /*tp_setattr*/
94-
0, /*tp_compare*/
95-
0, /*tp_repr*/
96-
0, /*tp_as_number*/
97-
0, /*tp_as_sequence*/
98-
0, /*tp_as_mapping*/
99-
0, /*tp_hash*/
100-
0, /*tp_call*/
101-
0, /*tp_str*/
102-
PyObject_GenericGetAttr,/*tp_getattro*/
103-
0, /*tp_setattro*/
104-
0, /*tp_as_buffer*/
105-
Py_TPFLAGS_DEFAULT, /*tp_flags*/
106-
0, /*tp_doc*/
107-
0, /*tp_traverse*/
108-
0, /*tp_clear*/
109-
0, /*tp_richcompare*/
110-
0, /*tp_weaklistoffset*/
111-
0, /*tp_iter*/
112-
0, /*tp_iternext*/
113-
unicodedata_functions, /*tp_methods*/
114-
DB_members, /*tp_members*/
115-
0, /*tp_getset*/
116-
0, /*tp_base*/
117-
0, /*tp_dict*/
118-
0, /*tp_descr_get*/
119-
0, /*tp_descr_set*/
120-
0, /*tp_dictoffset*/
121-
0, /*tp_init*/
122-
0, /*tp_alloc*/
123-
0, /*tp_new*/
124-
0, /*tp_free*/
125-
0, /*tp_is_gc*/
126-
};
78+
// forward declaration
79+
static PyTypeObject UCD_Type;
12780

12881
static PyObject*
12982
new_previous_version(const char*name, const change_record* (*getrecord)(Py_UCS4),
13083
Py_UCS4 (*normalization)(Py_UCS4))
13184
{
13285
PreviousDBVersion *self;
133-
self = PyObject_New(PreviousDBVersion, &Xxo_Type);
86+
self = PyObject_New(PreviousDBVersion, &UCD_Type);
13487
if (self == NULL)
13588
return NULL;
13689
self->name = name;
@@ -1163,7 +1116,52 @@ static PyMethodDef unicodedata_functions[] = {
11631116
{NULL, NULL} /* sentinel */
11641117
};
11651118

1166-
1119+
static PyTypeObject UCD_Type = {
1120+
/* The ob_type field must be initialized in the module init function
1121+
* to be portable to Windows without using C++. */
1122+
PyObject_HEAD_INIT(NULL)
1123+
0, /*ob_size*/
1124+
"unicodedata.UCD", /*tp_name*/
1125+
sizeof(PreviousDBVersion), /*tp_basicsize*/
1126+
0, /*tp_itemsize*/
1127+
/* methods */
1128+
(destructor)PyObject_Del, /*tp_dealloc*/
1129+
0, /*tp_print*/
1130+
0, /*tp_getattr*/
1131+
0, /*tp_setattr*/
1132+
0, /*tp_compare*/
1133+
0, /*tp_repr*/
1134+
0, /*tp_as_number*/
1135+
0, /*tp_as_sequence*/
1136+
0, /*tp_as_mapping*/
1137+
0, /*tp_hash*/
1138+
0, /*tp_call*/
1139+
0, /*tp_str*/
1140+
PyObject_GenericGetAttr,/*tp_getattro*/
1141+
0, /*tp_setattro*/
1142+
0, /*tp_as_buffer*/
1143+
Py_TPFLAGS_DEFAULT, /*tp_flags*/
1144+
0, /*tp_doc*/
1145+
0, /*tp_traverse*/
1146+
0, /*tp_clear*/
1147+
0, /*tp_richcompare*/
1148+
0, /*tp_weaklistoffset*/
1149+
0, /*tp_iter*/
1150+
0, /*tp_iternext*/
1151+
unicodedata_functions, /*tp_methods*/
1152+
DB_members, /*tp_members*/
1153+
0, /*tp_getset*/
1154+
0, /*tp_base*/
1155+
0, /*tp_dict*/
1156+
0, /*tp_descr_get*/
1157+
0, /*tp_descr_set*/
1158+
0, /*tp_dictoffset*/
1159+
0, /*tp_init*/
1160+
0, /*tp_alloc*/
1161+
0, /*tp_new*/
1162+
0, /*tp_free*/
1163+
0, /*tp_is_gc*/
1164+
};
11671165

11681166
PyDoc_STRVAR(unicodedata_docstring,
11691167
"This module provides access to the Unicode Character Database which\n\
@@ -1180,17 +1178,20 @@ initunicodedata(void)
11801178
{
11811179
PyObject *m, *v;
11821180

1181+
UCD_Type.ob_type = &PyType_Type;
1182+
11831183
m = Py_InitModule3(
11841184
"unicodedata", unicodedata_functions, unicodedata_docstring);
11851185
if (!m)
11861186
return;
11871187

11881188
PyModule_AddStringConstant(m, "unidata_version", UNIDATA_VERSION);
1189+
PyModule_AddObject(m, "UCD", (PyObject*)&UCD_Type);
11891190

11901191
/* Previous versions */
11911192
v = new_previous_version("3.2.0", get_change_3_2_0, normalization_3_2_0);
11921193
if (v != NULL)
1193-
PyModule_AddObject(m, "db_3_2_0", v);
1194+
PyModule_AddObject(m, "ucd_3_2_0", v);
11941195

11951196
/* Export C API */
11961197
v = PyCObject_FromVoidPtr((void *) &hashAPI, NULL);

0 commit comments

Comments
 (0)