Commit 4826a894 authored by Tim Peters's avatar Tim Peters

Close SF bug 110826: a complaint about the way Python #define'd NULL.

It's hard to sort out what the bug was, exactly.  So, Big Hammer:

1. Python shouldn't be in the business of #define'ing NULL, period.
2. Users of the Python C API shouldn't be in the business of not including
   Python.h, period.

Hence:

1. Removed all #define's of NULL in Python source code (pyport.h and
   object.h).
2. Since we're *relying* on stdio.h defining NULL, put an #error in
   Python.h after its #include of stdio.h if NULL isn't defined then.
parent ecaf0d8b
...@@ -36,6 +36,10 @@ ...@@ -36,6 +36,10 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#ifndef NULL
# error "Python.h requires that stdio.h define NULL."
#endif
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#ifdef HAVE_STDLIB_H #ifdef HAVE_STDLIB_H
......
...@@ -423,13 +423,6 @@ extern DL_IMPORT(long) _Py_RefTotal; ...@@ -423,13 +423,6 @@ extern DL_IMPORT(long) _Py_RefTotal;
#define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op) #define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op)
#define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op) #define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op)
/* Definition of NULL, so you don't have to include <stdio.h> */
#ifndef NULL
#define NULL 0
#endif
/* /*
_Py_NoneStruct is an object of undefined type which can be used in contexts _Py_NoneStruct is an object of undefined type which can be used in contexts
where NULL (nil) is not suitable (since NULL often means 'error'). where NULL (nil) is not suitable (since NULL often means 'error').
......
...@@ -313,10 +313,6 @@ extern double hypot(double, double); ...@@ -313,10 +313,6 @@ extern double hypot(double, double);
#define DL_IMPORT(RTYPE) RTYPE #define DL_IMPORT(RTYPE) RTYPE
#endif #endif
#ifndef NULL
#define NULL ((void *)0)
#endif
#ifdef MALLOC_ZERO_RETURNS_NULL #ifdef MALLOC_ZERO_RETURNS_NULL
/* XXX Always allocate one extra byte, since some malloc's return NULL /* XXX Always allocate one extra byte, since some malloc's return NULL
XXX for malloc(0) or realloc(p, 0). */ XXX for malloc(0) or realloc(p, 0). */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment