std.net.curl not working in 2.058 for Windows

2012-02-24 Thread Brad Anderson
There is no documentation (both on dlang.org and in the local 
documentation) so I'm not sure if it's supposed to be working 
yet.  I get linker errors when I try to use it:


$ dmd netcurl.d
OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
netcurl.obj(netcurl)
 Error 42: Symbol Undefined 
_D3std3net4curl3FTP8__cpctorMxFKxS3std3net4curl3FTPZv

netcurl.obj(netcurl)
 Error 42: Symbol Undefined 
_D3std3net4curl3FTP11__fieldDtorMFZv

netcurl.obj(netcurl)
 Error 42: Symbol Undefined _D3std3net4curl3FTP7performMFZv
netcurl.obj(netcurl)
 Error 42: Symbol Undefined 
_D3std3net4curl13CurlException7__ClassZ

netcurl.obj(netcurl)
 Error 42: Symbol Undefined 
_D3std3net4curl13CurlException6__ctorMFAyaAyakC6object9ThrowableZC3std3net4curl13CurlException

netcurl.obj(netcurl)

[snip]

Furthermore the documentation in the actual source says this 
should work:


string content = get(http://dlang.org;);

But that results in a compiler error error:

netcurl.d(5): Error: cannot implicitly convert expression 
(get(http://dlang.org,AutoProtocol())) of type char[] to string


get() signature from the source is:

T[] get(Conn = AutoProtocol, T = char)(const(char)[] url, 
Conn conn = Conn())
if ( isCurlConn!Conn  (is(T == char) || is(T == ubyte)) 
)


An .idup fixes it, of course, but the documentation is wrong (or 
the signature is wrong).


Finally, was the curl library included?  If not, where can it be 
found?  It needs to be an OMF version, right?  I don't see an OMF 
version on curl's website.


Regards,
Brad Anderson


Re: GDC: how to link with alternate version of Phobos?

2012-02-24 Thread Johannes Pfau
Am Thu, 23 Feb 2012 20:21:57 -0800
schrieb H. S. Teoh hst...@quickfur.ath.cx:

 I'm trying to test if a bug has been fixed in the latest Phobos git
 repository, but I'm having trouble convincing gdc to *not* use the
 default installation of Phobos. What option do I need on the
 commandline to tell it to use a different path to Phobos? -I only
 appends include paths *after* the default paths, so it'll always pick
 up the default installation first (plus it will cause import
 conflicts since there will be two modules claiming to be std.stdio).
 
 
 T
 

try -nophoboslib and/or -nostdinc. However, to use the git phobos
version with gdc you also have to compile it with gdc. I'm not sure but
I think the phobos source in gdc has gdc specific changes, at least it's
that way for druntime.


Re: std.net.curl not working in 2.058 for Windows

2012-02-24 Thread Brad Anderson

On Friday, 24 February 2012 at 07:59:50 UTC, Brad Anderson wrote:
There is no documentation (both on dlang.org and in the local 
documentation) so I'm not sure if it's supposed to be working 
yet.  I get linker errors when I try to use it:


$ dmd netcurl.d
OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
netcurl.obj(netcurl)
 Error 42: Symbol Undefined 
_D3std3net4curl3FTP8__cpctorMxFKxS3std3net4curl3FTPZv

netcurl.obj(netcurl)
 Error 42: Symbol Undefined 
_D3std3net4curl3FTP11__fieldDtorMFZv

netcurl.obj(netcurl)
 Error 42: Symbol Undefined _D3std3net4curl3FTP7performMFZv
netcurl.obj(netcurl)
 Error 42: Symbol Undefined 
_D3std3net4curl13CurlException7__ClassZ

netcurl.obj(netcurl)
 Error 42: Symbol Undefined 
_D3std3net4curl13CurlException6__ctorMFAyaAyakC6object9ThrowableZC3std3net4curl13CurlException

netcurl.obj(netcurl)

[snip]

Furthermore the documentation in the actual source says this 
should work:


string content = get(http://dlang.org;);

But that results in a compiler error error:

netcurl.d(5): Error: cannot implicitly convert expression 
(get(http://dlang.org,AutoProtocol())) of type char[] to 
string


get() signature from the source is:

T[] get(Conn = AutoProtocol, T = char)(const(char)[] url, 
Conn conn = Conn())
if ( isCurlConn!Conn  (is(T == char) || is(T == 
ubyte)) )


An .idup fixes it, of course, but the documentation is wrong 
(or the signature is wrong).


Finally, was the curl library included?  If not, where can it 
be found?  It needs to be an OMF version, right?  I don't see 
an OMF version on curl's website.


Regards,
Brad Anderson



It would appear phobos's win32.mak wasn't updated to include the 
curl wrapper.


I can try to figure out how the makefile works and send a pull 
request if nobody who knows what's going on has time.


Regards,
Brad Anderson


Compiling with -unittest on a c wrapper

2012-02-24 Thread simendsjo

Given the header file mymodule.h:
void f(void);

I'm creating mymodule.d:
extern(C) void f();

It works fine when compiling with this library, but when I compile with  
-unittest, I get undefined reference to ModuleInfo:
sample.o:(.data+0x210): undefined reference to  
`_D7mylibrary7mymodule12__ModuleInfoZ'


What am I doing wrong?

I saw the following snippet in deimos/openssl:
// Very boiled down version because we cannot use std.traits without  
causing
// DMD to create a ModuleInfo reference for _d_util, which would require  
users

// to include the Deimos files in the build.
template ExternC(T) if (is(typeof(*(T.init)) P == function)) {
static if (is(typeof(*(T.init)) R == return)) {
static if (is(typeof(*(T.init)) P == function)) {
alias extern(C) R function(P) ExternC;
}
}
}

.. but I'm not sure if this relates to my problem..


Re: 2.058 broke my build. Is this a bug?

2012-02-24 Thread Dmitry Olshansky

On 24.02.2012 10:28, Caligo wrote:

88

import std.datetime : benchmark;
import std.stdio : writefln;

struct A(int r, int c){

  public:
   alias float[r * c] Data;

   Data _data;

   auto opBinary(A a){
 float t;
 foreach(i; 0..r*c)
   foreach(j; 0..r*c)
t += this[i,j];


I guess that should be
foreach(i; 0..r)
foreach(j; 0..c)
t += this[i,j];
since you do row/col multiplication in opIndex?


 return a;
   }
   pure float opIndex(size_t rr, size_t cc = 0) const{ return _data[cc
+ rr * c]; }

   pure ref float opIndex(size_t rr, size_t cc = 0){ return _data[cc + rr * c]; 
}
}

void bench(alias fun)(string msg, uint n = 1_000_000){

   auto b = benchmark!fun(n);
   writefln( %s %s ms, msg, b[0].to!(msecs, int));
}

unittest{

   alias A!(3, 3) AA;
   AA a;

   bench!( {auto r = a * a;})(broken);
}

void main(){ }

88

Other parts of my code using bench() works fine, except in rare cases.
  So I'm guessing this is a bug?  I can't tell if it's in DMD or
std.datetime.  Can anyone help?

I will bug report myself tomorrow if it turns out to be a bug for sure.

DMD 2.058, 64-bit GNU/Linux



--
Dmitry Olshansky


Re: Compiling with -unittest on a c wrapper

2012-02-24 Thread simendsjo

On Fri, 24 Feb 2012 10:06:33 +0100, simendsjo simend...@gmail.com wrote:


Given the header file mymodule.h:
void f(void);

I'm creating mymodule.d:
extern(C) void f();

It works fine when compiling with this library, but when I compile with  
-unittest, I get undefined reference to ModuleInfo:
sample.o:(.data+0x210): undefined reference to  
`_D7mylibrary7mymodule12__ModuleInfoZ'


What am I doing wrong?

I saw the following snippet in deimos/openssl:
// Very boiled down version because we cannot use std.traits without  
causing
// DMD to create a ModuleInfo reference for _d_util, which would require  
users

// to include the Deimos files in the build.
template ExternC(T) if (is(typeof(*(T.init)) P == function)) {
static if (is(typeof(*(T.init)) R == return)) {
static if (is(typeof(*(T.init)) P == function)) {
alias extern(C) R function(P) ExternC;
}
}
}

.. but I'm not sure if this relates to my problem..


Hmm. If I add all the wrapper modules, I'm able to compile.. Guess it's  
related. What's the best way to handle this?


Re: D, Derelict2, and OpenGL

2012-02-24 Thread David

Am 24.02.2012 01:50, schrieb Chris Pons:

Is the documentation up-to-date on this site? So that I can search
through and try to learn more about a certain library and how it could
help me?


Which site? The derelict documentation? There is no real derelict 
documentation, but you normally dont need it, the only thing you're 
doing with derelict is initializing and loading a shared library (glfw, 
sdl, opengl …).


Re: SONAME and D

2012-02-24 Thread Jordi Sayol
Al 23/02/12 20:29, En/na bioinfornatics ha escrit:
 Le jeudi 23 février 2012 à 19:46 +0100, Mike Wey a écrit :
 On 02/23/2012 05:27 PM, bioinfornatics wrote:
 dear,
 for set soname with:
 - gdc: -Xlinker -soname myLib.so.1
 - ldc2: -soname myLib.so.1
 - dmd: ?

 someone know how set soname with dmd ?


 dmd -L-soname=mylib.so.1

 
 Thanks
 i will do so a $(SONAME_FLAG) in my makefile and maybe i will do a pull
 request for gtkd because ldc do not use -L-soname instead of dmd
 
 

Are you able to build dynamic libraries directly with DMD?
How?
-- 
Jordi Sayol



Re: SONAME and D

2012-02-24 Thread David

Am 24.02.2012 11:40, schrieb Jordi Sayol:

Al 23/02/12 20:29, En/na bioinfornatics ha escrit:

Le jeudi 23 février 2012 à 19:46 +0100, Mike Wey a écrit :

On 02/23/2012 05:27 PM, bioinfornatics wrote:

dear,
for set soname with:
- gdc: -Xlinker -soname myLib.so.1
- ldc2: -soname myLib.so.1
- dmd: ?

someone know how set soname with dmd ?



dmd -L-soname=mylib.so.1



Thanks
i will do so a $(SONAME_FLAG) in my makefile and maybe i will do a pull
request for gtkd because ldc do not use -L-soname instead of dmd




Are you able to build dynamic libraries directly with DMD?
How?

-sharedgenerate shared library


Re: SONAME and D

2012-02-24 Thread Jordi Sayol
Al 24/02/12 11:59, En/na David ha escrit:

 Are you able to build dynamic libraries directly with DMD?
 How?
 -sharedgenerate shared library
 

I got this:
$ dmd -fPIC -shared foo.d 
/usr/bin/ld: /usr/lib/libphobos2.a(minfo.o): relocation R_X86_64_32 against 
`.data' can not be used when making a shared object; recompile with -fPIC
/usr/lib/libphobos2.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
--- errorlevel 1

-- 
Jordi Sayol


Re: Pure and higher-order functions

2012-02-24 Thread mist

Ok, finally understood.

I was trying to declare hof like this: void f2( pure int 
function() param ) , similar to the way I declare usual pure 
functions. Looks like it is syntax error and only void f2( int 
function() pure param ) is allowed. That led me to false 
conclusion, that such signature is not allowed at all.


Are there any reasons for this inconsistency?


Re: Linking with d3d11.dll/lib

2012-02-24 Thread Sean Cavanaugh

On 2/23/2012 5:03 PM, John Burton wrote:

I'm trying to use the d3d11 bindings in
http://www.dsource.org/projects/bindings/wiki/DirectX to call
direct3d11 functions from my D program.

I've managed to get the code to compiler but when it links I get
this error -

Error 42 Symbol Undefined _D3D11CreateDeviceAndSwapChain@48

I have copied the D3D11.lib from the D3D SDK into my project and
then run COFFIMPLIB d3d11.lib -f to convert it and included the
library in my project settings.

Is there something else I need to do to make this link? Any help
appreciated.


I modified my test app to use D3D11CreateDeviceAndSwapChain instead of 
D3D11CreateDevice and it links and runs against either function.  The 
only trouble I had was when I went out of my way to delete the import 
libraries (d3d11.lib) in order to see what the link error looks like.


I am currently using dmd2 2.057 and building my project with Visual 
Studio + VisualD plugin (0.30).


Re: SONAME and D

2012-02-24 Thread Jordi Sayol
Al 24/02/12 11:59, En/na David ha escrit:

 Are you able to build dynamic libraries directly with DMD?
 How?
 -sharedgenerate shared library
 

It compiles to 32-bit but fails for 64-bit, maybe due to compiled libphobos2 
(64-bit) without -fPIC argument?

Another thing.
$ dmd -fPIC -shared foo.d -m32 -offoo.so.0.0.1
generate the incorrect foo.so.0.0.so file name.

but with:
$ dmd -fPIC -shared foo.d -m32 -L-ofoo.so.0.0.1
the correct foo.so.0.0.1 file name is created.

Best regards,
-- 
Jordi Sayol


Re: fedora/ldc where are druntime headers?

2012-02-24 Thread bioinfornatics
Le jeudi 23 février 2012 à 18:35 -0600, Ellery Newcomer a écrit :
 grumph. is it not possible to fix the packages in repo?
 
 On 02/23/2012 05:17 PM, bioinfornatics wrote:
  get latest ldc build here:
  http://koji.fedoraproject.org/koji/buildinfo?buildID=299767
 
  install it with yum install after dowloading these rpm
 

On fedora 16 ?
no until fedora 16 provides llvm 2.9



About CTFE and pointers

2012-02-24 Thread bearophile
I have seen this C++11 program:
http://kaizer.se/wiki/log/post/C++_constexpr/

I have translated it to this D code:


bool notEnd(const char *s, const int n) {
return s  s[n];
}
bool strPrefix(const char *s, const char *t, const int ns, const int nt) {
return (s == t) ||
   !t[nt] ||
   (s[ns] == t[nt]  (strPrefix(s, t, ns+1, nt+1)));
}
bool contains(const char *s, const char *needle, const int n=0) {
// Works only with C-style 0-terminated strings
return notEnd(s, n) 
   (strPrefix(s, needle, n, 0) || contains(s, needle, n+1));
}
enum int x = contains(froogler, oogle);
void main() {
//assert(contains(froogler, oogle));
}


If I run the version of the code with the run-time, it generates no errors.

If I run the version with enum with the latest dmd it gives:

test.d(6): Error: string index 5 is out of bounds [0 .. 5]
test.d(7):called from here: strPrefix(s,t,ns + 1,nt + 1)
test.d(4):5 recursive calls to function strPrefix
test.d(12):called from here: strPrefix(s,needle,n,0)
test.d(12):called from here: contains(s,needle,n + 1)
test.d(12):called from here: contains(s,needle,n + 1)
test.d(14):called from here: contains(froogler,oogle,0)


At first sight it looks like a CTFE bug, but studying the code a little it 
seems there is a off-by-one bug in the code 
(http://en.wikipedia.org/wiki/Off-by-one_error ). A quick translation to D 
arrays confirms it:


bool notEnd(in char[] s, in int n) {
return s  s[n];
}
bool strPrefix(in char[] s, in char[] t, in int ns, in int nt) {
return (s == t) ||
   !t[nt] ||
   (s[ns] == t[nt]  (strPrefix(s, t, ns+1, nt+1)));
}
bool contains(in char[] s, in char[] needle, in int n=0) {
// Works only with C-style 0-terminated strings
return notEnd(s, n) 
   (strPrefix(s, needle, n, 0) || contains(s, needle, n+1));
}
//enum int x = contains(froogler, oogle);
void main() {
assert(contains(froogler, oogle));
}


It gives at run-time:

core.exception.RangeError@test(6): Range violation

...\test.d(6): bool test.strPrefix(const(char[]), const(char[]), const(int), 
const(int))
...



So it seems that Don, when he has implemented the last parts of the CTFE 
interpreter, has done something curious, because in some cases it seems able to 
find out of bounds even when you use just raw pointers :-)

Bye,
bearophile


Re: Pure and higher-order functions

2012-02-24 Thread bearophile
mist:

 Are there any reasons for this inconsistency?

I don't know. Maybe it's just a parser bug. There are some of those in Bugzilla.

If you don't like it, then I suggest you to add it to D Bugzilla.

Bye,
bearophile


Re: About CTFE and pointers

2012-02-24 Thread Alex Rønne Petersen

On 24-02-2012 15:08, bearophile wrote:

I have seen this C++11 program:
http://kaizer.se/wiki/log/post/C++_constexpr/

I have translated it to this D code:


bool notEnd(const char *s, const int n) {
 return s  s[n];
}
bool strPrefix(const char *s, const char *t, const int ns, const int nt) {
 return (s == t) ||
!t[nt] ||
(s[ns] == t[nt]  (strPrefix(s, t, ns+1, nt+1)));
}
bool contains(const char *s, const char *needle, const int n=0) {
 // Works only with C-style 0-terminated strings
 return notEnd(s, n)
(strPrefix(s, needle, n, 0) || contains(s, needle, n+1));
}
enum int x = contains(froogler, oogle);
void main() {
//assert(contains(froogler, oogle));
}


If I run the version of the code with the run-time, it generates no errors.

If I run the version with enum with the latest dmd it gives:

test.d(6): Error: string index 5 is out of bounds [0 .. 5]
test.d(7):called from here: strPrefix(s,t,ns + 1,nt + 1)
test.d(4):5 recursive calls to function strPrefix
test.d(12):called from here: strPrefix(s,needle,n,0)
test.d(12):called from here: contains(s,needle,n + 1)
test.d(12):called from here: contains(s,needle,n + 1)
test.d(14):called from here: contains(froogler,oogle,0)


At first sight it looks like a CTFE bug, but studying the code a little it 
seems there is a off-by-one bug in the code 
(http://en.wikipedia.org/wiki/Off-by-one_error ). A quick translation to D 
arrays confirms it:


bool notEnd(in char[] s, in int n) {
 return s  s[n];
}
bool strPrefix(in char[] s, in char[] t, in int ns, in int nt) {
 return (s == t) ||
!t[nt] ||
(s[ns] == t[nt]  (strPrefix(s, t, ns+1, nt+1)));
}
bool contains(in char[] s, in char[] needle, in int n=0) {
 // Works only with C-style 0-terminated strings
 return notEnd(s, n)
(strPrefix(s, needle, n, 0) || contains(s, needle, n+1));
}
//enum int x = contains(froogler, oogle);
void main() {
 assert(contains(froogler, oogle));
}


It gives at run-time:

core.exception.RangeError@test(6): Range violation

\test.d(6): bool test.strPrefix(const(char[]), const(char[]), const(int), 
const(int))




So it seems that Don, when he has implemented the last parts of the CTFE 
interpreter, has done something curious, because in some cases it seems able to 
find out of bounds even when you use just raw pointers :-)

Bye,
bearophile


It's not at all unlikely that the CTFE interpreter represents blocks of 
memory as a pointer+length pair internally.


--
- Alex


Re: Linking with d3d11.dll/lib

2012-02-24 Thread John Burton
Thank you for checking. I'm guessing that the most likely problem
then is that either my d3d11.lib file is broken, or the build is
not finding it somehow... I'll check later.

Thank you for confiruming it basically works :)


Re: SONAME and D

2012-02-24 Thread Mike Wey

On 02/23/2012 08:29 PM, bioinfornatics wrote:

Le jeudi 23 février 2012 à 19:46 +0100, Mike Wey a écrit :

On 02/23/2012 05:27 PM, bioinfornatics wrote:

dear,
for set soname with:
- gdc: -Xlinker -soname myLib.so.1
- ldc2: -soname myLib.so.1
- dmd: ?

someone know how set soname with dmd ?



dmd -L-soname=mylib.so.1



Thanks
i will do so a $(SONAME_FLAG) in my makefile and maybe i will do a pull
request for gtkd because ldc do not use -L-soname instead of dmd



The GtkD Makefile uses:

$(LINKERFLAG)-soname=$@.$(call stripBugfix,$(SO_VERSION))

Witch works with all the compilers, $(LINKERFLAG) is either -L or 
-Xlinker (with a space on th end).


--
Mike Wey


Re: About CTFE and pointers

2012-02-24 Thread Don Clugston

On 24/02/12 15:18, Alex Rønne Petersen wrote:

On 24-02-2012 15:08, bearophile wrote:

I have seen this C++11 program:
http://kaizer.se/wiki/log/post/C++_constexpr/

I have translated it to this D code:


bool notEnd(const char *s, const int n) {
return s s[n];
}
bool strPrefix(const char *s, const char *t, const int ns, const int
nt) {
return (s == t) ||
!t[nt] ||
(s[ns] == t[nt] (strPrefix(s, t, ns+1, nt+1)));
}
bool contains(const char *s, const char *needle, const int n=0) {
// Works only with C-style 0-terminated strings
return notEnd(s, n)
(strPrefix(s, needle, n, 0) || contains(s, needle, n+1));
}
enum int x = contains(froogler, oogle);
void main() {
// assert(contains(froogler, oogle));
}


If I run the version of the code with the run-time, it generates no
errors.

If I run the version with enum with the latest dmd it gives:

test.d(6): Error: string index 5 is out of bounds [0 .. 5]
test.d(7): called from here: strPrefix(s,t,ns + 1,nt + 1)
test.d(4): 5 recursive calls to function strPrefix
test.d(12): called from here: strPrefix(s,needle,n,0)
test.d(12): called from here: contains(s,needle,n + 1)
test.d(12): called from here: contains(s,needle,n + 1)
test.d(14): called from here: contains(froogler,oogle,0)


At first sight it looks like a CTFE bug, but studying the code a
little it seems there is a off-by-one bug in the code
(http://en.wikipedia.org/wiki/Off-by-one_error ). A quick translation
to D arrays confirms it:


bool notEnd(in char[] s, in int n) {
return s s[n];
}
bool strPrefix(in char[] s, in char[] t, in int ns, in int nt) {
return (s == t) ||
!t[nt] ||
(s[ns] == t[nt] (strPrefix(s, t, ns+1, nt+1)));
}
bool contains(in char[] s, in char[] needle, in int n=0) {
// Works only with C-style 0-terminated strings
return notEnd(s, n)
(strPrefix(s, needle, n, 0) || contains(s, needle, n+1));
}
//enum int x = contains(froogler, oogle);
void main() {
assert(contains(froogler, oogle));
}


It gives at run-time:

core.exception.RangeError@test(6): Range violation

\test.d(6): bool test.strPrefix(const(char[]), const(char[]),
const(int), const(int))




So it seems that Don, when he has implemented the last parts of the
CTFE interpreter, has done something curious, because in some cases it
seems able to find out of bounds even when you use just raw pointers :-)

Bye,
bearophile


It's not at all unlikely that the CTFE interpreter represents blocks of
memory as a pointer+length pair internally.



Yes, that's exactly what it does. That's how it's able to implement 
pointers safely.


That's a nice story, Thanks, bearophile.



Re: Pure and higher-order functions

2012-02-24 Thread mist

Actually, looks like you have done it already 2 years ago :)
http://d.puremagic.com/issues/show_bug.cgi?id=4505


Re: D runtime Garbage Collector details

2012-02-24 Thread deadalnix

Le 24/02/2012 00:49, Vadim a écrit :

I am looking for the details on D Garbage Collection implementation. I
will much appreciate if someone suggests the answers or give some links
to existing documentation clarifying the following points:

1. Is it Mark-n-Sweep or copy or generational collector or simple
reference counting? Or anything else? Any documentation on this would be
very helpful



Mark and sweep, but do not copy and isn't generationnal.


2. Sun/Oracle JVM publishes a number of counters in shared memory so
that user may easily monitor the memory usage and the GC statistics
real-time without affecting the application (and without modifying the
application). Is there anything similar for D GC?



You should ask the system for thoses infos.


3. Is there any performance tests of D GC efficiency? Is it possible to
write GC-predictable code (without manual allocate/free) or at least do
something like System.gc()?


Its performance are quite poor ATM, it is getting better, but still not 
as effeiscient as java's GC for example. You could disable it using the 
class GC on critical period of time, so you'd know when it run and when 
it cannot trigger itself. D allow also to manage memory manually, and if 
you don't generate garbage, GC will not trigger.


Re: GDC: how to link with alternate version of Phobos?

2012-02-24 Thread Jonathan M Davis
On Friday, February 24, 2012 09:43:30 Johannes Pfau wrote:
 try -nophoboslib and/or -nostdinc. However, to use the git phobos
 version with gdc you also have to compile it with gdc. I'm not sure but
 I think the phobos source in gdc has gdc specific changes, at least it's
 that way for druntime.

That's necessary and expected for druntime. Each compiler is going to have its 
own version of druntime, so you _need_ GDC's version of druntime. However, at 
least in theory, Phobos should be the same across compilers. I don't know what 
GDC is currently doing though. Regardless, if you're using another version of
Phobos, you're going to need to build it against GDC's version of druntime.

- Jonathan M Davis


Using delegates in callbacks for extern(C) functions

2012-02-24 Thread simendsjo
I have a C function taking a callback function as a parameter. My thought  
was to wrap this up using a template, but I cannot get it to work:


extern(C) alias void function() Callback;

template Wrap(alias dg)
{
extern(C) void Wrap()
{
dg();
}
}

void main()
{
Callback cb = Wrap!( () {} );
}

Error: cannot implicitly convert expression (Wrap) of type void  
delegate() pure nothrow @safe to extern (C) void function()


Re: SONAME and D

2012-02-24 Thread Ellery Newcomer

On 02/24/2012 06:27 AM, Jordi Sayol wrote:


It compiles to 32-bit but fails for 64-bit, maybe due to compiled libphobos2 
(64-bit) without -fPIC argument?



What? -shared works with 32-bit?

Holy crap, it does! this is awesome!

maybe make a bug report for 64 bit?


Cannot cast void* to arrays..?

2012-02-24 Thread simendsjo

char[] a;
auto b = cast(void*)a;
auto c = cast(char[])b; // Error: e2ir: cannot cast b of type void* to  
type char[]


Re: SONAME and D

2012-02-24 Thread Jordi Sayol
Al 24/02/12 20:21, En/na Ellery Newcomer ha escrit:
 On 02/24/2012 06:27 AM, Jordi Sayol wrote:

 It compiles to 32-bit but fails for 64-bit, maybe due to compiled libphobos2 
 (64-bit) without -fPIC argument?

 
 What? -shared works with 32-bit?
 
 Holy crap, it does! this is awesome!
 
 maybe make a bug report for 64 bit?
 

better wait till libphobos2.a becomes libphobos2.so

-- 
Jordi Sayol


Re: SONAME and D

2012-02-24 Thread H. S. Teoh
On Fri, Feb 24, 2012 at 08:36:03PM +0100, Jordi Sayol wrote:
[...]
 better wait till libphobos2.a becomes libphobos2.so
[...]

You might have to wait a while for that. AFAIK there are no plans
currently to make phobos available as a shared library yet.

I personally think that phobos *should* be a shared object at some
point, but not everyone agrees with me.


T

-- 
Lottery: tax on the stupid. -- Slashdotter


Re: Cannot cast void* to arrays..?

2012-02-24 Thread H. S. Teoh
On Fri, Feb 24, 2012 at 08:34:19PM +0100, simendsjo wrote:
 char[] a;
 auto b = cast(void*)a;
 auto c = cast(char[])b; // Error: e2ir: cannot cast b of type
 void* to type char[]

D arrays are not the same as C arrays. D arrays also include length in
addition to the pointer, so you can't just cast a void* to an array.


T

-- 
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it. -- Brian W. Kernighan


Re: Cannot cast void* to arrays..?

2012-02-24 Thread Justin Whear
On Fri, 24 Feb 2012 20:34:19 +0100, simendsjo wrote:

 char[] a;
  auto b = cast(void*)a;
  auto c = cast(char[])b; // Error: e2ir: cannot cast b of type void*
  to
 type char[]

Arrays have a length--you need to cast the pointer to a char*, then slice 
it.


Re: Cannot cast void* to arrays..?

2012-02-24 Thread simendsjo
On Fri, 24 Feb 2012 20:42:20 +0100, Justin Whear  
jus...@economicmodeling.com wrote:



On Fri, 24 Feb 2012 20:34:19 +0100, simendsjo wrote:


char[] a;
 auto b = cast(void*)a;
 auto c = cast(char[])b; // Error: e2ir: cannot cast b of type void*
 to
type char[]


Arrays have a length--you need to cast the pointer to a char*, then slice
it.


Ah, of course, thanks.
But what about static arrays?
char[1] a;
//a.length = 10; // constant a.length is not an lvalue
auto b = cast(void*)a;
auto c = cast(char[1])b; // Error: e2ir: cannot cast b of type void*  
to type char[1LU]


Re: Cannot cast void* to arrays..?

2012-02-24 Thread Mantis

24.02.2012 21:34, simendsjo пишет:

char[] a;
auto b = cast(void*)a;
auto c = cast(char[])b; // Error: e2ir: cannot cast b of type 
void* to type char[]


Generally, you should not cast a struct to pointer and vise-versa. 
Besides, size of array structure is larger than size of pointer, and 
that triggers error in your case.


Re: Cannot cast void* to arrays..?

2012-02-24 Thread H. S. Teoh
 24.02.2012 21:34, simendsjo пишет:
 char[] a;
 auto b = cast(void*)a;
 auto c = cast(char[])b; // Error: e2ir: cannot cast b of type
 void* to type char[]
[...]

Just out of curiosity, what are you trying to accomplish with this cast?
In almost all normal D code, there's no need for any casting at all.


T

-- 
The right half of the brain controls the left half of the body. This
means that only left-handed people are in their right mind. -- Manoj
Srivastava


Re: Cannot cast void* to arrays..?

2012-02-24 Thread Ali Çehreli

On 02/24/2012 11:44 AM, simendsjo wrote:

On Fri, 24 Feb 2012 20:42:20 +0100, Justin Whear
jus...@economicmodeling.com wrote:


On Fri, 24 Feb 2012 20:34:19 +0100, simendsjo wrote:


char[] a;
auto b = cast(void*)a;
auto c = cast(char[])b; // Error: e2ir: cannot cast b of type void*
to
type char[]


Arrays have a length--you need to cast the pointer to a char*, then slice
it.


Ah, of course, thanks.
But what about static arrays?
char[1] a;
//a.length = 10; // constant a.length is not an lvalue
auto b = cast(void*)a;
auto c = cast(char[1])b; // Error: e2ir: cannot cast b of type void* to
type char[1LU]


char[1] a;
auto c = a.ptr[0..a.length];

Ali


Re: Adding overloaded methods

2012-02-24 Thread H. S. Teoh
On Fri, Feb 24, 2012 at 04:24:03PM +1300, James Miller wrote:
 On 24 February 2012 12:06, H. S. Teoh hst...@quickfur.ath.cx wrote:
  On Fri, Feb 24, 2012 at 04:06:52AM +1300, James Miller wrote:
  On 23 February 2012 13:15, BLM blm...@gmail.com wrote:
   After messing around for a while, I figured out what is making
   DMD choke on my file. The methods were defined in the base class
   using template mixins, and apparently DMD doesn't like it when
   mixins, inheritance, overloading, and aliases are all in the same
   piece of code :)
 
  And the award for Most Meta Code goes too...
  [...]
 
  I dunno, but most meta to me implies recursive mixins...
[.[..]
 True, I guess the Most Meta Code would be something that combines
 recursive mixins, string mixins, inheritance, overriding, overloading,
 aliases and is all inside a recursive template. Bonus points if the
 final result is a quine.
[...]

You forgot reflection. The quine would generate itself by reflecting
upon itself and reproducing itself via aliasing recursive mixins (by
which I mean string mixins that contain mixin in the string,
recursively) into a recursive template that generates a class hierarchy.

Bonus points if the code *in theory* would reproduce itself, but
actually causes dmd to run into an infinite loop. :P


T

-- 
If it breaks, you get to keep both pieces. -- Software disclaimer notice


Re: mixin template FAIL

2012-02-24 Thread Zach the Mystic

On 2/23/12 7:33 PM, Ellery Newcomer wrote:

import std.stdio;

mixin template helpMe()
{
writeln(Satisfying!);
}

does it do that if you replace the statement with a declaration?

like this:

mixin template helpMe()
{
int durrr = (writeln(Satisfying!), 1);
}


No, it doesn't. You're right. I guess I have a long way to go to learn 
these things.


Thank you. Even at my primitive level, though, I can see how awesome 
these things could be once you know how to program them. Does any other 
language come close to D in terms of generics? I don't know, I'm just 
asking?


Zach


Re: Cannot cast void* to arrays..?

2012-02-24 Thread simendsjo

On Fri, 24 Feb 2012 20:56:18 +0100, Ali Çehreli acehr...@yahoo.com wrote:


On 02/24/2012 11:44 AM, simendsjo wrote:

On Fri, 24 Feb 2012 20:42:20 +0100, Justin Whear
jus...@economicmodeling.com wrote:


On Fri, 24 Feb 2012 20:34:19 +0100, simendsjo wrote:


char[] a;
auto b = cast(void*)a;
auto c = cast(char[])b; // Error: e2ir: cannot cast b of type void*
to
type char[]


Arrays have a length--you need to cast the pointer to a char*, then  
slice

it.


Ah, of course, thanks.
But what about static arrays?
char[1] a;
//a.length = 10; // constant a.length is not an lvalue
auto b = cast(void*)a;
auto c = cast(char[1])b; // Error: e2ir: cannot cast b of type void* to
type char[1LU]


 char[1] a;
 auto c = a.ptr[0..a.length];

Ali



I don't get it. This gives me a dynamic array, not a static:
char[1] a;
auto b = cast(void*)a;
auto c = (cast(char*)b)[0..1];
c.length = 10; // auch!


Re: Cannot cast void* to arrays..?

2012-02-24 Thread simendsjo
On Fri, 24 Feb 2012 20:56:22 +0100, H. S. Teoh hst...@quickfur.ath.cx  
wrote:



24.02.2012 21:34, simendsjo пишет:
char[] a;
auto b = cast(void*)a;
auto c = cast(char[])b; // Error: e2ir: cannot cast b of type
void* to type char[]

[...]

Just out of curiosity, what are you trying to accomplish with this cast?
In almost all normal D code, there's no need for any casting at all.


T



Interacting with a C callback taking a void*. In my callback, I want to  
get the same type back.
See my previous question:  
http://forum.dlang.org/post/op.v963zyg0x8p62v@simendsjo-desktop (although  
I didn't include the parameters in that example)


Re: Cannot cast void* to arrays..?

2012-02-24 Thread H. S. Teoh
On Fri, Feb 24, 2012 at 11:56:18AM -0800, Ali Çehreli wrote:
[...]
 char[1] a;
 auto c = a.ptr[0..a.length];
[...]

Hey, that's an awesome way to implement copy-on-write static arrays!

I'll have to use that sometime. :)


T

-- 
Sometimes the best solution to morale problems is just to fire all of
the unhappy people. -- despair.com


Re: mixin template FAIL

2012-02-24 Thread H. S. Teoh
On Fri, Feb 24, 2012 at 03:08:18PM -0500, Zach the Mystic wrote:
[...]
 Does any other language come close to D in terms of generics? I don't
 know, I'm just asking?
[...]

AFAIK, no. But then I only have C++ to compare with, and if I understand
it correctly Java and C#'s generics don't even come close to C++'s
templates (in terms of expressive power, though they are certainly a lot
cleaner than the mess that is C++ template syntax).


T

-- 
Some ideas are so stupid that only intellectuals could believe them. -- George 
Orwell


Re: Cannot cast void* to arrays..?

2012-02-24 Thread Andrej Mitrovic
On 2/24/12, simendsjo simend...@gmail.com wrote:
 I don't get it. This gives me a dynamic array, not a static:
  char[1] a;
  auto b = cast(void*)a;
  auto c = (cast(char*)b)[0..1];
  c.length = 10; // auch!


You can do:
char[1] c = (cast(char*)b)[0..1];


Re: SONAME and D

2012-02-24 Thread Jordi Sayol
Al 24/02/12 20:45, En/na H. S. Teoh ha escrit:
 On Fri, Feb 24, 2012 at 08:36:03PM +0100, Jordi Sayol wrote:
 [...]
 better wait till libphobos2.a becomes libphobos2.so
 [...]
 
 You might have to wait a while for that. AFAIK there are no plans
 currently to make phobos available as a shared library yet.
 
 I personally think that phobos *should* be a shared object at some
 point, but not everyone agrees with me.
 

I think that phobos should be a shared object too, but only when it has some 
sense (by now, every dmd release breaks previous libraries, at least gtkd ones)

Best regards,
-- 
Jordi Sayol


Re: SONAME and D

2012-02-24 Thread H. S. Teoh
On Fri, Feb 24, 2012 at 09:35:57PM +0100, Jordi Sayol wrote:
 Al 24/02/12 20:45, En/na H. S. Teoh ha escrit:
[...]
  I personally think that phobos *should* be a shared object at some
  point, but not everyone agrees with me.
  
 
 I think that phobos should be a shared object too, but only when it
 has some sense (by now, every dmd release breaks previous libraries,
 at least gtkd ones)
[...]

I suppose D/Phobos is currently still too volatile to start committing
to shared library version numbers yet. One *could* in theory start doing
it and just end up with very large version numbers, which the system in
theory can handle just fine, although people seem aversive to the
possibility of having /usr/lib/libphobos.so.2.x for all x from 0 to some
very large number.


T

-- 
It won't be covered in the book. The source code has to be useful for
something, after all. -- Larry Wall


deh_end

2012-02-24 Thread Ellery Newcomer
So I'm all trying out this hot new shared switch, and it works just 
dandy for -m32 when d has the main function. But now I want to be able 
to call my shared lib from C.


my little shared lib, tup.d:


import std.stdio;
extern(C) void xyz(int i){
writeln(i);
}


compiled like so:

dmd -shared -m32 tup.d -oflibtup.so

my little C program, tok.c:

extern void xyz(int);

int main(int argc, char **argv){
xyz(1);
}


compiled like so:

gcc -m32 tok.c -L. -ltup

Oh no!

./libtup.so: undefined reference to `_deh_beg'
./libtup.so: undefined reference to `_tlsend'
./libtup.so: undefined reference to `_tlsstart'
./libtup.so: undefined reference to `_deh_end'
collect2: ld returned 1 exit status


It seems like I've run into this before with static libs, but I'll ask 
again anyways. What the heck are these symbols for?


looking in druntime, I find

extern (C)
{
extern __gshared
{
void* _deh_beg;
void* _deh_end;
}

So I guess I have to put those in tok.c? And then start druntime?

Okay, fine. add

void *_deh_beg;
void *_deh_end;
__thread void *_tlsstart;
__thread void *_tlsend;

to tok.c

Then everything compiles, but a.out segfaults. I guess it didn't start 
druntime on its own.


so add to tup.d

extern shared bool _D2rt6dmain212_d_isHaltingOb;
alias _D2rt6dmain212_d_isHaltingOb _d_isHalting;
extern(C) {

void rt_init();
void rt_term();

void _init() {
rt_init();
}

void _fini() {
if(!_d_isHalting){
rt_term();
}
}

}

then dmd complains about _fini and _init being multiply defined. what to do?


Re: Cannot cast void* to arrays..?

2012-02-24 Thread simendsjo
On Fri, 24 Feb 2012 21:36:21 +0100, Andrej Mitrovic  
andrej.mitrov...@gmail.com wrote:



On 2/24/12, simendsjo simend...@gmail.com wrote:

I don't get it. This gives me a dynamic array, not a static:
 char[1] a;
 auto b = cast(void*)a;
 auto c = (cast(char*)b)[0..1];
 c.length = 10; // auch!



You can do:
char[1] c = (cast(char*)b)[0..1];


Thanks! I had to do an explicit cast(char[1]) (or actually char[1][1] in  
my case.)


Re: 2.058 broke my build. Is this a bug?

2012-02-24 Thread Caligo
That was a typo, and it doesn't change anything.  Here is a shorter version:

88
import std.datetime;
import std.stdio;

struct A{

  auto fun(A a){ return 0; }
}

void bench(alias fun)(string msg, uint n = 1_000_000){

  auto b = benchmark!fun(n);
  writefln( %s %s ms, msg, b[0].to!(msecs, int));
}

unittest{

  A a, b;

  void test1(){
auto r = a.fun(b);
  }

  bench!( {auto r = a.fun(b);} )(Does Not work);
  bench!(test1)(Works);
}

void main(){ }
88



And here is the error:

/usr/include/d/dmd/phobos/std/datetime.d(30986): Error: safe function
'benchmark' cannot call system delegate '__lambda1'
t1.d(11): Error: template instance
t1.__unittest2.benchmark!(__lambda1) error instantiating
t1.d(23):instantiated from here: bench!(delegate @system void()
{
int r = a.fun(b);
}
)
t1.d(23): Error: template instance t1.__unittest2.bench!(delegate @system void()
{
int r = a.fun(b);
}
) error instantiating


Re: mixin template FAIL

2012-02-24 Thread James Miller
On Feb 25, 2012 9:08 AM, Zach the Mystic 
reachzachatgooglesmailserv...@dot.com wrote:

 On 2/23/12 7:33 PM, Ellery Newcomer wrote:

 import std.stdio;

 mixin template helpMe()
 {
 writeln(Satisfying!);
 }

 does it do that if you replace the statement with a declaration?

 like this:

 mixin template helpMe()
 {
 int durrr = (writeln(Satisfying!), 1);
 }


 No, it doesn't. You're right. I guess I have a long way to go to learn
these things.

 Thank you. Even at my primitive level, though, I can see how awesome
these things could be once you know how to program them. Does any other
language come close to D in terms of generics? I don't know, I'm just
asking?

 Zach

Lisp macros. But that's not a fair comparison, Lisp's object system was
built using their macros...

--
James Miller


Re: 2.058 broke my build. Is this a bug?

2012-02-24 Thread James Miller
On Feb 25, 2012 12:16 PM, Caligo iteronve...@gmail.com wrote:

 That was a typo, and it doesn't change anything.  Here is a shorter
version:

 88
 import std.datetime;
 import std.stdio;

 struct A{

  auto fun(A a){ return 0; }
 }

 void bench(alias fun)(string msg, uint n = 1_000_000){

  auto b = benchmark!fun(n);
  writefln( %s %s ms, msg, b[0].to!(msecs, int));
 }

 unittest{

  A a, b;

  void test1(){
auto r = a.fun(b);
  }

  bench!( {auto r = a.fun(b);} )(Does Not work);
  bench!(test1)(Works);
 }

 void main(){ }
 88



 And here is the error:

 /usr/include/d/dmd/phobos/std/datetime.d(30986): Error: safe function
 'benchmark' cannot call system delegate '__lambda1'
 t1.d(11): Error: template instance
 t1.__unittest2.benchmark!(__lambda1) error instantiating
 t1.d(23):instantiated from here: bench!(delegate @system void()
 {
 int r = a.fun(b);
 }
 )
 t1.d(23): Error: template instance t1.__unittest2.bench!(delegate @system
void()
 {
 int r = a.fun(b);
 }
 ) error instantiating

Hmm it seems that the delegate is being implicitly marked as system, and im
not sure why benchmark is @safe. I'd say file a bug report.


Re: 2.058 broke my build. Is this a bug?

2012-02-24 Thread Caligo
Is there another workaround than the one I've posted?

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

On Fri, Feb 24, 2012 at 8:44 PM, James Miller ja...@aatch.net wrote:
 Hmm it seems that the delegate is being implicitly marked as system, and im
 not sure why benchmark is @safe. I'd say file a bug report.


Re: std.net.curl not working in 2.058 for Windows

2012-02-24 Thread Brad Anderson

On Friday, 24 February 2012 at 08:47:14 UTC, Brad Anderson wrote:
On Friday, 24 February 2012 at 07:59:50 UTC, Brad Anderson 
wrote:
There is no documentation (both on dlang.org and in the local 
documentation) so I'm not sure if it's supposed to be working 
yet.  I get linker errors when I try to use it:


   $ dmd netcurl.d
   OPTLINK (R) for Win32  Release 8.00.12
   Copyright (C) Digital Mars 1989-2010  All rights reserved.
   http://www.digitalmars.com/ctg/optlink.html
   netcurl.obj(netcurl)
Error 42: Symbol Undefined 
_D3std3net4curl3FTP8__cpctorMxFKxS3std3net4curl3FTPZv

   netcurl.obj(netcurl)
Error 42: Symbol Undefined 
_D3std3net4curl3FTP11__fieldDtorMFZv

   netcurl.obj(netcurl)
Error 42: Symbol Undefined _D3std3net4curl3FTP7performMFZv
   netcurl.obj(netcurl)
Error 42: Symbol Undefined 
_D3std3net4curl13CurlException7__ClassZ

   netcurl.obj(netcurl)
Error 42: Symbol Undefined 
_D3std3net4curl13CurlException6__ctorMFAyaAyakC6object9ThrowableZC3std3net4curl13CurlException

   netcurl.obj(netcurl)

   [snip]

Furthermore the documentation in the actual source says this 
should work:


   string content = get(http://dlang.org;);

But that results in a compiler error error:

   netcurl.d(5): Error: cannot implicitly convert expression 
(get(http://dlang.org,AutoProtocol())) of type char[] to 
string


get() signature from the source is:

   T[] get(Conn = AutoProtocol, T = char)(const(char)[] url, 
Conn conn = Conn())
   if ( isCurlConn!Conn  (is(T == char) || is(T == 
ubyte)) )


An .idup fixes it, of course, but the documentation is wrong 
(or the signature is wrong).


Finally, was the curl library included?  If not, where can it 
be found?  It needs to be an OMF version, right?  I don't see 
an OMF version on curl's website.


Regards,
Brad Anderson



It would appear phobos's win32.mak wasn't updated to include 
the curl wrapper.


I can try to figure out how the makefile works and send a pull 
request if nobody who knows what's going on has time.


Regards,
Brad Anderson


https://github.com/D-Programming-Language/phobos/pull/458
https://github.com/D-Programming-Language/d-programming-language.org/pull/91

Regards,
Brad Anderson


Re: 2.058 broke my build. Is this a bug?

2012-02-24 Thread Caligo
I found another workaround: mark the module as trusted.


struct init() method

2012-02-24 Thread bearophile
This program comes from a reduction of a bug I've found:


struct Foo {
void init() {}
}
void main() {
Foo*[] foos;
//(*foos[0]).init(); // OK
foos[0].init(); // Error: function expected before (), not null of type Foo*
}


What do you think about the idea of not allowing methods named init() in 
structs? (Especially if they are a @property). Or maybe there is a better 
solution, opinions welcome.

Bye,
bearophile