Re: GC memory fragmentation

2021-04-14 Thread Heromyth via Digitalmars-d-learn

On Sunday, 11 April 2021 at 09:10:22 UTC, tchaloupka wrote:

Hi,
we're using vibe-d (on Linux) for a long running REST API 
server and have problem with constantly growing memory until 
system kills it with OOM killer.




The Hunt Framework is also suffering from this. We are trying to 
make a simple example to illustrate it.


Re: How to get the UDAs for a function parameter correctly?

2020-05-10 Thread Heromyth via Digitalmars-d-learn

On Monday, 11 May 2020 at 02:34:32 UTC, Adam D. Ruppe wrote:

On Monday, 11 May 2020 at 02:25:39 UTC, Heromyth wrote:
I want to get the UDAs for for a function parameter. Here the 
test code and I got some errors:


I think my blog aside is one of the few if only write-ups on 
how to do this:


http://dpldocs.info/this-week-in-d/Blog.Posted_2019_02_11.html#how-to-get-uda-on-a-function-param


the library will not help much, you need to slice the 
parameters yourself. (It might work combine lib stuff with 
slice though, e.g. getUDA!(Parameters!F[1 .. 2]) maybe, i have 
never tried).


but this does work:

static if(is(typeof(method) P == __parameters))
foreach(idx, _; P) {{
// alias for convenience later
alias param = P[idx .. idx + 1]; // this slice 
is the trick

// can get the identifier now
string ident = __traits(identifier, param);
// and the attributes
foreach(attr; __traits(getAttributes, param))
{}
}}


That's great! It should use
   static if(is(typeof(method) P == __parameters))
to get all the parameters instead of using:
   alias Params = Parameters!(member);


Here is the adjusted code:
=
import std.stdio;
import std.traits;
import std.meta;

struct Length {
int a;
int b;
}

class ClassA {
void test(@Length(1, 9) int len, @Length(2, 4) int size) {
writeln("It's OK");
}

void test(string name, @Length(3, 5) int len) {
writeln("Works now");
}

void test() {
}
}

string test(T)() {
string str;
alias currentMembers = __traits(getOverloads, T, "test");

static foreach(member; currentMembers) {{
static if(is(typeof(member) Params == __parameters)) {
static foreach(i, _; Params)
{{
alias ThisParameter =  Params[i .. i + 1];
static foreach(uda; __traits(getAttributes, 
ThisParameter)) {

str ~= uda.stringof ~  "\n";
}
}}
}
}}

return str;
}

void main() {
enum aa = test!(ClassA);
writeln(aa);
}




How to get the UDAs for a function parameter correctly?

2020-05-10 Thread Heromyth via Digitalmars-d-learn
I want to get the UDAs for for a function parameter. Here the 
test code and I got some errors:


source/app.d(29,33): Error: first argument is not a symbol
source/app.d(39,15): Error: template instance app.test!(ClassA) 
error instantiating


How can I fix this? Would this be a bug? Thanks.

=
import std.stdio;
import std.traits;
import std.meta;


struct Length {
int a;
int b;
}

class ClassA {
void test(@Length(1, 9) int len, @Length(2, 4) int size) {
writeln("It's OK");
}

void test(string name) {
writeln("Can't be compiled");
}
}

string test(T)() {
string str;
alias currentMembers = __traits(getOverloads, T, "test");

static foreach(member; currentMembers) {{
alias Params = Parameters!(member);
static foreach(i; 0 .. Params.length)
{{
alias ThisParameter =  Params[i .. i + 1];
static foreach(uda; __traits(getAttributes, 
ThisParameter)) {

str ~= uda.stringof ~  "\n";
}
}}
}}

return str;
}

void main() {
enum aa = test!(ClassA);
writeln(aa);
}



Re: Why can meson find hunt-net but not hunt-proton in dependency resolution?

2020-04-01 Thread Heromyth via Digitalmars-d-learn

On Wednesday, 1 April 2020 at 02:27:38 UTC, YD wrote:
Thanks for the reply! BTW is hunt-amqp for AMQP 1.0 only? 
Because when I try it on an AMQP 0.9 server, it does not seem 
to connect. Thanks again!


We are using RabbitMQ v3.8.2 for test. The hunt-amqp is based on 
AMQP 1.0, and is not tested with AMQP 0.9.


So, wo suggest you to upgrade the MQ server.


Re: Why can meson find hunt-net but not hunt-proton in dependency resolution?

2020-03-31 Thread Heromyth via Digitalmars-d-learn

On Wednesday, 1 April 2020 at 01:21:22 UTC, YD wrote:

On Tuesday, 31 March 2020 at 19:59:25 UTC, YD wrote:

[...]


So I found that the issue is that dub.json file in hunt-proton 
has an entry referring to the parent package with a relative 
file path in it. When that relative file path is removed, Meson 
can find hunt-proton.


However, even after Meson found it, there are two bad behaviors:

(1) Meson refused to automatically add the dependencies of 
hunt-proton, and I had to manually add them to meson.build.
(2) Meson did not automatically add the appropriate 
d_module_versions setting that is required by hunt (the 
HAVE_EPOLL/HAVE_IOCP/... setting), and I had to manually add 
that too.


Anyway, after manually tweaking the meson.build file like 
above, I got it to work (except that compiling/linking seems 
quite slow).


Sorry for the inconveniences. We are still testing Hunt-AMQP. The 
problems about dub.json will be fixed soon.


Re: Some code that compiles but shouldn't

2019-12-30 Thread Heromyth via Digitalmars-d-learn

On Monday, 30 December 2019 at 18:18:49 UTC, uranuz wrote:
I have created library/ framework to handle JSON-RPC requests 
using D methods. I use some *template magic* to translate 
JSON-RPC parameters and return values from/ and to JSON. And I 
have encountered funny bug that at first was hard to find. My 
programme just segfaulted when call to this method occured:


void getCompiledTemplate(HTTPContext ctx)
{
import std.exception: enforce;
enforce(ctx, `ctx is null`);
enforce(ctx.request, `ctx.request is null`);
enforce(ctx.request.form, `ctx.request is null`);
enforce(ivyEngine !is null, `ivyEngine is null`);
string moduleName = ctx.request.form[`moduleName`];
auto mod = ivyEngine.getByModuleName(moduleName);
return ctx.response.write(mod.toStdJSON().toString());
}


So as you see I have added a lot of enforce to test if all 
variables are not null. But nothing was null and the reason of 
segfault were unclear.
Today I just went home. Opened a bottle of beer. And have 
noticed that function is marked as returning `void`, but in 
fact it doesn't. When I fixed this segfault have gone. But why 
this even compiled?! Interesting...


We also have a piece of code, see here 
https://github.com/huntlabs/hunt-examples/blob/master/website-basic/source/app/controller/IndexController.d#L133.


It's a wrong function declaration.

There is no error message when compiling it. However, the 
showString() can't be called via the browser, because the router 
mapping fails.


What happened for this is that the IndexController is not used 
directly by others. It's used in `mixin MakeController;`, see 
https://github.com/huntlabs/hunt-framework/blob/master/source/hunt/framework/application/Controller.d#L153.


So the conclusion is the mixin needs to do more works to check 
the validation in mixined code.


Re: Deserializing JSON as an abstract type

2019-11-18 Thread Heromyth via Digitalmars-d-learn

On Tuesday, 19 November 2019 at 00:40:16 UTC, Chris wrote:
So I'm trying to make a D wrapper for Telegram's JSON API using 
libtdjson. All results coming from the JSON API take the 
following structure:


{
  "@type": "className",
  "foo": "bar",
  "baz" {
"@type": "otherClass"
  }
}

where every object, including nested ones, has a "@type" field 
which will correspond to a D class. There will be over 770 
possible types. So what I'm trying to figure out is how to 
deserialize the JSON so that it automatically gets parsed into 
the correct type.


I'm looking at asdf right now, but it doesn't seem like it has 
anything like that built in. Any ideas?


Can you have a look at this : 
https://github.com/huntlabs/hunt/blob/master/examples/UnitTest/source/test/JsonSerializerTest.d


The JsonSerializer can serialize and deserialize a complex class.


Re: Translating Java into D

2019-11-15 Thread Heromyth via Digitalmars-d-learn

On Friday, 15 November 2019 at 13:15:29 UTC, Andre Pany wrote:

On Friday, 15 November 2019 at 03:29:16 UTC, Heromyth wrote:

On Thursday, 14 November 2019 at 19:50:22 UTC, NonNull wrote:
Greetings, Java seems to be almost a subset of D in various 
ways.
No, it's not exactly right. Java is more powerful than D as 
for a language. Many things that Java can do can't be done by 
D. For example, reflection, full meta info for a type  in 
runtime, type deduction for a template, template member 
override.


See:
https://stackoverflow.com/questions/4829631/unusual-generic-syntax-arrays-stringaslist
https://www.baeldung.com/java-executor-service-tutorial

Has there been any work done to automatically translate Java 
source into D?


We ported some projects in Java by hand.


With the compile time reflection capabilities of D you can 
build a runtime reflection system. Therefore I would say D has 
reflection.


The other points I do not have enough knowledge what Java 
provides.


Kind regards
Andre


Yes, you can do everything with D in theory. The fact is that 
there are many stuff waiting for you to implement them when you 
are porting a project from Java to D, like the different or 
missing APIs, language features etc.


See what we got from the portings:

Containers: 
https://github.com/huntlabs/hunt/tree/master/source/hunt/collection
Threading: 
https://github.com/huntlabs/hunt/tree/master/source/hunt/concurrency




Re: Translating Java into D

2019-11-14 Thread Heromyth via Digitalmars-d-learn

On Thursday, 14 November 2019 at 19:50:22 UTC, NonNull wrote:
Greetings, Java seems to be almost a subset of D in various 
ways.
No, it's not exactly right. Java is more powerful than D as for a 
language. Many things that Java can do can't be done by D. For 
example, reflection, full meta info for a type  in runtime, type 
deduction for a template, template member override.


See:
https://stackoverflow.com/questions/4829631/unusual-generic-syntax-arrays-stringaslist
https://www.baeldung.com/java-executor-service-tutorial

Has there been any work done to automatically translate Java 
source into D?


We ported some projects in Java by hand.


Re: Mimicking Java's Type Erasure

2019-11-03 Thread Heromyth via Digitalmars-d-learn

On Monday, 4 November 2019 at 00:16:53 UTC, Superstar64 wrote:

Consider the following Java code.
--
import java.util.function.Function;
public class Main{

//basic Rank2 type
static interface Stringer{
 String show(Function type, A that);
}

static class Say implements Stringer {
public  String show(Function type, A that){
return type.apply(that);
}
}

static class Shout implements Stringer {
public  String show(Function type, A that){
return type.apply(that) + "!!!";
}
}

}
--
This uses Java's generics' type erasure to create a basic rank 
2 type.
What are some clean ways to implement something similar in D, 
in a type safe manner if preferable?


String show(A)(Stringer stringer, Function type, A 
that) {

   Shout shout = cast(Shout)stringer;
   if(shout !is null) {
 shout.show(type, that); return;
   }

   Say say = cast(Say)stringer;
   if(say !is null) {
 say.show(type, that); return;
   }

  assert(false, "Unsupported");
}

Stringer stringer = new Shout();
stringer.show(type, that);



Re: How to replace the main thread with custom thread

2019-05-04 Thread Heromyth via Digitalmars-d-learn

On Sunday, 5 May 2019 at 05:49:07 UTC, Heromyth wrote:

We have made some extensions to std.thread.
See: 
https://github.com/huntlabs/hunt/blob/master/source/hunt/concurrency/thread/ThreadEx.d.


All the threads except the main thread now can be created with 
ThreadEx.


My question is how can I create the main thread with ThreadEx. 
Is it possible or necessary?

Should I modify std.thread and rebuild the Phobos?

Thanks.


It's so sad. The std.thread should be core.thread.


How to replace the main thread with custom thread

2019-05-04 Thread Heromyth via Digitalmars-d-learn

We have made some extensions to std.thread.
See: 
https://github.com/huntlabs/hunt/blob/master/source/hunt/concurrency/thread/ThreadEx.d.


All the threads except the main thread now can be created with 
ThreadEx.


My question is how can I create the main thread with ThreadEx. Is 
it possible or necessary?

Should I modify std.thread and rebuild the Phobos?

Thanks.


Re: Why does D language do not support BigDecimal type?

2019-03-11 Thread Heromyth via Digitalmars-d-learn

On Monday, 11 March 2019 at 15:23:34 UTC, BoQsc wrote:
There is Money datatype that can be provided by using a third 
party package: https://code.dlang.org/packages/money


But that's only for money, what about math?
Why such fundamental as BigDecimal is still not included into 
the D language itself?

There is BigInt.

If it is unavoidable to use Floating point, how can I quickly 
and simply understand the rules of using float to make the 
least error, or should I just find a third party package for 
that as well?



There is an article on that, but it is not that straight 
forward:

https://dlang.org/articles/d-floating-point.html

Basically any thing that I find on Google, that include 
explaining floating point are badly written and hard to 
understand for the outsider lacking ability to understand 
advanced concepts.


We have being porting one from Java. See 
https://github.com/huntlabs/hunt/blob/master/source/hunt/math/BigDecimal.d.


It's so sad that many methods are still commented out.


Re: Using Async task with timer

2019-02-05 Thread Heromyth via Digitalmars-d-learn

On Wednesday, 6 February 2019 at 05:03:26 UTC, Sudhi wrote:

Hi All,

I am trying to use an Async task which would run at every 
interval of time.


I could not find any example for this. Can some one enlighten 
me on this. I did not find much documentation on timers also.


Thanks,
Sudhi


Here is an example, 
https://github.com/huntlabs/hunt/blob/master/examples/UnitTest/source/test/ScheduledThreadPoolTest.d


You can have a try.


Re: reimplementing an interface in a derived class

2019-01-09 Thread Heromyth via Digitalmars-d-learn

On Thursday, 3 January 2019 at 23:23:12 UTC, Neia Neutuladh wrote:

On Thu, 03 Jan 2019 22:30:48 +, kdevel wrote:

class A : D {
 int foo() { return 1; }
}

class B : A, D {
[...]

What is the meaning of the ", D"? It does not seem to make a 
difference if it is omitted.


B must provide its own implementation of D. It can't simply use 
A's implementation.


As for class B, it has already included foo(), even if it doesn't 
override this method. So, is it necessary to override it again? 
It not always needed to override foo(). Sometimes, we just want 
to keep it as the one in class A and override it as necessary. 
Honestly hope that the compiler can do this.


Re: How to initialize a globle variable nicely and properly?

2018-12-15 Thread Heromyth via Digitalmars-d-learn
On Saturday, 15 December 2018 at 03:48:15 UTC, Neia Neutuladh 
wrote:

On Sat, 15 Dec 2018 02:54:55 +, Heromyth wrote:

 shared static this() {
 writeln("running A in shared static this(),
sharedField=", sharedField);

 Thread th = new Thread(() {  });
 th.start();


When you start a D thread, thread-local static constructors get 
run. So don't start threads until your shared static 
constructors finish.


If I encountered something like this, I would set up a queue of 
actions to be run at the start of main() and fill them with 
static constructors. Instead of this static constructor 
creating a thread, it would enqueue a delegate that starts the 
thread.


Yes, it's very dangerous to create a new thread in shared static 
this(). For a big project, it sometimes hard to identify this 
problem. Maybe, the compiler should do something for this, should 
it?


How to initialize a globle variable nicely and properly?

2018-12-14 Thread Heromyth via Digitalmars-d-learn
We have a module including many globle variables which are needed 
to be initialized firstly in "shared static this() {}", see here 
https://github.com/huntlabs/hunt/blob/master/source/hunt/time/Init.d.


The problem is that these variables are not always initialized 
firstly when are referenced by some others moudles in "static 
this() {}". Here is a demo to illustrate it.


//
// module A
//
module test.A;

import std.stdio;
import core.thread;
import core.time;

class A {
__gshared int sharedField;

shared static this() {
writeln("running A in shared static this(), 
sharedField=", sharedField);


Thread th = new Thread(() {  });
th.start();

Thread.sleep(100.msecs);
sharedField = 2;
writeln("running A done in shared static this(), 
sharedField=", sharedField);

}

static this() {
writeln("running A in static this(), sharedField=", 
sharedField);

}
}

//
// module B
//
module test.B;

import test.A;
import std.stdio;
import core.thread;

shared static this() {
writeln("running in shared static this() from B");
}

class B {
shared static this() {
writeln("running B in shared static this(), 
sharedField=", A.sharedField);

}

static this() {
// bug is here
writeln("running B in static this(), sharedField=", 
A.sharedField);

}
}

//
// module main
//
import std.stdio;

import test.A;
import core.thread;

void main()
{
writeln("running in main.");
}

//
// output
//
Running ./demo
running A in shared static this(), sharedField=0
running A in static this(), sharedField=0
running B in static this(), sharedField=0  // bug is here
running A done in shared static this(), sharedField=2
running in shared static this() from B
running B in shared static this(), sharedField=2
running A in static this(), sharedField=2
running B in static this(), sharedField=2
running main.



You can see the sharedField is 0 in B's static this() at first. 
If Thread is disabled to run in shared static this(), this 
problem seems to be fixed.


Some related bugs:
1) https://issues.dlang.org/show_bug.cgi?id=6114
2) https://issues.dlang.org/show_bug.cgi?id=4923



Re: How do I use null in a struct?

2018-11-11 Thread Heromyth via Digitalmars-d-learn

On Saturday, 10 November 2018 at 19:42:47 UTC, Václav Kozák wrote:
I'm making a Rest API with vibe.d and I have a struct User. 
Sometimes I need to return only a few of the fields. So for 
example: return User(1, null, "John", null, null, ...);
If I do this, an error occurs: cannot implicitly convert 
expression null of type typeof(null) to ...

Thanks.


Another choice: 
https://github.com/huntlabs/hunt/blob/master/source/hunt/lang/Nullable.d


This Nullable is a class and we are using it.


Help needed to extend the core.thread

2018-10-25 Thread Heromyth via Digitalmars-d-learn
I want make some extensions to Thread in core.thread and wan. So 
I copy the whole of core.thread to another module named 
myext.thread.


Here are two errors occurred:
1)When building this module
In function `_D4myext6thread6Thread9termLocksFNiZv':
/home/dlang/UnitTest/source/myext/thread.d:1723: undefined 
reference to `_D4core4sync5mutex5Mutex6__dtorMFNiNeZv'


2)When running a simple demo with empty main().
Program exited with code -11

It seems it is bad idea to do so.
Maybe it's better to extend core.thread.Thread by inheriting it.
Am I right? Thanks!


Re: Help about Template and class inheritance

2018-10-14 Thread Heromyth via Digitalmars-d-learn

On Sunday, 14 October 2018 at 15:06:49 UTC, Basile B. wrote:


The basic problem you're faced to here is that D class / 
interface member functions that are templatized are never 
virtual. I'm not sure if i understand well the JAVA pattern you 
try to reproduce but since D interfaces can be templatized you 
can do something like this, using variadics:




That's a good try. I want to have a try with template mixin.

About Java's pattern, see also:
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html


The interface ExecutorService has many implements like 
AbstractExecutorService, ForkJoinPool, 
ScheduledThreadPoolExecutor, ThreadPoolExecutor etc.


The sample above is updated:

import std.stdio;

class Future(T)
{
T result;

this(T r) {
this.result = r;
}
}

interface IExecutorService {
// Future!(T) submit(T)(T result);  // can't be implemented
}

abstract class ExecutorService : IExecutorService {
 Future!(T) submit(T)(T result) {
return new Future!(T)(result);
}
}

class ThreadPoolExecutor : ExecutorService {
// alias submit = ExecutorService.submit;

// override Future!(T) submit(T)(T result) { // can't override it
//  return new Future!(T)(result + 10);
// }
}

class ForkJoinPool : ExecutorService {
// alias submit = ExecutorService.submit;

// override Future!(T) submit(T)(T result) { // can't override it
//  return new Future!(T)(result * 10);
// }
}

void testBase(ExecutorService service) {

writeln("testBase: ", typeid(service));

Future!(int) f = service.submit!int(12);
writeln(f.result);
}

void testInterface(IExecutorService service) {

writeln("testInterface: ", typeid(service));
writeln("testInterface: ", typeid(cast(Object)service));

// Future!(int) f = service.submit!int(12);
// writeln(f.result);
}

void main()
{
ThreadPoolExecutor threadPool = new ThreadPoolExecutor();
ForkJoinPool forkJoinPool = new ForkJoinPool();

testBase(threadPool);
writeln();
testBase(forkJoinPool);
writeln("\n");
testInterface(threadPool);
writeln();
testInterface(forkJoinPool);
}




Help about Template and class inheritance

2018-10-14 Thread Heromyth via Digitalmars-d-learn

Here is a sample code

```d
import std.stdio;

class Future(T)
{
T result;

this(T r) {
this.result = r;
}
}

interface IExecutorService {
// Future!(T) submit(T)(T result);  // can't be implemented
}

abstract class ExecutorService : IExecutorService {
 Future!(T) submit(T)(T result) {
return new Future!(T)(result);
}
}

class ThreadPoolExecutor : ExecutorService {
// alias submit = ExecutorService.submit;

// override Future!(T) submit(T)(T result) { // can't override it
//  return new Future!(T)(result + 10);
// }
}

void main()
{
ThreadPoolExecutor service = new ThreadPoolExecutor();
ExecutorService serviceBase = service;
IExecutorService serviceInterface = service;

Future!(int) f = service.submit!int(12);
writeln(f.result);

f = serviceBase.submit!int(12);
writeln(f.result);

// f = serviceInterface.submit!int(12);
// writeln(f.result);
}

```

The **submit** can't be defined in D as done in Java. See also 
(search for exchangeMessageVectorsAsync):


https://www.programcreek.com/java-api-examples/?code=aarmea/noise/noise-master/app/src/main/java/com/alternativeinfrastructures/noise/sync/StreamSync.java

So, is there a better way to do this in D?
Any suggestions are welcome.
Thanks.


Re: Is there an efficient byte buffer queue?

2018-10-14 Thread Heromyth via Digitalmars-d-learn

On Monday, 8 October 2018 at 09:39:55 UTC, John Burton wrote:

My use case is sending data to a socket.



We have ported some containers from JAVA.

ByteBuffer is a basic container interface and widely used in JAVA.

See also:
https://github.com/huntlabs/hunt/blob/master/source/hunt/container/ByteBuffer.d
https://github.com/huntlabs/hunt/tree/master/examples/ContainerDemo/source




Re: Is there websocket client implementation for D

2018-09-10 Thread Heromyth via Digitalmars-d-learn

On Tuesday, 24 March 2015 at 17:55:38 UTC, Ilya Korobitsyn wrote:

Hello!

Is there any websocket client implementation in D?
I know there is WS server as a part of vibe.d, but it does not 
seem to include client.

Maybe there are some library bindings that I've missed?



We just implemented one in D.
See 
https://github.com/huntlabs/hunt-http/tree/master/examples/WebSocketDemo




Re: How to list all the manifest constants in a class or struct

2018-06-17 Thread Heromyth via Digitalmars-d-learn

On Sunday, 17 June 2018 at 20:03:09 UTC, aliak wrote:

On Sunday, 17 June 2018 at 02:44:38 UTC, Heromyth wrote:

[...]


I think this bolts.isManifestAssignable [1] will get you 
partially there. The place where it'll fail though is a static 
immutable (since they are assignable to manifest constants) but 
you can filter those by seeing if you can take the address, 
something like:


foreach (m; __traits(allMembers, T)) {
  if (isManifestAssignable!(T, m) && 
!is(typeof(mixin(""~m))) {

// it's a manifest constant ... (?)
  }
}

There of course might be edge cases I can't think of/don't know 
about though.


Cheers,
- Ali

http://bolts.dpldocs.info/bolts.traits.isManifestAssignable.html


Thant's it. Thanks for your great lib: 
https://github.com/aliak00/bolts


Re: How to list all the manifest constants in a class or struct

2018-06-17 Thread Heromyth via Digitalmars-d-learn

On Sunday, 17 June 2018 at 04:32:29 UTC, Jonathan M Davis wrote:
On Sunday, June 17, 2018 02:44:38 Heromyth via 
Digitalmars-d-learn wrote:

Here is a struct named S:

struct S
{
  enum X = 10;
  enum Y
  {
i = 10
  }
  enum Z = "str";
  struct S {}
  class C {}

  static int sx = 0;
  __gshared int gx = 0;

 shared void g();
}

I want list all then the manifest constants in it.

I searched the std.traits and this forums, but get nothing. 
Maybe, my real question is how to get the storage class for a 
member in a class or struct.


As the storage class isn't part of the type, type introspection 
tends to ignore it. You'll basically have to get the full list 
of members of the type and then filter out stuff that isn't a 
manifest constant, which is not exactly pleasant and can get a 
bit tricky but should be possible. You'll probably have to do 
something like filter out all of the members where you can take 
their address and filter out all of the ones that are types, 
and and at that point, you'd be close, but I'd have to 
experiment to figure out whether that was enough or not or 
whether something crept through.


Andrei has been working on coming up with a better wrapper 
around the current introspection stuff so that you'll actually 
get data types which contain the information about a symbol 
rather than having to figure out which combination of __traits 
and traits from std.traits are required to get what you want. 
So, I expect that stuff like this will get a lot easier once 
that's ready, but in the interim, if you're trying to do 
something less common, it can involve having to do a lot clever 
filtering to get exactly the stuff you want and only the stuff 
you want - and I don't think that getting the list of manifest 
constants in a type is a very typical thing for folks to do, so 
std.traits certainly doesn't have anything like 
isManifestConstant.


- Jonathan M Davis


Thanks for your answers. It's so glad to see some works have been 
taken for this.


The isManifestConstant is really necessary. For example, I want 
to port an Enum type from Java to D. It seems better to use a 
Struct instead of an Enum.


See here:
https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/jetty-http/src/main/java/org/eclipse/jetty/http/HttpStatus.java
https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/jetty-http/src/main/java/org/eclipse/jetty/http/HttpHeaderValue.java

Of course, I can define a enum for members with the basic types 
in D.
Sometimes, I like to define them in a class or struct as manifest 
constants or immutable ones. So, I need isManifestConstant.




How to list all the manifest constants in a class or struct

2018-06-16 Thread Heromyth via Digitalmars-d-learn

Here is a struct named S:

struct S
{
enum X = 10;
enum Y
{
  i = 10
}
enum Z = "str";
struct S {}
class C {}

static int sx = 0;
__gshared int gx = 0;

shared void g();
}

I want list all then the manifest constants in it.

I searched the std.traits and this forums, but get nothing.
Maybe, my real question is how to get the storage class for a 
member in a class or struct.


Thanks.


Re: debugging in vs code on Windows

2017-10-14 Thread Heromyth via Digitalmars-d-learn

On Saturday, 14 October 2017 at 19:01:52 UTC, piotrklos wrote:

On Saturday, 14 October 2017 at 13:12:51 UTC, Jerry wrote:

On Friday, 13 October 2017 at 12:55:09 UTC, piotrklos wrote:

(...)


If you use generate a 32-bit binary using DMD, it generates it 
in a format that the C/C++ extension doesn't understand. You 
need to compile -m32mscoff or -m64, and you need to make sure 
the /DEBUG is passed to the linker, as I don't think dmd 
passes it that. You can do that by passing "-L/DEBUG" to DMD 
(when using -m32mscoff or -m64). There should be a .pdb file 
that gets generated, when you start the debugger it should say 
that symbols were loaded for the exe.


I also can't say for certain if debug information is even 
generated for the unittests, so that might be something worth 
looking into to make sure it does.


I have added this to dub.json:
"dmd-flags":[
"-g", "-m64", "-L/DEBUG"
]
but I don't see a pdb file generated when I build. What am I 
doing wrong?


It's not necessary to set "dmd-flags". You need to run dub with 
"--arch=x86_64 --build=debug". Then, the .pdb file is under the 
folder .dub.


To start a debug session, you would add a config file called 
launch.json, set the "program" and press F5.


By the way, don't foret to add a breakpoint.