Re: DMD on linux? (more problems)
On 2011-03-03 00:43, Sean Eskapp wrote: I'm still having issues with the linux dmd. Here's the relevant part of the output: ... function func function func gcc Nullimorphism.o -o Nullimorphism.exe -g -m32 -l -Xlinker - L/usr/lib32 -Xlinker -L/usr/lib64 -Xlinker --no-warn-search-mismatch -Xlinker --export-dynamic -lrt -lphobos2 -lpthread -lm /usr/bin/ld: cannot find -l-Xlinker collect2: ld returned 1 exit status --- errorlevel 1 make[1]: *** [all] Error 1 make[1]: Leaving directory ... Any help is appreciated. You can give this a try: https://bitbucket.org/doob/dvm/wiki/Home -- /Jacob Carlborg
Re: std.zlib and other tools
Jesse Phillips wrote: >I'm just wondering if anyone else has an issue with using std.zlib >with other programs such as gzip and 7-zip? zlib creates and loads gz >files right? > >The library works perfectly with itself, but I can't read or write >compressed files from other popular programs. > >mport std.stdio; >import std.file; >import std.zlib; >auto searchFolder = r"."; > >void main() { > foreach(string de; dirEntries(searchFolder, SpanMode.shallow)) { > if(de[$-"gz".length..$] != "gz") { > auto data = read(de); > std.file.write(de ~ ".gz", compress(data)); > } > } > foreach(string de; dirEntries(searchFolder, SpanMode.shallow)) { > if(de[$-"gz".length..$] == "gz") { > auto data = read(de); > std.file.write(de ~ ".txt", uncompress(data)); > } > } >} I think this could be the reason: http://zlib.net/zlib_faq.html#faq18 -- Johannes Pfau signature.asc Description: PGP signature
Re: Parameterized Structs
On 03/02/2011 11:11 PM, Peter Lundgren wrote: > == Quote from Ali Çehreli (acehr...@yahoo.com)'s article >> On 03/02/2011 08:56 PM, Peter Lundgren wrote: >>> Where can I go to learn about parameterized structs? I can't seem to find any >>> literature on the subject. In particular, what are you allowed to use as a >>> parameter? I would like to define a struct like so: >>> >>> struct MyStruct(T, T[] a) { >>> ... >>> } >>> >>> but I receive the following error: >>> >>> Error: arithmetic/string type expected for value-parameter, not T[] >>> >>> Are arrays not allowed? >> Are you trying to parametrize by the type of the container or just >> trying to use an array of a specified type? (As opposed to say, a linked >> list of the specified type?) >> If the former, it's simple. And the simplest thing is to just use an >> array in the implementation: >> struct S(T) >> { >> T[] a; >> void foo(T element) >> { >> /* Just use like an array */ >> a ~= element; >> a[0] = element; >> } >> } >> void main() >> { >> auto s = S!double(); >> s.foo(1.5); >> } >> If you want to use a different container of the specified T, then a >> second template parameter can be used. This one uses an array as the >> default one: >> class SomeContainer >> {} >> struct S(T, Cont = T[]) >> { >> Cont a; >> void foo(T element) >> { >> /* This time the use must match the allowed container types */ >> } >> } >> void main() >> { >> auto s = S!(double, SomeContainer)(); >> s.foo(1.5); >> } >> I would recommend pulling information out ;) of this page: >> http://digitalmars.com/d/2.0/template.html >> "Template Alias Parameters" is very different after C++ and can be very >> powerful: >> http://digitalmars.com/d/2.0/template.html#TemplateAliasParameter >> Ali > > I'm using this for an alternative implementation of a string, if you will. Where T > is the type of a single character and a would be the alphabet (an array of allowed > characters). The rest of the implementation of the struct would, of course, depend > upon the provided alphabet. > > I guess value parameters can't be arbitrary types. I can probably get by with > using a string for my alphabet just fine, it just seemed an arbitrary limitation. > Why accept only arrays of characters when the code will be the same for any type? I think the SomeContainer example above should work then: it is not "arrays of characters". T[] was just the default implementation. If SomeContainer is templatized, then I think this is what you want: /* A templatized container */ class SomeContainer(T) { /* having container functions */ void add(T element) {} T access(size_t index) { return T.init; } } /* This is your "alternative implementation of a string". Can use any * container type, the default is array of Ts */ struct S(T, Cont = T[]) { Cont a; void foo(T element) { /* here the use must match the allowed container types */ } } void main() { /* We are instantiating it with * * double as the element type * SomeContainer!double as the container type */ auto s = S!(double, SomeContainer!double)(); s.foo(1.5); } But we can make it better, because 'double' and 'SomeContainer!double' repeat "double". Here the alias template parameters are handy: struct S(T, alias ContType) // <-- alias { ContType!T a;// <-- ContType!T instead of just Cont void foo(T element) { /* here the use must match the allowed container types */ } } The second parameter is an alias template parameter. (I had to drop the default value; I think we can use Array!T there, but I haven't bothered to test.) Now the use is easier and less error prone, because 'double' need not be repeated: auto s = S!(double, SomeContainer)(); Ali
Re: Struct reference returning function and const members
On Wednesday 02 March 2011 22:42:18 Tom wrote: > I have... > > int main(string[] args) { > auto s1 = f(); // MH MH > auto s2 = g(); // OK > s2.c = null; // OK > return 0; > } > > class C {} > > struct StructWithConstMember { > this(int i, C c) { this.i=i; this.c=c; } > int i; > const(C) c; > } > > struct StructWithoutConstMember { > this(int i, C c) { this.i=i; this.c=c; } > int i; > C c; > } > > ref StructWithConstMember f() { > return * new StructWithConstMember(1, new C); // ERROR > } > > ref StructWithoutConstMember g() { > return * new StructWithoutConstMember(1, new C); // OK > } > > > And get the error... > src\main.d(27): Error: *new StructWithConstMember(1,new C) is not mutable > > So I can't return a struct that has a const member? Why? Am I missing > something something? Well, it has something do to with the ref, since passing be value works. I'm not sure if it's a bug or not. On the whole, I would _not_ advise that you have structs with const or immutable member variables. You can never reassign to them. And that may be related to why it's not working here. It may very well be a bug - I sure don't know why it isn't working here - but in general, having structs with const or immutable members probably isn't a good idea. - Jonathan M Davis
Re: Two questions about "%a"
On Wed, 02 Mar 2011 13:35:11 +0100, Magnus Lie Hetland wrote: > First question: I just noticed that writefln("%a", 1.2) writes > 0x1.3p+0, while writeln(format("%a", 1.2)) (that is, with > std.string.format) writes 0x9.8p-3 ... wouldn't it be nice > to be consistent here? (The former is what printf in gcc gives.) Or am I > missing a difference in functionality? Hm, that's weird. I'm pretty sure writefln() is doing the right thing here, since that's what printf() does. I've had a look at the code for format(), and it looks to me like it is using some old formatting code that is being phased out. I've created a bug report for this, and will look into fixing it shortly: http://d.puremagic.com/issues/show_bug.cgi?id=5687 > Second question: Just to make sure, this *is* an exact representation of > the underlying floating-point number? (I.e., if that'w what I'm after, > using %a *is* the way to go?) Yes, that's right. -Lars
Re: Parameterized Structs
== Quote from Ali Çehreli (acehr...@yahoo.com)'s article > On 03/02/2011 08:56 PM, Peter Lundgren wrote: > > Where can I go to learn about parameterized structs? I can't seem to find > > any > > literature on the subject. In particular, what are you allowed to use as a > > parameter? I would like to define a struct like so: > > > > struct MyStruct(T, T[] a) { > > ... > > } > > > > but I receive the following error: > > > > Error: arithmetic/string type expected for value-parameter, not T[] > > > > Are arrays not allowed? > Are you trying to parametrize by the type of the container or just > trying to use an array of a specified type? (As opposed to say, a linked > list of the specified type?) > If the former, it's simple. And the simplest thing is to just use an > array in the implementation: > struct S(T) > { > T[] a; > void foo(T element) > { > /* Just use like an array */ > a ~= element; > a[0] = element; > } > } > void main() > { > auto s = S!double(); > s.foo(1.5); > } > If you want to use a different container of the specified T, then a > second template parameter can be used. This one uses an array as the > default one: > class SomeContainer > {} > struct S(T, Cont = T[]) > { > Cont a; > void foo(T element) > { > /* This time the use must match the allowed container types */ > } > } > void main() > { > auto s = S!(double, SomeContainer)(); > s.foo(1.5); > } > I would recommend pulling information out ;) of this page: >http://digitalmars.com/d/2.0/template.html > "Template Alias Parameters" is very different after C++ and can be very > powerful: >http://digitalmars.com/d/2.0/template.html#TemplateAliasParameter > Ali I'm using this for an alternative implementation of a string, if you will. Where T is the type of a single character and a would be the alphabet (an array of allowed characters). The rest of the implementation of the struct would, of course, depend upon the provided alphabet. I guess value parameters can't be arbitrary types. I can probably get by with using a string for my alphabet just fine, it just seemed an arbitrary limitation. Why accept only arrays of characters when the code will be the same for any type?
Re: Struct reference returning function and const members
El 03/03/2011 03:47, Ali Çehreli escribió: On 03/02/2011 10:42 PM, Tom wrote: I have... int main(string[] args) { auto s1 = f(); // MH MH auto s2 = g(); // OK s2.c = null; // OK return 0; } class C {} struct StructWithConstMember { this(int i, C c) { this.i=i; this.c=c; } int i; const(C) c; } struct StructWithoutConstMember { this(int i, C c) { this.i=i; this.c=c; } int i; C c; } ref StructWithConstMember f() { return * new StructWithConstMember(1, new C); // ERROR } ref StructWithoutConstMember g() { return * new StructWithoutConstMember(1, new C); // OK } And get the error... src\main.d(27): Error: *new StructWithConstMember(1,new C) is not mutable So I can't return a struct that has a const member? Why? Am I missing something something? Thanks, Tom; I don't know the full answer but returning a reference to const object works: ref const(StructWithConstMember) f() { return * new StructWithConstMember(1, new C); // now compiles } Ali I know, but I don't want a const struct. It's like if const transitivity were going backwards, or something. :(
Re: Struct reference returning function and const members
On 03/02/2011 10:42 PM, Tom wrote: I have... int main(string[] args) { auto s1 = f(); // MH MH auto s2 = g(); // OK s2.c = null; // OK return 0; } class C {} struct StructWithConstMember { this(int i, C c) { this.i=i; this.c=c; } int i; const(C) c; } struct StructWithoutConstMember { this(int i, C c) { this.i=i; this.c=c; } int i; C c; } ref StructWithConstMember f() { return * new StructWithConstMember(1, new C); // ERROR } ref StructWithoutConstMember g() { return * new StructWithoutConstMember(1, new C); // OK } And get the error... src\main.d(27): Error: *new StructWithConstMember(1,new C) is not mutable So I can't return a struct that has a const member? Why? Am I missing something something? Thanks, Tom; I don't know the full answer but returning a reference to const object works: ref const(StructWithConstMember) f() { return * new StructWithConstMember(1, new C); // now compiles } Ali
Struct reference returning function and const members
I have... int main(string[] args) { auto s1 = f(); // MH MH auto s2 = g(); // OK s2.c = null; // OK return 0; } class C {} struct StructWithConstMember { this(int i, C c) { this.i=i; this.c=c; } int i; const(C) c; } struct StructWithoutConstMember { this(int i, C c) { this.i=i; this.c=c; } int i; C c; } ref StructWithConstMember f() { return * new StructWithConstMember(1, new C); // ERROR } ref StructWithoutConstMember g() { return * new StructWithoutConstMember(1, new C); // OK } And get the error... src\main.d(27): Error: *new StructWithConstMember(1,new C) is not mutable So I can't return a struct that has a const member? Why? Am I missing something something? Thanks, Tom;
Re: Parameterized Structs
On 03/02/2011 08:56 PM, Peter Lundgren wrote: Where can I go to learn about parameterized structs? I can't seem to find any literature on the subject. In particular, what are you allowed to use as a parameter? I would like to define a struct like so: struct MyStruct(T, T[] a) { ... } but I receive the following error: Error: arithmetic/string type expected for value-parameter, not T[] Are arrays not allowed? Are you trying to parametrize by the type of the container or just trying to use an array of a specified type? (As opposed to say, a linked list of the specified type?) If the former, it's simple. And the simplest thing is to just use an array in the implementation: struct S(T) { T[] a; void foo(T element) { /* Just use like an array */ a ~= element; a[0] = element; } } void main() { auto s = S!double(); s.foo(1.5); } If you want to use a different container of the specified T, then a second template parameter can be used. This one uses an array as the default one: class SomeContainer {} struct S(T, Cont = T[]) { Cont a; void foo(T element) { /* This time the use must match the allowed container types */ } } void main() { auto s = S!(double, SomeContainer)(); s.foo(1.5); } I would recommend pulling information out ;) of this page: http://digitalmars.com/d/2.0/template.html "Template Alias Parameters" is very different after C++ and can be very powerful: http://digitalmars.com/d/2.0/template.html#TemplateAliasParameter Ali
Re: Parameterized Structs
On 3/2/2011 8:56 PM, Peter Lundgren wrote: Where can I go to learn about parameterized structs? I can't seem to find any literature on the subject. In particular, what are you allowed to use as a parameter? I would like to define a struct like so: struct MyStruct(T, T[] a) { ... } but I receive the following error: Error: arithmetic/string type expected for value-parameter, not T[] Are arrays not allowed? This compiles: struct MyStruct(T : T[], T a) { T A = a.dup; } ...but I have yet to figure out how to properly invoke it.
Re: Parameterized Structs
On Wednesday 02 March 2011 20:56:41 Peter Lundgren wrote: > Where can I go to learn about parameterized structs? I can't seem to find > any literature on the subject. In particular, what are you allowed to use > as a parameter? I would like to define a struct like so: > > struct MyStruct(T, T[] a) { > ... > } > > but I receive the following error: > > Error: arithmetic/string type expected for value-parameter, not T[] > > Are arrays not allowed? I've never tried anything but arithmetic types and strings for a template value parameter, so I don't know, but the error message would certainly imply that it's not allowed. Regardless, its value would have to be known at compile time. - Jonathan M Davis
Parameterized Structs
Where can I go to learn about parameterized structs? I can't seem to find any literature on the subject. In particular, what are you allowed to use as a parameter? I would like to define a struct like so: struct MyStruct(T, T[] a) { ... } but I receive the following error: Error: arithmetic/string type expected for value-parameter, not T[] Are arrays not allowed?
Re: DMD on linux? (more problems)
Sean Eskapp Wrote: > I'm still having issues with the linux dmd. Here's the relevant part > of the output: > > ... > function func > function func > gcc Nullimorphism.o -o Nullimorphism.exe -g -m32 -l -Xlinker - > L/usr/lib32 -Xlinker -L/usr/lib64 -Xlinker --no-warn-search-mismatch > -Xlinker --export-dynamic -lrt -lphobos2 -lpthread -lm > /usr/bin/ld: cannot find -l-Xlinker > collect2: ld returned 1 exit status > --- errorlevel 1 > make[1]: *** [all] Error 1 > make[1]: Leaving directory > ... > > Any help is appreciated. I think the part LD is tripping up on is "-m32 -l -Xlinker" So it seems you are calling dmd incorrectly or modified dmd.conf incorrectly as there is no argument after -l so LD thinks you want to link against lib-Xlinker.
DMD on linux? (more problems)
I'm still having issues with the linux dmd. Here's the relevant part of the output: ... function func function func gcc Nullimorphism.o -o Nullimorphism.exe -g -m32 -l -Xlinker - L/usr/lib32 -Xlinker -L/usr/lib64 -Xlinker --no-warn-search-mismatch -Xlinker --export-dynamic -lrt -lphobos2 -lpthread -lm /usr/bin/ld: cannot find -l-Xlinker collect2: ld returned 1 exit status --- errorlevel 1 make[1]: *** [all] Error 1 make[1]: Leaving directory ... Any help is appreciated.
Re: DMD on linux?
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article > On Wednesday, March 02, 2011 13:52:29 Sean Eskapp wrote: > > I'm trying to work with D on Ubuntu, but I keep having this issue: > > > > ... > > function func > > function func > > gcc Nullimorphism.o -o Nullimorphism.exe -g -m32 -l -Xlinker > > -L/usr/bin/../lib32 -Xlinker - L/usr/bin/../lib64 -Xlinker > > --no-warn-search-mismatch -Xlinker --export-dynamic -lrt - lphobos2 > > -lpthread -lm > > /usr/bin/ld: cannot find -l-Xlinker > > /usr/bin/ld: cannot find -lphobos2 > > collect2: ld returned 1 exit status > > --- errorlevel 1 > > make[1]: *** [all] Error 1 > > ... > > > > I downloaded the DMD v2.052 ZIP from the download page, extracted the > > linux/bin folder into /usr/bin, the linux/lib64 folder into /usr/lib64, > > and the src folder into /usr/src. Can somebody please help? > 1. I never bother installing the zip anywhere. If you just unzip it and add > /path/to/unzipped/dmd2/linux/bin to your path, then you should be fine. I don't > see any real reason to actual try and install dmd into your system folders > (though you obviously can if you want to). > 2. Assuming that you _do_ move files around, you need to adjust your dmd.conf so > that it points to the appropriate places. > 3. If you just moved files around, then you might not _have_ a dmd.conf, and > you're doubly screwed. > Take a look at the documentation page for dmd on linux: > http://www.digitalmars.com/d/2.0/dmd-linux.html > It's slightly out of date, since with the last release, 64-bit support was > added, and the 32-bit version of libphobos.a is in > /path/to/unzipped/dmd2/linux/lib32 and the 64-bit version is in > /path/to/unzipped/dmd2/linux/lib64, but the instructions should be correct > otherwise. > You need to make sure that dmd is on your path and that a version of dmd.conf > which points to the place where libphobos2.a is is in one of the places that dmd > looks for dmd.conf (as described on that page). Also, make sure that you're > using a dmd.conf based on the most recent version, or you could be missing > necessary linker flags. > - Jonathan M Davis Hmm my dmd.conf seems fine, but since the .deb has been updated, I can just use that. Thanks!
std.zlib and other tools
I'm just wondering if anyone else has an issue with using std.zlib with other programs such as gzip and 7-zip? zlib creates and loads gz files right? The library works perfectly with itself, but I can't read or write compressed files from other popular programs. mport std.stdio; import std.file; import std.zlib; auto searchFolder = r"."; void main() { foreach(string de; dirEntries(searchFolder, SpanMode.shallow)) { if(de[$-"gz".length..$] != "gz") { auto data = read(de); std.file.write(de ~ ".gz", compress(data)); } } foreach(string de; dirEntries(searchFolder, SpanMode.shallow)) { if(de[$-"gz".length..$] == "gz") { auto data = read(de); std.file.write(de ~ ".txt", uncompress(data)); } } }
Re: DMD on linux?
On 02/03/11 21:52, Sean Eskapp wrote: I'm trying to work with D on Ubuntu, but I keep having this issue: ... function func function func gcc Nullimorphism.o -o Nullimorphism.exe -g -m32 -l -Xlinker -L/usr/bin/../lib32 -Xlinker - L/usr/bin/../lib64 -Xlinker --no-warn-search-mismatch -Xlinker --export-dynamic -lrt - lphobos2 -lpthread -lm /usr/bin/ld: cannot find -l-Xlinker /usr/bin/ld: cannot find -lphobos2 collect2: ld returned 1 exit status --- errorlevel 1 make[1]: *** [all] Error 1 ... I downloaded the DMD v2.052 ZIP from the download page, extracted the linux/bin folder into /usr/bin, the linux/lib64 folder into /usr/lib64, and the src folder into /usr/src. Can somebody please help? See also: http://ftp.digitalmars.com/dmd_2.052-0_i386.deb for everything to work out of the box. -- Robert http://octarineparrot.com/
Re: DMD on linux?
On Wednesday, March 02, 2011 13:52:29 Sean Eskapp wrote: > I'm trying to work with D on Ubuntu, but I keep having this issue: > > ... > function func > function func > gcc Nullimorphism.o -o Nullimorphism.exe -g -m32 -l -Xlinker > -L/usr/bin/../lib32 -Xlinker - L/usr/bin/../lib64 -Xlinker > --no-warn-search-mismatch -Xlinker --export-dynamic -lrt - lphobos2 > -lpthread -lm > /usr/bin/ld: cannot find -l-Xlinker > /usr/bin/ld: cannot find -lphobos2 > collect2: ld returned 1 exit status > --- errorlevel 1 > make[1]: *** [all] Error 1 > ... > > I downloaded the DMD v2.052 ZIP from the download page, extracted the > linux/bin folder into /usr/bin, the linux/lib64 folder into /usr/lib64, > and the src folder into /usr/src. Can somebody please help? 1. I never bother installing the zip anywhere. If you just unzip it and add /path/to/unzipped/dmd2/linux/bin to your path, then you should be fine. I don't see any real reason to actual try and install dmd into your system folders (though you obviously can if you want to). 2. Assuming that you _do_ move files around, you need to adjust your dmd.conf so that it points to the appropriate places. 3. If you just moved files around, then you might not _have_ a dmd.conf, and you're doubly screwed. Take a look at the documentation page for dmd on linux: http://www.digitalmars.com/d/2.0/dmd-linux.html It's slightly out of date, since with the last release, 64-bit support was added, and the 32-bit version of libphobos.a is in /path/to/unzipped/dmd2/linux/lib32 and the 64-bit version is in /path/to/unzipped/dmd2/linux/lib64, but the instructions should be correct otherwise. You need to make sure that dmd is on your path and that a version of dmd.conf which points to the place where libphobos2.a is is in one of the places that dmd looks for dmd.conf (as described on that page). Also, make sure that you're using a dmd.conf based on the most recent version, or you could be missing necessary linker flags. - Jonathan M Davis
DMD on linux?
I'm trying to work with D on Ubuntu, but I keep having this issue: ... function func function func gcc Nullimorphism.o -o Nullimorphism.exe -g -m32 -l -Xlinker -L/usr/bin/../lib32 -Xlinker - L/usr/bin/../lib64 -Xlinker --no-warn-search-mismatch -Xlinker --export-dynamic -lrt - lphobos2 -lpthread -lm /usr/bin/ld: cannot find -l-Xlinker /usr/bin/ld: cannot find -lphobos2 collect2: ld returned 1 exit status --- errorlevel 1 make[1]: *** [all] Error 1 ... I downloaded the DMD v2.052 ZIP from the download page, extracted the linux/bin folder into /usr/bin, the linux/lib64 folder into /usr/lib64, and the src folder into /usr/src. Can somebody please help?
Re: Template argument deduction
El 01/03/2011 16:05, Ali Çehreli escribió: On 02/28/2011 07:39 PM, Tom wrote: > foo([[1,2],[3,4],[5,6]]); // ERROR [1] > bar([[1,2],[3,4],[5,6]]); // OK > foo!int([[1,2],[3,4],[5,6]]); // OK ... > void foo(T)(T[2][] t) { > writeln(typeid(t)); > } > > void bar(T)(T[][] t) { > writeln(typeid(t)); > } On 03/01/2011 04:30 AM, bearophile wrote: > Ali Çehreli: > >> That's because the type of literals like [1, 2] are slices (dynamic >> arrays), not fixed-sized arrays. > > Then why is this accepted? > > foo!int([[1,2],[3,4],[5,6]]); // OK If I have to guess, I think supplying T as int now becomes a problem of matching [1,2] with int[2] and it already works: int[2] a = [1, 2]; int[2][] b = [ [1, 2] ]; I don't know whether the compiler should go the extra mile and help Tom in the original case. :-/ Ali I should post on D newsgroup. Perhaps Walter or Andrei could enlight us about this. Thanks, Tom;
Re: Can't figure out segfault
On 03/02/2011 01:49 AM, rm wrote: I put together bindings for DevIL in D to use on a school assignment. The bindings (attached) work fine on Windows, but cause a segfault on Linux when I call ilInit. this can be demonstrated by a little test program " import graphics.bindings.devil; public void main(string[] args) { ilInit(); } " compiled with "dmd -L-ldl test.d devil.d" where test.d is the above program and devil.d is attached. When run, this program segfaults, but if lines 112,113,165,166 of devil.d are commented out, the program works fine, and I can't figure out what the problem with those lines is. The fact that this works on Windows confuses me even more. Any help would be appreciated. On linux the linker is called with --export-dynamic by default and this tells the linker to export all the symbols pressent in your executable. So it is posible that dlsym is returning the address of the symbols in your execuable. Thunderbird is having some problems with your attachment so i'm not able to test, but renaming the functions should do the trick. -- Mike Wey
Re: Some weird crashes
On 3/2/11 10:52 AM, simendsjo wrote: I couldn't find a free download for coff2omf, that's why I don't use the supplied .lib. You can use coffimplib: ftp://ftp.digitalmars.com/coffimplib.zip
Re: Some weird crashes
On 02.03.2011 18:24, Denis Koroskin wrote: On Tue, 01 Mar 2011 23:01:21 +0300, simendsjo wrote: On 28.02.2011 20:24, Denis Koroskin wrote: On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo wrote: On 28.02.2011 18:52, simendsjo wrote: // ERROR auto res = mysql_library_init(0, null, null); auto cn = mysql_init(null); auto oldcn = cn; writeln(mysql_errno(cn)); assert(cn == oldcn); // when the last assert is active, the above line changes cn and thus fails. auto err = mysql_errno(cn); assert(cn == oldcn); Btw, if I don't use writeln it doesn't fail.. I think you have a bug at line 42. On a serious note, it might have helped if you'd attached source code, or at least binaries. Hmmm.. Seems my post last night didn't get through.. Here's the code and necessary libraries: http://share1t.com/4xgt2l What appears to be an error here is in fact an Access Violation at mysql_close. Here is a reduced test-case: import mysql; void main() { auto res = mysql_library_init(0, null, null); auto cn = mysql_init(null); mysql_close(cn); } Then I decided to check whether it is D's fault or not by porting this short program to C. Here is what I got: // mysql.c int mysql_server_init(int argc, char **argv, char **groups); struct MYSQL* mysql_init(struct MYSQL*); void mysql_close(struct MYSQL*); #define mysql_library_init mysql_server_init #define NULL 0 #include int main() { int res = mysql_library_init(0, NULL, NULL); struct MYSQL* cn = mysql_init(NULL); printf("here"); mysql_close(cn); return 0; } This program works fine, BUT try commenting out the "printf" call and it crashes, too. That said, it is unlikely to be DMD fault here. Are you sure those prototypes and/or .lib/.dll files are fine? The prototypes might be wrong. I'm in the process of checking everything. The dll is the one included in the download. The lib is made with implib /system But your c program fails..? Could the problem be with the implib library..? I couldn't find a free download for coff2omf, that's why I don't use the supplied .lib.
Re: About const and C functions
On 3/2/11 4:06 AM, bearophile wrote: Can't D/DMD err on the side of safety and consider the C-style variadic argument as not const, and so produce an error if you give to them something that's D const/immutable (and require a cast there)? (Especially a function like sscanf where the third and successive arguments are known to be modified). With an annotation on the function signature, perhaps, and certainly it should do this at all times in code marked @safe.
Re: comparing pointers passed to and returned from funcs
On 03/02/2011 02:24 PM, Steven Schveighoffer wrote: On Tue, 01 Mar 2011 18:11:00 -0500, bearophile wrote: http://d.puremagic.com/issues/show_bug.cgi?id=5678 I think there is a general bug where any time the compiler uses an enum, it simply replaces the expression declared for the enum. So basically enum TRUE = new DElement(true); void main() { auto delem1 = TRUE; auto delem2 = TRUE; assert(delem1 is delem2); // fails } gets morphed into this: void main() { auto delem1 = new Delement(true); auto delem2 = new Delement(true); assert(delem1 is delem2); // fails } Obviously this works great when the enum is a value type or a string literal (which is created at compile time). However, it is not so great for things like AAs, array literals, objects, or structs. I think there are a few of these bugs in bugzilla, and there should be at least a tracker, and if not, they should all be combined. This is a serious problem in D, and really creates havoc (both performance-wise and semantically). I don't anticipate there is an easy fix. Essentially, I'd say enum is completely useless except for builtin types and strings. Thank you Steven & Bearophile. This solves my problem. I first did not get Bearophile's answer about run/compile-time constants (I mean enums). I thought the time when they are created is irrelevant, isn't it? Anyway, placing the constant defs inside a module's block does what I mean. It does, in fact, ensure *unicity*. But I don't really understand the relation with Steven's explanation above: why/how does the fact that a constant's def is inside static this() prevent the compiler to rewrite it like shown above? Also, I basically don't understand why dmd does that anyway: it's obviously un-ecological ;-) Denis -- _ vita es estrany spir.wikidot.com
Re: Some weird crashes
On Tue, 01 Mar 2011 23:01:21 +0300, simendsjo wrote: On 28.02.2011 20:24, Denis Koroskin wrote: On Mon, 28 Feb 2011 22:04:44 +0300, simendsjo wrote: On 28.02.2011 18:52, simendsjo wrote: // ERROR auto res = mysql_library_init(0, null, null); auto cn = mysql_init(null); auto oldcn = cn; writeln(mysql_errno(cn)); assert(cn == oldcn); // when the last assert is active, the above line changes cn and thus fails. auto err = mysql_errno(cn); assert(cn == oldcn); Btw, if I don't use writeln it doesn't fail.. I think you have a bug at line 42. On a serious note, it might have helped if you'd attached source code, or at least binaries. Hmmm.. Seems my post last night didn't get through.. Here's the code and necessary libraries: http://share1t.com/4xgt2l What appears to be an error here is in fact an Access Violation at mysql_close. Here is a reduced test-case: import mysql; void main() { auto res = mysql_library_init(0, null, null); auto cn = mysql_init(null); mysql_close(cn); } Then I decided to check whether it is D's fault or not by porting this short program to C. Here is what I got: // mysql.c int mysql_server_init(int argc, char **argv, char **groups); struct MYSQL* mysql_init(struct MYSQL*); void mysql_close(struct MYSQL*); #define mysql_library_init mysql_server_init #define NULL 0 #include int main() { int res = mysql_library_init(0, NULL, NULL); struct MYSQL* cn = mysql_init(NULL); printf("here"); mysql_close(cn); return 0; } This program works fine, BUT try commenting out the "printf" call and it crashes, too. That said, it is unlikely to be DMD fault here. Are you sure those prototypes and/or .lib/.dll files are fine?
Re: comparing pointers passed to and returned from funcs
On Tue, 01 Mar 2011 18:11:00 -0500, bearophile wrote: http://d.puremagic.com/issues/show_bug.cgi?id=5678 I think there is a general bug where any time the compiler uses an enum, it simply replaces the expression declared for the enum. So basically enum TRUE = new DElement(true); void main() { auto delem1 = TRUE; auto delem2 = TRUE; assert(delem1 is delem2); // fails } gets morphed into this: void main() { auto delem1 = new Delement(true); auto delem2 = new Delement(true); assert(delem1 is delem2); // fails } Obviously this works great when the enum is a value type or a string literal (which is created at compile time). However, it is not so great for things like AAs, array literals, objects, or structs. I think there are a few of these bugs in bugzilla, and there should be at least a tracker, and if not, they should all be combined. This is a serious problem in D, and really creates havoc (both performance-wise and semantically). I don't anticipate there is an easy fix. Essentially, I'd say enum is completely useless except for builtin types and strings. -Steve
Re: Constructor template -- bug?
On 2011-03-02 09:07, Jonathan M Davis wrote: On Tuesday 01 March 2011 23:52:38 Jacob Carlborg wrote: On 2011-03-02 08:47, Jonathan M Davis wrote: On Tuesday 01 March 2011 23:43:27 Jonathan M Davis wrote: On Tuesday 01 March 2011 22:18:49 Bekenn wrote: Code: class MyException : Exception { this(string message, string file, size_t line, Throwable next = null) { super(message, file, line, next); } this(string file = __FILE__, size_t line = __LINE__)(string message, Throwable next = null) { this(message, file, line, next); } } void main() { throw new MyException("Bluh!"); } Error message: test.d(8): Error: template test.MyException.__ctor(string file = __FILE__,size_t line = __LINE__) conflicts with constructor test.MyException.this at test.d(3) If I remove the normal constructor and call super instead of this from the constructor template, then I get this slightly different error message: test.d(1): Error: constructor test.MyException.this conflicts with template test.MyException.__ctor(string file = __FILE__,uint line = __LINE__) at test.d(3) Is this a compiler bug, or am I Doing It Wrong? You cannot currently templatize class constructors: http://d.puremagic.com/issues/show_bug.cgi?id=435 And currently if one overload of a function is templatized, _all_ overloads of that function must templatized: http://d.puremagic.com/issues/show_bug.cgi?id=2972 http://d.puremagic.com/issues/show_bug.cgi?id=4749 I should also point out that there is absolutely no need to use template for what you're trying to do. Just declare the constructor like so: this(string message, string file = __FILE__, size_t line = __LINE__ Throwable next = null) { ... } - Jonathan M Davis I guess the reason why he would do that is to catch the file and line number where the constructor is called. Except that that works with normal default arguments. I assume that he did not realize that. - Jonathan M Davis Neither did I. -- /Jacob Carlborg
Re: @property ref foo() { ...} won't work...?
On 2011-03-01 13:20:18 +0100, Steven Schveighoffer said: On Tue, 01 Mar 2011 07:19:21 -0500, Lars T. Kyllingstad wrote: On Tue, 01 Mar 2011 12:25:30 +0100, Magnus Lie Hetland wrote: 2. How can I make r.front = foo work, when I only have r.front(), returning a ref (which seems like it is used in actual code)? I think this is a bug, but I'm not entirely sure. It is most definitely a bug. Please file. Done. -Steve -- Magnus Lie Hetland http://hetland.org
Two questions about "%a"
First question: I just noticed that writefln("%a", 1.2) writes 0x1.3p+0, while writeln(format("%a", 1.2)) (that is, with std.string.format) writes 0x9.8p-3 ... wouldn't it be nice to be consistent here? (The former is what printf in gcc gives.) Or am I missing a difference in functionality? Second question: Just to make sure, this *is* an exact representation of the underlying floating-point number? (I.e., if that'w what I'm after, using %a *is* the way to go?) -- Magnus Lie Hetland http://hetland.org
Re: About const and C functions
Bekenn: > I'm not sure that's checkable. I think this falls squarely into the > realm of "undefined behavior". The signature of sscanf is something like: int sscanf(char* str, char* format, ...); Can't D/DMD err on the side of safety and consider the C-style variadic argument as not const, and so produce an error if you give to them something that's D const/immutable (and require a cast there)? (Especially a function like sscanf where the third and successive arguments are known to be modified). Bye, bearophile
Re: About const and C functions
On 02/03/2011 11:28, Simon wrote: On 02/03/2011 08:56, Trass3r wrote: Am 01.03.2011, 23:33 Uhr, schrieb bearophile : Do you know why DMD doesn't give a compilation error here? import core.stdc.stdio: sscanf; immutable int value = 5; void main() { sscanf("10".ptr, "%d".ptr, &value); } What's the D signature of sscanf? void* after the format arg... Rather it's the ellipses, which is effectively void* -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk
Re: About const and C functions
On 02/03/2011 08:56, Trass3r wrote: Am 01.03.2011, 23:33 Uhr, schrieb bearophile : Do you know why DMD doesn't give a compilation error here? import core.stdc.stdio: sscanf; immutable int value = 5; void main() { sscanf("10".ptr, "%d".ptr, &value); } What's the D signature of sscanf? void* after the format arg... -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk
Re: Can't figure out segfault
Assuming you've checked that dlopen isn't returning null, I can't find the source of the error in that code, sorry. Unsolicited advice: Is there any reason you're manually loading the dll rather than using an import library? A couple of remarks about the rest of the code: Generally in D the constants would all be: enum uint IL_BLAH = BLAH; rather than immutable. You can specify attributes such as public and immutable in blocks public immutable { // lots of constants } Or if using enums, the following will have the same effect. enum : uint { constant1 = value, constant2 = value, } All of your function pointers are currently thread local, as are the static ctor/dtors. To have them run once rather than once per thread, you should use 'shared static this()' and 'shared static ~this()' instead, and mark the function pointer variables as __gshared. In all of the 'pointer = cast(function pointer)dlsym(...);' calls you're actually relying on a compiler bug, as you're assigning a 'extern(D) something function(args)' to a 'extern(System) something function(args)'. For shorter, clearer and correct code you could instead use: blah = cast(typeof(blah))dlsym(...); You don't need to call std.string.toStringz on string literals, they're guaranteed to be null-terminated. All the function signatures using immutable (void function(immutable(char)*), etc) are incorrect. C or C++ function signatures should be using const instead (eg void function(const(char)*) ). I really suggest using an import library if possible.
Re: About const and C functions
Am 01.03.2011, 23:33 Uhr, schrieb bearophile : Do you know why DMD doesn't give a compilation error here? import core.stdc.stdio: sscanf; immutable int value = 5; void main() { sscanf("10".ptr, "%d".ptr, &value); } What's the D signature of sscanf?
Re: Constructor template -- bug?
On Wednesday 02 March 2011 00:14:55 Bekenn wrote: > On 3/1/2011 11:47 PM, Jonathan M Davis wrote: > > I should also point out that there is absolutely no need to use template > > for what you're trying to do. Just declare the constructor like so: > > > > this(string message, string file = __FILE__, size_t line = __LINE__ > > Throwable next = null) { ... } > > You are absolutely right; silly me. I'd assumed that would pick up the > file and line at the point of declaration... I think that it works that way in C/C++, but it doesn't work that way in D. Actually, I had to point it out to Andrei at one point after he pointed out that it wouldn't work when I did it in some code he was reviewing. But I've tested it, and it definitely works. - Jonathan M Davis
Re: Constructor template -- bug?
On 3/1/2011 11:47 PM, Jonathan M Davis wrote: I should also point out that there is absolutely no need to use template for what you're trying to do. Just declare the constructor like so: this(string message, string file = __FILE__, size_t line = __LINE__ Throwable next = null) { ... } You are absolutely right; silly me. I'd assumed that would pick up the file and line at the point of declaration...
Re: Constructor template -- bug?
On Tuesday 01 March 2011 23:52:38 Jacob Carlborg wrote: > On 2011-03-02 08:47, Jonathan M Davis wrote: > > On Tuesday 01 March 2011 23:43:27 Jonathan M Davis wrote: > >> On Tuesday 01 March 2011 22:18:49 Bekenn wrote: > >>> Code: > >>> class MyException : Exception > >>> { > >>> > >>> this(string message, string file, size_t line, Throwable next = null) > >>> { > >>> > >>> super(message, file, line, next); > >>> > >>> } > >>> > >>> this(string file = __FILE__, size_t line = __LINE__)(string message, > >>> > >>> Throwable next = null) > >>> > >>> { > >>> > >>> this(message, file, line, next); > >>> > >>> } > >>> > >>> } > >>> > >>> void main() > >>> { > >>> > >>> throw new MyException("Bluh!"); > >>> > >>> } > >>> > >>> Error message: > >>> test.d(8): Error: template test.MyException.__ctor(string file = > >>> > >>> __FILE__,size_t line = __LINE__) conflicts with constructor > >>> test.MyException.this at test.d(3) > >>> > >>> If I remove the normal constructor and call super instead of this from > >>> > >>> the constructor template, then I get this slightly different error > >>> message: > >>> test.d(1): Error: constructor test.MyException.this conflicts with > >>> > >>> template test.MyException.__ctor(string file = __FILE__,uint line = > >>> __LINE__) at test.d(3) > >>> > >>> Is this a compiler bug, or am I Doing It Wrong? > >> > >> You cannot currently templatize class constructors: > >> > >> http://d.puremagic.com/issues/show_bug.cgi?id=435 > >> > >> And currently if one overload of a function is templatized, _all_ > >> overloads of that function must templatized: > >> > >> http://d.puremagic.com/issues/show_bug.cgi?id=2972 > >> http://d.puremagic.com/issues/show_bug.cgi?id=4749 > > > > I should also point out that there is absolutely no need to use template > > for what you're trying to do. Just declare the constructor like so: > > > > this(string message, string file = __FILE__, size_t line = __LINE__ > > Throwable next = null) { ... } > > > > - Jonathan M Davis > > I guess the reason why he would do that is to catch the file and line > number where the constructor is called. Except that that works with normal default arguments. I assume that he did not realize that. - Jonathan M Davis