Python CTypes translation of (pv != NULL)

p.lavarre at ieee.org p.lavarre at ieee.org
Thu Sep 28 19:47:21 EDT 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