[Python-Dev] are NULL checks in Objects/abstract.c reallyneeded?

Tim Peters tim.one@comcast.net
Thu, 13 Mar 2003 16:20:52 -0500


[Skip Montanaro]
> It's not clear to me that you'd see any benefit anyway.  The checking code
> currently looks like this:
>
>     if (o == NULL)
>         return null_error();
>
> If you changed it to use assert you'd have
>
>     assert(o != NULL);
>
> which expands to
>
>     ((o != NULL) ? 0 : __assert(...));
> ...

In the release build, Python arranges to #define the preprocessor NDEBUG
symbol, which in turn causes assert() to expand to nothing (or maybe to
(void)0, or something like that, depending on the compiler).  That's
standard ANSI C behavior for assert().  IOW, asserts cost nothing in a
release build -- and don't do anything in a release build either.