[Rpm-maint] [PATCH 06/15] Update module initialization to work with both Python 2.* and Python 3.*
David Malcolm
dmalcolm at redhat.com
Wed Oct 28 19:57:23 UTC 2009
On Mon, 2009-10-19 at 14:19 +0300, Panu Matilainen wrote:
> On Thu, 15 Oct 2009, David Malcolm wrote:
>
> > Introduce macros and conditional compilation to deal with the major
> > changes to the way that Python extension modules are initialized between
> > Python 2 and 3 (PEP 3121).
>
> Hmm, this is starting to look a bit more painful :)
[snip discussion of shared module state]
> I didn't try out what it'd actually look like, but it'd seem to me that
> the module initialization version differences could be made more obvious
> (less #ifdefs) by splitting out much of the init work into a separate
> function, ie something like
[snip]
I finally had a go at doing this; see the attached patch.
This patch splits each of the two modules' initialization into two
parts:
- a "prepareInitModule" function that's called _before_ trying to get
a PyObject module pointer,
- a "initModule" function that does the work upon a PyObject module
ptr.
giving four new functions in all; all of these functions return 1 for
success, 0 for failure.
These functions embed the commonality between 2 and 3 for module
initialization.
The 2 vs 3 differences are then reduced to calling out to each function
from 2 and 3-specific blocks of code.
Tested very briefly with python 2.6.4 and 3.1.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fixup-python2-vs-python3-module-initialization.patch
Type: text/x-patch
Size: 5033 bytes
Desc: not available
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20091028/83a7a87c/attachment.bin>
More information about the Rpm-maint
mailing list