@@ -2436,6 +2436,78 @@ pyexpat_capsule_destructor(PyObject *capsule)
24362436}
24372437
24382438
2439+ PyDoc_STRVAR (version_info__doc__ ,
2440+ "pyexpat.version_info\n\
2441+ \n\
2442+ Expat version information as a named tuple." );
2443+
2444+ static PyStructSequence_Field version_info_fields [] = {
2445+ {"major" , "Major release number" },
2446+ {"minor" , "Minor release number" },
2447+ {"micro" , "Micro release number" },
2448+ {0 }
2449+ };
2450+
2451+ static PyStructSequence_Desc version_info_desc = {
2452+ "pyexpat.version_info" , /* name */
2453+ version_info__doc__ , /* doc */
2454+ version_info_fields , /* fields */
2455+ 3
2456+ };
2457+
2458+ static PyObject *
2459+ make_version_info (PyTypeObject * type , int major , int minor , int micro )
2460+ {
2461+ PyObject * version ;
2462+ int pos = 0 ;
2463+
2464+ version = PyStructSequence_New (type );
2465+ if (version == NULL ) {
2466+ return NULL ;
2467+ }
2468+
2469+ #define SetItem (VALUE ) \
2470+ PyStructSequence_SET_ITEM(version, pos++, VALUE); \
2471+ if (PyErr_Occurred()) { \
2472+ Py_DECREF(version); \
2473+ return NULL; \
2474+ }
2475+
2476+ SetItem (PyLong_FromLong (major ))
2477+ SetItem (PyLong_FromLong (minor ))
2478+ SetItem (PyLong_FromLong (micro ))
2479+ #undef SetItem
2480+
2481+ return version ;
2482+ }
2483+
2484+ static int
2485+ add_version_info (PyObject * mod )
2486+ {
2487+ PyTypeObject * version_type ;
2488+ version_type = PyStructSequence_NewType (& version_info_desc );
2489+ if (version_type == NULL ) {
2490+ return -1 ;
2491+ }
2492+ if (PyModule_Add (mod , "VERSION_INFO" ,
2493+ make_version_info (version_type , XML_MAJOR_VERSION ,
2494+ XML_MINOR_VERSION , XML_MICRO_VERSION )) < 0 )
2495+ {
2496+ Py_DECREF (version_type );
2497+ return -1 ;
2498+ }
2499+ XML_Expat_Version info = XML_ExpatVersionInfo ();
2500+ if (PyModule_Add (mod , "version_info" ,
2501+ make_version_info (version_type , info .major ,
2502+ info .minor , info .micro )) < 0 )
2503+ {
2504+ Py_DECREF (version_type );
2505+ return -1 ;
2506+ }
2507+ Py_DECREF (version_type );
2508+ return 0 ;
2509+ }
2510+
24392511static int
24402512pyexpat_exec (PyObject * mod )
24412513{
@@ -2479,15 +2551,8 @@ pyexpat_exec(PyObject *mod)
24792551 XML_ExpatVersion ()) < 0 ) {
24802552 return -1 ;
24812553 }
2482- {
2483- XML_Expat_Version info = XML_ExpatVersionInfo ();
2484- PyObject * versionInfo = Py_BuildValue ("(iii)" ,
2485- info .major ,
2486- info .minor ,
2487- info .micro );
2488- if (PyModule_Add (mod , "version_info" , versionInfo ) < 0 ) {
2489- return -1 ;
2490- }
2554+ if (add_version_info (mod ) < 0 ) {
2555+ return -1 ;
24912556 }
24922557 /* XXX When Expat supports some way of figuring out how it was
24932558 compiled, this should check and set native_encoding
0 commit comments