Re: Interesting C header translation problem

2014-08-08 Thread Petteri Aimonen via Digitalmars-d-learn

Hi,

Honestly, I don't know. I would go stab the original API 
designers in the face and tell them to clean up their mess.


I'm sorry to reply to a 2-year-old topic, but as the original API 
designer, I simply couldn't resist :)


Please do not stab me in the face.

The nanopb API was never designed to be wrapped, or to be used as 
a dynamic library. The situation in the targeted embedded systems 
is that everything is compiled by the same compiler, under same 
settings, to a single binary.


The packed attribute on enums in GCC makes them use the smallest 
integer type, uint8_t in this case. All this has been replaced 
with simpler typedef and #defines nowadays though.


As for what was being tried to do in this thread, I would think a 
native protobuf implementation for D would be much saner than 
trying to wrap a C implementation.


--
Petteri


Re: getting autocompletion in emacs

2014-08-08 Thread Idan Arye via Digitalmars-d-learn

On Thursday, 7 August 2014 at 17:46:13 UTC, nikki wrote:
I want to learn SDL2 and learn D at the same time, for the SDL2 
part autocompletion would be very nice.


I've found DCD but can't get it working (not finding symbols or 
declarations) at the moment but I was wondering if there are 
any alternatives, it's hard to google for d things and emacs, 
cause of emacs.d :)


Did you start DCD and sent to it the import paths with the `-I` 
flag?


Re: D JSON (WAT?!)

2014-08-08 Thread Pavel via Digitalmars-d-learn

On Thursday, 24 July 2014 at 16:09:25 UTC, Justin Whear wrote:

On Thu, 24 Jul 2014 16:04:01 +, Pavel wrote:


Thanks to all you folks who explained in operator for me. My 
bad.
Let's focus on the real problem, which is JSON wrapper class. 
Is it

needed? Wouldn't it be better to get AA from parseJSON?


The following are valid JSON:

auto json1 = parseJSON(`1`);
auto json2 = parseJSON(`foo`);
auto json3 = parseJSON(`[1, 2, 3]`);

None of these fit naturally into an JSONValue[string] return 
type.


auto json4 = parseJSON(`true`);
This is a valid JSON also.

I know that as per JSON spec there's no boolean type specified, 
only separate true and false values, which are specified as type 
in http://dlang.org/library/std/json/JSON_TYPE.html, so I guess 
the only way to check boolean in JSONValue it is to write:


if (json4.type == JSON_TYPE.True) {
} else {
}

Am I right?


funny behavior of ..

2014-08-08 Thread seany via Digitalmars-d-learn

The .., range operator, when used like this :

string a = abcd;
string b = a[0 .. a.count()-1];

sets b to abc. is this the expected behavior?



Re: D JSON (WAT?!)

2014-08-08 Thread Justin Whear via Digitalmars-d-learn
On Fri, 08 Aug 2014 14:07:33 +, Pavel wrote:

 
 I know that as per JSON spec there's no boolean type specified, only
 separate true and false values, which are specified as type in
 http://dlang.org/library/std/json/JSON_TYPE.html, so I guess the only
 way to check boolean in JSONValue it is to write:
 
 if (json4.type == JSON_TYPE.True) {
 } else {
 }
 
 Am I right?

That's right.  Perhaps we need an `asBool` function or even an
opCast!bool that returns false on FALSE, NULL, and possibly empty strings/
objects/arrays.


Re: funny behavior of ..

2014-08-08 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn

On Friday, 8 August 2014 at 15:17:25 UTC, seany wrote:

The .., range operator, when used like this :

string a = abcd;
string b = a[0 .. a.count()-1];

sets b to abc. is this the expected behavior?


Yes. [..] is exclusive the last element.
So [0..1] is a single element [0]
That allows to avoid to always writing the -1.
BTW: you can even use $ instead of a.count():
string b = a[0..$];
And if you like to slice the whole string, leave even the backets 
out:

string b = a;


d malloc

2014-08-08 Thread seany via Digitalmars-d-learn

consider this :

struct S
{
/* ... */

}

void main()
{
   ulong [] u;

   for(// ...
   {
  S s_instance;
  // fillup .. S.key = value;
  u ~= cast(ulong)*s_instance;
   }

}

however, the structs are being allocated to the same place. 
Because, Every time the iterator ends an iteration, seemingly, 
s_instance is collected as garbage.


A test produces output like this.
object : a of type : tensor is stored at : 140737373264752
object : b of type : tensor is stored at : 140737373264752
object : c of type : tensor is stored at : 140737373264752
object : d of type : tensor is stored at : 140737373264752

So I would like to know if there is a malloc alternative in D, 
which I can use to explicitely allocate memory to hold a struct, 
or any other variable , such that the garbage collector does not 
remove it automatically.






Re: d malloc

2014-08-08 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 08, 2014 at 04:42:12PM +, seany via Digitalmars-d-learn wrote:
 consider this :
 
 struct S
 {
 /* ... */
 
 }
 
 void main()
 {
ulong [] u;
 
for(// ...
{
   S s_instance;
   // fillup .. S.key = value;
   u ~= cast(ulong)*s_instance;
}
 
 }
 
 however, the structs are being allocated to the same place. Because,
 Every time the iterator ends an iteration, seemingly, s_instance is
 collected as garbage.

This has nothing to do with the GC. You're storing an address to a local
variable on the stack, which is bad idea because once it goes out of
scope, it will get overwritten by other data (such as subsequent
instances of itself in the loop body).

You need to explicitly allocate the struct on the heap with 'new' if you
want it to survive past the end of the loop body:

S* s_instance = new S();
u ~= cast(ulong)s_instance;

Note that as long as you have pointers to the struct, the GC will not
collect it. So you actually don't need to worry about freeing the data
once you're done with it; just set all pointers to it to null, and the
GC will collect it for you.


T

-- 
Why are you blatanly misspelling blatant? -- Branden Robinson


Re: d malloc

2014-08-08 Thread seany via Digitalmars-d-learn
On Friday, 8 August 2014 at 16:51:37 UTC, H. S. Teoh via 
Digitalmars-d-learn wrote:
On Fri, Aug 08, 2014 at 04:42:12PM +, seany via 
Digitalmars-d-learn wrote:

consider this :

struct S
{
/* ... */

}

void main()
{
   ulong [] u;

   for(// ...
   {
  S s_instance;
  // fillup .. S.key = value;
  u ~= cast(ulong)*s_instance;
   }

}

however, the structs are being allocated to the same place. 
Because,
Every time the iterator ends an iteration, seemingly, 
s_instance is

collected as garbage.


This has nothing to do with the GC. You're storing an address 
to a local
variable on the stack, which is bad idea because once it goes 
out of

scope, it will get overwritten by other data (such as subsequent
instances of itself in the loop body).

You need to explicitly allocate the struct on the heap with 
'new' if you

want it to survive past the end of the loop body:

S* s_instance = new S();
u ~= cast(ulong)s_instance;

Note that as long as you have pointers to the struct, the GC 
will not
collect it. So you actually don't need to worry about freeing 
the data
once you're done with it; just set all pointers to it to null, 
and the

GC will collect it for you.


T



Okey, thank you.

And as discussed earlier, I was trying to save the pointers in an 
ulong (which is same as size_t or ptr_t, those are aliased) 
array, but both addresses 7ff11330eeb0 and 7ff11330ed00 is saved 
as 140733974163440.


What do I do?



How to use Code::Block with D compiler ?

2014-08-08 Thread Borneq via Digitalmars-d-learn
I want use dmd compiler with COde:Blocks. IDE detect compiler but 
is error can't find compiler executable. I have Windows 8.1, 
CodeBlocks 13.12 (now svn 9790)


Command line compiler and libraries

2014-08-08 Thread Borneq via Digitalmars-d-learn
I download dmd.2.065.0.zip. I try compile hello.d with command 
line. It compiles when I have core/,std/ and rt/ directories in 
my directory. Compiler wants source files. Which option is to 
using libs?


Re: d malloc

2014-08-08 Thread anonymous via Digitalmars-d-learn

On Friday, 8 August 2014 at 17:07:37 UTC, seany wrote:
And as discussed earlier, I was trying to save the pointers in 
an ulong (which is same as size_t or ptr_t, those are aliased)


(when compiling for x86-64 that is)

Generally, casting pointers to size_t is a horrible idea. Why
can't you at least go with void*?

array, but both addresses 7ff11330eeb0 and 7ff11330ed00 is 
saved as 140733974163440.


What do I do?


Please show a proper self-contained test-case. That is, the code
should compile as is, and show the problem (e.g. failing asserts,
strange output).


Re: Struct alignment vs alignment of fields

2014-08-08 Thread ketmar via Digitalmars-d-learn
p.s. seems that aligning works only on ints. i.e. on types which 
has sizeof = default platform align.


Re: Struct alignment vs alignment of fields

2014-08-08 Thread ketmar via Digitalmars-d-learn

yeah, chars (and bytes, and so on) are not aligned. i.e.

align(1) struct B {
  int qtim;
  int bid;
  int ofr;
  int bidsiz;
  int ofrsiz;
  short mode;
  char ex;
  byte mmid;
  char z;
}

has sizeof == 25. not sure if specs mentions this, but they 
should.


Re: d malloc

2014-08-08 Thread ketmar via Digitalmars-d-learn
On Fri, 08 Aug 2014 16:42:12 +
seany via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

a) we need the working code;
b) foreach (a; ...) doest struct copying, and you see the temporary
stack object as 'a'. either use 'ref a', or don't do that at all.

that is what i was able to understand from your code.


signature.asc
Description: PGP signature


Re: d malloc

2014-08-08 Thread seany via Digitalmars-d-learn

On Friday, 8 August 2014 at 17:44:29 UTC, anonymous wrote:

On Friday, 8 August 2014 at 17:07:37 UTC, seany wrote:
And as discussed earlier, I was trying to save the pointers in 
an ulong (which is same as size_t or ptr_t, those are aliased)


(when compiling for x86-64 that is)

Generally, casting pointers to size_t is a horrible idea. Why
can't you at least go with void*?



I am very confused. Void* magically sorted a lot of problems out. 
Why are void pointers better than ulong, if I may ask (yes, I am 
on a x86-64)




Re: d malloc

2014-08-08 Thread ketmar via Digitalmars-d-learn

Why are void pointers better than ulong, if I may ask
there is at least one reason: GC. yes, it is conservative, but 
there's no reason to scan ulong[] for any pointers, so you may 
lost your objects if there is no other references to 'em.


Re: getting autocompletion in emacs

2014-08-08 Thread nikki via Digitalmars-d-learn

It was quite some journey I got it working now ;)
https://github.com/Hackerpilot/DCD/issues/153


Are there desktop appications being developed in D currently?

2014-08-08 Thread Puming via Digitalmars-d-learn

Hi,

I bumped into a blog talking about building a (toy) browser 
engine in Rust:


(http://limpet.net/mbrubeck/2014/08/08/toy-layout-engine-1.html)

In the blog I found that the OP is in the mozilla servo team 
building a parallel browser for mozilla. The servo is hosted on 
github here:


(https://github.com/servo)

Yes, rust is a more infantile language compared to D, but people 
are already using them to create complicate applications like 
browser! This kind of projects would become a huge drive force to 
strengthen best practices in the language/lib design and attract 
newcomers.


When I learned about Clojure, and found that an editor/ide [Light 
Table](http://lighttable.com) was written entirely by 
Clojure(script), was really intrigged. [Atom](http://atom.io) is 
written in nodejs/coffeescript.


So I wonder, is there similar projects in D that I can take part, 
learn and enjoy?


I see the current hotspot of D are compilers、libs、http-server and 
game area, but haven't encountered an application project such as 
an editor, music player, etc.




opDispatch compiles fine, but still fails to resolve?

2014-08-08 Thread Vlad Levenfeld via Digitalmars-d-learn
More opDispatch woes. This feature keeps biting me, yet I keep 
trying to use it.


This time I'm trying to access elements of a vector GLSL-style 
(without swizzling... for now).


Here's the relevant code:

struct Vector (uint length, Element = double)
{
ref @property component (string c)()
{
enum mat = q{xyzw};
enum col = q{rgba};
enum tex = q{uv};

static if (mat.canFind (c))
return components[mat.countUntil (c)];
else static if (col.canFind (c))
return components[col.countUntil (c)];
else static if (tex.canFind (c))
return components[tex.countUntil (c)];
else static assert (0);
}

ref @property opDispatch (string c)()
if (c.length == 1)
{
auto v = component!c;
pragma(msg, typeof(v)); // this outputs the expected 
result
return v; // so everything is fine, right? wrong...
}

Element[length] components;
}

Calling vector.component!`x` or something works fine, but calling 
vector.x fails with Error: no property etc.


Now, I'm used to opDispatch silently failing when it can't 
compile (very annoying btw), but in this case, I tested every 
line with a pragma (msg, __traits(compiles...)) and everything 
checks out. All expressions are verified CTFE-able. The compiler 
apparently makes it all the way through the method without a 
hitch, but then just fails symbol resolution anyway.


Is this just a bug? Does anyone have any advice on what else to 
try? I'm out of ideas (short of falling back on generating 
property methods by string mixin).


Re: Are there desktop appications being developed in D currently?

2014-08-08 Thread ed via Digitalmars-d-learn

On Saturday, 9 August 2014 at 00:34:43 UTC, Puming wrote:

Hi,

I bumped into a blog talking about building a (toy) browser 
engine in Rust:


(http://limpet.net/mbrubeck/2014/08/08/toy-layout-engine-1.html)

In the blog I found that the OP is in the mozilla servo team 
building a parallel browser for mozilla. The servo is hosted on 
github here:


(https://github.com/servo)

Yes, rust is a more infantile language compared to D, but 
people are already using them to create complicate applications 
like browser! This kind of projects would become a huge drive 
force to strengthen best practices in the language/lib design 
and attract newcomers.


When I learned about Clojure, and found that an editor/ide 
[Light Table](http://lighttable.com) was written entirely by 
Clojure(script), was really intrigged. [Atom](http://atom.io) 
is written in nodejs/coffeescript.


So I wonder, is there similar projects in D that I can take 
part, learn and enjoy?


I see the current hotspot of D are compilers、libs、http-server 
and game area, but haven't encountered an application project 
such as an editor, music player, etc.


Manu started a project a while back which you may be interested 
in looking at.


http://forum.dlang.org/thread/mailman.470.1386845003.3242.digitalmar...@puremagic.com

https://github.com/FeedBackDevs/feedback


Cheers,
ed


Re: opDispatch compiles fine, but still fails to resolve?

2014-08-08 Thread Meta via Digitalmars-d-learn

On Saturday, 9 August 2014 at 01:20:33 UTC, Vlad Levenfeld wrote:
More opDispatch woes. This feature keeps biting me, yet I keep 
trying to use it.


This time I'm trying to access elements of a vector GLSL-style 
(without swizzling... for now).


Here's the relevant code:

struct Vector (uint length, Element = double)
{
ref @property component (string c)()
{
enum mat = q{xyzw};
enum col = q{rgba};
enum tex = q{uv};

static if (mat.canFind (c))
return components[mat.countUntil (c)];
else static if (col.canFind (c))
return components[col.countUntil (c)];
else static if (tex.canFind (c))
return components[tex.countUntil (c)];
else static assert (0);
}

ref @property opDispatch (string c)()
if (c.length == 1)
{
auto v = component!c;
pragma(msg, typeof(v)); // this outputs the expected 
result
return v; // so everything is fine, right? wrong...
}

Element[length] components;
}

Calling vector.component!`x` or something works fine, but 
calling vector.x fails with Error: no property etc.


Now, I'm used to opDispatch silently failing when it can't 
compile (very annoying btw), but in this case, I tested every 
line with a pragma (msg, __traits(compiles...)) and everything 
checks out. All expressions are verified CTFE-able. The 
compiler apparently makes it all the way through the method 
without a hitch, but then just fails symbol resolution anyway.


Is this just a bug? Does anyone have any advice on what else to 
try? I'm out of ideas (short of falling back on generating 
property methods by string mixin).


Have you tried it without @property? It's probably that which is 
causing the Error: no property message. As far as I know, 
opDispatch *only* works for variable-like access (i.e., 
vector.x), so making it @property is unnecessary and probably, in 
this case, buggy.


Re: 'with(Foo):' not allowed, why?

2014-08-08 Thread timotheecour via Digitalmars-d-learn

On Wednesday, 6 August 2014 at 17:03:23 UTC, Timothee Cour via
Digitalmars-d-learn wrote:
Is there a reason why 'with(Foo):' is not allowed, and we have 
to

use with(Foo){...} ?
It would be more in line with how other scope definitions work 
(extern(C)

etc)


ping, anyone?


Re: Are there desktop appications being developed in D currently?

2014-08-08 Thread Puming via Digitalmars-d-learn

On Saturday, 9 August 2014 at 01:26:05 UTC, ed wrote:

On Saturday, 9 August 2014 at 00:34:43 UTC, Puming wrote:

Hi,

I bumped into a blog talking about building a (toy) browser 
engine in Rust:


(http://limpet.net/mbrubeck/2014/08/08/toy-layout-engine-1.html)

In the blog I found that the OP is in the mozilla servo team 
building a parallel browser for mozilla. The servo is hosted 
on github here:


(https://github.com/servo)

Yes, rust is a more infantile language compared to D, but 
people are already using them to create complicate 
applications like browser! This kind of projects would become 
a huge drive force to strengthen best practices in the 
language/lib design and attract newcomers.


When I learned about Clojure, and found that an editor/ide 
[Light Table](http://lighttable.com) was written entirely by 
Clojure(script), was really intrigged. [Atom](http://atom.io) 
is written in nodejs/coffeescript.


So I wonder, is there similar projects in D that I can take 
part, learn and enjoy?


I see the current hotspot of D are compilers、libs、http-server 
and game area, but haven't encountered an application project 
such as an editor, music player, etc.


Manu started a project a while back which you may be interested 
in looking at.


http://forum.dlang.org/thread/mailman.470.1386845003.3242.digitalmar...@puremagic.com

https://github.com/FeedBackDevs/feedback


Cheers,
ed


Thanks, I could recall the discussion, but was not able to find 
it. Definitely gonna look at it :-)






Re: Examples of Windows services in D?

2014-08-08 Thread Tyler Jensen via Digitalmars-d-learn
I am very interested to find a good example for D2 of a Windows 
Service implementation. Can you point me to one?



On Saturday, 7 September 2013 at 13:57:07 UTC, HeiHon wrote:

On Thursday, 23 February 2012 at 01:33:10 UTC, DNewbie wrote:

Here is a simple service in D
http://my.opera.com/run3/blog/2012/02/23/windows-services-in-d
It's basically c translated to d.



This example seems to have 404ed.

Is there an example of a simple service written in D2 somewhere?

I have a service written in D1 that works just fine. But I 
couldn't get it to work with D2 - I think I ran into the same 
problems as Steve Teale:


http://forum.dlang.org/thread/ic32he$2ifl$1...@digitalmars.com

All other example code I could find also was D1 only.




Re: opDispatch compiles fine, but still fails to resolve?

2014-08-08 Thread Vlad Levenfeld via Digitalmars-d-learn

Yep, replacing @property with auto did the trick.

The lack of error messages in opDispatch is frustrating. I 
realize that, due to tricks like __traits(compiles, 
Foo.testing_for_some_function), having opDispatch stop 
compilation if it fails is not going to work, but there's gotta 
be some way to expose what's going on with it when it fails. 
Maybe some kind of pragma to cause opDispatch to report its 
failures, I don't know.


Re: opDispatch compiles fine, but still fails to resolve?

2014-08-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Aug 09, 2014 at 05:34:40AM +, Vlad Levenfeld via 
Digitalmars-d-learn wrote:
 Yep, replacing @property with auto did the trick.
 
 The lack of error messages in opDispatch is frustrating. I realize
 that, due to tricks like __traits(compiles,
 Foo.testing_for_some_function), having opDispatch stop compilation if
 it fails is not going to work, but there's gotta be some way to expose
 what's going on with it when it fails. Maybe some kind of pragma to
 cause opDispatch to report its failures, I don't know.

Why would having opDispatch actually generate compile errors cause
problems for __traits(compiles,...)? __traits(compiles...) already works
fine with a whole bunch of other non-compiling stuff (by gagging errors
while it attempts them).

The problem with opDispatch is that it gags too much, even when the
resolution ultimately fails, so you're left with mysterious
disappearances of opDispatch with no hint as to what went wrong. I'm
not familiar with this part of DMD, but surely there's a way to make
this behave better??


T

-- 
The number you have dialed is imaginary. Please rotate your phone 90 degrees 
and try again.