[ctypes-commit] ctypes winssh.txt,1.1,1.2 test-cf.py,1.1,1.2 setup.py,1.128,1.129 ctypes-dev.el,1.2,
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2006-03-03 20:08:10
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3363 Added Files: winssh.txt test-cf.py setup.py ctypes-dev.el README.txt README.CVS NEWS.txt MANIFEST.in LICENSE.txt ChangeLog ANNOUNCE ACKS .cvsignore Log Message: Moving files from branch_1_0 to HEAD. --- NEW FILE: .cvsignore --- *.c *.h *.ilk *.log *.pdb *.pyc *.pyo *.tlb *.zip MANIFEST _ctypes.pyd _ctypes_d.pyd archive build dist extensions test.output comtypes --- NEW FILE: ctypes-dev.el --- ;; In the ~/init.el file, write: ;; (setq load-path (cons "c:\\sf\\ctypes" load-path) ;; (require 'ctypes-dev) ;; ;; Try M-x customize-group ctypes-dev ;; ;; Based on twisted-dev.el (provide 'ctypes-dev) (defgroup ctypes-dev nil "Various ctypes development utilities" :group 'development) (defcustom ctypes-dev-directory "c:\\sf\\ctypes_dist" "ctypes root directory" :group 'ctypes-dev :type 'string) (setenv "PYTHONPATH" ctypes-dev-directory) (defmacro with-cd (dirname &rest code) `(let ((old-dirname default-directory) (start-buffer (current-buffer))) (cd ,dirname) (unwind-protect (progn ,@code) (let ((end-buffer (current-buffer))) ;; (cd ,dirname) (set-buffer start-buffer) (cd old-dirname) (set-buffer end-buffer))))) (defun ctypes-dev-build () (interactive) (with-cd ctypes-dev-directory (compile "python setup.py build"))) (defun ctypes-dev-build-debug () (interactive) (with-cd ctypes-dev-directory (compile "py_d setup.py build -g"))) (defun ctypes-dev-rebuild () (interactive) (with-cd ctypes-dev-directory (compile "python setup.py build -f"))) (defun ctypes-dev-test () (interactive) (with-cd (concat ctypes-dev-directory "\\unittests") (compile "python runtests.py"))) (defun ctypes-dev-test-debug () (interactive) (with-cd (concat ctypes-dev-directory "\\unittests") (compile "py_d runtests.py"))) (defun comtypes-test () (interactive) (with-cd (concat ctypes-dev-directory "\\comtypes\\unittests") (compile "python runtests.py"))) (defun comtypes-test-debug () (interactive) (with-cd (concat ctypes-dev-directory "\\comtypes\\unittests") (compile "py_d runtests.py"))) (define-minor-mode ctypes-dev-mode "Toggle ctypes-dev mode. With no argument, this command toggles the mode. Non-null prefix argument turns on the mode. Null prefix argument turns off the mode." ;; The initial value. nil ;; The indicator for the mode line. " ctypes" ;; The minor mode bindings. '( ;; ([f6] . ctypes-dev-genapidoc) ;; ([f7] . ctypes-dev-gendoc) ('(shift f8) . ctypes-dev-build-debug) ([f8] . ctypes-dev-build) ('(shift f9) . ctypes-dev-test-debug) ([f9] . ctypes-dev-test) ([f10] . comtypes-test) ('(shift f10) . comtypes-test-debug) ;; ([f11] . ctypes-dev-grep) ;; ([f12] . ctypes-dev-gendocs) )) (add-hook 'find-file-hooks (lambda () (let ((full-ctypes-path (expand-file-name ctypes-dev-directory))) (if (> (length (buffer-file-name)) (length full-ctypes-path)) (if (string= (substring (buffer-file-name) 0 (length full-ctypes-path)) full-ctypes-path) (ctypes-dev-mode) ))))) ;(add-hook ; 'python-mode-hook ; (lambda () ; (ctypes-dev-mode t))) --- NEW FILE: winssh.txt --- This file was originally here: http://www.python.org/dev/winssh.txt I grabbed it before it was removed (Python core development doesn't use CVS anymore, but other projects do!). Thomas Heller, 11/2005 Setting up a cmdline CVS to work with SourceForge under Windows --------------------------------------------------------------- 28-Jun-2000 Original by Andy Robinson (an...@re...) 03-Jul-2000 Modified by Tim Peters (ti...@ms...) 16-Aug-2000 Modified by Riaan Booysen (riaan@e.co.za) 25-Aug-2000 Modified by Tim Peters (ti...@ms...) 1. Get ftp.reportlab.com/tools/cvs-1.10-win.zip ftp.reportlab.com/tools/ssh-1.2.14-win32bin.zip (copied from somewhere obscure for safety, I forget where) 2. Unzip these to a location on your path. Type 'cvs' and 'ssh' from somewhere else to verify. 3. Choose where to keep your CVS projects; let's assume C:\Code 4. Create a subdirectory C:\Code\.ssh (yes, dot-ssh) 5. (see #8 for an alternative) Create two environment variables: HOME=C:\Code CVS_RSH=ssh HOME must point to the directory above your .ssh directory. On Win9x, this can be done in a batch file or autoexec.bat; e.g., set HOME=c:\Code set CVS_RSH=ssh Run the batch file, or reboot if you're using autoexec.bat. On NT or 2000, go to Control Panel | System | Environment and set them at either user or machine level. 6. If not done so, get a Sourceforge account and a project you can log in to. 7. OPTIONAL (& if you skip this now, you can do it later if you change your mind). If you want to avoid typing in your SourceForge password before every CVS operation, generate the ssh public and private identity keys like this: ssh-keygen -C $KEY -f C:\Code\.ssh\identity where $KEY is just some identifier (like your name or email address; this is not used for authentication, it's just stored in the public identity file as a reminder to you why you created this key). Note that you must use -f! ssh-keygen fails to work without it on Windows. When asked for a passphrase, security experts will tell you to choose a long and hard-to-guess string. But then you have to type *that* all the time instead of your SourceForge password. If you just hit ENTER (leave the passphrase empty), you won't be bothered with SourceForge passwords or ssh passphrases again. This is a security tradeoff only you can make. If in doubt, ChOOzAl0Ng&HaRDtoGUessSTr1Ng. ssh-keygen creates two files under .ssh\: identity This is your private key, and is a binary file. NEVER reveal it to anyone. Do NOT share your .ssh directory across a network either. The scheme is only as secure as this file. identity.pub This is your public key, a text file, full of lots of digits and the mnemonic $KEY you gave to ssh-keygen. This file can be shared freely, and indeed must be shared for the scheme to be of any use. On your SourceForge account page, in the 'Shell Account Information' section click the [Edit Keys] link. Copy/paste the contents of the generated identity.pub file as one line into the Authorized Keys text box. After the next cron job (max 6 hours) your information should be updated. 8. Teach SSH about your project's home, by doing ssh -l $USERNAME $MYPROJECT.sourceforge.net where $USERNAME is your SourceForge login name and $MYPROJECT your SourceForge project name. You'll see Host "$MYPROJECT.sourceforge.net" added to the list of known hosts. and then Creating random seed file ~/.ssh/random_seed This may take a while. After a while it will prompt for a password. Type your SourceForge password and hit ENTER. After some SourceForge msgs scroll by, you'll be left at a SourceForge shell prompt. Type exit and hit ENTER. Now you're back at the DOS prompt. 9. You will need either a lengthy command line or a batch file for each sourceforge project. I set cvsroot in a batch file in my 'c:\code' directory, and have one such file for each CVS project I use (about ten of them!): set CVSROOT=:ext:$USERNAME@cvs.$MYPROJECT.sourceforge.net:/cvsroot/$DIRNAME where $USERNAME and $MYPROJECT are again your SourceForge login and project names, and $DIRNAME is the top-level directory in the SourceForge CVS tree; a project can have several, but usually there is just one. Note: you can keep HOME and CVS_RSH out of your permanent environment (see #5) by adding those definitions to this batch file instead. 10. Execute this batch file. You can now go to C:\Code and do cvs -z7 checkout $MYPROJECT (z7 means 'compress network traffic', handy over dialup lines) 11. From now on, just use CVS normally, running this batch file first each time you bring up a DOS box you're going to use for CVS work. Note: If you did not follow step 7, you'll be asked for your password each time you enter a CVS command. I wouldn't survive without Karl Fogel's book "Open Source Development with CVS", Coriolis Press. The CVS reference material (about 225 printed pages!) from this book is available for free download from http://cvsbook.red-bean.com/ Footnote: for anonymous checkout, I think you just omit the 'my_user_name@' part from the CVSROOT variable. I hope this helps; let me know if people have any problems with the instructions. - Andy Robinson ReportLab --- NEW FILE: ChangeLog --- 2006-03-03 Thomas Heller <th...@py...> * ctypes/__init__.py, ctypes/test/test_sizes.py: Added c_int8, c_int16, c_int32, c_int64, c_uint8, c_uint16, c_uint32, c_uint64 types. Patch and unittest provided by Joe Wreschnig. * (Repository): Removed the codegenerator in ctypes/wrap completely. The last state has been tagged in CVS as 'BEFORE_REMOVAL'. It will be revived later - not yet sure where. * Changed the version number to 0.9.9.4. 2006-03-01 Thomas Heller <th...@py...> * (Repository): Removed the samples subdirectory completely, because it has become out of sync. * (Repository): Moved the ctypes.wintypes module into the ctypes/ directory, got rid of the platform specific modules magic in setup.py [...1096 lines suppressed...] no two conversions take place. This is now used by SimpleType_from_param(), byref(), and Pointer_as_parameter(), and is understood by ConvParam(). In the long run this should be the only thing (besides primitive Python data types with trivial conversions) used by ConvParam(). Also ConvParam should probably *return* these things. 2003-01-17 Thomas Heller <th...@py...> * source/_ctypes.c: Rewrite of SimpleType_from_param complete. unittests/test_parameters.py shows that it does the right things in most cases. * (Repository): Moved everything from local CVS to the SF repository, and restructured the directories. --- NEW FILE: MANIFEST.in --- # standard files include ACKS ANNOUNCE ChangeLog MANIFEST MANIFEST.in LICENSE.txt NEWS.txt README* # support files for development include ctypes-dev.el include ctypes/.CTYPES_DEVEL include setup.py include test-cf.py include setup.cfg # libffi build files include source/libffi/aclocal.m4 include source/libffi/config.guess include source/libffi/config.sub include source/libffi/configure include source/libffi/configure.ac include source/libffi/fficonfig.h.in include source/libffi/fficonfig.py.in include source/libffi/install-sh include source/libffi/LICENSE include source/libffi/README # all source files recursive-include source *.c *.h *.S *.asm *.in # windows CE project files include wince/_ctypes.vcw wince/_ctypes.vcp wince/_ctypes_test.vcp # docs/manual include docs/manual/*.txt include docs/manual/*.html --- NEW FILE: NEWS.txt --- ctypes News - http://starship.python.net/crew/theller/ctypes.html Changes in 0.9.1 ================ ctypes 0.9.1 should be fully compatible again with Gary Bishop's readline module which is also used by IPython. ctypes changes The internal conversions that ctypes does between unicode and strings can now use a specified encoding and error handling. A set_conversion_mode() function allows to set them, it returns the previous values. The inital values are ('mbcs', 'ignore') on Windows, and ('ascii', 'strict') on other systems. When internal processing of an argument for a function call fails, the new ctypes.ArgumentError is raised. CDLL and its subclasses now accept an optional second handle parameter. If this is supplied, it is used instead of calling LoadLibrary() or dlopen() to get one. Sometimes objects have been freed too early when calling functions where argtypes have been set. Fixed the create_unicode_buffer function - it was returning c_char arrays instead of c_wchar arrays. Both create_string_buffer and create_unicode_buffer can now be called with string and unicode instances, they will do the needed conversions themselves. ctypes now allows calling Python C api functions. The 'pythonapi' symbol should be used to access these functions, this will automatically use the correct calling convention and exception handling. The 'py_object' type is the ctypes variant of 'PyObject *'. This feature should also work if you are using a static python build. It is now possible to call cdecl functions with more arguments than the length of the argtypes sequence specifies - this allows to provide functions like sprintf() with a proper prototype. It is now possible to create strings or unicode strings if you have the integer address by calling c_char_p(address) or c_wchar_p(address). Integers can also be assigned to structure fields of type c_char_p and c_wchar_p. c_char_p and c_wchar_p both accept strings and unicode strings - if needed they are encoded or decoded using 'strict' error handling. The _ctypes.call_function function, although private and deprecated, has been put back in - it is used by Gary Bishop's readline module. Array and pointer instances now support slicing, for pointers only getslice is implemented (setslice is too dangerous, probably). Slices are represented as lists of the elements, except for character and unicode character pointer and arrays, where strings resp. unicode strings are used instead. On windows, the include files were missing from the source distribution. The alignment function was not exported by the ctypes module. It returns the alignment requirements in bytes of a type or instance. ctypes.com changes Applied a patch from Bruce Dodson which fixes an infinite loop in readtlb.py if a typelib references types defined in another typelib. readtlb still generates bad code for such cases, but the results could be edited by hand if the dependencies can be sorted out. ctypes now caches the types that WINFUNCTYPE and CFUNCTYPE creates, to avoid unneeeded creation of classes. This makes importing files containing a lot of COM interfaces (like the ones that the readtlb tool generates) a lot (10 x) faster. COM servers now print a short usage message when they are run without the /regserver or /unregserver flag. VARIANT does now handle the COM DATE type (VT_DATE) as Python datetime. VARIANT now handles integers and longs correctly - if longs are too large they are stored as doubles (VT_R8). Integers are now stored as VT_I4 instead of VT_INT. Cache the types that WINFUNCTYPE and CFUNCTYPE creates, to avoid creation of a lot of similar classes. Rearrange the code to use try:except: instead of dict.get(xxx, None), the former is faster if lookup mostly succeeds - as is the case for POINTER imo. This makes importing large COM files created by readtlb a lot faster, since WINFUNCTYPE is called for every COM method. The python wrapper for mshtml.tlb, which contains nearly 600 interfaces, now imports in 3 seconds instead of 40! Array and POINTER instance now support slicing, for POINTER only getslice is implemented (setslice is too dangerous, probably). Slices are accepted or returned as lists of the elements, except for character and unicode character pointer and arrays, where strings resp. unicode strings are used - much more convenient. Changes in 0.9.0 ================ ctypes now requires Python 2.3 or higher, Python 2.2 is no longer supported. The big change is that ctypes now uses the same code base on all platforms, many, many bug should have been fixed this way on non-windows systems. The destribution now contains libffi, no need to find, download, build and install a compatible version. There have been lots of improvements and additions both to ctypes itself, and to the ctypes.com windows framework, too many to remember now and document here. Most prominent additions to ctypes.com are: A ctypes.com.client module supporting dynamic dispatch An internet explorer toolband sample Many improvements to the stoplite sample Other Versions: no news recorded in this file! Please see the CVS commit messages. Version 0.4.0, 2003-02-07: This an intermediate release, there is still a lot to be done. Changes: ctypes works with Python 2.2 and Python 2.3 now. Structure and Union fields have now readonly .size and .offset properties, see the docs. POINTER instances can now be indexed as if they point to arrays of objects instead of only a single object. CFunction instances now have a .from_param class method. (This is the protocol which allows to validate and convert function call arguments from Python to C - in other words, you can now use a CFunction subclass in the argtype attribute for a function from a DLL to specify the type of the callback function. Does anyone understand this?) Argument conversion from Python to C is somewhat faster now. I added a lot of unittests, which not only check for bugs, but also 'describe the current behaviour'. Unittest rocks! Lots and lots of bugs and potential crashes have been fixed: Alignment and sizes of structures and unions is now correct as far as I can see. Assigning Python numbers to mutable integer types (c_short, c_int, c_long and so on) now correctly checks for valid range, you can no longer assign a negative Python number to an unsigned C data type for example. General News: I moved the sources from local CVS to SourceForge CVS repository. Version 0.3.5, 2003-01-14: Runs under linux now, and hopefully also other systems where libffi works. More changes, like enabling the Python garbage collector on CFunction objects. Version 0.2.0, 2002-11-12: Allows to assign callables to functions' restype attribute. Refactored _CallProc, for much clearer and less buggy code. Plugged some gross memory leaks. License is MIT, not BSD. --- NEW FILE: ACKS --- Acknowledgements ---------------- This list is probably incomplete, but I would like to thank everybody who contributed code, patches, bug reports, encouragement, ... Apologies if I have forgotten anyone. -- Thomas Heller ---------------- Nick Adams Robin Becker Dave Brueck Hye-Shik Chang Greg Chapman David Creemer Andreas Daegert Bruce Dodson Luke Dunstan Chuck Esterbrook Mike Fletcher David Foster Richie Hindle Shane Holloway Andrew MacIntyre Paul Moore Ronald Oussoren Henk Punt Jimmy Retzlaff Just van Rossum Alexander Semenov Wolfgang Strobl Niki Spahiev --- NEW FILE: test-cf.py --- # Script to build and test ctypes on the compile-farm servers. # Accepts the same arguments as setup.py hostinfo = [ # Not python 2.3 or newer: ## ("x86-openbsd1", "/usr/local/bin/python -u"), ("x86-solaris1", "env PATH=/opt/SUNWspro/bin:/usr/local/bin:/usr/local/sbin:$PATH python -u"), ("x86-linux1", "/usr/bin/python -u"), ("x86-linux2", "/usr/bin/python -u"), # Host key verification failed ("x86-freebsd1", "/usr/local/bin/python -u"), # ImportError: _ctypes.so: Undefined PLT symbol "PyGILState_Ensure" # Python without threading module??? ("x86-netbsd1", "/usr/pkg/bin/python2.3 -u"), ("amd64-linux1", "/usr/bin/python -u"), # Same platform as the previous one: ## ("amd64-linux2", "/usr/bin/python -u"), # Host key verification failed ("alpha-linux1", "/usr/bin/python -u"), # No route to host: ("ppc-osx1", "/sw/bin/python -u"), # No route to host: ("ppc-osx2", "/usr/bin/python -u"), # Not python 2.3 or newer: ## ("sparc-solaris1", "/usr/local/bin/python -u"), ## ("sparc-solaris2", "/usr/local/bin/python -u"), ("openpower-linux1", "python -u")] import sys, os for hostname, python in hostinfo: print "*" * 20, hostname, "*" * 20 if len(sys.argv) > 1: cmd = "cd ~/ctypes; %s setup.py %s" % (python, " ".join(sys.argv[1:])) else: cmd = "cd ~/ctypes; %s setup.py -q build_ext -f test -v " % python print cmd ret = os.system('ssh -l theller cf-shell.sf.net "ssh %s \'%s\'"' % (hostname, cmd)) if ret: print "(RETCODE %s)" % ret print "-" * 50 print --- NEW FILE: README.CVS --- I added support to run ctypes from a CVS sandbox without the need to install the package. This even works for different Python versions on the same machine. This behaviour is triggered by the presence of a .CTYPE_DEVEL file in the ctypes package directory. Just do a 'setup.py build' and insert the top-level directory into sys.path (with setting the PYTHONPATH env variable, with a .pth file, or however), and it should work. --- NEW FILE: ANNOUNCE --- ctypes 0.9.9.3 released - Feb 15, 2006 ====================================== Overview ctypes is an advanced ffi (Foreign Function Interface) package for Python 2.3 and higher. ctypes allows to call functions exposed from dlls/shared libraries and has extensive facilities to create, access and manipulate simple and complicated C data types in Python - in other words: wrap libraries in pure Python. It is even possible to implement C callback functions in pure Python. ctypes includes a code generator toolchain which allows automatic creation of library wrappers from C header files. This feature is still experimental and beta quality. ctypes runs on Windows, Windows CE, MacOS X, Linux, Solaris, FreeBSD, OpenBSD. It may also run on other systems, provided that libffi supports this platform. Important If you download the source distribution, please choose the ZIP file for Windows, and the .tar.gz file for other machines. These archive have different contents! There have been lots of changes - if you are the author or user of a package that uses ctypes, please test it with this release and report problems on the ctypes-users mailing list. Changes in 0.9.9.3 (These are the most important changes, see the ChangeLog for complete details) Windows The ctypes.com package is no longer included and supported. It is replaced by the comtypes package which will be released separately. ctypes has been ported to Windows CE by Luke Dunstan. Other platforms Hye-Shik Chang has written a new build system for libffi which should remove possible licensing issues. All platforms The library loading code has been rewritten by Andreas Degert, there are now sophisticated methods to find shared libraries. On OS X, this uses files from Bob Ippolito's macholib. See the manual for details. Finally I started to write the manual, it is available online: http://tinyurl.com/7bpg4 New 'errcheck' protocol to check the return values of foreign functions, suggested by Mike Fletcher. Lots of bug fixes, especially for 64-bit platforms. Improved performance when creating ctypes instances. Subclasses of simple types (c_int, c_void_p, and so on) now behave as expected - they are not automatically converted into native Python types any longer. Support for explicit byte ordering in structures has been added (BigEndianStructure, LittleEndianStructure base classes). call byref() automatically, if needed, for POINTER types in argtypes. Lots of improvements to the code generator. Changes in 0.9.6 Thanks to all of you who reported bugs so quickly, and those who tried out the codegenerator toolchain. Bug fixes: - keyword arguments in Structure/Union initializers had no effect. - it was impossible to override the from_parm class method in subclasses of c_void_p, c_char_p, and c_wchar_p. - removed the __del__ method of _CDLL. It caused uncollectable garbage in Python's gc. - ctypes.com.register: enclose the Python script to run a com server in quotes, otherwise it won't run correctly when the directory name contains spaces. Enhancements: - Several changes have been made to the h2xml script from the codegenerator toolchain. See the documentation (linked below) for details. Additions in 0.9.5 New package ctypes.wrap. This contains decorators usable for easier creation of wrapper functions. This package also contains a toolchain for (semi)automatic creation of wrappers for external libraries - it can parse C header files and generate ctypes code for the declarations in them. It can even handle preprocessor definitions! For details, see http://starship.python.net/crew/theller/ctypes/codegen.html Changes in 0.9.5 On systems where sizeof(int) == sizeof(long), c_int/c_long and c_uint/c_ulong are now aliases. Similar for c_long/c_longlong and c_ulong/c_ulonglong. This prevents unneeded type errors. If an exception occurs in a callback function, a full traceback is now printed. Raising SystemExit in a callback function now correctly exists Python. HRESULT is now a proper ctype - no longer a function. This allows to use it in the argtypes sequence for function prototypes. An easier way to define structures and unions that reference themselves, or have dependencies to other data types. The _fields_ attribute can now be set *after* the Structure/Union class has been created. This makes the SetPointerType function obsolete. The semantics of the _fields_ attribute in sub-subclasses of Structure and Union has been fixed. The baseclasses _fields_ list is extended, not replaced, in subclasses. Assigning _fields_ when it is no longer possible raises an error now. Structures and unions now work as restype and in the argtypes list for functions. An important bug has been fixed with pointers. Detailed changelog is in CVS: <http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ChangeLog?rev=1.86.2.39> Download Downloads are available in the sourceforge files section <http://sourceforge.net/project/showfiles.php?group_id=71702> Separate source distributions are available for windows and non-windows systems. Please use the .zip file for Windows and Windows CE, and use the .tar.gz file for non-Windows systems (it contains the complete cross-platform libffi sources). Binary windows installers, which contain compiled extension modules, are also available, be sure to download the correct one for the Python version you are using. Homepage <http://starship.python.net/crew/theller/ctypes/> Enjoy, Thomas --- NEW FILE: setup.py --- #!/usr/bin/env python # # $Id: setup.py,v 1.129 2006/03/03 20:07:59 theller Exp $ # # """ctypes is a Python package to create and manipulate C data types in Python, and to call functions in dynamic link libraries/shared dlls. It allows wrapping these libraries in pure Python. """ LIBFFI_SOURCES='source/libffi' __version__ = "0.9.9.4" ################################################################ ##from ez_setup import use_setuptools ##use_setuptools() import os, sys if sys.version_info < (2, 3): raise Exception, "ctypes %s requires Python 2.3 or better" % __version__ from distutils.core import setup, Extension, Command import distutils.core from distutils.errors import DistutilsOptionError from distutils.command import build_py, build_ext, clean from distutils.command import install_data from distutils.dir_util import mkpath from distutils.util import get_platform ################################################################ # Manipulate the environment for the build process. # if get_platform() in ["solaris-2.9-sun4u", "linux-x86_64"]: os.environ["CFLAGS"] = "-fPIC" ################################################################ # Additional and overridden distutils commands # class test(Command): # Original version of this class posted # by Berthold Hoellmann to dis...@py... description = "run tests" user_options = [ ('tests=', 't', "comma-separated list of packages that contain test modules"), ('use-resources=', 'u', "resources to use - resource names are defined by tests"), ('refcounts', 'r', "repeat tests to search for refcount leaks (requires 'sys.gettotalrefcount')"), ] boolean_options = ["refcounts"] def initialize_options(self): self.build_base = 'build' self.use_resources = "" self.refcounts = False if sys.platform == "win32": self.tests = "ctypes.test,comtypes.test" else: self.tests = "ctypes.test" # initialize_options() def finalize_options(self): if self.refcounts and not hasattr(sys, "gettotalrefcount"): raise DistutilsOptionError("refcount option requires Python debug build") self.tests = self.tests.split(",") self.use_resources = self.use_resources.split(",") # finalize_options() def run(self): self.run_command('build') import ctypes.test ctypes.test.use_resources.extend(self.use_resources) for name in self.tests: package = __import__(name, globals(), locals(), ['*']) print "Testing package", name ctypes.test.run_tests(package, "test_*.py", self.verbose, self.refcounts) # run() # class test class my_build_py(build_py.build_py): def find_package_modules (self, package, package_dir): """We extend distutils' build_py.find_package_modules() method to include all modules found in the platform specific root package directory into the 'ctypes' root package.""" import glob, sys result = build_py.build_py.find_package_modules(self, package, package_dir) if package == 'ctypes': for pathname in glob.glob(os.path.join(sys.platform, "*.py")): modname = os.path.splitext(os.path.basename(pathname))[0] result.append(('ctypes', modname, pathname)) return result def find_file_in_subdir(dirname, filename): # if <filename> is in <dirname> or any subdirectory thereof, # return the directory name, else None for d, _, names in os.walk(dirname): if filename in names: return d return None class my_build_ext(build_ext.build_ext): def finalize_options(self): if self.debug is None: import imp self.debug = ('_d.pyd', 'rb', imp.C_EXTENSION) in imp.get_suffixes() build_ext.build_ext.finalize_options(self) # First configure a libffi library, then build the _ctypes extension. def build_extensions(self): self.configure_libffi() # Add .S (preprocessed assembly) to C compiler source extensions. self.compiler.src_extensions.append('.S') build_ext.build_ext.build_extensions(self) def fix_extension(self, ffi_dir): fficonfigfile = os.path.join(ffi_dir, 'fficonfig.py') if not os.path.exists(fficonfigfile): return 0 incdir = find_file_in_subdir(os.path.join(ffi_dir, "include"), "ffi.h") if not incdir: return 0 incdir_2 = find_file_in_subdir(ffi_dir, "fficonfig.h") if not incdir_2: return 0 fficonfig = {} execfile(fficonfigfile, globals(), fficonfig) srcdir = os.path.join(fficonfig['ffi_srcdir'], 'src') for ext in self.extensions: if ext.name == "_ctypes": ext.include_dirs.append(incdir) ext.include_dirs.append(incdir_2) ext.include_dirs.append(srcdir) ext.sources.extend(fficonfig['ffi_sources']) if fficonfig['ffi_cflags'].strip(): ext.extra_compile_args.extend( fficonfig['ffi_cflags'].split()) return 1 def configure_libffi(self): if sys.platform == "win32": return if LIBFFI_SOURCES == None: return src_dir = os.path.abspath(LIBFFI_SOURCES) # Building libffi in a path containing spaces doesn't work: self.build_temp = self.build_temp.replace(" ", "") build_dir = os.path.join(self.build_temp, 'libffi') if not self.force and self.fix_extension(build_dir): return mkpath(build_dir) config_args = [] # Pass empty CFLAGS because we'll just append the resulting CFLAGS # to Python's; -g or -O2 is to be avoided. cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \ % (build_dir, src_dir, " ".join(config_args)) print 'Configuring static FFI library:' print cmd res = os.system(cmd) if res: print "Failed" sys.exit(res) assert self.fix_extension(build_dir), "Could not find libffi after building it" # Since we mangle the build_temp dir, we must also do this in the clean command. class my_clean(clean.clean): def run(self): self.build_temp = self.build_temp.replace(" ", "") clean.clean.run(self) class my_install_data(install_data.install_data): """A custom install_data command, which will install it's files into the standard directories (normally lib/site-packages). """ def finalize_options(self): if self.install_dir is None: installobj = self.distribution.get_command_obj('install') self.install_dir = installobj.install_lib print 'Installing data files to %s' % self.install_dir install_data.install_data.finalize_options(self) ################################################################ # Specify the _ctypes extension # kw = {} # common source files kw["sources"] = ["source/_ctypes.c", "source/callbacks.c", "source/callproc.c", "source/stgdict.c", "source/cfield.c", "source/malloc_closure.c"] # common header file kw["depends"] = ["source/ctypes.h"] if sys.platform == "win32": kw["sources"].extend([ # types.c is no longer needed, ffi_type defs are in cfield.c "source/libffi_msvc/ffi.c", "source/libffi_msvc/prep_cif.c", "source/libffi_msvc/win32.c", ]) extensions = [Extension("_ctypes", export_symbols=["DllGetClassObject,PRIVATE", "DllCanUnloadNow,PRIVATE"], libraries=["ole32", "user32", "oleaut32"], include_dirs=["source/libffi_msvc"], **kw), Extension("_ctypes_test", libraries=["oleaut32", "user32"], sources=["source/_ctypes_test.c"], include_dirs=["source/libffi_msvc"], ) ] if kw.has_key("depends"): kw["depends"].extend(["source/libffi_msvc/ffi.h", "source/libffi_msvc/fficonfig.h", "source/libffi_msvc/ffitarget.h", "source/libffi_msvc/ffi_common.h"]) else: include_dirs = [] library_dirs = [] extra_link_args = [] if sys.platform == "darwin": kw["sources"].append("source/darwin/dlfcn_simple.c") extra_link_args.extend(['-read_only_relocs', 'warning']) include_dirs.append("source/darwin") elif sys.platform == "sunos5": extra_link_args.extend(['-mimpure-text']) extensions = [Extension("_ctypes", include_dirs=include_dirs, library_dirs=library_dirs, extra_link_args=extra_link_args, **kw), Extension("_ctypes_test", sources=["source/_ctypes_test.c"]) ] ################################################################ # the ctypes package # packages = ["ctypes", "ctypes.macholib", "ctypes.test"] ################################################################ # pypi classifiers # classifiers = [ 'Development Status :: 4 - Beta', 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', 'Programming Language :: C', 'Programming Language :: Python', 'Topic :: Software Development :: Libraries :: Python Modules', ] ################################################################ # main section # ##from ce import ce_install_lib if __name__ == '__main__': setup(name="ctypes", ## entry_points = {"console_scripts" : ["xml2py = ctypes.wrap.xml2py:main", ## "h2xml = ctypes.wrap.h2xml:main"]}, ext_modules = extensions, packages = packages, classifiers = classifiers, version=__version__, description="create and manipulate C data types in Python, call functions in shared libraries", long_description = __doc__, author="Thomas Heller", author_email="th...@py...", license="MIT License", url="http://starship.python.net/crew/theller/ctypes.html", platforms=["windows", "Linux", "MacOS X", "Solaris", "FreeBSD"], cmdclass = {'test': test, 'build_py': my_build_py, 'build_ext': my_build_ext, 'clean': my_clean, 'install_data': my_install_data, ## 'ce_install_lib': ce_install_lib }, ) ## Local Variables: ## compile-command: "python setup.py build" ## End: --- NEW FILE: LICENSE.txt --- Copyright (c) 2000, 2001, 2002, 2003, 2004 Thomas Heller Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --- NEW FILE: README.txt --- Overview ctypes is a ffi (Foreign Function Interface) package for Python. It allows to call functions exposed from dlls/shared libraries and has extensive facilities to create, access and manipulate simpole and complicated C data types transparently from Python - in other words: wrap libraries in pure Python. ctypes runs on Windows, MacOS X, Linux, Solaris, FreeBSD. It may also run on other systems, provided that libffi supports this platform. On Windows, ctypes contains (the beginning of) a COM framework mainly targetted to use and implement custom COM interfaces. News ctypes now uses the same code base and libffi on all platforms. For easier installation, the libffi sources are now included in the source distribution - no need to find, build, and install a compatible libffi version. Requirements ctypes 0.9 requires Python 2.3 or higher, since it makes intensive use of the new type system. ctypes uses libffi, which is copyright Red Hat, Inc. Complete license see below. Installation Windows On Windows, it is the easiest to download the executable installer for your Python version and execute this. Installation from source Separate source distributions are available for windows and non-windows systems. Please use the .zip file for Windows (it contains the ctypes.com framework), and use the .tar.gz file for non-Windows systems (it contains the complete cross-platform libffi sources). To install ctypes from source, unpack the distribution, enter the ctypes-0.9.x source directory, and enter python setup.py build This will build the Python extension modules. A C compiler is required. On OS X, the segment attribute live_support must be defined. If your compiler doesn't know about it, upgrade or set the environment variable CCASFLAGS="-Dno_live_support". To run the supplied tests, enter python setup.py test To install ctypes, enter python setup.py install --help to see the avaibable options, and finally python setup.py install [options] For Windows CE, a project file is provided in wince\_ctypes.vcw. MS embedded Visual C 4.0 is required to build the extension modules. Additional notes Current version: 0.9.9.3 Homepage: http://starship.python.net/crew/theller/ctypes.html ctypes license Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Thomas Heller Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. libffi license libffi - Copyright (c) 1996-2003 Red Hat, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ``Software''), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |