Jump to page: 1 2 3
Thread overview
Python calling D
Dec 11, 2013
CJS
Dec 11, 2013
FreeSlave
Dec 11, 2013
Chris
Dec 11, 2013
John Colvin
Jan 19, 2014
Russel Winder
Jan 20, 2014
CJS
Jan 24, 2014
Ellery Newcomer
Jan 24, 2014
Russel Winder
Jan 26, 2014
Ellery Newcomer
Jan 26, 2014
Russel Winder
Jan 26, 2014
Russel Winder
Feb 01, 2014
Ellery Newcomer
Feb 01, 2014
Russel Winder
Feb 02, 2014
Ellery Newcomer
Feb 02, 2014
Russel Winder
Feb 04, 2014
Artem Tarasov
Feb 04, 2014
Russel Winder
Feb 04, 2014
Artem Tarasov
Feb 04, 2014
Russel Winder
Feb 07, 2014
Ellery Newcomer
Dec 11, 2013
John Colvin
December 11, 2013
I'd like to use cython to wrap a D library. It's possible to do this with a statically compiled C library, but it fails when I try with a statically compiled D library. Any suggestions on how to do this successfully?
December 11, 2013
On Wednesday, 11 December 2013 at 05:30:49 UTC, CJS wrote:
> I'd like to use cython to wrap a D library. It's possible to do this with a statically compiled C library, but it fails when I try with a statically compiled D library. Any suggestions on how to do this successfully?

I'm not Cython guy, but as I know, Cython generates C code, right? Then probably at first you should learn how to call D functions from C side. I don't know how to do it correctly. It's easily to call those D functions which don't use 'new' operation and garbage collection (explicitly or implicitly). But when they do that, I get segmentation fault.
December 11, 2013
On Wednesday, 11 December 2013 at 05:30:49 UTC, CJS wrote:
> I'd like to use cython to wrap a D library. It's possible to do this with a statically compiled C library, but it fails when I try with a statically compiled D library. Any suggestions on how to do this successfully?

Have you had a look at this:

http://pyd.dsource.org/
https://github.com/dansanduleac/pyd

December 11, 2013
On Wednesday, 11 December 2013 at 11:41:11 UTC, Chris wrote:
> On Wednesday, 11 December 2013 at 05:30:49 UTC, CJS wrote:
>> I'd like to use cython to wrap a D library. It's possible to do this with a statically compiled C library, but it fails when I try with a statically compiled D library. Any suggestions on how to do this successfully?
>
> Have you had a look at this:
>
> http://pyd.dsource.org/
> https://github.com/dansanduleac/pyd

both of those are out of date, this is where development is now: https://bitbucket.org/ariovistus/pyd
December 11, 2013
On Wednesday, 11 December 2013 at 05:30:49 UTC, CJS wrote:
> I'd like to use cython to wrap a D library. It's possible to do this with a statically compiled C library, but it fails when I try with a statically compiled D library. Any suggestions on how to do this successfully?

1) have you declared the functions you want to call with extern(C)?

2) you will need to compile the D code as a shared library.

3) you will need to call rt_init / rt_term to start / stop the runtime in order to use some features of D. There are problems with the runtime when using multiple D shared libraries, so it's best to link everything you need as a single shared lib.
January 19, 2014
On Wed, 2013-12-11 at 12:56 +0100, John Colvin wrote:
> On Wednesday, 11 December 2013 at 11:41:11 UTC, Chris wrote:
[…]
> > Have you had a look at this:
> >
> > http://pyd.dsource.org/
> > https://github.com/dansanduleac/pyd
> 
> both of those are out of date, this is where development is now: https://bitbucket.org/ariovistus/pyd

Sorry to be late coming to this.

It would great to be able to push D as a CPython extension language. However the state of pyd.dsource.org and places reached from it do make it seem that the project died in 2009.

ariovistus' GitHub project on Bitbucket is moving but everything else appears to be a problem.

Is it possible to decide on a location for activity, create some infrastructure, and then get the old stuff cleaned out.

My start point is to get PyD working in virtualenvs for Python 2.7 and Python 3.3. Findout out what the SCons and Tup stuff is for would be useful. On the side I could help with documentation and stuff, but only if it can be done by DVCS and pull requests with email, I am not interested in non DVCS wikis nor forums.

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

January 20, 2014
> Sorry to be late coming to this.
>
> It would great to be able to push D as a CPython extension language.
> However the state of pyd.dsource.org and places reached from it do make
> it seem that the project died in 2009.
>
> ariovistus' GitHub project on Bitbucket is moving but everything else
> appears to be a problem.
>
> Is it possible to decide on a location for activity, create some
> infrastructure, and then get the old stuff cleaned out.
>
> My start point is to get PyD working in virtualenvs for Python 2.7 and
> Python 3.3. Findout out what the SCons and Tup stuff is for would be
> useful. On the side I could help with documentation and stuff, but only
> if it can be done by DVCS and pull requests with email, I am not
> interested in non DVCS wikis nor forums.

For future reference, I tried but wasn't able to make calling D from python work. I tried to just compile D to an .a library, including statically linking phobos, and then wrapping it with cython like I would with C code. (I've made this work before with C.)

My thinking was that there's already been a lot of work in the Python world in the past 4-6 years to make calling C fairly straight forward. So D should be able to piggy back on that work.

(Though to a lot of Python people a legitimate question would be, "is this worth it?" You can just profile python code to find the hot spots and then use ctypes/cython to pass objects allocated by Python to C-level functions to do the time-intensive stuff.)
January 24, 2014
On Monday, 20 January 2014 at 02:30:46 UTC, CJS wrote:
>
> For future reference, I tried but wasn't able to make calling D from python work. I tried to just compile D to an .a library, including statically linking phobos, and then wrapping it with cython like I would with C code. (I've made this work before with C.)

python wants shared libs, not static libs. but this is very fiddly. so use pyd.

1. clone the ariovistus/pyd repo
2. from top dir, type

python setup install
python runtests.py hello

(or
cd examples/hello
python setup.py build
python test.py)

this will run the code found in examples/hello (it's a simple python calls D)

use python 2.7 and have dmd 2.064 on your path somewhere. It should just work.
January 24, 2014
On Fri, 2014-01-24 at 02:29 +0000, Ellery Newcomer wrote: […]

I have just tried a trivial D source shared object on Debian Unstable using DMD 2.064.2 from d-apt. Compile up the shared object with entries C linkage, try to use ctypes or CFFI from Python just gives a segmentation violation :-(

> python wants shared libs, not static libs. but this is very fiddly. so use pyd.
> 
> 1. clone the ariovistus/pyd repo
> 2. from top dir, type
> 
> python setup install
> python runtests.py hello

Probably want to use a virtualenv for this rather than install into the base installation

> (or
> cd examples/hello
> python setup.py build
> python test.py)
> 
> this will run the code found in examples/hello (it's a simple python calls D)
> 
> use python 2.7 and have dmd 2.064 on your path somewhere. It should just work.

It needs to work for Python 3.3 as well!

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

January 26, 2014
On Friday, 24 January 2014 at 10:55:34 UTC, Russel Winder wrote:
>
> Probably want to use a virtualenv for this rather than install into the
> base installation
>

you can also do

python setup.py build
python runtests.py -b hello

>
> It needs to work for Python 3.3 as well!

try the latest commit
« First   ‹ Prev
1 2 3