ctypes for Python for S60

Mon Sep 10 16:32:17 2007


  1. Introduction
  2. Status
  3. Limitations
  4. Example
  5. License
  6. Download
  7. Dependencies
  8. Contributing
  9. Acknowledgements

1. Introduction

This is a ctypes (back)port for Python for S60 (PyS60). Building has only been tested with an S60 3rd Edition SDK.

The idea here is simply to take the latest ctypes and try and get it to work with PyS60. This means both backporting a Python 2.5.1 module to (a modified) Python 2.2.2, and to get it running on Symbian OS.

2. Status

Something works. Callbacks to Python are not supported. There are compiler warnings. Static writables have not been removed. __init__.py is not yet fully ported, and hence some of the API is unavailable.

3. Limitations

As with the Open C implementation of libdl, address lookups are by ordinal, not by symbol name. This is limitation is due to Symbian OS. To determine ordinals in a Unix environment, you can say use the nm command on the relevant library file.

4. Example

Open C includes libcrypto, and it is possible to say use its message digest algorithm via ctypes, as shown below. This example could be made to look nicer if the library was fully working.

  import ctypes
  import _ctypes
  
  h = _ctypes.dlopen("libcrypto.dll")
  try:
      sha = _ctypes.dlsym(h, "1491")
      data = "digestible message"
      result = ctypes.create_string_buffer(20)
      _ctypes.call_function(sha, (data, len(data), result))
      print ctypes.sizeof(result), repr(result.raw)
  finally:
      _ctypes.dlclose(h)

5. License

The ported software was originally extracted from the Python 2.5.1 codebase, before modifications. Python 2.5.1 is covered by the PSF v2 license. The changes made for the port are minor, and are released under the original license.

6. Download

A collection of release builds is available. The sisx file without a version number is the latest release.

A darcs repository of the source code (with change history) is also available, and can be retrieved with the get command of darcs.

7. Dependencies

Depends on both Open C and Python for S60. Does not depend on non-public APIs or anything exotic. Also depends on libffi for Symbian OS. Open C, Python, and libffi must all be installed on the target device to run this software. Open C will be built in starting from S60 3rd FP2.

For building, an S60 3rd Edition SDK, the Open C plugin, and the PyS60 plugin is required. The libffi LIB and header files are required as well, and this is easiest to arrange by building the libffi library once on the development machine.

8. Contributing

Contributions are welcome. Send patches to the below email address. The send command of darcs may be used.

9. Acknowledgements

The port was done in the Services for All (E!2023 ITEA S4ALL) project at HIIT.


Tero Hasu
tero.hasu@hut.fi