From f79bdee20cacc521d7ec3a8720a43087b47326d6 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Wed, 23 Sep 2015 20:45:19 -0700 Subject: Import gdb 7.10 linux-x86_64 prebuilt. Taken from aosp-master-ndk build 2274331. Bug: http://b/21920612 Change-Id: I2129ab5b85c96273bdb97ee9ca82116bb4db87fa --- lib/python2.7/ctypes/__init__.py | 555 +++++++++++++++++++++ lib/python2.7/ctypes/__init__.pyc | Bin 0 -> 23089 bytes lib/python2.7/ctypes/__init__.pyo | Bin 0 -> 23089 bytes lib/python2.7/ctypes/_endian.py | 64 +++ lib/python2.7/ctypes/_endian.pyc | Bin 0 -> 2589 bytes lib/python2.7/ctypes/_endian.pyo | Bin 0 -> 2589 bytes lib/python2.7/ctypes/macholib/README.ctypes | 7 + lib/python2.7/ctypes/macholib/__init__.py | 12 + lib/python2.7/ctypes/macholib/__init__.pyc | Bin 0 -> 363 bytes lib/python2.7/ctypes/macholib/__init__.pyo | Bin 0 -> 363 bytes lib/python2.7/ctypes/macholib/dyld.py | 169 +++++++ lib/python2.7/ctypes/macholib/dyld.pyc | Bin 0 -> 6539 bytes lib/python2.7/ctypes/macholib/dyld.pyo | Bin 0 -> 6333 bytes lib/python2.7/ctypes/macholib/dylib.py | 66 +++ lib/python2.7/ctypes/macholib/dylib.pyc | Bin 0 -> 2503 bytes lib/python2.7/ctypes/macholib/dylib.pyo | Bin 0 -> 1921 bytes lib/python2.7/ctypes/macholib/fetch_macholib | 2 + lib/python2.7/ctypes/macholib/fetch_macholib.bat | 1 + lib/python2.7/ctypes/macholib/framework.py | 68 +++ lib/python2.7/ctypes/macholib/framework.pyc | Bin 0 -> 2813 bytes lib/python2.7/ctypes/macholib/framework.pyo | Bin 0 -> 2063 bytes lib/python2.7/ctypes/test/__init__.py | 208 ++++++++ lib/python2.7/ctypes/test/__init__.pyc | Bin 0 -> 8459 bytes lib/python2.7/ctypes/test/__init__.pyo | Bin 0 -> 8459 bytes lib/python2.7/ctypes/test/runtests.py | 19 + lib/python2.7/ctypes/test/runtests.pyc | Bin 0 -> 941 bytes lib/python2.7/ctypes/test/runtests.pyo | Bin 0 -> 941 bytes lib/python2.7/ctypes/test/test_anon.py | 60 +++ lib/python2.7/ctypes/test/test_anon.pyc | Bin 0 -> 3768 bytes lib/python2.7/ctypes/test/test_anon.pyo | Bin 0 -> 3768 bytes lib/python2.7/ctypes/test/test_array_in_pointer.py | 64 +++ .../ctypes/test/test_array_in_pointer.pyc | Bin 0 -> 2589 bytes .../ctypes/test/test_array_in_pointer.pyo | Bin 0 -> 2589 bytes lib/python2.7/ctypes/test/test_arrays.py | 134 +++++ lib/python2.7/ctypes/test/test_arrays.pyc | Bin 0 -> 4704 bytes lib/python2.7/ctypes/test/test_arrays.pyo | Bin 0 -> 4704 bytes lib/python2.7/ctypes/test/test_as_parameter.py | 233 +++++++++ lib/python2.7/ctypes/test/test_as_parameter.pyc | Bin 0 -> 10398 bytes lib/python2.7/ctypes/test/test_as_parameter.pyo | Bin 0 -> 10398 bytes lib/python2.7/ctypes/test/test_bitfields.py | 264 ++++++++++ lib/python2.7/ctypes/test/test_bitfields.pyc | Bin 0 -> 14724 bytes lib/python2.7/ctypes/test/test_bitfields.pyo | Bin 0 -> 14724 bytes lib/python2.7/ctypes/test/test_buffers.py | 74 +++ lib/python2.7/ctypes/test/test_buffers.pyc | Bin 0 -> 3593 bytes lib/python2.7/ctypes/test/test_buffers.pyo | Bin 0 -> 3593 bytes lib/python2.7/ctypes/test/test_byteswap.py | 294 +++++++++++ lib/python2.7/ctypes/test/test_byteswap.pyc | Bin 0 -> 10860 bytes lib/python2.7/ctypes/test/test_byteswap.pyo | Bin 0 -> 10860 bytes lib/python2.7/ctypes/test/test_callbacks.py | 256 ++++++++++ lib/python2.7/ctypes/test/test_callbacks.pyc | Bin 0 -> 13154 bytes lib/python2.7/ctypes/test/test_callbacks.pyo | Bin 0 -> 13154 bytes lib/python2.7/ctypes/test/test_cast.py | 89 ++++ lib/python2.7/ctypes/test/test_cast.pyc | Bin 0 -> 4026 bytes lib/python2.7/ctypes/test/test_cast.pyo | Bin 0 -> 4026 bytes lib/python2.7/ctypes/test/test_cfuncs.py | 211 ++++++++ lib/python2.7/ctypes/test/test_cfuncs.pyc | Bin 0 -> 12405 bytes lib/python2.7/ctypes/test/test_cfuncs.pyo | Bin 0 -> 12405 bytes lib/python2.7/ctypes/test/test_checkretval.py | 39 ++ lib/python2.7/ctypes/test/test_checkretval.pyc | Bin 0 -> 1959 bytes lib/python2.7/ctypes/test/test_checkretval.pyo | Bin 0 -> 1959 bytes lib/python2.7/ctypes/test/test_delattr.py | 21 + lib/python2.7/ctypes/test/test_delattr.pyc | Bin 0 -> 1639 bytes lib/python2.7/ctypes/test/test_delattr.pyo | Bin 0 -> 1639 bytes lib/python2.7/ctypes/test/test_errcheck.py | 19 + lib/python2.7/ctypes/test/test_errcheck.pyc | Bin 0 -> 242 bytes lib/python2.7/ctypes/test/test_errcheck.pyo | Bin 0 -> 242 bytes lib/python2.7/ctypes/test/test_errno.py | 80 +++ lib/python2.7/ctypes/test/test_errno.pyc | Bin 0 -> 3188 bytes lib/python2.7/ctypes/test/test_errno.pyo | Bin 0 -> 3188 bytes lib/python2.7/ctypes/test/test_find.py | 82 +++ lib/python2.7/ctypes/test/test_find.pyc | Bin 0 -> 2345 bytes lib/python2.7/ctypes/test/test_find.pyo | Bin 0 -> 2345 bytes lib/python2.7/ctypes/test/test_frombuffer.py | 81 +++ lib/python2.7/ctypes/test/test_frombuffer.pyc | Bin 0 -> 4071 bytes lib/python2.7/ctypes/test/test_frombuffer.pyo | Bin 0 -> 4071 bytes lib/python2.7/ctypes/test/test_funcptr.py | 127 +++++ lib/python2.7/ctypes/test/test_funcptr.pyc | Bin 0 -> 4672 bytes lib/python2.7/ctypes/test/test_funcptr.pyo | Bin 0 -> 4672 bytes lib/python2.7/ctypes/test/test_functions.py | 412 +++++++++++++++ lib/python2.7/ctypes/test/test_functions.pyc | Bin 0 -> 17129 bytes lib/python2.7/ctypes/test/test_functions.pyo | Bin 0 -> 17129 bytes lib/python2.7/ctypes/test/test_incomplete.py | 42 ++ lib/python2.7/ctypes/test/test_incomplete.pyc | Bin 0 -> 1553 bytes lib/python2.7/ctypes/test/test_incomplete.pyo | Bin 0 -> 1553 bytes lib/python2.7/ctypes/test/test_init.py | 40 ++ lib/python2.7/ctypes/test/test_init.pyc | Bin 0 -> 2159 bytes lib/python2.7/ctypes/test/test_init.pyo | Bin 0 -> 2159 bytes lib/python2.7/ctypes/test/test_integers.py | 5 + lib/python2.7/ctypes/test/test_integers.pyc | Bin 0 -> 277 bytes lib/python2.7/ctypes/test/test_integers.pyo | Bin 0 -> 277 bytes lib/python2.7/ctypes/test/test_internals.py | 103 ++++ lib/python2.7/ctypes/test/test_internals.pyc | Bin 0 -> 4831 bytes lib/python2.7/ctypes/test/test_internals.pyo | Bin 0 -> 4831 bytes lib/python2.7/ctypes/test/test_keeprefs.py | 152 ++++++ lib/python2.7/ctypes/test/test_keeprefs.pyc | Bin 0 -> 7807 bytes lib/python2.7/ctypes/test/test_keeprefs.pyo | Bin 0 -> 7807 bytes lib/python2.7/ctypes/test/test_libc.py | 29 ++ lib/python2.7/ctypes/test/test_libc.pyc | Bin 0 -> 1873 bytes lib/python2.7/ctypes/test/test_libc.pyo | Bin 0 -> 1873 bytes lib/python2.7/ctypes/test/test_loading.py | 106 ++++ lib/python2.7/ctypes/test/test_loading.pyc | Bin 0 -> 4360 bytes lib/python2.7/ctypes/test/test_loading.pyo | Bin 0 -> 4360 bytes lib/python2.7/ctypes/test/test_macholib.py | 62 +++ lib/python2.7/ctypes/test/test_macholib.pyc | Bin 0 -> 1682 bytes lib/python2.7/ctypes/test/test_macholib.pyo | Bin 0 -> 1682 bytes lib/python2.7/ctypes/test/test_memfunctions.py | 79 +++ lib/python2.7/ctypes/test/test_memfunctions.pyc | Bin 0 -> 3385 bytes lib/python2.7/ctypes/test/test_memfunctions.pyo | Bin 0 -> 3385 bytes lib/python2.7/ctypes/test/test_numbers.py | 286 +++++++++++ lib/python2.7/ctypes/test/test_numbers.pyc | Bin 0 -> 10838 bytes lib/python2.7/ctypes/test/test_numbers.pyo | Bin 0 -> 10838 bytes lib/python2.7/ctypes/test/test_objects.py | 70 +++ lib/python2.7/ctypes/test/test_objects.pyc | Bin 0 -> 2314 bytes lib/python2.7/ctypes/test/test_objects.pyo | Bin 0 -> 2314 bytes lib/python2.7/ctypes/test/test_parameters.py | 188 +++++++ lib/python2.7/ctypes/test/test_parameters.pyc | Bin 0 -> 8919 bytes lib/python2.7/ctypes/test/test_parameters.pyo | Bin 0 -> 8919 bytes lib/python2.7/ctypes/test/test_pep3118.py | 196 ++++++++ lib/python2.7/ctypes/test/test_pep3118.pyc | Bin 0 -> 6199 bytes lib/python2.7/ctypes/test/test_pep3118.pyo | Bin 0 -> 6199 bytes lib/python2.7/ctypes/test/test_pickling.py | 83 +++ lib/python2.7/ctypes/test/test_pickling.pyc | Bin 0 -> 5093 bytes lib/python2.7/ctypes/test/test_pickling.pyo | Bin 0 -> 5093 bytes lib/python2.7/ctypes/test/test_pointers.py | 192 +++++++ lib/python2.7/ctypes/test/test_pointers.pyc | Bin 0 -> 7456 bytes lib/python2.7/ctypes/test/test_pointers.pyo | Bin 0 -> 7413 bytes lib/python2.7/ctypes/test/test_prototypes.py | 221 ++++++++ lib/python2.7/ctypes/test/test_prototypes.pyc | Bin 0 -> 7875 bytes lib/python2.7/ctypes/test/test_prototypes.pyo | Bin 0 -> 7836 bytes lib/python2.7/ctypes/test/test_python_api.py | 90 ++++ lib/python2.7/ctypes/test/test_python_api.pyc | Bin 0 -> 3702 bytes lib/python2.7/ctypes/test/test_python_api.pyo | Bin 0 -> 3702 bytes lib/python2.7/ctypes/test/test_random_things.py | 75 +++ lib/python2.7/ctypes/test/test_random_things.pyc | Bin 0 -> 3711 bytes lib/python2.7/ctypes/test/test_random_things.pyo | Bin 0 -> 3711 bytes lib/python2.7/ctypes/test/test_refcounts.py | 98 ++++ lib/python2.7/ctypes/test/test_refcounts.pyc | Bin 0 -> 3591 bytes lib/python2.7/ctypes/test/test_refcounts.pyo | Bin 0 -> 3591 bytes lib/python2.7/ctypes/test/test_repr.py | 29 ++ lib/python2.7/ctypes/test/test_repr.pyc | Bin 0 -> 2028 bytes lib/python2.7/ctypes/test/test_repr.pyo | Bin 0 -> 2028 bytes lib/python2.7/ctypes/test/test_returnfuncptrs.py | 65 +++ lib/python2.7/ctypes/test/test_returnfuncptrs.pyc | Bin 0 -> 3262 bytes lib/python2.7/ctypes/test/test_returnfuncptrs.pyo | Bin 0 -> 3262 bytes lib/python2.7/ctypes/test/test_simplesubclasses.py | 57 +++ .../ctypes/test/test_simplesubclasses.pyc | Bin 0 -> 3467 bytes .../ctypes/test/test_simplesubclasses.pyo | Bin 0 -> 3467 bytes lib/python2.7/ctypes/test/test_sizes.py | 34 ++ lib/python2.7/ctypes/test/test_sizes.pyc | Bin 0 -> 2236 bytes lib/python2.7/ctypes/test/test_sizes.pyo | Bin 0 -> 2236 bytes lib/python2.7/ctypes/test/test_slicing.py | 178 +++++++ lib/python2.7/ctypes/test/test_slicing.pyc | Bin 0 -> 6890 bytes lib/python2.7/ctypes/test/test_slicing.pyo | Bin 0 -> 6890 bytes lib/python2.7/ctypes/test/test_stringptr.py | 75 +++ lib/python2.7/ctypes/test/test_stringptr.pyc | Bin 0 -> 3007 bytes lib/python2.7/ctypes/test/test_stringptr.pyo | Bin 0 -> 3007 bytes lib/python2.7/ctypes/test/test_strings.py | 225 +++++++++ lib/python2.7/ctypes/test/test_strings.pyc | Bin 0 -> 8296 bytes lib/python2.7/ctypes/test/test_strings.pyo | Bin 0 -> 8296 bytes lib/python2.7/ctypes/test/test_struct_fields.py | 50 ++ lib/python2.7/ctypes/test/test_struct_fields.pyc | Bin 0 -> 3615 bytes lib/python2.7/ctypes/test/test_struct_fields.pyo | Bin 0 -> 3615 bytes lib/python2.7/ctypes/test/test_structures.py | 478 ++++++++++++++++++ lib/python2.7/ctypes/test/test_structures.pyc | Bin 0 -> 26260 bytes lib/python2.7/ctypes/test/test_structures.pyo | Bin 0 -> 26260 bytes .../ctypes/test/test_unaligned_structures.py | 45 ++ .../ctypes/test/test_unaligned_structures.pyc | Bin 0 -> 2360 bytes .../ctypes/test/test_unaligned_structures.pyo | Bin 0 -> 2360 bytes lib/python2.7/ctypes/test/test_unicode.py | 129 +++++ lib/python2.7/ctypes/test/test_unicode.pyc | Bin 0 -> 6361 bytes lib/python2.7/ctypes/test/test_unicode.pyo | Bin 0 -> 6361 bytes lib/python2.7/ctypes/test/test_values.py | 82 +++ lib/python2.7/ctypes/test/test_values.pyc | Bin 0 -> 3542 bytes lib/python2.7/ctypes/test/test_values.pyo | Bin 0 -> 3600 bytes lib/python2.7/ctypes/test/test_varsize_struct.py | 50 ++ lib/python2.7/ctypes/test/test_varsize_struct.pyc | Bin 0 -> 2795 bytes lib/python2.7/ctypes/test/test_varsize_struct.pyo | Bin 0 -> 2795 bytes lib/python2.7/ctypes/test/test_win32.py | 93 ++++ lib/python2.7/ctypes/test/test_win32.pyc | Bin 0 -> 4979 bytes lib/python2.7/ctypes/test/test_win32.pyo | Bin 0 -> 4979 bytes lib/python2.7/ctypes/test/test_wintypes.py | 43 ++ lib/python2.7/ctypes/test/test_wintypes.pyc | Bin 0 -> 1772 bytes lib/python2.7/ctypes/test/test_wintypes.pyo | Bin 0 -> 1772 bytes lib/python2.7/ctypes/util.py | 290 +++++++++++ lib/python2.7/ctypes/util.pyc | Bin 0 -> 8782 bytes lib/python2.7/ctypes/util.pyo | Bin 0 -> 8782 bytes lib/python2.7/ctypes/wintypes.py | 185 +++++++ lib/python2.7/ctypes/wintypes.pyc | Bin 0 -> 6566 bytes lib/python2.7/ctypes/wintypes.pyo | Bin 0 -> 6566 bytes 189 files changed, 7936 insertions(+) create mode 100644 lib/python2.7/ctypes/__init__.py create mode 100644 lib/python2.7/ctypes/__init__.pyc create mode 100644 lib/python2.7/ctypes/__init__.pyo create mode 100644 lib/python2.7/ctypes/_endian.py create mode 100644 lib/python2.7/ctypes/_endian.pyc create mode 100644 lib/python2.7/ctypes/_endian.pyo create mode 100644 lib/python2.7/ctypes/macholib/README.ctypes create mode 100644 lib/python2.7/ctypes/macholib/__init__.py create mode 100644 lib/python2.7/ctypes/macholib/__init__.pyc create mode 100644 lib/python2.7/ctypes/macholib/__init__.pyo create mode 100644 lib/python2.7/ctypes/macholib/dyld.py create mode 100644 lib/python2.7/ctypes/macholib/dyld.pyc create mode 100644 lib/python2.7/ctypes/macholib/dyld.pyo create mode 100644 lib/python2.7/ctypes/macholib/dylib.py create mode 100644 lib/python2.7/ctypes/macholib/dylib.pyc create mode 100644 lib/python2.7/ctypes/macholib/dylib.pyo create mode 100755 lib/python2.7/ctypes/macholib/fetch_macholib create mode 100644 lib/python2.7/ctypes/macholib/fetch_macholib.bat create mode 100644 lib/python2.7/ctypes/macholib/framework.py create mode 100644 lib/python2.7/ctypes/macholib/framework.pyc create mode 100644 lib/python2.7/ctypes/macholib/framework.pyo create mode 100644 lib/python2.7/ctypes/test/__init__.py create mode 100644 lib/python2.7/ctypes/test/__init__.pyc create mode 100644 lib/python2.7/ctypes/test/__init__.pyo create mode 100644 lib/python2.7/ctypes/test/runtests.py create mode 100644 lib/python2.7/ctypes/test/runtests.pyc create mode 100644 lib/python2.7/ctypes/test/runtests.pyo create mode 100644 lib/python2.7/ctypes/test/test_anon.py create mode 100644 lib/python2.7/ctypes/test/test_anon.pyc create mode 100644 lib/python2.7/ctypes/test/test_anon.pyo create mode 100644 lib/python2.7/ctypes/test/test_array_in_pointer.py create mode 100644 lib/python2.7/ctypes/test/test_array_in_pointer.pyc create mode 100644 lib/python2.7/ctypes/test/test_array_in_pointer.pyo create mode 100644 lib/python2.7/ctypes/test/test_arrays.py create mode 100644 lib/python2.7/ctypes/test/test_arrays.pyc create mode 100644 lib/python2.7/ctypes/test/test_arrays.pyo create mode 100644 lib/python2.7/ctypes/test/test_as_parameter.py create mode 100644 lib/python2.7/ctypes/test/test_as_parameter.pyc create mode 100644 lib/python2.7/ctypes/test/test_as_parameter.pyo create mode 100644 lib/python2.7/ctypes/test/test_bitfields.py create mode 100644 lib/python2.7/ctypes/test/test_bitfields.pyc create mode 100644 lib/python2.7/ctypes/test/test_bitfields.pyo create mode 100644 lib/python2.7/ctypes/test/test_buffers.py create mode 100644 lib/python2.7/ctypes/test/test_buffers.pyc create mode 100644 lib/python2.7/ctypes/test/test_buffers.pyo create mode 100644 lib/python2.7/ctypes/test/test_byteswap.py create mode 100644 lib/python2.7/ctypes/test/test_byteswap.pyc create mode 100644 lib/python2.7/ctypes/test/test_byteswap.pyo create mode 100644 lib/python2.7/ctypes/test/test_callbacks.py create mode 100644 lib/python2.7/ctypes/test/test_callbacks.pyc create mode 100644 lib/python2.7/ctypes/test/test_callbacks.pyo create mode 100644 lib/python2.7/ctypes/test/test_cast.py create mode 100644 lib/python2.7/ctypes/test/test_cast.pyc create mode 100644 lib/python2.7/ctypes/test/test_cast.pyo create mode 100644 lib/python2.7/ctypes/test/test_cfuncs.py create mode 100644 lib/python2.7/ctypes/test/test_cfuncs.pyc create mode 100644 lib/python2.7/ctypes/test/test_cfuncs.pyo create mode 100644 lib/python2.7/ctypes/test/test_checkretval.py create mode 100644 lib/python2.7/ctypes/test/test_checkretval.pyc create mode 100644 lib/python2.7/ctypes/test/test_checkretval.pyo create mode 100644 lib/python2.7/ctypes/test/test_delattr.py create mode 100644 lib/python2.7/ctypes/test/test_delattr.pyc create mode 100644 lib/python2.7/ctypes/test/test_delattr.pyo create mode 100644 lib/python2.7/ctypes/test/test_errcheck.py create mode 100644 lib/python2.7/ctypes/test/test_errcheck.pyc create mode 100644 lib/python2.7/ctypes/test/test_errcheck.pyo create mode 100644 lib/python2.7/ctypes/test/test_errno.py create mode 100644 lib/python2.7/ctypes/test/test_errno.pyc create mode 100644 lib/python2.7/ctypes/test/test_errno.pyo create mode 100644 lib/python2.7/ctypes/test/test_find.py create mode 100644 lib/python2.7/ctypes/test/test_find.pyc create mode 100644 lib/python2.7/ctypes/test/test_find.pyo create mode 100644 lib/python2.7/ctypes/test/test_frombuffer.py create mode 100644 lib/python2.7/ctypes/test/test_frombuffer.pyc create mode 100644 lib/python2.7/ctypes/test/test_frombuffer.pyo create mode 100644 lib/python2.7/ctypes/test/test_funcptr.py create mode 100644 lib/python2.7/ctypes/test/test_funcptr.pyc create mode 100644 lib/python2.7/ctypes/test/test_funcptr.pyo create mode 100644 lib/python2.7/ctypes/test/test_functions.py create mode 100644 lib/python2.7/ctypes/test/test_functions.pyc create mode 100644 lib/python2.7/ctypes/test/test_functions.pyo create mode 100644 lib/python2.7/ctypes/test/test_incomplete.py create mode 100644 lib/python2.7/ctypes/test/test_incomplete.pyc create mode 100644 lib/python2.7/ctypes/test/test_incomplete.pyo create mode 100644 lib/python2.7/ctypes/test/test_init.py create mode 100644 lib/python2.7/ctypes/test/test_init.pyc create mode 100644 lib/python2.7/ctypes/test/test_init.pyo create mode 100644 lib/python2.7/ctypes/test/test_integers.py create mode 100644 lib/python2.7/ctypes/test/test_integers.pyc create mode 100644 lib/python2.7/ctypes/test/test_integers.pyo create mode 100644 lib/python2.7/ctypes/test/test_internals.py create mode 100644 lib/python2.7/ctypes/test/test_internals.pyc create mode 100644 lib/python2.7/ctypes/test/test_internals.pyo create mode 100644 lib/python2.7/ctypes/test/test_keeprefs.py create mode 100644 lib/python2.7/ctypes/test/test_keeprefs.pyc create mode 100644 lib/python2.7/ctypes/test/test_keeprefs.pyo create mode 100644 lib/python2.7/ctypes/test/test_libc.py create mode 100644 lib/python2.7/ctypes/test/test_libc.pyc create mode 100644 lib/python2.7/ctypes/test/test_libc.pyo create mode 100644 lib/python2.7/ctypes/test/test_loading.py create mode 100644 lib/python2.7/ctypes/test/test_loading.pyc create mode 100644 lib/python2.7/ctypes/test/test_loading.pyo create mode 100644 lib/python2.7/ctypes/test/test_macholib.py create mode 100644 lib/python2.7/ctypes/test/test_macholib.pyc create mode 100644 lib/python2.7/ctypes/test/test_macholib.pyo create mode 100644 lib/python2.7/ctypes/test/test_memfunctions.py create mode 100644 lib/python2.7/ctypes/test/test_memfunctions.pyc create mode 100644 lib/python2.7/ctypes/test/test_memfunctions.pyo create mode 100644 lib/python2.7/ctypes/test/test_numbers.py create mode 100644 lib/python2.7/ctypes/test/test_numbers.pyc create mode 100644 lib/python2.7/ctypes/test/test_numbers.pyo create mode 100644 lib/python2.7/ctypes/test/test_objects.py create mode 100644 lib/python2.7/ctypes/test/test_objects.pyc create mode 100644 lib/python2.7/ctypes/test/test_objects.pyo create mode 100644 lib/python2.7/ctypes/test/test_parameters.py create mode 100644 lib/python2.7/ctypes/test/test_parameters.pyc create mode 100644 lib/python2.7/ctypes/test/test_parameters.pyo create mode 100644 lib/python2.7/ctypes/test/test_pep3118.py create mode 100644 lib/python2.7/ctypes/test/test_pep3118.pyc create mode 100644 lib/python2.7/ctypes/test/test_pep3118.pyo create mode 100644 lib/python2.7/ctypes/test/test_pickling.py create mode 100644 lib/python2.7/ctypes/test/test_pickling.pyc create mode 100644 lib/python2.7/ctypes/test/test_pickling.pyo create mode 100644 lib/python2.7/ctypes/test/test_pointers.py create mode 100644 lib/python2.7/ctypes/test/test_pointers.pyc create mode 100644 lib/python2.7/ctypes/test/test_pointers.pyo create mode 100644 lib/python2.7/ctypes/test/test_prototypes.py create mode 100644 lib/python2.7/ctypes/test/test_prototypes.pyc create mode 100644 lib/python2.7/ctypes/test/test_prototypes.pyo create mode 100644 lib/python2.7/ctypes/test/test_python_api.py create mode 100644 lib/python2.7/ctypes/test/test_python_api.pyc create mode 100644 lib/python2.7/ctypes/test/test_python_api.pyo create mode 100644 lib/python2.7/ctypes/test/test_random_things.py create mode 100644 lib/python2.7/ctypes/test/test_random_things.pyc create mode 100644 lib/python2.7/ctypes/test/test_random_things.pyo create mode 100644 lib/python2.7/ctypes/test/test_refcounts.py create mode 100644 lib/python2.7/ctypes/test/test_refcounts.pyc create mode 100644 lib/python2.7/ctypes/test/test_refcounts.pyo create mode 100644 lib/python2.7/ctypes/test/test_repr.py create mode 100644 lib/python2.7/ctypes/test/test_repr.pyc create mode 100644 lib/python2.7/ctypes/test/test_repr.pyo create mode 100644 lib/python2.7/ctypes/test/test_returnfuncptrs.py create mode 100644 lib/python2.7/ctypes/test/test_returnfuncptrs.pyc create mode 100644 lib/python2.7/ctypes/test/test_returnfuncptrs.pyo create mode 100644 lib/python2.7/ctypes/test/test_simplesubclasses.py create mode 100644 lib/python2.7/ctypes/test/test_simplesubclasses.pyc create mode 100644 lib/python2.7/ctypes/test/test_simplesubclasses.pyo create mode 100644 lib/python2.7/ctypes/test/test_sizes.py create mode 100644 lib/python2.7/ctypes/test/test_sizes.pyc create mode 100644 lib/python2.7/ctypes/test/test_sizes.pyo create mode 100644 lib/python2.7/ctypes/test/test_slicing.py create mode 100644 lib/python2.7/ctypes/test/test_slicing.pyc create mode 100644 lib/python2.7/ctypes/test/test_slicing.pyo create mode 100644 lib/python2.7/ctypes/test/test_stringptr.py create mode 100644 lib/python2.7/ctypes/test/test_stringptr.pyc create mode 100644 lib/python2.7/ctypes/test/test_stringptr.pyo create mode 100644 lib/python2.7/ctypes/test/test_strings.py create mode 100644 lib/python2.7/ctypes/test/test_strings.pyc create mode 100644 lib/python2.7/ctypes/test/test_strings.pyo create mode 100644 lib/python2.7/ctypes/test/test_struct_fields.py create mode 100644 lib/python2.7/ctypes/test/test_struct_fields.pyc create mode 100644 lib/python2.7/ctypes/test/test_struct_fields.pyo create mode 100644 lib/python2.7/ctypes/test/test_structures.py create mode 100644 lib/python2.7/ctypes/test/test_structures.pyc create mode 100644 lib/python2.7/ctypes/test/test_structures.pyo create mode 100644 lib/python2.7/ctypes/test/test_unaligned_structures.py create mode 100644 lib/python2.7/ctypes/test/test_unaligned_structures.pyc create mode 100644 lib/python2.7/ctypes/test/test_unaligned_structures.pyo create mode 100644 lib/python2.7/ctypes/test/test_unicode.py create mode 100644 lib/python2.7/ctypes/test/test_unicode.pyc create mode 100644 lib/python2.7/ctypes/test/test_unicode.pyo create mode 100644 lib/python2.7/ctypes/test/test_values.py create mode 100644 lib/python2.7/ctypes/test/test_values.pyc create mode 100644 lib/python2.7/ctypes/test/test_values.pyo create mode 100644 lib/python2.7/ctypes/test/test_varsize_struct.py create mode 100644 lib/python2.7/ctypes/test/test_varsize_struct.pyc create mode 100644 lib/python2.7/ctypes/test/test_varsize_struct.pyo create mode 100644 lib/python2.7/ctypes/test/test_win32.py create mode 100644 lib/python2.7/ctypes/test/test_win32.pyc create mode 100644 lib/python2.7/ctypes/test/test_win32.pyo create mode 100644 lib/python2.7/ctypes/test/test_wintypes.py create mode 100644 lib/python2.7/ctypes/test/test_wintypes.pyc create mode 100644 lib/python2.7/ctypes/test/test_wintypes.pyo create mode 100644 lib/python2.7/ctypes/util.py create mode 100644 lib/python2.7/ctypes/util.pyc create mode 100644 lib/python2.7/ctypes/util.pyo create mode 100644 lib/python2.7/ctypes/wintypes.py create mode 100644 lib/python2.7/ctypes/wintypes.pyc create mode 100644 lib/python2.7/ctypes/wintypes.pyo (limited to 'lib/python2.7/ctypes') diff --git a/lib/python2.7/ctypes/__init__.py b/lib/python2.7/ctypes/__init__.py new file mode 100644 index 0000000..4e97c15 --- /dev/null +++ b/lib/python2.7/ctypes/__init__.py @@ -0,0 +1,555 @@ +###################################################################### +# This file should be kept compatible with Python 2.3, see PEP 291. # +###################################################################### +"""create and manipulate C data types in Python""" + +import os as _os, sys as _sys + +__version__ = "1.1.0" + +from _ctypes import Union, Structure, Array +from _ctypes import _Pointer +from _ctypes import CFuncPtr as _CFuncPtr +from _ctypes import __version__ as _ctypes_version +from _ctypes import RTLD_LOCAL, RTLD_GLOBAL +from _ctypes import ArgumentError + +from struct import calcsize as _calcsize + +if __version__ != _ctypes_version: + raise Exception("Version number mismatch", __version__, _ctypes_version) + +if _os.name in ("nt", "ce"): + from _ctypes import FormatError + +DEFAULT_MODE = RTLD_LOCAL +if _os.name == "posix" and _sys.platform == "darwin": + # On OS X 10.3, we use RTLD_GLOBAL as default mode + # because RTLD_LOCAL does not work at least on some + # libraries. OS X 10.3 is Darwin 7, so we check for + # that. + + if int(_os.uname()[2].split('.')[0]) < 8: + DEFAULT_MODE = RTLD_GLOBAL + +from _ctypes import FUNCFLAG_CDECL as _FUNCFLAG_CDECL, \ + FUNCFLAG_PYTHONAPI as _FUNCFLAG_PYTHONAPI, \ + FUNCFLAG_USE_ERRNO as _FUNCFLAG_USE_ERRNO, \ + FUNCFLAG_USE_LASTERROR as _FUNCFLAG_USE_LASTERROR + +""" +WINOLEAPI -> HRESULT +WINOLEAPI_(type) + +STDMETHODCALLTYPE + +STDMETHOD(name) +STDMETHOD_(type, name) + +STDAPICALLTYPE +""" + +def create_string_buffer(init, size=None): + """create_string_buffer(aString) -> character array + create_string_buffer(anInteger) -> character array + create_string_buffer(aString, anInteger) -> character array + """ + if isinstance(init, (str, unicode)): + if size is None: + size = len(init)+1 + buftype = c_char * size + buf = buftype() + buf.value = init + return buf + elif isinstance(init, (int, long)): + buftype = c_char * init + buf = buftype() + return buf + raise TypeError(init) + +def c_buffer(init, size=None): +## "deprecated, use create_string_buffer instead" +## import warnings +## warnings.warn("c_buffer is deprecated, use create_string_buffer instead", +## DeprecationWarning, stacklevel=2) + return create_string_buffer(init, size) + +_c_functype_cache = {} +def CFUNCTYPE(restype, *argtypes, **kw): + """CFUNCTYPE(restype, *argtypes, + use_errno=False, use_last_error=False) -> function prototype. + + restype: the result type + argtypes: a sequence specifying the argument types + + The function prototype can be called in different ways to create a + callable object: + + prototype(integer address) -> foreign function + prototype(callable) -> create and return a C callable function from callable + prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method + prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal + prototype((function name, dll object)[, paramflags]) -> foreign function exported by name + """ + flags = _FUNCFLAG_CDECL + if kw.pop("use_errno", False): + flags |= _FUNCFLAG_USE_ERRNO + if kw.pop("use_last_error", False): + flags |= _FUNCFLAG_USE_LASTERROR + if kw: + raise ValueError("unexpected keyword argument(s) %s" % kw.keys()) + try: + return _c_functype_cache[(restype, argtypes, flags)] + except KeyError: + class CFunctionType(_CFuncPtr): + _argtypes_ = argtypes + _restype_ = restype + _flags_ = flags + _c_functype_cache[(restype, argtypes, flags)] = CFunctionType + return CFunctionType + +if _os.name in ("nt", "ce"): + from _ctypes import LoadLibrary as _dlopen + from _ctypes import FUNCFLAG_STDCALL as _FUNCFLAG_STDCALL + if _os.name == "ce": + # 'ce' doesn't have the stdcall calling convention + _FUNCFLAG_STDCALL = _FUNCFLAG_CDECL + + _win_functype_cache = {} + def WINFUNCTYPE(restype, *argtypes, **kw): + # docstring set later (very similar to CFUNCTYPE.__doc__) + flags = _FUNCFLAG_STDCALL + if kw.pop("use_errno", False): + flags |= _FUNCFLAG_USE_ERRNO + if kw.pop("use_last_error", False): + flags |= _FUNCFLAG_USE_LASTERROR + if kw: + raise ValueError("unexpected keyword argument(s) %s" % kw.keys()) + try: + return _win_functype_cache[(restype, argtypes, flags)] + except KeyError: + class WinFunctionType(_CFuncPtr): + _argtypes_ = argtypes + _restype_ = restype + _flags_ = flags + _win_functype_cache[(restype, argtypes, flags)] = WinFunctionType + return WinFunctionType + if WINFUNCTYPE.__doc__: + WINFUNCTYPE.__doc__ = CFUNCTYPE.__doc__.replace("CFUNCTYPE", "WINFUNCTYPE") + +elif _os.name == "posix": + from _ctypes import dlopen as _dlopen + +from _ctypes import sizeof, byref, addressof, alignment, resize +from _ctypes import get_errno, set_errno +from _ctypes import _SimpleCData + +def _check_size(typ, typecode=None): + # Check if sizeof(ctypes_type) against struct.calcsize. This + # should protect somewhat against a misconfigured libffi. + from struct import calcsize + if typecode is None: + # Most _type_ codes are the same as used in struct + typecode = typ._type_ + actual, required = sizeof(typ), calcsize(typecode) + if actual != required: + raise SystemError("sizeof(%s) wrong: %d instead of %d" % \ + (typ, actual, required)) + +class py_object(_SimpleCData): + _type_ = "O" + def __repr__(self): + try: + return super(py_object, self).__repr__() + except ValueError: + return "%s()" % type(self).__name__ +_check_size(py_object, "P") + +class c_short(_SimpleCData): + _type_ = "h" +_check_size(c_short) + +class c_ushort(_SimpleCData): + _type_ = "H" +_check_size(c_ushort) + +class c_long(_SimpleCData): + _type_ = "l" +_check_size(c_long) + +class c_ulong(_SimpleCData): + _type_ = "L" +_check_size(c_ulong) + +if _calcsize("i") == _calcsize("l"): + # if int and long have the same size, make c_int an alias for c_long + c_int = c_long + c_uint = c_ulong +else: + class c_int(_SimpleCData): + _type_ = "i" + _check_size(c_int) + + class c_uint(_SimpleCData): + _type_ = "I" + _check_size(c_uint) + +class c_float(_SimpleCData): + _type_ = "f" +_check_size(c_float) + +class c_double(_SimpleCData): + _type_ = "d" +_check_size(c_double) + +class c_longdouble(_SimpleCData): + _type_ = "g" +if sizeof(c_longdouble) == sizeof(c_double): + c_longdouble = c_double + +if _calcsize("l") == _calcsize("q"): + # if long and long long have the same size, make c_longlong an alias for c_long + c_longlong = c_long + c_ulonglong = c_ulong +else: + class c_longlong(_SimpleCData): + _type_ = "q" + _check_size(c_longlong) + + class c_ulonglong(_SimpleCData): + _type_ = "Q" + ## def from_param(cls, val): + ## return ('d', float(val), val) + ## from_param = classmethod(from_param) + _check_size(c_ulonglong) + +class c_ubyte(_SimpleCData): + _type_ = "B" +c_ubyte.__ctype_le__ = c_ubyte.__ctype_be__ = c_ubyte +# backward compatibility: +##c_uchar = c_ubyte +_check_size(c_ubyte) + +class c_byte(_SimpleCData): + _type_ = "b" +c_byte.__ctype_le__ = c_byte.__ctype_be__ = c_byte +_check_size(c_byte) + +class c_char(_SimpleCData): + _type_ = "c" +c_char.__ctype_le__ = c_char.__ctype_be__ = c_char +_check_size(c_char) + +class c_char_p(_SimpleCData): + _type_ = "z" + if _os.name == "nt": + def __repr__(self): + if not windll.kernel32.IsBadStringPtrA(self, -1): + return "%s(%r)" % (self.__class__.__name__, self.value) + return "%s(%s)" % (self.__class__.__name__, cast(self, c_void_p).value) + else: + def __repr__(self): + return "%s(%s)" % (self.__class__.__name__, cast(self, c_void_p).value) +_check_size(c_char_p, "P") + +class c_void_p(_SimpleCData): + _type_ = "P" +c_voidp = c_void_p # backwards compatibility (to a bug) +_check_size(c_void_p) + +class c_bool(_SimpleCData): + _type_ = "?" + +from _ctypes import POINTER, pointer, _pointer_type_cache + +def _reset_cache(): + _pointer_type_cache.clear() + _c_functype_cache.clear() + if _os.name in ("nt", "ce"): + _win_functype_cache.clear() + # _SimpleCData.c_wchar_p_from_param + POINTER(c_wchar).from_param = c_wchar_p.from_param + # _SimpleCData.c_char_p_from_param + POINTER(c_char).from_param = c_char_p.from_param + _pointer_type_cache[None] = c_void_p + # XXX for whatever reasons, creating the first instance of a callback + # function is needed for the unittests on Win64 to succeed. This MAY + # be a compiler bug, since the problem occurs only when _ctypes is + # compiled with the MS SDK compiler. Or an uninitialized variable? + CFUNCTYPE(c_int)(lambda: None) + +try: + from _ctypes import set_conversion_mode +except ImportError: + pass +else: + if _os.name in ("nt", "ce"): + set_conversion_mode("mbcs", "ignore") + else: + set_conversion_mode("ascii", "strict") + + class c_wchar_p(_SimpleCData): + _type_ = "Z" + + class c_wchar(_SimpleCData): + _type_ = "u" + + def create_unicode_buffer(init, size=None): + """create_unicode_buffer(aString) -> character array + create_unicode_buffer(anInteger) -> character array + create_unicode_buffer(aString, anInteger) -> character array + """ + if isinstance(init, (str, unicode)): + if size is None: + size = len(init)+1 + buftype = c_wchar * size + buf = buftype() + buf.value = init + return buf + elif isinstance(init, (int, long)): + buftype = c_wchar * init + buf = buftype() + return buf + raise TypeError(init) + +# XXX Deprecated +def SetPointerType(pointer, cls): + if _pointer_type_cache.get(cls, None) is not None: + raise RuntimeError("This type already exists in the cache") + if id(pointer) not in _pointer_type_cache: + raise RuntimeError("What's this???") + pointer.set_type(cls) + _pointer_type_cache[cls] = pointer + del _pointer_type_cache[id(pointer)] + +# XXX Deprecated +def ARRAY(typ, len): + return typ * len + +################################################################ + + +class CDLL(object): + """An instance of this class represents a loaded dll/shared + library, exporting functions using the standard C calling + convention (named 'cdecl' on Windows). + + The exported functions can be accessed as attributes, or by + indexing with the function name. Examples: + + .qsort -> callable object + ['qsort'] -> callable object + + Calling the functions releases the Python GIL during the call and + reacquires it afterwards. + """ + _func_flags_ = _FUNCFLAG_CDECL + _func_restype_ = c_int + + def __init__(self, name, mode=DEFAULT_MODE, handle=None, + use_errno=False, + use_last_error=False): + self._name = name + flags = self._func_flags_ + if use_errno: + flags |= _FUNCFLAG_USE_ERRNO + if use_last_error: + flags |= _FUNCFLAG_USE_LASTERROR + + class _FuncPtr(_CFuncPtr): + _flags_ = flags + _restype_ = self._func_restype_ + self._FuncPtr = _FuncPtr + + if handle is None: + self._handle = _dlopen(self._name, mode) + else: + self._handle = handle + + def __repr__(self): + return "<%s '%s', handle %x at %x>" % \ + (self.__class__.__name__, self._name, + (self._handle & (_sys.maxint*2 + 1)), + id(self) & (_sys.maxint*2 + 1)) + + def __getattr__(self, name): + if name.startswith('__') and name.endswith('__'): + raise AttributeError(name) + func = self.__getitem__(name) + setattr(self, name, func) + return func + + def __getitem__(self, name_or_ordinal): + func = self._FuncPtr((name_or_ordinal, self)) + if not isinstance(name_or_ordinal, (int, long)): + func.__name__ = name_or_ordinal + return func + +class PyDLL(CDLL): + """This class represents the Python library itself. It allows to + access Python API functions. The GIL is not released, and + Python exceptions are handled correctly. + """ + _func_flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI + +if _os.name in ("nt", "ce"): + + class WinDLL(CDLL): + """This class represents a dll exporting functions using the + Windows stdcall calling convention. + """ + _func_flags_ = _FUNCFLAG_STDCALL + + # XXX Hm, what about HRESULT as normal parameter? + # Mustn't it derive from c_long then? + from _ctypes import _check_HRESULT, _SimpleCData + class HRESULT(_SimpleCData): + _type_ = "l" + # _check_retval_ is called with the function's result when it + # is used as restype. It checks for the FAILED bit, and + # raises a WindowsError if it is set. + # + # The _check_retval_ method is implemented in C, so that the + # method definition itself is not included in the traceback + # when it raises an error - that is what we want (and Python + # doesn't have a way to raise an exception in the caller's + # frame). + _check_retval_ = _check_HRESULT + + class OleDLL(CDLL): + """This class represents a dll exporting functions using the + Windows stdcall calling convention, and returning HRESULT. + HRESULT error values are automatically raised as WindowsError + exceptions. + """ + _func_flags_ = _FUNCFLAG_STDCALL + _func_restype_ = HRESULT + +class LibraryLoader(object): + def __init__(self, dlltype): + self._dlltype = dlltype + + def __getattr__(self, name): + if name[0] == '_': + raise AttributeError(name) + dll = self._dlltype(name) + setattr(self, name, dll) + return dll + + def __getitem__(self, name): + return getattr(self, name) + + def LoadLibrary(self, name): + return self._dlltype(name) + +cdll = LibraryLoader(CDLL) +pydll = LibraryLoader(PyDLL) + +if _os.name in ("nt", "ce"): + pythonapi = PyDLL("python dll", None, _sys.dllhandle) +elif _sys.platform == "cygwin": + pythonapi = PyDLL("libpython%d.%d.dll" % _sys.version_info[:2]) +else: + pythonapi = PyDLL(None) + + +if _os.name in ("nt", "ce"): + windll = LibraryLoader(WinDLL) + oledll = LibraryLoader(OleDLL) + + if _os.name == "nt": + GetLastError = windll.kernel32.GetLastError + else: + GetLastError = windll.coredll.GetLastError + from _ctypes import get_last_error, set_last_error + + def WinError(code=None, descr=None): + if code is None: + code = GetLastError() + if descr is None: + descr = FormatError(code).strip() + return WindowsError(code, descr) + +if sizeof(c_uint) == sizeof(c_void_p): + c_size_t = c_uint + c_ssize_t = c_int +elif sizeof(c_ulong) == sizeof(c_void_p): + c_size_t = c_ulong + c_ssize_t = c_long +elif sizeof(c_ulonglong) == sizeof(c_void_p): + c_size_t = c_ulonglong + c_ssize_t = c_longlong + +# functions + +from _ctypes import _memmove_addr, _memset_addr, _string_at_addr, _cast_addr + +## void *memmove(void *, const void *, size_t); +memmove = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)(_memmove_addr) + +## void *memset(void *, int, size_t) +memset = CFUNCTYPE(c_void_p, c_void_p, c_int, c_size_t)(_memset_addr) + +def PYFUNCTYPE(restype, *argtypes): + class CFunctionType(_CFuncPtr): + _argtypes_ = argtypes + _restype_ = restype + _flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI + return CFunctionType + +_cast = PYFUNCTYPE(py_object, c_void_p, py_object, py_object)(_cast_addr) +def cast(obj, typ): + return _cast(obj, obj, typ) + +_string_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr) +def string_at(ptr, size=-1): + """string_at(addr[, size]) -> string + + Return the string at addr.""" + return _string_at(ptr, size) + +try: + from _ctypes import _wstring_at_addr +except ImportError: + pass +else: + _wstring_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_wstring_at_addr) + def wstring_at(ptr, size=-1): + """wstring_at(addr[, size]) -> string + + Return the string at addr.""" + return _wstring_at(ptr, size) + + +if _os.name in ("nt", "ce"): # COM stuff + def DllGetClassObject(rclsid, riid, ppv): + try: + ccom = __import__("comtypes.server.inprocserver", globals(), locals(), ['*']) + except ImportError: + return -2147221231 # CLASS_E_CLASSNOTAVAILABLE + else: + return ccom.DllGetClassObject(rclsid, riid, ppv) + + def DllCanUnloadNow(): + try: + ccom = __import__("comtypes.server.inprocserver", globals(), locals(), ['*']) + except ImportError: + return 0 # S_OK + return ccom.DllCanUnloadNow() + +from ctypes._endian import BigEndianStructure, LittleEndianStructure + +# Fill in specifically-sized types +c_int8 = c_byte +c_uint8 = c_ubyte +for kind in [c_short, c_int, c_long, c_longlong]: + if sizeof(kind) == 2: c_int16 = kind + elif sizeof(kind) == 4: c_int32 = kind + elif sizeof(kind) == 8: c_int64 = kind +for kind in [c_ushort, c_uint, c_ulong, c_ulonglong]: + if sizeof(kind) == 2: c_uint16 = kind + elif sizeof(kind) == 4: c_uint32 = kind + elif sizeof(kind) == 8: c_uint64 = kind +del(kind) + +_reset_cache() diff --git a/lib/python2.7/ctypes/__init__.pyc b/lib/python2.7/ctypes/__init__.pyc new file mode 100644 index 0000000..cbd2b2d Binary files /dev/null and b/lib/python2.7/ctypes/__init__.pyc differ diff --git a/lib/python2.7/ctypes/__init__.pyo b/lib/python2.7/ctypes/__init__.pyo new file mode 100644 index 0000000..cbd2b2d Binary files /dev/null and b/lib/python2.7/ctypes/__init__.pyo differ diff --git a/lib/python2.7/ctypes/_endian.py b/lib/python2.7/ctypes/_endian.py new file mode 100644 index 0000000..f80e675 --- /dev/null +++ b/lib/python2.7/ctypes/_endian.py @@ -0,0 +1,64 @@ +###################################################################### +# This file should be kept compatible with Python 2.3, see PEP 291. # +###################################################################### +import sys +from ctypes import * + +_array_type = type(Array) + +def _other_endian(typ): + """Return the type with the 'other' byte order. Simple types like + c_int and so on already have __ctype_be__ and __ctype_le__ + attributes which contain the types, for more complicated types + arrays and structures are supported. + """ + # check _OTHER_ENDIAN attribute (present if typ is primitive type) + if hasattr(typ, _OTHER_ENDIAN): + return getattr(typ, _OTHER_ENDIAN) + # if typ is array + if isinstance(typ, _array_type): + return _other_endian(typ._type_) * typ._length_ + # if typ is structure + if issubclass(typ, Structure): + return typ + raise TypeError("This type does not support other endian: %s" % typ) + +class _swapped_meta(type(Structure)): + def __setattr__(self, attrname, value): + if attrname == "_fields_": + fields = [] + for desc in value: + name = desc[0] + typ = desc[1] + rest = desc[2:] + fields.append((name, _other_endian(typ)) + rest) + value = fields + super(_swapped_meta, self).__setattr__(attrname, value) + +################################################################ + +# Note: The Structure metaclass checks for the *presence* (not the +# value!) of a _swapped_bytes_ attribute to determine the bit order in +# structures containing bit fields. + +if sys.byteorder == "little": + _OTHER_ENDIAN = "__ctype_be__" + + LittleEndianStructure = Structure + + class BigEndianStructure(Structure): + """Structure with big endian byte order""" + __metaclass__ = _swapped_meta + _swappedbytes_ = None + +elif sys.byteorder == "big": + _OTHER_ENDIAN = "__ctype_le__" + + BigEndianStructure = Structure + class LittleEndianStructure(Structure): + """Structure with little endian byte order""" + __metaclass__ = _swapped_meta + _swappedbytes_ = None + +else: + raise RuntimeError("Invalid byteorder") diff --git a/lib/python2.7/ctypes/_endian.pyc b/lib/python2.7/ctypes/_endian.pyc new file mode 100644 index 0000000..3ac696c Binary files /dev/null and b/lib/python2.7/ctypes/_endian.pyc differ diff --git a/lib/python2.7/ctypes/_endian.pyo b/lib/python2.7/ctypes/_endian.pyo new file mode 100644 index 0000000..3ac696c Binary files /dev/null and b/lib/python2.7/ctypes/_endian.pyo differ diff --git a/lib/python2.7/ctypes/macholib/README.ctypes b/lib/python2.7/ctypes/macholib/README.ctypes new file mode 100644 index 0000000..4e10cbe --- /dev/null +++ b/lib/python2.7/ctypes/macholib/README.ctypes @@ -0,0 +1,7 @@ +Files in this directory from from Bob Ippolito's py2app. + +License: Any components of the py2app suite may be distributed under +the MIT or PSF open source licenses. + +This is version 1.0, SVN revision 789, from 2006/01/25. +The main repository is http://svn.red-bean.com/bob/macholib/trunk/macholib/ \ No newline at end of file diff --git a/lib/python2.7/ctypes/macholib/__init__.py b/lib/python2.7/ctypes/macholib/__init__.py new file mode 100644 index 0000000..36149d2 --- /dev/null +++ b/lib/python2.7/ctypes/macholib/__init__.py @@ -0,0 +1,12 @@ +###################################################################### +# This file should be kept compatible with Python 2.3, see PEP 291. # +###################################################################### +""" +Enough Mach-O to make your head spin. + +See the relevant header files in /usr/include/mach-o + +And also Apple's documentation. +""" + +__version__ = '1.0' diff --git a/lib/python2.7/ctypes/macholib/__init__.pyc b/lib/python2.7/ctypes/macholib/__init__.pyc new file mode 100644 index 0000000..60d6a9f Binary files /dev/null and b/lib/python2.7/ctypes/macholib/__init__.pyc differ diff --git a/lib/python2.7/ctypes/macholib/__init__.pyo b/lib/python2.7/ctypes/macholib/__init__.pyo new file mode 100644 index 0000000..60d6a9f Binary files /dev/null and b/lib/python2.7/ctypes/macholib/__init__.pyo differ diff --git a/lib/python2.7/ctypes/macholib/dyld.py b/lib/python2.7/ctypes/macholib/dyld.py new file mode 100644 index 0000000..9714ec6 --- /dev/null +++ b/lib/python2.7/ctypes/macholib/dyld.py @@ -0,0 +1,169 @@ +###################################################################### +# This file should be kept compatible with Python 2.3, see PEP 291. # +###################################################################### +""" +dyld emulation +""" + +import os +from framework import framework_info +from dylib import dylib_info +from itertools import * + +__all__ = [ + 'dyld_find', 'framework_find', + 'framework_info', 'dylib_info', +] + +# These are the defaults as per man dyld(1) +# +DEFAULT_FRAMEWORK_FALLBACK = [ + os.path.expanduser("~/Library/Frameworks"), + "/Library/Frameworks", + "/Network/Library/Frameworks", + "/System/Library/Frameworks", +] + +DEFAULT_LIBRARY_FALLBACK = [ + os.path.expanduser("~/lib"), + "/usr/local/lib", + "/lib", + "/usr/lib", +] + +def ensure_utf8(s): + """Not all of PyObjC and Python understand unicode paths very well yet""" + if isinstance(s, unicode): + return s.encode('utf8') + return s + +def dyld_env(env, var): + if env is None: + env = os.environ + rval = env.get(var) + if rval is None: + return [] + return rval.split(':') + +def dyld_image_suffix(env=None): + if env is None: + env = os.environ + return env.get('DYLD_IMAGE_SUFFIX') + +def dyld_framework_path(env=None): + return dyld_env(env, 'DYLD_FRAMEWORK_PATH') + +def dyld_library_path(env=None): + return dyld_env(env, 'DYLD_LIBRARY_PATH') + +def dyld_fallback_framework_path(env=None): + return dyld_env(env, 'DYLD_FALLBACK_FRAMEWORK_PATH') + +def dyld_fallback_library_path(env=None): + return dyld_env(env, 'DYLD_FALLBACK_LIBRARY_PATH') + +def dyld_image_suffix_search(iterator, env=None): + """For a potential path iterator, add DYLD_IMAGE_SUFFIX semantics""" + suffix = dyld_image_suffix(env) + if suffix is None: + return iterator + def _inject(iterator=iterator, suffix=suffix): + for path in iterator: + if path.endswith('.dylib'): + yield path[:-len('.dylib')] + suffix + '.dylib' + else: + yield path + suffix + yield path + return _inject() + +def dyld_override_search(name, env=None): + # If DYLD_FRAMEWORK_PATH is set and this dylib_name is a + # framework name, use the first file that exists in the framework + # path if any. If there is none go on to search the DYLD_LIBRARY_PATH + # if any. + + framework = framework_info(name) + + if framework is not None: + for path in dyld_framework_path(env): + yield os.path.join(path, framework['name']) + + # If DYLD_LIBRARY_PATH is set then use the first file that exists + # in the path. If none use the original name. + for path in dyld_library_path(env): + yield os.path.join(path, os.path.basename(name)) + +def dyld_executable_path_search(name, executable_path=None): + # If we haven't done any searching and found a library and the + # dylib_name starts with "@executable_path/" then construct the + # library name. + if name.startswith('@executable_path/') and executable_path is not None: + yield os.path.join(executable_path, name[len('@executable_path/'):]) + +def dyld_default_search(name, env=None): + yield name + + framework = framework_info(name) + + if framework is not None: + fallback_framework_path = dyld_fallback_framework_path(env) + for path in fallback_framework_path: + yield os.path.join(path, framework['name']) + + fallback_library_path = dyld_fallback_library_path(env) + for path in fallback_library_path: + yield os.path.join(path, os.path.basename(name)) + + if framework is not None and not fallback_framework_path: + for path in DEFAULT_FRAMEWORK_FALLBACK: + yield os.path.join(path, framework['name']) + + if not fallback_library_path: + for path in DEFAULT_LIBRARY_FALLBACK: + yield os.path.join(path, os.path.basename(name)) + +def dyld_find(name, executable_path=None, env=None): + """ + Find a library or framework using dyld semantics + """ + name = ensure_utf8(name) + executable_path = ensure_utf8(executable_path) + for path in dyld_image_suffix_search(chain( + dyld_override_search(name, env), + dyld_executable_path_search(name, executable_path), + dyld_default_search(name, env), + ), env): + if os.path.isfile(path): + return path + raise ValueError("dylib %s could not be found" % (name,)) + +def framework_find(fn, executable_path=None, env=None): + """ + Find a framework using dyld semantics in a very loose manner. + + Will take input such as: + Python + Python.framework + Python.framework/Versions/Current + """ + try: + return dyld_find(fn, executable_path=executable_path, env=env) + except ValueError, e: + pass + fmwk_index = fn.rfind('.framework') + if fmwk_index == -1: + fmwk_index = len(fn) + fn += '.framework' + fn = os.path.join(fn, os.path.basename(fn[:fmwk_index])) + try: + return dyld_find(fn, executable_path=executable_path, env=env) + except ValueError: + raise e + +def test_dyld_find(): + env = {} + assert dyld_find('libSystem.dylib') == '/usr/lib/libSystem.dylib' + assert dyld_find('System.framework/System') == '/System/Library/Frameworks/System.framework/System' + +if __name__ == '__main__': + test_dyld_find() diff --git a/lib/python2.7/ctypes/macholib/dyld.pyc b/lib/python2.7/ctypes/macholib/dyld.pyc new file mode 100644 index 0000000..3283750 Binary files /dev/null and b/lib/python2.7/ctypes/macholib/dyld.pyc differ diff --git a/lib/python2.7/ctypes/macholib/dyld.pyo b/lib/python2.7/ctypes/macholib/dyld.pyo new file mode 100644 index 0000000..70a2986 Binary files /dev/null and b/lib/python2.7/ctypes/macholib/dyld.pyo differ diff --git a/lib/python2.7/ctypes/macholib/dylib.py b/lib/python2.7/ctypes/macholib/dylib.py new file mode 100644 index 0000000..ea3dd38 --- /dev/null +++ b/lib/python2.7/ctypes/macholib/dylib.py @@ -0,0 +1,66 @@ +###################################################################### +# This file should be kept compatible with Python 2.3, see PEP 291. # +###################################################################### +""" +Generic dylib path manipulation +""" + +import re + +__all__ = ['dylib_info'] + +DYLIB_RE = re.compile(r"""(?x) +(?P^.*)(?:^|/) +(?P + (?P\w+?) + (?:\.(?P[^._]+))? + (?:_(?P[^._]+))? + \.dylib$ +) +""") + +def dylib_info(filename): + """ + A dylib name can take one of the following four forms: + Location/Name.SomeVersion_Suffix.dylib + Location/Name.SomeVersion.dylib + Location/Name_Suffix.dylib + Location/Name.dylib + + returns None if not found or a mapping equivalent to: + dict( + location='Location', + name='Name.SomeVersion_Suffix.dylib', + shortname='Name', + version='SomeVersion', + suffix='Suffix', + ) + + Note that SomeVersion and Suffix are optional and may be None + if not present. + """ + is_dylib = DYLIB_RE.match(filename) + if not is_dylib: + return None + return is_dylib.groupdict() + + +def test_dylib_info(): + def d(location=None, name=None, shortname=None, version=None, suffix=None): + return dict( + location=location, + name=name, + shortname=shortname, + version=version, + suffix=suffix + ) + assert dylib_info('completely/invalid') is None + assert dylib_info('completely/invalide_debug') is None + assert dylib_info('P/Foo.dylib') == d('P', 'Foo.dylib', 'Foo') + assert dylib_info('P/Foo_debug.dylib') == d('P', 'Foo_debug.dylib', 'Foo', suffix='debug') + assert dylib_info('P/Foo.A.dylib') == d('P', 'Foo.A.dylib', 'Foo', 'A') + assert dylib_info('P/Foo_debug.A.dylib') == d('P', 'Foo_debug.A.dylib', 'Foo_debug', 'A') + assert dylib_info('P/Foo.A_debug.dylib') == d('P', 'Foo.A_debug.dylib', 'Foo', 'A', 'debug') + +if __name__ == '__main__': + test_dylib_info() diff --git a/lib/python2.7/ctypes/macholib/dylib.pyc b/lib/python2.7/ctypes/macholib/dylib.pyc new file mode 100644 index 0000000..715d2b8 Binary files /dev/null and b/lib/python2.7/ctypes/macholib/dylib.pyc differ diff --git a/lib/python2.7/ctypes/macholib/dylib.pyo b/lib/python2.7/ctypes/macholib/dylib.pyo new file mode 100644 index 0000000..743bc57 Binary files /dev/null and b/lib/python2.7/ctypes/macholib/dylib.pyo differ diff --git a/lib/python2.7/ctypes/macholib/fetch_macholib b/lib/python2.7/ctypes/macholib/fetch_macholib new file mode 100755 index 0000000..e6d6a22 --- /dev/null +++ b/lib/python2.7/ctypes/macholib/fetch_macholib @@ -0,0 +1,2 @@ +#!/bin/sh +svn export --force http://svn.red-bean.com/bob/macholib/trunk/macholib/ . diff --git a/lib/python2.7/ctypes/macholib/fetch_macholib.bat b/lib/python2.7/ctypes/macholib/fetch_macholib.bat new file mode 100644 index 0000000..f9e1c0d --- /dev/null +++ b/lib/python2.7/ctypes/macholib/fetch_macholib.bat @@ -0,0 +1 @@ +svn export --force http://svn.red-bean.com/bob/macholib/trunk/macholib/ . diff --git a/lib/python2.7/ctypes/macholib/framework.py b/lib/python2.7/ctypes/macholib/framework.py new file mode 100644 index 0000000..dd7fb2f --- /dev/null +++ b/lib/python2.7/ctypes/macholib/framework.py @@ -0,0 +1,68 @@ +###################################################################### +# This file should be kept compatible with Python 2.3, see PEP 291. # +###################################################################### +""" +Generic framework path manipulation +""" + +import re + +__all__ = ['framework_info'] + +STRICT_FRAMEWORK_RE = re.compile(r"""(?x) +(?P^.*)(?:^|/) +(?P + (?P\w+).framework/ + (?:Versions/(?P[^/]+)/)? + (?P=shortname) + (?:_(?P[^_]+))? +)$ +""") + +def framework_info(filename): + """ + A framework name can take one of the following four forms: + Location/Name.framework/Versions/SomeVersion/Name_Suffix + Location/Name.framework/Versions/SomeVersion/Name + Location/Name.framework/Name_Suffix + Location/Name.framework/Name + + returns None if not found, or a mapping equivalent to: + dict( + location='Location', + name='Name.framework/Versions/SomeVersion/Name_Suffix', + shortname='Name', + version='SomeVersion', + suffix='Suffix', + ) + + Note that SomeVersion and Suffix are optional and may be None + if not present + """ + is_framework = STRICT_FRAMEWORK_RE.match(filename) + if not is_framework: + return None + return is_framework.groupdict() + +def test_framework_info(): + def d(location=None, name=None, shortname=None, version=None, suffix=None): + return dict( + location=location, + name=name, + shortname=shortname, + version=version, + suffix=suffix + ) + assert framework_info('completely/invalid') is None + assert framework_info('completely/invalid/_debug') is None + assert framework_info('P/F.framework') is None + assert framework_info('P/F.framework/_debug') is None + assert framework_info('P/F.framework/F') == d('P', 'F.framework/F', 'F') + assert framework_info('P/F.framework/F_debug') == d('P', 'F.framework/F_debug', 'F', suffix='debug') + assert framework_info('P/F.framework/Versions') is None + assert framework_info('P/F.framework/Versions/A') is None + assert framework_info('P/F.framework/Versions/A/F') == d('P', 'F.framework/Versions/A/F', 'F', 'A') + assert framework_info('P/F.framework/Versions/A/F_debug') == d('P', 'F.framework/Versions/A/F_debug', 'F', 'A', 'debug') + +if __name__ == '__main__': + test_framework_info() diff --git a/lib/python2.7/ctypes/macholib/framework.pyc b/lib/python2.7/ctypes/macholib/framework.pyc new file mode 100644 index 0000000..4a79a59 Binary files /dev/null and b/lib/python2.7/ctypes/macholib/framework.pyc differ diff --git a/lib/python2.7/ctypes/macholib/framework.pyo b/lib/python2.7/ctypes/macholib/framework.pyo new file mode 100644 index 0000000..f328535 Binary files /dev/null and b/lib/python2.7/ctypes/macholib/framework.pyo differ diff --git a/lib/python2.7/ctypes/test/__init__.py b/lib/python2.7/ctypes/test/__init__.py new file mode 100644 index 0000000..808e418 --- /dev/null +++ b/lib/python2.7/ctypes/test/__init__.py @@ -0,0 +1,208 @@ +import os, sys, unittest, getopt, time + +use_resources = [] + +class ResourceDenied(Exception): + """Test skipped because it requested a disallowed resource. + + This is raised when a test calls requires() for a resource that + has not be enabled. Resources are defined by test modules. + """ + +def is_resource_enabled(resource): + """Test whether a resource is enabled. + + If the caller's module is __main__ then automatically return True.""" + if sys._getframe().f_back.f_globals.get("__name__") == "__main__": + return True + result = use_resources is not None and \ + (resource in use_resources or "*" in use_resources) + if not result: + _unavail[resource] = None + return result + +_unavail = {} +def requires(resource, msg=None): + """Raise ResourceDenied if the specified resource is not available. + + If the caller's module is __main__ then automatically return True.""" + # see if the caller's module is __main__ - if so, treat as if + # the resource was set + if sys._getframe().f_back.f_globals.get("__name__") == "__main__": + return + if not is_resource_enabled(resource): + if msg is None: + msg = "Use of the `%s' resource not enabled" % resource + raise ResourceDenied(msg) + +def find_package_modules(package, mask): + import fnmatch + if (hasattr(package, "__loader__") and + hasattr(package.__loader__, '_files')): + path = package.__name__.replace(".", os.path.sep) + mask = os.path.join(path, mask) + for fnm in package.__loader__._files.iterkeys(): + if fnmatch.fnmatchcase(fnm, mask): + yield os.path.splitext(fnm)[0].replace(os.path.sep, ".") + else: + path = package.__path__[0] + for fnm in os.listdir(path): + if fnmatch.fnmatchcase(fnm, mask): + yield "%s.%s" % (package.__name__, os.path.splitext(fnm)[0]) + +def get_tests(package, mask, verbosity, exclude=()): + """Return a list of skipped test modules, and a list of test cases.""" + tests = [] + skipped = [] + for modname in find_package_modules(package, mask): + if modname.split(".")[-1] in exclude: + skipped.append(modname) + if verbosity > 1: + print >> sys.stderr, "Skipped %s: excluded" % modname + continue + try: + mod = __import__(modname, globals(), locals(), ['*']) + except (ResourceDenied, unittest.SkipTest) as detail: + skipped.append(modname) + if verbosity > 1: + print >> sys.stderr, "Skipped %s: %s" % (modname, detail) + continue + for name in dir(mod): + if name.startswith("_"): + continue + o = getattr(mod, name) + if type(o) is type(unittest.TestCase) and issubclass(o, unittest.TestCase): + tests.append(o) + return skipped, tests + +def usage(): + print __doc__ + return 1 + +def test_with_refcounts(runner, verbosity, testcase): + """Run testcase several times, tracking reference counts.""" + import gc + import ctypes + ptc = ctypes._pointer_type_cache.copy() + cfc = ctypes._c_functype_cache.copy() + wfc = ctypes._win_functype_cache.copy() + + # when searching for refcount leaks, we have to manually reset any + # caches that ctypes has. + def cleanup(): + ctypes._pointer_type_cache = ptc.copy() + ctypes._c_functype_cache = cfc.copy() + ctypes._win_functype_cache = wfc.copy() + gc.collect() + + test = unittest.makeSuite(testcase) + for i in range(5): + rc = sys.gettotalrefcount() + runner.run(test) + cleanup() + COUNT = 5 + refcounts = [None] * COUNT + for i in range(COUNT): + rc = sys.gettotalrefcount() + runner.run(test) + cleanup() + refcounts[i] = sys.gettotalrefcount() - rc + if filter(None, refcounts): + print "%s leaks:\n\t" % testcase, refcounts + elif verbosity: + print "%s: ok." % testcase + +class TestRunner(unittest.TextTestRunner): + def run(self, test, skipped): + "Run the given test case or test suite." + # Same as unittest.TextTestRunner.run, except that it reports + # skipped tests. + result = self._makeResult() + startTime = time.time() + test(result) + stopTime = time.time() + timeTaken = stopTime - startTime + result.printErrors() + self.stream.writeln(result.separator2) + run = result.testsRun + if _unavail: #skipped: + requested = _unavail.keys() + requested.sort() + self.stream.writeln("Ran %d test%s in %.3fs (%s module%s skipped)" % + (run, run != 1 and "s" or "", timeTaken, + len(skipped), + len(skipped) != 1 and "s" or "")) + self.stream.writeln("Unavailable resources: %s" % ", ".join(requested)) + else: + self.stream.writeln("Ran %d test%s in %.3fs" % + (run, run != 1 and "s" or "", timeTaken)) + self.stream.writeln() + if not result.wasSuccessful(): + self.stream.write("FAILED (") + failed, errored = map(len, (result.failures, result.errors)) + if failed: + self.stream.write("failures=%d" % failed) + if errored: + if failed: self.stream.write(", ") + self.stream.write("errors=%d" % errored) + self.stream.writeln(")") + else: + self.stream.writeln("OK") + return result + + +def main(*packages): + try: + opts, args = getopt.getopt(sys.argv[1:], "rqvu:x:") + except getopt.error: + return usage() + + verbosity = 1 + search_leaks = False + exclude = [] + for flag, value in opts: + if flag == "-q": + verbosity -= 1 + elif flag == "-v": + verbosity += 1 + elif flag == "-r": + try: + sys.gettotalrefcount + except AttributeError: + print >> sys.stderr, "-r flag requires Python debug build" + return -1 + search_leaks = True + elif flag == "-u": + use_resources.extend(value.split(",")) + elif flag == "-x": + exclude.extend(value.split(",")) + + mask = "test_*.py" + if args: + mask = args[0] + + for package in packages: + run_tests(package, mask, verbosity, search_leaks, exclude) + + +def run_tests(package, mask, verbosity, search_leaks, exclude): + skipped, testcases = get_tests(package, mask, verbosity, exclude) + runner = TestRunner(verbosity=verbosity) + + suites = [unittest.makeSuite(o) for o in testcases] + suite = unittest.TestSuite(suites) + result = runner.run(suite, skipped) + + if search_leaks: + # hunt for refcount leaks + runner = BasicTestRunner() + for t in testcases: + test_with_refcounts(runner, verbosity, t) + + return bool(result.errors) + +class BasicTestRunner: + def run(self, test): + result = unittest.TestResult() + test(result) + return result diff --git a/lib/python2.7/ctypes/test/__init__.pyc b/lib/python2.7/ctypes/test/__init__.pyc new file mode 100644 index 0000000..8fdbe55 Binary files /dev/null and b/lib/python2.7/ctypes/test/__init__.pyc differ diff --git a/lib/python2.7/ctypes/test/__init__.pyo b/lib/python2.7/ctypes/test/__init__.pyo new file mode 100644 index 0000000..8fdbe55 Binary files /dev/null and b/lib/python2.7/ctypes/test/__init__.pyo differ diff --git a/lib/python2.7/ctypes/test/runtests.py b/lib/python2.7/ctypes/test/runtests.py new file mode 100644 index 0000000..ec31fc8 --- /dev/null +++ b/lib/python2.7/ctypes/test/runtests.py @@ -0,0 +1,19 @@ +"""Usage: runtests.py [-q] [-r] [-v] [-u resources] [mask] + +Run all tests found in this directory, and print a summary of the results. +Command line flags: + -q quiet mode: don't prnt anything while the tests are running + -r run tests repeatedly, look for refcount leaks + -u + Add resources to the lits of allowed resources. '*' allows all + resources. + -v verbose mode: print the test currently executed + -x + Exclude specified tests. + mask mask to select filenames containing testcases, wildcards allowed +""" +import sys +import ctypes.test + +if __name__ == "__main__": + sys.exit(ctypes.test.main(ctypes.test)) diff --git a/lib/python2.7/ctypes/test/runtests.pyc b/lib/python2.7/ctypes/test/runtests.pyc new file mode 100644 index 0000000..de3aa0b Binary files /dev/null and b/lib/python2.7/ctypes/test/runtests.pyc differ diff --git a/lib/python2.7/ctypes/test/runtests.pyo b/lib/python2.7/ctypes/test/runtests.pyo new file mode 100644 index 0000000..de3aa0b Binary files /dev/null and b/lib/python2.7/ctypes/test/runtests.pyo differ diff --git a/lib/python2.7/ctypes/test/test_anon.py b/lib/python2.7/ctypes/test/test_anon.py new file mode 100644 index 0000000..d892b59 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_anon.py @@ -0,0 +1,60 @@ +import unittest +from ctypes import * + +class AnonTest(unittest.TestCase): + + def test_anon(self): + class ANON(Union): + _fields_ = [("a", c_int), + ("b", c_int)] + + class Y(Structure): + _fields_ = [("x", c_int), + ("_", ANON), + ("y", c_int)] + _anonymous_ = ["_"] + + self.assertEqual(Y.a.offset, sizeof(c_int)) + self.assertEqual(Y.b.offset, sizeof(c_int)) + + self.assertEqual(ANON.a.offset, 0) + self.assertEqual(ANON.b.offset, 0) + + def test_anon_nonseq(self): + # TypeError: _anonymous_ must be a sequence + self.assertRaises(TypeError, + lambda: type(Structure)("Name", + (Structure,), + {"_fields_": [], "_anonymous_": 42})) + + def test_anon_nonmember(self): + # AttributeError: type object 'Name' has no attribute 'x' + self.assertRaises(AttributeError, + lambda: type(Structure)("Name", + (Structure,), + {"_fields_": [], + "_anonymous_": ["x"]})) + + def test_nested(self): + class ANON_S(Structure): + _fields_ = [("a", c_int)] + + class ANON_U(Union): + _fields_ = [("_", ANON_S), + ("b", c_int)] + _anonymous_ = ["_"] + + class Y(Structure): + _fields_ = [("x", c_int), + ("_", ANON_U), + ("y", c_int)] + _anonymous_ = ["_"] + + self.assertEqual(Y.x.offset, 0) + self.assertEqual(Y.a.offset, sizeof(c_int)) + self.assertEqual(Y.b.offset, sizeof(c_int)) + self.assertEqual(Y._.offset, sizeof(c_int)) + self.assertEqual(Y.y.offset, sizeof(c_int) * 2) + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_anon.pyc b/lib/python2.7/ctypes/test/test_anon.pyc new file mode 100644 index 0000000..e1b1ddc Binary files /dev/null and b/lib/python2.7/ctypes/test/test_anon.pyc differ diff --git a/lib/python2.7/ctypes/test/test_anon.pyo b/lib/python2.7/ctypes/test/test_anon.pyo new file mode 100644 index 0000000..e1b1ddc Binary files /dev/null and b/lib/python2.7/ctypes/test/test_anon.pyo differ diff --git a/lib/python2.7/ctypes/test/test_array_in_pointer.py b/lib/python2.7/ctypes/test/test_array_in_pointer.py new file mode 100644 index 0000000..ee7863c --- /dev/null +++ b/lib/python2.7/ctypes/test/test_array_in_pointer.py @@ -0,0 +1,64 @@ +import unittest +from ctypes import * +from binascii import hexlify +import re + +def dump(obj): + # helper function to dump memory contents in hex, with a hyphen + # between the bytes. + h = hexlify(memoryview(obj)) + return re.sub(r"(..)", r"\1-", h)[:-1] + + +class Value(Structure): + _fields_ = [("val", c_byte)] + +class Container(Structure): + _fields_ = [("pvalues", POINTER(Value))] + +class Test(unittest.TestCase): + def test(self): + # create an array of 4 values + val_array = (Value * 4)() + + # create a container, which holds a pointer to the pvalues array. + c = Container() + c.pvalues = val_array + + # memory contains 4 NUL bytes now, that's correct + self.assertEqual("00-00-00-00", dump(val_array)) + + # set the values of the array through the pointer: + for i in range(4): + c.pvalues[i].val = i + 1 + + values = [c.pvalues[i].val for i in range(4)] + + # These are the expected results: here s the bug! + self.assertEqual( + (values, dump(val_array)), + ([1, 2, 3, 4], "01-02-03-04") + ) + + def test_2(self): + + val_array = (Value * 4)() + + # memory contains 4 NUL bytes now, that's correct + self.assertEqual("00-00-00-00", dump(val_array)) + + ptr = cast(val_array, POINTER(Value)) + # set the values of the array through the pointer: + for i in range(4): + ptr[i].val = i + 1 + + values = [ptr[i].val for i in range(4)] + + # These are the expected results: here s the bug! + self.assertEqual( + (values, dump(val_array)), + ([1, 2, 3, 4], "01-02-03-04") + ) + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_array_in_pointer.pyc b/lib/python2.7/ctypes/test/test_array_in_pointer.pyc new file mode 100644 index 0000000..44d5598 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_array_in_pointer.pyc differ diff --git a/lib/python2.7/ctypes/test/test_array_in_pointer.pyo b/lib/python2.7/ctypes/test/test_array_in_pointer.pyo new file mode 100644 index 0000000..44d5598 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_array_in_pointer.pyo differ diff --git a/lib/python2.7/ctypes/test/test_arrays.py b/lib/python2.7/ctypes/test/test_arrays.py new file mode 100644 index 0000000..925f8bf --- /dev/null +++ b/lib/python2.7/ctypes/test/test_arrays.py @@ -0,0 +1,134 @@ +import unittest +from ctypes import * + +formats = "bBhHiIlLqQfd" + +formats = c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, \ + c_long, c_ulonglong, c_float, c_double, c_longdouble + +class ArrayTestCase(unittest.TestCase): + def test_simple(self): + # create classes holding simple numeric types, and check + # various properties. + + init = range(15, 25) + + for fmt in formats: + alen = len(init) + int_array = ARRAY(fmt, alen) + + ia = int_array(*init) + # length of instance ok? + self.assertEqual(len(ia), alen) + + # slot values ok? + values = [ia[i] for i in range(len(init))] + self.assertEqual(values, init) + + # change the items + from operator import setitem + new_values = range(42, 42+alen) + [setitem(ia, n, new_values[n]) for n in range(alen)] + values = [ia[i] for i in range(len(init))] + self.assertEqual(values, new_values) + + # are the items initialized to 0? + ia = int_array() + values = [ia[i] for i in range(len(init))] + self.assertEqual(values, [0] * len(init)) + + # Too many initializers should be caught + self.assertRaises(IndexError, int_array, *range(alen*2)) + + CharArray = ARRAY(c_char, 3) + + ca = CharArray("a", "b", "c") + + # Should this work? It doesn't: + # CharArray("abc") + self.assertRaises(TypeError, CharArray, "abc") + + self.assertEqual(ca[0], "a") + self.assertEqual(ca[1], "b") + self.assertEqual(ca[2], "c") + self.assertEqual(ca[-3], "a") + self.assertEqual(ca[-2], "b") + self.assertEqual(ca[-1], "c") + + self.assertEqual(len(ca), 3) + + # slicing is now supported, but not extended slicing (3-argument)! + from operator import getslice, delitem + self.assertRaises(TypeError, getslice, ca, 0, 1, -1) + + # cannot delete items + self.assertRaises(TypeError, delitem, ca, 0) + + def test_numeric_arrays(self): + + alen = 5 + + numarray = ARRAY(c_int, alen) + + na = numarray() + values = [na[i] for i in range(alen)] + self.assertEqual(values, [0] * alen) + + na = numarray(*[c_int()] * alen) + values = [na[i] for i in range(alen)] + self.assertEqual(values, [0]*alen) + + na = numarray(1, 2, 3, 4, 5) + values = [i for i in na] + self.assertEqual(values, [1, 2, 3, 4, 5]) + + na = numarray(*map(c_int, (1, 2, 3, 4, 5))) + values = [i for i in na] + self.assertEqual(values, [1, 2, 3, 4, 5]) + + def test_classcache(self): + self.assertTrue(not ARRAY(c_int, 3) is ARRAY(c_int, 4)) + self.assertTrue(ARRAY(c_int, 3) is ARRAY(c_int, 3)) + + def test_from_address(self): + # Failed with 0.9.8, reported by JUrner + p = create_string_buffer("foo") + sz = (c_char * 3).from_address(addressof(p)) + self.assertEqual(sz[:], "foo") + self.assertEqual(sz[::], "foo") + self.assertEqual(sz[::-1], "oof") + self.assertEqual(sz[::3], "f") + self.assertEqual(sz[1:4:2], "o") + self.assertEqual(sz.value, "foo") + + try: + create_unicode_buffer + except NameError: + pass + else: + def test_from_addressW(self): + p = create_unicode_buffer("foo") + sz = (c_wchar * 3).from_address(addressof(p)) + self.assertEqual(sz[:], "foo") + self.assertEqual(sz[::], "foo") + self.assertEqual(sz[::-1], "oof") + self.assertEqual(sz[::3], "f") + self.assertEqual(sz[1:4:2], "o") + self.assertEqual(sz.value, "foo") + + def test_cache(self): + # Array types are cached internally in the _ctypes extension, + # in a WeakValueDictionary. Make sure the array type is + # removed from the cache when the itemtype goes away. This + # test will not fail, but will show a leak in the testsuite. + + # Create a new type: + class my_int(c_int): + pass + # Create a new array type based on it: + t1 = my_int * 1 + t2 = my_int * 1 + self.assertTrue(t1 is t2) + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_arrays.pyc b/lib/python2.7/ctypes/test/test_arrays.pyc new file mode 100644 index 0000000..f8e4ef1 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_arrays.pyc differ diff --git a/lib/python2.7/ctypes/test/test_arrays.pyo b/lib/python2.7/ctypes/test/test_arrays.pyo new file mode 100644 index 0000000..f8e4ef1 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_arrays.pyo differ diff --git a/lib/python2.7/ctypes/test/test_as_parameter.py b/lib/python2.7/ctypes/test/test_as_parameter.py new file mode 100644 index 0000000..0553e66 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_as_parameter.py @@ -0,0 +1,233 @@ +import unittest +from ctypes import * +import _ctypes_test +import sys + +dll = CDLL(_ctypes_test.__file__) + +try: + CALLBACK_FUNCTYPE = WINFUNCTYPE +except NameError: + # fake to enable this test on Linux + CALLBACK_FUNCTYPE = CFUNCTYPE + +class POINT(Structure): + _fields_ = [("x", c_int), ("y", c_int)] + +class BasicWrapTestCase(unittest.TestCase): + def wrap(self, param): + return param + + def test_wchar_parm(self): + try: + c_wchar + except NameError: + return + f = dll._testfunc_i_bhilfd + f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double] + result = f(self.wrap(1), self.wrap(u"x"), self.wrap(3), self.wrap(4), self.wrap(5.0), self.wrap(6.0)) + self.assertEqual(result, 139) + self.assertTrue(type(result), int) + + def test_pointers(self): + f = dll._testfunc_p_p + f.restype = POINTER(c_int) + f.argtypes = [POINTER(c_int)] + + # This only works if the value c_int(42) passed to the + # function is still alive while the pointer (the result) is + # used. + + v = c_int(42) + + self.assertEqual(pointer(v).contents.value, 42) + result = f(self.wrap(pointer(v))) + self.assertEqual(type(result), POINTER(c_int)) + self.assertEqual(result.contents.value, 42) + + # This on works... + result = f(self.wrap(pointer(v))) + self.assertEqual(result.contents.value, v.value) + + p = pointer(c_int(99)) + result = f(self.wrap(p)) + self.assertEqual(result.contents.value, 99) + + def test_shorts(self): + f = dll._testfunc_callback_i_if + + args = [] + expected = [262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, + 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1] + + def callback(v): + args.append(v) + return v + + CallBack = CFUNCTYPE(c_int, c_int) + + cb = CallBack(callback) + f(self.wrap(2**18), self.wrap(cb)) + self.assertEqual(args, expected) + + ################################################################ + + def test_callbacks(self): + f = dll._testfunc_callback_i_if + f.restype = c_int + f.argtypes = None + + MyCallback = CFUNCTYPE(c_int, c_int) + + def callback(value): + #print "called back with", value + return value + + cb = MyCallback(callback) + + result = f(self.wrap(-10), self.wrap(cb)) + self.assertEqual(result, -18) + + # test with prototype + f.argtypes = [c_int, MyCallback] + cb = MyCallback(callback) + + result = f(self.wrap(-10), self.wrap(cb)) + self.assertEqual(result, -18) + + result = f(self.wrap(-10), self.wrap(cb)) + self.assertEqual(result, -18) + + AnotherCallback = CALLBACK_FUNCTYPE(c_int, c_int, c_int, c_int, c_int) + + # check that the prototype works: we call f with wrong + # argument types + cb = AnotherCallback(callback) + self.assertRaises(ArgumentError, f, self.wrap(-10), self.wrap(cb)) + + def test_callbacks_2(self): + # Can also use simple datatypes as argument type specifiers + # for the callback function. + # In this case the call receives an instance of that type + f = dll._testfunc_callback_i_if + f.restype = c_int + + MyCallback = CFUNCTYPE(c_int, c_int) + + f.argtypes = [c_int, MyCallback] + + def callback(value): + #print "called back with", value + self.assertEqual(type(value), int) + return value + + cb = MyCallback(callback) + result = f(self.wrap(-10), self.wrap(cb)) + self.assertEqual(result, -18) + + def test_longlong_callbacks(self): + + f = dll._testfunc_callback_q_qf + f.restype = c_longlong + + MyCallback = CFUNCTYPE(c_longlong, c_longlong) + + f.argtypes = [c_longlong, MyCallback] + + def callback(value): + self.assertTrue(isinstance(value, (int, long))) + return value & 0x7FFFFFFF + + cb = MyCallback(callback) + + self.assertEqual(13577625587, int(f(self.wrap(1000000000000), self.wrap(cb)))) + + def test_byval(self): + # without prototype + ptin = POINT(1, 2) + ptout = POINT() + # EXPORT int _testfunc_byval(point in, point *pout) + result = dll._testfunc_byval(ptin, byref(ptout)) + got = result, ptout.x, ptout.y + expected = 3, 1, 2 + self.assertEqual(got, expected) + + # with prototype + ptin = POINT(101, 102) + ptout = POINT() + dll._testfunc_byval.argtypes = (POINT, POINTER(POINT)) + dll._testfunc_byval.restype = c_int + result = dll._testfunc_byval(self.wrap(ptin), byref(ptout)) + got = result, ptout.x, ptout.y + expected = 203, 101, 102 + self.assertEqual(got, expected) + + def test_struct_return_2H(self): + class S2H(Structure): + _fields_ = [("x", c_short), + ("y", c_short)] + dll.ret_2h_func.restype = S2H + dll.ret_2h_func.argtypes = [S2H] + inp = S2H(99, 88) + s2h = dll.ret_2h_func(self.wrap(inp)) + self.assertEqual((s2h.x, s2h.y), (99*2, 88*3)) + + # This is known cdecl incompatibility between GCC + # and MSVC. It is addressed in GCC issue #36834. + # Python libffi detect it and complain. + @unittest.skipIf(sys.platform == "win32" and sys.version.find("GCC") >= 0, 'XFAIL GCC(mingw)') + def test_struct_return_8H(self): + class S8I(Structure): + _fields_ = [("a", c_int), + ("b", c_int), + ("c", c_int), + ("d", c_int), + ("e", c_int), + ("f", c_int), + ("g", c_int), + ("h", c_int)] + dll.ret_8i_func.restype = S8I + dll.ret_8i_func.argtypes = [S8I] + inp = S8I(9, 8, 7, 6, 5, 4, 3, 2) + s8i = dll.ret_8i_func(self.wrap(inp)) + self.assertEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h), + (9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9)) + + def test_recursive_as_param(self): + from ctypes import c_int + + class A(object): + pass + + a = A() + a._as_parameter_ = a + with self.assertRaises(RuntimeError): + c_int.from_param(a) + + +#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +class AsParamWrapper(object): + def __init__(self, param): + self._as_parameter_ = param + +class AsParamWrapperTestCase(BasicWrapTestCase): + wrap = AsParamWrapper + +#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +class AsParamPropertyWrapper(object): + def __init__(self, param): + self._param = param + + def getParameter(self): + return self._param + _as_parameter_ = property(getParameter) + +class AsParamPropertyWrapperTestCase(BasicWrapTestCase): + wrap = AsParamPropertyWrapper + +#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_as_parameter.pyc b/lib/python2.7/ctypes/test/test_as_parameter.pyc new file mode 100644 index 0000000..a923bb7 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_as_parameter.pyc differ diff --git a/lib/python2.7/ctypes/test/test_as_parameter.pyo b/lib/python2.7/ctypes/test/test_as_parameter.pyo new file mode 100644 index 0000000..a923bb7 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_as_parameter.pyo differ diff --git a/lib/python2.7/ctypes/test/test_bitfields.py b/lib/python2.7/ctypes/test/test_bitfields.py new file mode 100644 index 0000000..3bcc67f --- /dev/null +++ b/lib/python2.7/ctypes/test/test_bitfields.py @@ -0,0 +1,264 @@ +from ctypes import * +import unittest +import os + +import ctypes +import _ctypes_test + +class BITS(Structure): + _fields_ = [("A", c_int, 1), + ("B", c_int, 2), + ("C", c_int, 3), + ("D", c_int, 4), + ("E", c_int, 5), + ("F", c_int, 6), + ("G", c_int, 7), + ("H", c_int, 8), + ("I", c_int, 9), + + ("M", c_short, 1), + ("N", c_short, 2), + ("O", c_short, 3), + ("P", c_short, 4), + ("Q", c_short, 5), + ("R", c_short, 6), + ("S", c_short, 7)] + +func = CDLL(_ctypes_test.__file__).unpack_bitfields +func.argtypes = POINTER(BITS), c_char + +##for n in "ABCDEFGHIMNOPQRS": +## print n, hex(getattr(BITS, n).size), getattr(BITS, n).offset + +class C_Test(unittest.TestCase): + + def test_ints(self): + for i in range(512): + for name in "ABCDEFGHI": + b = BITS() + setattr(b, name, i) + self.assertEqual((name, i, getattr(b, name)), (name, i, func(byref(b), name))) + + def test_shorts(self): + for i in range(256): + for name in "MNOPQRS": + b = BITS() + setattr(b, name, i) + self.assertEqual((name, i, getattr(b, name)), (name, i, func(byref(b), name))) + +signed_int_types = (c_byte, c_short, c_int, c_long, c_longlong) +unsigned_int_types = (c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong) +int_types = unsigned_int_types + signed_int_types + +class BitFieldTest(unittest.TestCase): + + def test_longlong(self): + class X(Structure): + _fields_ = [("a", c_longlong, 1), + ("b", c_longlong, 62), + ("c", c_longlong, 1)] + + self.assertEqual(sizeof(X), sizeof(c_longlong)) + x = X() + x.a, x.b, x.c = -1, 7, -1 + self.assertEqual((x.a, x.b, x.c), (-1, 7, -1)) + + def test_ulonglong(self): + class X(Structure): + _fields_ = [("a", c_ulonglong, 1), + ("b", c_ulonglong, 62), + ("c", c_ulonglong, 1)] + + self.assertEqual(sizeof(X), sizeof(c_longlong)) + x = X() + self.assertEqual((x.a, x.b, x.c), (0, 0, 0)) + x.a, x.b, x.c = 7, 7, 7 + self.assertEqual((x.a, x.b, x.c), (1, 7, 1)) + + def test_signed(self): + for c_typ in signed_int_types: + class X(Structure): + _fields_ = [("dummy", c_typ), + ("a", c_typ, 3), + ("b", c_typ, 3), + ("c", c_typ, 1)] + self.assertEqual(sizeof(X), sizeof(c_typ)*2) + + x = X() + self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, 0, 0)) + x.a = -1 + self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, -1, 0, 0)) + x.a, x.b = 0, -1 + self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, -1, 0)) + + + def test_unsigned(self): + for c_typ in unsigned_int_types: + class X(Structure): + _fields_ = [("a", c_typ, 3), + ("b", c_typ, 3), + ("c", c_typ, 1)] + self.assertEqual(sizeof(X), sizeof(c_typ)) + + x = X() + self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, 0, 0)) + x.a = -1 + self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, 7, 0, 0)) + x.a, x.b = 0, -1 + self.assertEqual((c_typ, x.a, x.b, x.c), (c_typ, 0, 7, 0)) + + + def fail_fields(self, *fields): + return self.get_except(type(Structure), "X", (), + {"_fields_": fields}) + + def test_nonint_types(self): + # bit fields are not allowed on non-integer types. + result = self.fail_fields(("a", c_char_p, 1)) + self.assertEqual(result, (TypeError, 'bit fields not allowed for type c_char_p')) + + result = self.fail_fields(("a", c_void_p, 1)) + self.assertEqual(result, (TypeError, 'bit fields not allowed for type c_void_p')) + + if c_int != c_long: + result = self.fail_fields(("a", POINTER(c_int), 1)) + self.assertEqual(result, (TypeError, 'bit fields not allowed for type LP_c_int')) + + result = self.fail_fields(("a", c_char, 1)) + self.assertEqual(result, (TypeError, 'bit fields not allowed for type c_char')) + + try: + c_wchar + except NameError: + pass + else: + result = self.fail_fields(("a", c_wchar, 1)) + self.assertEqual(result, (TypeError, 'bit fields not allowed for type c_wchar')) + + class Dummy(Structure): + _fields_ = [] + + result = self.fail_fields(("a", Dummy, 1)) + self.assertEqual(result, (TypeError, 'bit fields not allowed for type Dummy')) + + def test_single_bitfield_size(self): + for c_typ in int_types: + result = self.fail_fields(("a", c_typ, -1)) + self.assertEqual(result, (ValueError, 'number of bits invalid for bit field')) + + result = self.fail_fields(("a", c_typ, 0)) + self.assertEqual(result, (ValueError, 'number of bits invalid for bit field')) + + class X(Structure): + _fields_ = [("a", c_typ, 1)] + self.assertEqual(sizeof(X), sizeof(c_typ)) + + class X(Structure): + _fields_ = [("a", c_typ, sizeof(c_typ)*8)] + self.assertEqual(sizeof(X), sizeof(c_typ)) + + result = self.fail_fields(("a", c_typ, sizeof(c_typ)*8 + 1)) + self.assertEqual(result, (ValueError, 'number of bits invalid for bit field')) + + def test_multi_bitfields_size(self): + class X(Structure): + _fields_ = [("a", c_short, 1), + ("b", c_short, 14), + ("c", c_short, 1)] + self.assertEqual(sizeof(X), sizeof(c_short)) + + class X(Structure): + _fields_ = [("a", c_short, 1), + ("a1", c_short), + ("b", c_short, 14), + ("c", c_short, 1)] + self.assertEqual(sizeof(X), sizeof(c_short)*3) + self.assertEqual(X.a.offset, 0) + self.assertEqual(X.a1.offset, sizeof(c_short)) + self.assertEqual(X.b.offset, sizeof(c_short)*2) + self.assertEqual(X.c.offset, sizeof(c_short)*2) + + class X(Structure): + _fields_ = [("a", c_short, 3), + ("b", c_short, 14), + ("c", c_short, 14)] + self.assertEqual(sizeof(X), sizeof(c_short)*3) + self.assertEqual(X.a.offset, sizeof(c_short)*0) + self.assertEqual(X.b.offset, sizeof(c_short)*1) + self.assertEqual(X.c.offset, sizeof(c_short)*2) + + + def get_except(self, func, *args, **kw): + try: + func(*args, **kw) + except Exception, detail: + return detail.__class__, str(detail) + + def test_mixed_1(self): + class X(Structure): + _fields_ = [("a", c_byte, 4), + ("b", c_int, 4)] + if os.name in ("nt", "ce"): + self.assertEqual(sizeof(X), sizeof(c_int)*2) + else: + self.assertEqual(sizeof(X), sizeof(c_int)) + + def test_mixed_2(self): + class X(Structure): + _fields_ = [("a", c_byte, 4), + ("b", c_int, 32)] + self.assertEqual(sizeof(X), sizeof(c_int)*2) + + def test_mixed_3(self): + class X(Structure): + _fields_ = [("a", c_byte, 4), + ("b", c_ubyte, 4)] + self.assertEqual(sizeof(X), sizeof(c_byte)) + + def test_mixed_4(self): + class X(Structure): + _fields_ = [("a", c_short, 4), + ("b", c_short, 4), + ("c", c_int, 24), + ("d", c_short, 4), + ("e", c_short, 4), + ("f", c_int, 24)] + # MSVC does NOT combine c_short and c_int into one field, GCC + # does (unless GCC is run with '-mms-bitfields' which + # produces code compatible with MSVC). + if os.name in ("nt", "ce"): + self.assertEqual(sizeof(X), sizeof(c_int) * 4) + else: + self.assertEqual(sizeof(X), sizeof(c_int) * 2) + + def test_anon_bitfields(self): + # anonymous bit-fields gave a strange error message + class X(Structure): + _fields_ = [("a", c_byte, 4), + ("b", c_ubyte, 4)] + class Y(Structure): + _anonymous_ = ["_"] + _fields_ = [("_", X)] + + @unittest.skipUnless(hasattr(ctypes, "c_uint32"), "c_int32 is required") + def test_uint32(self): + class X(Structure): + _fields_ = [("a", c_uint32, 32)] + x = X() + x.a = 10 + self.assertEqual(x.a, 10) + x.a = 0xFDCBA987 + self.assertEqual(x.a, 0xFDCBA987) + + @unittest.skipUnless(hasattr(ctypes, "c_uint64"), "c_int64 is required") + def test_uint64(self): + class X(Structure): + _fields_ = [("a", c_uint64, 64)] + x = X() + x.a = 10 + self.assertEqual(x.a, 10) + x.a = 0xFEDCBA9876543211 + self.assertEqual(x.a, 0xFEDCBA9876543211) + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_bitfields.pyc b/lib/python2.7/ctypes/test/test_bitfields.pyc new file mode 100644 index 0000000..00b9e2b Binary files /dev/null and b/lib/python2.7/ctypes/test/test_bitfields.pyc differ diff --git a/lib/python2.7/ctypes/test/test_bitfields.pyo b/lib/python2.7/ctypes/test/test_bitfields.pyo new file mode 100644 index 0000000..00b9e2b Binary files /dev/null and b/lib/python2.7/ctypes/test/test_bitfields.pyo differ diff --git a/lib/python2.7/ctypes/test/test_buffers.py b/lib/python2.7/ctypes/test/test_buffers.py new file mode 100644 index 0000000..12945ed --- /dev/null +++ b/lib/python2.7/ctypes/test/test_buffers.py @@ -0,0 +1,74 @@ +from ctypes import * +import unittest + +class StringBufferTestCase(unittest.TestCase): + + def test_buffer(self): + b = create_string_buffer(32) + self.assertEqual(len(b), 32) + self.assertEqual(sizeof(b), 32 * sizeof(c_char)) + self.assertTrue(type(b[0]) is str) + + b = create_string_buffer("abc") + self.assertEqual(len(b), 4) # trailing nul char + self.assertEqual(sizeof(b), 4 * sizeof(c_char)) + self.assertTrue(type(b[0]) is str) + self.assertEqual(b[0], "a") + self.assertEqual(b[:], "abc\0") + self.assertEqual(b[::], "abc\0") + self.assertEqual(b[::-1], "\0cba") + self.assertEqual(b[::2], "ac") + self.assertEqual(b[::5], "a") + + def test_buffer_interface(self): + self.assertEqual(len(bytearray(create_string_buffer(0))), 0) + self.assertEqual(len(bytearray(create_string_buffer(1))), 1) + + def test_string_conversion(self): + b = create_string_buffer(u"abc") + self.assertEqual(len(b), 4) # trailing nul char + self.assertEqual(sizeof(b), 4 * sizeof(c_char)) + self.assertTrue(type(b[0]) is str) + self.assertEqual(b[0], "a") + self.assertEqual(b[:], "abc\0") + self.assertEqual(b[::], "abc\0") + self.assertEqual(b[::-1], "\0cba") + self.assertEqual(b[::2], "ac") + self.assertEqual(b[::5], "a") + + try: + c_wchar + except NameError: + pass + else: + def test_unicode_buffer(self): + b = create_unicode_buffer(32) + self.assertEqual(len(b), 32) + self.assertEqual(sizeof(b), 32 * sizeof(c_wchar)) + self.assertTrue(type(b[0]) is unicode) + + b = create_unicode_buffer(u"abc") + self.assertEqual(len(b), 4) # trailing nul char + self.assertEqual(sizeof(b), 4 * sizeof(c_wchar)) + self.assertTrue(type(b[0]) is unicode) + self.assertEqual(b[0], u"a") + self.assertEqual(b[:], "abc\0") + self.assertEqual(b[::], "abc\0") + self.assertEqual(b[::-1], "\0cba") + self.assertEqual(b[::2], "ac") + self.assertEqual(b[::5], "a") + + def test_unicode_conversion(self): + b = create_unicode_buffer("abc") + self.assertEqual(len(b), 4) # trailing nul char + self.assertEqual(sizeof(b), 4 * sizeof(c_wchar)) + self.assertTrue(type(b[0]) is unicode) + self.assertEqual(b[0], u"a") + self.assertEqual(b[:], "abc\0") + self.assertEqual(b[::], "abc\0") + self.assertEqual(b[::-1], "\0cba") + self.assertEqual(b[::2], "ac") + self.assertEqual(b[::5], "a") + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_buffers.pyc b/lib/python2.7/ctypes/test/test_buffers.pyc new file mode 100644 index 0000000..0605adf Binary files /dev/null and b/lib/python2.7/ctypes/test/test_buffers.pyc differ diff --git a/lib/python2.7/ctypes/test/test_buffers.pyo b/lib/python2.7/ctypes/test/test_buffers.pyo new file mode 100644 index 0000000..0605adf Binary files /dev/null and b/lib/python2.7/ctypes/test/test_buffers.pyo differ diff --git a/lib/python2.7/ctypes/test/test_byteswap.py b/lib/python2.7/ctypes/test/test_byteswap.py new file mode 100644 index 0000000..4bd75cd --- /dev/null +++ b/lib/python2.7/ctypes/test/test_byteswap.py @@ -0,0 +1,294 @@ +import sys, unittest, struct, math, ctypes +from binascii import hexlify + +from ctypes import * + +def bin(s): + return hexlify(memoryview(s)).upper() + +# Each *simple* type that supports different byte orders has an +# __ctype_be__ attribute that specifies the same type in BIG ENDIAN +# byte order, and a __ctype_le__ attribute that is the same type in +# LITTLE ENDIAN byte order. +# +# For Structures and Unions, these types are created on demand. + +class Test(unittest.TestCase): + def X_test(self): + print >> sys.stderr, sys.byteorder + for i in range(32): + bits = BITS() + setattr(bits, "i%s" % i, 1) + dump(bits) + + def test_endian_short(self): + if sys.byteorder == "little": + self.assertTrue(c_short.__ctype_le__ is c_short) + self.assertTrue(c_short.__ctype_be__.__ctype_le__ is c_short) + else: + self.assertTrue(c_short.__ctype_be__ is c_short) + self.assertTrue(c_short.__ctype_le__.__ctype_be__ is c_short) + s = c_short.__ctype_be__(0x1234) + self.assertEqual(bin(struct.pack(">h", 0x1234)), "1234") + self.assertEqual(bin(s), "1234") + self.assertEqual(s.value, 0x1234) + + s = c_short.__ctype_le__(0x1234) + self.assertEqual(bin(struct.pack("h", 0x1234)), "1234") + self.assertEqual(bin(s), "1234") + self.assertEqual(s.value, 0x1234) + + s = c_ushort.__ctype_le__(0x1234) + self.assertEqual(bin(struct.pack("i", 0x12345678)), "12345678") + self.assertEqual(bin(s), "12345678") + self.assertEqual(s.value, 0x12345678) + + s = c_int.__ctype_le__(0x12345678) + self.assertEqual(bin(struct.pack("I", 0x12345678)), "12345678") + self.assertEqual(bin(s), "12345678") + self.assertEqual(s.value, 0x12345678) + + s = c_uint.__ctype_le__(0x12345678) + self.assertEqual(bin(struct.pack("q", 0x1234567890ABCDEF)), "1234567890ABCDEF") + self.assertEqual(bin(s), "1234567890ABCDEF") + self.assertEqual(s.value, 0x1234567890ABCDEF) + + s = c_longlong.__ctype_le__(0x1234567890ABCDEF) + self.assertEqual(bin(struct.pack("Q", 0x1234567890ABCDEF)), "1234567890ABCDEF") + self.assertEqual(bin(s), "1234567890ABCDEF") + self.assertEqual(s.value, 0x1234567890ABCDEF) + + s = c_ulonglong.__ctype_le__(0x1234567890ABCDEF) + self.assertEqual(bin(struct.pack("f", math.pi)), bin(s)) + + def test_endian_double(self): + if sys.byteorder == "little": + self.assertTrue(c_double.__ctype_le__ is c_double) + self.assertTrue(c_double.__ctype_be__.__ctype_le__ is c_double) + else: + self.assertTrue(c_double.__ctype_be__ is c_double) + self.assertTrue(c_double.__ctype_le__.__ctype_be__ is c_double) + s = c_double(math.pi) + self.assertEqual(s.value, math.pi) + self.assertEqual(bin(struct.pack("d", math.pi)), bin(s)) + s = c_double.__ctype_le__(math.pi) + self.assertEqual(s.value, math.pi) + self.assertEqual(bin(struct.pack("d", math.pi)), bin(s)) + + def test_endian_other(self): + self.assertTrue(c_byte.__ctype_le__ is c_byte) + self.assertTrue(c_byte.__ctype_be__ is c_byte) + + self.assertTrue(c_ubyte.__ctype_le__ is c_ubyte) + self.assertTrue(c_ubyte.__ctype_be__ is c_ubyte) + + self.assertTrue(c_char.__ctype_le__ is c_char) + self.assertTrue(c_char.__ctype_be__ is c_char) + + def test_struct_fields_1(self): + if sys.byteorder == "little": + base = BigEndianStructure + else: + base = LittleEndianStructure + + class T(base): + pass + _fields_ = [("a", c_ubyte), + ("b", c_byte), + ("c", c_short), + ("d", c_ushort), + ("e", c_int), + ("f", c_uint), + ("g", c_long), + ("h", c_ulong), + ("i", c_longlong), + ("k", c_ulonglong), + ("l", c_float), + ("m", c_double), + ("n", c_char), + + ("b1", c_byte, 3), + ("b2", c_byte, 3), + ("b3", c_byte, 2), + ("a", c_int * 3 * 3 * 3)] + T._fields_ = _fields_ + + # these fields do not support different byte order: + for typ in c_wchar, c_void_p, POINTER(c_int): + _fields_.append(("x", typ)) + class T(base): + pass + self.assertRaises(TypeError, setattr, T, "_fields_", [("x", typ)]) + + def test_struct_struct(self): + # nested structures with different byteorders + + # create nested structures with given byteorders and set memory to data + + for nested, data in ( + (BigEndianStructure, b'\0\0\0\1\0\0\0\2'), + (LittleEndianStructure, b'\1\0\0\0\2\0\0\0'), + ): + for parent in ( + BigEndianStructure, + LittleEndianStructure, + Structure, + ): + class NestedStructure(nested): + _fields_ = [("x", c_uint32), + ("y", c_uint32)] + + class TestStructure(parent): + _fields_ = [("point", NestedStructure)] + + self.assertEqual(len(data), sizeof(TestStructure)) + ptr = POINTER(TestStructure) + s = cast(data, ptr)[0] + del ctypes._pointer_type_cache[TestStructure] + self.assertEqual(s.point.x, 1) + self.assertEqual(s.point.y, 2) + + def test_struct_fields_2(self): + # standard packing in struct uses no alignment. + # So, we have to align using pad bytes. + # + # Unaligned accesses will crash Python (on those platforms that + # don't allow it, like sparc solaris). + if sys.byteorder == "little": + base = BigEndianStructure + fmt = ">bxhid" + else: + base = LittleEndianStructure + fmt = " float -> double + import math + self.check_type(c_float, math.e) + self.check_type(c_float, -math.e) + + def test_double(self): + self.check_type(c_double, 3.14) + self.check_type(c_double, -3.14) + + def test_longdouble(self): + self.check_type(c_longdouble, 3.14) + self.check_type(c_longdouble, -3.14) + + def test_char(self): + self.check_type(c_char, "x") + self.check_type(c_char, "a") + + # disabled: would now (correctly) raise a RuntimeWarning about + # a memory leak. A callback function cannot return a non-integral + # C type without causing a memory leak. +## def test_char_p(self): +## self.check_type(c_char_p, "abc") +## self.check_type(c_char_p, "def") + + def test_pyobject(self): + o = () + from sys import getrefcount as grc + for o in (), [], object(): + initial = grc(o) + # This call leaks a reference to 'o'... + self.check_type(py_object, o) + before = grc(o) + # ...but this call doesn't leak any more. Where is the refcount? + self.check_type(py_object, o) + after = grc(o) + self.assertEqual((after, o), (before, o)) + + def test_unsupported_restype_1(self): + # Only "fundamental" result types are supported for callback + # functions, the type must have a non-NULL stgdict->setfunc. + # POINTER(c_double), for example, is not supported. + + prototype = self.functype.im_func(POINTER(c_double)) + # The type is checked when the prototype is called + self.assertRaises(TypeError, prototype, lambda: None) + + def test_unsupported_restype_2(self): + prototype = self.functype.im_func(object) + self.assertRaises(TypeError, prototype, lambda: None) + + def test_issue_7959(self): + proto = self.functype.im_func(None) + + class X(object): + def func(self): pass + def __init__(self): + self.v = proto(self.func) + + import gc + for i in range(32): + X() + gc.collect() + live = [x for x in gc.get_objects() + if isinstance(x, X)] + self.assertEqual(len(live), 0) + + def test_issue12483(self): + import gc + class Nasty: + def __del__(self): + gc.collect() + CFUNCTYPE(None)(lambda x=Nasty(): None) + + +try: + WINFUNCTYPE +except NameError: + pass +else: + class StdcallCallbacks(Callbacks): + functype = WINFUNCTYPE + +################################################################ + +class SampleCallbacksTestCase(unittest.TestCase): + + def test_integrate(self): + # Derived from some then non-working code, posted by David Foster + dll = CDLL(_ctypes_test.__file__) + + # The function prototype called by 'integrate': double func(double); + CALLBACK = CFUNCTYPE(c_double, c_double) + + # The integrate function itself, exposed from the _ctypes_test dll + integrate = dll.integrate + integrate.argtypes = (c_double, c_double, CALLBACK, c_long) + integrate.restype = c_double + + def func(x): + return x**2 + + result = integrate(0.0, 1.0, CALLBACK(func), 10) + diff = abs(result - 1./3.) + + self.assertLess(diff, 0.01, "%s not less than 0.01" % diff) + + def test_issue_8959_a(self): + from ctypes.util import find_library + libc_path = find_library("c") + if not libc_path: + return # cannot test + libc = CDLL(libc_path) + + @CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int)) + def cmp_func(a, b): + return a[0] - b[0] + + array = (c_int * 5)(5, 1, 99, 7, 33) + + libc.qsort(array, len(array), sizeof(c_int), cmp_func) + self.assertEqual(array[:], [1, 5, 7, 33, 99]) + + try: + WINFUNCTYPE + except NameError: + pass + else: + def test_issue_8959_b(self): + from ctypes.wintypes import BOOL, HWND, LPARAM + global windowCount + windowCount = 0 + + @WINFUNCTYPE(BOOL, HWND, LPARAM) + def EnumWindowsCallbackFunc(hwnd, lParam): + global windowCount + windowCount += 1 + return True #Allow windows to keep enumerating + + windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0) + + def test_callback_register_int(self): + # Issue #8275: buggy handling of callback args under Win64 + # NOTE: should be run on release builds as well + dll = CDLL(_ctypes_test.__file__) + CALLBACK = CFUNCTYPE(c_int, c_int, c_int, c_int, c_int, c_int) + # All this function does is call the callback with its args squared + func = dll._testfunc_cbk_reg_int + func.argtypes = (c_int, c_int, c_int, c_int, c_int, CALLBACK) + func.restype = c_int + + def callback(a, b, c, d, e): + return a + b + c + d + e + + result = func(2, 3, 4, 5, 6, CALLBACK(callback)) + self.assertEqual(result, callback(2*2, 3*3, 4*4, 5*5, 6*6)) + + def test_callback_register_double(self): + # Issue #8275: buggy handling of callback args under Win64 + # NOTE: should be run on release builds as well + dll = CDLL(_ctypes_test.__file__) + CALLBACK = CFUNCTYPE(c_double, c_double, c_double, c_double, + c_double, c_double) + # All this function does is call the callback with its args squared + func = dll._testfunc_cbk_reg_double + func.argtypes = (c_double, c_double, c_double, + c_double, c_double, CALLBACK) + func.restype = c_double + + def callback(a, b, c, d, e): + return a + b + c + d + e + + result = func(1.1, 2.2, 3.3, 4.4, 5.5, CALLBACK(callback)) + self.assertEqual(result, + callback(1.1*1.1, 2.2*2.2, 3.3*3.3, 4.4*4.4, 5.5*5.5)) + + +################################################################ + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_callbacks.pyc b/lib/python2.7/ctypes/test/test_callbacks.pyc new file mode 100644 index 0000000..8043611 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_callbacks.pyc differ diff --git a/lib/python2.7/ctypes/test/test_callbacks.pyo b/lib/python2.7/ctypes/test/test_callbacks.pyo new file mode 100644 index 0000000..8043611 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_callbacks.pyo differ diff --git a/lib/python2.7/ctypes/test/test_cast.py b/lib/python2.7/ctypes/test/test_cast.py new file mode 100644 index 0000000..906fffc --- /dev/null +++ b/lib/python2.7/ctypes/test/test_cast.py @@ -0,0 +1,89 @@ +from ctypes import * +import unittest +import sys + +class Test(unittest.TestCase): + + def test_array2pointer(self): + array = (c_int * 3)(42, 17, 2) + + # casting an array to a pointer works. + ptr = cast(array, POINTER(c_int)) + self.assertEqual([ptr[i] for i in range(3)], [42, 17, 2]) + + if 2*sizeof(c_short) == sizeof(c_int): + ptr = cast(array, POINTER(c_short)) + if sys.byteorder == "little": + self.assertEqual([ptr[i] for i in range(6)], + [42, 0, 17, 0, 2, 0]) + else: + self.assertEqual([ptr[i] for i in range(6)], + [0, 42, 0, 17, 0, 2]) + + def test_address2pointer(self): + array = (c_int * 3)(42, 17, 2) + + address = addressof(array) + ptr = cast(c_void_p(address), POINTER(c_int)) + self.assertEqual([ptr[i] for i in range(3)], [42, 17, 2]) + + ptr = cast(address, POINTER(c_int)) + self.assertEqual([ptr[i] for i in range(3)], [42, 17, 2]) + + def test_p2a_objects(self): + array = (c_char_p * 5)() + self.assertEqual(array._objects, None) + array[0] = "foo bar" + self.assertEqual(array._objects, {'0': "foo bar"}) + + p = cast(array, POINTER(c_char_p)) + # array and p share a common _objects attribute + self.assertTrue(p._objects is array._objects) + self.assertEqual(array._objects, {'0': "foo bar", id(array): array}) + p[0] = "spam spam" + self.assertEqual(p._objects, {'0': "spam spam", id(array): array}) + self.assertTrue(array._objects is p._objects) + p[1] = "foo bar" + self.assertEqual(p._objects, {'1': 'foo bar', '0': "spam spam", id(array): array}) + self.assertTrue(array._objects is p._objects) + + def test_other(self): + p = cast((c_int * 4)(1, 2, 3, 4), POINTER(c_int)) + self.assertEqual(p[:4], [1,2, 3, 4]) + self.assertEqual(p[:4:], [1, 2, 3, 4]) + self.assertEqual(p[3:-1:-1], [4, 3, 2, 1]) + self.assertEqual(p[:4:3], [1, 4]) + c_int() + self.assertEqual(p[:4], [1, 2, 3, 4]) + self.assertEqual(p[:4:], [1, 2, 3, 4]) + self.assertEqual(p[3:-1:-1], [4, 3, 2, 1]) + self.assertEqual(p[:4:3], [1, 4]) + p[2] = 96 + self.assertEqual(p[:4], [1, 2, 96, 4]) + self.assertEqual(p[:4:], [1, 2, 96, 4]) + self.assertEqual(p[3:-1:-1], [4, 96, 2, 1]) + self.assertEqual(p[:4:3], [1, 4]) + c_int() + self.assertEqual(p[:4], [1, 2, 96, 4]) + self.assertEqual(p[:4:], [1, 2, 96, 4]) + self.assertEqual(p[3:-1:-1], [4, 96, 2, 1]) + self.assertEqual(p[:4:3], [1, 4]) + + def test_char_p(self): + # This didn't work: bad argument to internal function + s = c_char_p("hiho") + self.assertEqual(cast(cast(s, c_void_p), c_char_p).value, + "hiho") + + try: + c_wchar_p + except NameError: + pass + else: + def test_wchar_p(self): + s = c_wchar_p("hiho") + self.assertEqual(cast(cast(s, c_void_p), c_wchar_p).value, + "hiho") + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_cast.pyc b/lib/python2.7/ctypes/test/test_cast.pyc new file mode 100644 index 0000000..cc30124 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_cast.pyc differ diff --git a/lib/python2.7/ctypes/test/test_cast.pyo b/lib/python2.7/ctypes/test/test_cast.pyo new file mode 100644 index 0000000..cc30124 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_cast.pyo differ diff --git a/lib/python2.7/ctypes/test/test_cfuncs.py b/lib/python2.7/ctypes/test/test_cfuncs.py new file mode 100644 index 0000000..493cbe9 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_cfuncs.py @@ -0,0 +1,211 @@ +# A lot of failures in these tests on Mac OS X. +# Byte order related? + +import unittest +from ctypes import * + +import _ctypes_test + +class CFunctions(unittest.TestCase): + _dll = CDLL(_ctypes_test.__file__) + + def S(self): + return c_longlong.in_dll(self._dll, "last_tf_arg_s").value + def U(self): + return c_ulonglong.in_dll(self._dll, "last_tf_arg_u").value + + def test_byte(self): + self._dll.tf_b.restype = c_byte + self._dll.tf_b.argtypes = (c_byte,) + self.assertEqual(self._dll.tf_b(-126), -42) + self.assertEqual(self.S(), -126) + + def test_byte_plus(self): + self._dll.tf_bb.restype = c_byte + self._dll.tf_bb.argtypes = (c_byte, c_byte) + self.assertEqual(self._dll.tf_bb(0, -126), -42) + self.assertEqual(self.S(), -126) + + def test_ubyte(self): + self._dll.tf_B.restype = c_ubyte + self._dll.tf_B.argtypes = (c_ubyte,) + self.assertEqual(self._dll.tf_B(255), 85) + self.assertEqual(self.U(), 255) + + def test_ubyte_plus(self): + self._dll.tf_bB.restype = c_ubyte + self._dll.tf_bB.argtypes = (c_byte, c_ubyte) + self.assertEqual(self._dll.tf_bB(0, 255), 85) + self.assertEqual(self.U(), 255) + + def test_short(self): + self._dll.tf_h.restype = c_short + self._dll.tf_h.argtypes = (c_short,) + self.assertEqual(self._dll.tf_h(-32766), -10922) + self.assertEqual(self.S(), -32766) + + def test_short_plus(self): + self._dll.tf_bh.restype = c_short + self._dll.tf_bh.argtypes = (c_byte, c_short) + self.assertEqual(self._dll.tf_bh(0, -32766), -10922) + self.assertEqual(self.S(), -32766) + + def test_ushort(self): + self._dll.tf_H.restype = c_ushort + self._dll.tf_H.argtypes = (c_ushort,) + self.assertEqual(self._dll.tf_H(65535), 21845) + self.assertEqual(self.U(), 65535) + + def test_ushort_plus(self): + self._dll.tf_bH.restype = c_ushort + self._dll.tf_bH.argtypes = (c_byte, c_ushort) + self.assertEqual(self._dll.tf_bH(0, 65535), 21845) + self.assertEqual(self.U(), 65535) + + def test_int(self): + self._dll.tf_i.restype = c_int + self._dll.tf_i.argtypes = (c_int,) + self.assertEqual(self._dll.tf_i(-2147483646), -715827882) + self.assertEqual(self.S(), -2147483646) + + def test_int_plus(self): + self._dll.tf_bi.restype = c_int + self._dll.tf_bi.argtypes = (c_byte, c_int) + self.assertEqual(self._dll.tf_bi(0, -2147483646), -715827882) + self.assertEqual(self.S(), -2147483646) + + def test_uint(self): + self._dll.tf_I.restype = c_uint + self._dll.tf_I.argtypes = (c_uint,) + self.assertEqual(self._dll.tf_I(4294967295), 1431655765) + self.assertEqual(self.U(), 4294967295) + + def test_uint_plus(self): + self._dll.tf_bI.restype = c_uint + self._dll.tf_bI.argtypes = (c_byte, c_uint) + self.assertEqual(self._dll.tf_bI(0, 4294967295), 1431655765) + self.assertEqual(self.U(), 4294967295) + + def test_long(self): + self._dll.tf_l.restype = c_long + self._dll.tf_l.argtypes = (c_long,) + self.assertEqual(self._dll.tf_l(-2147483646), -715827882) + self.assertEqual(self.S(), -2147483646) + + def test_long_plus(self): + self._dll.tf_bl.restype = c_long + self._dll.tf_bl.argtypes = (c_byte, c_long) + self.assertEqual(self._dll.tf_bl(0, -2147483646), -715827882) + self.assertEqual(self.S(), -2147483646) + + def test_ulong(self): + self._dll.tf_L.restype = c_ulong + self._dll.tf_L.argtypes = (c_ulong,) + self.assertEqual(self._dll.tf_L(4294967295), 1431655765) + self.assertEqual(self.U(), 4294967295) + + def test_ulong_plus(self): + self._dll.tf_bL.restype = c_ulong + self._dll.tf_bL.argtypes = (c_char, c_ulong) + self.assertEqual(self._dll.tf_bL(' ', 4294967295), 1431655765) + self.assertEqual(self.U(), 4294967295) + + def test_longlong(self): + self._dll.tf_q.restype = c_longlong + self._dll.tf_q.argtypes = (c_longlong, ) + self.assertEqual(self._dll.tf_q(-9223372036854775806), -3074457345618258602) + self.assertEqual(self.S(), -9223372036854775806) + + def test_longlong_plus(self): + self._dll.tf_bq.restype = c_longlong + self._dll.tf_bq.argtypes = (c_byte, c_longlong) + self.assertEqual(self._dll.tf_bq(0, -9223372036854775806), -3074457345618258602) + self.assertEqual(self.S(), -9223372036854775806) + + def test_ulonglong(self): + self._dll.tf_Q.restype = c_ulonglong + self._dll.tf_Q.argtypes = (c_ulonglong, ) + self.assertEqual(self._dll.tf_Q(18446744073709551615), 6148914691236517205) + self.assertEqual(self.U(), 18446744073709551615) + + def test_ulonglong_plus(self): + self._dll.tf_bQ.restype = c_ulonglong + self._dll.tf_bQ.argtypes = (c_byte, c_ulonglong) + self.assertEqual(self._dll.tf_bQ(0, 18446744073709551615), 6148914691236517205) + self.assertEqual(self.U(), 18446744073709551615) + + def test_float(self): + self._dll.tf_f.restype = c_float + self._dll.tf_f.argtypes = (c_float,) + self.assertEqual(self._dll.tf_f(-42.), -14.) + self.assertEqual(self.S(), -42) + + def test_float_plus(self): + self._dll.tf_bf.restype = c_float + self._dll.tf_bf.argtypes = (c_byte, c_float) + self.assertEqual(self._dll.tf_bf(0, -42.), -14.) + self.assertEqual(self.S(), -42) + + def test_double(self): + self._dll.tf_d.restype = c_double + self._dll.tf_d.argtypes = (c_double,) + self.assertEqual(self._dll.tf_d(42.), 14.) + self.assertEqual(self.S(), 42) + + def test_double_plus(self): + self._dll.tf_bd.restype = c_double + self._dll.tf_bd.argtypes = (c_byte, c_double) + self.assertEqual(self._dll.tf_bd(0, 42.), 14.) + self.assertEqual(self.S(), 42) + + def test_longdouble(self): + self._dll.tf_D.restype = c_longdouble + self._dll.tf_D.argtypes = (c_longdouble,) + self.assertEqual(self._dll.tf_D(42.), 14.) + self.assertEqual(self.S(), 42) + + def test_longdouble_plus(self): + self._dll.tf_bD.restype = c_longdouble + self._dll.tf_bD.argtypes = (c_byte, c_longdouble) + self.assertEqual(self._dll.tf_bD(0, 42.), 14.) + self.assertEqual(self.S(), 42) + + def test_callwithresult(self): + def process_result(result): + return result * 2 + self._dll.tf_i.restype = process_result + self._dll.tf_i.argtypes = (c_int,) + self.assertEqual(self._dll.tf_i(42), 28) + self.assertEqual(self.S(), 42) + self.assertEqual(self._dll.tf_i(-42), -28) + self.assertEqual(self.S(), -42) + + def test_void(self): + self._dll.tv_i.restype = None + self._dll.tv_i.argtypes = (c_int,) + self.assertEqual(self._dll.tv_i(42), None) + self.assertEqual(self.S(), 42) + self.assertEqual(self._dll.tv_i(-42), None) + self.assertEqual(self.S(), -42) + +# The following repeates the above tests with stdcall functions (where +# they are available) +try: + WinDLL +except NameError: + pass +else: + class stdcall_dll(WinDLL): + def __getattr__(self, name): + if name[:2] == '__' and name[-2:] == '__': + raise AttributeError(name) + func = self._FuncPtr(("s_" + name, self)) + setattr(self, name, func) + return func + + class stdcallCFunctions(CFunctions): + _dll = stdcall_dll(_ctypes_test.__file__) + pass + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_cfuncs.pyc b/lib/python2.7/ctypes/test/test_cfuncs.pyc new file mode 100644 index 0000000..6d03766 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_cfuncs.pyc differ diff --git a/lib/python2.7/ctypes/test/test_cfuncs.pyo b/lib/python2.7/ctypes/test/test_cfuncs.pyo new file mode 100644 index 0000000..6d03766 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_cfuncs.pyo differ diff --git a/lib/python2.7/ctypes/test/test_checkretval.py b/lib/python2.7/ctypes/test/test_checkretval.py new file mode 100644 index 0000000..01ccc57 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_checkretval.py @@ -0,0 +1,39 @@ +import unittest + +from ctypes import * + +class CHECKED(c_int): + def _check_retval_(value): + # Receives a CHECKED instance. + return str(value.value) + _check_retval_ = staticmethod(_check_retval_) + +class Test(unittest.TestCase): + + def test_checkretval(self): + + import _ctypes_test + dll = CDLL(_ctypes_test.__file__) + self.assertEqual(42, dll._testfunc_p_p(42)) + + dll._testfunc_p_p.restype = CHECKED + self.assertEqual("42", dll._testfunc_p_p(42)) + + dll._testfunc_p_p.restype = None + self.assertEqual(None, dll._testfunc_p_p(42)) + + del dll._testfunc_p_p.restype + self.assertEqual(42, dll._testfunc_p_p(42)) + + try: + oledll + except NameError: + pass + else: + def test_oledll(self): + self.assertRaises(WindowsError, + oledll.oleaut32.CreateTypeLib2, + 0, None, None) + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_checkretval.pyc b/lib/python2.7/ctypes/test/test_checkretval.pyc new file mode 100644 index 0000000..463e9a8 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_checkretval.pyc differ diff --git a/lib/python2.7/ctypes/test/test_checkretval.pyo b/lib/python2.7/ctypes/test/test_checkretval.pyo new file mode 100644 index 0000000..463e9a8 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_checkretval.pyo differ diff --git a/lib/python2.7/ctypes/test/test_delattr.py b/lib/python2.7/ctypes/test/test_delattr.py new file mode 100644 index 0000000..0f4d586 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_delattr.py @@ -0,0 +1,21 @@ +import unittest +from ctypes import * + +class X(Structure): + _fields_ = [("foo", c_int)] + +class TestCase(unittest.TestCase): + def test_simple(self): + self.assertRaises(TypeError, + delattr, c_int(42), "value") + + def test_chararray(self): + self.assertRaises(TypeError, + delattr, (c_char * 5)(), "value") + + def test_struct(self): + self.assertRaises(TypeError, + delattr, X(), "foo") + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_delattr.pyc b/lib/python2.7/ctypes/test/test_delattr.pyc new file mode 100644 index 0000000..9ecaa93 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_delattr.pyc differ diff --git a/lib/python2.7/ctypes/test/test_delattr.pyo b/lib/python2.7/ctypes/test/test_delattr.pyo new file mode 100644 index 0000000..9ecaa93 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_delattr.pyo differ diff --git a/lib/python2.7/ctypes/test/test_errcheck.py b/lib/python2.7/ctypes/test/test_errcheck.py new file mode 100644 index 0000000..a4913f9 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_errcheck.py @@ -0,0 +1,19 @@ +import sys +from ctypes import * + +##class HMODULE(Structure): +## _fields_ = [("value", c_void_p)] + +## def __repr__(self): +## return "" % self.value + +##windll.kernel32.GetModuleHandleA.restype = HMODULE + +##print windll.kernel32.GetModuleHandleA("python23.dll") +##print hex(sys.dllhandle) + +##def nonzero(handle): +## return (GetLastError(), handle) + +##windll.kernel32.GetModuleHandleA.errcheck = nonzero +##print windll.kernel32.GetModuleHandleA("spam") diff --git a/lib/python2.7/ctypes/test/test_errcheck.pyc b/lib/python2.7/ctypes/test/test_errcheck.pyc new file mode 100644 index 0000000..edf9aca Binary files /dev/null and b/lib/python2.7/ctypes/test/test_errcheck.pyc differ diff --git a/lib/python2.7/ctypes/test/test_errcheck.pyo b/lib/python2.7/ctypes/test/test_errcheck.pyo new file mode 100644 index 0000000..edf9aca Binary files /dev/null and b/lib/python2.7/ctypes/test/test_errcheck.pyo differ diff --git a/lib/python2.7/ctypes/test/test_errno.py b/lib/python2.7/ctypes/test/test_errno.py new file mode 100644 index 0000000..c7a5bf0 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_errno.py @@ -0,0 +1,80 @@ +import unittest, os, errno +from ctypes import * +from ctypes.util import find_library +from test import test_support +try: + import threading +except ImportError: + threading = None + +class Test(unittest.TestCase): + def test_open(self): + libc_name = find_library("c") + if libc_name is None: + raise unittest.SkipTest("Unable to find C library") + libc = CDLL(libc_name, use_errno=True) + if os.name == "nt": + libc_open = libc._open + else: + libc_open = libc.open + + libc_open.argtypes = c_char_p, c_int + + self.assertEqual(libc_open("", 0), -1) + self.assertEqual(get_errno(), errno.ENOENT) + + self.assertEqual(set_errno(32), errno.ENOENT) + self.assertEqual(get_errno(), 32) + + if threading: + def _worker(): + set_errno(0) + + libc = CDLL(libc_name, use_errno=False) + if os.name == "nt": + libc_open = libc._open + else: + libc_open = libc.open + libc_open.argtypes = c_char_p, c_int + self.assertEqual(libc_open("", 0), -1) + self.assertEqual(get_errno(), 0) + + t = threading.Thread(target=_worker) + t.start() + t.join() + + self.assertEqual(get_errno(), 32) + set_errno(0) + + @unittest.skipUnless(os.name == "nt", 'Test specific to Windows') + def test_GetLastError(self): + dll = WinDLL("kernel32", use_last_error=True) + GetModuleHandle = dll.GetModuleHandleA + GetModuleHandle.argtypes = [c_wchar_p] + + self.assertEqual(0, GetModuleHandle("foo")) + self.assertEqual(get_last_error(), 126) + + self.assertEqual(set_last_error(32), 126) + self.assertEqual(get_last_error(), 32) + + def _worker(): + set_last_error(0) + + dll = WinDLL("kernel32", use_last_error=False) + GetModuleHandle = dll.GetModuleHandleW + GetModuleHandle.argtypes = [c_wchar_p] + GetModuleHandle("bar") + + self.assertEqual(get_last_error(), 0) + + t = threading.Thread(target=_worker) + t.start() + t.join() + + self.assertEqual(get_last_error(), 32) + + set_last_error(0) + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_errno.pyc b/lib/python2.7/ctypes/test/test_errno.pyc new file mode 100644 index 0000000..537b5f3 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_errno.pyc differ diff --git a/lib/python2.7/ctypes/test/test_errno.pyo b/lib/python2.7/ctypes/test/test_errno.pyo new file mode 100644 index 0000000..537b5f3 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_errno.pyo differ diff --git a/lib/python2.7/ctypes/test/test_find.py b/lib/python2.7/ctypes/test/test_find.py new file mode 100644 index 0000000..77e789f --- /dev/null +++ b/lib/python2.7/ctypes/test/test_find.py @@ -0,0 +1,82 @@ +import unittest +import sys +from ctypes import * +from ctypes.util import find_library +from ctypes.test import is_resource_enabled + +if sys.platform == "win32": + lib_gl = find_library("OpenGL32") + lib_glu = find_library("Glu32") + lib_gle = None +elif sys.platform == "darwin": + lib_gl = lib_glu = find_library("OpenGL") + lib_gle = None +else: + lib_gl = find_library("GL") + lib_glu = find_library("GLU") + lib_gle = find_library("gle") + +## print, for debugging +if is_resource_enabled("printing"): + if lib_gl or lib_glu or lib_gle: + print "OpenGL libraries:" + for item in (("GL", lib_gl), + ("GLU", lib_glu), + ("gle", lib_gle)): + print "\t", item + + +# On some systems, loading the OpenGL libraries needs the RTLD_GLOBAL mode. +class Test_OpenGL_libs(unittest.TestCase): + def setUp(self): + self.gl = self.glu = self.gle = None + if lib_gl: + self.gl = CDLL(lib_gl, mode=RTLD_GLOBAL) + if lib_glu: + self.glu = CDLL(lib_glu, RTLD_GLOBAL) + if lib_gle: + try: + self.gle = CDLL(lib_gle) + except OSError: + pass + + if lib_gl: + def test_gl(self): + if self.gl: + self.gl.glClearIndex + + if lib_glu: + def test_glu(self): + if self.glu: + self.glu.gluBeginCurve + + if lib_gle: + def test_gle(self): + if self.gle: + self.gle.gleGetJoinStyle + +##if os.name == "posix" and sys.platform != "darwin": + +## # On platforms where the default shared library suffix is '.so', +## # at least some libraries can be loaded as attributes of the cdll +## # object, since ctypes now tries loading the lib again +## # with '.so' appended of the first try fails. +## # +## # Won't work for libc, unfortunately. OTOH, it isn't +## # needed for libc since this is already mapped into the current +## # process (?) +## # +## # On MAC OSX, it won't work either, because dlopen() needs a full path, +## # and the default suffix is either none or '.dylib'. + +## class LoadLibs(unittest.TestCase): +## def test_libm(self): +## import math +## libm = cdll.libm +## sqrt = libm.sqrt +## sqrt.argtypes = (c_double,) +## sqrt.restype = c_double +## self.assertEqual(sqrt(2), math.sqrt(2)) + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_find.pyc b/lib/python2.7/ctypes/test/test_find.pyc new file mode 100644 index 0000000..814397a Binary files /dev/null and b/lib/python2.7/ctypes/test/test_find.pyc differ diff --git a/lib/python2.7/ctypes/test/test_find.pyo b/lib/python2.7/ctypes/test/test_find.pyo new file mode 100644 index 0000000..814397a Binary files /dev/null and b/lib/python2.7/ctypes/test/test_find.pyo differ diff --git a/lib/python2.7/ctypes/test/test_frombuffer.py b/lib/python2.7/ctypes/test/test_frombuffer.py new file mode 100644 index 0000000..624fb70 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_frombuffer.py @@ -0,0 +1,81 @@ +from ctypes import * +import array +import gc +import unittest + +class X(Structure): + _fields_ = [("c_int", c_int)] + init_called = False + def __init__(self): + self._init_called = True + +class Test(unittest.TestCase): + def test_fom_buffer(self): + a = array.array("i", range(16)) + x = (c_int * 16).from_buffer(a) + + y = X.from_buffer(a) + self.assertEqual(y.c_int, a[0]) + self.assertFalse(y.init_called) + + self.assertEqual(x[:], a.tolist()) + + a[0], a[-1] = 200, -200 + self.assertEqual(x[:], a.tolist()) + + self.assertTrue(a in x._objects.values()) + + self.assertRaises(ValueError, + c_int.from_buffer, a, -1) + + expected = x[:] + del a; gc.collect(); gc.collect(); gc.collect() + self.assertEqual(x[:], expected) + + self.assertRaises(TypeError, + (c_char * 16).from_buffer, "a" * 16) + + def test_fom_buffer_with_offset(self): + a = array.array("i", range(16)) + x = (c_int * 15).from_buffer(a, sizeof(c_int)) + + self.assertEqual(x[:], a.tolist()[1:]) + self.assertRaises(ValueError, lambda: (c_int * 16).from_buffer(a, sizeof(c_int))) + self.assertRaises(ValueError, lambda: (c_int * 1).from_buffer(a, 16 * sizeof(c_int))) + + def test_from_buffer_copy(self): + a = array.array("i", range(16)) + x = (c_int * 16).from_buffer_copy(a) + + y = X.from_buffer_copy(a) + self.assertEqual(y.c_int, a[0]) + self.assertFalse(y.init_called) + + self.assertEqual(x[:], range(16)) + + a[0], a[-1] = 200, -200 + self.assertEqual(x[:], range(16)) + + self.assertEqual(x._objects, None) + + self.assertRaises(ValueError, + c_int.from_buffer, a, -1) + + del a; gc.collect(); gc.collect(); gc.collect() + self.assertEqual(x[:], range(16)) + + x = (c_char * 16).from_buffer_copy("a" * 16) + self.assertEqual(x[:], "a" * 16) + + def test_fom_buffer_copy_with_offset(self): + a = array.array("i", range(16)) + x = (c_int * 15).from_buffer_copy(a, sizeof(c_int)) + + self.assertEqual(x[:], a.tolist()[1:]) + self.assertRaises(ValueError, + (c_int * 16).from_buffer_copy, a, sizeof(c_int)) + self.assertRaises(ValueError, + (c_int * 1).from_buffer_copy, a, 16 * sizeof(c_int)) + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_frombuffer.pyc b/lib/python2.7/ctypes/test/test_frombuffer.pyc new file mode 100644 index 0000000..a18bf7a Binary files /dev/null and b/lib/python2.7/ctypes/test/test_frombuffer.pyc differ diff --git a/lib/python2.7/ctypes/test/test_frombuffer.pyo b/lib/python2.7/ctypes/test/test_frombuffer.pyo new file mode 100644 index 0000000..a18bf7a Binary files /dev/null and b/lib/python2.7/ctypes/test/test_frombuffer.pyo differ diff --git a/lib/python2.7/ctypes/test/test_funcptr.py b/lib/python2.7/ctypes/test/test_funcptr.py new file mode 100644 index 0000000..99af5ed --- /dev/null +++ b/lib/python2.7/ctypes/test/test_funcptr.py @@ -0,0 +1,127 @@ +import os, unittest +from ctypes import * + +try: + WINFUNCTYPE +except NameError: + # fake to enable this test on Linux + WINFUNCTYPE = CFUNCTYPE + +import _ctypes_test +lib = CDLL(_ctypes_test.__file__) + +class CFuncPtrTestCase(unittest.TestCase): + def test_basic(self): + X = WINFUNCTYPE(c_int, c_int, c_int) + + def func(*args): + return len(args) + + x = X(func) + self.assertEqual(x.restype, c_int) + self.assertEqual(x.argtypes, (c_int, c_int)) + self.assertEqual(sizeof(x), sizeof(c_voidp)) + self.assertEqual(sizeof(X), sizeof(c_voidp)) + + def test_first(self): + StdCallback = WINFUNCTYPE(c_int, c_int, c_int) + CdeclCallback = CFUNCTYPE(c_int, c_int, c_int) + + def func(a, b): + return a + b + + s = StdCallback(func) + c = CdeclCallback(func) + + self.assertEqual(s(1, 2), 3) + self.assertEqual(c(1, 2), 3) + # The following no longer raises a TypeError - it is now + # possible, as in C, to call cdecl functions with more parameters. + #self.assertRaises(TypeError, c, 1, 2, 3) + self.assertEqual(c(1, 2, 3, 4, 5, 6), 3) + if not WINFUNCTYPE is CFUNCTYPE and os.name != "ce": + self.assertRaises(TypeError, s, 1, 2, 3) + + def test_structures(self): + WNDPROC = WINFUNCTYPE(c_long, c_int, c_int, c_int, c_int) + + def wndproc(hwnd, msg, wParam, lParam): + return hwnd + msg + wParam + lParam + + HINSTANCE = c_int + HICON = c_int + HCURSOR = c_int + LPCTSTR = c_char_p + + class WNDCLASS(Structure): + _fields_ = [("style", c_uint), + ("lpfnWndProc", WNDPROC), + ("cbClsExtra", c_int), + ("cbWndExtra", c_int), + ("hInstance", HINSTANCE), + ("hIcon", HICON), + ("hCursor", HCURSOR), + ("lpszMenuName", LPCTSTR), + ("lpszClassName", LPCTSTR)] + + wndclass = WNDCLASS() + wndclass.lpfnWndProc = WNDPROC(wndproc) + + WNDPROC_2 = WINFUNCTYPE(c_long, c_int, c_int, c_int, c_int) + + # This is no longer true, now that WINFUNCTYPE caches created types internally. + ## # CFuncPtr subclasses are compared by identity, so this raises a TypeError: + ## self.assertRaises(TypeError, setattr, wndclass, + ## "lpfnWndProc", WNDPROC_2(wndproc)) + # instead: + + self.assertTrue(WNDPROC is WNDPROC_2) + # 'wndclass.lpfnWndProc' leaks 94 references. Why? + self.assertEqual(wndclass.lpfnWndProc(1, 2, 3, 4), 10) + + + f = wndclass.lpfnWndProc + + del wndclass + del wndproc + + self.assertEqual(f(10, 11, 12, 13), 46) + + def test_dllfunctions(self): + + def NoNullHandle(value): + if not value: + raise WinError() + return value + + strchr = lib.my_strchr + strchr.restype = c_char_p + strchr.argtypes = (c_char_p, c_char) + self.assertEqual(strchr("abcdefghi", "b"), "bcdefghi") + self.assertEqual(strchr("abcdefghi", "x"), None) + + + strtok = lib.my_strtok + strtok.restype = c_char_p + # Neither of this does work: strtok changes the buffer it is passed +## strtok.argtypes = (c_char_p, c_char_p) +## strtok.argtypes = (c_string, c_char_p) + + def c_string(init): + size = len(init) + 1 + return (c_char*size)(*init) + + s = "a\nb\nc" + b = c_string(s) + +## b = (c_char * (len(s)+1))() +## b.value = s + +## b = c_string(s) + self.assertEqual(strtok(b, "\n"), "a") + self.assertEqual(strtok(None, "\n"), "b") + self.assertEqual(strtok(None, "\n"), "c") + self.assertEqual(strtok(None, "\n"), None) + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_funcptr.pyc b/lib/python2.7/ctypes/test/test_funcptr.pyc new file mode 100644 index 0000000..30dd5d3 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_funcptr.pyc differ diff --git a/lib/python2.7/ctypes/test/test_funcptr.pyo b/lib/python2.7/ctypes/test/test_funcptr.pyo new file mode 100644 index 0000000..30dd5d3 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_funcptr.pyo differ diff --git a/lib/python2.7/ctypes/test/test_functions.py b/lib/python2.7/ctypes/test/test_functions.py new file mode 100644 index 0000000..13bd3ec --- /dev/null +++ b/lib/python2.7/ctypes/test/test_functions.py @@ -0,0 +1,412 @@ +""" +Here is probably the place to write the docs, since the test-cases +show how the type behave. + +Later... +""" + +from ctypes import * +import sys, unittest + +try: + WINFUNCTYPE +except NameError: + # fake to enable this test on Linux + WINFUNCTYPE = CFUNCTYPE + +import _ctypes_test +dll = CDLL(_ctypes_test.__file__) +if sys.platform == "win32": + windll = WinDLL(_ctypes_test.__file__) + +class POINT(Structure): + _fields_ = [("x", c_int), ("y", c_int)] +class RECT(Structure): + _fields_ = [("left", c_int), ("top", c_int), + ("right", c_int), ("bottom", c_int)] +class FunctionTestCase(unittest.TestCase): + + def test_mro(self): + # in Python 2.3, this raises TypeError: MRO conflict among bases classes, + # in Python 2.2 it works. + # + # But in early versions of _ctypes.c, the result of tp_new + # wasn't checked, and it even crashed Python. + # Found by Greg Chapman. + + try: + class X(object, Array): + _length_ = 5 + _type_ = "i" + except TypeError: + pass + + + from _ctypes import _Pointer + try: + class X(object, _Pointer): + pass + except TypeError: + pass + + from _ctypes import _SimpleCData + try: + class X(object, _SimpleCData): + _type_ = "i" + except TypeError: + pass + + try: + class X(object, Structure): + _fields_ = [] + except TypeError: + pass + + + def test_wchar_parm(self): + try: + c_wchar + except NameError: + return + f = dll._testfunc_i_bhilfd + f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double] + result = f(1, u"x", 3, 4, 5.0, 6.0) + self.assertEqual(result, 139) + self.assertEqual(type(result), int) + + def test_wchar_result(self): + try: + c_wchar + except NameError: + return + f = dll._testfunc_i_bhilfd + f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] + f.restype = c_wchar + result = f(0, 0, 0, 0, 0, 0) + self.assertEqual(result, u'\x00') + + def test_voidresult(self): + f = dll._testfunc_v + f.restype = None + f.argtypes = [c_int, c_int, POINTER(c_int)] + result = c_int() + self.assertEqual(None, f(1, 2, byref(result))) + self.assertEqual(result.value, 3) + + def test_intresult(self): + f = dll._testfunc_i_bhilfd + f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] + f.restype = c_int + result = f(1, 2, 3, 4, 5.0, 6.0) + self.assertEqual(result, 21) + self.assertEqual(type(result), int) + + result = f(-1, -2, -3, -4, -5.0, -6.0) + self.assertEqual(result, -21) + self.assertEqual(type(result), int) + + # If we declare the function to return a short, + # is the high part split off? + f.restype = c_short + result = f(1, 2, 3, 4, 5.0, 6.0) + self.assertEqual(result, 21) + self.assertEqual(type(result), int) + + result = f(1, 2, 3, 0x10004, 5.0, 6.0) + self.assertEqual(result, 21) + self.assertEqual(type(result), int) + + # You cannot assign character format codes as restype any longer + self.assertRaises(TypeError, setattr, f, "restype", "i") + + def test_floatresult(self): + f = dll._testfunc_f_bhilfd + f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] + f.restype = c_float + result = f(1, 2, 3, 4, 5.0, 6.0) + self.assertEqual(result, 21) + self.assertEqual(type(result), float) + + result = f(-1, -2, -3, -4, -5.0, -6.0) + self.assertEqual(result, -21) + self.assertEqual(type(result), float) + + def test_doubleresult(self): + f = dll._testfunc_d_bhilfd + f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] + f.restype = c_double + result = f(1, 2, 3, 4, 5.0, 6.0) + self.assertEqual(result, 21) + self.assertEqual(type(result), float) + + result = f(-1, -2, -3, -4, -5.0, -6.0) + self.assertEqual(result, -21) + self.assertEqual(type(result), float) + + def test_longdoubleresult(self): + f = dll._testfunc_D_bhilfD + f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_longdouble] + f.restype = c_longdouble + result = f(1, 2, 3, 4, 5.0, 6.0) + self.assertEqual(result, 21) + self.assertEqual(type(result), float) + + result = f(-1, -2, -3, -4, -5.0, -6.0) + self.assertEqual(result, -21) + self.assertEqual(type(result), float) + + def test_longlongresult(self): + try: + c_longlong + except NameError: + return + f = dll._testfunc_q_bhilfd + f.restype = c_longlong + f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] + result = f(1, 2, 3, 4, 5.0, 6.0) + self.assertEqual(result, 21) + + f = dll._testfunc_q_bhilfdq + f.restype = c_longlong + f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double, c_longlong] + result = f(1, 2, 3, 4, 5.0, 6.0, 21) + self.assertEqual(result, 42) + + def test_stringresult(self): + f = dll._testfunc_p_p + f.argtypes = None + f.restype = c_char_p + result = f("123") + self.assertEqual(result, "123") + + result = f(None) + self.assertEqual(result, None) + + def test_pointers(self): + f = dll._testfunc_p_p + f.restype = POINTER(c_int) + f.argtypes = [POINTER(c_int)] + + # This only works if the value c_int(42) passed to the + # function is still alive while the pointer (the result) is + # used. + + v = c_int(42) + + self.assertEqual(pointer(v).contents.value, 42) + result = f(pointer(v)) + self.assertEqual(type(result), POINTER(c_int)) + self.assertEqual(result.contents.value, 42) + + # This on works... + result = f(pointer(v)) + self.assertEqual(result.contents.value, v.value) + + p = pointer(c_int(99)) + result = f(p) + self.assertEqual(result.contents.value, 99) + + arg = byref(v) + result = f(arg) + self.assertNotEqual(result.contents, v.value) + + self.assertRaises(ArgumentError, f, byref(c_short(22))) + + # It is dangerous, however, because you don't control the lifetime + # of the pointer: + result = f(byref(c_int(99))) + self.assertNotEqual(result.contents, 99) + + def test_errors(self): + f = dll._testfunc_p_p + f.restype = c_int + + class X(Structure): + _fields_ = [("y", c_int)] + + self.assertRaises(TypeError, f, X()) #cannot convert parameter + + ################################################################ + def test_shorts(self): + f = dll._testfunc_callback_i_if + + args = [] + expected = [262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, + 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1] + + def callback(v): + args.append(v) + return v + + CallBack = CFUNCTYPE(c_int, c_int) + + cb = CallBack(callback) + f(2**18, cb) + self.assertEqual(args, expected) + + ################################################################ + + + def test_callbacks(self): + f = dll._testfunc_callback_i_if + f.restype = c_int + f.argtypes = None + + MyCallback = CFUNCTYPE(c_int, c_int) + + def callback(value): + #print "called back with", value + return value + + cb = MyCallback(callback) + result = f(-10, cb) + self.assertEqual(result, -18) + + # test with prototype + f.argtypes = [c_int, MyCallback] + cb = MyCallback(callback) + result = f(-10, cb) + self.assertEqual(result, -18) + + AnotherCallback = WINFUNCTYPE(c_int, c_int, c_int, c_int, c_int) + + # check that the prototype works: we call f with wrong + # argument types + cb = AnotherCallback(callback) + self.assertRaises(ArgumentError, f, -10, cb) + + + def test_callbacks_2(self): + # Can also use simple datatypes as argument type specifiers + # for the callback function. + # In this case the call receives an instance of that type + f = dll._testfunc_callback_i_if + f.restype = c_int + + MyCallback = CFUNCTYPE(c_int, c_int) + + f.argtypes = [c_int, MyCallback] + + def callback(value): + #print "called back with", value + self.assertEqual(type(value), int) + return value + + cb = MyCallback(callback) + result = f(-10, cb) + self.assertEqual(result, -18) + + def test_longlong_callbacks(self): + + f = dll._testfunc_callback_q_qf + f.restype = c_longlong + + MyCallback = CFUNCTYPE(c_longlong, c_longlong) + + f.argtypes = [c_longlong, MyCallback] + + def callback(value): + self.assertTrue(isinstance(value, (int, long))) + return value & 0x7FFFFFFF + + cb = MyCallback(callback) + + self.assertEqual(13577625587, f(1000000000000, cb)) + + def test_errors(self): + self.assertRaises(AttributeError, getattr, dll, "_xxx_yyy") + self.assertRaises(ValueError, c_int.in_dll, dll, "_xxx_yyy") + + def test_byval(self): + + # without prototype + ptin = POINT(1, 2) + ptout = POINT() + # EXPORT int _testfunc_byval(point in, point *pout) + result = dll._testfunc_byval(ptin, byref(ptout)) + got = result, ptout.x, ptout.y + expected = 3, 1, 2 + self.assertEqual(got, expected) + + # with prototype + ptin = POINT(101, 102) + ptout = POINT() + dll._testfunc_byval.argtypes = (POINT, POINTER(POINT)) + dll._testfunc_byval.restype = c_int + result = dll._testfunc_byval(ptin, byref(ptout)) + got = result, ptout.x, ptout.y + expected = 203, 101, 102 + self.assertEqual(got, expected) + + def test_struct_return_2H(self): + class S2H(Structure): + _fields_ = [("x", c_short), + ("y", c_short)] + dll.ret_2h_func.restype = S2H + dll.ret_2h_func.argtypes = [S2H] + inp = S2H(99, 88) + s2h = dll.ret_2h_func(inp) + self.assertEqual((s2h.x, s2h.y), (99*2, 88*3)) + + if sys.platform == "win32": + def test_struct_return_2H_stdcall(self): + class S2H(Structure): + _fields_ = [("x", c_short), + ("y", c_short)] + + windll.s_ret_2h_func.restype = S2H + windll.s_ret_2h_func.argtypes = [S2H] + s2h = windll.s_ret_2h_func(S2H(99, 88)) + self.assertEqual((s2h.x, s2h.y), (99*2, 88*3)) + + # This is known cdecl incompatibility between GCC + # and MSVC. It is addressed in GCC issue #36834. + # Python libffi detect it and complain. + @unittest.skipIf(sys.platform == "win32" and sys.version.find("GCC") >= 0, 'XFAIL GCC(mingw)') + def test_struct_return_8H(self): + class S8I(Structure): + _fields_ = [("a", c_int), + ("b", c_int), + ("c", c_int), + ("d", c_int), + ("e", c_int), + ("f", c_int), + ("g", c_int), + ("h", c_int)] + dll.ret_8i_func.restype = S8I + dll.ret_8i_func.argtypes = [S8I] + inp = S8I(9, 8, 7, 6, 5, 4, 3, 2) + s8i = dll.ret_8i_func(inp) + self.assertEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h), + (9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9)) + + if sys.platform == "win32": + def test_struct_return_8H_stdcall(self): + class S8I(Structure): + _fields_ = [("a", c_int), + ("b", c_int), + ("c", c_int), + ("d", c_int), + ("e", c_int), + ("f", c_int), + ("g", c_int), + ("h", c_int)] + windll.s_ret_8i_func.restype = S8I + windll.s_ret_8i_func.argtypes = [S8I] + inp = S8I(9, 8, 7, 6, 5, 4, 3, 2) + s8i = windll.s_ret_8i_func(inp) + self.assertEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h), + (9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9)) + + def test_sf1651235(self): + # see http://www.python.org/sf/1651235 + + proto = CFUNCTYPE(c_int, RECT, POINT) + def callback(*args): + return 0 + + callback = proto(callback) + self.assertRaises(ArgumentError, lambda: callback((1, 2, 3, 4), POINT())) + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_functions.pyc b/lib/python2.7/ctypes/test/test_functions.pyc new file mode 100644 index 0000000..1b5dfb0 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_functions.pyc differ diff --git a/lib/python2.7/ctypes/test/test_functions.pyo b/lib/python2.7/ctypes/test/test_functions.pyo new file mode 100644 index 0000000..1b5dfb0 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_functions.pyo differ diff --git a/lib/python2.7/ctypes/test/test_incomplete.py b/lib/python2.7/ctypes/test/test_incomplete.py new file mode 100644 index 0000000..1e03e9f --- /dev/null +++ b/lib/python2.7/ctypes/test/test_incomplete.py @@ -0,0 +1,42 @@ +import unittest +from ctypes import * + +################################################################ +# +# The incomplete pointer example from the tutorial +# + +class MyTestCase(unittest.TestCase): + + def test_incomplete_example(self): + lpcell = POINTER("cell") + class cell(Structure): + _fields_ = [("name", c_char_p), + ("next", lpcell)] + + SetPointerType(lpcell, cell) + + c1 = cell() + c1.name = "foo" + c2 = cell() + c2.name = "bar" + + c1.next = pointer(c2) + c2.next = pointer(c1) + + p = c1 + + result = [] + for i in range(8): + result.append(p.name) + p = p.next[0] + self.assertEqual(result, ["foo", "bar"] * 4) + + # to not leak references, we must clean _pointer_type_cache + from ctypes import _pointer_type_cache + del _pointer_type_cache[cell] + +################################################################ + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_incomplete.pyc b/lib/python2.7/ctypes/test/test_incomplete.pyc new file mode 100644 index 0000000..10cf911 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_incomplete.pyc differ diff --git a/lib/python2.7/ctypes/test/test_incomplete.pyo b/lib/python2.7/ctypes/test/test_incomplete.pyo new file mode 100644 index 0000000..10cf911 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_incomplete.pyo differ diff --git a/lib/python2.7/ctypes/test/test_init.py b/lib/python2.7/ctypes/test/test_init.py new file mode 100644 index 0000000..82bd1f9 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_init.py @@ -0,0 +1,40 @@ +from ctypes import * +import unittest + +class X(Structure): + _fields_ = [("a", c_int), + ("b", c_int)] + new_was_called = False + + def __new__(cls): + result = super(X, cls).__new__(cls) + result.new_was_called = True + return result + + def __init__(self): + self.a = 9 + self.b = 12 + +class Y(Structure): + _fields_ = [("x", X)] + + +class InitTest(unittest.TestCase): + def test_get(self): + # make sure the only accessing a nested structure + # doesn't call the structure's __new__ and __init__ + y = Y() + self.assertEqual((y.x.a, y.x.b), (0, 0)) + self.assertEqual(y.x.new_was_called, False) + + # But explicitly creating an X structure calls __new__ and __init__, of course. + x = X() + self.assertEqual((x.a, x.b), (9, 12)) + self.assertEqual(x.new_was_called, True) + + y.x = x + self.assertEqual((y.x.a, y.x.b), (9, 12)) + self.assertEqual(y.x.new_was_called, False) + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_init.pyc b/lib/python2.7/ctypes/test/test_init.pyc new file mode 100644 index 0000000..5725450 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_init.pyc differ diff --git a/lib/python2.7/ctypes/test/test_init.pyo b/lib/python2.7/ctypes/test/test_init.pyo new file mode 100644 index 0000000..5725450 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_init.pyo differ diff --git a/lib/python2.7/ctypes/test/test_integers.py b/lib/python2.7/ctypes/test/test_integers.py new file mode 100644 index 0000000..5b6453a --- /dev/null +++ b/lib/python2.7/ctypes/test/test_integers.py @@ -0,0 +1,5 @@ +# superseeded by test_numbers.py +import unittest + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_integers.pyc b/lib/python2.7/ctypes/test/test_integers.pyc new file mode 100644 index 0000000..95983a0 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_integers.pyc differ diff --git a/lib/python2.7/ctypes/test/test_integers.pyo b/lib/python2.7/ctypes/test/test_integers.pyo new file mode 100644 index 0000000..95983a0 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_integers.pyo differ diff --git a/lib/python2.7/ctypes/test/test_internals.py b/lib/python2.7/ctypes/test/test_internals.py new file mode 100644 index 0000000..2e5b1fe --- /dev/null +++ b/lib/python2.7/ctypes/test/test_internals.py @@ -0,0 +1,103 @@ +# This tests the internal _objects attribute +import unittest +from ctypes import * +from sys import getrefcount as grc + +# XXX This test must be reviewed for correctness!!! + +""" +ctypes' types are container types. + +They have an internal memory block, which only consists of some bytes, +but it has to keep references to other objects as well. This is not +really needed for trivial C types like int or char, but it is important +for aggregate types like strings or pointers in particular. + +What about pointers? + +""" + +class ObjectsTestCase(unittest.TestCase): + def assertSame(self, a, b): + self.assertEqual(id(a), id(b)) + + def test_ints(self): + i = 42000123 + refcnt = grc(i) + ci = c_int(i) + self.assertEqual(refcnt, grc(i)) + self.assertEqual(ci._objects, None) + + def test_c_char_p(self): + s = "Hello, World" + refcnt = grc(s) + cs = c_char_p(s) + self.assertEqual(refcnt + 1, grc(s)) + self.assertSame(cs._objects, s) + + def test_simple_struct(self): + class X(Structure): + _fields_ = [("a", c_int), ("b", c_int)] + + a = 421234 + b = 421235 + x = X() + self.assertEqual(x._objects, None) + x.a = a + x.b = b + self.assertEqual(x._objects, None) + + def test_embedded_structs(self): + class X(Structure): + _fields_ = [("a", c_int), ("b", c_int)] + + class Y(Structure): + _fields_ = [("x", X), ("y", X)] + + y = Y() + self.assertEqual(y._objects, None) + + x1, x2 = X(), X() + y.x, y.y = x1, x2 + self.assertEqual(y._objects, {"0": {}, "1": {}}) + x1.a, x2.b = 42, 93 + self.assertEqual(y._objects, {"0": {}, "1": {}}) + + def test_xxx(self): + class X(Structure): + _fields_ = [("a", c_char_p), ("b", c_char_p)] + + class Y(Structure): + _fields_ = [("x", X), ("y", X)] + + s1 = "Hello, World" + s2 = "Hallo, Welt" + + x = X() + x.a = s1 + x.b = s2 + self.assertEqual(x._objects, {"0": s1, "1": s2}) + + y = Y() + y.x = x + self.assertEqual(y._objects, {"0": {"0": s1, "1": s2}}) +## x = y.x +## del y +## print x._b_base_._objects + + def test_ptr_struct(self): + class X(Structure): + _fields_ = [("data", POINTER(c_int))] + + A = c_int*4 + a = A(11, 22, 33, 44) + self.assertEqual(a._objects, None) + + x = X() + x.data = a +##XXX print x._objects +##XXX print x.data[0] +##XXX print x.data._objects + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_internals.pyc b/lib/python2.7/ctypes/test/test_internals.pyc new file mode 100644 index 0000000..c293e42 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_internals.pyc differ diff --git a/lib/python2.7/ctypes/test/test_internals.pyo b/lib/python2.7/ctypes/test/test_internals.pyo new file mode 100644 index 0000000..c293e42 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_internals.pyo differ diff --git a/lib/python2.7/ctypes/test/test_keeprefs.py b/lib/python2.7/ctypes/test/test_keeprefs.py new file mode 100644 index 0000000..b504c0c --- /dev/null +++ b/lib/python2.7/ctypes/test/test_keeprefs.py @@ -0,0 +1,152 @@ +from ctypes import * +import unittest + +class SimpleTestCase(unittest.TestCase): + def test_cint(self): + x = c_int() + self.assertEqual(x._objects, None) + x.value = 42 + self.assertEqual(x._objects, None) + x = c_int(99) + self.assertEqual(x._objects, None) + + def test_ccharp(self): + x = c_char_p() + self.assertEqual(x._objects, None) + x.value = "abc" + self.assertEqual(x._objects, "abc") + x = c_char_p("spam") + self.assertEqual(x._objects, "spam") + +class StructureTestCase(unittest.TestCase): + def test_cint_struct(self): + class X(Structure): + _fields_ = [("a", c_int), + ("b", c_int)] + + x = X() + self.assertEqual(x._objects, None) + x.a = 42 + x.b = 99 + self.assertEqual(x._objects, None) + + def test_ccharp_struct(self): + class X(Structure): + _fields_ = [("a", c_char_p), + ("b", c_char_p)] + x = X() + self.assertEqual(x._objects, None) + + x.a = "spam" + x.b = "foo" + self.assertEqual(x._objects, {"0": "spam", "1": "foo"}) + + def test_struct_struct(self): + class POINT(Structure): + _fields_ = [("x", c_int), ("y", c_int)] + class RECT(Structure): + _fields_ = [("ul", POINT), ("lr", POINT)] + + r = RECT() + r.ul.x = 0 + r.ul.y = 1 + r.lr.x = 2 + r.lr.y = 3 + self.assertEqual(r._objects, None) + + r = RECT() + pt = POINT(1, 2) + r.ul = pt + self.assertEqual(r._objects, {'0': {}}) + r.ul.x = 22 + r.ul.y = 44 + self.assertEqual(r._objects, {'0': {}}) + r.lr = POINT() + self.assertEqual(r._objects, {'0': {}, '1': {}}) + +class ArrayTestCase(unittest.TestCase): + def test_cint_array(self): + INTARR = c_int * 3 + + ia = INTARR() + self.assertEqual(ia._objects, None) + ia[0] = 1 + ia[1] = 2 + ia[2] = 3 + self.assertEqual(ia._objects, None) + + class X(Structure): + _fields_ = [("x", c_int), + ("a", INTARR)] + + x = X() + x.x = 1000 + x.a[0] = 42 + x.a[1] = 96 + self.assertEqual(x._objects, None) + x.a = ia + self.assertEqual(x._objects, {'1': {}}) + +class PointerTestCase(unittest.TestCase): + def test_p_cint(self): + i = c_int(42) + x = pointer(i) + self.assertEqual(x._objects, {'1': i}) + +class DeletePointerTestCase(unittest.TestCase): + def X_test(self): + class X(Structure): + _fields_ = [("p", POINTER(c_char_p))] + x = X() + i = c_char_p("abc def") + from sys import getrefcount as grc + print "2?", grc(i) + x.p = pointer(i) + print "3?", grc(i) + for i in range(320): + c_int(99) + x.p[0] + print x.p[0] +## del x +## print "2?", grc(i) +## del i + import gc + gc.collect() + for i in range(320): + c_int(99) + x.p[0] + print x.p[0] + print x.p.contents +## print x._objects + + x.p[0] = "spam spam" +## print x.p[0] + print "+" * 42 + print x._objects + +class PointerToStructure(unittest.TestCase): + def test(self): + class POINT(Structure): + _fields_ = [("x", c_int), ("y", c_int)] + class RECT(Structure): + _fields_ = [("a", POINTER(POINT)), + ("b", POINTER(POINT))] + r = RECT() + p1 = POINT(1, 2) + + r.a = pointer(p1) + r.b = pointer(p1) +## from pprint import pprint as pp +## pp(p1._objects) +## pp(r._objects) + + r.a[0].x = 42 + r.a[0].y = 99 + + # to avoid leaking when tests are run several times + # clean up the types left in the cache. + from ctypes import _pointer_type_cache + del _pointer_type_cache[POINT] + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_keeprefs.pyc b/lib/python2.7/ctypes/test/test_keeprefs.pyc new file mode 100644 index 0000000..e112325 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_keeprefs.pyc differ diff --git a/lib/python2.7/ctypes/test/test_keeprefs.pyo b/lib/python2.7/ctypes/test/test_keeprefs.pyo new file mode 100644 index 0000000..e112325 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_keeprefs.pyo differ diff --git a/lib/python2.7/ctypes/test/test_libc.py b/lib/python2.7/ctypes/test/test_libc.py new file mode 100644 index 0000000..3dc463f --- /dev/null +++ b/lib/python2.7/ctypes/test/test_libc.py @@ -0,0 +1,29 @@ +import unittest + +from ctypes import * +import _ctypes_test + +lib = CDLL(_ctypes_test.__file__) + +class LibTest(unittest.TestCase): + def test_sqrt(self): + lib.my_sqrt.argtypes = c_double, + lib.my_sqrt.restype = c_double + self.assertEqual(lib.my_sqrt(4.0), 2.0) + import math + self.assertEqual(lib.my_sqrt(2.0), math.sqrt(2.0)) + + def test_qsort(self): + comparefunc = CFUNCTYPE(c_int, POINTER(c_char), POINTER(c_char)) + lib.my_qsort.argtypes = c_void_p, c_size_t, c_size_t, comparefunc + lib.my_qsort.restype = None + + def sort(a, b): + return cmp(a[0], b[0]) + + chars = create_string_buffer("spam, spam, and spam") + lib.my_qsort(chars, len(chars)-1, sizeof(c_char), comparefunc(sort)) + self.assertEqual(chars.raw, " ,,aaaadmmmnpppsss\x00") + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_libc.pyc b/lib/python2.7/ctypes/test/test_libc.pyc new file mode 100644 index 0000000..a223cbd Binary files /dev/null and b/lib/python2.7/ctypes/test/test_libc.pyc differ diff --git a/lib/python2.7/ctypes/test/test_libc.pyo b/lib/python2.7/ctypes/test/test_libc.pyo new file mode 100644 index 0000000..a223cbd Binary files /dev/null and b/lib/python2.7/ctypes/test/test_libc.pyo differ diff --git a/lib/python2.7/ctypes/test/test_loading.py b/lib/python2.7/ctypes/test/test_loading.py new file mode 100644 index 0000000..26683d8 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_loading.py @@ -0,0 +1,106 @@ +from ctypes import * +import sys, unittest +import os +from ctypes.util import find_library +from ctypes.test import is_resource_enabled + +libc_name = None +if os.name == "nt": + libc_name = find_library("c") +elif os.name == "ce": + libc_name = "coredll" +elif sys.platform == "cygwin": + libc_name = "cygwin1.dll" +else: + libc_name = find_library("c") + +if is_resource_enabled("printing"): + print "libc_name is", libc_name + +class LoaderTest(unittest.TestCase): + + unknowndll = "xxrandomnamexx" + + if libc_name is not None: + def test_load(self): + CDLL(libc_name) + CDLL(os.path.basename(libc_name)) + self.assertRaises(OSError, CDLL, self.unknowndll) + + if libc_name is not None and os.path.basename(libc_name) == "libc.so.6": + def test_load_version(self): + cdll.LoadLibrary("libc.so.6") + # linux uses version, libc 9 should not exist + self.assertRaises(OSError, cdll.LoadLibrary, "libc.so.9") + self.assertRaises(OSError, cdll.LoadLibrary, self.unknowndll) + + def test_find(self): + for name in ("c", "m"): + lib = find_library(name) + if lib: + cdll.LoadLibrary(lib) + CDLL(lib) + + if os.name in ("nt", "ce"): + def test_load_library(self): + self.assertFalse(libc_name is None) + if is_resource_enabled("printing"): + print find_library("kernel32") + print find_library("user32") + + if os.name == "nt": + windll.kernel32.GetModuleHandleW + windll["kernel32"].GetModuleHandleW + windll.LoadLibrary("kernel32").GetModuleHandleW + WinDLL("kernel32").GetModuleHandleW + elif os.name == "ce": + windll.coredll.GetModuleHandleW + windll["coredll"].GetModuleHandleW + windll.LoadLibrary("coredll").GetModuleHandleW + WinDLL("coredll").GetModuleHandleW + + def test_load_ordinal_functions(self): + import _ctypes_test + dll = WinDLL(_ctypes_test.__file__) + # We load the same function both via ordinal and name + func_ord = dll[2] + func_name = dll.GetString + # addressof gets the address where the function pointer is stored + a_ord = addressof(func_ord) + a_name = addressof(func_name) + f_ord_addr = c_void_p.from_address(a_ord).value + f_name_addr = c_void_p.from_address(a_name).value + self.assertEqual(hex(f_ord_addr), hex(f_name_addr)) + + self.assertRaises(AttributeError, dll.__getitem__, 1234) + + if os.name == "nt": + def test_1703286_A(self): + from _ctypes import LoadLibrary, FreeLibrary + # On winXP 64-bit, advapi32 loads at an address that does + # NOT fit into a 32-bit integer. FreeLibrary must be able + # to accept this address. + + # These are tests for http://www.python.org/sf/1703286 + handle = LoadLibrary("advapi32") + FreeLibrary(handle) + + def test_1703286_B(self): + # Since on winXP 64-bit advapi32 loads like described + # above, the (arbitrarily selected) CloseEventLog function + # also has a high address. 'call_function' should accept + # addresses so large. + from _ctypes import call_function + advapi32 = windll.advapi32 + # Calling CloseEventLog with a NULL argument should fail, + # but the call should not segfault or so. + self.assertEqual(0, advapi32.CloseEventLog(None)) + windll.kernel32.GetProcAddress.argtypes = c_void_p, c_char_p + windll.kernel32.GetProcAddress.restype = c_void_p + proc = windll.kernel32.GetProcAddress(advapi32._handle, "CloseEventLog") + self.assertTrue(proc) + # This is the real test: call the function via 'call_function' + self.assertEqual(0, call_function(proc, (None,))) + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_loading.pyc b/lib/python2.7/ctypes/test/test_loading.pyc new file mode 100644 index 0000000..cd9b099 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_loading.pyc differ diff --git a/lib/python2.7/ctypes/test/test_loading.pyo b/lib/python2.7/ctypes/test/test_loading.pyo new file mode 100644 index 0000000..cd9b099 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_loading.pyo differ diff --git a/lib/python2.7/ctypes/test/test_macholib.py b/lib/python2.7/ctypes/test/test_macholib.py new file mode 100644 index 0000000..eda846d --- /dev/null +++ b/lib/python2.7/ctypes/test/test_macholib.py @@ -0,0 +1,62 @@ +import os +import sys +import unittest + +# Bob Ippolito: +""" +Ok.. the code to find the filename for __getattr__ should look +something like: + +import os +from macholib.dyld import dyld_find + +def find_lib(name): + possible = ['lib'+name+'.dylib', name+'.dylib', + name+'.framework/'+name] + for dylib in possible: + try: + return os.path.realpath(dyld_find(dylib)) + except ValueError: + pass + raise ValueError, "%s not found" % (name,) + +It'll have output like this: + + >>> find_lib('pthread') +'/usr/lib/libSystem.B.dylib' + >>> find_lib('z') +'/usr/lib/libz.1.dylib' + >>> find_lib('IOKit') +'/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit' + +-bob + +""" + +from ctypes.macholib.dyld import dyld_find + +def find_lib(name): + possible = ['lib'+name+'.dylib', name+'.dylib', name+'.framework/'+name] + for dylib in possible: + try: + return os.path.realpath(dyld_find(dylib)) + except ValueError: + pass + raise ValueError("%s not found" % (name,)) + +class MachOTest(unittest.TestCase): + if sys.platform == "darwin": + def test_find(self): + + self.assertEqual(find_lib('pthread'), + '/usr/lib/libSystem.B.dylib') + + result = find_lib('z') + self.assertTrue(result.startswith('/usr/lib/libz.1')) + self.assertTrue(result.endswith('.dylib')) + + self.assertEqual(find_lib('IOKit'), + '/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit') + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_macholib.pyc b/lib/python2.7/ctypes/test/test_macholib.pyc new file mode 100644 index 0000000..7fddd56 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_macholib.pyc differ diff --git a/lib/python2.7/ctypes/test/test_macholib.pyo b/lib/python2.7/ctypes/test/test_macholib.pyo new file mode 100644 index 0000000..7fddd56 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_macholib.pyo differ diff --git a/lib/python2.7/ctypes/test/test_memfunctions.py b/lib/python2.7/ctypes/test/test_memfunctions.py new file mode 100644 index 0000000..d072603 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_memfunctions.py @@ -0,0 +1,79 @@ +import sys +import unittest +from ctypes import * + +class MemFunctionsTest(unittest.TestCase): +## def test_overflow(self): +## # string_at and wstring_at must use the Python calling +## # convention (which acquires the GIL and checks the Python +## # error flag). Provoke an error and catch it; see also issue +## # #3554: +## self.assertRaises((OverflowError, MemoryError, SystemError), +## lambda: wstring_at(u"foo", sys.maxint - 1)) +## self.assertRaises((OverflowError, MemoryError, SystemError), +## lambda: string_at("foo", sys.maxint - 1)) + + def test_memmove(self): + # large buffers apparently increase the chance that the memory + # is allocated in high address space. + a = create_string_buffer(1000000) + p = "Hello, World" + result = memmove(a, p, len(p)) + self.assertEqual(a.value, "Hello, World") + + self.assertEqual(string_at(result), "Hello, World") + self.assertEqual(string_at(result, 5), "Hello") + self.assertEqual(string_at(result, 16), "Hello, World\0\0\0\0") + self.assertEqual(string_at(result, 0), "") + + def test_memset(self): + a = create_string_buffer(1000000) + result = memset(a, ord('x'), 16) + self.assertEqual(a.value, "xxxxxxxxxxxxxxxx") + + self.assertEqual(string_at(result), "xxxxxxxxxxxxxxxx") + self.assertEqual(string_at(a), "xxxxxxxxxxxxxxxx") + self.assertEqual(string_at(a, 20), "xxxxxxxxxxxxxxxx\0\0\0\0") + + def test_cast(self): + a = (c_ubyte * 32)(*map(ord, "abcdef")) + self.assertEqual(cast(a, c_char_p).value, "abcdef") + self.assertEqual(cast(a, POINTER(c_byte))[:7], + [97, 98, 99, 100, 101, 102, 0]) + self.assertEqual(cast(a, POINTER(c_byte))[:7:], + [97, 98, 99, 100, 101, 102, 0]) + self.assertEqual(cast(a, POINTER(c_byte))[6:-1:-1], + [0, 102, 101, 100, 99, 98, 97]) + self.assertEqual(cast(a, POINTER(c_byte))[:7:2], + [97, 99, 101, 0]) + self.assertEqual(cast(a, POINTER(c_byte))[:7:7], + [97]) + + def test_string_at(self): + s = string_at("foo bar") + # XXX The following may be wrong, depending on how Python + # manages string instances + self.assertEqual(2, sys.getrefcount(s)) + self.assertTrue(s, "foo bar") + + self.assertEqual(string_at("foo bar", 8), "foo bar\0") + self.assertEqual(string_at("foo bar", 3), "foo") + + try: + create_unicode_buffer + except NameError: + pass + else: + def test_wstring_at(self): + p = create_unicode_buffer("Hello, World") + a = create_unicode_buffer(1000000) + result = memmove(a, p, len(p) * sizeof(c_wchar)) + self.assertEqual(a.value, "Hello, World") + + self.assertEqual(wstring_at(a), "Hello, World") + self.assertEqual(wstring_at(a, 5), "Hello") + self.assertEqual(wstring_at(a, 16), "Hello, World\0\0\0\0") + self.assertEqual(wstring_at(a, 0), "") + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_memfunctions.pyc b/lib/python2.7/ctypes/test/test_memfunctions.pyc new file mode 100644 index 0000000..3d417b5 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_memfunctions.pyc differ diff --git a/lib/python2.7/ctypes/test/test_memfunctions.pyo b/lib/python2.7/ctypes/test/test_memfunctions.pyo new file mode 100644 index 0000000..3d417b5 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_memfunctions.pyo differ diff --git a/lib/python2.7/ctypes/test/test_numbers.py b/lib/python2.7/ctypes/test/test_numbers.py new file mode 100644 index 0000000..7923906 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_numbers.py @@ -0,0 +1,286 @@ +from ctypes import * +import unittest +import struct + +def valid_ranges(*types): + # given a sequence of numeric types, collect their _type_ + # attribute, which is a single format character compatible with + # the struct module, use the struct module to calculate the + # minimum and maximum value allowed for this format. + # Returns a list of (min, max) values. + result = [] + for t in types: + fmt = t._type_ + size = struct.calcsize(fmt) + a = struct.unpack(fmt, ("\x00"*32)[:size])[0] + b = struct.unpack(fmt, ("\xFF"*32)[:size])[0] + c = struct.unpack(fmt, ("\x7F"+"\x00"*32)[:size])[0] + d = struct.unpack(fmt, ("\x80"+"\xFF"*32)[:size])[0] + result.append((min(a, b, c, d), max(a, b, c, d))) + return result + +ArgType = type(byref(c_int(0))) + +unsigned_types = [c_ubyte, c_ushort, c_uint, c_ulong] +signed_types = [c_byte, c_short, c_int, c_long, c_longlong] + +bool_types = [] + +float_types = [c_double, c_float] + +try: + c_ulonglong + c_longlong +except NameError: + pass +else: + unsigned_types.append(c_ulonglong) + signed_types.append(c_longlong) + +try: + c_bool +except NameError: + pass +else: + bool_types.append(c_bool) + +unsigned_ranges = valid_ranges(*unsigned_types) +signed_ranges = valid_ranges(*signed_types) +bool_values = [True, False, 0, 1, -1, 5000, 'test', [], [1]] + +################################################################ + +class NumberTestCase(unittest.TestCase): + + def test_default_init(self): + # default values are set to zero + for t in signed_types + unsigned_types + float_types: + self.assertEqual(t().value, 0) + + def test_unsigned_values(self): + # the value given to the constructor is available + # as the 'value' attribute + for t, (l, h) in zip(unsigned_types, unsigned_ranges): + self.assertEqual(t(l).value, l) + self.assertEqual(t(h).value, h) + + def test_signed_values(self): + # see above + for t, (l, h) in zip(signed_types, signed_ranges): + self.assertEqual(t(l).value, l) + self.assertEqual(t(h).value, h) + + def test_bool_values(self): + from operator import truth + for t, v in zip(bool_types, bool_values): + self.assertEqual(t(v).value, truth(v)) + + def test_typeerror(self): + # Only numbers are allowed in the contructor, + # otherwise TypeError is raised + for t in signed_types + unsigned_types + float_types: + self.assertRaises(TypeError, t, "") + self.assertRaises(TypeError, t, None) + +## def test_valid_ranges(self): +## # invalid values of the correct type +## # raise ValueError (not OverflowError) +## for t, (l, h) in zip(unsigned_types, unsigned_ranges): +## self.assertRaises(ValueError, t, l-1) +## self.assertRaises(ValueError, t, h+1) + + def test_from_param(self): + # the from_param class method attribute always + # returns PyCArgObject instances + for t in signed_types + unsigned_types + float_types: + self.assertEqual(ArgType, type(t.from_param(0))) + + def test_byref(self): + # calling byref returns also a PyCArgObject instance + for t in signed_types + unsigned_types + float_types + bool_types: + parm = byref(t()) + self.assertEqual(ArgType, type(parm)) + + + def test_floats(self): + # c_float and c_double can be created from + # Python int, long and float + class FloatLike(object): + def __float__(self): + return 2.0 + f = FloatLike() + for t in float_types: + self.assertEqual(t(2.0).value, 2.0) + self.assertEqual(t(2).value, 2.0) + self.assertEqual(t(2L).value, 2.0) + self.assertEqual(t(f).value, 2.0) + + def test_integers(self): + class FloatLike(object): + def __float__(self): + return 2.0 + f = FloatLike() + class IntLike(object): + def __int__(self): + return 2 + i = IntLike() + # integers cannot be constructed from floats, + # but from integer-like objects + for t in signed_types + unsigned_types: + self.assertRaises(TypeError, t, 3.14) + self.assertRaises(TypeError, t, f) + self.assertEqual(t(i).value, 2) + + def test_sizes(self): + for t in signed_types + unsigned_types + float_types + bool_types: + try: + size = struct.calcsize(t._type_) + except struct.error: + continue + # sizeof of the type... + self.assertEqual(sizeof(t), size) + # and sizeof of an instance + self.assertEqual(sizeof(t()), size) + + def test_alignments(self): + for t in signed_types + unsigned_types + float_types: + code = t._type_ # the typecode + align = struct.calcsize("c%c" % code) - struct.calcsize(code) + + # alignment of the type... + self.assertEqual((code, alignment(t)), + (code, align)) + # and alignment of an instance + self.assertEqual((code, alignment(t())), + (code, align)) + + def test_int_from_address(self): + from array import array + for t in signed_types + unsigned_types: + # the array module doesn't support all format codes + # (no 'q' or 'Q') + try: + array(t._type_) + except ValueError: + continue + a = array(t._type_, [100]) + + # v now is an integer at an 'external' memory location + v = t.from_address(a.buffer_info()[0]) + self.assertEqual(v.value, a[0]) + self.assertEqual(type(v), t) + + # changing the value at the memory location changes v's value also + a[0] = 42 + self.assertEqual(v.value, a[0]) + + + def test_float_from_address(self): + from array import array + for t in float_types: + a = array(t._type_, [3.14]) + v = t.from_address(a.buffer_info()[0]) + self.assertEqual(v.value, a[0]) + self.assertTrue(type(v) is t) + a[0] = 2.3456e17 + self.assertEqual(v.value, a[0]) + self.assertTrue(type(v) is t) + + def test_char_from_address(self): + from ctypes import c_char + from array import array + + a = array('c', 'x') + v = c_char.from_address(a.buffer_info()[0]) + self.assertEqual(v.value, a[0]) + self.assertTrue(type(v) is c_char) + + a[0] = '?' + self.assertEqual(v.value, a[0]) + + # array does not support c_bool / 't' + # def test_bool_from_address(self): + # from ctypes import c_bool + # from array import array + # a = array(c_bool._type_, [True]) + # v = t.from_address(a.buffer_info()[0]) + # self.assertEqual(v.value, a[0]) + # self.assertEqual(type(v) is t) + # a[0] = False + # self.assertEqual(v.value, a[0]) + # self.assertEqual(type(v) is t) + + def test_init(self): + # c_int() can be initialized from Python's int, and c_int. + # Not from c_long or so, which seems strange, abd should + # probably be changed: + self.assertRaises(TypeError, c_int, c_long(42)) + + def test_float_overflow(self): + import sys + big_int = int(sys.float_info.max) * 2 + for t in float_types + [c_longdouble]: + self.assertRaises(OverflowError, t, big_int) + if (hasattr(t, "__ctype_be__")): + self.assertRaises(OverflowError, t.__ctype_be__, big_int) + if (hasattr(t, "__ctype_le__")): + self.assertRaises(OverflowError, t.__ctype_le__, big_int) + +## def test_perf(self): +## check_perf() + +from ctypes import _SimpleCData +class c_int_S(_SimpleCData): + _type_ = "i" + __slots__ = [] + +def run_test(rep, msg, func, arg=None): +## items = [None] * rep + items = range(rep) + from time import clock + if arg is not None: + start = clock() + for i in items: + func(arg); func(arg); func(arg); func(arg); func(arg) + stop = clock() + else: + start = clock() + for i in items: + func(); func(); func(); func(); func() + stop = clock() + print "%15s: %.2f us" % (msg, ((stop-start)*1e6/5/rep)) + +def check_perf(): + # Construct 5 objects + from ctypes import c_int + + REP = 200000 + + run_test(REP, "int()", int) + run_test(REP, "int(999)", int) + run_test(REP, "c_int()", c_int) + run_test(REP, "c_int(999)", c_int) + run_test(REP, "c_int_S()", c_int_S) + run_test(REP, "c_int_S(999)", c_int_S) + +# Python 2.3 -OO, win2k, P4 700 MHz: +# +# int(): 0.87 us +# int(999): 0.87 us +# c_int(): 3.35 us +# c_int(999): 3.34 us +# c_int_S(): 3.23 us +# c_int_S(999): 3.24 us + +# Python 2.2 -OO, win2k, P4 700 MHz: +# +# int(): 0.89 us +# int(999): 0.89 us +# c_int(): 9.99 us +# c_int(999): 10.02 us +# c_int_S(): 9.87 us +# c_int_S(999): 9.85 us + +if __name__ == '__main__': +## check_perf() + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_numbers.pyc b/lib/python2.7/ctypes/test/test_numbers.pyc new file mode 100644 index 0000000..cf2995e Binary files /dev/null and b/lib/python2.7/ctypes/test/test_numbers.pyc differ diff --git a/lib/python2.7/ctypes/test/test_numbers.pyo b/lib/python2.7/ctypes/test/test_numbers.pyo new file mode 100644 index 0000000..cf2995e Binary files /dev/null and b/lib/python2.7/ctypes/test/test_numbers.pyo differ diff --git a/lib/python2.7/ctypes/test/test_objects.py b/lib/python2.7/ctypes/test/test_objects.py new file mode 100644 index 0000000..4d921d2 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_objects.py @@ -0,0 +1,70 @@ +r''' +This tests the '_objects' attribute of ctypes instances. '_objects' +holds references to objects that must be kept alive as long as the +ctypes instance, to make sure that the memory buffer is valid. + +WARNING: The '_objects' attribute is exposed ONLY for debugging ctypes itself, +it MUST NEVER BE MODIFIED! + +'_objects' is initialized to a dictionary on first use, before that it +is None. + +Here is an array of string pointers: + +>>> from ctypes import * +>>> array = (c_char_p * 5)() +>>> print array._objects +None +>>> + +The memory block stores pointers to strings, and the strings itself +assigned from Python must be kept. + +>>> array[4] = 'foo bar' +>>> array._objects +{'4': 'foo bar'} +>>> array[4] +'foo bar' +>>> + +It gets more complicated when the ctypes instance itself is contained +in a 'base' object. + +>>> class X(Structure): +... _fields_ = [("x", c_int), ("y", c_int), ("array", c_char_p * 5)] +... +>>> x = X() +>>> print x._objects +None +>>> + +The'array' attribute of the 'x' object shares part of the memory buffer +of 'x' ('_b_base_' is either None, or the root object owning the memory block): + +>>> print x.array._b_base_ # doctest: +ELLIPSIS + +>>> + +>>> x.array[0] = 'spam spam spam' +>>> x._objects +{'0:2': 'spam spam spam'} +>>> x.array._b_base_._objects +{'0:2': 'spam spam spam'} +>>> + +''' + +import unittest, doctest, sys + +import ctypes.test.test_objects + +class TestCase(unittest.TestCase): + if sys.hexversion > 0x02040000: + # Python 2.3 has no ELLIPSIS flag, so we don't test with this + # version: + def test(self): + doctest.testmod(ctypes.test.test_objects) + +if __name__ == '__main__': + if sys.hexversion > 0x02040000: + doctest.testmod(ctypes.test.test_objects) diff --git a/lib/python2.7/ctypes/test/test_objects.pyc b/lib/python2.7/ctypes/test/test_objects.pyc new file mode 100644 index 0000000..5b8094b Binary files /dev/null and b/lib/python2.7/ctypes/test/test_objects.pyc differ diff --git a/lib/python2.7/ctypes/test/test_objects.pyo b/lib/python2.7/ctypes/test/test_objects.pyo new file mode 100644 index 0000000..5b8094b Binary files /dev/null and b/lib/python2.7/ctypes/test/test_objects.pyo differ diff --git a/lib/python2.7/ctypes/test/test_parameters.py b/lib/python2.7/ctypes/test/test_parameters.py new file mode 100644 index 0000000..82704d5 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_parameters.py @@ -0,0 +1,188 @@ +import unittest, sys + +class SimpleTypesTestCase(unittest.TestCase): + + def setUp(self): + import ctypes + try: + from _ctypes import set_conversion_mode + except ImportError: + pass + else: + self.prev_conv_mode = set_conversion_mode("ascii", "strict") + + def tearDown(self): + try: + from _ctypes import set_conversion_mode + except ImportError: + pass + else: + set_conversion_mode(*self.prev_conv_mode) + + + def test_subclasses(self): + from ctypes import c_void_p, c_char_p + # ctypes 0.9.5 and before did overwrite from_param in SimpleType_new + class CVOIDP(c_void_p): + def from_param(cls, value): + return value * 2 + from_param = classmethod(from_param) + + class CCHARP(c_char_p): + def from_param(cls, value): + return value * 4 + from_param = classmethod(from_param) + + self.assertEqual(CVOIDP.from_param("abc"), "abcabc") + self.assertEqual(CCHARP.from_param("abc"), "abcabcabcabc") + + try: + from ctypes import c_wchar_p + except ImportError: + return + + class CWCHARP(c_wchar_p): + def from_param(cls, value): + return value * 3 + from_param = classmethod(from_param) + + self.assertEqual(CWCHARP.from_param("abc"), "abcabcabc") + + # XXX Replace by c_char_p tests + def test_cstrings(self): + from ctypes import c_char_p, byref + + # c_char_p.from_param on a Python String packs the string + # into a cparam object + s = "123" + self.assertTrue(c_char_p.from_param(s)._obj is s) + + # new in 0.9.1: convert (encode) unicode to ascii + self.assertEqual(c_char_p.from_param(u"123")._obj, "123") + self.assertRaises(UnicodeEncodeError, c_char_p.from_param, u"123\377") + + self.assertRaises(TypeError, c_char_p.from_param, 42) + + # calling c_char_p.from_param with a c_char_p instance + # returns the argument itself: + a = c_char_p("123") + self.assertTrue(c_char_p.from_param(a) is a) + + def test_cw_strings(self): + from ctypes import byref + try: + from ctypes import c_wchar_p + except ImportError: +## print "(No c_wchar_p)" + return + s = u"123" + if sys.platform == "win32": + self.assertTrue(c_wchar_p.from_param(s)._obj is s) + self.assertRaises(TypeError, c_wchar_p.from_param, 42) + + # new in 0.9.1: convert (decode) ascii to unicode + self.assertEqual(c_wchar_p.from_param("123")._obj, u"123") + self.assertRaises(UnicodeDecodeError, c_wchar_p.from_param, "123\377") + + pa = c_wchar_p.from_param(c_wchar_p(u"123")) + self.assertEqual(type(pa), c_wchar_p) + + def test_int_pointers(self): + from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer + LPINT = POINTER(c_int) + +## p = pointer(c_int(42)) +## x = LPINT.from_param(p) + x = LPINT.from_param(pointer(c_int(42))) + self.assertEqual(x.contents.value, 42) + self.assertEqual(LPINT(c_int(42)).contents.value, 42) + + self.assertEqual(LPINT.from_param(None), None) + + if c_int != c_long: + self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42))) + self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42))) + self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42))) + + def test_byref_pointer(self): + # The from_param class method of POINTER(typ) classes accepts what is + # returned by byref(obj), it type(obj) == typ + from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref + LPINT = POINTER(c_int) + + LPINT.from_param(byref(c_int(42))) + + self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22))) + if c_int != c_long: + self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22))) + self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22))) + + def test_byref_pointerpointer(self): + # See above + from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref + + LPLPINT = POINTER(POINTER(c_int)) + LPLPINT.from_param(byref(pointer(c_int(42)))) + + self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22)))) + if c_int != c_long: + self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22)))) + self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22)))) + + def test_array_pointers(self): + from ctypes import c_short, c_uint, c_int, c_long, POINTER + INTARRAY = c_int * 3 + ia = INTARRAY() + self.assertEqual(len(ia), 3) + self.assertEqual([ia[i] for i in range(3)], [0, 0, 0]) + + # Pointers are only compatible with arrays containing items of + # the same type! + LPINT = POINTER(c_int) + LPINT.from_param((c_int*3)()) + self.assertRaises(TypeError, LPINT.from_param, c_short*3) + self.assertRaises(TypeError, LPINT.from_param, c_long*3) + self.assertRaises(TypeError, LPINT.from_param, c_uint*3) + +## def test_performance(self): +## check_perf() + + def test_noctypes_argtype(self): + import _ctypes_test + from ctypes import CDLL, c_void_p, ArgumentError + + func = CDLL(_ctypes_test.__file__)._testfunc_p_p + func.restype = c_void_p + # TypeError: has no from_param method + self.assertRaises(TypeError, setattr, func, "argtypes", (object,)) + + class Adapter(object): + def from_param(cls, obj): + return None + + func.argtypes = (Adapter(),) + self.assertEqual(func(None), None) + self.assertEqual(func(object()), None) + + class Adapter(object): + def from_param(cls, obj): + return obj + + func.argtypes = (Adapter(),) + # don't know how to convert parameter 1 + self.assertRaises(ArgumentError, func, object()) + self.assertEqual(func(c_void_p(42)), 42) + + class Adapter(object): + def from_param(cls, obj): + raise ValueError(obj) + + func.argtypes = (Adapter(),) + # ArgumentError: argument 1: ValueError: 99 + self.assertRaises(ArgumentError, func, 99) + + +################################################################ + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_parameters.pyc b/lib/python2.7/ctypes/test/test_parameters.pyc new file mode 100644 index 0000000..c799a36 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_parameters.pyc differ diff --git a/lib/python2.7/ctypes/test/test_parameters.pyo b/lib/python2.7/ctypes/test/test_parameters.pyo new file mode 100644 index 0000000..c799a36 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_parameters.pyo differ diff --git a/lib/python2.7/ctypes/test/test_pep3118.py b/lib/python2.7/ctypes/test/test_pep3118.py new file mode 100644 index 0000000..976473c --- /dev/null +++ b/lib/python2.7/ctypes/test/test_pep3118.py @@ -0,0 +1,196 @@ +import unittest +from ctypes import * +import re, sys + +if sys.byteorder == "little": + THIS_ENDIAN = "<" + OTHER_ENDIAN = ">" +else: + THIS_ENDIAN = ">" + OTHER_ENDIAN = "<" + +def normalize(format): + # Remove current endian specifier and white space from a format + # string + if format is None: + return "" + format = format.replace(OTHER_ENDIAN, THIS_ENDIAN) + return re.sub(r"\s", "", format) + +class Test(unittest.TestCase): + + def test_native_types(self): + for tp, fmt, shape, itemtp in native_types: + ob = tp() + v = memoryview(ob) + try: + self.assertEqual(normalize(v.format), normalize(fmt)) + if shape is not None: + self.assertEqual(len(v), shape[0]) + else: + self.assertEqual(len(v) * sizeof(itemtp), sizeof(ob)) + self.assertEqual(v.itemsize, sizeof(itemtp)) + self.assertEqual(v.shape, shape) + # ctypes object always have a non-strided memory block + self.assertEqual(v.strides, None) + # they are always read/write + self.assertFalse(v.readonly) + + if v.shape: + n = 1 + for dim in v.shape: + n = n * dim + self.assertEqual(n * v.itemsize, len(v.tobytes())) + except: + # so that we can see the failing type + print(tp) + raise + + def test_endian_types(self): + for tp, fmt, shape, itemtp in endian_types: + ob = tp() + v = memoryview(ob) + try: + self.assertEqual(v.format, fmt) + if shape is not None: + self.assertEqual(len(v), shape[0]) + else: + self.assertEqual(len(v) * sizeof(itemtp), sizeof(ob)) + self.assertEqual(v.itemsize, sizeof(itemtp)) + self.assertEqual(v.shape, shape) + # ctypes object always have a non-strided memory block + self.assertEqual(v.strides, None) + # they are always read/write + self.assertFalse(v.readonly) + + if v.shape: + n = 1 + for dim in v.shape: + n = n * dim + self.assertEqual(n, len(v)) + except: + # so that we can see the failing type + print(tp) + raise + +# define some structure classes + +class Point(Structure): + _fields_ = [("x", c_long), ("y", c_long)] + +class PackedPoint(Structure): + _pack_ = 2 + _fields_ = [("x", c_long), ("y", c_long)] + +class Point2(Structure): + pass +Point2._fields_ = [("x", c_long), ("y", c_long)] + +class EmptyStruct(Structure): + _fields_ = [] + +class aUnion(Union): + _fields_ = [("a", c_int)] + +class Incomplete(Structure): + pass + +class Complete(Structure): + pass +PComplete = POINTER(Complete) +Complete._fields_ = [("a", c_long)] + +################################################################ +# +# This table contains format strings as they look on little endian +# machines. The test replaces '<' with '>' on big endian machines. +# +native_types = [ + # type format shape calc itemsize + + ## simple types + + (c_char, "l:x:>l:y:}", None, BEPoint), + (LEPoint, "T{l:x:>l:y:}", None, POINTER(BEPoint)), + (POINTER(LEPoint), "&T{= 0: + return a + # View the bits in `a` as unsigned instead. + import struct + num_bits = struct.calcsize("P") * 8 # num bits in native machine address + a += 1L << num_bits + assert a >= 0 + return a + +def c_wbuffer(init): + n = len(init) + 1 + return (c_wchar * n)(*init) + +class CharPointersTestCase(unittest.TestCase): + + def setUp(self): + func = testdll._testfunc_p_p + func.restype = c_long + func.argtypes = None + + def test_paramflags(self): + # function returns c_void_p result, + # and has a required parameter named 'input' + prototype = CFUNCTYPE(c_void_p, c_void_p) + func = prototype(("_testfunc_p_p", testdll), + ((1, "input"),)) + + try: + func() + except TypeError, details: + self.assertEqual(str(details), "required argument 'input' missing") + else: + self.fail("TypeError not raised") + + self.assertEqual(func(None), None) + self.assertEqual(func(input=None), None) + + + def test_int_pointer_arg(self): + func = testdll._testfunc_p_p + func.restype = c_long + self.assertEqual(0, func(0)) + + ci = c_int(0) + + func.argtypes = POINTER(c_int), + self.assertEqual(positive_address(addressof(ci)), + positive_address(func(byref(ci)))) + + func.argtypes = c_char_p, + self.assertRaises(ArgumentError, func, byref(ci)) + + func.argtypes = POINTER(c_short), + self.assertRaises(ArgumentError, func, byref(ci)) + + func.argtypes = POINTER(c_double), + self.assertRaises(ArgumentError, func, byref(ci)) + + def test_POINTER_c_char_arg(self): + func = testdll._testfunc_p_p + func.restype = c_char_p + func.argtypes = POINTER(c_char), + + self.assertEqual(None, func(None)) + self.assertEqual("123", func("123")) + self.assertEqual(None, func(c_char_p(None))) + self.assertEqual("123", func(c_char_p("123"))) + + self.assertEqual("123", func(c_buffer("123"))) + ca = c_char("a") + self.assertEqual("a", func(pointer(ca))[0]) + self.assertEqual("a", func(byref(ca))[0]) + + def test_c_char_p_arg(self): + func = testdll._testfunc_p_p + func.restype = c_char_p + func.argtypes = c_char_p, + + self.assertEqual(None, func(None)) + self.assertEqual("123", func("123")) + self.assertEqual(None, func(c_char_p(None))) + self.assertEqual("123", func(c_char_p("123"))) + + self.assertEqual("123", func(c_buffer("123"))) + ca = c_char("a") + self.assertEqual("a", func(pointer(ca))[0]) + self.assertEqual("a", func(byref(ca))[0]) + + def test_c_void_p_arg(self): + func = testdll._testfunc_p_p + func.restype = c_char_p + func.argtypes = c_void_p, + + self.assertEqual(None, func(None)) + self.assertEqual("123", func("123")) + self.assertEqual("123", func(c_char_p("123"))) + self.assertEqual(None, func(c_char_p(None))) + + self.assertEqual("123", func(c_buffer("123"))) + ca = c_char("a") + self.assertEqual("a", func(pointer(ca))[0]) + self.assertEqual("a", func(byref(ca))[0]) + + func(byref(c_int())) + func(pointer(c_int())) + func((c_int * 3)()) + + try: + func.restype = c_wchar_p + except NameError: + pass + else: + self.assertEqual(None, func(c_wchar_p(None))) + self.assertEqual(u"123", func(c_wchar_p(u"123"))) + + def test_instance(self): + func = testdll._testfunc_p_p + func.restype = c_void_p + + class X: + _as_parameter_ = None + + func.argtypes = c_void_p, + self.assertEqual(None, func(X())) + + func.argtypes = None + self.assertEqual(None, func(X())) + +try: + c_wchar +except NameError: + pass +else: + class WCharPointersTestCase(unittest.TestCase): + + def setUp(self): + func = testdll._testfunc_p_p + func.restype = c_int + func.argtypes = None + + + def test_POINTER_c_wchar_arg(self): + func = testdll._testfunc_p_p + func.restype = c_wchar_p + func.argtypes = POINTER(c_wchar), + + self.assertEqual(None, func(None)) + self.assertEqual(u"123", func(u"123")) + self.assertEqual(None, func(c_wchar_p(None))) + self.assertEqual(u"123", func(c_wchar_p(u"123"))) + + self.assertEqual(u"123", func(c_wbuffer(u"123"))) + ca = c_wchar("a") + self.assertEqual(u"a", func(pointer(ca))[0]) + self.assertEqual(u"a", func(byref(ca))[0]) + + def test_c_wchar_p_arg(self): + func = testdll._testfunc_p_p + func.restype = c_wchar_p + func.argtypes = c_wchar_p, + + c_wchar_p.from_param(u"123") + + self.assertEqual(None, func(None)) + self.assertEqual("123", func(u"123")) + self.assertEqual(None, func(c_wchar_p(None))) + self.assertEqual("123", func(c_wchar_p("123"))) + + # XXX Currently, these raise TypeErrors, although they shouldn't: + self.assertEqual("123", func(c_wbuffer("123"))) + ca = c_wchar("a") + self.assertEqual("a", func(pointer(ca))[0]) + self.assertEqual("a", func(byref(ca))[0]) + +class ArrayTest(unittest.TestCase): + def test(self): + func = testdll._testfunc_ai8 + func.restype = POINTER(c_int) + func.argtypes = c_int * 8, + + func((c_int * 8)(1, 2, 3, 4, 5, 6, 7, 8)) + + # This did crash before: + + def func(): pass + CFUNCTYPE(None, c_int * 3)(func) + +################################################################ + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_prototypes.pyc b/lib/python2.7/ctypes/test/test_prototypes.pyc new file mode 100644 index 0000000..ad0edaf Binary files /dev/null and b/lib/python2.7/ctypes/test/test_prototypes.pyc differ diff --git a/lib/python2.7/ctypes/test/test_prototypes.pyo b/lib/python2.7/ctypes/test/test_prototypes.pyo new file mode 100644 index 0000000..f76be4d Binary files /dev/null and b/lib/python2.7/ctypes/test/test_prototypes.pyo differ diff --git a/lib/python2.7/ctypes/test/test_python_api.py b/lib/python2.7/ctypes/test/test_python_api.py new file mode 100644 index 0000000..698170f --- /dev/null +++ b/lib/python2.7/ctypes/test/test_python_api.py @@ -0,0 +1,90 @@ +from ctypes import * +import unittest, sys +from ctypes.test import is_resource_enabled + +################################################################ +# This section should be moved into ctypes\__init__.py, when it's ready. + +from _ctypes import PyObj_FromPtr + +################################################################ + +from sys import getrefcount as grc +if sys.version_info > (2, 4): + c_py_ssize_t = c_size_t +else: + c_py_ssize_t = c_int + +class PythonAPITestCase(unittest.TestCase): + + def test_PyString_FromStringAndSize(self): + PyString_FromStringAndSize = pythonapi.PyString_FromStringAndSize + + PyString_FromStringAndSize.restype = py_object + PyString_FromStringAndSize.argtypes = c_char_p, c_py_ssize_t + + self.assertEqual(PyString_FromStringAndSize("abcdefghi", 3), "abc") + + def test_PyString_FromString(self): + pythonapi.PyString_FromString.restype = py_object + pythonapi.PyString_FromString.argtypes = (c_char_p,) + + s = "abc" + refcnt = grc(s) + pyob = pythonapi.PyString_FromString(s) + self.assertEqual(grc(s), refcnt) + self.assertEqual(s, pyob) + del pyob + self.assertEqual(grc(s), refcnt) + + if is_resource_enabled("refcount"): + # This test is unreliable, because it is possible that code in + # unittest changes the refcount of the '42' integer. So, it + # is disabled by default. + def test_PyInt_Long(self): + ref42 = grc(42) + pythonapi.PyInt_FromLong.restype = py_object + self.assertEqual(pythonapi.PyInt_FromLong(42), 42) + + self.assertEqual(grc(42), ref42) + + pythonapi.PyInt_AsLong.argtypes = (py_object,) + pythonapi.PyInt_AsLong.restype = c_long + + res = pythonapi.PyInt_AsLong(42) + self.assertEqual(grc(res), ref42 + 1) + del res + self.assertEqual(grc(42), ref42) + + def test_PyObj_FromPtr(self): + s = "abc def ghi jkl" + ref = grc(s) + # id(python-object) is the address + pyobj = PyObj_FromPtr(id(s)) + self.assertTrue(s is pyobj) + + self.assertEqual(grc(s), ref + 1) + del pyobj + self.assertEqual(grc(s), ref) + + def test_PyOS_snprintf(self): + PyOS_snprintf = pythonapi.PyOS_snprintf + PyOS_snprintf.argtypes = POINTER(c_char), c_size_t, c_char_p + + buf = c_buffer(256) + PyOS_snprintf(buf, sizeof(buf), "Hello from %s", "ctypes") + self.assertEqual(buf.value, "Hello from ctypes") + + PyOS_snprintf(buf, sizeof(buf), "Hello from %s", "ctypes", 1, 2, 3) + self.assertEqual(buf.value, "Hello from ctypes") + + # not enough arguments + self.assertRaises(TypeError, PyOS_snprintf, buf) + + def test_pyobject_repr(self): + self.assertEqual(repr(py_object()), "py_object()") + self.assertEqual(repr(py_object(42)), "py_object(42)") + self.assertEqual(repr(py_object(object)), "py_object(%r)" % object) + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_python_api.pyc b/lib/python2.7/ctypes/test/test_python_api.pyc new file mode 100644 index 0000000..6fa76a2 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_python_api.pyc differ diff --git a/lib/python2.7/ctypes/test/test_python_api.pyo b/lib/python2.7/ctypes/test/test_python_api.pyo new file mode 100644 index 0000000..6fa76a2 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_python_api.pyo differ diff --git a/lib/python2.7/ctypes/test/test_random_things.py b/lib/python2.7/ctypes/test/test_random_things.py new file mode 100644 index 0000000..1c217c3 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_random_things.py @@ -0,0 +1,75 @@ +from ctypes import * +import unittest, sys + +def callback_func(arg): + 42 // arg + raise ValueError(arg) + +if sys.platform == "win32": + + class call_function_TestCase(unittest.TestCase): + # _ctypes.call_function is deprecated and private, but used by + # Gary Bishp's readline module. If we have it, we must test it as well. + + def test(self): + from _ctypes import call_function + windll.kernel32.LoadLibraryA.restype = c_void_p + windll.kernel32.GetProcAddress.argtypes = c_void_p, c_char_p + windll.kernel32.GetProcAddress.restype = c_void_p + + hdll = windll.kernel32.LoadLibraryA("kernel32") + funcaddr = windll.kernel32.GetProcAddress(hdll, "GetModuleHandleA") + + self.assertEqual(call_function(funcaddr, (None,)), + windll.kernel32.GetModuleHandleA(None)) + +class CallbackTracbackTestCase(unittest.TestCase): + # When an exception is raised in a ctypes callback function, the C + # code prints a traceback. + # + # This test makes sure the exception types *and* the exception + # value is printed correctly. + # + # Changed in 0.9.3: No longer is '(in callback)' prepended to the + # error message - instead a additional frame for the C code is + # created, then a full traceback printed. When SystemExit is + # raised in a callback function, the interpreter exits. + + def capture_stderr(self, func, *args, **kw): + # helper - call function 'func', and return the captured stderr + import StringIO + old_stderr = sys.stderr + logger = sys.stderr = StringIO.StringIO() + try: + func(*args, **kw) + finally: + sys.stderr = old_stderr + return logger.getvalue() + + def test_ValueError(self): + cb = CFUNCTYPE(c_int, c_int)(callback_func) + out = self.capture_stderr(cb, 42) + self.assertEqual(out.splitlines()[-1], + "ValueError: 42") + + def test_IntegerDivisionError(self): + cb = CFUNCTYPE(c_int, c_int)(callback_func) + out = self.capture_stderr(cb, 0) + self.assertEqual(out.splitlines()[-1][:19], + "ZeroDivisionError: ") + + def test_FloatDivisionError(self): + cb = CFUNCTYPE(c_int, c_double)(callback_func) + out = self.capture_stderr(cb, 0.0) + self.assertEqual(out.splitlines()[-1][:19], + "ZeroDivisionError: ") + + def test_TypeErrorDivisionError(self): + cb = CFUNCTYPE(c_int, c_char_p)(callback_func) + out = self.capture_stderr(cb, "spam") + self.assertEqual(out.splitlines()[-1], + "TypeError: " + "unsupported operand type(s) for //: 'int' and 'str'") + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_random_things.pyc b/lib/python2.7/ctypes/test/test_random_things.pyc new file mode 100644 index 0000000..dd148fc Binary files /dev/null and b/lib/python2.7/ctypes/test/test_random_things.pyc differ diff --git a/lib/python2.7/ctypes/test/test_random_things.pyo b/lib/python2.7/ctypes/test/test_random_things.pyo new file mode 100644 index 0000000..dd148fc Binary files /dev/null and b/lib/python2.7/ctypes/test/test_random_things.pyo differ diff --git a/lib/python2.7/ctypes/test/test_refcounts.py b/lib/python2.7/ctypes/test/test_refcounts.py new file mode 100644 index 0000000..35a81aa --- /dev/null +++ b/lib/python2.7/ctypes/test/test_refcounts.py @@ -0,0 +1,98 @@ +import unittest +import ctypes +import gc + +MyCallback = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int) +OtherCallback = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_ulonglong) + +import _ctypes_test +dll = ctypes.CDLL(_ctypes_test.__file__) + +class RefcountTestCase(unittest.TestCase): + + def test_1(self): + from sys import getrefcount as grc + + f = dll._testfunc_callback_i_if + f.restype = ctypes.c_int + f.argtypes = [ctypes.c_int, MyCallback] + + def callback(value): + #print "called back with", value + return value + + self.assertEqual(grc(callback), 2) + cb = MyCallback(callback) + + self.assertTrue(grc(callback) > 2) + result = f(-10, cb) + self.assertEqual(result, -18) + cb = None + + gc.collect() + + self.assertEqual(grc(callback), 2) + + + def test_refcount(self): + from sys import getrefcount as grc + def func(*args): + pass + # this is the standard refcount for func + self.assertEqual(grc(func), 2) + + # the CFuncPtr instance holds atr least one refcount on func: + f = OtherCallback(func) + self.assertTrue(grc(func) > 2) + + # and may release it again + del f + self.assertTrue(grc(func) >= 2) + + # but now it must be gone + gc.collect() + self.assertTrue(grc(func) == 2) + + class X(ctypes.Structure): + _fields_ = [("a", OtherCallback)] + x = X() + x.a = OtherCallback(func) + + # the CFuncPtr instance holds atr least one refcount on func: + self.assertTrue(grc(func) > 2) + + # and may release it again + del x + self.assertTrue(grc(func) >= 2) + + # and now it must be gone again + gc.collect() + self.assertEqual(grc(func), 2) + + f = OtherCallback(func) + + # the CFuncPtr instance holds atr least one refcount on func: + self.assertTrue(grc(func) > 2) + + # create a cycle + f.cycle = f + + del f + gc.collect() + self.assertEqual(grc(func), 2) + +class AnotherLeak(unittest.TestCase): + def test_callback(self): + import sys + + proto = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_int) + def func(a, b): + return a * b * 2 + f = proto(func) + + a = sys.getrefcount(ctypes.c_int) + f(1, 2) + self.assertEqual(sys.getrefcount(ctypes.c_int), a) + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_refcounts.pyc b/lib/python2.7/ctypes/test/test_refcounts.pyc new file mode 100644 index 0000000..dfe16a5 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_refcounts.pyc differ diff --git a/lib/python2.7/ctypes/test/test_refcounts.pyo b/lib/python2.7/ctypes/test/test_refcounts.pyo new file mode 100644 index 0000000..dfe16a5 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_refcounts.pyo differ diff --git a/lib/python2.7/ctypes/test/test_repr.py b/lib/python2.7/ctypes/test/test_repr.py new file mode 100644 index 0000000..99cc556 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_repr.py @@ -0,0 +1,29 @@ +from ctypes import * +import unittest + +subclasses = [] +for base in [c_byte, c_short, c_int, c_long, c_longlong, + c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong, + c_float, c_double, c_longdouble, c_bool]: + class X(base): + pass + subclasses.append(X) + +class X(c_char): + pass + +# This test checks if the __repr__ is correct for subclasses of simple types + +class ReprTest(unittest.TestCase): + def test_numbers(self): + for typ in subclasses: + base = typ.__bases__[0] + self.assertTrue(repr(base(42)).startswith(base.__name__)) + self.assertEqual(": " + "expected string or Unicode object, int found") + else: + self.assertEqual(msg, + "(Phone) exceptions.TypeError: " + "expected string or Unicode object, int found") + + cls, msg = self.get_except(Person, "Someone", ("a", "b", "c")) + self.assertEqual(cls, RuntimeError) + if issubclass(Exception, object): + self.assertEqual(msg, + "(Phone) : too many initializers") + else: + self.assertEqual(msg, "(Phone) exceptions.TypeError: too many initializers") + + def test_huge_field_name(self): + # issue12881: segfault with large structure field names + def create_class(length): + class S(Structure): + _fields_ = [('x' * length, c_int)] + + for length in [10 ** i for i in range(0, 8)]: + try: + create_class(length) + except MemoryError: + # MemoryErrors are OK, we just don't want to segfault + pass + + def get_except(self, func, *args): + try: + func(*args) + except Exception, detail: + return detail.__class__, str(detail) + + +## def test_subclass_creation(self): +## meta = type(Structure) +## # same as 'class X(Structure): pass' +## # fails, since we need either a _fields_ or a _abstract_ attribute +## cls, msg = self.get_except(meta, "X", (Structure,), {}) +## self.assertEqual((cls, msg), +## (AttributeError, "class must define a '_fields_' attribute")) + + def test_abstract_class(self): + class X(Structure): + _abstract_ = "something" + # try 'X()' + cls, msg = self.get_except(eval, "X()", locals()) + self.assertEqual((cls, msg), (TypeError, "abstract class")) + + def test_methods(self): +## class X(Structure): +## _fields_ = [] + + self.assertTrue("in_dll" in dir(type(Structure))) + self.assertTrue("from_address" in dir(type(Structure))) + self.assertTrue("in_dll" in dir(type(Structure))) + + def test_positional_args(self): + # see also http://bugs.python.org/issue5042 + class W(Structure): + _fields_ = [("a", c_int), ("b", c_int)] + class X(W): + _fields_ = [("c", c_int)] + class Y(X): + pass + class Z(Y): + _fields_ = [("d", c_int), ("e", c_int), ("f", c_int)] + + z = Z(1, 2, 3, 4, 5, 6) + self.assertEqual((z.a, z.b, z.c, z.d, z.e, z.f), + (1, 2, 3, 4, 5, 6)) + z = Z(1) + self.assertEqual((z.a, z.b, z.c, z.d, z.e, z.f), + (1, 0, 0, 0, 0, 0)) + self.assertRaises(TypeError, lambda: Z(1, 2, 3, 4, 5, 6, 7)) + +class PointerMemberTestCase(unittest.TestCase): + + def test(self): + # a Structure with a POINTER field + class S(Structure): + _fields_ = [("array", POINTER(c_int))] + + s = S() + # We can assign arrays of the correct type + s.array = (c_int * 3)(1, 2, 3) + items = [s.array[i] for i in range(3)] + self.assertEqual(items, [1, 2, 3]) + + # The following are bugs, but are included here because the unittests + # also describe the current behaviour. + # + # This fails with SystemError: bad arg to internal function + # or with IndexError (with a patch I have) + + s.array[0] = 42 + + items = [s.array[i] for i in range(3)] + self.assertEqual(items, [42, 2, 3]) + + s.array[0] = 1 + +## s.array[1] = 42 + + items = [s.array[i] for i in range(3)] + self.assertEqual(items, [1, 2, 3]) + + def test_none_to_pointer_fields(self): + class S(Structure): + _fields_ = [("x", c_int), + ("p", POINTER(c_int))] + + s = S() + s.x = 12345678 + s.p = None + self.assertEqual(s.x, 12345678) + +class TestRecursiveStructure(unittest.TestCase): + def test_contains_itself(self): + class Recursive(Structure): + pass + + try: + Recursive._fields_ = [("next", Recursive)] + except AttributeError, details: + self.assertTrue("Structure or union cannot contain itself" in + str(details)) + else: + self.fail("Structure or union cannot contain itself") + + + def test_vice_versa(self): + class First(Structure): + pass + class Second(Structure): + pass + + First._fields_ = [("second", Second)] + + try: + Second._fields_ = [("first", First)] + except AttributeError, details: + self.assertTrue("_fields_ is final" in + str(details)) + else: + self.fail("AttributeError not raised") + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_structures.pyc b/lib/python2.7/ctypes/test/test_structures.pyc new file mode 100644 index 0000000..eb6955b Binary files /dev/null and b/lib/python2.7/ctypes/test/test_structures.pyc differ diff --git a/lib/python2.7/ctypes/test/test_structures.pyo b/lib/python2.7/ctypes/test/test_structures.pyo new file mode 100644 index 0000000..eb6955b Binary files /dev/null and b/lib/python2.7/ctypes/test/test_structures.pyo differ diff --git a/lib/python2.7/ctypes/test/test_unaligned_structures.py b/lib/python2.7/ctypes/test/test_unaligned_structures.py new file mode 100644 index 0000000..bcacfc8 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_unaligned_structures.py @@ -0,0 +1,45 @@ +import sys, unittest +from ctypes import * + +structures = [] +byteswapped_structures = [] + + +if sys.byteorder == "little": + SwappedStructure = BigEndianStructure +else: + SwappedStructure = LittleEndianStructure + +for typ in [c_short, c_int, c_long, c_longlong, + c_float, c_double, + c_ushort, c_uint, c_ulong, c_ulonglong]: + class X(Structure): + _pack_ = 1 + _fields_ = [("pad", c_byte), + ("value", typ)] + class Y(SwappedStructure): + _pack_ = 1 + _fields_ = [("pad", c_byte), + ("value", typ)] + structures.append(X) + byteswapped_structures.append(Y) + +class TestStructures(unittest.TestCase): + def test_native(self): + for typ in structures: +## print typ.value + self.assertEqual(typ.value.offset, 1) + o = typ() + o.value = 4 + self.assertEqual(o.value, 4) + + def test_swapped(self): + for typ in byteswapped_structures: +## print >> sys.stderr, typ.value + self.assertEqual(typ.value.offset, 1) + o = typ() + o.value = 4 + self.assertEqual(o.value, 4) + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_unaligned_structures.pyc b/lib/python2.7/ctypes/test/test_unaligned_structures.pyc new file mode 100644 index 0000000..85bc49d Binary files /dev/null and b/lib/python2.7/ctypes/test/test_unaligned_structures.pyc differ diff --git a/lib/python2.7/ctypes/test/test_unaligned_structures.pyo b/lib/python2.7/ctypes/test/test_unaligned_structures.pyo new file mode 100644 index 0000000..85bc49d Binary files /dev/null and b/lib/python2.7/ctypes/test/test_unaligned_structures.pyo differ diff --git a/lib/python2.7/ctypes/test/test_unicode.py b/lib/python2.7/ctypes/test/test_unicode.py new file mode 100644 index 0000000..6557479 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_unicode.py @@ -0,0 +1,129 @@ +# coding: latin-1 +import unittest +import ctypes + +try: + ctypes.c_wchar +except AttributeError: + pass +else: + import _ctypes_test + dll = ctypes.CDLL(_ctypes_test.__file__) + wcslen = dll.my_wcslen + wcslen.argtypes = [ctypes.c_wchar_p] + + + class UnicodeTestCase(unittest.TestCase): + def setUp(self): + self.prev_conv_mode = ctypes.set_conversion_mode("ascii", "strict") + + def tearDown(self): + ctypes.set_conversion_mode(*self.prev_conv_mode) + + def test_ascii_strict(self): + ctypes.set_conversion_mode("ascii", "strict") + # no conversions take place with unicode arguments + self.assertEqual(wcslen(u"abc"), 3) + self.assertEqual(wcslen(u"ab\u2070"), 3) + # string args are converted + self.assertEqual(wcslen("abc"), 3) + self.assertRaises(ctypes.ArgumentError, wcslen, "abä") + + def test_ascii_replace(self): + ctypes.set_conversion_mode("ascii", "replace") + self.assertEqual(wcslen(u"abc"), 3) + self.assertEqual(wcslen(u"ab\u2070"), 3) + self.assertEqual(wcslen("abc"), 3) + self.assertEqual(wcslen("abä"), 3) + + def test_ascii_ignore(self): + ctypes.set_conversion_mode("ascii", "ignore") + self.assertEqual(wcslen(u"abc"), 3) + self.assertEqual(wcslen(u"ab\u2070"), 3) + # ignore error mode skips non-ascii characters + self.assertEqual(wcslen("abc"), 3) + self.assertEqual(wcslen("äöüß"), 0) + + def test_latin1_strict(self): + ctypes.set_conversion_mode("latin-1", "strict") + self.assertEqual(wcslen(u"abc"), 3) + self.assertEqual(wcslen(u"ab\u2070"), 3) + self.assertEqual(wcslen("abc"), 3) + self.assertEqual(wcslen("äöüß"), 4) + + def test_buffers(self): + ctypes.set_conversion_mode("ascii", "strict") + buf = ctypes.create_unicode_buffer("abc") + self.assertEqual(len(buf), 3+1) + + ctypes.set_conversion_mode("ascii", "replace") + buf = ctypes.create_unicode_buffer("abäöü") + self.assertEqual(buf[:], u"ab\uFFFD\uFFFD\uFFFD\0") + self.assertEqual(buf[::], u"ab\uFFFD\uFFFD\uFFFD\0") + self.assertEqual(buf[::-1], u"\0\uFFFD\uFFFD\uFFFDba") + self.assertEqual(buf[::2], u"a\uFFFD\uFFFD") + self.assertEqual(buf[6:5:-1], u"") + + ctypes.set_conversion_mode("ascii", "ignore") + buf = ctypes.create_unicode_buffer("abäöü") + # is that correct? not sure. But with 'ignore', you get what you pay for.. + self.assertEqual(buf[:], u"ab\0\0\0\0") + self.assertEqual(buf[::], u"ab\0\0\0\0") + self.assertEqual(buf[::-1], u"\0\0\0\0ba") + self.assertEqual(buf[::2], u"a\0\0") + self.assertEqual(buf[6:5:-1], u"") + + import _ctypes_test + func = ctypes.CDLL(_ctypes_test.__file__)._testfunc_p_p + + class StringTestCase(UnicodeTestCase): + def setUp(self): + self.prev_conv_mode = ctypes.set_conversion_mode("ascii", "strict") + func.argtypes = [ctypes.c_char_p] + func.restype = ctypes.c_char_p + + def tearDown(self): + ctypes.set_conversion_mode(*self.prev_conv_mode) + func.argtypes = None + func.restype = ctypes.c_int + + def test_ascii_replace(self): + ctypes.set_conversion_mode("ascii", "strict") + self.assertEqual(func("abc"), "abc") + self.assertEqual(func(u"abc"), "abc") + self.assertRaises(ctypes.ArgumentError, func, u"abä") + + def test_ascii_ignore(self): + ctypes.set_conversion_mode("ascii", "ignore") + self.assertEqual(func("abc"), "abc") + self.assertEqual(func(u"abc"), "abc") + self.assertEqual(func(u"äöüß"), "") + + def test_ascii_replace(self): + ctypes.set_conversion_mode("ascii", "replace") + self.assertEqual(func("abc"), "abc") + self.assertEqual(func(u"abc"), "abc") + self.assertEqual(func(u"äöüß"), "????") + + def test_buffers(self): + ctypes.set_conversion_mode("ascii", "strict") + buf = ctypes.create_string_buffer(u"abc") + self.assertEqual(len(buf), 3+1) + + ctypes.set_conversion_mode("ascii", "replace") + buf = ctypes.create_string_buffer(u"abäöü") + self.assertEqual(buf[:], "ab???\0") + self.assertEqual(buf[::], "ab???\0") + self.assertEqual(buf[::-1], "\0???ba") + self.assertEqual(buf[::2], "a??") + self.assertEqual(buf[6:5:-1], "") + + ctypes.set_conversion_mode("ascii", "ignore") + buf = ctypes.create_string_buffer(u"abäöü") + # is that correct? not sure. But with 'ignore', you get what you pay for.. + self.assertEqual(buf[:], "ab\0\0\0\0") + self.assertEqual(buf[::], "ab\0\0\0\0") + self.assertEqual(buf[::-1], "\0\0\0\0ba") + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_unicode.pyc b/lib/python2.7/ctypes/test/test_unicode.pyc new file mode 100644 index 0000000..647bbc1 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_unicode.pyc differ diff --git a/lib/python2.7/ctypes/test/test_unicode.pyo b/lib/python2.7/ctypes/test/test_unicode.pyo new file mode 100644 index 0000000..647bbc1 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_unicode.pyo differ diff --git a/lib/python2.7/ctypes/test/test_values.py b/lib/python2.7/ctypes/test/test_values.py new file mode 100644 index 0000000..4cbfd4b --- /dev/null +++ b/lib/python2.7/ctypes/test/test_values.py @@ -0,0 +1,82 @@ +""" +A testcase which accesses *values* in a dll. +""" + +import unittest +from ctypes import * + +import _ctypes_test + +class ValuesTestCase(unittest.TestCase): + + def test_an_integer(self): + ctdll = CDLL(_ctypes_test.__file__) + an_integer = c_int.in_dll(ctdll, "an_integer") + x = an_integer.value + self.assertEqual(x, ctdll.get_an_integer()) + an_integer.value *= 2 + self.assertEqual(x*2, ctdll.get_an_integer()) + + def test_undefined(self): + ctdll = CDLL(_ctypes_test.__file__) + self.assertRaises(ValueError, c_int.in_dll, ctdll, "Undefined_Symbol") + + class Win_ValuesTestCase(unittest.TestCase): + """This test only works when python itself is a dll/shared library""" + + def test_optimizeflag(self): + # This test accesses the Py_OptimizeFlag intger, which is + # exported by the Python dll. + + # It's value is set depending on the -O and -OO flags: + # if not given, it is 0 and __debug__ is 1. + # If -O is given, the flag is 1, for -OO it is 2. + # docstrings are also removed in the latter case. + opt = c_int.in_dll(pydll, "Py_OptimizeFlag").value + if __debug__: + self.assertEqual(opt, 0) + elif ValuesTestCase.__doc__ is not None: + self.assertEqual(opt, 1) + else: + self.assertEqual(opt, 2) + + def test_frozentable(self): + # Python exports a PyImport_FrozenModules symbol. This is a + # pointer to an array of struct _frozen entries. The end of the + # array is marked by an entry containing a NULL name and zero + # size. + + # In standard Python, this table contains a __hello__ + # module, and a __phello__ package containing a spam + # module. + class struct_frozen(Structure): + _fields_ = [("name", c_char_p), + ("code", POINTER(c_ubyte)), + ("size", c_int)] + FrozenTable = POINTER(struct_frozen) + + ft = FrozenTable.in_dll(pydll, "PyImport_FrozenModules") + # ft is a pointer to the struct_frozen entries: + items = [] + for entry in ft: + # This is dangerous. We *can* iterate over a pointer, but + # the loop will not terminate (maybe with an access + # violation;-) because the pointer instance has no size. + if entry.name is None: + break + items.append((entry.name, entry.size)) + import sys + if sys.version_info[:2] >= (2, 3): + expected = [("__hello__", 104), ("__phello__", -104), ("__phello__.spam", 104)] + else: + expected = [("__hello__", 100), ("__phello__", -100), ("__phello__.spam", 100)] + self.assertEqual(items, expected) + + from ctypes import _pointer_type_cache + del _pointer_type_cache[struct_frozen] + + def test_undefined(self): + self.assertRaises(ValueError, c_int.in_dll, pydll, "Undefined_Symbol") + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_values.pyc b/lib/python2.7/ctypes/test/test_values.pyc new file mode 100644 index 0000000..cbca9cb Binary files /dev/null and b/lib/python2.7/ctypes/test/test_values.pyc differ diff --git a/lib/python2.7/ctypes/test/test_values.pyo b/lib/python2.7/ctypes/test/test_values.pyo new file mode 100644 index 0000000..2ed3010 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_values.pyo differ diff --git a/lib/python2.7/ctypes/test/test_varsize_struct.py b/lib/python2.7/ctypes/test/test_varsize_struct.py new file mode 100644 index 0000000..f409500 --- /dev/null +++ b/lib/python2.7/ctypes/test/test_varsize_struct.py @@ -0,0 +1,50 @@ +from ctypes import * +import unittest + +class VarSizeTest(unittest.TestCase): + def test_resize(self): + class X(Structure): + _fields_ = [("item", c_int), + ("array", c_int * 1)] + + self.assertEqual(sizeof(X), sizeof(c_int) * 2) + x = X() + x.item = 42 + x.array[0] = 100 + self.assertEqual(sizeof(x), sizeof(c_int) * 2) + + # make room for one additional item + new_size = sizeof(X) + sizeof(c_int) * 1 + resize(x, new_size) + self.assertEqual(sizeof(x), new_size) + self.assertEqual((x.item, x.array[0]), (42, 100)) + + # make room for 10 additional items + new_size = sizeof(X) + sizeof(c_int) * 9 + resize(x, new_size) + self.assertEqual(sizeof(x), new_size) + self.assertEqual((x.item, x.array[0]), (42, 100)) + + # make room for one additional item + new_size = sizeof(X) + sizeof(c_int) * 1 + resize(x, new_size) + self.assertEqual(sizeof(x), new_size) + self.assertEqual((x.item, x.array[0]), (42, 100)) + + def test_array_invalid_length(self): + # cannot create arrays with non-positive size + self.assertRaises(ValueError, lambda: c_int * -1) + self.assertRaises(ValueError, lambda: c_int * -3) + + def test_zerosized_array(self): + array = (c_int * 0)() + # accessing elements of zero-sized arrays raise IndexError + self.assertRaises(IndexError, array.__setitem__, 0, None) + self.assertRaises(IndexError, array.__getitem__, 0) + self.assertRaises(IndexError, array.__setitem__, 1, None) + self.assertRaises(IndexError, array.__getitem__, 1) + self.assertRaises(IndexError, array.__setitem__, -1, None) + self.assertRaises(IndexError, array.__getitem__, -1) + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_varsize_struct.pyc b/lib/python2.7/ctypes/test/test_varsize_struct.pyc new file mode 100644 index 0000000..35d03ba Binary files /dev/null and b/lib/python2.7/ctypes/test/test_varsize_struct.pyc differ diff --git a/lib/python2.7/ctypes/test/test_varsize_struct.pyo b/lib/python2.7/ctypes/test/test_varsize_struct.pyo new file mode 100644 index 0000000..35d03ba Binary files /dev/null and b/lib/python2.7/ctypes/test/test_varsize_struct.pyo differ diff --git a/lib/python2.7/ctypes/test/test_win32.py b/lib/python2.7/ctypes/test/test_win32.py new file mode 100644 index 0000000..77e6fea --- /dev/null +++ b/lib/python2.7/ctypes/test/test_win32.py @@ -0,0 +1,93 @@ +# Windows specific tests + +from ctypes import * +from ctypes.test import is_resource_enabled +import unittest, sys +from test import test_support as support + +import _ctypes_test + +if sys.platform == "win32" and sizeof(c_void_p) == sizeof(c_int): + # Only windows 32-bit has different calling conventions. + + class WindowsTestCase(unittest.TestCase): + def test_callconv_1(self): + # Testing stdcall function + + IsWindow = windll.user32.IsWindow + # ValueError: Procedure probably called with not enough arguments (4 bytes missing) + self.assertRaises(ValueError, IsWindow) + + # This one should succeed... + self.assertEqual(0, IsWindow(0)) + + # ValueError: Procedure probably called with too many arguments (8 bytes in excess) + self.assertRaises(ValueError, IsWindow, 0, 0, 0) + + def test_callconv_2(self): + # Calling stdcall function as cdecl + + IsWindow = cdll.user32.IsWindow + + # ValueError: Procedure called with not enough arguments (4 bytes missing) + # or wrong calling convention + self.assertRaises(ValueError, IsWindow, None) + +if sys.platform == "win32": + class FunctionCallTestCase(unittest.TestCase): + + if is_resource_enabled("SEH"): + def test_SEH(self): + # Call functions with invalid arguments, and make sure + # that access violations are trapped and raise an + # exception. + self.assertRaises(WindowsError, windll.kernel32.GetModuleHandleA, 32) + + def test_noargs(self): + # This is a special case on win32 x64 + windll.user32.GetDesktopWindow() + + class TestWintypes(unittest.TestCase): + def test_HWND(self): + from ctypes import wintypes + self.assertEqual(sizeof(wintypes.HWND), sizeof(c_void_p)) + + def test_PARAM(self): + from ctypes import wintypes + self.assertEqual(sizeof(wintypes.WPARAM), + sizeof(c_void_p)) + self.assertEqual(sizeof(wintypes.LPARAM), + sizeof(c_void_p)) + + def test_COMError(self): + from _ctypes import COMError + if support.HAVE_DOCSTRINGS: + self.assertEqual(COMError.__doc__, + "Raised when a COM method call failed.") + + ex = COMError(-1, "text", ("details",)) + self.assertEqual(ex.hresult, -1) + self.assertEqual(ex.text, "text") + self.assertEqual(ex.details, ("details",)) + +class Structures(unittest.TestCase): + + def test_struct_by_value(self): + class POINT(Structure): + _fields_ = [("x", c_long), + ("y", c_long)] + + class RECT(Structure): + _fields_ = [("left", c_long), + ("top", c_long), + ("right", c_long), + ("bottom", c_long)] + + dll = CDLL(_ctypes_test.__file__) + + pt = POINT(10, 10) + rect = RECT(0, 0, 20, 20) + self.assertEqual(1, dll.PointInRect(byref(rect), pt)) + +if __name__ == '__main__': + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_win32.pyc b/lib/python2.7/ctypes/test/test_win32.pyc new file mode 100644 index 0000000..ce54572 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_win32.pyc differ diff --git a/lib/python2.7/ctypes/test/test_win32.pyo b/lib/python2.7/ctypes/test/test_win32.pyo new file mode 100644 index 0000000..ce54572 Binary files /dev/null and b/lib/python2.7/ctypes/test/test_win32.pyo differ diff --git a/lib/python2.7/ctypes/test/test_wintypes.py b/lib/python2.7/ctypes/test/test_wintypes.py new file mode 100644 index 0000000..806fcce --- /dev/null +++ b/lib/python2.7/ctypes/test/test_wintypes.py @@ -0,0 +1,43 @@ +import sys +import unittest + +if not sys.platform.startswith('win'): + raise unittest.SkipTest('Windows-only test') + +from ctypes import * +from ctypes import wintypes + +class WinTypesTest(unittest.TestCase): + def test_variant_bool(self): + # reads 16-bits from memory, anything non-zero is True + for true_value in (1, 32767, 32768, 65535, 65537): + true = POINTER(c_int16)(c_int16(true_value)) + value = cast(true, POINTER(wintypes.VARIANT_BOOL)) + self.assertEqual(repr(value.contents), 'VARIANT_BOOL(True)') + + vb = wintypes.VARIANT_BOOL() + self.assertIs(vb.value, False) + vb.value = True + self.assertIs(vb.value, True) + vb.value = true_value + self.assertIs(vb.value, True) + + for false_value in (0, 65536, 262144, 2**33): + false = POINTER(c_int16)(c_int16(false_value)) + value = cast(false, POINTER(wintypes.VARIANT_BOOL)) + self.assertEqual(repr(value.contents), 'VARIANT_BOOL(False)') + + # allow any bool conversion on assignment to value + for set_value in (65536, 262144, 2**33): + vb = wintypes.VARIANT_BOOL() + vb.value = set_value + self.assertIs(vb.value, True) + + vb = wintypes.VARIANT_BOOL() + vb.value = [2, 3] + self.assertIs(vb.value, True) + vb.value = [] + self.assertIs(vb.value, False) + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python2.7/ctypes/test/test_wintypes.pyc b/lib/python2.7/ctypes/test/test_wintypes.pyc new file mode 100644 index 0000000..406461d Binary files /dev/null and b/lib/python2.7/ctypes/test/test_wintypes.pyc differ diff --git a/lib/python2.7/ctypes/test/test_wintypes.pyo b/lib/python2.7/ctypes/test/test_wintypes.pyo new file mode 100644 index 0000000..406461d Binary files /dev/null and b/lib/python2.7/ctypes/test/test_wintypes.pyo differ diff --git a/lib/python2.7/ctypes/util.py b/lib/python2.7/ctypes/util.py new file mode 100644 index 0000000..f98087f --- /dev/null +++ b/lib/python2.7/ctypes/util.py @@ -0,0 +1,290 @@ +###################################################################### +# This file should be kept compatible with Python 2.3, see PEP 291. # +###################################################################### +import sys, os + +# find_library(name) returns the pathname of a library, or None. +if os.name == "nt": + + def _get_build_version(): + #*********************************************************** + # NOTE: As example for GCC(mingw) build sys.version return: + # '2.7a0 (trunk:M, ,