Re: Print debug data

2024-04-24 Thread mw via Digitalmars-d-learn

On Monday, 17 July 2023 at 03:43:04 UTC, Alain De Vos wrote:

Is it possible to print runtime memory usage of:
-The stack
-The heap
-The garbage collector ?


And how to print the memory stats of each class / struct type?




Re: Recommendations on porting Python to D

2024-04-25 Thread mw via Digitalmars-d-learn

On Wednesday, 24 April 2024 at 22:07:41 UTC, Chris Piker wrote:


Python-AST to D source converter may already exist?


https://github.com/joortcom/eiffel_rename/tree/main/yi

A rudimentary converter from (extended) Python to D. Maybe you 
can use it as a starting point.


It uses: PEG parser generator for (standard) Python (to extend 
Python syntax):


https://github.com/we-like-parsers/pegen



Another thing you can try (but both the Python-like syntax and 
parser is home-made I think):


dmt is a converter (offline or auto-invoking compiler after 
conversion) from Python-like indention style to curly braces for 
D programming language.


https://github.com/baryluk/dmt

ref:

https://forum.dlang.org/thread/vtftlolshtrtwhlhg...@forum.dlang.org?page=1


Re: Recommendations on porting Python to D

2024-04-25 Thread mw via Digitalmars-d-learn

BTW, maybe you can also try Mojo:

https://github.com/modularml/mojo




Recommendations for good concurrent hashset (esp. for strings)?

2024-05-01 Thread mw via Digitalmars-d-learn

Hi,

I'm looking for recommendations for good concurrent hashset (esp. 
for strings)?


Any libraries?

Thanks.




Re: Recommendations on porting Python to D

2024-05-03 Thread mw via Digitalmars-d-learn

On Friday, 3 May 2024 at 17:38:10 UTC, Chris Piker wrote:

On Thursday, 25 April 2024 at 16:57:53 UTC, mw wrote:

On Wednesday, 24 April 2024 at 22:07:41 UTC, Chris Piker wrote:


Python-AST to D source converter may already exist?


https://github.com/joortcom/eiffel_rename/tree/main/yi

A rudimentary converter from (extended) Python to D. Maybe you 
can use it as a starting point.


Thanks for the suggestions.  I put the question aside for a 
bit, but yesterday ran across a python transpiler here:


  https://github.com/py2many/py2many

It already has support for C++, Go and others.  Since I have 
mountains of python code created over many years, maybe it 
would be worth contributing to this project out of self 
interest.


Can you take a look at py2many and see what you think about it? 
 Getting D on the support list might be good.


(Haven't checked its own implementation and output code quality.)

But it says has output for Kotlin, Dart, these two languages are 
similar to D syntactically, so will be a good start.




Re: Recommendations on porting Python to D

2024-05-23 Thread mw via Digitalmars-d-learn

On Friday, 3 May 2024 at 17:53:41 UTC, mw wrote:

On Friday, 3 May 2024 at 17:38:10 UTC, Chris Piker wrote:

On Thursday, 25 April 2024 at 16:57:53 UTC, mw wrote:

[...]


Thanks for the suggestions.  I put the question aside for a 
bit, but yesterday ran across a python transpiler here:


  https://github.com/py2many/py2many

It already has support for C++, Go and others.  Since I have 
mountains of python code created over many years, maybe it 
would be worth contributing to this project out of self 
interest.


Can you take a look at py2many and see what you think about 
it?  Getting D on the support list might be good.


(Haven't checked its own implementation and output code 
quality.)


But it says has output for Kotlin, Dart, these two languages 
are similar to D syntactically, so will be a good start.


I took another quick look of the project, it uses the Python 
builtin `ast` module as parser, and visitor design pattern to 
implement the transcompiler, so I think it's of decent quality.


HTH.


Re: Parallel safe associative array?

2024-05-24 Thread mw via Digitalmars-d-learn

https://code.dlang.org/packages/rust_interop_d

wrapped:

DashMap: is an implementation of a concurrent associative 
array/hashmap in Rust.


Re: Problem with clear on shared associative array?

2024-05-26 Thread mw via Digitalmars-d-learn

On Monday, 27 May 2024 at 00:43:47 UTC, Serg Gini wrote:

On Sunday, 26 May 2024 at 20:15:54 UTC, Andy Valencia wrote:
For others wrestling with this issue, I found out how to cast 
to unshared at this article:




You can check also this solution 
https://github.com/DmitryOlshansky/sharded-map



Pls NOTE: it is
a   `sharded` (meaning trunk-ed) NON-concurrent map,
not `shared` concurrent map.

These two words looks similar, but the meaning is very different.




What's the latest GDC stable release version?

2024-06-16 Thread mw via Digitalmars-d-learn

Hi,

What's the latest GDC stable release version?


The GDC link on:

https://dlang.org/download.html

is very out dated.

I think it at least should show the latest version number, and 
link to the announcement.



Thanks.



Re: What's the latest GDC stable release version?

2024-06-17 Thread mw via Digitalmars-d-learn

On Monday, 17 June 2024 at 15:33:46 UTC, Dejan Lekic wrote:

On Sunday, 16 June 2024 at 16:26:08 UTC, mw wrote:

Hi,

What's the latest GDC stable release version?


Stable release version is the same as stable GCC release 
version. Find it here: https://gcc.gnu.org/


(GDC is part of the GCC project for years)


Thanks, but it's not clear which D (dmd) language version they 
are corresponding to,e.g. I found:


https://forum.dlang.org/post/qbjmtdyglcwmzekyx...@forum.dlang.org

GCC version 12.2 has been released.

Updated the D front-end from v2.100.0-rc1 to v2.100.1.


But for GCC 13, 14, the status is less clear: are these version 
stable and released, and when?


https://forum.dlang.org/post/amsduzcnbgvptaxjt...@forum.dlang.org

He was also preparing to push out GDC 13.2. GDC 13 maps to DMD 
2.103. He had backported around ten regression fixes for it so 
far.


GDC 14, the current development version, was still tracking the 
upstream DMD mainline. There were no blockers there and 
everything was going fine merging from DMD master down to GDC.






Re: What's the latest GDC stable release version?

2024-06-17 Thread mw via Digitalmars-d-learn
and GDC 14: 
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=09992f8b881aa2dfbee1e9d6954c3ca90cd3fe41


So GDC 14.1 includes the D language at v2.108.0.


This is wonderful:

Synchronizing with the upstream release of v2.108.0.


BTW, if the following two pages are updated with version 
information, that will be great:


https://dlang.org/download.html

https://gdcproject.org/downloads




Re: ImportC "no include path set"

2024-06-21 Thread mw via Digitalmars-d-learn

On Monday, 6 February 2023 at 14:35:53 UTC, bachmeier wrote:

On Monday, 6 February 2023 at 06:55:02 UTC, Elfstone wrote:


So how am I supposed to set the include path?


https://dlang.org/spec/importc.html#preprocessor

The -Ppreprocessorflag switch passes preprocessorflag to the 
preprocessor.


So if you normally use `-I/foo`, you'd add `-P-I/foo`.


How to do this in the dub.json file? and work across DMD/LDC/GDC?

Thanks.


importC Error: undefined identifier `__atomic_thread_fence`

2024-06-21 Thread mw via Digitalmars-d-learn
Looks like `__atomic_thread_fence` is a GCC built-in function, so 
how to make importC recognize it?


Thanks.



Re: ImportC in a Dub project

2024-06-21 Thread mw via Digitalmars-d-learn
On Friday, 28 October 2022 at 19:08:47 UTC, Steven Schveighoffer 
wrote:

On 10/28/22 2:43 PM, Carsten Schlote wrote:
On Friday, 28 October 2022 at 18:31:25 UTC, Steven 
Schveighoffer wrote:



Are you passing the c file to the compiler? Also, you must be

...
By default dub does not build C files (as evidenced by your 
command line). It may not even let you I don't know, but try:


```json
  "sourceFiles" : ["source/zstdc_binding.c"]
```


What if the dub.json target is a staticLibrary?

Right now I have this error:

```
gdc: fatal error: cannot specify ‘-o’ with ‘-c’, ‘-S’ or ‘-E’ 
with multiple files

```

Since both (a single) .d file and the single line .c (include 
".h") file is on the command line:


e.g.

```
gdc -dip25 -Wno-error=builtin-declaration-mismatch 
-fall-instantiations -c -o 
/.dub/cache/liblfdsd/0.3.4/build/library-unittest-swOTDhNpx8l9YtK1BPSAow/liblfdsd.a -fdebug -g -Werror -Wall -Wno-deprecated /.dub/packages/liblfdsd/0.3.4/liblfdsd/source/liblfdsd.d /.dub/packages/liblfdsd/0.3.4/liblfdsd/source/liblfdsd_ImportC.c -Xlinker -Xlinker -llfdsd -Xlinker -llfdsdc -Xlinker -llfds711


```

Thanks.


Why `foo.x.saa.aa` and `foo.y.saa.aa` is the same? `shared_AA.saa` should still be instance variable, not class variable, right?

2024-06-24 Thread mw via Digitalmars-d-learn

Sorry about the silly code, but I just tried this:

```
$ cat shared_aa.d
import std;

synchronized class shared_AA_class {
 private:
  int[int] aa;
  alias aa this;

 public:
  void print() {
  writeln(&aa, aa);
  }
}

struct shared_AA {
  shared_AA_class saa = new shared_AA_class();  // by this syntax 
`saa` is still instance variable?

  alias saa this;
}

class Foo {
shared shared_AA x;
shared shared_AA y;

this() {
x[1] = 1;  // only modified `x`, not `y`
}
}

void main() {
Foo foo = new Foo();
foo.x.print();
foo.y.print();
writeln(&(foo.x.saa));
writeln(&(foo.y.saa));
}
```

```
$ dmd ./shared_aa
$ ./shared_aa
63B699474020[1:1]
63B699474020[1:1]
76CDDB518010
76CDDB518018
```

```
$ ldc2 shared_aa.d
$ ./shared_aa
558A95DF90C0[1:1]
558A95DF90C0[1:1]
743BE2B00010
743BE2B00018
```

Why `foo.x.saa.aa` and `foo.y.saa.aa` is the same? (and of course 
print out the same contents).


`shared_AA.saa` should still be instance variable, not class 
variable, right?


Thanks.



Re: Why `foo.x.saa.aa` and `foo.y.saa.aa` is the same? `shared_AA.saa` should still be instance variable, not class variable, right?

2024-06-24 Thread mw via Digitalmars-d-learn
On Tuesday, 25 June 2024 at 02:25:14 UTC, Richard (Rikki) Andrew 
Cattermole wrote:

On 25/06/2024 2:16 PM, mw wrote:

struct shared_AA {
   shared_AA_class saa = new shared_AA_class();  // by this 
syntax `saa` is still instance variable?

   alias saa this;
}


When you specify an initializer like this, that instance of 
``shared_AA_class`` gets put into the .init of ``shared_AA``.




This is confusing -- well, let's try something similar in C++ and 
Java:


```
$ cat shared_aa.cpp
#include 

class shared_AA_class {
public:
  int aa;
  shared_AA_class() {
  printf("new shared_AA_class\n");
  }

  void print() {
  printf("%d\n", aa);
  }
};

struct shared_AA {
  shared_AA_class* saa = new shared_AA_class();  // by this 
syntax `saa` is still instance variable

};

class Foo {
public:
 shared_AA x;
 shared_AA y;

 Foo() {
x.saa->aa = 1;  // only modified `x`, not `y`
 }

};

int main() {

Foo foo;

foo.x.saa->print();
foo.y.saa->print();

printf("%d\n", foo.x.saa->aa);
printf("%d\n", foo.y.saa->aa);
}

$ g++ shared_aa.cpp
$ ./a.out
new shared_AA_class
new shared_AA_class
1
0
1
0
```

The `shared_AA_class` ctor is called twice, and `foo.x.saa` and 
`foo.y.saa` are different object.



```
$ cat Foo.java
class shared_AA_class {
 public
  int aa;
  shared_AA_class() {
  System.out.println("new shared_AA_class");
  }

  void print() {
  System.out.println(aa);
  }
}

class shared_AA {
  shared_AA_class saa = new shared_AA_class();  // by this syntax 
`saa` is still instance variable

}

class Foo {
 shared_AA x;
 shared_AA y;

Foo() {
x = new shared_AA();
y = new shared_AA();
x.saa.aa = 1;  // only modified `x`, not `y`
}

public static void main(String[] args) {

Foo foo = new Foo();

foo.x.saa.print();
foo.y.saa.print();

System.out.println(foo.x.saa.aa);
System.out.println(foo.y.saa.aa);
}

}

$ javac Foo.java
$ java Foo
new shared_AA_class
new shared_AA_class
1
0
1
0


```

The `shared_AA_class` ctor is called twice, and `foo.x.saa` and 
`foo.y.saa` are different object.



Why D choose to be different here? i.e. `shared_AA_class saa = 
new shared_AA_class()` only evaluate only once, and even force it 
must be evaluate-able at compile time?





Re: Why `foo.x.saa.aa` and `foo.y.saa.aa` is the same? `shared_AA.saa` should still be instance variable, not class variable, right?

2024-06-25 Thread mw via Digitalmars-d-learn

On Tuesday, 25 June 2024 at 21:13:44 UTC, Nick Treleaven wrote:

On Tuesday, 25 June 2024 at 02:16:25 UTC, mw wrote:
Why `foo.x.saa.aa` and `foo.y.saa.aa` is the same? (and of 
course print out the same contents).


`shared_AA.saa` should still be instance variable, not class 
variable, right?


`saa` is an instance variable, but both `foo.x.saa` and 
`foo.y.saa` are initialized to the same instance of 
`shared_AA_class`. I think in the next edition of D we can 
forbid tail mutable initializers.



I think the main problem here is that most people come to D from 
Java / C++ world (among the most popular languages). This tail 
initializer's syntax looks the same, but the semantics is so 
different and so surprisingly unexpected! (as I demo-ed in my 
previous reply).


At least, we need to have a document for Java / C++ programmers, 
which clearly highlights such important differences.




Re: Why `foo.x.saa.aa` and `foo.y.saa.aa` is the same? `shared_AA.saa` should still be instance variable, not class variable, right?

2024-06-25 Thread mw via Digitalmars-d-learn

On Tuesday, 25 June 2024 at 21:13:44 UTC, Nick Treleaven wrote:

I think in the next edition of D we can forbid tail mutable 
initializers.




It is still (or maybe only) useful for fields of a singleton 
class.





Re: Why `foo.x.saa.aa` and `foo.y.saa.aa` is the same? `shared_AA.saa` should still be instance variable, not class variable, right?

2024-06-25 Thread mw via Digitalmars-d-learn

On Wednesday, 26 June 2024 at 01:17:01 UTC, mw wrote:

On Tuesday, 25 June 2024 at 21:13:44 UTC, Nick Treleaven wrote:

I think in the next edition of D we can forbid tail mutable 
initializers.




It is still (or maybe only) useful for fields of a singleton 
class.


But a compiler warning message will be very useful.



Re: Recommendations on porting Python to D

2024-07-12 Thread mw via Digitalmars-d-learn

On Friday, 3 May 2024 at 17:38:10 UTC, Chris Piker wrote:

On Thursday, 25 April 2024 at 16:57:53 UTC, mw wrote:

On Wednesday, 24 April 2024 at 22:07:41 UTC, Chris Piker wrote:


Python-AST to D source converter may already exist?


https://github.com/joortcom/eiffel_rename/tree/main/yi

A rudimentary converter from (extended) Python to D. Maybe you 
can use it as a starting point.


Thanks for the suggestions.  I put the question aside for a 
bit, but yesterday ran across a python transpiler here:


  https://github.com/py2many/py2many

It already has support for C++, Go and others.  Since I have 
mountains of python code created over many years, maybe it 
would be worth contributing to this project out of self 
interest.


Can you take a look at py2many and see what you think about it? 
 Getting D on the support list might be good.


Hi,

I have made basic py2many.pyd work at language/syntax level in my 
dlang fork:


https://github.com/mw66/py2many/tree/dlang

The following examples works now:

https://github.com/mw66/py2many/tree/dlang/tests/expected

py2many/ 13:56:23$ ls ./tests/expected/*.d
./tests/expected/bubble_sort.d
./tests/expected/cls.d
./tests/expected/fib.d
./tests/expected/import_tests.d
./tests/expected/classes.d
./tests/expected/dict.d
./tests/expected/hello_world.d
./tests/expected/nested_dict.d


I haven't created PR to be merged into the main branch, since 
it's better to pass all the tests.


All the remaining work is to make Python's specific feature (e.g. 
async), library (e.g. complex number, NamedTemporaryFile) work in 
D. There are many things need to be done, if you have time, you 
can pick up from my fork, and work from there. (E.g. you can 
create PR to my branch, and when everything is ready, we submit 
to the main py2many all together).



HTH.



Re: Recommendations on porting Python to D

2024-07-12 Thread mw via Digitalmars-d-learn

On Friday, 12 July 2024 at 18:07:50 UTC, mw wrote:

On Friday, 3 May 2024 at 17:38:10 UTC, Chris Piker wrote:

...


Hi,

I have made basic py2many.pyd work at language/syntax level in 
my dlang fork:


https://github.com/mw66/py2many/tree/dlang

The following examples works now:

https://github.com/mw66/py2many/tree/dlang/tests/expected

py2many/ 13:56:23$ ls ./tests/expected/*.d
./tests/expected/bubble_sort.d
./tests/expected/cls.d
./tests/expected/fib.d
./tests/expected/import_tests.d
./tests/expected/classes.d
./tests/expected/dict.d
./tests/expected/hello_world.d
./tests/expected/nested_dict.d


I haven't created PR to be merged into the main branch, since 
it's better to pass all the tests.


All the remaining work is to make Python's specific feature 
(e.g. async), library (e.g. complex number, NamedTemporaryFile) 
work in D. There are many things need to be done, if you have 
time, you can pick up from my fork, and work from there. (E.g. 
you can create PR to my branch, and when everything is ready, 
we submit to the main py2many all together).



HTH.



Please use this Makefile for local setup and run tests:

https://github.com/mw66/py2many/blob/dlang/Makefile




std.container.rbtree has no search method?! e.g. `contains`, `canFind`

2024-07-13 Thread mw via Digitalmars-d-learn

Hi,

on doc:

https://dlang.org/phobos/std_container_rbtree.html#.RedBlackTree

I cannot find any search method?! e.g. `contains`, `canFind`.

Is this a over look? Or there are such functions else where?





Re: std.container.rbtree has no search method?! e.g. `contains`, `canFind`

2024-07-14 Thread mw via Digitalmars-d-learn
On Sunday, 14 July 2024 at 02:01:44 UTC, Steven Schveighoffer 
wrote:

On Saturday, 13 July 2024 at 17:41:42 UTC, mw wrote:

Hi,

on doc:

https://dlang.org/phobos/std_container_rbtree.html#.RedBlackTree

I cannot find any search method?! e.g. `contains`, `canFind`.

Is this a over look? Or there are such functions else where?


The functions are called `equalRange` (which gives you a range 
of all the elements that compare equal to the parameter), 
`lowerBound` (all elements less than the parameter), and 
`upperBound` (all elements greater than the parameter).


This was not my choice, my original dcollections implementation 
used a `find` function. It was a condition for having the type 
added to phobos.


-Steve


I think for containers, it's better to have uniform naming 
convention, either `contains`, `canFind` or `in`, so writing 
generic code (e.g. via D template) is easier.




Re: Recommendations on porting Python to D

2024-07-15 Thread mw via Digitalmars-d-learn

On Friday, 12 July 2024 at 18:07:50 UTC, mw wrote:

On Friday, 3 May 2024 at 17:38:10 UTC, Chris Piker wrote:

On Thursday, 25 April 2024 at 16:57:53 UTC, mw wrote:
On Wednesday, 24 April 2024 at 22:07:41 UTC, Chris Piker 
wrote:



Python-AST to D source converter may already exist?


https://github.com/joortcom/eiffel_rename/tree/main/yi

A rudimentary converter from (extended) Python to D. Maybe 
you can use it as a starting point.


Thanks for the suggestions.  I put the question aside for a 
bit, but yesterday ran across a python transpiler here:


  https://github.com/py2many/py2many

It already has support for C++, Go and others.  Since I have 
mountains of python code created over many years, maybe it 
would be worth contributing to this project out of self 
interest.


Can you take a look at py2many and see what you think about 
it?  Getting D on the support list might be good.


Hi,

I have made basic py2many.pyd work at language/syntax level in 
my dlang fork:


https://github.com/mw66/py2many/tree/dlang

The following examples works now:

https://github.com/mw66/py2many/tree/dlang/tests/expected

py2many/ 13:56:23$ ls ./tests/expected/*.d
./tests/expected/bubble_sort.d
./tests/expected/cls.d
./tests/expected/fib.d
./tests/expected/import_tests.d
./tests/expected/classes.d
./tests/expected/dict.d
./tests/expected/hello_world.d
./tests/expected/nested_dict.d


I haven't created PR to be merged into the main branch, since 
it's better to pass all the tests.


All the remaining work is to make Python's specific feature 
(e.g. async), library (e.g. complex number, NamedTemporaryFile) 
work in D. There are many things need to be done, if you have 
time, you can pick up from my fork, and work from there. (E.g. 
you can create PR to my branch, and when everything is ready, 
we submit to the main py2many all together).



HTH.


FYI, now merged into the main branch:

https://github.com/py2many/py2many/tree/main/pyd




Re: Recommendations on porting Python to D

2024-08-08 Thread mw via Digitalmars-d-learn

FYI, the code has been merged into the main branch already:

https://github.com/py2many/py2many/tree/main/pyd


On Thursday, 8 August 2024 at 20:20:11 UTC, Chris Piker wrote:

On Friday, 12 July 2024 at 18:07:50 UTC, mw wrote:
I have made basic py2many.pyd work at language/syntax level in 
my dlang fork:


https://github.com/mw66/py2many/tree/dlang

The following examples works now:

https://github.com/mw66/py2many/tree/dlang/tests/expected

py2many/ 13:56:23$ ls ./tests/expected/*.d
./tests/expected/bubble_sort.d
...


Outstanding! Thanks for the work! (Apologies for my slow 
response. I've been back on a C project for a while and didn't 
notice your posts.)


I will definitely make use of this when D is back atop the 
stack, should be about three weeks from now. One of my core 
support services still has about 20% python (the rest is D).  
Will be nice to convert the remaining 20%.





Re: Do you have a better way to remove element from a array?

2024-08-10 Thread mw via Digitalmars-d-learn

On Thursday, 5 February 2015 at 14:09:10 UTC, bearophile wrote:

Tobias Pankrath:

Works as designed: 
http://dlang.org/phobos/std_algorithm.html#.remove


Unfortunately it's one of the worst designed functions of 
Phobos:

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

Bye,
bearophile


Hit this one today,

Has `removeAt` or `removeAtIndex` be added to the std lib?

BTW, for associative array, `remove()` is in-place; but here for 
std.algorithm.mutation.remove (*keyword*: mutation), one need to 
do


```
  array = array.remove(index);  // return a new container

  // v.s.
  aa.remove(key);  // return bool (if it's removed)
```

This in-consistence is really bad.




Re: How pretty-print a struct?

2022-03-31 Thread mw via Digitalmars-d-learn

On Thursday, 31 March 2022 at 06:35:15 UTC, ZZ wrote:

Hi,

Is there an easy way to pretty-print a struct which also 
includes arrays?


pretty_array does a very good job for arrays.




If you want the field variable names in the output, you can use:


https://code.dlang.org/packages/jdiutil

https://code.dlang.org/packages/boilerplate


one liner to split a string into every n chars?

2022-04-12 Thread mw via Digitalmars-d-learn

Hi,

What's the D's idiom to split a string into an array of every n 
chars? (prefer one liner)


Thanks.


Re: Does D programming language have work steal queue?

2022-05-22 Thread mw via Digitalmars-d-learn

On Sunday, 22 May 2022 at 21:07:19 UTC, zoujiaqing wrote:

Does D language have task steal queue?
The requirements are high-performance, lock-free, and 
thread-safe.


I have a C's liblfds D wrapper:

https://github.com/mw66/liblfdsd

right now only bmm and bss queue are wrapped.

It's not in dub yet, but I have been using it for a while, feel 
free to give it a try, or even send PRs :-)


Re: Does D programming language have work steal queue?

2022-05-22 Thread mw via Digitalmars-d-learn

On Sunday, 22 May 2022 at 22:37:43 UTC, Stefan Koch wrote:

On Sunday, 22 May 2022 at 21:07:19 UTC, zoujiaqing wrote:

Does D language have task steal queue?
The requirements are high-performance, lock-free, and 
thread-safe.


I have one called fluffy:
https://github.com/UplinkCoder/fluffy




The git link 404?

I am not 100% sure about the performance I did try to make it 
reasonable but in the absence of anything else it might be 
jumping off point for you.





Re: Does D programming language have work steal queue?

2022-05-23 Thread mw via Digitalmars-d-learn

On Monday, 23 May 2022 at 23:07:00 UTC, zoujiaqing wrote:

On Sunday, 22 May 2022 at 23:34:19 UTC, mw wrote:

On Sunday, 22 May 2022 at 21:07:19 UTC, zoujiaqing wrote:

Does D language have task steal queue?
The requirements are high-performance, lock-free, and 
thread-safe.


I have a C's liblfds D wrapper:

https://github.com/mw66/liblfdsd

right now only bmm and bss queue are wrapped.

It's not in dub yet, but I have been using it for a while, 
feel free to give it a try, or even send PRs :-)



BTW, some very simple performance comparison with other D queues 
are here:


https://github.com/mw66/liblfdsd/tree/master/comparison


Re: Does D programming language have work steal queue?

2022-06-05 Thread mw via Digitalmars-d-learn

I will try it.


It's in dub now:

https://code.dlang.org/packages/liblfdsd


Also added queue_umm: unbounded,manyproducer,many_consumer, 
lock-free queue






want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

2022-06-06 Thread mw via Digitalmars-d-learn

Hi,

Suppose I have this code:

```
class GCAllocated {
  float[] data;

  this() {
// non-gc-allocated field
this.data = cast(float[])(core.stdc.stdlib.malloc(nBytes)[0 
.. nBytes]);

  }
}

void foo() {
  auto obj = new GCAllocated();  // gc-allocated owning object
  ...
}

```

So when `obj` is cleanup by the GC, obj.data won't be freed by 
the GC: because the `data` is non-gc-allocated (and it's 
allocated on the non-gc heap), the GC scanner will just skip that 
field during a collection scan. Is this understanding correct?


I need this behavior for a special purpose, so I want to confirm 
it.


Thanks.



Re: want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

2022-06-06 Thread mw via Digitalmars-d-learn

On Monday, 6 June 2022 at 22:22:05 UTC, max haughton wrote:
float[] doesn't contain pointers, so the GC won't do anything 
to or with it.


does every array have a .ptr attr?

https://dlang.org/spec/arrays.html

Dynamic Array Properties

.ptrReturns a pointer to the first element of the array.



Re: want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

2022-06-07 Thread mw via Digitalmars-d-learn
On Tuesday, 7 June 2022 at 13:56:23 UTC, Steven Schveighoffer 
wrote:
So you are safe, it will see the pointer inside the array 
reference, and see that it doesn't point at GC memory, so 
nothing further will be done.


Thanks for the detailed explanation, and everyone who has replied.



Re: 'each' can take static arrays

2022-06-10 Thread mw via Digitalmars-d-learn

On Friday, 10 June 2022 at 17:27:13 UTC, Adam D Ruppe wrote:

On Friday, 10 June 2022 at 16:59:04 UTC, Ali Çehreli wrote:

Why the inconsistency?


Phobos has dozens of random special cases throughout. I'd 
prefer if these were all removed, but right now there's just 
some functions that special case to allow it and others that 
don't.


Apparently each is one that does.


Special cases are always bad, inconsistency is a mental burden to 
the developers, and can even lead to serious but silent bugs when 
overlooked.


1) we should fix them as soon as we discover any of them
2) or at least doc such inconsistency with emphasize



Re: Bug in dmd?

2022-06-15 Thread mw via Digitalmars-d-learn

Create a simple test case, file bug at:

https://issues.dlang.org/


Re: Consuming D libraries from other languages

2022-06-15 Thread mw via Digitalmars-d-learn
On Wednesday, 15 June 2022 at 17:37:32 UTC, Templated Person 
wrote:
It there any resources on how to build D static (`.lib` / `.a`) 
and dynamic libraries (`.dll` / `.so`), and then use them from 
C?


Do I need to link and initialize phobos somehow? What if I 
don't want to use the D runtime? What happens with module level 
`this()` and `~this()`? Is there a comprehensive guide on how 
to do this stuff?



Check:

https://code.dlang.org/packages/autowrap

And examples such as c#, Python here:

https://github.com/symmetryinvestments/autowrap/tree/master/examples




Python <==> d call both ways example (with PyD and autowrap)?

2022-06-22 Thread mw via Digitalmars-d-learn

Hi,

I know with PyD, D can call Python, and with autowrap, Python can 
call a D .dll, I'm just wondering if someone can show an example 
that Python <==> d can call both ways? esp. show passing D 
objects to Python and then call its member function there, and 
vice versa.


Thanks.


Re: Python <==> d call both ways example (with PyD and autowrap)?

2022-06-22 Thread mw via Digitalmars-d-learn

On Thursday, 23 June 2022 at 02:35:25 UTC, Tejas wrote:




IIRC the best you can do is embed a Python interpreter inside a 
D program


https://pyd.readthedocs.io/en/latest/embed.html


Thanks. I tried something like this:

https://github.com/symmetryinvestments/autowrap/issues/314


Although there were some compilation errors, I was able to built 
a dll and run.


Maybe that error message is not a real error.


Re: How to call a function from a dll created with d ?

2022-07-01 Thread mw via Digitalmars-d-learn

On Friday, 1 July 2022 at 19:11:16 UTC, Vinod KC wrote:

Hi all,
I have created a dll file with this code.
```d
module dimedll;


export void testFunc() {
writeln("This is from dll");
}
```


void main() {   
log("Lets build our own ime");
testFunc(); 
}
```

```
dime.obj : error LNK2019: unresolved external symbol 
__D4dime8testFuncFZv referenced in



I think the problem is the linker looking for dime.testFunc, 
while your lib function  is dimedll.testFunc




Re: How to call a function from a dll created with d ?

2022-07-01 Thread mw via Digitalmars-d-learn

On Friday, 1 July 2022 at 21:15:50 UTC, Vinod K Chandran wrote:

On Friday, 1 July 2022 at 21:02:20 UTC, mw wrote:


I think the problem is the linker looking for dime.testFunc, 
while your lib function  is dimedll.testFunc


Thanks for the reply. What about this `mixin SimpleDllMain;` I 
suspect this.


Try follow instructions here:

https://wiki.dlang.org/Win32_DLLs_in_D


Re: How to call a function from a dll created with d ?

2022-07-02 Thread mw via Digitalmars-d-learn

On Saturday, 2 July 2022 at 20:43:41 UTC, Vinod KC wrote:

On Saturday, 2 July 2022 at 14:32:11 UTC, apz28 wrote:


dmd -of=dimedll.dll dimedll.d dimedll.def
dmd dime.d dimedll.di


Thanks for the reply. Well, I am sorry to say that your 
suggestions resulted in failure.
First of all, when I used this command -- ` dmd -of=dimedll.dll 
dimedll.d dimedll.def` I got this error message-

`Error: unrecognized file extension dll`.


Actually, can you create a github repo, I'm sure people will send 
you a working PR.




Re: How long will DUB update a package from github release?

2022-08-15 Thread mw via Digitalmars-d-learn

On Tuesday, 16 August 2022 at 02:12:32 UTC, Domain wrote:
The project [Lumars](https://code.dlang.org/packages/lumars) 
has released a new version 10 days ago in 
[github](https://github.com/BradleyChatha/lumars). But still 
unavailable in DUB.


It has problems recently, you can log a bug here:


https://github.com/dlang/dub-registry/issues/338


what's this error: allocatestack.c:384: advise_stack_range: Assertion `freesize < size' failed.

2022-08-23 Thread mw via Digitalmars-d-learn

Hi,

I got an error message when my program exits (the main 
functionality is done, I guess the error happened during D 
runtime's cleanup)


: allocatestack.c:384: advise_stack_range: Assertion `freesize < 
size' failed.


I suspect it somehow related to I pass some (object) pointers to 
foreign languages containers (C and Rust). But my main program 
seems behave correctly (I keep those pointers on the D side to 
prevent them from being GC-ed), this error only happens when the 
program exits.


Anyone can give me some hint where I should look at? (and where 
is the allocatestack.c?)


Thanks.



is it possible synchronized(null) ? i.e NO-OP

2022-08-26 Thread mw via Digitalmars-d-learn

Hi,

I haven't tried, but can I do:

```
void foo(lots of params) {
  Object lock = (a particular condition) ? realLock : null;

  synchronized(lock) {
// lots of complex code block here
  }

}
```

i.e depending on a a particular condition, the complex code block 
either need to be sync-protected, or not needed.


Method foo has lots of params, I try to avoid refactor the inner 
code block into a separate method.


So my question: is it possible synchronized(null)? essentially 
means NO-OP.


If it's not currently supported, can we add such feature?

Thank.



how to use dub to run all / chosen dependency lib's unittests

2022-09-19 Thread mw via Digitalmars-d-learn

Hi,

I'm using dub.json to specify the dependencies libs for my 
project.


I'm just wondering how I can use dub to run all the tests of 
those dependencies libs (of the transitive closure of *all* the 
libs) to make sure my project is built on a very solid foundation?


I know this could be very time-consuming, probably will run it 
over-night.


On the other hand, what's the command to run dub test on a single 
dependency lib?



Thanks.



Re: how to use dub to run all / chosen dependency lib's unittests

2022-09-19 Thread mw via Digitalmars-d-learn
On Monday, 19 September 2022 at 23:57:31 UTC, Steven 
Schveighoffer wrote:




I don't see any specific command to do it in dub itself.

I've recently discovered that `dub describe` gives you the 
directories of all your dependencies in a JSON format.


I used this to write an install script for dependent library 
artifacts. See 
[here](https://github.com/schveiguy/raylib-d/blob/master/install/source/app.d).


It would be pretty easy to do the same thing to run dependency 
unit tests. e.g. something like `foreach(dir; 
getDubDependencyDirectories) { cd(dir); execute("dub", "test"); 
}`


You'd have to write getDubDependencyDirectories. But it's just 
parsing JSON.




Thanks. Maybe Python is easier for such glue code.


BTW, does any of the unit test library can do what I want? E.g.

https://code.dlang.org/packages/unit-threaded






Best way to read CSV data file into Mir (2d array) ndslice?

2022-09-20 Thread mw via Digitalmars-d-learn

Hi,

I'm just wondering what is the best way to read CSV data file 
into Mir (2d array) ndslice? Esp. if it can parse date into 
int/float.


I searched a bit, but can't find any example.


Thanks.


Re: Best way to read CSV data file into Mir (2d array) ndslice?

2022-09-21 Thread mw via Digitalmars-d-learn

On Wednesday, 21 September 2022 at 19:14:30 UTC, jmh530 wrote:


I just tried doing it with `std.csv`, but my version was a bit 
awkward since it doesn't seem quite so straightforward to just 
take the result of csvReader and put it in a array. I had to 
read it in there. I also wanted to allocate the array up front, 
but to do that I needed to know how big it was and ended up 
doing two passes on reading the data, which isn't ideal.




Thanks, as you said this isn't ideal.

For Mir to catch up with numpy, being able to easily read CSV to 
import data is a must to attract data scientists.


In numpy/pandas, it's just *one* liner.

I logged an issue here as a feature request:

https://github.com/libmir/mir-algorithm/issues/442



Re: Interfacing with Rust

2022-09-29 Thread mw via Digitalmars-d-learn
On Thursday, 29 September 2022 at 16:02:43 UTC, Ruby The Roobster 
wrote:
Is there any way one can interface with Rust, such as with a 
struct, or a function?


I know that rust has an extern keyword, but I can't get it to 
work.


https://code.dlang.org/packages/rust_interop_d


Read the notes on memory management:

Only pass pointers as u64 as value type.




Re: How to do alligned allocation?

2022-09-30 Thread mw via Digitalmars-d-learn
On Friday, 30 September 2022 at 15:57:22 UTC, Quirin Schroll 
wrote:
When I do `new void[](n)`, is that buffer allocated with an 
alignment of 1 or what are the guarantees? How can I set an 
alignment? Also, is the alignment of any type guaranteed to be 
a power of 2?


https://dlang.org/library/core/stdc/stdlib/aligned_alloc.html

It's the C func, so check C lib doc.


Re: How to do alligned allocation?

2022-09-30 Thread mw via Digitalmars-d-learn

On Friday, 30 September 2022 at 16:23:00 UTC, mw wrote:
On Friday, 30 September 2022 at 15:57:22 UTC, Quirin Schroll 
wrote:
When I do `new void[](n)`, is that buffer allocated with an 
alignment of 1 or what are the guarantees? How can I set an 
alignment? Also, is the alignment of any type guaranteed to be 
a power of 2?


https://dlang.org/library/core/stdc/stdlib/aligned_alloc.html

It's the C func, so check C lib doc.


and then use emplace on the C-alloc-ed memory.


Re: Interfacing with Rust

2022-09-30 Thread mw via Digitalmars-d-learn

extern(C++)?

Why do you think Rust export C++ linkage?

And why do you think Rust export some kind of OO object model 
linkage?



Do it in plain C style, you may make it work.

As said, check how it's done in:

https://code.dlang.org/packages/rust_interop_d


csvReader: how to read only selected columns while the class Layout has extra field?

2022-10-02 Thread mw via Digitalmars-d-learn

Hi,

I'm following the example on

https://dlang.org/phobos/std_csv.html

```
class Layout
{
int value;
double other;
string name;
int extra_field;  // un-comment to see the error
}

void main()
{
import std.csv;
import std.stdio: write, writeln, writef, writefln;
import std.algorithm.comparison : equal;
string text = "a,b,c\nHello,65,2.5\nWorld,123,7.5";

auto records =
text.csvReader!Layout(["b","c","a"]);  // Read only these 
column

foreach (r; records) writeln(r.name);
}
```

This works fine so far, but if I un-comment the extra_field line, 
I got runtime error:


```
core.exception.ArrayIndexError@/dlang/dmd/linux/bin64/../../src/phobos/std/csv.d(1209):
 index [3] is out of bounds for array of length 3

??:? _d_arraybounds_indexp [0x5565b4b974d1]
/dlang/dmd/linux/bin64/../../src/phobos/std/csv.d:1209 pure @safe 
void std.csv.CsvReader!(onlineapp.Layout, 1, immutable(char)[], 
dchar, immutable(char)[][]).CsvReader.prime() [0x5565b4b73ed2]
/dlang/dmd/linux/bin64/../../src/phobos/std/csv.d:1154 pure @safe 
void std.csv.CsvReader!(onlineapp.Layout, 1, immutable(char)[], 
dchar, immutable(char)[][]).CsvReader.popFront() [0x5565b4b73c80]
/dlang/dmd/linux/bin64/../../src/phobos/std/csv.d:1069 pure ref 
@safe std.csv.CsvReader!(onlineapp.Layout, 1, immutable(char)[], 
dchar, immutable(char)[][]).CsvReader 
std.csv.CsvReader!(onlineapp.Layout, 1, immutable(char)[], dchar, 
immutable(char)[][]).CsvReader.__ctor(immutable(char)[], 
immutable(char)[][], dchar, dchar, bool) [0x5565b4b73ae8]
/dlang/dmd/linux/bin64/../../src/phobos/std/csv.d:366 pure @safe 
std.csv.CsvReader!(onlineapp.Layout, 1, immutable(char)[], dchar, 
immutable(char)[][]).CsvReader 
std.csv.csvReader!(onlineapp.Layout, 1, immutable(char)[], 
immutable(char)[][], char).csvReader(immutable(char)[], 
immutable(char)[][], char, char, bool) [0x5565b4b735f3]

./onlineapp.d:18 _Dmain [0x5565b4b72ca4]
```

I'm just wondering how to work-around this?

Thanks.


Re: csvReader: how to read only selected columns while the class Layout has extra field?

2022-10-02 Thread mw via Digitalmars-d-learn

```
text.csvReader!Layout(["b","c","a"]);  // Read only these 
column

```

The intention is very clear: only read the selected columns from 
the csv, and for any other fields of class Layout, just ignore 
(with the default D .init value).




Re: csvReader: how to read only selected columns while the class Layout has extra field?

2022-10-02 Thread mw via Digitalmars-d-learn

On Sunday, 2 October 2022 at 21:03:40 UTC, rassoc wrote:

But say, I'm curious, what's the purpose of adding an 
optional/useless contents field? What's the use-case here?



We have a class/struct for a data record,
some of its data fields need to be saved/loaded from CSV files; 
while there are other helper fields which are useful for various 
computation tasks (e.g. caching some intermediate computation 
results), these fields do not need to be saved/loaded from the 
csv files.



A CSV library should consider all the use cases, and allow users 
to ignore certain fields.


Re: csvReader: how to read only selected columns while the class Layout has extra field?

2022-10-03 Thread mw via Digitalmars-d-learn

On Monday, 3 October 2022 at 18:02:51 UTC, Salih Dincer wrote:

On Sunday, 2 October 2022 at 19:48:52 UTC, mw wrote:

```
text.csvReader!Layout(["b","c","a"]);  // Read only 
these column

```

The intention is very clear: only read the selected columns 
from the csv, and for any other fields of class Layout, just 
ignore (with the default D .init value).


Why don't you do this?  For example you can try the following?

```d
import std.csv, std.math.algebraic : abs;

 
string str = "a,b,c\nHello,65,63.63\n➊➋➂❹,123,3673.562";

 struct Layout
 {
 int value;
 double other;
 string name;
 }



You didn't get my question, please add:

```
int extra_field;  // un-comment to see the error
```

to the struct, then you will see the error.




cannot gdb LDC build binary: Segmentation fault

2022-10-06 Thread mw via Digitalmars-d-learn

Hi,

I have a LDC (1.30.0) built binary on Ubuntu 18.04.5 LTS x86_64, 
the program core dumps somewhere, so I want to debug it. However 
under gdb, the program fails as soon as I start it:


```
(gdb) r
[Thread debugging using libthread_db enabled]
Using host libthread_db library 
"/lib/x86_64-linux-gnu/libthread_db.so.1".

[New Thread 0x155544f17700 (LWP 55978)]
[Thread 0x155544f17700 (LWP 55978) exited]
[New Thread 0x1554b700 (LWP 55979)]
[New Thread 0x15542700 (LWP 55980)]
[New Thread 0x15539700 (LWP 55981)]
[New Thread 0x15530700 (LWP 55982)]
[New Thread 0x153b2700 (LWP 55983)]
[New Thread 0x153a9700 (LWP 55984)]
[New Thread 0x153a0700 (LWP 55985)]
[New Thread 0x15397700 (LWP 55986)]
[New Thread 0x1538e700 (LWP 55987)]
[New Thread 0x15385700 (LWP 55988)]

Thread 11 "lt" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x1538e700 (LWP 55987)]
__GI___get_nprocs () at 
../sysdeps/unix/sysv/linux/getsysstats.c:146
146 ../sysdeps/unix/sysv/linux/getsysstats.c: No such file or 
directory.

(gdb) q
A debugging session is active.

Inferior 1 [process 55973] will be killed.

Quit anyway? (y or n) y
```

Without gdb, the program at least can run for a while, and make 
some progress before it core dumps.


Has anyone experienced such problem before?

any suggestions where I should look at?

Thanks.



best memory profiler (to debug accumulated allocation of each line) for D?

2022-10-14 Thread mw via Digitalmars-d-learn

Hi,

With CPU profiler, we can see the accumulated run time of each 
function & line, I'm wondering if there is such a profiler for 
memory allocation?


The reason I'm asking is because I suspect there are some small 
but repetitive memory allocation going on in the libraries (in C 
and D) I'm using which I do not have control (and no source 
available), but I want to find out where.


I want to run on some test data, and get the memory allocation 
stats for each function (better for each line of code), so I can 
find out where the problem is.


Any suggestions?

Thanks.




Re: best memory profiler (to debug accumulated allocation of each line) for D?

2022-10-14 Thread mw via Digitalmars-d-learn

On Friday, 14 October 2022 at 19:06:12 UTC, rassoc wrote:

On 10/14/22 20:45, mw via Digitalmars-d-learn wrote:

Any suggestions?


There's `dmd -profile=gc` or `dub build --build=profile-gc`.


Thanks. I eventually use valgrind --tool=massif, and found the 
problem was in a underlying C library doing lots of small 
allocations.


Re: library to solve the system of linear equations

2022-10-17 Thread mw via Digitalmars-d-learn

On Monday, 17 October 2022 at 19:54:12 UTC, Yura wrote:

it is possible to install the most recent ldc and gdc compilers 
on Ubuntu 18.04?


Yes, I used LDC on the same system.


Re: library to solve the system of linear equations

2022-10-17 Thread mw via Digitalmars-d-learn

On Monday, 17 October 2022 at 20:22:47 UTC, jmh530 wrote:


If you have a problem with support for mir, submit a bug 
report. I don't think gdc is supported, but ldc should be.


The latest version of Mir can only be compiled with latest Ldc 
1.30, 1.29 doesn't work.


Maybe Mir should add static check for supported complier 
versions, rather than let user try and error.


Re: library to solve the system of linear equations

2022-10-17 Thread mw via Digitalmars-d-learn
On Monday, 17 October 2022 at 20:39:10 UTC, rikki cattermole 
wrote:

On 18/10/2022 9:37 AM, mw wrote:
Maybe Mir should add static check for supported complier 
versions, rather than let user try and error.


Dub has dependency checks for compiler/dub in it.

It doesn't need to be in code.


Not everyone use dub to build.


Re: library to solve the system of linear equations

2022-10-18 Thread mw via Digitalmars-d-learn
On Tuesday, 18 October 2022 at 09:56:09 UTC, Siarhei Siamashka 
wrote:

On Monday, 17 October 2022 at 20:05:24 UTC, mw wrote:

On Monday, 17 October 2022 at 19:54:12 UTC, Yura wrote:

it is possible to install the most recent ldc and gdc 
compilers on Ubuntu 18.04?


Yes, I used LDC on the same system.


What's the recommended way to have up to date D compilers in 
Ubuntu?


I just download the official prebuilt binary from the ldc github 
repo.





Re: Can someone tell me what the compiler thought I was trying to do?

2022-10-18 Thread mw via Digitalmars-d-learn

On Wednesday, 19 October 2022 at 01:30:23 UTC, H. S. Teoh wrote:

On Wed, Oct 19, 2022 at 01:15:37AM +, Adam D Ruppe via


it only applies to types, not to functions.


Wat... so what's the use of it then?  So it's not possible to 
mark the return value of an int function @mustUse without 
making, in theory, *all* ints @mustUse?


I must confess I'm baffled as to the purpose of this strange 
design.




Same, can't believe it.

Is there any (design) doc about this?



Re: Can someone tell me what the compiler thought I was trying to do?

2022-10-18 Thread mw via Digitalmars-d-learn

On Wednesday, 19 October 2022 at 01:38:27 UTC, Adam D Ruppe wrote:

On Wednesday, 19 October 2022 at 01:34:54 UTC, mw wrote:

Is there any (design) doc about this?


scroll up, click the link from this very thread.

https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1038.md#design-goals-and-possible-alternatives


"""
Rather than make either sacrifice, this DIP proposes a design 
that allows both rigor and simplicity to be maintained, and 
reserves the possibility for a future DIP to allow @mustUse as a 
function attribute.

"""

Another future DIP? I think this DIP is flawed for not using 
"@mustUse as a function attribute"




Re: Can someone tell me what the compiler thought I was trying to do?

2022-10-18 Thread mw via Digitalmars-d-learn
@mustuse as a function attribute was in the original version of 
the DIP. It was vetoed by Walter. Thus, only the type attribute 
remains in the accepted version.


Let's continue the discussion here:

https://forum.dlang.org/thread/nmornkxaxddfziqmq...@forum.dlang.org

in general, it's about: command query separation principle


druntime thread (from foreach parallel?) cleanup bug

2022-11-01 Thread mw via Digitalmars-d-learn

My program received signal SIGSEGV, Segmentation fault.

Its simplified structure looks like this:

```
void foo() {
  ...
  writeln("done");  // saw this got printed!
}

int main() {
  foo();
  return 0;
}

```

So, just before the program exit, it failed. I suspect druntime 
has a thread (maybe due to foreach parallel) cleanup bug 
somewhere, which is unrelated to my own code. This kind of bug is 
hard to re-produce, not sure if I should file an issue.


I'm using: LDC - the LLVM D compiler (1.30.0) on x86_64.


Under gdb, here is the threads info (for the record):

Thread 11 "xxx" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x153df700 (LWP 36258)]
__GI___res_iclose (free_addr=true, statp=0x153dfdb8) at 
res-close.c:103

103 res-close.c: No such file or directory.


(gdb) info threads
  Id   Target Id Frame
  1Thread 0x15515000 (LWP 36244) "lt" 0x10af1d2d 
in __GI___pthread_timedjoin_ex (threadid=23456246527744, 
thread_return=0x0, abstime=0x0, block=) at 
pthread_join_common.c:89
* 11   Thread 0x153df700 (LWP 36258) "lt" __GI___res_iclose 
(free_addr=true, statp=0x153dfdb8) at res-close.c:103
  17   Thread 0x155544817700 (LWP 36264) "lt" 0x10afac70 
in __GI___nanosleep (requested_time=0x155544810e90, 
remaining=0x155544810ea8) at 
../sysdeps/unix/sysv/linux/nanosleep.c:28



(gdb) thread 1
[Switching to thread 1 (Thread 0x15515000 (LWP 36244))]
#0  0x10af1d2d in __GI___pthread_timedjoin_ex 
(threadid=23456246527744, thread_return=0x0, abstime=0x0, 
block=) at pthread_join_common.c:89

89  pthread_join_common.c: No such file or directory.
(gdb) where
#0  0x10af1d2d in __GI___pthread_timedjoin_ex 
(threadid=23456246527744, thread_return=0x0, abstime=0x0, 
block=) at pthread_join_common.c:89
#1  0x55fb94f8 in 
core.thread.osthread.joinLowLevelThread(ulong) ()
#2  0x55fd7210 in 
_D4core8internal2gc4impl12conservativeQw3Gcx15stopScanThreadsMFNbZv ()
#3  0x55fd3ae7 in 
_D4core8internal2gc4impl12conservativeQw3Gcx4DtorMFZv ()
#4  0x55fd3962 in 
_D4core8internal2gc4impl12conservativeQw14ConservativeGC6__dtorMFZv ()

#5  0x55fc2ce7 in rt_finalize2 ()
#6  0x55fc0056 in rt_term ()
#7  0x55fc0471 in 
_D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv ()

#8  0x55fc0356 in _d_run_main2 ()
#9  0x55fc01ae in _d_run_main ()
#10 0x55840c02 in main (argc=2, argv=0x7fffe188) at 
//home/zhou/project/ldc2-1.30.0-linux-x86_64/bin/../import/core/internal/entrypoint.d:42
#11 0x10163b97 in __libc_start_main (main=0x55840be0 
, argc=2, argv=0x7fffe188, init=, 
fini=, rtld_fini=, 
stack_end=0x7fffe178)

at ../csu/libc-start.c:310
#12 0x556dccca in _start ()


(gdb) thread 11
[Switching to thread 11 (Thread 0x153df700 (LWP 36258))]
#0  __GI___res_iclose (free_addr=true, statp=0x153dfdb8) at 
res-close.c:103

103 res-close.c: No such file or directory.
(gdb) where
#0  __GI___res_iclose (free_addr=true, statp=0x153dfdb8) at 
res-close.c:103

#1  res_thread_freeres () at res-close.c:138
#2  0x102de8c2 in __libc_thread_freeres () at 
thread-freeres.c:29
#3  0x10af0700 in start_thread (arg=0x153df700) at 
pthread_create.c:476
#4  0x10263a3f in clone () at 
../sysdeps/unix/sysv/linux/x86_64/clone.S:95



(gdb) thread 17
[Switching to thread 17 (Thread 0x155544817700 (LWP 36264))]
#0  0x10afac70 in __GI___nanosleep 
(requested_time=0x155544810e90, remaining=0x155544810ea8) at 
../sysdeps/unix/sysv/linux/nanosleep.c:28
28  ../sysdeps/unix/sysv/linux/nanosleep.c: No such file or 
directory.

(gdb) where
#0  0x10afac70 in __GI___nanosleep 
(requested_time=0x155544810e90, remaining=0x155544810ea8) at 
../sysdeps/unix/sysv/linux/nanosleep.c:28
#1  0x55fb8c3b in 
_D4core6thread8osthread6Thread5sleepFNbNiSQBo4time8DurationZv ()
#2  0x55d9a0c2 in 
_D4hunt4util8DateTimeQj25_sharedStaticCtor_L406_C5FZ9__lambda4MFZv () at home/zhou/.dub/packages/hunt-1.7.16/hunt/source/hunt/util/DateTime.d:430

#3  0x55fb89f4 in thread_entryPoint ()
#4  0x10af06db in start_thread (arg=0x155544817700) at 
pthread_create.c:463
#5  0x10263a3f in clone () at 
../sysdeps/unix/sysv/linux/x86_64/clone.S:95





Re: druntime thread (from foreach parallel?) cleanup bug

2022-11-01 Thread mw via Digitalmars-d-learn

Can you show a code snippet that includes the parallel foreach?


(It's just a very straight forward foreach on an array; as I said 
it may not be relevant.)



And I just noticed, one of the thread trace points to here:

https://github.com/huntlabs/hunt/blob/master/source/hunt/util/DateTime.d#L430

```
class DateTime {
  shared static this() {
...
dateThread.isDaemon = true;  // not sure if this is related
  }
}
```

in the comments, it said: "BUG: ... crashed".  Looks like someone 
run into this (cleanup) issue already, but unable to fix it.


Anyway I logged an issue there:

https://github.com/huntlabs/hunt/issues/96




Re: druntime thread (from foreach parallel?) cleanup bug

2022-11-01 Thread mw via Digitalmars-d-learn
On Tuesday, 1 November 2022 at 18:18:45 UTC, Steven Schveighoffer 
wrote:




And I just noticed, one of the thread trace points to here:

https://github.com/huntlabs/hunt/blob/master/source/hunt/util/DateTime.d#L430

```
class DateTime {
   shared static this() {
     ...
     dateThread.isDaemon = true;  // not sure if this is 
related

   }
}
```

in the comments, it said: "BUG: ... crashed".  Looks like 
someone run into this (cleanup) issue already, but unable to 
fix it.


Anyway I logged an issue there:

https://github.com/huntlabs/hunt/issues/96




Oh yeah, isDaemon detaches the thread from the GC. Don't do 
that unless you know what you are doing.




Maybe the hunt library author doesn't know. (My code does not 
directly use this library, it got pulled in by some other 
decencies.)



Currently, the `isDaemon` doc does not mention this about this:

https://dlang.org/library/core/thread/threadbase/thread_base.is_daemon.html

Sets the daemon status for this thread. While the runtime will 
wait for all normal threads to complete before tearing down the 
process, daemon threads are effectively ignored and thus will not 
prevent the process from terminating. In effect, daemon threads 
will be terminated automatically by the OS when the process exits.


Maybe we should add to the doc?


BTW, what is exactly going wrong with their code?

I saw the tick() method call inside the anonymous `dateThread` is 
accessing these two stack variables of shared static this():


https://github.com/huntlabs/hunt/blob/master/source/hunt/util/DateTime.d#L409

Appender!(char[])[2] bufs;
const(char)[][2] targets;

Why does this tick() call work after the static this() finished 
in a normal run?


Why the problem only shows up when program finish?




difference between x.atomicOp!"+="(1) and atomicFetchAdd(x, 1)?

2022-11-10 Thread mw via Digitalmars-d-learn

Hi,

Anyone can help explain what is the difference between 
x.atomicOp!"+="(1) and atomicFetchAdd(x, 1)?


From the doc, their return values are different

atomicOp
Performs the binary operation 'op' on val using 'mod' as the 
modifier.

Returns:
The result of the operation.


atomicFetchAdd
Atomically adds mod to the value referenced by val and returns 
the value val held previously. This operation is both lock-free 
and atomic.

Returns:
The value held previously by val.


Apart from this, any other difference, esp in a multithreaded 
program? Are they the same? Is atomicOp also lock-free?


Thanks.





Re: difference between x.atomicOp!"+="(1) and atomicFetchAdd(x, 1)?

2022-11-10 Thread mw via Digitalmars-d-learn

On Thursday, 10 November 2022 at 18:30:16 UTC, Paul Backus wrote:

On Thursday, 10 November 2022 at 17:04:31 UTC, mw wrote:

Hi,

Anyone can help explain what is the difference between 
x.atomicOp!"+="(1) and atomicFetchAdd(x, 1)?


Looking at the source in druntime, `atomicOp!"+="` forwards to 
`atomicFetchAdd` internally, so they should have the same 
behavior.


Thanks! Indeed:

https://github.com/dlang/dmd/blob/master/druntime/src/core/atomic.d#L582

(source is always your best friend :-)

and looks like atomicFetchAdd is more fundamental:

```
return cast(T)(atomicFetchAdd(val, mod) + mod);
```


does dmd --build=profile-gc work with core.stdc.stdlib.exit()?

2022-11-13 Thread mw via Digitalmars-d-learn

Hi,

I'm mem-profiling a multi-threaded program, and want it to exit 
early, so I added a call

```
core.stdc.stdlib.exit(-1);
```

in a loop in one of the thread.

However when the program reached this point, it seems hang: it's 
not exiting, and CPU usage dropped to 0%.


I'm wondering does dmd --build=profile-gc work with 
core.stdc.stdlib.exit()?


And where is the output report file, and the filename? I didn't 
see any report file generated in the current working dir.


BTW, can --build=profile-gc can intercept "Ctrl+C" and generate 
*partial* report file?


And what's the suggested proper way to do early exit, and still 
let --build=profile-gc generate reports?


Thanks!


Re: does dmd --build=profile-gc work with core.stdc.stdlib.exit()?

2022-11-13 Thread mw via Digitalmars-d-learn

On Sunday, 13 November 2022 at 18:48:42 UTC, mw wrote:
BTW, can --build=profile-gc can intercept "Ctrl+C" and generate 
*partial* report file?


And what's the suggested proper way to do early exit, and still 
let --build=profile-gc generate reports?


I tried presss "Ctrl+C", and that cannot stop the program, it 
just hangs there.


I have to `kill -9 ` it to get it stopped.


Re: does dmd --build=profile-gc work with core.stdc.stdlib.exit()?

2022-11-13 Thread mw via Digitalmars-d-learn

On Sunday, 13 November 2022 at 18:51:17 UTC, mw wrote:

On Sunday, 13 November 2022 at 18:48:42 UTC, mw wrote:
BTW, can --build=profile-gc can intercept "Ctrl+C" and 
generate *partial* report file?


And what's the suggested proper way to do early exit, and 
still let --build=profile-gc generate reports?


I tried presss "Ctrl+C", and that cannot stop the program, it 
just hangs there.


I have to `kill -9 ` it to get it stopped.


My build command is:
```
/dmd2/linux/bin64/dub build --build=profile-gc --config=... 
--compiler=dmd

```



Re: Proper way to exit with specific exit code?

2022-11-13 Thread mw via Digitalmars-d-learn
On Saturday, 19 September 2020 at 06:11:15 UTC, Jacob Carlborg 
wrote:

On 2020-09-17 16:58, drathier wrote:

What's the proper way to exit with a specific exit code?

I found a bunch of old threads discussing this, making sure 
destructors run and the runtime terminates properly, all of 
which seemingly concluding that it's sad that there isn't a 
way to do this easily, but hopefully things have changed in 
the last 5-10 years and I'm just missing the obvious solution.


The proper way is:

int main()
{
return 42;
}

I highly recommend against trying to terminate the application 
using `exit` or any other way. Just let the control flow return 
back to the `main` function.


I'm facing this problem to exit early from a multi threaded 
program for mem profiling purpose:


https://forum.dlang.org/thread/zbdevevgghtdgfryu...@forum.dlang.org


So what the simplest and reliable way to terminate all threads 
and exit to os?


I even tried core.stdc.stdlib.exit(-1), it does not work.






Re: does dmd --build=profile-gc work with core.stdc.stdlib.exit()?

2022-11-13 Thread mw via Digitalmars-d-learn

On Sunday, 13 November 2022 at 19:02:29 UTC, mw wrote:
BTW, can --build=profile-gc can intercept "Ctrl+C" and 
generate *partial* report file?


And what's the suggested proper way to do


Is there a profile-gc plugin function I can call in the middle of 
my program to generate *partial* report file?


Re: Proper way to exit with specific exit code?

2022-11-13 Thread mw via Digitalmars-d-learn

On Sunday, 13 November 2022 at 21:16:32 UTC, mw wrote:


I even tried core.stdc.stdlib.exit(-1), it does not work.


Tried
```
import core.runtime;
   Runtime.terminate();
   core.stdc.stdlib.exit(-1);
```

Still does not work.


Re: Proper way to exit with specific exit code?

2022-11-13 Thread mw via Digitalmars-d-learn

On Sunday, 13 November 2022 at 22:06:09 UTC, Imperatorn wrote:

On Sunday, 13 November 2022 at 21:37:47 UTC, mw wrote:

On Sunday, 13 November 2022 at 21:16:32 UTC, mw wrote:


I even tried core.stdc.stdlib.exit(-1), it does not work.


Tried
```
import core.runtime;
   Runtime.terminate();
   core.stdc.stdlib.exit(-1);
```

Still does not work.


I have no idea why it would fail. What about assert(0)?



I guess these two calls somehow only terminate the calling thread 
(? this is strange for core.stdc.stdlib.exit), the whole program 
just hangs after the call, and can only be terminated by `kill 
-9`.



I have to manually go thru each of the treads and plug in some 
kind of early exit logic to stop the whole program.



Will try assert(0) later.


Re: Proper way to exit with specific exit code?

2022-11-13 Thread mw via Digitalmars-d-learn

On Sunday, 13 November 2022 at 22:17:32 UTC, mw wrote:

On Sunday, 13 November 2022 at 22:06:09 UTC, Imperatorn wrote:

On Sunday, 13 November 2022 at 21:37:47 UTC, mw wrote:

On Sunday, 13 November 2022 at 21:16:32 UTC, mw wrote:


I even tried core.stdc.stdlib.exit(-1), it does not work.


Tried
```
import core.runtime;
   Runtime.terminate();
   core.stdc.stdlib.exit(-1);
```

Still does not work.


I have no idea why it would fail. What about assert(0)?



I guess these two calls somehow only terminate the calling 
thread (? this is strange for core.stdc.stdlib.exit), the whole 
program just hangs after the call, and can only be terminated 
by `kill -9`.



I have to manually go thru each of the treads and plug in some 
kind of early exit logic to stop the whole program.



Will try assert(0) later.


tried:

```
core.runtime.Runtime.terminate();
core.stdc.stdlib.exit(-1);
assert(0);
enforce(false);
```

Still not working, not even "Ctrl+C", have to `kill -9` to 
terminate it.


Re: Proper way to exit with specific exit code?

2022-11-13 Thread mw via Digitalmars-d-learn

On Sunday, 13 November 2022 at 22:42:45 UTC, mw wrote:

On Sunday, 13 November 2022 at 22:17:32 UTC, mw wrote:

On Sunday, 13 November 2022 at 22:06:09 UTC, Imperatorn wrote:

On Sunday, 13 November 2022 at 21:37:47 UTC, mw wrote:

On Sunday, 13 November 2022 at 21:16:32 UTC, mw wrote:


I even tried core.stdc.stdlib.exit(-1), it does not work.


Tried
```
import core.runtime;
   Runtime.terminate();
   core.stdc.stdlib.exit(-1);
```

Still does not work.


I have no idea why it would fail. What about assert(0)?



I guess these two calls somehow only terminate the calling 
thread (? this is strange for core.stdc.stdlib.exit), the 
whole program just hangs after the call, and can only be 
terminated by `kill -9`.



I have to manually go thru each of the treads and plug in some 
kind of early exit logic to stop the whole program.



Will try assert(0) later.


tried:

```
core.runtime.Runtime.terminate();
core.stdc.stdlib.exit(-1);
assert(0);
enforce(false);
```

Still not working, not even "Ctrl+C", have to `kill -9` to 
terminate it.


Tried put assert(0) at the top:


```
assert(0);
enforce(false);
core.runtime.Runtime.terminate();
core.stdc.stdlib.exit(-1);
```

Seems cannot even terminate the calling thread, since I got that 
assertion error thousands of times in the log.




in dub single file build how to pass "-J" options?

2022-12-21 Thread mw via Digitalmars-d-learn

I have example.d:

```
#!/usr/bin/env dub

/+dub.sdl:
dependency "tkd" version="~>1.1.14"
+/
...
```

$ dub build --single example.d

...
Error: need `-J` switch to import text file `folder_page.png`


I'm wondering how to pass  "-J" options?


BTW, for such single file build, do I have to use dub? is there 
another way to just use dmd?


Thanks.



Re: in dub single file build how to pass "-J" options?

2022-12-21 Thread mw via Digitalmars-d-learn

On Thursday, 22 December 2022 at 02:19:23 UTC, mw wrote:

I have example.d:

```
#!/usr/bin/env dub

/+dub.sdl:
dependency "tkd" version="~>1.1.14"
+/
...
```

$ dub build --single example.d

...
Error: need `-J` switch to import text file `folder_page.png`


I'm wondering how to pass  "-J" options?


Found it, it's:

```
/+dub.sdl:
dependency "tkd" version="~>1.1.14"
dflags "-Jmedia"
+/
```


BTW, for such single file build, do I have to use dub? is there 
another way to just use dmd?


Still don't know how to directly invoke dmd to build.



How to debug/set breakpoint a dynamic library.so ?

2023-02-09 Thread mw via Digitalmars-d-learn
The dynamic library.so is built from D (with pyd), and invoked 
from Python.


I'm just wondering How to debug/set breakpoint a dynamic 
library.so ?


Can someone give an example?

Thanks.


Re: How to debug/set breakpoint a dynamic library.so ?

2023-02-09 Thread mw via Digitalmars-d-learn

On Thursday, 9 February 2023 at 19:26:59 UTC, Ali Çehreli wrote:

On 2/9/23 06:00, mw wrote:
The dynamic library.so is built from D (with pyd), and invoked 
from Python.


I'm just wondering How to debug/set breakpoint a dynamic 
library.so ?


Can someone give an example?

Thanks.


I may be totally off on this but I think it is as simple as the 
following:


  gdb --args your_python_program

Once inside, set a break point on the dynamic library symbol. 
Then run.


Ali



Thank you, it worked!


All the best wishes for the recent earthquake in Turkey.




help: Unresolvable dependencies to package openssl

2023-03-08 Thread mw via Digitalmars-d-learn

Hi,

In my dub.json, I have:

```
"dependencies": {
"apache-thrift": "==0.16.0",
...
}

"subConfigurations": {
"apache-thrift": "use_openssl_1_1",
"pyd": "python39"
},

```

But:

$ dub build
Unresolvable dependencies to package openssl:
  apache-thrift 0.16.0 depends on openssl ~>2.0.3
  apache-thrift 0.16.0 depends on openssl ~>1.1.6
  app ~master depends on openssl ~>2.0.3


Why the subConfigurations: "use_openssl_1_1":

https://github.com/apache/thrift/blob/master/dub.json#L26

{
  "name": "use_openssl_1_1",
  "versions": ["use_openssl_1_1_x"],
  "dependencies": {
"openssl": {
  "version": "~>2.0.3"
}
  }
}

did not pick up the 2.0.3? but report conflict instead?

Thanks.




Re: help: Unresolvable dependencies to package openssl

2023-03-09 Thread mw via Digitalmars-d-learn
On Thursday, 9 March 2023 at 01:22:08 UTC, Steven Schveighoffer 
wrote:


This is a known limitation -- dub builds the selections file 
based on *all* configurations in the file. If you have 
conflicting ones, it will not know what to pick.


However, if you manually construct the selections file, then it 
will work.


Thanks, it worked.



See https://github.com/dlang/dub/issues/1217

-Steve





As of 2023, we still cannot declaring a constant string[char] AA?

2023-05-16 Thread mw via Digitalmars-d-learn

Hi,

I just run into this problem again:

https://stackoverflow.com/questions/26861708/what-is-the-syntax-for-declaring-a-constant-stringchar-aa

So, the solution still is to use:
```
static this () {
  ...
}
```

What happened to this comments:
"""
It should be noted that this restriction will eventually go away, 
once there is a solid library implementation of associative 
arrays. There is currently work in progress to this effect, which 
seems to be nearing completion. –

Meta  Nov 14, 2014 at 17:41
"""

Still not there yet, after ~10 years?


how to skip empty field in csvReader?

2023-06-05 Thread mw via Digitalmars-d-learn

Hi,

https://run.dlang.io/is/9afmT1

```
void main()
{
import std.csv;
import std.stdio: write, writeln, writef, writefln;
import std.algorithm.comparison : equal;
string text = "Hello;65;;\nWorld;123;7.5";
struct Layout
{
string name;
int value;
double other;
}

auto records = text.csvReader!Layout(';');
assert(records.equal([
Layout("Hello", 65, 2.5),
Layout("World", 123, 7.5),
]));


}
```

There is an empty field in the 1st line: "Hello;65;;", then

std.csv.CSVException@/dlang/dmd/linux/bin64/../../src/phobos/std/csv.d(1232): Floating 
point conversion error for input "".

Is there a way to tell csvReader to skip such empty fields?

Or, is there another CSV reader library with this functionality I 
can use?



Thanks.



Re: how to skip empty field in csvReader?

2023-06-06 Thread mw via Digitalmars-d-learn
On Tuesday, 6 June 2023 at 14:18:25 UTC, Steven Schveighoffer 
wrote:

On 6/6/23 1:09 AM, mw wrote:


Is there a way to tell csvReader to skip such empty fields?


What I have done is specify that it's a string, and then handle 
the conversion myself.



The std library need to be enhanced to skip such empty field 
(very simple change I think), it's a common scenario in real 
world data, which Python can handle easily.



Possibly it can use Nullable, but I'm not sure.

Or, is there another CSV reader library with this 
functionality I can use?


I don't know how much of this is supported in tsv-utils but you 
might give it a look.



https://github.com/eBay/tsv-utils

Do you know if there is any API doc?

Readme only has command line doc.





Re: looking for work-around: _d_assocarrayliteralTX segfault assigning a shared associative array an AA literal

2023-06-13 Thread mw via Digitalmars-d-learn

On Tuesday, 13 June 2023 at 17:12:41 UTC, Anonymouse wrote:

On Tuesday, 13 June 2023 at 17:06:55 UTC, mw wrote:

Does anyone know how to fix it? or any work-around?


Thanks.


I don't know if it's *correct* or not, but I think I did this 
at the time to work around it.


```
shared string[string] aa;

void main()
{
auto aaTemp = [ "abc" : "123" ];
aa = cast(shared)aaTemp;
}
```


Thanks, I just did a simple test:

https://gist.github.com/run-dlang/88cefdde8bb7f61f173ad11b2a03d5ee

(BTW, https://run.dlang.org/ is not stable these few days).

```
import core.thread;
import std;
import std.parallelism;

shared string[string] aa;

void fun() {
  foreach (i; 0 .. 5) {
writeln("fun", i, aa);
foreach (num; parallel(iota(5))) {
// writeln(num);
}
Thread.sleep(5.seconds);
  }
}


void main() {
writeln("start", aa);
auto aaTemp = [ "abc" : "123" ];
aa = cast(shared)aaTemp;
writeln(aa);
foreach (num; parallel(iota(5))) {
  auto t = new Thread({fun();}).start();
}
}
```

run result:
```
start[]
["abc":"123"]
fun0["abc":"123"]
fun0["abc":"123"]
fun0["abc":"123"]
fun0["abc":"123"]
fun0["abc":"123"]
fun1["abc":"123"]
fun1["abc":"123"]
fun1["abc":"123"]
fun1["abc":"123"]
fun1["abc":"123"]
fun2["abc":"123"]
fun2["abc":"123"]
fun2["abc":"123"]
fun2["abc":"123"]
fun2["abc":"123"]
fun3["abc":"123"]
fun3["abc":"123"]
fun3["abc":"123"]
fun3["abc":"123"]
fun3["abc":"123"]
fun4["abc":"123"]
fun4["abc":"123"]
fun4["abc":"123"]
fun4["abc":"123"]
fun4["abc":"123"]
```

looks like different threads can read the same `aa` contents. So 
at least it's working.


looking for hint to debug a strange multi-thread bug (grpc-d-core)

2023-06-13 Thread mw via Digitalmars-d-learn

Hi,

I recently found and started playing with the grpc-d-core[1] 
package, and my program structure looks like this:


https://github.com/mw66/grpc-demo/blob/master/source/main.d

If I run L64 alone (without L66 ~ 79 grpc-d part):
```
64: auto t = new Thread({fun();}).start();
```
it works fine.

If I run L66 ~ 79 grpc-d part alone (without L64), it also works 
fine.


But if I run both, the program received signal SIGSEGV, 
Segmentation fault at here:


https://github.com/mw66/grpc-d/blob/master/source/grpc/server/package.d#L94

with LDC, the print out of `services.keys` shows its corrupted 
with some strange values.


under DMD, it fails at:

https://github.com/mw66/grpc-d/blob/master/source/grpc/server/package.d#L99

while the `services.keys` seems fine.

What puzzles me is that: these two parts of the code are actually 
independent, does not know each other at all (as I just started 
to add the grpc-d skeleton code with dummy returns, and no client 
connected or made any rpc calls).


And the `services` defined here is a private class field:

https://github.com/mw66/grpc-d/blob/master/source/grpc/server/package.d#L21

So how can it be corrupted by `fun()`?


Any suggestions where should I look into?

Thanks.


[1] https://code.dlang.org/packages/grpc-d-core




Re: looking for work-around: _d_assocarrayliteralTX segfault assigning a shared associative array an AA literal

2023-06-13 Thread mw via Digitalmars-d-learn
On Tuesday, 13 June 2023 at 22:21:10 UTC, Steven Schveighoffer 
wrote:
As far as I can tell, this problem has been occurring for a 
long time.


BTW, you don't need to define it in global space, just:

```d
void main()
{
   shared aa = ["abc": "123"];
}
```


I have to ask the old-timers on this forums: looks like the dlang 
built-in AA has caused us too many problems, I'm just wondering 
which (dict / map) library on https://code.dlang.org/ provides 
the best (reliable and convenient) drop-in replacement of the 
built-in AA?


Thanks.



Re: looking for hint to debug a strange multi-thread bug (grpc-d-core)

2023-06-13 Thread mw via Digitalmars-d-learn
UPDATE: life is too short to debug dlang built-in AA to right, 
let's just use HashMap from emsi_containers


https://github.com/mw66/grpc-d/blob/master/source/grpc/server/package.d#L25
```
HashMap!(string, ServiceHandlerInterface) services;
```

After this change, the problem goes away.

I think there are some bugs in the builtin AA implementation, as 
demo-ed in this multi-threaded program (maybe also related to 
GC?).




ldc link error on new machine: undefined reference to `_D6object9Throwable7messageMxFNbNfZAxa'

2023-06-14 Thread mw via Digitalmars-d-learn

Hi,

I switched to a different machine to build my project, suddenly I 
got lots of link errors. (It builds fine on the old machine, and 
my software version are the same on both machines LDC - the LLVM 
D compiler (1.32.2))


e.g.:
```
...
/usr/bin/ld: 
/home//.dub/cache/cachetools/0.3.1/build/library-unittest-linux.posix-x86_64-ldc_v1.32.2-71414BF132F687B008642EB263AC23264B21497EA1FEF7D8AFA169EDF7967ADF/libcachetools.a(cachetools.containers.hashmap.o):(.data.rel.ro._D10cachetools10containers7hashmap11KeyNotFound6__vtblZ+0x48): undefined reference to `_D6object9Throwable7messageMxFNbNfZAxa'

```

even manually specify
```
"lflags-ldc": [
"-ldruntime-ldc"
],
```
does not solve the problem, while the symbol is there:

```
$ nm /project/ldc2/lib/libdruntime-ldc.a | grep 
_D6object9Throwable7messageMxFNbNfZAxa

 U _D6object9Throwable7messageMxFNbNfZAxa
 U _D6object9Throwable7messageMxFNbNfZAxa
 U _D6object9Throwable7messageMxFNbNfZAxa
 U _D6object9Throwable7messageMxFNbNfZAxa
 U _D6object9Throwable7messageMxFNbNfZAxa
 T _D6object9Throwable7messageMxFNbNfZAxa
```

Anything else I should check?

Thanks.



Re: ldc link error on new machine: undefined reference to `_D6object9Throwable7messageMxFNbNfZAxa'

2023-06-14 Thread mw via Digitalmars-d-learn

On Thursday, 15 June 2023 at 01:20:50 UTC, H. S. Teoh wrote:
On Thu, Jun 15, 2023 at 12:49:30AM +, mw via 
Digitalmars-d-learn wrote:

Hi,

Recently encountered a similar problem, ultimately the cause 
was that my library paths turned out to be wrongly set, so it 
was picking up the wrong version of the precompiled libraries.  
Probably you could check whether the library paths in ldc2.conf 
are set correctly, and also double-check whether the libraries 
at those paths are actually the correct ones for your compiler 
version (you may have installed the wrong libraries in the 
right paths).  Mixing up libraries from different LDC releases 
tend to show up as link errors of this kind.


Thanks for the tip, indeed it was caused by `ld` picking up the 
wrong lib (in a different sys path):


```
$ locate libdruntime-ldc
(... my local LDC install)
/usr/lib/x86_64-linux-gnu/libdruntime-ldc-debug-shared.so
/usr/lib/x86_64-linux-gnu/libdruntime-ldc-debug-shared.so.2.0.98
/usr/lib/x86_64-linux-gnu/libdruntime-ldc-debug-shared.so.98
/usr/lib/x86_64-linux-gnu/libdruntime-ldc-debug.a
/usr/lib/x86_64-linux-gnu/libdruntime-ldc-shared.so
/usr/lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.2.0.98
/usr/lib/x86_64-linux-gnu/libdruntime-ldc-shared.so.98
/usr/lib/x86_64-linux-gnu/libdruntime-ldc.a
```

while I'm using my local installed LDC.  After removing the 
system installation, it worked.





Using C++ Classes From D: dmd cannot link, while ldc segfault

2023-06-18 Thread mw via Digitalmars-d-learn

Hi,

I'm following this example:

https://dlang.org/spec/cpp_interface.html#using_cpp_classes_from_d

and try to wrap a std::list

base.cpp
```cpp
#include 
#include 

using namespace std;

class Base
{
public:
virtual void print3i(int a, int b, int c) = 0;
};

class Derived : public Base
{
public:
int field;
Derived(int field) : field(field) {}

void print3i(int a, int b, int c)
{
cout << "a = " << a << endl;
cout << "b = " << b << endl;
cout << "c = " << c << endl;
}

int mul(int factor);
};

template class std_list : public std::list {};
void getInts(std_list* list);

int Derived::mul(int factor)
{
return field * factor;
}

Derived *createInstance(int i)
{
// get list of ints from D side
std_list list;
list.push_back(911);
::getInts(&list);
for (int i : list) {
cout << "i = " << i << endl;
}

return new Derived(i);
}

void deleteInstance(Derived *&d)
{
delete d;
d = 0;
}
```

main.c
```
extern(C++)
{
abstract class Base
{
void print3i(int a, int b, int c);
}

class Derived : Base
{
int field;
@disable this();
override void print3i(int a, int b, int c);
final int mul(int factor);
}

Derived createInstance(int i);
void deleteInstance(ref Derived d);
}

extern(C++) {

class std_list(T) {
  @disable this();
  void push_back(const ref T value);
}

void getInts(std_list!(int) list) {
  foreach (int i; 0 .. 10) {
list.push_back(i);
  }
}

}

void main()
{
import std.stdio;

auto d1 = createInstance(5);
writeln(d1.field);
writeln(d1.mul(4));

Base b1 = d1;
b1.print3i(1, 2, 3);

deleteInstance(d1);
assert(d1 is null);

auto d2 = createInstance(42);
writeln(d2.field);

deleteInstance(d2);
assert(d2 is null);
}

```

Makefile
```
c2d:
g++ -c -g -ggdb base.cpp
ldmd2 -g main.d base.o -L-lstdc++ && ./main

```

if I use LCD (ldmd2), it segfaults:
```
$ make
g++ -c -g -ggdb base.cpp
ldmd2 -g main.d base.o -L-lstdc++ && ./main
Segmentation fault (core dumped)
```

and gdb shows it fails at: main.d:29 list.push_back(i);

if I use DMD, it cannot link:
```
$ make
g++ -c -g -ggdb base.cpp
dmd -g main.d base.o -L-lstdc++ && ./main
/usr/bin/ld: main.o:(.data._D4main__T8std_listTiZQm6__vtblZ+0x0): 
undefined reference to `std_list::push_back(int const&)'

collect2: error: ld returned 1 exit status
Error: linker exited with status 1
```

Looks like something wrong with the push_back().

So, how to fix this DMD link error, and LDC segfaults?

Thanks.




Re: Using C++ Classes From D: dmd cannot link, while ldc segfault

2023-06-18 Thread mw via Digitalmars-d-learn
On Monday, 19 June 2023 at 05:32:23 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
This is just a guess, but I think the problem is the vtable is 
incomplete.


Because of this the offsets are wrong. So you wouldn't be 
calling push_back.


So, you mean on the D side, it need to list all the fields and 
methods of the C++ class?


```d
class std_list(T) {
  @disable this();
  void push_back(const ref T value);
}
```

Then it will be very tedious, esp. for such library class 
std::list.


Is there a tool that can automate this?

Thanks.



Re: Using C++ Classes From D: dmd cannot link, while ldc segfault

2023-06-18 Thread mw via Digitalmars-d-learn

On Monday, 19 June 2023 at 05:39:51 UTC, mw wrote:
Then it will be very tedious, esp. for such library class 
std::list.


Is there a tool that can automate this?



A related question: basically I want to pass an array of objects 
from D side to the Cpp side, is there any example showing how to 
do this?


On this page

https://dlang.org/spec/cpp_interface.html#cpp-templates

I did not find any information about passing array (containers) 
between D and Cpp.


Thanks.


  1   2   3   >