8.1 Extending PyS60
The general rules and guidelines for writing Python extensions apply
in the S60 Python environment as well.
The steps for the implementation of an extension modules include:
- Preparation of the data structures that make the C/C++ coded extensions
      visible to the Python interpreter and make it possible to perform calls from
      Python to C/C++ code
 
- Conversions between C/C++ representations of the Python objects and
      object types used in the extension code
 
- Maintenance of the reference counts of the C/C++ representations of the
      Python objects
 
- Passing of exceptions between C/C++ code and Python
 
- Management of interpreter's thread state and the interpreter lock
 
In addition to the concerns common for all Python C extensions, the
following principles should be considered when implementing new Python
interfaces in the S60 environment:
- Maximize the usage of Python's built-in types at the interfaces.
 
- Related to the above: design interfaces in such a way that information
      can be passed between them with minimal conversions.
 
- Convert Symbian operating system exceptions or errors to Python exceptions.
 
- Unicode strings are used at the interfaces to represent text that gets
      shown on the GUI. They can be passed to and from Symbian operating system
      without conversions.
 
- While performing potentially long-lasting or blocking calls from an
      extension implementation to services outside the interpreter, the
      interpreter lock must be released and then re-acquired after the call.
 
- Rather than always implementing a thin wrapper on top of a Symbian OS
      facility, consider the actual task for which the script writer needs the
      particular interface. For example, if the task involves interaction with
      the users using the GUI, the script writer's interest may well be limited
      to performing the interaction or information exchange in a way that is
      compatible with the UI style rather than having full control of the
      low-level details of the GUI implementation.
 
- The C/C++ implementation of a Python interface should be optimized for
      performance and covering access to the necessary features of the
      underlying Platform. Where necessary, the Python programming interface can
      be further refined by wrapper modules written in Python.
 
The pyd name should be of the format 'kf_<module-name>.pyd'. Note that this change
is required only for the pyd name and module name is not required to have this prefix.
The module initialization function must be exported at ordinal 1. The module
identification is based on the filename only. As a special feature of PyS60, an
optional module finalizer function may be exported at ordinal 2.
The extension modules added by the developer should be placed in the module repo
folder of the PyS60 Application Packager so that the compiled PYD's can be picked
up while packaging. For information on this topic refer 8.1.3, Distributing Extension Modules.
Release 2.0.0 final  , documentation updated on 10 Feb 2010.
 
See About this document... for information on suggesting changes.