Re: Source code annotations alla Java

2014-12-10 Thread Paulo Pinto via Digitalmars-d-learn
On Thursday, 20 January 2011 at 14:04:54 UTC, Steven 
Schveighoffer wrote:
On Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson 
j...@nospam.com wrote:


Not long ago the Java Language people introduced the idea of 
annotations together with an annotation processing tool (apt).


Now perhaps the idea of source code annotations is not 
actually a Java invention per se, however for someone learning 
D is there any equivalent idiom [of Java annotations] in the D 
language?


Haven't used Java since they added annotations, but I think 
they are like C# attributes?




Yes, this is one case where Java copied back from C#.

--
Paulo


Re: Garbage collector collects live objects

2014-12-10 Thread Ruslan Mullakhmetov via Digitalmars-d-learn
On Wednesday, 10 December 2014 at 02:43:19 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Tue, 09 Dec 2014 17:18:44 +
Ruslan Mullakhmetov via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

but i still have no clue how to overcome GC =(
why do you want to fight with GC? most of the time GC is your 
friend.




see the topic: i got corruption when dereferencing object.


Re: Garbage collector collects live objects

2014-12-10 Thread ketmar via Digitalmars-d-learn
On Wed, 10 Dec 2014 08:32:12 +
Ruslan Mullakhmetov via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 On Wednesday, 10 December 2014 at 02:43:19 UTC, ketmar via 
 Digitalmars-d-learn wrote:
  On Tue, 09 Dec 2014 17:18:44 +
  Ruslan Mullakhmetov via Digitalmars-d-learn
  digitalmars-d-learn@puremagic.com wrote:
  but i still have no clue how to overcome GC =(
  why do you want to fight with GC? most of the time GC is your 
  friend.
 
 
 see the topic: i got corruption when dereferencing object.
that is easily fixable: just stop dereferencing it! ;-)


signature.asc
Description: PGP signature


Re: Garbage collector collects live objects

2014-12-10 Thread Ruslan Mullakhmetov via Digitalmars-d-learn
On Tuesday, 9 December 2014 at 21:38:57 UTC, Steven Schveighoffer 
wrote:

On 12/9/14 2:56 PM, Steven Schveighoffer wrote:

On 12/9/14 12:40 PM, Ruslan Mullakhmetov wrote:


array holds 11 64bit pointers but it's block size is only 128 
bytes  11

* 64 = 704 bytes. what's wrong with this arithmetics?


Hah, just realized what's wrong. It's not 64 *bytes* per 
pointer, it's 64 *bits*. So 8 bytes.


11 * 8 == 88.

Starting to sound more and more normal...

-Steve



yes. that was the mistake. also after fixing bug in Blk 
Attributes printing i got more reasonable attrs


for object blk: FINALIZE
for array of objects blk: NO_SCAN APPENDABLE

this is sound good except for NO_SCAN.


I did simple test file in which allocate array of Foo objects 
(http://dpaste.dzfl.pl/89ab00a897f6)


there i see blk attrs only APPENDABLE without NO_SCAN.

as far as i understand GC will not scan this array for references 
and those if the only reference to object is stored in this array 
will not see it, those assume this object as **not** referenced 
and collects it, am i right?


the other question why this happens... try to debug more.


Re: Derelict / SDL error

2014-12-10 Thread Paul via Digitalmars-d-learn

On Tuesday, 9 December 2014 at 22:27:43 UTC, anonymous wrote:

On Tuesday, 9 December 2014 at 16:12:35 UTC, Paul wrote:

import derelict.sdl2.sdl;
import std.stdio;
import std.conv;

void main()
{
   scope(exit) {

SDL_Quit();
   }

   DerelictSDL2.load();
   DerelictSDL2Image.load();

When I run dub that last line gives me:

source/app.d(15): Error: undefined identifier DerelictSDL2Image


You're missing `import derelict.sdl2.image;`.


Adding that reveals that I need to add SDL_image 2.0 (I didn't 
know that that wasn't a part of the standard SDL install) so I've 
compiled that too. I now get the error:


Unsupported image format

whether I use a png or jpg.

IMG_Load() does however work in the same way as SDL_LoadBMP if I 
feed it a .bmp - the image is displayed but there is a seg fault.


Nightmare.







Re: Derelict / SDL error

2014-12-10 Thread ketmar via Digitalmars-d-learn
On Wed, 10 Dec 2014 08:59:36 +
Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 Adding that reveals that I need to add SDL_image 2.0 (I didn't 
 know that that wasn't a part of the standard SDL install) so I've 
 compiled that too. I now get the error:
 
 Unsupported image format
 
 whether I use a png or jpg.
do you have the corresponding libraries installed? SDL_Image uses
libpng and libjpeg for decoding images, so if you don't have those
installed (with corresponding -dev if your system needs that) you will
not be able to load images in those formats.

also please note that libpng has two incompatible versions, so
double-check README for SDL_Image.


signature.asc
Description: PGP signature


mixin template had error by calling shared function

2014-12-10 Thread Vlasov Roman via Digitalmars-d-learn

I have this code

import std.stdio;

mixin template Template(void function() func1, void function() 
func2) {


voidto() {
func1();
func2();
}
};

class SomeClass {
mixin Template!(func, func23);

void func() {
writeln(First function!);
}

void func23() {
writeln(First function!);
}

void toTemplate() {
to();
}
}

void main() {
SomeClass a = new SomeClass();

a.toTemplate();
}

After running the program give me SIGSEGV in func23();

Terminal with gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00428352 in invariant._d_invariant(Object) ()
(gdb) up
#1  0x004257f7 in main.SomeClass.func23() ()


Manjaro Linux 0.9.0 x86_64
dmd 2.066
Kernel 3.14.4


Re: mixin template had error by calling shared function

2014-12-10 Thread Rikki Cattermole via Digitalmars-d-learn

On 10/12/2014 10:10 p.m., Vlasov Roman wrote:

I have this code

import std.stdio;

mixin template Template(void function() func1, void function() func2) {

 void to() {
 func1();
 func2();
 }
};

class SomeClass {
 mixin Template!(func, func23);

 void func() {
 writeln(First function!);
 }

 void func23() {
 writeln(First function!);
 }

 void toTemplate() {
 to();
 }
}

void main() {
 SomeClass a = new SomeClass();

 a.toTemplate();
}

After running the program give me SIGSEGV in func23();

Terminal with gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00428352 in invariant._d_invariant(Object) ()
(gdb) up
#1  0x004257f7 in main.SomeClass.func23() ()


Manjaro Linux 0.9.0 x86_64
dmd 2.066
Kernel 3.14.4


Ugh, that's a compiler bug.
You should not be able to pass in delegates as function pointers to a 
mixin template.


A better way would be to pass in the names of the methods into the mixin 
template and then use string mixin's to call the methods.


Re: mixin template had error by calling shared function

2014-12-10 Thread via Digitalmars-d-learn
On Wednesday, 10 December 2014 at 09:41:43 UTC, Rikki Cattermole 
wrote:

On 10/12/2014 10:10 p.m., Vlasov Roman wrote:

I have this code

import std.stdio;

mixin template Template(void function() func1, void function() 
func2) {


void to() {
func1();
func2();
}
};

class SomeClass {
mixin Template!(func, func23);

void func() {
writeln(First function!);
}

void func23() {
writeln(First function!);
}

void toTemplate() {
to();
}
}

void main() {
SomeClass a = new SomeClass();

a.toTemplate();
}

After running the program give me SIGSEGV in func23();

Terminal with gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00428352 in invariant._d_invariant(Object) ()
(gdb) up
#1  0x004257f7 in main.SomeClass.func23() ()


Manjaro Linux 0.9.0 x86_64
dmd 2.066
Kernel 3.14.4


Ugh, that's a compiler bug.
You should not be able to pass in delegates as function 
pointers to a mixin template.


A better way would be to pass in the names of the methods into 
the mixin template and then use string mixin's to call the 
methods.


Better yet, try this:

mixin template Template(void delegate() func1, void delegate() 
func2)


Re: mixin template had error by calling shared function

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

https://issues.dlang.org/show_bug.cgi?id=13850


Re: mixin template had error by calling shared function

2014-12-10 Thread Vlasov Roman via Digitalmars-d-learn

On Wednesday, 10 December 2014 at 10:34:25 UTC, Marc Schütz wrote:
On Wednesday, 10 December 2014 at 09:41:43 UTC, Rikki 
Cattermole wrote:

On 10/12/2014 10:10 p.m., Vlasov Roman wrote:

I have this code

import std.stdio;

mixin template Template(void function() func1, void 
function() func2) {


   void to() {
   func1();
   func2();
   }
};

class SomeClass {
   mixin Template!(func, func23);

   void func() {
   writeln(First function!);
   }

   void func23() {
   writeln(First function!);
   }

   void toTemplate() {
   to();
   }
}

void main() {
   SomeClass a = new SomeClass();

   a.toTemplate();
}

After running the program give me SIGSEGV in func23();

Terminal with gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00428352 in invariant._d_invariant(Object) ()
(gdb) up
#1  0x004257f7 in main.SomeClass.func23() ()


Manjaro Linux 0.9.0 x86_64
dmd 2.066
Kernel 3.14.4


Ugh, that's a compiler bug.
You should not be able to pass in delegates as function 
pointers to a mixin template.


A better way would be to pass in the names of the methods into 
the mixin template and then use string mixin's to call the 
methods.


Better yet, try this:

mixin template Template(void delegate() func1, void delegate() 
func2)


I tried this, but compiler give me error

main.d(12): Error: no 'this' to create delegate for func
main.d(12): Error: no 'this' to create delegate for func23

I think that error because i don't completly know dlang



Re: mixin template had error by calling shared function

2014-12-10 Thread Rikki Cattermole via Digitalmars-d-learn

On 11/12/2014 12:24 a.m., Vlasov Roman wrote:

On Wednesday, 10 December 2014 at 10:34:25 UTC, Marc Schütz wrote:

On Wednesday, 10 December 2014 at 09:41:43 UTC, Rikki Cattermole wrote:

On 10/12/2014 10:10 p.m., Vlasov Roman wrote:

I have this code

import std.stdio;

mixin template Template(void function() func1, void function() func2) {

   void to() {
   func1();
   func2();
   }
};

class SomeClass {
   mixin Template!(func, func23);

   void func() {
   writeln(First function!);
   }

   void func23() {
   writeln(First function!);
   }

   void toTemplate() {
   to();
   }
}

void main() {
   SomeClass a = new SomeClass();

   a.toTemplate();
}

After running the program give me SIGSEGV in func23();

Terminal with gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00428352 in invariant._d_invariant(Object) ()
(gdb) up
#1  0x004257f7 in main.SomeClass.func23() ()


Manjaro Linux 0.9.0 x86_64
dmd 2.066
Kernel 3.14.4


Ugh, that's a compiler bug.
You should not be able to pass in delegates as function pointers to a
mixin template.

A better way would be to pass in the names of the methods into the
mixin template and then use string mixin's to call the methods.


Better yet, try this:

mixin template Template(void delegate() func1, void delegate() func2)


I tried this, but compiler give me error

main.d(12): Error: no 'this' to create delegate for func
main.d(12): Error: no 'this' to create delegate for func23

I think that error because i don't completly know dlang


This is why I didn't suggest this myself.
Basically you are trying to take a pointer to a function that takes an 
argument (this). But a delegate is not exactly that. A delegate is a 
function pointer + this pointer as well.

Essentially you can't do this for a type.


Template mixin enum stringof

2014-12-10 Thread Lemonfiend via Digitalmars-d-learn

Consider the following:

---
enum Foo { BAR, }

mixin template S(string s_)
{
enum s = s_;
}

void main()
{
	mixin S!(Foo.BAR.stringof); // Error: identifier 'stringof' of 
'Foo.BAR.stringof' is not defined


enum e = Foo.BAR.stringof;
mixin S!(e); // works fine
}
---

Why doesn't the first work? And is there an alternative to the 
second version?


Re: Template mixin enum stringof

2014-12-10 Thread ketmar via Digitalmars-d-learn
On Wed, 10 Dec 2014 11:52:11 +
Lemonfiend via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 Consider the following:
 
 ---
 enum Foo { BAR, }
 
 mixin template S(string s_)
 {
   enum s = s_;
 }
 
 void main()
 {
   mixin S!(Foo.BAR.stringof); // Error: identifier 'stringof' of 
 'Foo.BAR.stringof' is not defined
 
   enum e = Foo.BAR.stringof;
   mixin S!(e); // works fine
 }
 ---
 
 Why doesn't the first work? And is there an alternative to the 
 second version?

  mixin S!((Foo.BAR).stringof);

sorry, don't remember the parsing rule for this.


signature.asc
Description: PGP signature


Re: Derelict / SDL error

2014-12-10 Thread Mike Parker via Digitalmars-d-learn

On 12/10/2014 5:59 PM, Paul wrote:


Adding that reveals that I need to add SDL_image 2.0 (I didn't know that
that wasn't a part of the standard SDL install) so I've compiled that
too. I now get the error:

Unsupported image format

whether I use a png or jpg.


int flags = IMG_INIT_PNG | IMG_INIT_JPG;
if( IMG_Init( flags ) != flags )
{
...
}

https://www.libsdl.org/projects/SDL_image/docs/SDL_image_8.html




IMG_Load() does however work in the same way as SDL_LoadBMP if I feed it
a .bmp - the image is displayed but there is a seg fault.



I recommend you give it a try with a hardware renderer and see what 
happens. That could potentially narrow it down a bit.


Also, though this is unrelated (I just noticed it when looking at your 
code again), I strongly recommend you move the line


scope( exit ) SDL_Quit();

to somewhere after DerelictSDL2.load(). If the SDL shared library fails 
to load for some reason, an exception will be thrown and as the function 
exits the runtime will happily call SDL_Quit -- even though it will very 
likely be a null pointer at that point since the library never loaded. 
Always keep in mind when using Derelict that you're working through 
function pointers since the shared libraries are loaded manually. If the 
library fails to load because it was missing, none of the function 
pointers will be valid. If loading aborts because a function is missing, 
only the ones loaded before it will have been properly set, so that case 
should be treated as if they are all invalid.




Re: Template mixin enum stringof

2014-12-10 Thread Lemonfiend via Digitalmars-d-learn
On Wednesday, 10 December 2014 at 12:08:34 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Wed, 10 Dec 2014 11:52:11 +
Lemonfiend via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:


Consider the following:

---
enum Foo { BAR, }

mixin template S(string s_)
{
enum s = s_;
}

void main()
{
	mixin S!(Foo.BAR.stringof); // Error: identifier 'stringof' 
of 'Foo.BAR.stringof' is not defined


enum e = Foo.BAR.stringof;
mixin S!(e); // works fine
}
---

Why doesn't the first work? And is there an alternative to the 
second version?


  mixin S!((Foo.BAR).stringof);

sorry, don't remember the parsing rule for this.


Wow, I didn't even consider that.. Thanks!


Re: Template mixin enum stringof

2014-12-10 Thread Daniel Kozák via Digitalmars-d-learn
V Wed, 10 Dec 2014 11:52:11 +
Lemonfiend via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
napsáno:

 Consider the following:
 
 ---
 enum Foo { BAR, }
 
 mixin template S(string s_)
 {
   enum s = s_;
 }
 
 void main()
 {
   mixin S!(Foo.BAR.stringof); // Error: identifier 'stringof'
 of 'Foo.BAR.stringof' is not defined
 
   enum e = Foo.BAR.stringof;
   mixin S!(e); // works fine
 }
 ---
 
 Why doesn't the first work? And is there an alternative to the 
 second version?

import std.traits;

enum Foo { BAR, }

mixin template S(string s_)
{
enum s = s_;
}

void main()
{
mixin S!(fullyQualifiedName!(Foo.BAR));

enum e = fullyQualifiedName!(Foo.BAR);
mixin S!(e); // works fine
}



Re: Garbage collector collects live objects

2014-12-10 Thread Ruslan Mullakhmetov via Digitalmars-d-learn
On Wednesday, 10 December 2014 at 08:46:12 UTC, Ruslan 
Mullakhmetov wrote:
yes. that was the mistake. also after fixing bug in Blk 
Attributes printing i got more reasonable attrs


for object blk: FINALIZE
for array of objects blk: NO_SCAN APPENDABLE

this is sound good except for NO_SCAN.

...
the other question why this happens... try to debug more.


I've done more dubugging.

what i've found:

initially array blk has only attrs APPENDABLE, but after some 
time this blk is shrinked and reallocated (moved) and then 
NO_SCAN attr appears.



here the output of my extended logs:


before tag: 1 len: 2 ptr: 103DD9058 root: 103DD8000:8192 attr: 
APPENDABLE
after tag: 1 len: 3 ptr: 103A21DD0 root: 103A21DC0:64 attr: 
NO_SCAN APPENDABLE



this is produced by the following code

http://dpaste.dzfl.pl/0c6dc16270a1

so in a nutshell after appending to array via ~= operator blk 
attrs changed from APPENDABLE to NO_SCAN APPENDABLE which cause 
the problem.


why and how this happens? can anybody explain it to me?



Re: Template mixin enum stringof

2014-12-10 Thread Daniel Kozák via Digitalmars-d-learn
V Wed, 10 Dec 2014 12:35:44 +
Lemonfiend via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
napsáno:

 On Wednesday, 10 December 2014 at 12:08:34 UTC, ketmar via 
 Digitalmars-d-learn wrote:
  On Wed, 10 Dec 2014 11:52:11 +
  Lemonfiend via Digitalmars-d-learn 
  digitalmars-d-learn@puremagic.com
  wrote:
 
  Consider the following:
  
  ---
  enum Foo { BAR, }
  
  mixin template S(string s_)
  {
 enum s = s_;
  }
  
  void main()
  {
 mixin S!(Foo.BAR.stringof); // Error: identifier
  'stringof' of 'Foo.BAR.stringof' is not defined
  
 enum e = Foo.BAR.stringof;
 mixin S!(e); // works fine
  }
  ---
  
  Why doesn't the first work? And is there an alternative to the 
  second version?
 
mixin S!((Foo.BAR).stringof);
 
  sorry, don't remember the parsing rule for this.
 
 Wow, I didn't even consider that.. Thanks!

Note: Using .stringof for code generation is not recommended, as the
internal representation of a type or expression can change between
different compiler versions.

http://dlang.org/property#stringof



Re: Template mixin enum stringof

2014-12-10 Thread ketmar via Digitalmars-d-learn
On Wed, 10 Dec 2014 12:35:44 +
Lemonfiend via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 On Wednesday, 10 December 2014 at 12:08:34 UTC, ketmar via 
 Digitalmars-d-learn wrote:
  On Wed, 10 Dec 2014 11:52:11 +
  Lemonfiend via Digitalmars-d-learn 
  digitalmars-d-learn@puremagic.com
  wrote:
 
  Consider the following:
  
  ---
  enum Foo { BAR, }
  
  mixin template S(string s_)
  {
 enum s = s_;
  }
  
  void main()
  {
 mixin S!(Foo.BAR.stringof); // Error: identifier 'stringof' 
  of 'Foo.BAR.stringof' is not defined
  
 enum e = Foo.BAR.stringof;
 mixin S!(e); // works fine
  }
  ---
  
  Why doesn't the first work? And is there an alternative to the 
  second version?
 
mixin S!((Foo.BAR).stringof);
 
  sorry, don't remember the parsing rule for this.
 
 Wow, I didn't even consider that.. Thanks!
also, you can use this:

  import std.conv : to;
  ...
  mixin S!(to!string(Foo.BAR));

people tend to forget that many `to!` variants are usable in CTFE.


signature.asc
Description: PGP signature


Re: Garbage collector collects live objects

2014-12-10 Thread ketmar via Digitalmars-d-learn
On Wed, 10 Dec 2014 12:52:22 +
Ruslan Mullakhmetov via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 On Wednesday, 10 December 2014 at 08:46:12 UTC, Ruslan 
 Mullakhmetov wrote:
  yes. that was the mistake. also after fixing bug in Blk 
  Attributes printing i got more reasonable attrs
 
  for object blk: FINALIZE
  for array of objects blk: NO_SCAN APPENDABLE
 
  this is sound good except for NO_SCAN.
 
  ...
  the other question why this happens... try to debug more.
 
 I've done more dubugging.
 
 what i've found:
 
 initially array blk has only attrs APPENDABLE, but after some 
 time this blk is shrinked and reallocated (moved) and then 
 NO_SCAN attr appears.
 
 
 here the output of my extended logs:
 
 
 before tag: 1 len: 2 ptr: 103DD9058 root: 103DD8000:8192 attr: 
 APPENDABLE
 after tag: 1 len: 3 ptr: 103A21DD0 root: 103A21DC0:64 attr: 
 NO_SCAN APPENDABLE
 
 
 this is produced by the following code
 
 http://dpaste.dzfl.pl/0c6dc16270a1
 
 so in a nutshell after appending to array via ~= operator blk 
 attrs changed from APPENDABLE to NO_SCAN APPENDABLE which cause 
 the problem.
 
 why and how this happens? can anybody explain it to me?
 
can you give us a minified code that causes this behavior?


signature.asc
Description: PGP signature


Re: Garbage collector collects live objects

2014-12-10 Thread Ruslan Mullakhmetov via Digitalmars-d-learn
On Wednesday, 10 December 2014 at 12:52:24 UTC, Ruslan 
Mullakhmetov wrote:


why and how this happens? can anybody explain it to me?


I tried to extract this and saw NO NO_SCAN attrs after moving blk:


the following piece of output produced by 
http://dpaste.dzfl.pl/6f773e17de92


len: 6 ptr: 109DF0010 root: 109DF:1048576 attr: APPENDABLE
len: 7 ptr: 109DF0010 root: 109DF:1048576 attr: APPENDABLE
len: 8 ptr: 109DF0010 root: 109DF:1048576 attr: APPENDABLE
len: 9 ptr: 109DF0010 root: 109DF:1048576 attr: APPENDABLE
len: 10 ptr: 109DF0010 root: 109DF:1048576 attr: 
APPENDABLE

--- shrinked --
len: 1 ptr: 109EB3508 root: 109DF:1048576 attr: APPENDABLE
len: 2 ptr: 109EB3508 root: 109DF:1048576 attr: APPENDABLE
len: 3 ptr: 109EB3508 root: 109DF:1048576 attr: APPENDABLE
len: 4 ptr: 109EB3508 root: 109DF:1048576 attr: APPENDABLE
len: 5 ptr: 109EB3508 root: 109DF:1048576 attr: APPENDABLE
len: 6 ptr: 109F60640 root: 109F60640:64 attr: APPENDABLE
len: 7 ptr: 109F60640 root: 109F60640:64 attr: APPENDABLE


Re: Garbage collector collects live objects

2014-12-10 Thread Ruslan Mullakhmetov via Digitalmars-d-learn
On Wednesday, 10 December 2014 at 13:00:45 UTC, ketmar via 
Digitalmars-d-learn wrote:

can you give us a minified code that causes this behavior?


see previous post. the problem vanish if i try to extract it.



Re: Garbage collector collects live objects

2014-12-10 Thread ketmar via Digitalmars-d-learn
On Wed, 10 Dec 2014 13:03:21 +
Ruslan Mullakhmetov via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 On Wednesday, 10 December 2014 at 12:52:24 UTC, Ruslan 
 Mullakhmetov wrote:
 
  why and how this happens? can anybody explain it to me?
 
 I tried to extract this and saw NO NO_SCAN attrs after moving blk:
i strongly believe that you have some strange casts buried somewhere in
the depth of the complex code, or something similar.

maybe trackallocs.d from https://bitbucket.org/infognition/dstuff can
help to track (re)allocations. you can modify source to dump the flags.


signature.asc
Description: PGP signature


Re: Template mixin enum stringof

2014-12-10 Thread Lemonfiend via Digitalmars-d-learn
On Wednesday, 10 December 2014 at 12:57:07 UTC, Daniel Kozák via 
Digitalmars-d-learn wrote:

V Wed, 10 Dec 2014 12:35:44 +
Lemonfiend via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

napsáno:

On Wednesday, 10 December 2014 at 12:08:34 UTC, ketmar via 
Digitalmars-d-learn wrote:

 On Wed, 10 Dec 2014 11:52:11 +
 Lemonfiend via Digitalmars-d-learn 
 digitalmars-d-learn@puremagic.com

 wrote:

 Consider the following:
 
 ---

 enum Foo { BAR, }
 
 mixin template S(string s_)

 {
enum s = s_;
 }
 
 void main()

 {
mixin S!(Foo.BAR.stringof); // Error: identifier
 'stringof' of 'Foo.BAR.stringof' is not defined
 
 	enum e = Foo.BAR.stringof;

mixin S!(e); // works fine
 }
 ---
 
 Why doesn't the first work? And is there an alternative to 
 the second version?


   mixin S!((Foo.BAR).stringof);

 sorry, don't remember the parsing rule for this.

Wow, I didn't even consider that.. Thanks!


Note: Using .stringof for code generation is not recommended, 
as the
internal representation of a type or expression can change 
between

different compiler versions.

http://dlang.org/property#stringof


Ah, thanks for the warning!


Re: Template mixin enum stringof

2014-12-10 Thread Lemonfiend via Digitalmars-d-learn
On Wednesday, 10 December 2014 at 12:57:16 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Wed, 10 Dec 2014 12:35:44 +
Lemonfiend via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:

On Wednesday, 10 December 2014 at 12:08:34 UTC, ketmar via 
Digitalmars-d-learn wrote:

 On Wed, 10 Dec 2014 11:52:11 +
 Lemonfiend via Digitalmars-d-learn 
 digitalmars-d-learn@puremagic.com

 wrote:

 Consider the following:
 
 ---

 enum Foo { BAR, }
 
 mixin template S(string s_)

 {
enum s = s_;
 }
 
 void main()

 {
 	mixin S!(Foo.BAR.stringof); // Error: identifier 
 'stringof' of 'Foo.BAR.stringof' is not defined
 
 	enum e = Foo.BAR.stringof;

mixin S!(e); // works fine
 }
 ---
 
 Why doesn't the first work? And is there an alternative to 
 the second version?


   mixin S!((Foo.BAR).stringof);

 sorry, don't remember the parsing rule for this.

Wow, I didn't even consider that.. Thanks!

also, you can use this:

  import std.conv : to;
  ...
  mixin S!(to!string(Foo.BAR));

people tend to forget that many `to!` variants are usable in 
CTFE.


Seems like I'd want to move the converting-to-string 
functionality to within the template mixin then, something like:


---
mixin template S(T, T t) if (is(T == enum))
{
//import std.traits;
	//enum s = fullyQualifiedName!(t); // unfortunately this results 
in t


import std.conv: to;
enum s = to!string(t); // this works
}

mixin S!(Foo, Foo.BAR);
---

But passing an enum as parameter seems to be somewhat annoying. 
If I leave off the first Foo, then it complains about no-matching 
template for int parameter.

!(Foo, Foo.BAR) seems kinda redundant..


Re: Template mixin enum stringof

2014-12-10 Thread ketmar via Digitalmars-d-learn
On Wed, 10 Dec 2014 13:58:20 +
Lemonfiend via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 On Wednesday, 10 December 2014 at 12:57:16 UTC, ketmar via 
 Digitalmars-d-learn wrote:
  On Wed, 10 Dec 2014 12:35:44 +
  Lemonfiend via Digitalmars-d-learn 
  digitalmars-d-learn@puremagic.com
  wrote:
 
  On Wednesday, 10 December 2014 at 12:08:34 UTC, ketmar via 
  Digitalmars-d-learn wrote:
   On Wed, 10 Dec 2014 11:52:11 +
   Lemonfiend via Digitalmars-d-learn 
   digitalmars-d-learn@puremagic.com
   wrote:
  
   Consider the following:
   
   ---
   enum Foo { BAR, }
   
   mixin template S(string s_)
   {
   enum s = s_;
   }
   
   void main()
   {
   mixin S!(Foo.BAR.stringof); // Error: identifier 
   'stringof' of 'Foo.BAR.stringof' is not defined
   
   enum e = Foo.BAR.stringof;
   mixin S!(e); // works fine
   }
   ---
   
   Why doesn't the first work? And is there an alternative to 
   the second version?
  
 mixin S!((Foo.BAR).stringof);
  
   sorry, don't remember the parsing rule for this.
  
  Wow, I didn't even consider that.. Thanks!
  also, you can use this:
 
import std.conv : to;
...
mixin S!(to!string(Foo.BAR));
 
  people tend to forget that many `to!` variants are usable in 
  CTFE.
 
 Seems like I'd want to move the converting-to-string 
 functionality to within the template mixin then, something like:
 
 ---
 mixin template S(T, T t) if (is(T == enum))
 {
   //import std.traits;
   //enum s = fullyQualifiedName!(t); // unfortunately this results 
 in t
 
   import std.conv: to;
   enum s = to!string(t); // this works
 }
 
 mixin S!(Foo, Foo.BAR);
 ---
 
 But passing an enum as parameter seems to be somewhat annoying. 
 If I leave off the first Foo, then it complains about no-matching 
 template for int parameter.
 !(Foo, Foo.BAR) seems kinda redundant..
something like this?

  mixin template S(alias fld) if (is(typeof(fld) == enum))
  {
import std.conv : to;
enum s = to!string(fld); // BAR
// or this:
//import std.traits : fullyQualifiedName;
//enum s = to!string(fullyQualifiedName!(fld)); // test.Foo.BAR
  }

  enum Foo { BAR, }

  void main()
  {
mixin S!(Foo.BAR);
  }


signature.asc
Description: PGP signature


Re: Template mixin enum stringof

2014-12-10 Thread Lemonfiend via Digitalmars-d-learn
On Wednesday, 10 December 2014 at 14:25:30 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Wed, 10 Dec 2014 13:58:20 +
Lemonfiend via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:

On Wednesday, 10 December 2014 at 12:57:16 UTC, ketmar via 
Digitalmars-d-learn wrote:

 On Wed, 10 Dec 2014 12:35:44 +
 Lemonfiend via Digitalmars-d-learn 
 digitalmars-d-learn@puremagic.com

 wrote:

 On Wednesday, 10 December 2014 at 12:08:34 UTC, ketmar via 
 Digitalmars-d-learn wrote:

  On Wed, 10 Dec 2014 11:52:11 +
  Lemonfiend via Digitalmars-d-learn 
  digitalmars-d-learn@puremagic.com

  wrote:
 
  Consider the following:
  
  ---

  enum Foo { BAR, }
  
  mixin template S(string s_)

  {
enum s = s_;
  }
  
  void main()

  {
  	mixin S!(Foo.BAR.stringof); // Error: identifier 
  'stringof' of 'Foo.BAR.stringof' is not defined
  
  	enum e = Foo.BAR.stringof;

mixin S!(e); // works fine
  }
  ---
  
  Why doesn't the first work? And is there an alternative 
  to the second version?

 
mixin S!((Foo.BAR).stringof);
 
  sorry, don't remember the parsing rule for this.
 
 Wow, I didn't even consider that.. Thanks!

 also, you can use this:

   import std.conv : to;
   ...
   mixin S!(to!string(Foo.BAR));

 people tend to forget that many `to!` variants are usable in 
 CTFE.


Seems like I'd want to move the converting-to-string 
functionality to within the template mixin then, something 
like:


---
mixin template S(T, T t) if (is(T == enum))
{
//import std.traits;
	//enum s = fullyQualifiedName!(t); // unfortunately this 
results in t


import std.conv: to;
enum s = to!string(t); // this works
}

mixin S!(Foo, Foo.BAR);
---

But passing an enum as parameter seems to be somewhat 
annoying. If I leave off the first Foo, then it complains 
about no-matching template for int parameter.

!(Foo, Foo.BAR) seems kinda redundant..

something like this?

  mixin template S(alias fld) if (is(typeof(fld) == enum))
  {
import std.conv : to;
enum s = to!string(fld); // BAR
// or this:
//import std.traits : fullyQualifiedName;
//enum s = to!string(fullyQualifiedName!(fld)); // 
test.Foo.BAR

  }

  enum Foo { BAR, }

  void main()
  {
mixin S!(Foo.BAR);
  }


Perfect, thanks.


Re: Template mixin enum stringof

2014-12-10 Thread ketmar via Digitalmars-d-learn
On Wed, 10 Dec 2014 14:32:12 +
Lemonfiend via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

mixin template S(alias fld) if (is(typeof(fld) == enum))
{
  import std.conv : to;
  enum s = to!string(fld); // BAR
  // or this:
  //import std.traits : fullyQualifiedName;
  //enum s = to!string(fullyQualifiedName!(fld)); // 
  test.Foo.BAR
}
 
enum Foo { BAR, }
 
void main()
{
  mixin S!(Foo.BAR);
}
 
 Perfect, thanks.
p.s. be careful with imports, as they will go to the same scope as `s`.
this may or may not be important.


signature.asc
Description: PGP signature


Re: Derelict / SDL error

2014-12-10 Thread Paul via Digitalmars-d-learn

On Wednesday, 10 December 2014 at 12:10:23 UTC, Mike Parker wrote:


Also, though this is unrelated (I just noticed it when looking 
at your code again), I strongly recommend you move the line


scope( exit ) SDL_Quit();

to somewhere after DerelictSDL2.load(). If the SDL shared 
library fails to load for some reason, an exception will be 
thrown and as the function exits the runtime will happily call 
SDL_Quit -- even though it will very likely be a null pointer 
at that point since the library never loaded. Always keep in 
mind when using Derelict that you're working through function 
pointers since the shared libraries are loaded manually. If the 
library fails to load because it was missing, none of the 
function pointers will be valid. If loading aborts because a 
function is missing, only the ones loaded before it will have 
been properly set, so that case should be treated as if they 
are all invalid.


I see, makes sense!


Re: Derelict / SDL error

2014-12-10 Thread Paul via Digitalmars-d-learn
On Wednesday, 10 December 2014 at 09:07:56 UTC, ketmar via 
Digitalmars-d-learn wrote:
do you have the corresponding libraries installed? SDL_Image 
uses
libpng and libjpeg for decoding images, so if you don't have 
those
installed (with corresponding -dev if your system needs that) 
you will

not be able to load images in those formats.

also please note that libpng has two incompatible versions, so
double-check README for SDL_Image.


On Wednesday, 10 December 2014 at 09:07:56 UTC, ketmar via 
Digitalmars-d-learn wrote:
do you have the corresponding libraries installed? SDL_Image 
uses
libpng and libjpeg for decoding images, so if you don't have 
those
installed (with corresponding -dev if your system needs that) 
you will

not be able to load images in those formats.

also please note that libpng has two incompatible versions, so
double-check README for SDL_Image.


The readme for SDL_image doesn't say anything about incompatible 
versions of libpng - I have version 1.2.46 installed along with 
the dev files. It also says zlib is required and those are also 
installed.


On the project page[1] is lists libpng 1.5.7 as being used for 
the pre-built binaries (presumably for Win) although the link it 
provides is dead.


libpng 1.5.2 is the nearest version on that project page[2]. I 
built that then rebuilt SDL_image. dub --force now gives me:


IMG_Load error: Failed loading png_set_longjmp_fn: 
/lib/i386-linux-gnu/libpng12.so.0: undefined symbol: 
_png_set_longjmp_fn


Which looks like it is still referring to the old version of 
libpng.


I downloaded the source for the latest version of libpng but 
there is no simple install procedure - the configuration required 
is beyond my level of knowledge.


This thread has degenerated into a discussion of the set up of my 
OS which is miles off topic and should probably be abandoned. 
Thanks for trying all the same.


[1]https://www.libsdl.org/projects/SDL_image/
[2]http://www.libpng.org/pub/png/libpng.html


Re: Derelict / SDL error

2014-12-10 Thread Mike Parker via Digitalmars-d-learn

On 12/11/2014 12:31 AM, Paul wrote:



This thread has degenerated into a discussion of the set up of my OS
which is miles off topic and should probably be abandoned.


Maybe not. The trouble is that others have been able to compile and run 
the same code without error. Given that you are still unable to, that 
puts your system configuration in the spotlight. Your error with libpng 
points even more in that direction. If that turns out to be the culprit, 
it wouldn't be the first time someone has had run-time errors because of 
something not quite right on their system.


Without a failure that others can reproduce, there's not much for anyone 
to do other than make (hopefully educated) guesses. I'm happy to keep 
doing so until it's either resolved or I run out of ideas.






Re: Derelict / SDL error

2014-12-10 Thread Paul via Digitalmars-d-learn

On Wednesday, 10 December 2014 at 16:58:57 UTC, Mike Parker wrote:

On 12/11/2014 12:31 AM, Paul wrote:



This thread has degenerated into a discussion of the set up of 
my OS

which is miles off topic and should probably be abandoned.


Maybe not. The trouble is that others have been able to compile 
and run the same code without error. Given that you are still 
unable to, that puts your system configuration in the 
spotlight. Your error with libpng points even more in that 
direction. If that turns out to be the culprit, it wouldn't be 
the first time someone has had run-time errors because of 
something not quite right on their system.


Without a failure that others can reproduce, there's not much 
for anyone to do other than make (hopefully educated) guesses. 
I'm happy to keep doing so until it's either resolved or I run 
out of ideas.


I appreciate that Mike, I would really like to get this sorted so 
I can get on with learning D. I read up on the procedure for 
building the latest libpng which I did. It gives same error 
message as using the earlier version.


It seems to me that trying to use SDL_image rather than the 
'built in' *.bmp handling might be compounding the problem 
(unless libpng is called upon to render bmps as well?). I don't 
know what to try next I'm afraid.


Re: Derelict / SDL error

2014-12-10 Thread Paul via Digitalmars-d-learn

On Wednesday, 10 December 2014 at 18:06:08 UTC, Paul wrote:
On Wednesday, 10 December 2014 at 16:58:57 UTC, Mike Parker 
wrote:

On 12/11/2014 12:31 AM, Paul wrote:



This thread has degenerated into a discussion of the set up 
of my OS

which is miles off topic and should probably be abandoned.


Maybe not. The trouble is that others have been able to 
compile and run the same code without error. Given that you 
are still unable to, that puts your system configuration in 
the spotlight. Your error with libpng points even more in that 
direction. If that turns out to be the culprit, it wouldn't be 
the first time someone has had run-time errors because of 
something not quite right on their system.


Without a failure that others can reproduce, there's not much 
for anyone to do other than make (hopefully educated) guesses. 
I'm happy to keep doing so until it's either resolved or I run 
out of ideas.


I appreciate that Mike, I would really like to get this sorted 
so I can get on with learning D. I read up on the procedure for 
building the latest libpng which I did. It gives same error 
message as using the earlier version.


It seems to me that trying to use SDL_image rather than the 
'built in' *.bmp handling might be compounding the problem 
(unless libpng is called upon to render bmps as well?). I don't 
know what to try next I'm afraid.


On another of my machines (64 bit Linux 17 XFCE) I've just 
installed dmd (64 bit) and dub binary, xorg-dev (includes libpng 
1.2.50) and built SDL2. This program now works without any errors:


import derelict.sdl2.sdl;
import std.stdio;
import std.conv;



void main()
{


DerelictSDL2.load();

scope(exit) SDL_Quit();

//init sdl
if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
writeln(SDL_Init Error: , to!string( SDL_GetError() ));
return;
}

//open a window
	SDL_Window *window = SDL_CreateWindow(Window Title!, 100, 100, 
640, 480, SDL_WINDOW_SHOWN);

if (window == null){
writeln(SDL_CreateWindow Error: , to!string(SDL_GetError() ));
return;
}   

//get a renderer (ie buffer), use software renderer for now
	SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 
SDL_RENDERER_SOFTWARE);

if (renderer == null){
		writeln( SDL_CreateRenderer Error:  , to!string( 
SDL_GetError() ));

return;
}

//load a bitmap
SDL_Surface *image = SDL_LoadBMP(./test.bmp);
if (image == null){
writeln( SDL_LoadBMP error:  , to!string(SDL_GetError() ));
return;
}   

//create texture for bitmap
	SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, 
image);

if (texture == null){
		writeln( CreateTextureFromSurface error:  , 
to!string(SDL_GetError() ));

return;
}   

//copy to renderer at correct position  scale
SDL_Rect sourceRect = { 0, 0, 64, 64 };
SDL_Rect destRect = { 100, 100, 64, 64 };
SDL_RenderCopy(renderer, texture, sourceRect, destRect);  


//display and pause
SDL_RenderPresent(renderer);
SDL_Delay(2000);


}

The two machines on which errors occur are a Mint 13 (32 bit) box 
and an ageing laptop with Lubuntu 14.04. I've followed the same 
procedures but the 64 bit obviously has the 64 bit dmd compiler.





Re: Derelict / SDL error

2014-12-10 Thread Paul via Digitalmars-d-learn

On Wednesday, 10 December 2014 at 18:58:15 UTC, Paul wrote:

The two machines on which errors occur are a Mint 13 (32 bit) 
box and an ageing laptop with Lubuntu 14.04. I've followed the 
same procedures but the 64 bit obviously has the 64 bit dmd 
compiler.


Just added SDL_image to this 64 bit system and the program works 
as expected with a *.png format image.


http://picpaste.com/Screenshot_-_101214_-_19_14_15-cUuIeloG.png


Re: Sorted Array Wrapper Range

2014-12-10 Thread Nordlöw

On Monday, 8 December 2014 at 15:43:37 UTC, Tobias Pankrath wrote:
Was my fault. The phobos checkout didn't match my dmd version. 
Here is my current state (has some more unittest, bugs fixed, 
no assignment via SortedRange views on Sorted.): 
https://github.com/Panke/phobos/blob/sorted/std/container/sorted.d


Further it's nicer to use new enum syntax at

https://github.com/Panke/phobos/blob/sorted/std/container/sorted.d#L12

as

enum isRAContainer(T) = isRandomAccessRange!(typeof(T.init[])) ...


Re: @property usage

2014-12-10 Thread Joseph Rushton Wakeling via Digitalmars-d-learn

On 09/12/14 08:31, Nicholas Londey via Digitalmars-d-learn wrote:

Does @property ever make sense for a free floating function?


http://dlang.org/phobos/std_random.html#.rndGen :-)



Re: Sorted Array Wrapper Range

2014-12-10 Thread Nordlöw

On Monday, 8 December 2014 at 20:18:51 UTC, Nordlöw wrote:

Great! You should do a PR when you're satisfied! :)


https://github.com/D-Programming-Language/phobos/pull/2793


Re: Derelict / SDL error

2014-12-10 Thread Mike Parker via Digitalmars-d-learn

On 12/11/2014 4:17 AM, Paul wrote:

On Wednesday, 10 December 2014 at 18:58:15 UTC, Paul wrote:


The two machines on which errors occur are a Mint 13 (32 bit) box and
an ageing laptop with Lubuntu 14.04. I've followed the same procedures
but the 64 bit obviously has the 64 bit dmd compiler.


Just added SDL_image to this 64 bit system and the program works as
expected with a *.png format image.

http://picpaste.com/Screenshot_-_101214_-_19_14_15-cUuIeloG.png


More evidence pointing toward the system configuration on the problem 
machines. I'm quite far from being a Linux guru, but at this point I 
would be looking at removing the binaries I've compiled myself and 
installing the binary packages through apt-get (given that you're using 
Mint). If the test program runs with those shared libraries, then you 
can start looking for what went wrong when you compiled them yourself if 
you feel motivated to dig into it.


std.algorithm and templates

2014-12-10 Thread meat via Digitalmars-d-learn
Hello! Thanks for the notice. I've been enjoying delving into D 
recently, and have made quite some progress, but I've become 
stumped on this one problem!
I consider myself decent at natural debugging, but this problem 
has eluded me.


I don't believe any of this problem is implementation specific to 
the rest of my project, but please note if this is too vague. I'm 
defining something like..


class Woah(){}
class Bro: Woah{}
DList!Woah woahs;

and I'm having trouble with..

foreach( bro; woahs.filter!( a = cast(Bro)a !is null))

I'd figure that this would enumerate a collection of Woahs that 
are in fact Bros. Maybe I'm just spoiled by Linq.

Instead, I'm getting hit by this.

Error: template std.algorithm.filter cannot deduce function from 
argument types !()(DList!(Woah), void), candidates are:

..\src\phobos\std\algorithm.d(1628):
std.algorithm.filter(alias pred) if (is(typeof(unaryFun!pred)))

[ Likewise if I specify by filter!( func)( collection) ]

It seems to me that maybe it's a problem with the predicate I'm 
supplying; even though it's unary.
Any help, or how I can proceed and remove my eyesore placeholder 
will be greatly appreciated.

Thanks!


Re: std.algorithm and templates

2014-12-10 Thread bearophile via Digitalmars-d-learn

meat:


class Woah(){}
class Bro: Woah{}
DList!Woah woahs;

and I'm having trouble with..

foreach( bro; woahs.filter!( a = cast(Bro)a !is null))



import std.algorithm, std.container;

class Woah {}
class Bro : Woah {}

void main() {
DList!Woah woahs;
foreach (bro; woahs[].filter!(a = cast(Bro)a !is null)) {}
}

Bye,
bearophile