pypy / lib_pypy / pypy_test / test_ctypes_support.py

The branch 'stm-gc' does not exist.
from __future__ import absolute_import

import py
from ctypes import *
try:
    from ctypes_support import standard_c_lib, get_errno, set_errno
except ImportError:    # on top of cpython
    from lib_pypy.ctypes_support import standard_c_lib, get_errno, set_errno


def test_stdlib_and_errno():
    py.test.skip("this is expected on top of pypy, we need to fix ctypes in a way that is now in 2.6 in order to make this reliable")
    write = standard_c_lib.write
    write.argtypes = [c_int, c_char_p, c_size_t]
    write.restype = c_size_t
    # clear errno first
    set_errno(0)
    assert get_errno() == 0
    write(-345, "abc", 3)
    assert get_errno() != 0
    set_errno(0)
    assert get_errno() == 0

def test_argument_conversion_and_checks():
    strlen = standard_c_lib.strlen
    strlen.argtypes = [c_char_p]
    strlen.restype = c_size_t
    assert strlen("eggs") == 4

    # Should raise ArgumentError, not segfault
    py.test.raises(ArgumentError, strlen, False)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.