Re: SWIG vs. ctypes (Was: ANN: PyEnchant 1.5.0)

2008-11-25 Thread skip

Roy I'm debating whether I should do the Python version with SWIG or
Roy ctypes. 

Unless your C++ library exports a C api I don't think you can use ctypes to
make it available within Python.

-- 
Skip Montanaro - [EMAIL PROTECTED] - http://smontanaro.dyndns.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: SWIG vs. ctypes (Was: ANN: PyEnchant 1.5.0)

2008-11-25 Thread Diez B. Roggisch
Roy Smith wrote:

 In article [EMAIL PROTECTED],
  Ryan Kelly [EMAIL PROTECTED] wrote:
 
 * Migrated from SWIG to ctypes for the C binding:
 
 Ryan,
 
 I'm looking at a doing a Python wrapper for a C++ library.  We've already
 done a Perl wrapper for this library using SWIG (I wasn't personally
 involved in that effort).  I'm debating whether I should do the Python
 version with SWIG or ctypes.  I'd be interested to hear about your
 experiences with both and why you switched.

You can't use ctypes for C++, only for C-style APIs.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: SWIG vs. ctypes (Was: ANN: PyEnchant 1.5.0)

2008-11-25 Thread cptnwillard
On Nov 25, 4:34 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:

 You can't use ctypes for C++, only for C-style APIs.

 Diez

With some work, you can convert your C++ objects to PyObject* and then
return the latter in a function with C bindings.
--
http://mail.python.org/mailman/listinfo/python-list


Re: SWIG vs. ctypes (Was: ANN: PyEnchant 1.5.0)

2008-11-25 Thread Olivier Grisel
2008/11/25  [EMAIL PROTECTED]:
 On Nov 25, 4:34 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:

 You can't use ctypes for C++, only for C-style APIs.

 Diez

 With some work, you can convert your C++ objects to PyObject* and then
 return the latter in a function with C bindings.

http://cython.org also has some support for C++ bindings.

I also heard that Boost.Python is very well suited to make full
featured C++ / python bindings though I never tried myself.

-- 
Olivier
--
http://mail.python.org/mailman/listinfo/python-list


Re: SWIG vs. ctypes (Was: ANN: PyEnchant 1.5.0)

2008-11-25 Thread Matthieu Brucher
Boost.Python is difficult to understand, far more than SWIG. It may be
faster, but I don't think it is worth it ATM.
Binding C++ classes with SWIG is really simple.

Matthieu

2008/11/25 Olivier Grisel [EMAIL PROTECTED]:
 2008/11/25  [EMAIL PROTECTED]:
 On Nov 25, 4:34 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:

 You can't use ctypes for C++, only for C-style APIs.

 Diez

 With some work, you can convert your C++ objects to PyObject* and then
 return the latter in a function with C bindings.

 http://cython.org also has some support for C++ bindings.

 I also heard that Boost.Python is very well suited to make full
 featured C++ / python bindings though I never tried myself.

 --
 Olivier
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Information System Engineer, Ph.D.
Website: http://matthieu-brucher.developpez.com/
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn: http://www.linkedin.com/in/matthieubrucher
--
http://mail.python.org/mailman/listinfo/python-list


Re: SWIG vs. ctypes (Was: ANN: PyEnchant 1.5.0)

2008-11-25 Thread Diez B. Roggisch

[EMAIL PROTECTED] schrieb:

On Nov 25, 4:34 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:

You can't use ctypes for C++, only for C-style APIs.

Diez


With some work, you can convert your C++ objects to PyObject* and then
return the latter in a function with C bindings.


Or you use SWIG or SIP or Python::Boost to do that for you with less work.


Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: SWIG vs. ctypes (Was: ANN: PyEnchant 1.5.0)

2008-11-25 Thread rfk
 I'd be interested to hear about your
 experiences with both and why you switched.

Enchant has a pretty simple C API so the binding process was
straightforward with both SWIG and ctypes.  The only real trick was in
passing python functions as callbacks to the C API, for which I found
ctypes a little easier to use.

The switch wasn't motivated by any problems with SWIG, but simply
because ctypes seems to have a lot of momentum on the alternate python
implementations such as PyPy, Jython etc.

As others have noted, ctypes unfortunately doesn't support C++
bindings. There was a recent post on the PyPy blog discussing options
for C++ that you might be interested in:

   
http://morepypy.blogspot.com/2008/10/sprint-discussions-c-library-bindings.html


 Cheers,

   Ryan
--
http://mail.python.org/mailman/listinfo/python-list