public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* Howto compile py-smbus with python 3.2
@ 2012-05-14 11:16 Renz, Bernhard
       [not found] ` <DDF9A29ED50FA94F83C55CFA4BB8EF5F08323B-8+ddyajbMjLtkydW1Tv2DlZafE0Mqj5e5/FHAH3NXZDDzftRWevZcw@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Renz, Bernhard @ 2012-05-14 11:16 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

Hello @All,

i try to compile i2c-tools-3.1.0 py-smbus, smbusmodule.c with the following command under Ubuntu 12.04:
python3.2 ./setup.py build

But it fail with the following errors:
running build
running build_ext
building 'smbus' extension
gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -fPIC -I/usr/include/python3.2mu -c smbusmodule.c -o build/temp.linux-x86_64-3.2/smbusmodule.o


smbusmodule.c: In function 'SMBus_dealloc':
smbusmodule.c:94:6: error: 'SMBus' has no member named 'ob_type'
smbusmodule.c: In function 'SMBus_list_to_data':

With Python 2.7 it works. So it seems that the smbusmodule.c is written for Python 2.7.
I googled a bit, and found the following article where the changes in the c extentation between Python 2.X and Python 3 is described (espancially the ob_type problem):
http://python3porting.com/cextensions.html

Citation:
Another change in the object header is that the PyObject_HEAD macro has changed so that ob_type is now in a nested structure. This means you no longer can pick the ob_type directly from the struct, so code like ob->ob_type stops working. You should replace this with Py_TYPE(ob). The Py_TYPE macro doesn't appear until Python 2.6, so to support earlier versions we make another #ifndef:
#ifndef Py_TYPE
    #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
#endif
In both cases the definitions above are taken directly from the Python 2.6 headers, where they are defined for forward compatibility purposes with Python 3. They work well in earlier Python versions as well, so this is a trick you can use as a general rule; if you need to use a macro that is defined in Python 3 and Python 2.6, just steal the Python 2.6 or Python 2.7 definition and put it inside an #ifndef.


Has anybody smbusmodule.c port to use with python 3?

With kind regards
Bernhard


________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-04-24 18:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-14 11:16 Howto compile py-smbus with python 3.2 Renz, Bernhard
     [not found] ` <DDF9A29ED50FA94F83C55CFA4BB8EF5F08323B-8+ddyajbMjLtkydW1Tv2DlZafE0Mqj5e5/FHAH3NXZDDzftRWevZcw@public.gmane.org>
2012-05-21 15:10   ` Renz, Bernhard
     [not found]     ` <DDF9A29ED50FA94F83C55CFA4BB8EF5F08A9BD-8+ddyajbMjJjmjMfHwPPEFZafE0Mqj5e5/FHAH3NXZDDzftRWevZcw@public.gmane.org>
2012-05-21 15:14       ` Jean Delvare
     [not found]         ` <20120521171419.2ef13147-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-05-21 15:40           ` Renz, Bernhard
2013-04-24 18:21     ` Tom Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox