1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-23 02:50:08 +03:00

build: Rework mmap checks

Switch to AC_CHECK_DECLS/check_symbol_exists. Don't check for
sys/mman.h separately. Don't check for munmap.
This commit is contained in:
Nick Wellnhofer 2024-07-22 14:58:16 +02:00
parent e1657f3f27
commit 3ef6661175
5 changed files with 15 additions and 38 deletions

View File

@ -144,14 +144,12 @@ check_include_files(dl.h HAVE_DL_H)
check_symbol_exists(getentropy "sys/random.h" HAVE_DECL_GETENTROPY)
check_library_exists(history append_history "" HAVE_LIBHISTORY)
check_library_exists(readline readline "" HAVE_LIBREADLINE)
check_function_exists(mmap HAVE_MMAP)
check_function_exists(munmap HAVE_MUNMAP)
check_symbol_exists(mmap "sys/mman.h" HAVE_DECL_MMAP)
check_include_files(netdb.h HAVE_NETDB_H)
check_include_files(netinet/in.h HAVE_NETINET_IN_H)
check_include_files(poll.h HAVE_POLL_H)
check_library_exists(dld shl_load "" HAVE_SHLLOAD)
check_include_files(stdint.h HAVE_STDINT_H)
check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
check_include_files(sys/select.h HAVE_SYS_SELECT_H)
check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)

View File

@ -23,15 +23,7 @@
#cmakedefine HAVE_LIBREADLINE 1
/* Define to 1 if you have the `mmap' function. */
#cmakedefine HAVE_MMAP 1
/* Define to 1 if you have the `munmap' function. */
#cmakedefine HAVE_MUNMAP 1
/* mmap() is no good without munmap() */
#if defined(HAVE_MMAP) && !defined(HAVE_MUNMAP)
# undef /**/ HAVE_MMAP
#endif
#cmakedefine HAVE_DECL_MMAP 1
/* Define to 1 if you have the <netdb.h> header file. */
#cmakedefine HAVE_NETDB_H 1
@ -51,9 +43,6 @@
/* Define to 1 if you have the <stdint.h> header file. */
#cmakedefine HAVE_STDINT_H 1
/* Define to 1 if you have the <sys/mman.h> header file. */
#cmakedefine HAVE_SYS_MMAN_H 1
/* Define to 1 if you have the <sys/select.h> header file. */
#cmakedefine HAVE_SYS_SELECT_H 1

View File

@ -298,20 +298,12 @@ dnl
dnl Checks for header files.
dnl
AC_CHECK_HEADERS([stdint.h])
AC_CHECK_HEADERS([sys/mman.h])
AC_CHECK_HEADERS([dl.h dlfcn.h])
AC_CHECK_HEADERS([glob.h])
AM_CONDITIONAL(WITH_GLOB, test "$ac_cv_header_glob_h" = "yes")
dnl Checks for library functions.
AC_CHECK_FUNCS([mmap munmap])
AH_VERBATIM([HAVE_MUNMAP_AFTER],[/* mmap() is no good without munmap() */
#if defined(HAVE_MMAP) && !defined(HAVE_MUNMAP)
# undef /**/ HAVE_MMAP
#endif])
AC_CHECK_DECLS([mmap], [], [], [#include <sys/mman.h>])
AC_CHECK_DECLS([getentropy], [], [], [#include <sys/random.h>])
dnl

View File

@ -234,7 +234,6 @@ config_h.set_quoted('LOCALEDIR', dir_locale)
# header files
xml_check_headers = [
'stdint.h',
'sys/mman.h',
'dl.h',
'dlfcn.h',
'glob.h',
@ -258,8 +257,7 @@ endforeach
xml_check_functions = [
# fct | header
['getentropy', 'sys/random.h', 'HAVE_DECL_GETENTROPY'],
['mmap', 'sys/mman.h', 'HAVE_MMAP'],
['munmap', 'sys/mman.h', 'HAVE_MUNMAP'],
['mmap', 'sys/mman.h', 'HAVE_DECL_MMAP'],
]
foreach function : xml_check_functions

View File

@ -28,7 +28,7 @@
#include <unistd.h>
#endif
#ifdef HAVE_SYS_MMAN_H
#if HAVE_DECL_MMAP
#include <sys/mman.h>
/* seems needed for Solaris */
#ifndef MAP_FAILED
@ -140,7 +140,7 @@ static int htmlout = 0;
static int push = 0;
static int pushsize = 4096;
#endif /* LIBXML_PUSH_ENABLED */
#ifdef HAVE_MMAP
#if HAVE_DECL_MMAP
static int memory = 0;
#endif
static int testIO = 0;
@ -1481,7 +1481,7 @@ static void processNode(xmlTextReaderPtr reader) {
static void streamFile(const char *filename) {
xmlTextReaderPtr reader;
int ret;
#ifdef HAVE_MMAP
#if HAVE_DECL_MMAP
int fd = -1;
struct stat info;
const char *base = NULL;
@ -1630,7 +1630,7 @@ static void streamFile(const char *filename) {
patstream = NULL;
}
#endif
#ifdef HAVE_MMAP
#if HAVE_DECL_MMAP
if (memory) {
munmap((char *) base, info.st_size);
close(fd);
@ -1906,7 +1906,7 @@ parseFile(const char *filename, xmlParserCtxtPtr rectxt) {
}
#endif /* LIBXML_PUSH_ENABLED */
#ifdef HAVE_MMAP
#if HAVE_DECL_MMAP
if ((html) && (memory)) {
int fd;
struct stat info;
@ -2028,7 +2028,7 @@ parseFile(const char *filename, xmlParserCtxtPtr rectxt) {
doc = xmlCtxtReadIO(ctxt, myRead, myClose, f, filename, NULL,
options);
#ifdef HAVE_MMAP
#if HAVE_DECL_MMAP
} else if (memory) {
int fd;
struct stat info;
@ -2304,7 +2304,7 @@ parseAndPrintFile(const char *filename, xmlParserCtxtPtr rectxt) {
}
} else
#endif
#ifdef HAVE_MMAP
#if HAVE_DECL_MMAP
if (memory) {
xmlChar *result;
int len;
@ -2332,7 +2332,7 @@ parseAndPrintFile(const char *filename, xmlParserCtxtPtr rectxt) {
}
} else
#endif /* HAVE_MMAP */
#endif /* HAVE_DECL_MMAP */
if (compress) {
xmlSaveFile(output ? output : "-", doc);
} else {
@ -2692,7 +2692,7 @@ static void usage(FILE *f, const char *name) {
fprintf(f, "\t--push : use the push mode of the parser\n");
fprintf(f, "\t--pushsmall : use the push mode of the parser using tiny increments\n");
#endif /* LIBXML_PUSH_ENABLED */
#ifdef HAVE_MMAP
#if HAVE_DECL_MMAP
fprintf(f, "\t--memory : parse from memory\n");
#endif
fprintf(f, "\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n");
@ -2884,7 +2884,7 @@ xmllintMain(int argc, const char **argv, xmlResourceLoader loader) {
push = 0;
pushsize = 4096;
#endif /* LIBXML_PUSH_ENABLED */
#ifdef HAVE_MMAP
#if HAVE_DECL_MMAP
memory = 0;
#endif
testIO = 0;
@ -3069,7 +3069,7 @@ xmllintMain(int argc, const char **argv, xmlResourceLoader loader) {
pushsize = 10;
}
#endif /* LIBXML_PUSH_ENABLED */
#ifdef HAVE_MMAP
#if HAVE_DECL_MMAP
else if ((!strcmp(argv[i], "-memory")) ||
(!strcmp(argv[i], "--memory")))
memory++;