Python CTypes translation of (pv != NULL)

p.lavarre at ieee.org p.lavarre at ieee.org
Fri Sep 29 01:47:21 CEST 2006


Future Googlers might like this thread to end with the Thomas Heller's
brief conclusive review:

/// Copied 2006-09-28 from
/// http://starship.python.net/crew/theller/moin.cgi/CodeSnippets

1.2 Check for NULL ctypes pointers

The truth value of any NULL ctypes pointer instance is False.

So, this C code

    if (pv == NULL)
        /* handle NULL pointer */
    else
        /* handle non-NULL pointer */

translates to this Python code

    if not pv:
        # handle NULL pointer
    else:
        # handle non-NULL pointer

The above is true for instances of c_void_p, c_char_p, c_wchar_p, and
POINTER(some_ctype).

///




More information about the Python-list mailing list