Re: C++/D class interop example crashes

2021-03-27 Thread Mike Parker via Digitalmars-d-learn

On Saturday, 27 March 2021 at 21:50:19 UTC, Jan wrote:
On Saturday, 27 March 2021 at 18:39:53 UTC, Bastiaan Veelo 
wrote:
The example links objects statically. You may be experiencing 
additional challenges with crossing DLL boundaries. I have not 
yet used DLLs, but did you initialise the D runtime?


I haven't done anything extra (I'm pretty new to D). Do you 
mean calling this from the D code before using writeln?

https://dlang.org/phobos/core_runtime.html#initialize

I would have thought that happens automatically anyway.


It should be in this case since the D code in the example is an 
application with a D main. The compiler will generate an 
extern(C) main that initializes the runtime and calls your D 
main. You have to initialize the runtime manually in three cases: 
you implement an extern(C) main yourself, you use WinMain instead 
of main, or you implement a shared library in D.


The problem most likely has to do with your use of a DLL rather 
than linking statically as in the example. D interfaces with C 
DLLs just fine, but given that C++ compatibility is limited, I 
would expect issues when interfacing with C++ DLLs.




Re: code.dlang.org package search subtly broken?

2021-03-27 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 27 March 2021 at 20:36:08 UTC, bachmeier wrote:

On Saturday, 27 March 2021 at 14:53:52 UTC, Imperatorn wrote:

Yeah, the search is broken sadly. I made a PR about it some 
time ago. Partial searches doesn't work


I don't think it's Dub search that's broken, really, it's that 
Dub uses MongoDB for searches, as discussed here:


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

There have been complaints about Dub search for as long as I 
can remember, but for whatever reason it's never been brought 
up to standards.


I have a fix for it but got stuck at setting up dub-registry. 
There was some config or credentiall issue or smth. Maybe I can 
try again next week


Re: Immutable

2021-03-27 Thread Meta via Digitalmars-d-learn

On Saturday, 27 March 2021 at 20:44:12 UTC, Brad wrote:
I was looking through lots of sample code on Rosetta Code.  D 
has a lot of solutions out there.  That is really nice but it 
has me wondering - coming from other languages that do not 
support the concept of immutability - do real world programmers 
and/or hobbyists really use it as much as I see it on Rosetta 
Code?  I know it adds a layer of security to your code, but I 
am still thinking "why?".


Thanks for entertaining a newbie question.


FYI, most of those examples were written by someone who goes by 
"Bearophile", and their style of writing D uses 
immutable/const/pure/nothrow/etc. wherever possible. It's not 
necessarily the style that all D programmers use, though there 
are a number of people that do.


As for advantages, when it comes to the basic value types (int, 
float, bool, etc.), it's not all that useful. Where immutable can 
become very useful, though, is with types that have indirections 
(i.e. pointers). D's `string` type, for example, is actually a 
simple alias in Druntime:


alias string = immutable(char)[];

Meaning "a mutable array of immutable chars". This means that you 
can modify the array itself, such as changing its length, 
appending to it, etc., but you cannot its individual elements. 
E.g., the following will work:


string s1 = "this is a string";
s1 ~= '.';
assert(s1 == "this is a string.");

But this will NOT work:

string s2 = "this is a string ";
s2[$ - 1] = '.'; Error: cannot modify immutable expression 
s2[__dollar - 1LU]


This is just a simple example, but it allows the compiler to do 
some major optimizations on string handling code. Something that 
is usually very slow in C/C++ is such code, because strings are 
mutable arrays of mutable characters. Thus, they have to be 
copied around everywhere, which is slow and uses a lot of memory 
unnecessarily.


Not so in D; because strings are mutable arrays of immutable 
characters, you can freely pass out references to the whole 
string, or a subrange of it. This would be very dangerous in 
C/C++, but in D you don't have to worry about the string changing 
out from under you by some code somewhere else in the program 
that you gave a reference to. Thus, string handling code is far 
faster in D than in C/C++.


That is just one example, but you can see how immutable makes 
possible a lot of optimizations that would simply be impossible 
in languages without it.


Re: Immutable

2021-03-27 Thread bachmeier via Digitalmars-d-learn

On Saturday, 27 March 2021 at 20:44:12 UTC, Brad wrote:
I was looking through lots of sample code on Rosetta Code.  D 
has a lot of solutions out there.  That is really nice but it 
has me wondering - coming from other languages that do not 
support the concept of immutability - do real world programmers 
and/or hobbyists really use it as much as I see it on Rosetta 
Code?  I know it adds a layer of security to your code, but I 
am still thinking "why?".


Thanks for entertaining a newbie question.


I'm not enough of an expert on immutable to give an informed 
opinion (I don't care for the implementation). Jonathan Davis has 
written this blog post about the limitations of const, which also 
talks about immutable quite a bit:


http://www.jmdavisprog.com/articles/why-const-sucks.html


Re: C++/D class interop example crashes

2021-03-27 Thread Jan via Digitalmars-d-learn

On Saturday, 27 March 2021 at 18:39:53 UTC, Bastiaan Veelo wrote:
The example links objects statically. You may be experiencing 
additional challenges with crossing DLL boundaries. I have not 
yet used DLLs, but did you initialise the D runtime?


I haven't done anything extra (I'm pretty new to D). Do you mean 
calling this from the D code before using writeln?

https://dlang.org/phobos/core_runtime.html#initialize

I would have thought that happens automatically anyway.


Immutable

2021-03-27 Thread Brad via Digitalmars-d-learn
I was looking through lots of sample code on Rosetta Code.  D has 
a lot of solutions out there.  That is really nice but it has me 
wondering - coming from other languages that do not support the 
concept of immutability - do real world programmers and/or 
hobbyists really use it as much as I see it on Rosetta Code?  I 
know it adds a layer of security to your code, but I am still 
thinking "why?".


Thanks for entertaining a newbie question.


Re: code.dlang.org package search subtly broken?

2021-03-27 Thread bachmeier via Digitalmars-d-learn

On Saturday, 27 March 2021 at 14:53:52 UTC, Imperatorn wrote:

Yeah, the search is broken sadly. I made a PR about it some 
time ago. Partial searches doesn't work


I don't think it's Dub search that's broken, really, it's that 
Dub uses MongoDB for searches, as discussed here:


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

There have been complaints about Dub search for as long as I can 
remember, but for whatever reason it's never been brought up to 
standards.


Re: C++/D class interop example crashes

2021-03-27 Thread bachmeier via Digitalmars-d-learn

On Saturday, 27 March 2021 at 18:39:53 UTC, Bastiaan Veelo wrote:

The example links objects statically. You may be experiencing 
additional challenges with crossing DLL boundaries. I have not 
yet used DLLs, but did you initialise the D runtime?


— Bastiaan.


This is an example taken from the documentation. It should work 
out of the box.


I tried with LDC (don't have dmd on this computer) and I got this 
error:


/usr/bin/ld: base.o: undefined reference to symbol '_d_allocclass'
/usr/bin/ld: /usr/lib64/libdruntime-ldc-shared.so.90: error 
adding symbols: DSO missing from command line

collect2: error: ld returned 1 exit status

Given that someone interoperating with C++ probably cares about 
performance, it should also work out of the box with LDC, or at 
least tell you the changes that need to be made. I'll open an 
issue in the bug tracker when I return home (traveling now) if 
someone else doesn't.


Re: C++/D class interop example crashes

2021-03-27 Thread Bastiaan Veelo via Digitalmars-d-learn

On Saturday, 27 March 2021 at 15:09:20 UTC, Jan wrote:

I just tried to get this example to work:
https://dlang.org/spec/cpp_interface.html#using_d_classes_from_cpp

It kept crashing for me with a 'privileged instruction' error 
when the function 'bar' was executed. Finally I removed the 
call to writefln and voilà it finally works.


So why does it fail? I assumed the standard library functions 
should all work.
I'm compiling with "dmd -shared -m64 -debug" and link against a 
C++ DLL that was built with VS2019. Should the D DLL not 
contain everything to be self-sufficient to use it's entire 
runtime functionality?

And if not, what other functions might be problematic?


The example links objects statically. You may be experiencing 
additional challenges with crossing DLL boundaries. I have not 
yet used DLLs, but did you initialise the D runtime?


— Bastiaan.



Re: code.dlang.org package search subtly broken?

2021-03-27 Thread Brian via Digitalmars-d-learn

On Saturday, 27 March 2021 at 14:53:52 UTC, Imperatorn wrote:
Yeah, the search is broken sadly. I made a PR about it some 
time ago. Partial searches doesn't work


Good to know. Thank you.


C++/D class interop example crashes

2021-03-27 Thread Jan via Digitalmars-d-learn

I just tried to get this example to work:
https://dlang.org/spec/cpp_interface.html#using_d_classes_from_cpp

It kept crashing for me with a 'privileged instruction' error 
when the function 'bar' was executed. Finally I removed the call 
to writefln and voilà it finally works.


So why does it fail? I assumed the standard library functions 
should all work.
I'm compiling with "dmd -shared -m64 -debug" and link against a 
C++ DLL that was built with VS2019. Should the D DLL not contain 
everything to be self-sufficient to use it's entire runtime 
functionality?

And if not, what other functions might be problematic?

Also, if anyone here has contacts to the people that maintain the 
samples, maybe someone should adjust the sample to not contain 
code that may break this way.


Re: code.dlang.org package search subtly broken?

2021-03-27 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 27 March 2021 at 13:48:10 UTC, Brian wrote:

Hello --

When I go to https://code.dlang.org and use the search function 
on the top right corner, it usually works fine. However, there 
was one package I knew I specifically wanted (png-d) but when I 
typed png-d into the search bar, I was greeted with an error 
page, reproduced at the bottom of this message. I get this 
error whenever a hyphen is in the search query. I have not 
tested other special characters for this error.


[...]


Yeah, the search is broken sadly. I made a PR about it some time 
ago. Partial searches doesn't work


code.dlang.org package search subtly broken?

2021-03-27 Thread Brian via Digitalmars-d-learn

Hello --

When I go to https://code.dlang.org and use the search function 
on the top right corner, it usually works fine. However, there 
was one package I knew I specifically wanted (png-d) but when I 
typed png-d into the search bar, I was greeted with an error 
page, reproduced at the bottom of this message. I get this error 
whenever a hyphen is in the search query. I have not tested other 
special characters for this error.


Thanks!

~Brian

500 - Internal Server Error

Internal Server Error

Internal error information:
vibe.db.mongo.connection.MongoDriverException@../../vibe.d/mongodb/vibe/db/mongo/cursor.d(304):
 Query failed. Does the database exist?

??:? [0x562f5f97e175]
??:? [0x562f5f9a62b6]
??:? [0x562f5f98912d]
/root/ldc2-1.24.0-linux-x86_64/bin/../import/std/exception.d:517 
[0x562f5f3ee1c5]
/root/ldc2-1.24.0-linux-x86_64/bin/../import/std/exception.d:437 
[0x562f5f3e0625]

/mnt/c/Users/soenke/develop/0-dlang/dub-registry/../../vibe.d/mongodb/vibe/db/mongo/cursor.d:304
 [0x562f5f44820d]
/mnt/c/Users/soenke/develop/0-dlang/dub-registry/source/app.d:462 
[0x562f5f448cb0]
/mnt/c/Users/soenke/develop/0-dlang/dub-registry/source/app.d:322 
[0x562f5f448ad7]
/mnt/c/Users/soenke/develop/0-dlang/dub-registry/source/app.d:367 
[0x562f5f470f96]

/mnt/c/Users/soenke/develop/0-dlang/dub-registry/../../vibe.d/mongodb/vibe/db/mongo/cursor.d:233
 [0x562f5f447cfd]
/mnt/c/Users/soenke/develop/0-dlang/dub-registry/../../vibe.d/mongodb/vibe/db/mongo/cursor.d:60
 [0x562f5f36ba6d]
/root/ldc2-1.24.0-linux-x86_64/bin/../import/std/algorithm/iteration.d:615 
[0x562f5f470088]
/root/ldc2-1.24.0-linux-x86_64/bin/../import/std/array.d:140 
[0x562f5f366182]

/mnt/c/Users/soenke/develop/0-dlang/dub-registry/source/dubregistry/dbcontroller.d:333
 [0x562f5f31dee0]
/mnt/c/Users/soenke/develop/0-dlang/dub-registry/source/dubregistry/registry.d:103
 [0x562f5f2eba03]
/mnt/c/Users/soenke/develop/0-dlang/dub-registry/source/dubregistry/web.d:476 
[0x562f5f2eb967]
/mnt/c/Users/soenke/develop/0-dlang/dub-registry/../../vibe.d/web/vibe/web/web.d:1043
 [0x562f5f39947a]
/mnt/c/Users/soenke/develop/0-dlang/dub-registry/../../vibe.d/web/vibe/web/web.d:214
 [0x562f5f399083]
router.d:218 [0x562f5f7f0024]
router.d:674 [0x562f5f7f2856]
router.d:607 [0x562f5f7efcf6]
router.d:211 [0x562f5f7efaae]
server.d:2292 [0x562f5f7f80cb]
server.d:253 [0x562f5f7f64fe]
server.d:245 [0x562f5f7f5dbd]
server.d:2048 [0x562f5f80047e]
task.d:712 [0x562f5f8ea4b5]
task.d:730 [0x562f5f8e7091]
task.d:439 [0x562f5f8e67db]
??:? [0x562f5f97f5ba]


Re: isPOD is broken?

2021-03-27 Thread Oleg B via Digitalmars-d-learn

On Friday, 26 March 2021 at 12:13:29 UTC, kinke wrote:
A class *reference* is always a POD. Only structs can be 
non-PODs.


In this case what means "does not have virtual functions, does 
not inherit"? Structs doesn't have virtual methods and they can't 
inherits.