]> Savannah Git Hosting - gnulib.git/commitdiff
malloc-posix, calloc-posix, realloc-posix: Optimize on MSVC.
authorBruno Haible <bruno@clisp.org>
Thu, 31 Oct 2024 19:54:52 +0000 (20:54 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 31 Oct 2024 19:54:52 +0000 (20:54 +0100)
* m4/malloc.m4 (gl_CHECK_MALLOC_POSIX): Assume that malloc sets errno
upon failure if UCRT is in use.

ChangeLog
m4/malloc.m4

index 79df4886b7ef4877cf138e8a81e70d3ae0ad4637..dc16a1fda998c3f7abe04fb1c2488341c34e5950 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-10-31  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        realloc-posix tests: Enhance tests.
index df3a492d4091cff757c2f16f3f952f363268fbff..d7684f418c71863d00a20a02724bf70d3c26a4fd 100644 (file)
@@ -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 <stdio.h>
+                #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.