Avoid forward-declaring the methods array. · python/cpython@5bd7c02

GitHub

@@ -70,67 +70,20 @@ typedef struct previous_version {

70707171#defineget_old_record(self, v) ((((PreviousDBVersion*)self)->getrecord)(v))

727273-/* Forward declaration */

74-staticPyMethodDefunicodedata_functions[];

75-7673staticPyMemberDefDB_members[] = {

7774 {"unidata_version", T_STRING, offsetof(PreviousDBVersion, name), READONLY},

7875 {NULL}

7976};

807781-staticPyTypeObjectXxo_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+staticPyTypeObjectUCD_Type;

1278012881staticPyObject*

12982new_previous_version(constchar*name, constchange_record* (*getrecord)(Py_UCS4),

13083Py_UCS4 (*normalization)(Py_UCS4))

13184{

13285PreviousDBVersion*self;

133-self=PyObject_New(PreviousDBVersion, &Xxo_Type);

86+self=PyObject_New(PreviousDBVersion, &UCD_Type);

13487if (self==NULL)

13588returnNULL;

13689self->name=name;

@@ -1163,7 +1116,52 @@ static PyMethodDef unicodedata_functions[] = {

11631116 {NULL, NULL} /* sentinel */

11641117};

116511181166-1119+staticPyTypeObjectUCD_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+};

1167116511681166PyDoc_STRVAR(unicodedata_docstring,

11691167"This module provides access to the Unicode Character Database which\n\

@@ -1180,17 +1178,20 @@ initunicodedata(void)

11801178{

11811179PyObject*m, *v;

118211801181+UCD_Type.ob_type=&PyType_Type;

1182+11831183m=Py_InitModule3(

11841184"unicodedata", unicodedata_functions, unicodedata_docstring);

11851185if (!m)

11861186return;

1187118711881188PyModule_AddStringConstant(m, "unidata_version", UNIDATA_VERSION);

1189+PyModule_AddObject(m, "UCD", (PyObject*)&UCD_Type);

1189119011901191/* Previous versions */

11911192v=new_previous_version("3.2.0", get_change_3_2_0, normalization_3_2_0);

11921193if (v!=NULL)

1193-PyModule_AddObject(m, "db_3_2_0", v);

1194+PyModule_AddObject(m, "ucd_3_2_0", v);

1194119511951196/* Export C API */

11961197v=PyCObject_FromVoidPtr((void*) &hashAPI, NULL);