[New-bugs-announce] [issue4309] ctypes documentation

David W. Lambert report at bugs.python.org
Wed Nov 12 21:53:14 CET 2008


New submission from David W. Lambert <lambertdw at corning.com>:

'''
    http://docs.python.org/dev/3.0/library/ctypes.html

    Where web page says

    >>> printf("An int %d, a double %f\n", 1234, c_double(3.14))
    Integer 1234, double 3.1400001049
    31
    >>>

    should instead read
 
    >>> printf(c_char_p("An int %d, a double %f\n"), 1234, c_double(3.14))
    An int 1234, a double 3.140000
    31

    Although the intent of the message is clear, it is inexact with
    regard to "An int" and "a double".  Core dump is bigger problem:


    Processor: Dual-Core AMD Opteron(tm) Processor 2218
    Python: Python 3.0rc1+ (py3k, Nov  5 2008, 14:44:46) 
            [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2

    core dumps by segmentation fault for all the printf examples without
    specifying c_char_p("string").
'''

# this program succeeds

from ctypes import *
libc = CDLL("libc.so.6")
print(libc.printf(c_char_p("An int %d, a double %f\n"), 1234,
c_double(3.14)))

----------
assignee: georg.brandl
components: Documentation
messages: 75793
nosy: LambertDW, georg.brandl
severity: normal
status: open
title: ctypes documentation
type: crash
versions: Python 3.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4309>
_______________________________________


More information about the New-bugs-announce mailing list