From: Bruno Haible Date: Thu, 31 Oct 2024 19:54:52 +0000 (+0100) Subject: malloc-posix, calloc-posix, realloc-posix: Optimize on MSVC. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=ea0babb11240a9ebeb73133697fccaa6e77b708a;p=gnulib.git malloc-posix, calloc-posix, realloc-posix: Optimize on MSVC. * m4/malloc.m4 (gl_CHECK_MALLOC_POSIX): Assume that malloc sets errno upon failure if UCRT is in use. --- diff --git a/ChangeLog b/ChangeLog index 79df4886b7..dc16a1fda9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-10-31 Bruno Haible + + malloc-posix, calloc-posix, realloc-posix: Optimize on MSVC. + * m4/malloc.m4 (gl_CHECK_MALLOC_POSIX): Assume that malloc sets errno + upon failure if UCRT is in use. + 2024-10-31 Bruno Haible realloc-posix tests: Enhance tests. diff --git a/m4/malloc.m4 b/m4/malloc.m4 index df3a492d40..d7684f418c 100644 --- a/m4/malloc.m4 +++ b/m4/malloc.m4 @@ -1,5 +1,5 @@ # malloc.m4 -# serial 36 +# serial 37 dnl Copyright (C) 2007, 2009-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -146,7 +146,21 @@ AC_DEFUN([gl_CHECK_MALLOC_POSIX], dnl 'test-realloc-posix', 'test-calloc-gnu' fail. case "$host_os" in mingw* | windows*) - gl_cv_func_malloc_posix=no ;; + dnl Old MSVCRT from 2001 did not set errno=ENOMEM when malloc failed. + dnl More recent MSVCRT from 2019 does so. + dnl UCRT is the successor of MSVCRT. Assume that UCRT does so as well. + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #ifndef _UCRT + msvcrt yuck + #endif + ]], + [[]]) + ], + [gl_cv_func_malloc_posix=yes], + [gl_cv_func_malloc_posix=no]) + ;; irix* | solaris*) dnl On IRIX 6.5, the three functions return NULL with errno unset dnl when the argument is larger than PTRDIFF_MAX.