Re: Is D a good choice for embedding python/octave/julia

2016-03-15 Thread Ellery Newcomer via Digitalmars-d-learn

On 03/13/2016 02:36 PM, Laeeth Isharc wrote:


InterpContext context = new InterpContext();

 context.py_stmts(outdent("
 import numpy
 a = numpy.eye(2, dtype='complex128')
 "));

 context.a.to_d!(Complex!double[][] )();





nitpicking, but the outdent is unnecessary, py_stmts calls it.

hm. maybe that should be documented..


Re: Calling python code from D

2016-02-27 Thread Ellery Newcomer via Digitalmars-d-learn

On Thursday, 25 February 2016 at 21:40:45 UTC, Wyatt wrote:
I have a project I started in Python before I realised I really 
don't enjoy Python.  It's been on the back-burner for a few 
years and I'd like to start again in D, but there's a 
particular python module (Mutagen) that I outright refuse to 
reimplement.  What's the state of the art in calling Python 
code from D?


I have a hunch PyD fits somewhere in this equation, but the 
documentation is pretty sparse, and what little I can find 
about this area makes it seem like a fairly tedious manual 
process.  Is there a less-painful and intensive way to truss 
things up?  Something to generate a simple D wrapper from a 
python module?


-Wyatt


If you want to call python from D, you should be able to install 
pyd with dub. Depending on your python setup, it should Just 
Work. If python is set up weird (ubuntu), you will need to 
generate some custom dub config and insert it in your dub.json. 
look for generate_dub_config.py on github for the generation 
part. or install pyd with pip and run python -m 
pyd.generate_dub_config


after that, you should be good to go. some example usage off the 
top of my head that probably doesn't compile:


py_init();
InterpContext context = new InterpContext();
context.pystmts(`
  from mutagen.flac import FLAC
  audio = FLAC("example.flac")
  audio["title"] = "An example"
`);
auto audio = context.audio;
audio.pprint();
audio.save();


Re: Dlang seems like java now,but why not let d more like C# Style?

2015-03-16 Thread Ellery Newcomer via Digitalmars-d-learn

On Sunday, 15 March 2015 at 14:58:54 UTC, Idan Arye wrote:


Even if we can't get the lambdas as syntax tress, the fact that 
we can send whatever types we want to the delegates and 
overload operators and stuff means we can still convert the 
lambdas into SQL.


There are limitations on operator overloading that make it much 
less likely you can use the exact same lambdas for collections 
and sql. Bad for testability.


At any rate, I really don't like what C# did with LINQ-to-SQL. 
The whole special-syntax to functional-style to syntax-tree to 
SQL is too overcomplicated - a simply lisp-style macro 
system(like what they have in Scala or Rust) could have done 
the trick in a simpler and faster way.


overcomplicated? probably - it's microsoft. And any time I have 
to manipulate the ASTs I find myself wishing for a language with 
pattern matching. I wonder if F# offers anything in that regards..


Re: Dlang seems like java now,but why not let d more like C# Style?

2015-03-14 Thread Ellery Newcomer via Digitalmars-d-learn

On Saturday, 14 March 2015 at 23:57:33 UTC, weaselcat wrote:
On Saturday, 14 March 2015 at 23:46:28 UTC, Ellery Newcomer 
wrote:
And C# has LINQ, which when combined with the last point is 
fricken awesome.


what does LINQ offer that UFCS-style functional programming 
does not?


LINQ basically is a UFCS-style api. AST reflection is what makes 
it nice.


consider:

X.Where(x = x.Members.Count() == x.Admins.Count())

straightforward in both D and C# when X is an array or container 
type.


When X is a table in a database, things get tricky for D.

C# can interpret the lambda as an ExpressionFunc (an AST type), 
so the implementation of X can reflect over the body of the 
lambda and use it to generate the appropriate SQL. ORMs such as 
entity framework and nhibernate do this now.


Re: Dlang seems like java now,but why not let d more like C# Style?

2015-03-14 Thread Ellery Newcomer via Digitalmars-d-learn
On Saturday, 14 March 2015 at 13:52:13 UTC, Craig Dillabaugh 
wrote:


I don't have any C# experience so I can't compare those 
languages much, but I've heard people say their are D / C# 
similarities.


Anyway, this isn't a criticism of your comment, I was just 
curious what (other than the shared C++ syntax heritage) you 
find so Java-like in D?


Cheers,

Craig


I've been using C# pretty extensively for the last year or so. 
Superficially, at least, C# and D are pretty similar, eg auto 
(var), foreach, lambdas, classes and structs. C# is more biased 
towards OO than D.


Metaprogramming is significantly weaker in C#. This is probably 
the one area where I've wished for some of D's functionality.


Reflection is all runtime.

C# has some AST capabilities that D doesn't. This is probably the 
main area where I envy C# when using D.


And C# has LINQ, which when combined with the last point is 
fricken awesome.


Re: embedding Pyd in Windows program

2015-03-14 Thread Ellery Newcomer via Digitalmars-d-learn

On Saturday, 14 March 2015 at 07:28:04 UTC, Matt wrote:


Yeah, dub is what I'm using. Actually, I made a mistake 
regarding the py_eval. I'm including the pyd modules in a 
module other than the one that has my main() function, so they 
weren't visible. I feel like a proper idiot for that one..


So I set up a separate project to test the samples exactly. The 
simple_embedded sample seems to work no problem.


I haven't gotten round to trying the shared_embedded, yet, but 
I will do at some point.


Does pyd have any documentation, or are we working from the 
source for understanding the functions?


there is readthedocs: http://pyd.readthedocs.org/en/latest/

there is [old] ddoc: http://ariovistus.bitbucket.org/index.html
which I've been meaning to figure out how to get into readthedocs.

there is a confluence space: 
https://pythond.atlassian.net/wiki/display/pyd/pyd+Home

where I occasionally log tidbits that might be of value


Re: embedding Pyd in Windows program

2015-03-13 Thread Ellery Newcomer via Digitalmars-d-learn

On Friday, 13 March 2015 at 19:05:59 UTC, Matt wrote:

example code, see if I can figure it out, but if you can 
advise, that would be fantastic. Thank you for all the help so 
far, it's really been appreciated


My penitence for not putting this information on readthedocs.



I've tried the hello.d example from GitHub, and get the error 
message:
   Error: template instance py_eval!string template 'py_eval' 
is not defined


Unfortunately, that's all I seem to get. Is py_eval not 
deprecated in 0.9.4?


hmm. that's odd. are you trying to build with dub? the only 
examples that build with dub are in examples/dub. the rest use 
distutils.


Re: embedding Pyd in Windows program

2015-03-13 Thread Ellery Newcomer via Digitalmars-d-learn

On Friday, 13 March 2015 at 09:38:45 UTC, Matt wrote:


I used the ~0.9.4 branch in dub, and I'm not sure how to 
change configuration. Do you mean I should be using ~master 
or ~develop?


nope. configurations are a different thing.

you can set them in your project's dub.json. example:

https://github.com/ariovistus/pyd/blob/master/examples/dub/simple_embedded/dub.json

for your project, I think you'd want

subConfigurations: {
  pyd: python34,
}



as for the transferring the python3.dll, I downloaded and 
installed a fresh copy of the latest Python build, version 3.4, 
and copied the libraries from there. Even so, I had to add 
PYD_PACKAGE_DIR manually to get it to work.


PYD_PACKAGE_DIR is necessary for linking the OMF files found in 
infrastructure/windows. hmm. why did it not Just Work?


I'm not sure I'm going to be able to run the python snippet you 
sent, since my program, which currently opens a window for 
three seconds before closing again, doesn't even get that far, 
and chokes when I run py_init().


you can put it in the top of site.py



Re: embedding Pyd in Windows program

2015-03-12 Thread Ellery Newcomer via Digitalmars-d-learn

On 03/11/2015 07:59 PM, Matt wrote:


Right, copying site.py into my program's working dir sorts out the
missing module error, but I now get a syntax error:

 file=sys.stderr)
 ^
SyntaxError: invalid syntax
Error executing command run: Program exited with code 1

I googled this, and apparently it's caused by an older interpreter. The
only files I have transferred over are:
   python3.DLL
   python3.LIB
   python34.LIB

Does anyone have any idea what I might be doing wrong, or how I can fix
this?


I'm guessing your python path is screwed up. In your embedded python,

import sys
print (sys.path)

make sure everything is pointing where it should.

Failing that,

are you using the correct dub configuration? without checking, I believe 
it defaults to python 2.7.


Failing that,

you transferred python3.dll from somewhere to somewhere? I believe pyd 
links to \windows\system32\python3.dll or some such. At least, I think 
that's where those lib files point to. not sure. If that is an issue and 
you want to use your own lib files, you will need to generate OMF files 
from them.





Re: PyD-like wrapping for Excel/VBA and Julia?

2014-12-18 Thread Ellery Newcomer via Digitalmars-d-learn

On 12/18/2014 12:41 PM, Laeeth Isharc wrote:

I have a bunch of D functions I would like to make available to Excel
(and possibly Julia) without having to write wrappers for each function
individually.



I've thought about refactoring the reflection parts of pyd into a 
reusable library for e.g. resurrecting RuD. Come to think of it, that 
would probably be necessary for supporting pypy.


It'd be a heck of a lot of work, though.



For your wrapper, you can probably do something like

extern(Windows) double vbwrap_test(double* inp,size_t num_inp,double* 
oup,size_t num_oup)

{
return test(inp[0 .. num_inp], arg_oup[0 .. num_oup]);
}

with .dup sprinkled in as you see fit. And you don't need to explicitly 
copy the results back! Might need to take the ref off oup in test..


Re: threading issues with D - C - Python

2014-12-17 Thread Ellery Newcomer via Digitalmars-d-learn

On 12/07/2014 03:12 PM, Michael wrote:

now to figure out how to use them in the general case.


This is great.. Thank you. I'm looking forward to being able to try the
finished result.


My build servers are broken at the moment, but I think I have this 
fixed, on linux at least.


Re: detaching a thread from druntime 2.067

2014-12-16 Thread Ellery Newcomer via Digitalmars-d-learn

On 12/16/2014 10:41 AM, Sean Kelly wrote:

On Tuesday, 16 December 2014 at 04:56:10 UTC, Ellery Newcomer wrote:

If I have a thread that I need to detach from druntime, I can call
thread_detachInstance, but for 2.066, this function does not exist. Is
there any way to do this in 2.066? I notice there is a
thread_detachByAddr, but I'm not sure how to get a ThreadAddr out of a
Thread..


thread_detachThis?


the thread I want to detach isn't currently running.


detaching a thread from druntime 2.067

2014-12-15 Thread Ellery Newcomer via Digitalmars-d-learn
If I have a thread that I need to detach from druntime, I can call 
thread_detachInstance, but for 2.066, this function does not exist. Is 
there any way to do this in 2.066? I notice there is a 
thread_detachByAddr, but I'm not sure how to get a ThreadAddr out of a 
Thread..


Re: threading issues with D - C - Python

2014-12-07 Thread Ellery Newcomer via Digitalmars-d-learn

On 12/07/2014 03:12 PM, Michael wrote:

On Saturday, 6 December 2014 at 00:40:49 UTC, Ellery Newcomer wrote:

On 12/04/2014 10:55 PM, Ellery Newcomer wrote:


I guess tomorrow I can try messing around with thread_attachThis, as the
fullcollect happening in #2 might be screwing with python data. But you
aren't really passing anything from python to d or vice versa, so I'm
not sure why the gc would need to know about the python threads.


by gum, thread_attachThis and thread_detachThis fix the issue!

now to figure out how to use them in the general case.


This is great.. Thank you. I'm looking forward to being able to try the
finished result.


It would be great if there were some convenient hook in python to stick 
these calls. Near as I can tell, there isn't. That leaves you with 
either explicitly calling attach and detach with an exposed api, or pyd 
obsessively checking whether the current thread is registered.


Actually, I suppose with a thread local flag the latter wouldn't be too bad.

Mind if I incorporate your example into pyd's test suite?


Re: threading issues with D - C - Python

2014-12-05 Thread Ellery Newcomer via Digitalmars-d-learn

On 12/04/2014 10:55 PM, Ellery Newcomer wrote:


I guess tomorrow I can try messing around with thread_attachThis, as the
fullcollect happening in #2 might be screwing with python data. But you
aren't really passing anything from python to d or vice versa, so I'm
not sure why the gc would need to know about the python threads.


by gum, thread_attachThis and thread_detachThis fix the issue!

now to figure out how to use them in the general case.



Re: threading issues with D - C - Python

2014-12-04 Thread Ellery Newcomer via Digitalmars-d-learn

On 12/04/2014 02:11 PM, Michael wrote:

On Thursday, 4 December 2014 at 03:22:05 UTC, Ellery Newcomer wrote:


dustmite?


Not sure what went wrong with dustmite, but every time I tried it it
just started deleting all the files in the directory and setup.py would
give errors. I manually deleted a reasonable chunk of the code and I'm
left with these files which still seem to cause segfaults:

Main code: http://pastebin.com/zqgNTk9w
PyD definitions: http://pastebin.com/6mRH3KZZ
setup.py: http://pastebin.com/i9Ph78UC
test code that causes segfaults: http://pastebin.com/1ukzShVh

Cheers,
Michael.


hmm.. looks like here it originates in python when it tries to acquire 
the GIL. specifically, pthread_cond_timedwait is segfaulting.


in your code, execution inside a python thread makes it to 
receiveTimeout in get_image. it made it past receiveTimeout in acquire.


then I guess there is a context switch. the main python thread throws an 
exception, but a number of things trigger the segfault. I think it's 
just the interpreter loop calling RestoreThread. backtrace looks like


#0  pthread_cond_timedwait@@GLIBC_2.3.2 ()
at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S:238
#1  0x003799d07bb3 in PyCOND_TIMEDWAIT (cond=0x379a063220 gil_cond,
mut=0x379a0631e0 gil_mutex, us=5000)
at /usr/src/debug/Python-3.3.2/Python/condvar.h:103
#2  take_gil (tstate=tstate@entry=0x604410)
at /usr/src/debug/Python-3.3.2/Python/ceval_gil.h:224
#3  0x003799d081fb in PyEval_RestoreThread 
(tstate=tstate@entry=0x604410)

...

It looks like this is the python main thread.

I see two other threads. (i took out one of your python spawns) #2 looks 
to be your listener thread. std.concurrency.send seems to have gotten it 
into a gc_malloc, but it looks like it's just waiting. it's currently in 
sem_wait. this one would have been spawned in D code by #3


#3 is your other python thread. it is also in pthread_cond_timedwait. by 
its stack trace, receiveTimeout is just waiting.



I guess tomorrow I can try messing around with thread_attachThis, as the 
fullcollect happening in #2 might be screwing with python data. But you 
aren't really passing anything from python to d or vice versa, so I'm 
not sure why the gc would need to know about the python threads.


not exactly my area of expertise, this.


Re: threading issues with D - C - Python

2014-12-03 Thread Ellery Newcomer via Digitalmars-d-learn

On 12/03/2014 04:43 PM, Michael wrote:

On Wednesday, 3 December 2014 at 21:35:48 UTC, ketmar via
Digitalmars-d-learn wrote:

ah, dsource strikes back! that vile site keep biting us again and
again. let's hope that new admins will kill it for good.


Yeah. I've got the new PyD and it compiles and does everything I want
much nicer, but it appears to have the exact same problems. When calling
a python thread to my code, it can cause segfaults and hanging issues.

Cheers,
Michael.


okay. that's not too surprising.

If you can get me a minimal example, I'd be happy to have a look since 
pyd should probably support this case.


Re: threading issues with D - C - Python

2014-12-03 Thread Ellery Newcomer via Digitalmars-d-learn

On 12/03/2014 06:56 PM, Michael wrote:

On Thursday, 4 December 2014 at 02:31:51 UTC, Ellery Newcomer wrote:


okay. that's not too surprising.

If you can get me a minimal example, I'd be happy to have a look since
pyd should probably support this case.


Cool. Unfortunately most of the times I've attempted to reduce this down
it always seems to work, but I think that's because I often did the
example code in D. I'll play around with it and try to send you an example.

Cheers,
Michael.


dustmite?


Re: threading issues with D - C - Python

2014-12-02 Thread Ellery Newcomer via Digitalmars-d-learn

On 12/02/2014 05:07 PM, Michael wrote:

Hi. I'm new here and this is my first post. I'm not sure this is the
right subforum for it, but wasn't sure where else to put it either.

I've written a library to talk to some external hardware using a socket.
It uses the std.concurrency threads to send messages between the main
D-object for the hardware and the D-object for the sockets. I then
wanted to be able to call these functions from Python. PyD appeared to
be out of date, so I've been using a D - C interface, and a C - Python
interface. The python code will often run from different python threads,
so I then added yet another message-passing layer between the D-C
interface and the D-hardware interface.



are you looking at this pyd: https://bitbucket.org/ariovistus/pyd



Re: building shared library from D code to import into cython

2014-10-12 Thread Ellery Newcomer via Digitalmars-d-learn

On Sunday, 12 October 2014 at 16:07:19 UTC, Laeeth Isharc wrote:
Any thoughts on speed in 2014  of pyd vs using cython to talk 
to D directly via C/C++ interface?  I saw this old coment here:




pyd is basically just a convenience layer on top of the C 
interface. The part that would most likely screw with performance 
would be conversion from D objects to python objects and vice 
versa since that normally does a value copy. At the time of that 
comment, pyd's strategy for arrays was just iterate and convert 
each element. Now pyd can take advantage of the buffer protocol 
if it is exposed (2.7+), so converting e.g. numpy arrays should 
be just a memcopy.


If you want by ref semantics instead of by value, use PydObject 
instead of a D type in your function signature. You can also turn 
off all conveniences and just use the C api with raw_only 
(https://bitbucket.org/ariovistus/pyd/wiki/CeleriD)


Re: building shared library from D code to import into cython

2014-10-09 Thread Ellery Newcomer via Digitalmars-d-learn

On Wednesday, 8 October 2014 at 00:25:57 UTC, Laeeth Isharc wrote:

Hi.

Thanks for the quick response.

The -defaultlib was left around from trying all kinds of 
combinations of dmd and gcc.  I am not used to gcc, and it will 
take me some time to become properly acquainted with all the 
options.




I managed to get it to compile with default dmd rpm:

https://github.com/ariovistus/cythonic_d

fedora 20, x86_64

Are you aware of pyd? (https://bitbucket.org/ariovistus/pyd)

It knows how to build shared libraries, so I recommend you play 
with it, if only to watch how it does that. Biggest gotcha is 
starting up druntime.


how to tell if a thing is a template

2014-08-23 Thread Ellery Newcomer via Digitalmars-d-learn

Can't think off the top of my head how you do this

template IsTemplate(alias t) {
 ??
}

static assert(IsTemplate!IsTemplate)


Re: Something like Python's psutils for D?

2014-07-12 Thread Ellery Newcomer via Digitalmars-d-learn

On Saturday, 12 July 2014 at 08:34:41 UTC, Thomas Mader wrote:
The Subject says it all, is something like psutils available in 
D?


would psutils itself be acceptable?

https://bitbucket.org/ariovistus/pyd


Re: C++'s defaulted comparison operators proposal

2014-06-18 Thread Ellery Newcomer via Digitalmars-d-learn

On Wednesday, 18 June 2014 at 05:49:30 UTC, Ali Çehreli wrote:
Can you come up with a D library solution to the following 
C++11 proposal:


  
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3950.html




did this years ago (or something similar, at least):
https://bitbucket.org/ariovistus/multi_index/src/0993f8604c1438f6d9f26f580939b42fdd159a67/src/multi_index.d?at=default#cl-4654

example:

https://bitbucket.org/ariovistus/multi_index/src/0993f8604c1438f6d9f26f580939b42fdd159a67/unittests/multi_compare.d?at=default


Re: Linking with C on Windows

2014-06-05 Thread Ellery Newcomer via Digitalmars-d-learn

On Thursday, 5 June 2014 at 23:12:56 UTC, Mark Isaacson wrote:


I need to eventually be able to export a
dll that can talk with anything.


how would using dmc conflict with this goal?

dmd/dmc output omf object files, windows infrastructure is all 
coff object files. linux/mingw/etc are.. something else..


your options are

1. use dmd/dmc, and if you need to link to windows api dlls or 
others, use coffimplib (here - ftp://ftp.dlang.org/) to convert 
the appropriate lib files.


2. if you can stomach the loss of generality, use dmd -m64, which 
does output coff object files and go your merry way with vc++. (I 
don't do this, so don't quote me on this)


3. use the mingw builds of ldc/gcc (I don't do this either and 
can't comment on how much fun you'll have getting dlls out of 
them/linking to other dlls)




Re: Using D static library from C

2014-06-05 Thread Ellery Newcomer via Digitalmars-d-learn

On Thursday, 5 June 2014 at 18:51:25 UTC, George Sapkin wrote:
I'm trying to link a simple D static library to C code, but I'm 
can't figure out how to do it properly without getting a 
segfault when running it.


try this:

dmd -lib test.d -defaultlib=libphobos2.a -oflibtest.a
gcc main.c libtest.a -l:libphobos2.a -lpthread -lm -lrt


Re: Using D static library from C

2014-06-05 Thread Ellery Newcomer via Digitalmars-d-learn

On Friday, 6 June 2014 at 02:17:50 UTC, George Sapkin wrote:

On Friday, 6 June 2014 at 02:13:08 UTC, Ellery Newcomer wrote:

On Thursday, 5 June 2014 at 18:51:25 UTC, George Sapkin wrote:
I'm trying to link a simple D static library to C code, but 
I'm can't figure out how to do it properly without getting a 
segfault when running it.


try this:

dmd -lib test.d -defaultlib=libphobos2.a -oflibtest.a
gcc main.c libtest.a -l:libphobos2.a -lpthread -lm -lrt


Awesome! That works! Thanks.
So is dmd linking to shared/different phobos2 by default or 
something?


yeah, -defaultlib=libphobos2.so is the other option, I guess it's 
default now.


Re: dxl (the d port of jexcelapi)

2014-05-22 Thread Ellery Newcomer via Digitalmars-d-learn

On Thursday, 8 May 2014 at 20:57:08 UTC, Taylor Hillegeist wrote:
So i was thinking i wonder if anyone has a d library for excel 
and behold there it was. however, it seems like d has grown 
since this was written.


I'm getting bunches of errors telling me that i can't override 
a function without the override keyword. which is not a big 
deal, however I seem to be missing libraries.


std.date; cannot be found :(
is this equivalent to std.datetime?

dcollections.LinkList; I found it but should i use It? is there 
not something in std.containers; that would replace it?


Last I used std.containers (which admittedly has been a few 
years), I developed a pretty deep distrust of DList. Personally, 
I would use multi_index, but you are probably better off sticking 
with dcollections. unless steve hasn't been maintaining it..


Also, I'm the author/porter of dxl. I think I quit maintaining it 
because I was waiting for the new io api, which I guess still 
hasn't happened. I don't really have time to work on it right 
now, but if you have questions, feel free to ask.


string - string literal

2014-04-20 Thread Ellery Newcomer via Digitalmars-d-learn
is there a function in phobos anywhere that takes a string and 
escapes it into a string literal suitable for string mixins? 
something like


assert (f(abc\ndef) == \abc\\ndef\);


Re: Python calling D

2014-02-06 Thread Ellery Newcomer

On Tuesday, 4 February 2014 at 16:17:30 UTC, Russel Winder wrote:

On Tue, 2014-02-04 at 12:45 +, Artem Tarasov wrote:

But it does lead to a working system :-)


Any particular reason you aren't using CeleriD to build this 
shared lib? CeleriD uses some hooks to call rt_init when the 
library loads.


https://bitbucket.org/ariovistus/pyd/src/92b9962b429ed33afa7048cf1923fd76d0fe8977/infrastructure/d/?at=default

see so_ctor.c and python_so_linux_boilerplate.d

Also, note however you do it, if you have multiple shared libs, 
don't call initialize/term more than once. segfaults happen.


Re: Python calling D

2014-02-01 Thread Ellery Newcomer

On Sunday, 26 January 2014 at 14:17:18 UTC, Russel Winder wrote:

On Sun, 2014-01-26 at 12:11 +, Russel Winder wrote:
[…]

However with Python 2 the example from:

   https://bitbucket.org/ariovistus/pyd/wiki/QuickStart

leads to:



This all sounds suspiciously like stuff I thought I'd already 
fixed. see


https://bitbucket.org/ariovistus/pyd/issue/15/some-issues-getting-pyd-to-work


Re: Python calling D

2014-02-01 Thread Ellery Newcomer

On Saturday, 1 February 2014 at 22:02:24 UTC, Russel Winder wrote:


My problem of the moment is segmentation faults during 
execution, and I

have no model of how to go about providing useful data to debug
this :-((


It wouldn't by any chance be related to

https://bitbucket.org/ariovistus/pyd/issue/17/it-seems-py_incref-missed-when-pydobject

would it?


Re: Python calling D

2014-01-25 Thread Ellery Newcomer

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


Re: Shared library: loading doesn't call shared static this

2013-12-08 Thread Ellery Newcomer

On Sunday, 8 December 2013 at 10:31:32 UTC, Mathias LANG wrote:


Thank you, and yazd, it did the trick.
May I ask why I don't want to call it multiple time though ?
From the sentence If the runtime was already successfully 
initialized this returns true., I though this was handled in 
some way. Or do you mean, multiple time in case of multiple 
libraries ?


rt_term at least will [did] segfault when you call it a second 
time. So just don't have N shared libs each with a ctor calling 
rt_init and dtor calling rt_term.


Re: how to compose delegate type

2013-12-08 Thread Ellery Newcomer

On Sunday, 8 December 2013 at 00:43:51 UTC, Jesse Phillips wrote:


What is wrong with the current template which returns an 
immutable delegate type? It still store you're immutable member 
function.


It composes the wrong type. It composes a type that has different 
constness than the target type, which will likely cause problems 
due to transitive const.


Anyways, I'm trying to find a workaround to

https://d.puremagic.com/issues/show_bug.cgi?id=11694



Re: Shared library: loading doesn't call shared static this

2013-12-07 Thread Ellery Newcomer

On Saturday, 7 December 2013 at 20:11:15 UTC, Mathias LANG wrote:

afaik, druntime does not officially support the C main, D shared 
library use case yet.


If you have only 1 D shared library, you can insert calls to 
rt_init and rt_term into shared lib constructors/dtors with gcc. 
This has worked for me in pyd:


https://bitbucket.org/ariovistus/pyd/src/32cf9709d711/examples/misc/dmd_sharedlibs/?at=default

You don't want to be calling rt_init or rt_term multiple times, 
though.


Re: how to compose delegate type

2013-12-07 Thread Ellery Newcomer
On Saturday, 7 December 2013 at 19:36:50 UTC, Jesse Phillips 
wrote:


This declaration doesn't make sense to me:

string a() immutable {
return  1;
}


http://dlang.org/class.html#member-functions


Re: how to compose delegate type

2013-12-06 Thread Ellery Newcomer

On 12/05/2013 09:33 PM, Jesse Phillips wrote:


I don't think I understand what you mean:


this code illustrates it:

class Z {
string a() immutable {
return  1;
}
string b() {
return 2;
}
}

template F(t) {
alias immutable(t) F;
}
alias typeof(Z.init.a) Texpected;
alias typeof(Z.init.a) T;

static assert(is(F!(T) == Texpected));

void main() {}



above F doesn't work; immutable(void delegate()) and void delegate() 
immutable are different types (I think the latter means 'this' is 
immutable).
If t were a function pointer, you would apply the immutable to the 
pointer target like so:


alias immutable(pointerTarget!t)* F




how to compose delegate type

2013-12-05 Thread Ellery Newcomer

how do I construct F!(T) to yield

void delegate() immutable

when T is void delegate()

?

[its been a long day]


core.sys.posix.termios

2013-11-23 Thread Ellery Newcomer

is there any particular reason it is missing

B115200

and friends?


Re: Red-Black tree storing color without additional memory requirements

2013-11-20 Thread Ellery Newcomer

On 11/20/2013 06:50 AM, bearophile wrote:

safety0ff:


Since the GC supports interior pointers, I think you can justify using
the least significant bits as long as the size and alignment of the
pointed object guarantee that the pointer + tag will always lie inside
the memory block.


From:
http://dlang.org/garbage.html


Do not take advantage of alignment of pointers to store bit flags in
the low order bits:


Bye,
bearophile


ha. I did this with steve's rb tree. hasn't bit me yet.


Re: bitwise operation and type

2013-11-20 Thread Ellery Newcomer

On 11/20/2013 11:21 PM, bioinfornatics wrote:

why this fail http://www.dpaste.dzfl.pl/a6d6acf4


as with c, most of the integer operators return int for integral types 
smaller than int. also, this is a case where


a += b

does something different than

a = a + b

i guess the former automatically inserts a cast or something.



I want to works with ubyte -  
i do not want use int for manipulating these byte and consume more
memory as need!


tough. use a cast.


Re: bidirectional map

2013-11-12 Thread Ellery Newcomer

On 11/11/2013 05:14 PM, bioinfornatics wrote:

Dear,
I am looking for a bidirectional map i.e
http://en.wikipedia.org/wiki/Bidirectional_map

My seach into D documentation seem to said to me that this structure is
not implemented.

Something like (for primary idea):


struct BidirectionalMap(T,U){
 private:
 T[U] _forwardHash;
 U[T] _reverseHash;

 public:

 @safe
 void opIndeyAssign( T k, U v){ // pure?
 _forwardHash[k] = v;
 _reverseHash[v] = k;
 }


 @property
 BidirectionalMap!(T,U) dup(){
 return BidirectionalMap!(T,U)( this );
 }
}


you could build one using multi_index.

https://bitbucket.org/ariovistus/multi_index

at least, that is how boost::bimap was done. I always assumed it would 
be trivial in D, but I haven't tried doing it. Something like


alias MultiIndexContainer!(Tuple!(T,t,U,u), 
IndexedBy!(HashedUnique!(a.t), HashedUnique!(a.u))) BiMap;


and then wrap as you see fit.


Re: spurious gc allocation

2013-11-09 Thread Ellery Newcomer

On 11/09/2013 12:35 AM, lomereiter wrote:

Indeed, disassembly reveals an allocation (with all three compilers =
it's the front-end which generates this crap).


ouch.



I guess the compiler incorrectly treats { node.value; } as a delegate
and copies the node to GC heap.

void foo() {
 int* node = null;
 enum mutable = __traits(compiles, {node.value ;});
}

void main() {
 foo();
}


oh, I see, it's the delegate doing that. that's helpful.


https://d.puremagic.com/issues/show_bug.cgi?id=11483


Re: spurious gc allocation

2013-11-08 Thread Ellery Newcomer

On 11/08/2013 06:19 AM, Timon Gehr wrote:

On 11/08/2013 07:12 AM, Benjamin Thaut wrote:



The problem is that you define the struct Thing as a inner struct.


struct Thing only exists in the decompiled version, not in the original
source. So far it looks like a bug to me.


I've reduced it to the following:

a.d:
class C
{
void _InsertAllBut(int v) {
int* node = null;
enum mutable = __traits(compiles, {node.value ;});
}

}

test.d:
import a;

void main () {
C c = new C();
c._InsertAllBut(1);
}


compile:

dmd test.d a.d

order doesn't seem to matter, works with -m32 and -m64, apparently I am 
running dmd v2.063-devel-e23c785


objdump -d --disassembler-options=intel test | ddemangle

shows me

...
00417888 void a.C._InsertAllBut(int):
  417888:   55  push   rbp
  417889:   48 8b ecmovrbp,rsp
  41788c:   48 83 ec 38 subrsp,0x38
  417890:   53  push   rbx
  417891:   48 89 7d f0 movQWORD PTR [rbp-0x10],rdi
  417895:   48 bf 10 00 00 00 00movabs rdi,0x10
  41789c:   00 00 00
  41789f:   e8 10 22 00 00  call   419ab4 _d_allocmemory
  4178a4:   48 89 45 e0 movQWORD PTR [rbp-0x20],rax
  4178a8:   48 8b 4d f0 movrcx,QWORD PTR [rbp-0x10]
  4178ac:   48 89 08movQWORD PTR [rax],rcx
  4178af:   48 85 c9test   rcx,rcx
...


can anyone confirm?


spurious gc allocation

2013-11-07 Thread Ellery Newcomer

hello all.

I have a class member function that essentially looks like this:

ThisNode* _InsertAllBut(int value) {
ThisNode* node = MallocAllocator.allocate!(ThisNode)(1);
node.value = value;
node_count++;
return node;
}


I compile it on x86_64 and the compiler inserts a gc allocation.

I decompiled it, and it looks like it does this:

  ThisNode* _InsertAllBut(int value) {
  struct Thing {
  typeof(this) thing1;
  ThisNode* thing2;
  int thing3;
  }
  Thing* rbp28 = _d_allocmemory(0x14);
  rbp28.thing1 = this;
  rbp28.thing3 = value;
  if (this == 0) {
  // not wasting my time figuring out _d_assert_msg's calling 
conventions

  r8d = 0x137c;
  rcx = something pointing to src/multi_index.d;
  rdi = {length associated with rsi};
  rsi = something pointing to null this;
  rdx = {length associated with rcx};
  _d_assert_msg();
  }
  invariant._d_invariant(this);
  rbp28.thing2 = MallocAllocator.allocate(1);
  rbp28.thing2.value = rbp28.thing3;
  this.nodecount ++;
  return rbp28.thing2;
  }


So. Why the heck is it using heap space for stack space? How the heck am 
I supposed to call this from within a destructor?


Re: PyD status and tutorials

2013-09-04 Thread Ellery Newcomer

On Saturday, 31 August 2013 at 15:44:03 UTC, Russel Winder wrote:

On Sat, 2013-08-31 at 12:56 +0200, Larry wrote:

Ok python3-dev was missing.


Are you using Python 3.3?

Are you using SCons or Tup for the build?

I just tried the SCons build OOTB and it fails to build PyD 
with DMD :-(


Ehh, yeah. I gave up on build systems a while back because it 
made it unnecessarily complicated to set up test vms for more 
exotic systems. Now we use


python setup.py [build|install]

because python's always there. OP has that right.

Since I've been out of the loop for a while, can gdc build shared 
libraries yet? That's what OP's build command is trying to do.


Re: DLLs: Cleaning up

2013-07-17 Thread Ellery Newcomer

On 07/17/2013 08:13 AM, Chris wrote:


with some nasty surprises as regards obtaining
(valid) paths on Windows as opposed to Linux / Mac.


Do tell.


(Any time and life saving advice about linking to other libraries / DLLs?)

Thanks everyone!


celerid should be up to the task.


Re: DLLs: Cleaning up

2013-07-15 Thread Ellery Newcomer

On 07/15/2013 07:18 AM, Chris wrote:

doesn't work with newer versions of dmd


does too. (I'm the maintainer)

https://bitbucket.org/ariovistus/pyd



getter/setter in one function (almost)

2013-07-15 Thread Ellery Newcomer


unfortunately, dmd doesn't accept the signature as a valid property.



import std.stdio;
import std.typecons;

struct T {
int _i;

@property int i(Nullable!int derp = Nullable!int.init) {
return _i = derp.isNull ? _i : derp.get;
}
}
void main () {
T t;
t.i = 1;
writeln(t.i);
}




Re: DLLs: Cleaning up

2013-07-14 Thread Ellery Newcomer

On 07/11/2013 05:58 AM, Chris wrote:

I have a DLL written in D I load into a Python application via ctypes
like so:

lib = CDLL(mydll)

The DLL loads and can be used no problem. However, once the DLL is
discarded of by the program, the program either doesn't react or
crashes. I still haven't worked out how to clean up the DLL correctly
before it is unloaded / detached (from Python). I guess it's the GC
and/or some C stuff I've overlooked. I have tried both approaches
described on this page: http://dlang.org/dll.html.

Maybe someone of yous once had a similar problem and found a solution.
Any hints or suggestions would be appreciated. Thanks.


hmm. pyd uses the example under 'DLLs with a C Interface' for its 
windows dll code and it seems pretty stable, but then it doesn't use 
ctypes. It doesn't look like you need to be mucking with rt_init and 
rt_term, so maybe the garbage collector is trying to collect something 
that python still has a reference to?


Also, if you can finagle a dll out of gdc I would love to hear about it. 
I have not used it on windows, though.


Re: How can i increase max number recursive template expansions?

2013-07-10 Thread Ellery Newcomer

On 07/07/2013 01:22 PM, John Colvin wrote:

On Sunday, 7 July 2013 at 19:55:26 UTC, QAston wrote:

I have a large enum in my code (opcodes for a protocol) - using
std.traits.EnumMembers gives me a recursive template error.

How can i increase max number recursive template expansions?


I don't think you can. Please file a bug report: even though it might
not get fixed any time soon (other than maybe just upping the
threshold), there is talk of enabling more imperative-style programming
in templates at the moment, and this would be a good case for it.



or feel free to commandeer this one

http://d.puremagic.com/issues/show_bug.cgi?id=6471



Re: [Question] Could a function return a list of arguments to call another function?

2013-06-28 Thread Ellery Newcomer

On 06/28/2013 11:07 AM, MattCoder wrote:

Hi,

I would like to know if it's possible to pass the return of a function
as argument to another function as below:

import std.stdio;

auto foo(int x, int y){
 writeln(x, y);
 return 3, 4;
}

void main(){
 foo(foo(1,2));
}

I would like to print:
1 2
3 4

PS: I tried return a tuple but it doesn't works.

Thanks,

Matheus.


No, functions cannot return tuples.

However, they can return std.typecons.Tuple, so you could do this:

auto foo(int i, int j) {
writeln(i,  , j);
return tuple(3,4);
}
void main() {
foo(foo(1,2).field);
}



Re: how to reflect on function attributes

2013-06-05 Thread Ellery Newcomer

On 06/05/2013 12:02 AM, Jonathan M Davis wrote:

On Wednesday, June 05, 2013 08:52:35 lomereiter wrote:

This doesn't work when the method is marked as @property. Any
idea why is that so?

On Wednesday, 5 June 2013 at 02:19:38 UTC, Jonathan M Davis wrote:

is(typeof(A.func) == const)

- Jonathan M Davis


I don't know. My first guess would be that it thought that it was calling it
except that it's being referenced by the type, not by an instance, so that
doesn't really make sense.

- Jonathan M Davis


P.S. Please don't top-post. It makes it harder to follow posts and is
generally considered bad newsgroup etiquette.





pragma(msg, is(FunctionTypeOf!(A.func) == const));


how to reflect on function attributes

2013-06-04 Thread Ellery Newcomer

specifically, const, eg.

class A { void func() const { blah } }

std.traits.FunctionAttributes makes no mention of it


Re: how to reflect on function attributes

2013-06-04 Thread Ellery Newcomer

On 06/04/2013 07:19 PM, Jonathan M Davis wrote:

On Tuesday, June 04, 2013 19:03:47 Ellery Newcomer wrote:

specifically, const, eg.

class A { void func() const { blah } }

std.traits.FunctionAttributes makes no mention of it


is(typeof(A.func) == const)

- Jonathan M Davis



I think that is for type only. It returns false for me.


Re: how to reflect on function attributes

2013-06-04 Thread Ellery Newcomer

On 06/04/2013 07:43 PM, Jonathan M Davis wrote:

On Tuesday, June 04, 2013 19:23:45 Ellery Newcomer wrote:

On 06/04/2013 07:19 PM, Jonathan M Davis wrote:

On Tuesday, June 04, 2013 19:03:47 Ellery Newcomer wrote:

specifically, const, eg.

class A { void func() const { blah } }

std.traits.FunctionAttributes makes no mention of it


is(typeof(A.func) == const)

- Jonathan M Davis


I think that is for type only. It returns false for me.


What do you mean for type only? const is part of the type. What else would it
be part of? For the code example that you gave (minus the blah in the middle),
it returns true.

- Jonathan M Davis



Ah, you're right. don't know how I screwed that up.


Re: how to reflect on function attributes

2013-06-04 Thread Ellery Newcomer


Ah, you're right. don't know how I screwed that up.


Yes I do. I was trying to use typeof(A.func)


Re: more fun with ubuntu

2013-05-26 Thread Ellery Newcomer

On 05/25/2013 10:20 PM, estew wrote:

On Sunday, 26 May 2013 at 05:01:10 UTC, Ellery Newcomer wrote:

I have a project here which fails on link on ubuntu 12.10.

It give undefined reference errors for functions in libdl and libutil.
For some reason, ld won't cooperate unless you pass -ldl -lutil at the
end of the command string. Holy Ubuntu!

I can't seem to get dmd to do this though. Any suggestions?

I am using the beta, but apparently this is a thing with ubuntu.


I have the same on Fedora 18 using derelict and some other D libs which
I can't remember right now. My understanding is derelict requires libdl
for dynamic loading of libs at runtime.

My compiler flags are similar to this:

dmd -gc -w -Iderelict_import_dir -L-Lderelict_lib_dir -L-lDerelictGL3
-L-lDerelictGLFW3 -L-lDerelictUtil -L-lGL -L-lGLU -L-lglfw -L-ldl myapp.d

Could you post your compiler command line?

Cheers,
Stewart


huh. I haven't run into it on fedora. python is built differently, though.

dmd -L-lpthread -L-ldl -L-lutil -L-L/usr/lib -L-lz 
/usr/lib/python2.7/config/libpython2.7.a -debug 
-ofbuild/lib.linux-x86_64-2.7/link {lotsaobjectfiles} -L-ldl -L-lutil -v


Re: more fun with ubuntu

2013-05-26 Thread Ellery Newcomer

On 05/26/2013 07:55 AM, Jesse Phillips wrote:

On Sunday, 26 May 2013 at 05:01:10 UTC, Ellery Newcomer wrote:

I have a project here which fails on link on ubuntu 12.10.

It give undefined reference errors for functions in libdl and libutil.
For some reason, ld won't cooperate unless you pass -ldl -lutil at the
end of the command string. Holy Ubuntu!

I can't seem to get dmd to do this though. Any suggestions?

I am using the beta, but apparently this is a thing with ubuntu.


It is not uncommon to request the libraries needed to build your app.
Dmd passes a couple/one for phobos dependencies, but other libraries
need to be reqested.


I am doing that.

I think the problem is libpython2.7.a requires libdl and libutil, and ld 
requires -ldl and -lutil be positioned after libpython2.7.a, but dmd 
very stubbornly arranges them before libpython2.7.a in the call to gcc.


Re: more fun with ubuntu

2013-05-26 Thread Ellery Newcomer

On 05/26/2013 08:10 AM, Ellery Newcomer wrote:

On 05/26/2013 07:55 AM, Jesse Phillips wrote:

On Sunday, 26 May 2013 at 05:01:10 UTC, Ellery Newcomer wrote:

I have a project here which fails on link on ubuntu 12.10.

It give undefined reference errors for functions in libdl and libutil.
For some reason, ld won't cooperate unless you pass -ldl -lutil at the
end of the command string. Holy Ubuntu!

I can't seem to get dmd to do this though. Any suggestions?

I am using the beta, but apparently this is a thing with ubuntu.


It is not uncommon to request the libraries needed to build your app.
Dmd passes a couple/one for phobos dependencies, but other libraries
need to be reqested.


I am doing that.

I think the problem is libpython2.7.a requires libdl and libutil, and ld
requires -ldl and -lutil be positioned after libpython2.7.a, but dmd
very stubbornly arranges them before libpython2.7.a in the call to gcc.



dmd -unittest -property -debug -gc  -version=Python_2_7_Or_Later 
-version=Python_2_6_Or_Later -version=Python_2_5_Or_Later 
-version=Python_2_4_Or_Later -L-ldl 
/usr/lib/python2.7/config/libpython2.7.a  object_.d -ofobject_.x 
-I../../infrastructure/  -L-ldl -L-lutil -v



dmd turns the above into:

gcc object_.o -o object_.x -g -m64 -ldl -ldl -lutil 
-L/usr/lib/x86_64-linux-gnu -L/usr/lib/i386-linux-gnu -Xlinker 
--no-warn-search-mismatch -Xlinker --export-dynamic 
/usr/lib/python2.7/config/libpython2.7.a -l:libphobos2.a -lpthread -lm -lrt


which fails, but


gcc object_.o -o object_.x -g -m64 -ldl -ldl -lutil 
-L/usr/lib/x86_64-linux-gnu -L/usr/lib/i386-linux-gnu -Xlinker 
--no-warn-search-mismatch -Xlinker --export-dynamic 
/usr/lib/python2.7/config/libpython2.7.a -l:libphobos2.a -lpthread -lm 
-lrt -ldl -lutil


works.


more fun with ubuntu

2013-05-25 Thread Ellery Newcomer

I have a project here which fails on link on ubuntu 12.10.

It give undefined reference errors for functions in libdl and libutil. 
For some reason, ld won't cooperate unless you pass -ldl -lutil at the 
end of the command string. Holy Ubuntu!


I can't seem to get dmd to do this though. Any suggestions?

I am using the beta, but apparently this is a thing with ubuntu.


Re: equivalent of __attribute__((constructor))

2013-05-24 Thread Ellery Newcomer

On 05/23/2013 11:39 PM, Jacob Carlborg wrote:

On 2013-05-24 02:02, Ellery Newcomer wrote:


posix.mak makes no reference to it


Then I guess it's not used. Just compile it manually and link with it. I
don't think that D has anything corresponding to
__attribute__((constructor)). I also see a problem with adding such
feature. It will be run before the runtime is initialized (that's how it
works now). Then people will start using it and complain about there
code failing in mysterious ways because the runtime isn't initialized.



so don't document it :)


Re: equivalent of __attribute__((constructor))

2013-05-23 Thread Ellery Newcomer

On 05/22/2013 11:18 PM, Jacob Carlborg wrote:

On 2013-05-23 06:27, Ellery Newcomer wrote:

I don't know if it's automatically linked but here you go:

https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dylib_fixes.c




posix.mak makes no reference to it


equivalent of __attribute__((constructor))

2013-05-22 Thread Ellery Newcomer

In the context of shared libraries, with gcc

__attribute__((constructor))
void myfunc() { .. }

is used to make myfunc be called upon loading of the shared library (you 
can tell I know what I am talking about here) via some field in the ELF 
headers, apparently. Is there any way to get our trusty d compilers to 
do the equivalent?


Sure, Ellery, we have this awesome feature called module constructors. 
Check em out.


Ehh, I would be using this to initialize druntime...

You could just define _init, couldn't you?

Yes, but there is only one _init, while the above can be used with 
multiple functions and thus wouldn't inadvertently cause important code 
to not run. If I don't have to, I'd rather not.


Wait, why are you initializing druntime?

Because druntime isn't set up to do it yet for c main calling d shared 
lib. You'd think it would need the same sort of functionality when it 
does implement it, though.


foo is not an lvalue

2013-04-17 Thread Ellery Newcomer

void main() {
foo!();
}

template foo( ) {
void foo() {
auto a = (foo);
}
}

dmd from master (a few days ago) gives:

 Error: foo()() is not an lvalue


wut?


Re: foo is not an lvalue

2013-04-17 Thread Ellery Newcomer

On 04/17/2013 06:02 PM, bearophile wrote:

Ellery Newcomer:


dmd from master (a few days ago) gives:

 Error: foo()() is not an lvalue


wut?


I think you need to write:

auto a = foo!();

Bye,
bearophile


wouldn't that be infinitely recursing template instantiation?


Re: PyD status and tutorials

2013-04-03 Thread Ellery Newcomer

Hi.

Yes, the bitbucket repo is up to date (or was, a month ago. I've been a 
bit busy..).


It looks like you want to embed python into D, in which case the 
situation is better than the main page suggests. Pyd supports


* CPython - 2.4 through 3.2
* dmd 2.060+
* ldc {whatever is based on dmdfe 2.060+}

on linux.

Somehow I still haven't gotten around to building gdc yet, but 
supporting gdc for embedding python would just be a matter of updating 
the CeleriD configurations and ensuring everything links. Might as well 
do that tonight. Stay tuned.


Pyd is pretty reliable. I try to avoid making changes to the API, but 
there were a few when I implemented python3 support. There will probably 
be a few more when I tackle PyPy.


On 04/03/2013 05:27 AM, Joseph Rushton Wakeling wrote:

Hello all,

Can anyone advise on where things stand with PyD, in terms of Python version(s)
supported, D version(s) supported, general up-to-dateness and stability?

The writeups on the Dsource page http://pyd.dsource.org/ look like they
haven't been maintained in a long time, so I presume the Bitbucket repo is now
the current up-to-date location?
https://bitbucket.org/ariovistus/pyd

According to that page it's supported on Linux with Python 2.7 and LDC, with GDC
status unknown.  Are the support issues here down to backend, or is it the
frontend version that matters?  Is it possible to link against PyD built with
LDC with D code built with GDC?

Also, given that the API is being updated, how reliable/stable are PyD/CeleriD
right now?

Finally, any advice on uninstallation/installing new versions when the source is
updated?  Python novice here. :-)

For those who are curious, my particular interest is in using this library in
conjunction with D: http://networkx.github.com/  Don't suppose anyone has
already tried this and has experience to share?

Thanks  best wishes,

 -- Joe





Re: PyD status and tutorials

2013-04-03 Thread Ellery Newcomer

On 04/03/2013 05:58 PM, Ellery Newcomer wrote:


Somehow I still haven't gotten around to building gdc yet, but
supporting gdc for embedding python would just be a matter of updating
the CeleriD configurations and ensuring everything links. Might as well
do that tonight. Stay tuned.



Actually, it looks like pyd is working just fine with gdc built from 
master, so have some randomly diced NetworkX Quick Example:


// thimble.d

import std.stdio;
import pyd.pyd, pyd.embedded;

void main() {
py_init();

auto ctxt = new InterpContext();
ctxt.py_stmts(import networkx as nx);
ctxt.py_stmts(q
G=nx.Graph()
G.add_node(spam)
);
ctxt.G.add_edge(1,2);
ctxt.py_stmts(print(G.nodes()));
// **(^*( corner case with properties
writeln(ctxt.G.edges.opCall());
}

// setup.py

from celerid.support import setup, Extension

setup(
name=thimble,
version='1.0',
ext_modules=[
Extension(thimble, [thimble.d],
build_deimos=True
)
],
)

// command line:

 python setup.py pydexe --compiler=gdc
 ./thimble

[1L, 2L, 'spam']
[(1L, 2L)]


safety of move

2012-11-27 Thread Ellery Newcomer

I find myself using [abusing?] move lately:

import std.algorithm;
import std.stdio;

struct A {
const(int) i;
int j;
int k;
}

void main() {
A* a = new A(); // pretend this is malloc or something
// *a = A(1)
A a2 = A(1);
move(a2, *a);

A[] arr = new A[](2);
//arr[1] = *a;
move(*a, arr[1]);
}

For the first part, I have a A* pointing to uninitialized memory and I 
need to initialize it somehow. move works I guess because it uses memcpy 
or something. Not complaining, but wondering.


The second part violates D's const semantics and maybe shouldn't be 
permitted. But it is.




Re: shared lib and __data_start

2012-11-12 Thread Ellery Newcomer

On 11/12/2012 12:54 AM, Johannes Pfau wrote:

How did you link that shared lib? With ld, gcc or g++? If you link via
gcc it pulls in some special object files, one of these could contain
__data_start. g++ pulls in some more object files for c++ support, but
that's probably not necessary here.


gcc -nostartfiles


But anyway, the runtime uses __data_start to find the data
section which should be scanned by the gc (see rt.memory). I really
doubt this approach will work in an application with multiple shared
libraries.



Well, that could be one reason why multiple shared libs doesn't work 
with my setup.


shared lib and __data_start

2012-11-11 Thread Ellery Newcomer

Playing with pypy.

I build me a shared library with ldc and try to access it via ctypes, 
and it gives me a


/usr/lib64/libdruntime-ldc.so.60: undefined symbol: __data_start

So the natural question is what is __data_start? Am I right in assuming 
it is a symbol that points to the data section or something and that it 
is relevant in executables but not shared libraries (and thus shouldn't 
be in druntime for shared lib builds)?


Re: Ranges and Library and toir.c internal error

2012-10-31 Thread Ellery Newcomer

On 10/31/2012 04:35 PM, StupidIsAsStupidDoes wrote:


The char call doesn't compile and I get a toir.c internal error.



On a recent dmd  build from github, I don't get any ICE, so it may have 
been fixed. I do get some disconcerting type deduction failures, though...



I'm still trying to get my head around Ranges. Is a int array a valid
range but a character array not?


All arrays are valid ranges, but char[], wchar[], and const variations 
thereof are special. They are treated as ranges of dchar so that you are 
guaranteed to get complete unicode characters out of them.


your code, modified:

import std.traits;

size_t countBetween(Range)(Range arr, ElementType!Range low, 
ElementType!Range high) {

return count!( (x){return ((x = low)  (x = high)); })(arr);
}

ought to handle both int[] and char[] properly.


Re: SFML-D working example

2012-10-20 Thread Ellery Newcomer

On Saturday, 20 October 2012 at 20:25:09 UTC, Zhenya wrote:
Hi!I have a little problem with building example.I downloaded 
SFML-D working example at this adress 
https://github.com/krzat/SFML-D/downloads.But then I tried to 
build it myself,I received many errors like that:
 Symbol Undefined 
_D2sf8graphics7Texture6__ctorMFPxaPS2sf8graphics7IntRectZC2sf8graphics7Texture


I don't understand why compiler isn't satisfied,becouse I 
include all .lib files,that is in example.Can anybody help my?


dmd_build.bat works for me. Are you using it?


Re: optlink and weak symbols

2012-10-18 Thread Ellery Newcomer

On 10/17/2012 11:41 PM, Jacob Carlborg wrote:

On 2012-10-18 05:12, Ellery Newcomer wrote:


nice tip, but adding extern doesn't change link behavior at all.


Hmm, are you linking with the DLL (the import library) ? In not, you
need to use dlopen, or what the corresponding Windows function is.



I am using python27_digitalmars.lib, which is generated from 
libs\python27.lib with coffimplib, and it is linking my executables with 
python.dll.


Re: optlink and weak symbols

2012-10-18 Thread Ellery Newcomer

On 10/18/2012 11:36 AM, Jacob Carlborg wrote:

On 2012-10-18 13:55, Ellery Newcomer wrote:


I am using python27_digitalmars.lib, which is generated from
libs\python27.lib with coffimplib, and it is linking my executables with
python.dll.


Ok. Do you know how the corresponding C code would look like? Maybe you
need to use the export attribute. It's the same as
__declspec(dllimport), have a look:

http://dlang.org/htomodule.html

If that doesn't work then I'm out of suggestions, Windows is not my
primary platform.



ha HA!

extern(C) extern export PyTypeObject PyType_Type;

seems to do the trick (I'm using a boiled down case just now)!

High five to the [non-me] non-windows dev!


Re: optlink and weak symbols

2012-10-17 Thread Ellery Newcomer

On 10/16/2012 11:16 PM, Jacob Carlborg wrote:


You need to declare the variable as extern if it's defined in the C code:

extern(C) extern __gshared PyTypeObject PyType_Type;

http://dlang.org/interfaceToC.html#C%20Globals



nice tip, but adding extern doesn't change link behavior at all.


optlink and weak symbols

2012-10-16 Thread Ellery Newcomer
I am interfacing with some C code [python.dll], which has some structs 
declared like so:


PyTypeObject PyType_Type;

I wish to be able to link to PyType_Type like so:

extern(C) __gshared PyTypeObject PyType_Type;

in linux, I can do exactly that, but optlink is generating a new memory 
location for PyType_Type.


strings output suggests that my lib file contains the symbol PyType_Type.

Is this sort of thing supposed to work?


function is not function

2012-09-21 Thread Ellery Newcomer

solution is to use std.traits, but can someone explain this to me?

import std.stdio;

void main() {
auto a = {
writeln(hi);
};
pragma(msg, typeof(a)); // void function()
pragma(msg, is(typeof(a) == delegate)); // nope!
pragma(msg, is(typeof(a) == function)); // nope!
}


Re: function is not function

2012-09-21 Thread Ellery Newcomer

On 09/21/2012 01:10 PM, Ali Çehreli wrote:


You have probably tried the following already:

 pragma(msg, is(typeof(a) == void function()));



No, but that's also not very generic.

void main() {
auto a = {
return 1;
};
pragma(msg, is(typeof(a) == void function())); // nope!
pragma(msg, typeof(a)); // void function() pure nothrow @safe
}

guess what I'm fighting with just now


Re: function is not function

2012-09-21 Thread Ellery Newcomer

On 09/21/2012 01:17 PM, bearophile wrote:

pragma(msg, is(typeof(a) == function)); // nope!


code in pyd suggests this evaluated to true once upon a time.



Re: undefined reference to `_D6deimos6python6Python12__ModuleInfoZ'

2012-09-19 Thread Ellery Newcomer

On 09/19/2012 01:30 PM, Jesse Phillips wrote:

On Tuesday, 18 September 2012 at 04:56:27 UTC, Ellery Newcomer wrote:


In a templated function in my header file, I make a call to enforce.
When the function is not called [instantiated], all is well. When the
function is called, it generates yon undefined reference to
__ModuleInfoZ.

I guess this is because D needs a pointer to the module in order to
look up enforce?


What does the call to enforce look like? The error isn't from the
compiler so you are pulling in a symbol which isn't in your object files.


here is an older file, as I haven't committed recently, but it shows the 
identical call:


https://bitbucket.org/ariovistus/pyd/src/364451b5d732/infrastructure/python/python.d#cl-653

making a call to enforce elsewhere doesn't fix the linker problem.


ctfe slicing

2012-09-17 Thread Ellery Newcomer

does it still copy the slice?


undefined reference to `_D6deimos6python6Python12__ModuleInfoZ'

2012-09-17 Thread Ellery Newcomer
With a deimos header file, I expect to need only to pass the dpath to it 
and the library it references to dmd, e.g.


stuff
 - deimos
  - python
   - Python.d

dmd otherstuff -Istuff -L-lpython2.7

I should not need to actually pass stuff/deimos/python/Python.d to dmd.

Unfortunately, that is currently not the case, and I am having a 
difficult time trying to figure out what is getting in my way.


been thumbing through nm output lately.


Anyone have any suggestions?



Re: undefined reference to `_D6deimos6python6Python12__ModuleInfoZ'

2012-09-17 Thread Ellery Newcomer

On 09/17/2012 04:16 PM, Ellery Newcomer wrote:

With a deimos header file, I expect to need only to pass the dpath to it
and the library it references to dmd, e.g.

stuff
  - deimos
   - python
- Python.d

dmd otherstuff -Istuff -L-lpython2.7

I should not need to actually pass stuff/deimos/python/Python.d to dmd.

Unfortunately, that is currently not the case, and I am having a
difficult time trying to figure out what is getting in my way.

been thumbing through nm output lately.


Anyone have any suggestions?



Found one little gotcha.

In a templated function in my header file, I make a call to enforce. 
When the function is not called [instantiated], all is well. When the 
function is called, it generates yon undefined reference to __ModuleInfoZ.


I guess this is because D needs a pointer to the module in order to look 
up enforce?


Re: bigint - python long

2012-09-11 Thread Ellery Newcomer

On 09/10/2012 10:50 PM, Russel Winder wrote:


Python 2 and Python 3 are totally different in this regard. I don't have
a obvious proposal to make to avoid having PyD for Python 2 and a
different PyD for Python 3, but the six package might have some hints as
it is intended to support creating Python codebases guaranteed to run
under Python 2 and Python 3.


Pyd doesn't really have a python codebase, I was talking mostly about 
PyString_AsString - PyUnicode_Whatever, since even for Python 2, 
unicode is much more appropriate for anything interfacing with D.


For getting pyd to support python 3, its mostly a matter of choosing the 
right C API functions, and anyways I have version identifiers I can rely 
on if there is divergence.


Wait, CeleriD is python. I might need that six package after all. Thanks 
for the tip.


Re: scons and D: flags

2012-09-11 Thread Ellery Newcomer

On 09/11/2012 11:42 AM, Russel Winder wrote:

On Tue, 2012-09-11 at 10:40 -0700, Ellery Newcomer wrote:

how do you pass compiler flags through scons?

e.g. -unittest, -property


Depends on the SConstruct (and optionally SConscript), but you need to
get a list of the options into the DFLAGS of the environment you are
compiling in.



dmd.py's doc header doesn't say this.


Re: bigint - python long

2012-09-11 Thread Ellery Newcomer

On 09/05/2012 07:10 PM, bearophile wrote:

Ellery Newcomer:


Yep.


Oh, good.



Have any suggestions for supported conversion out of the box?


There are several important cases, like:

Some D lazy ranges == Python lazy iterators/generators

array.array == D arrays

NumPy arrays == D arrays



Welp. I started on NumPy arrays == D arrays, and it turned out to be 
pretty easy. It's in its own function; maybe I'll put it in pyd.extras 
or something. But now I have just about all of the above cases working.


Bearophile: would you be interested in contributing some code showcasing 
what we can do with numpy? Just, say, a D function operating on D arrays 
that does something that maybe numpy doesn't have built in.




Re: bigint - python long

2012-09-10 Thread Ellery Newcomer

On 09/05/2012 07:10 PM, bearophile wrote:


NumPy arrays == D arrays



I've been thinking about this one a bit more, and I am not sure it 
belongs in pyd.


First, the conversion is not symmetric. One can convert a numpy.ndarray 
to a d array like so:


PyObject* ndarray;
double[][] matrix = d_type!(double[][])(ndarray);

however, going back

PyObject* res = _py(matrix);

It is not at all clear that the user wants res to be a numpy.ndarray. 
The problem is partially that d arrays would be overloaded to a few too 
many things (list, str, array, any iterable, any buffer). That last one 
is a doozy. d_type never actually touches ndarray's type, so _py can 
hardly know what to use to convert matrix. (what if ndarray is actually 
a foo.BizBar matrix?)


I could just specialize _py for numpy.ndarrays, defaulting to lists of 
lists (which is what we do already), but I kinda want a specialized type 
for numpy.ndarrays.


Also, all these conversions imply data copying; is this reasonable for 
numpy arrays?


It is easy enough to get a void* and shape information out of the 
ndarray, but building a decent matrix type out of them is not trivial. 
Is there a good matrix library for D that would be suitable for this?


Oh yeah, also: rectangular matrices. For static arrays, the conversion 
is 1 memcpy. For dynamic arrays: lots of memcpys. I suppose I could 
abuse slicing much.


Re: bigint - python long

2012-09-10 Thread Ellery Newcomer

On 09/10/2012 12:11 PM, bearophile wrote:


I understand. The point of Pyd is to interface D and Python, while NumPy
is something external. So if you find difficulties just keep it out.
Adding it later is possible.



Thing is, pyd will convert a ndarray to d array already, it just won't 
do it as quickly as it could if it made use of the underlying c array, and


_py(d_type!(double[][])(ndarray))

will result in a list of lists.

So it's really a question of should I add more oddness to an already odd 
situation.



OT Bugger, I'm going to have to go through pyd and replace all usages 
of str with unicode. /OT


Re: since when was this valid syntax?

2012-09-09 Thread Ellery Newcomer

On 09/08/2012 09:01 AM, Timon Gehr wrote:

On 09/08/2012 04:11 PM, Ellery Newcomer wrote:

alias enum int e;


It is valid according to the grammar


I don't believe you. Show me the derivation.



Re: linker @_@

2012-09-08 Thread Ellery Newcomer

On 09/08/2012 03:39 AM, Johannes Pfau wrote:


-L-llzmadec



Woot! it worked!


since when was this valid syntax?

2012-09-08 Thread Ellery Newcomer

alias enum int e;


Re: bigint - python long

2012-09-08 Thread Ellery Newcomer

On 09/08/2012 03:09 AM, Russel Winder wrote:

On Fri, 2012-09-07 at 15:21 -0700, Ellery Newcomer wrote:

On 09/06/2012 12:07 AM, Russel Winder wrote:

[…]

just used your scons fork to build the pyd embedded unittests. works
pretty nice


Splendid :-)



Okay, here: https://bitbucket.org/ariovistus/deimos-elfutils/overview

I have some code with a working makefile and a nonworking SConstruct file.

I believe the issue is the header files have pragma(lib, X) in them, and 
a single call to dmd links the appropriate lib in, but scons' link step 
loses that information.


Do you have any intention of supporting pragma(lib) in scons?



offsetof + foreach

2012-09-07 Thread Ellery Newcomer

I have a struct buffer, and I want to print out its members' offsetof.

This:

foreach(i,_t; buffer.tupleof) {
writefln(%s@: %s, _t.stringof, _t.offsetof);
}

complains

Error: undefined identifier 'offsetof'

what should I be doing?


Re: offsetof + foreach

2012-09-07 Thread Ellery Newcomer

On 09/07/2012 10:31 AM, Ellery Newcomer wrote:

I have a struct buffer, and I want to print out its members' offsetof.

This:

foreach(i,_t; buffer.tupleof) {
 writefln(%s@: %s, _t.stringof, _t.offsetof);
 }

complains

Error: undefined identifier 'offsetof'

what should I be doing?


nevermind, I remember tupleof + foreach has always been broken

writefln(%s@: %s, buffer.tupleof[i].stringof, buffer.tupleof[i].offsetof);


Re: bigint - python long

2012-09-07 Thread Ellery Newcomer

On 09/06/2012 09:48 AM, Ellery Newcomer wrote:

On 09/05/2012 11:19 PM, Jacob Carlborg wr


Associative arrays?



check.



eh, that was check as in yes, not check as in look it up yourself.

didn't seem ambiguous at the time.


Re: bigint - python long

2012-09-07 Thread Ellery Newcomer

On 09/06/2012 12:07 AM, Russel Winder wrote:


I am guessing this is interfacing to CPython, remember there is also
PyPy and ActiveState, they have different ways of doing things.  Well
the ActiveState C API will be very close to the CPython C API, but PyPy
(which is the best Python 2.7 just now) doesn't have a C API since it is
written in RPython.


Yep, CPython for now. If activestate supports the CPython C API, then 
supporting it will probably just be a matter of linkage.


Googling, it looks like PyPy is/was trying to grow some CPython C API 
compatibility, so hopefully we can squeeze it in at some point.




Oh yes.

NumPy is basically a subsystem that Python applications make calls into.
Although the data structure can be accessed and amended, algorithms on
the data structures should never be written in Python, they should
always be function calls into the NumPy framework.


I had a look at numpy, and at least ndarray supports the new style 
buffer interface (which is pretty freaking complicated), so convertion 
is totally doable. I'll fold in support as soon as I can get dmd to stop 
stabbing me in the face.



just used your scons fork to build the pyd embedded unittests. works 
pretty nice




linker @_@

2012-09-07 Thread Ellery Newcomer


playing with some old headers I had lying around,

dmd libdw_test.d {{header files}} -L-ldw

gives me

/usr/bin/ld: /usr/lib64/dmd-2.060/libphobos2.a(memory_4a8_620.o): 
undefined reference to symbol '_end'
/usr/bin/ld: note: '_end' is defined in DSO /lib64/liblzma.so.5 so try 
adding it to the linker command line

/lib64/liblzma.so.5: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status


any english suggestions?


int[3][4]*

2012-09-07 Thread Ellery Newcomer


alright what's the deal?

void main () {
alias int[3][4] fooz;
int[3][4]* i = new fooz;
}


wiz.d(6): Error: new can only create structs, dynamic arrays or class 
objects, not int[3LU][4LU]'s


  1   2   3   4   >