September 19, 2015
On Sat, 2015-09-19 at 17:15 +0100, Russel Winder wrote:
> 
[…]
> Sadly the:
> 
>  pragma(LDC_global_crt_ctor, 0)
>     void initRuntime() {
>       import core.runtime: Runtime;
>       Runtime.initialize();
>    }
> 
> will not compile under DMD :-(

On the otherhand using a:

    version(LDC) {
    …
    }

solves the problem.

-- 
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



September 19, 2015
On Saturday, 19 September 2015 at 16:25:28 UTC, Laeeth Isharc wrote:
> On Saturday, 19 September 2015 at 12:21:02 UTC, ponce wrote:
>> [...]
>
> What is the difference between shared static this and the global constructor ?  Russell, if you use shared static this for dmd does it work ?  Laeeth.

IIRC shared static this is only called by the runtime, so obviously you can't use it to initialise the runtime itself.
September 19, 2015
On Sat, 2015-09-19 at 16:25 +0000, Laeeth Isharc via Digitalmars-d -learn wrote:
> 
[…]
> What is the difference between shared static this and the global constructor ?  Russell, if you use shared static this for dmd does it work ?  Laeeth.

I had no idea what to put in a:

shared static this {
…
}

so I don't have one.

-- 
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



September 19, 2015
On Saturday, 19 September 2015 at 16:32:18 UTC, Russel Winder wrote:
>
> (*) ponce is arguably not the most positive or constructive name to go
> by.

Friend call me like this IRL since forever.

It seems to be a swear word in english?
September 19, 2015
On Saturday, 19 September 2015 at 16:34:05 UTC, John Colvin wrote:
> On Saturday, 19 September 2015 at 16:25:28 UTC, Laeeth Isharc wrote:
>> On Saturday, 19 September 2015 at 12:21:02 UTC, ponce wrote:
>>> [...]
>>
>> What is the difference between shared static this and the global constructor ?  Russell, if you use shared static this for dmd does it work ?  Laeeth.
>
> IIRC shared static this is only called by the runtime, so obviously you can't use it to initialise the runtime itself.

Aha...  Is there an equivalent in dmd to the global constructor ?

September 19, 2015
On Sat, 2015-09-19 at 16:33 +0000, John Colvin via Digitalmars-d-learn wrote:
> On Saturday, 19 September 2015 at 16:15:45 UTC, Russel Winder wrote:
> > Sadly the:
> > 
> >  pragma(LDC_global_crt_ctor, 0)
> >     void initRuntime() {
> >       import core.runtime: Runtime;
> >       Runtime.initialize();
> >    }
> > 
> > will not compile under DMD :-(
> 
> version(LDC){ /* ... */ }
> 
> not that it helps make things work correctly, but at least they'll compile :)

Indeed, it works well. Well for LDC. DMD and GDC are still broken. My GDC problems are deeper that this code: Debian packages seem to have weird problems and Fedora do not package GDC.

-- 
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



September 19, 2015
On Sat, 2015-09-19 at 16:41 +0000, ponce via Digitalmars-d-learn wrote:
> 
[…]
> Friend call me like this IRL since forever.
> 
> It seems to be a swear word in english?

English and Spanish meanings of the word are very different. In UK (not sure about Canada, USA, Australia, New Zealand, South Africa,…) it is generally a somewhat derogatory term.

-- 
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



September 19, 2015
On Saturday, 19 September 2015 at 10:45:22 UTC, Russel Winder wrote:
> Calling D from Python. I have two functions in D, compiled to a shared object on Linux using LDC (but I get same problem using DMD).
>
> The sequential code:
>
>     extern(C)
>     double sequential(const int n, const double delta) {
>       Runtime.initialize();
>       const pi = 4.0 * delta * reduce!(
>             (double t, int i){ immutable x = (i - 0.5) * delta; return t + 1.0 / (1.0 + x * x); })(
>             0.0, iota(1, n + 1));
>       Runtime.terminate();
>       return pi;
>     }
>
> works entirely fine. However the "parallel" code:
>
>     extern(C)
>     double parallel(const int n, const double delta) {
>       Runtime.initialize();
>       const pi = 4.0 * delta * taskPool.reduce!"a + b"(
>           map!((int i){ immutable x = (i - 0.5) * delta; return 1.0 / (1.0 + x * x); })(iota(1, n + 1)));
>       Runtime.terminate();
>       return pi;
>     }
>
> causes an immediate segfault (with LDC and DMD.  I am assuming that the problem is the lack of initialization of the std.parallelism module and hence the use of taskPool is causing a problem. I am betting I am missing something very simple about module initialization, and that this is not actually a bug.
>
> Anyone any proposals?

Btw have you looked at Colvin's prettypyd ?  It's a nicer way to wrap things.  Just @pdef!() before functions, aggregates and fields to wrap them.

For demos, I should also think that showing Python code in one Jupyter cell  calling D code in another is a pretty nice way to show interop.  Just need to install the pyd Magic.    Your D code can import dub libraries too.


September 19, 2015
On Saturday, 19 September 2015 at 17:41:39 UTC, Laeeth Isharc wrote:
> On Saturday, 19 September 2015 at 10:45:22 UTC, Russel Winder wrote:
>> Calling D from Python. I have two functions in D, compiled to a shared object on Linux using LDC (but I get same problem using DMD).
>>
>> The sequential code:
>>
>>     extern(C)
>>     double sequential(const int n, const double delta) {
>>       Runtime.initialize();
>>       const pi = 4.0 * delta * reduce!(
>>             (double t, int i){ immutable x = (i - 0.5) * delta; return t + 1.0 / (1.0 + x * x); })(
>>             0.0, iota(1, n + 1));
>>       Runtime.terminate();
>>       return pi;
>>     }
>>
>> works entirely fine. However the "parallel" code:
>>
>>     extern(C)
>>     double parallel(const int n, const double delta) {
>>       Runtime.initialize();
>>       const pi = 4.0 * delta * taskPool.reduce!"a + b"(
>>           map!((int i){ immutable x = (i - 0.5) * delta; return 1.0 / (1.0 + x * x); })(iota(1, n + 1)));
>>       Runtime.terminate();
>>       return pi;
>>     }
>>
>> causes an immediate segfault (with LDC and DMD.  I am assuming that the problem is the lack of initialization of the std.parallelism module and hence the use of taskPool is causing a problem. I am betting I am missing something very simple about module initialization, and that this is not actually a bug.
>>
>> Anyone any proposals?
>
> Btw have you looked at Colvin's prettypyd ?  It's a nicer way to wrap things.  Just @pdef!() before functions, aggregates and fields to wrap them.
>
> For demos, I should also think that showing Python code in one Jupyter cell  calling D code in another is a pretty nice way to show interop.  Just need to install the pyd Magic.    Your D code can import dub libraries too.


In particular it should just work that way as PyD should deal with runtime initialization and the like.

https://github.com/DlangScience/PydMagic
https://github.com/DlangScience/PydMagic/blob/master/examples/test.ipynb
https://github.com/John-Colvin/ppyd





September 20, 2015
On Saturday, 19 September 2015 at 10:45:22 UTC, Russel Winder wrote:
> Calling D from Python. I have two functions in D, compiled to a shared object on Linux using LDC (but I get same problem using DMD).
>
> The sequential code:
>
>     extern(C)
>     double sequential(const int n, const double delta) {
>       Runtime.initialize();
>       const pi = 4.0 * delta * reduce!(
>             (double t, int i){ immutable x = (i - 0.5) * delta; return t + 1.0 / (1.0 + x * x); })(
>             0.0, iota(1, n + 1));
>       Runtime.terminate();
>       return pi;
>     }
>
> works entirely fine. However the "parallel" code:
>
>     extern(C)
>     double parallel(const int n, const double delta) {
>       Runtime.initialize();
>       const pi = 4.0 * delta * taskPool.reduce!"a + b"(
>           map!((int i){ immutable x = (i - 0.5) * delta; return 1.0 / (1.0 + x * x); })(iota(1, n + 1)));
>       Runtime.terminate();
>       return pi;
>     }
>
> causes an immediate segfault (with LDC and DMD.  I am assuming that the problem is the lack of initialization of the std.parallelism module and hence the use of taskPool is causing a problem. I am betting I am missing something very simple about module initialization, and that this is not actually a bug.
>
> Anyone any proposals?


Isn't it simply that when doing some work asynchronously, as with task pool, work is being done in other threads than the main. All the while, you're killing the Runtime. The fact that when removing  Runtime.terminate makes the code work might support that explanation.