Skip to content

Commit d3ad3b6

Browse files
authored
Merge pull request #20742 from jdavies-st/greater-expatations-thereturn
Update bundled expat to 2.9.0
2 parents e91800f + 9649fbe commit d3ad3b6

34 files changed

Lines changed: 3315 additions & 1689 deletions

‎astropy/utils/xml/setup_package.py‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ def get_extensions(build_type="release"):
2323
cfg[k].extend(v)
2424
else:
2525
EXPAT_DIR = "cextern/expat/lib"
26-
cfg["sources"].extend(
27-
[
28-
join(EXPAT_DIR, fn)
29-
for fn in ["xmlparse.c", "xmlrole.c", "xmltok.c", "xmltok_impl.c"]
30-
]
31-
)
26+
expat_sources = [
27+
"xcs.c",
28+
"xmlparse.c",
29+
"xmlrole.c",
30+
"xmltok.c",
31+
"xmltok_impl.c",
32+
]
33+
# Source of entropy for the hash salt, matching expat_config.h
34+
if sys.platform == "win32":
35+
expat_sources.append("random_rand_s.c")
36+
else:
37+
expat_sources.append("random_dev_urandom.c")
38+
cfg["sources"].extend([join(EXPAT_DIR, fn) for fn in expat_sources])
3239
cfg["include_dirs"].extend([XML_DIR, EXPAT_DIR])
3340
if sys.platform.startswith("linux"):
3441
# This is to ensure we only export the Python entry point

‎astropy/utils/xml/src/expat_config.h‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
/* Define to 1 if you have the <fcntl.h> header file. */
2424
#define HAVE_FCNTL_H 1
2525

26+
/* Define to 1 if you have the `getentropy' function. */
27+
/* #undef HAVE_GETENTROPY */
28+
2629
/* Define to 1 if you have the 'getpagesize' function. */
2730
#define HAVE_GETPAGESIZE 1
2831

@@ -32,9 +35,6 @@
3235
/* Define to 1 if you have the <inttypes.h> header file. */
3336
#define HAVE_INTTYPES_H 1
3437

35-
/* Define to 1 if you have the 'bsd' library (-lbsd). */
36-
/* #undef HAVE_LIBBSD */
37-
3838
/* Define to 1 if you have a working 'mmap' system call. */
3939
#define HAVE_MMAP 1
4040

@@ -80,7 +80,7 @@
8080
#define PACKAGE_NAME "expat"
8181

8282
/* Define to the full name and version of this package. */
83-
#define PACKAGE_STRING "expat 2.7.3"
83+
#define PACKAGE_STRING "expat 2.9.0"
8484

8585
/* Define to the one symbol short name of this package. */
8686
#define PACKAGE_TARNAME "expat"
@@ -89,15 +89,15 @@
8989
#define PACKAGE_URL ""
9090

9191
/* Define to the version of this package. */
92-
#define PACKAGE_VERSION "2.7.3"
92+
#define PACKAGE_VERSION "2.9.0"
9393

9494
/* Define to 1 if all of the C89 standard headers exist (not just the ones
9595
required in a freestanding environment). This macro is provided for
9696
backward compatibility; new code need not use it. */
9797
#define STDC_HEADERS 1
9898

9999
/* Version number of package */
100-
#define VERSION "2.7.3"
100+
#define VERSION "2.9.0"
101101

102102
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
103103
significant byte first (like Motorola and SPARC, unlike Intel). */
@@ -111,10 +111,6 @@
111111
#endif
112112
#endif
113113

114-
/* Define to allow retrieving the byte offsets for attribute names and values.
115-
*/
116-
/* #undef XML_ATTR_INFO */
117-
118114
/* Define to specify how much context to retain around the current parse
119115
point, 0 to disable. */
120116
#define XML_CONTEXT_BYTES 1024

‎astropy/utils/xml/src/iterparse.c‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
#undef CLAMP
4343
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
4444

45+
/* expat 2.9.0 deprecates the line and column functions in favor of 64-bit
46+
versions, but a system expat (ASTROPY_USE_SYSTEM_EXPAT) may be older. */
47+
#if XML_MAJOR_VERSION > 2 || (XML_MAJOR_VERSION == 2 && XML_MINOR_VERSION >= 9)
48+
#define GET_LINE_NUMBER XML_GetCurrentLineNumber64
49+
#define GET_COLUMN_NUMBER XML_GetCurrentColumnNumber64
50+
#else
51+
#define GET_LINE_NUMBER XML_GetCurrentLineNumber
52+
#define GET_COLUMN_NUMBER XML_GetCurrentColumnNumber
53+
#endif
54+
4555
static Py_ssize_t next_power_of_2(Py_ssize_t n)
4656
{
4757
/* Calculate the next-higher power of two that is >= 'n' */
@@ -445,8 +455,8 @@ static void startElement(IterParser *self, const XML_Char *name, const XML_Char
445455
PyTuple_SetItem(tuple, 2, pyatts);
446456
pyatts = NULL;
447457

448-
self->last_line = (unsigned long)XML_GetCurrentLineNumber(self->parser);
449-
self->last_col = (unsigned long)XML_GetCurrentColumnNumber(self->parser);
458+
self->last_line = (unsigned long)GET_LINE_NUMBER(self->parser);
459+
self->last_col = (unsigned long)GET_COLUMN_NUMBER(self->parser);
450460

451461
pos = make_pos(self);
452462
if (pos == NULL) {
@@ -584,8 +594,8 @@ static void characterData(IterParser *self, const XML_Char *text, int len)
584594
}
585595

586596
if (self->text_size == 0) {
587-
self->last_line = (unsigned long)XML_GetCurrentLineNumber(self->parser);
588-
self->last_col = (unsigned long)XML_GetCurrentColumnNumber(self->parser);
597+
self->last_line = (unsigned long)GET_LINE_NUMBER(self->parser);
598+
self->last_col = (unsigned long)GET_COLUMN_NUMBER(self->parser);
589599
}
590600

591601
if (self->keep_text) {
@@ -663,8 +673,8 @@ static void xmlDecl(
663673
PyTuple_SetItem(tuple, 2, attrs);
664674
attrs = NULL;
665675

666-
self->last_line = (unsigned long)XML_GetCurrentLineNumber(self->parser);
667-
self->last_col = (unsigned long)XML_GetCurrentColumnNumber(self->parser);
676+
self->last_line = (unsigned long)GET_LINE_NUMBER(self->parser);
677+
self->last_col = (unsigned long)GET_COLUMN_NUMBER(self->parser);
668678

669679
pos = make_pos(self);
670680
if (pos == NULL) {
@@ -797,8 +807,8 @@ static PyObject *IterParser_next(PyObject *selfO)
797807
PyErr_Format(
798808
PyExc_ValueError,
799809
"%lu:%lu: %s",
800-
XML_GetCurrentLineNumber(self->parser),
801-
XML_GetCurrentColumnNumber(self->parser),
810+
(unsigned long)GET_LINE_NUMBER(self->parser),
811+
(unsigned long)GET_COLUMN_NUMBER(self->parser),
802812
XML_ErrorString(XML_GetErrorCode(self->parser))
803813
);
804814
goto fail;

0 commit comments

Comments
 (0)