From akitada at gmail.com Thu Nov 6 00:30:05 2008 From: akitada at gmail.com (Akira Kitada) Date: Thu, 6 Nov 2008 08:30:05 +0900 Subject: [capi-sig] Fwd: Can I build Python with lthread instead of pthread? In-Reply-To: References: Message-ID: <90bb445a0811051530v2a00c747u5ec538c85c24258c@mail.gmail.com> suggested to try to ask capi-sig for this question. Forwarding. ---------- Forwarded message ---------- From: Aahz Date: Thu, Nov 6, 2008 at 1:08 AM Subject: Re: Can I build Python with lthread instead of pthread? To: python-list at python.org In article , Akira Kitada wrote: > >I'm running Python 2.5 on FreeBSD 4. >pthread on FreeBSD 4 has some problems so I would like to build >python with lthread (linuxthreads) instead of BSD's pthread. >So I looked at configure options but couldn't find any options for it. >Python support lthread? and how can I build python with it? You may want to try asking on capi-sig -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity -- http://mail.python.org/mailman/listinfo/python-list From philipp at achtziger.de Tue Nov 11 15:55:58 2008 From: philipp at achtziger.de (Philipp Heuser) Date: Tue, 11 Nov 2008 15:55:58 +0100 Subject: [capi-sig] Beginner Question PyObject* to int Message-ID: <49199CFE.20608@achtziger.de> Hi all, I am just starting to use the C API for Python. What I want to do is to use an external funtion availabele in C and therfore I want to 'convert' a list of floats from Python to an array of floats in C which I can forward to the external function. So first step is tp parse a list to C and let the C code print the variables! The obviously too simplistic approach is below... When I call this function from python, e.g. cpp([1,2,3]) the output is: 25180552 25180540 25180528 Could you be so kind to help me here to get started with using C-functions from Python? Where is the error? Thank you very much and kind regards, Philipp static PyObject * cpp_foo(PyObject *self, PyObject* args) { PyObject* obj; PyObject* seq; int i, len; if(!PyArg_ParseTuple(args, "O", &obj)) return NULL; seq = PySequence_Fast(obj, "expected a sequence"); len = PySequence_Size(obj); PyObject* item; int a; for (i=0; i References: <49199CFE.20608@achtziger.de> Message-ID: On 12/11/2008, at 1:55 AM, Philipp Heuser wrote: > Hi all, > > I am just starting to use the C API for Python. What I want to do is > to use an external funtion availabele in C and therfore I want to > 'convert' a list of floats from Python to an array of floats in C > which I can forward to the external function. So first step is tp > parse a list to C and let the C code print the variables! The > obviously too simplistic approach is below... When I call this > function from python, e.g. cpp([1,2,3]) the output is: > 25180552 > 25180540 > 25180528 > > Could you be so kind to help me here to get started with using C- > functions from Python? Where is the error? > > Thank you very much and kind regards, > > Philipp > > > > static PyObject * > cpp_foo(PyObject *self, PyObject* args) > { > PyObject* obj; > PyObject* seq; > int i, len; > if(!PyArg_ParseTuple(args, "O", &obj)) > return NULL; > seq = PySequence_Fast(obj, "expected a sequence"); > len = PySequence_Size(obj); > PyObject* item; > int a; > > for (i=0; i { > item=PySequence_Fast_GET_ITEM(seq, i); > a=item; // ????????????????????????????????????????? Perhaps something like: long a; a = PyInt_AsLong(item); if (a == -1 && PyErr_Occurred()) return NULL; /* error */ printf("%i\n", a); Cheers, Chris Miles From ggpolo at gmail.com Wed Nov 12 13:06:27 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 12 Nov 2008 10:06:27 -0200 Subject: [capi-sig] Beginner Question PyObject* to int In-Reply-To: <49199CFE.20608@achtziger.de> References: <49199CFE.20608@achtziger.de> Message-ID: On Tue, Nov 11, 2008 at 12:55 PM, Philipp Heuser wrote: > Hi all, > > I am just starting to use the C API for Python. What I want to do is to use > an external funtion availabele in C and therfore I want to 'convert' a list > of floats from Python to an array of floats in C which I can forward to the > external function. So first step is tp parse a list to C and let the C code > print the variables! The obviously too simplistic approach is below... When > I call this function from python, e.g. cpp([1,2,3]) the output is: > 25180552 > 25180540 > 25180528 > > Could you be so kind to help me here to get started with using C-functions > from Python? Where is the error? > > Thank you very much and kind regards, > > Philipp > > > > static PyObject * > cpp_foo(PyObject *self, PyObject* args) > { > PyObject* obj; > PyObject* seq; > int i, len; > if(!PyArg_ParseTuple(args, "O", &obj)) > return NULL; > seq = PySequence_Fast(obj, "expected a sequence"); > len = PySequence_Size(obj); > PyObject* item; > int a; > > for (i=0; i { > item=PySequence_Fast_GET_ITEM(seq, i); > a=item; // ????????????????????????????????????????? Add more '?'s here. PySequence_FAST_GET_ITEM returns a PyObject, you can't just go and give it to 'a' to turn it into an integer. Also, this variable 'i' better be of type Py_ssize_t instead of int. So, to get your value as a long, first check item is indeed a long using PyLong_Check(item) and then convert it to a long with PyLong_AsLong(item): > printf("%i\n", a); > } > Py_DECREF(seq); return None; > } > > _______________________________________________ > capi-sig mailing list > capi-sig at python.org > http://mail.python.org/mailman/listinfo/capi-sig > -- -- Guilherme H. Polo Goncalves From philipp at achtziger.de Wed Nov 12 14:37:05 2008 From: philipp at achtziger.de (Philipp Heuser) Date: Wed, 12 Nov 2008 14:37:05 +0100 Subject: [capi-sig] Beginner Question PyObject* to int In-Reply-To: References: <49199CFE.20608@achtziger.de> Message-ID: <491ADC01.1080809@achtziger.de> Thanks for your replies! Philipp From stefan_ml at behnel.de Wed Nov 12 12:55:00 2008 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 12 Nov 2008 12:55:00 +0100 (CET) Subject: [capi-sig] Beginner Question PyObject* to int In-Reply-To: <49199CFE.20608@achtziger.de> References: <49199CFE.20608@achtziger.de> Message-ID: <54669.213.61.181.86.1226490900.squirrel@groupware.dvs.informatik.tu-darmstadt.de> Philipp Heuser wrote: > I am just starting to use the C API for Python. What I want to do is to > use an external funtion availabele in C and therfore I want to 'convert' > a list of floats from Python to an array of floats in C Since you're just starting, it's generally worth looking into Cython first, before investing time to learn the raw Python C-API. http://cython.org/ Stefan From koder.mail at gmail.com Thu Nov 13 13:00:36 2008 From: koder.mail at gmail.com (KoDer) Date: Thu, 13 Nov 2008 14:00:36 +0200 Subject: [capi-sig] Beginner Question PyObject* to int In-Reply-To: <54669.213.61.181.86.1226490900.squirrel@groupware.dvs.informatik.tu-darmstadt.de> References: <49199CFE.20608@achtziger.de> <54669.213.61.181.86.1226490900.squirrel@groupware.dvs.informatik.tu-darmstadt.de> Message-ID: <6e8b06c90811130400m5bfcf9dfo20508fad7e3854a7@mail.gmail.com> 2008/11/12 Stefan Behnel : > Philipp Heuser wrote: >> I am just starting to use the C API for Python. What I want to do is to >> use an external funtion availabele in C and therfore I want to 'convert' >> a list of floats from Python to an array of floats in C > > Since you're just starting, it's generally worth looking into Cython > first, before investing time to learn the raw Python C-API. > > http://cython.org/ > Or http://cxx.sourceforge.net/ -- K.Danilov aka KoDer ICQ:214286120 Skype:koder.ua Tel:8-050-4030512 Jabber:koder_ua at jabber.ru From python_capi at behnel.de Thu Nov 13 13:45:28 2008 From: python_capi at behnel.de (Stefan Behnel) Date: Thu, 13 Nov 2008 13:45:28 +0100 (CET) Subject: [capi-sig] Beginner Question PyObject* to int In-Reply-To: <6e8b06c90811130400m5bfcf9dfo20508fad7e3854a7@mail.gmail.com> References: <49199CFE.20608@achtziger.de> <54669.213.61.181.86.1226490900.squirrel@groupware.dvs.informatik.tu-darmstadt.de> <6e8b06c90811130400m5bfcf9dfo20508fad7e3854a7@mail.gmail.com> Message-ID: <65384.213.61.181.86.1226580328.squirrel@groupware.dvs.informatik.tu-darmstadt.de> KoDer wrote: > 2008/11/12 Stefan Behnel: >> Since you're just starting, it's generally worth looking into Cython >> first, before investing time to learn the raw Python C-API. >> >> http://cython.org/ > > Or http://cxx.sourceforge.net/ Interesting, I hadn't heard of it yet. Definitely has a steeper learning curve for a Python developer than Cython, but it looks like C++ developers could benefit from it. Stefan From philipp at achtziger.de Wed Nov 19 18:00:11 2008 From: philipp at achtziger.de (Philipp Heuser) Date: Wed, 19 Nov 2008 18:00:11 +0100 Subject: [capi-sig] Compiling/Linking external Functions (setup.py, distutils, gcc?) Message-ID: <4924461B.4060801@achtziger.de> Hello all, I would like to use an existing C-Function from python. Therfore I made up an wrapper (wrap.c), where all the variable transformations from Python to C are done. That works. Now I would like to call the external fuction, which is placed in lets say ext_foo.a with a corresponding ext_foo.h and can be used as a library from plain C. I am assuming, that I do have to include the ext_foo.h in my wrap.c with #include "ext_foo.h" that I have to introduce the function in my C-Code: extern int foo(int); that I have to tell the setup.py using the distutils stuff where the library can be found... when compiling a C-Code which is not for python usage I do type gcc -o test.o ./test.c ./ext_foo.a -I./foo_h_file_path/ and everything is fine, where within these setup.py files do I have to mention the ./ext_foo.a ? When I do place it in the sources-tag, setup procedure complains that it doesn't know any .a files... if I don't mention it explicitly, just giving the include_dirs, compilation works fine, but when importing from python 'import wrap' I do get the message: Symbol not found: _foo Any help is very much appreciated! Thanks Philipp From carsten.haese at gmail.com Wed Nov 19 18:25:30 2008 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 19 Nov 2008 12:25:30 -0500 Subject: [capi-sig] Compiling/Linking external Functions (setup.py, distutils, gcc?) In-Reply-To: <4924461B.4060801@achtziger.de> References: <4924461B.4060801@achtziger.de> Message-ID: <5fbcfcff0811190925h33dd1ce4p9d8ff3bffeebab8@mail.gmail.com> On Wed, Nov 19, 2008 at 12:00 PM, Philipp Heuser wrote: > where within these setup.py files do I have to mention the ./ext_foo.a ? > When I do place it in the sources-tag, setup procedure complains that it > doesn't know any .a files... if I don't mention it explicitly, just giving > the include_dirs, compilation works fine, but when importing from python > 'import wrap' I do get the message: Symbol not found: _foo > The "sources" parameter lists source files that need to be compiled. Your ext_foo.a doesn't need to be compiled; it just needs to be linked. Try adding a parameter link_objects=['ext_foo.a'] to the Extension(...) definition. HTH, -- Carsten Haese http://informixdb.sourceforge.net From mal at egenix.com Wed Nov 19 18:35:49 2008 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 19 Nov 2008 18:35:49 +0100 Subject: [capi-sig] Compiling/Linking external Functions (setup.py, distutils, gcc?) In-Reply-To: <4924461B.4060801@achtziger.de> References: <4924461B.4060801@achtziger.de> Message-ID: <49244E75.7020304@egenix.com> On 2008-11-19 18:00, Philipp Heuser wrote: > Hello all, > > I would like to use an existing C-Function from python. Therfore I made > up an wrapper (wrap.c), where all the variable transformations from > Python to C are done. That works. Now I would like to call the external > fuction, which is placed in lets say ext_foo.a with a corresponding > ext_foo.h and can be used as a library from plain C. > > I am assuming, that I do have to include the ext_foo.h in my wrap.c with > #include "ext_foo.h" > > that I have to introduce the function in my C-Code: > > extern int foo(int); > > that I have to tell the setup.py using the distutils stuff where the > library can be found... > > when compiling a C-Code which is not for python usage I do type > > gcc -o test.o ./test.c ./ext_foo.a -I./foo_h_file_path/ > > and everything is fine, > where within these setup.py files do I have to mention the ./ext_foo.a ? > When I do place it in the sources-tag, setup procedure complains that it > doesn't know any .a files... The .a file is a library, so you have use the libraries parameter to have distutils link against this library. http://docs.python.org/extending/building.html > if I don't mention it explicitly, just > giving the include_dirs, compilation works fine, but when importing from > python 'import wrap' I do get the message: Symbol not found: _foo -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 19 2008) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2008-11-12: Released mxODBC.Connect 0.9.3 http://python.egenix.com/ :::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611