Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 39f59b0

Browse files
committed
Remove MALLOC_ZERO_RETURNS_NULL.
1 parent 19cf4ee commit 39f59b0

6 files changed

Lines changed: 5 additions & 110 deletions

File tree

Include/pymem.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,11 @@ PyAPI_FUNC(void) PyMem_Free(void *);
6262

6363
#else /* ! PYMALLOC_DEBUG */
6464

65-
#ifdef MALLOC_ZERO_RETURNS_NULL
65+
/* PyMem_MALLOC(0) means malloc(1). Some systems would return NULL
66+
for malloc(0), which would be treated as an error. Some platforms
67+
would return a pointer with no memory behind it, which would break
68+
pymalloc. To solve these problems, allocate an extra byte. */
6669
#define PyMem_MALLOC(n) malloc((n) ? (n) : 1)
67-
#else
68-
#define PyMem_MALLOC malloc
69-
#endif
70-
71-
/* Caution: whether MALLOC_ZERO_RETURNS_NULL is #defined has nothing to
72-
do with whether platform realloc(non-NULL, 0) normally frees the memory
73-
or returns NULL. Rather than introduce yet another config variation,
74-
just make a realloc to 0 bytes act as if to 1 instead. */
7570
#define PyMem_REALLOC(p, n) realloc((p), (n) ? (n) : 1)
7671

7772
#endif /* PYMALLOC_DEBUG */

Objects/obmalloc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,8 @@ PyObject_Malloc(size_t nbytes)
688688
* last chance to serve the request) or when the max memory limit
689689
* has been reached.
690690
*/
691-
#ifdef MALLOC_ZERO_RETURNS_NULL
692691
if (nbytes == 0)
693692
nbytes = 1;
694-
#endif
695693
return (void *)malloc(nbytes);
696694
}
697695

RISCOS/pyconfig.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@
184184
/* Define if nice() returns success/failure instead of the new priority. */
185185
#undef HAVE_BROKEN_NICE
186186

187-
/* Define if malloc(0) returns a NULL pointer */
188-
#undef MALLOC_ZERO_RETURNS_NULL
189-
190187
/* Define if you have POSIX threads */
191188
#undef _POSIX_THREADS
192189

configure

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 1.370 .
2+
# From configure.in Revision: 1.371 .
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.53 for python 2.3.
55
#
@@ -15306,69 +15306,6 @@ done
1530615306
1530715307
LIBS=$LIBS_SAVE
1530815308
15309-
# check whether malloc(0) returns NULL or not
15310-
echo "$as_me:$LINENO: checking what malloc(0) returns" >&5
15311-
echo $ECHO_N "checking what malloc(0) returns... $ECHO_C" >&6
15312-
if test "${ac_cv_malloc_zero+set}" = set; then
15313-
echo $ECHO_N "(cached) $ECHO_C" >&6
15314-
else
15315-
if test "$cross_compiling" = yes; then
15316-
ac_cv_malloc_zero=nonnull
15317-
else
15318-
cat >conftest.$ac_ext <<_ACEOF
15319-
#line $LINENO "configure"
15320-
#include "confdefs.h"
15321-
#include <stdio.h>
15322-
#ifdef HAVE_STDLIB
15323-
#include <stdlib.h>
15324-
#else
15325-
char *malloc(), *realloc();
15326-
int *free();
15327-
#endif
15328-
main() {
15329-
char *p;
15330-
p = malloc(0);
15331-
if (p == NULL) exit(1);
15332-
p = realloc(p, 0);
15333-
if (p == NULL) exit(1);
15334-
free(p);
15335-
exit(0);
15336-
}
15337-
_ACEOF
15338-
rm -f conftest$ac_exeext
15339-
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
15340-
(eval $ac_link) 2>&5
15341-
ac_status=$?
15342-
echo "$as_me:$LINENO: \$? = $ac_status" >&5
15343-
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
15344-
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
15345-
(eval $ac_try) 2>&5
15346-
ac_status=$?
15347-
echo "$as_me:$LINENO: \$? = $ac_status" >&5
15348-
(exit $ac_status); }; }; then
15349-
ac_cv_malloc_zero=nonnull
15350-
else
15351-
echo "$as_me: program exited with status $ac_status" >&5
15352-
echo "$as_me: failed program was:" >&5
15353-
cat conftest.$ac_ext >&5
15354-
( exit $ac_status )
15355-
ac_cv_malloc_zero=null
15356-
fi
15357-
rm -f core core.* *.core conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
15358-
fi
15359-
fi
15360-
# XXX arm cross-compile?
15361-
echo "$as_me:$LINENO: result: $ac_cv_malloc_zero" >&5
15362-
echo "${ECHO_T}$ac_cv_malloc_zero" >&6
15363-
if test "$ac_cv_malloc_zero" = null
15364-
then
15365-
15366-
cat >>confdefs.h <<\_ACEOF
15367-
#define MALLOC_ZERO_RETURNS_NULL 1
15368-
_ACEOF
15369-
15370-
fi
15371-
1537215309
# check for wchar.h
1537315310
if test "${ac_cv_header_wchar_h+set}" = set; then
1537415311
echo "$as_me:$LINENO: checking for wchar.h" >&5

configure.in

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,35 +2243,6 @@ LIBS="$LIBS $LIBM"
22432243
AC_REPLACE_FUNCS(hypot)
22442244
LIBS=$LIBS_SAVE
22452245

2246-
# check whether malloc(0) returns NULL or not
2247-
AC_MSG_CHECKING(what malloc(0) returns)
2248-
AC_CACHE_VAL(ac_cv_malloc_zero,
2249-
[AC_TRY_RUN([#include <stdio.h>
2250-
#ifdef HAVE_STDLIB
2251-
#include <stdlib.h>
2252-
#else
2253-
char *malloc(), *realloc();
2254-
int *free();
2255-
#endif
2256-
main() {
2257-
char *p;
2258-
p = malloc(0);
2259-
if (p == NULL) exit(1);
2260-
p = realloc(p, 0);
2261-
if (p == NULL) exit(1);
2262-
free(p);
2263-
exit(0);
2264-
}],
2265-
ac_cv_malloc_zero=nonnull,
2266-
ac_cv_malloc_zero=null,
2267-
ac_cv_malloc_zero=nonnull)]) # XXX arm cross-compile?
2268-
AC_MSG_RESULT($ac_cv_malloc_zero)
2269-
if test "$ac_cv_malloc_zero" = null
2270-
then
2271-
AC_DEFINE(MALLOC_ZERO_RETURNS_NULL, 1,
2272-
[Define if malloc(0) returns a NULL pointer.])
2273-
fi
2274-
22752246
# check for wchar.h
22762247
AC_CHECK_HEADER(wchar.h, [
22772248
AC_DEFINE(HAVE_WCHAR_H, 1,

pyconfig.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,6 @@
603603
<sysmacros.h>. */
604604
#undef MAJOR_IN_SYSMACROS
605605

606-
/* Define if malloc(0) returns a NULL pointer. */
607-
#undef MALLOC_ZERO_RETURNS_NULL
608-
609606
/* Define if mvwdelch in curses.h is an expression. */
610607
#undef MVWDELCH_IS_EXPRESSION
611608

0 commit comments

Comments
 (0)