Re: tupleof seems to break encapsulation

2020-09-06 Thread Jacob Carlborg via Digitalmars-d-learn

On 2020-09-05 07:14, 60rntogo wrote:

I wouldn't dispute that it is useful, but that's besides the point. If I 
declare something private, it's usually because I want to preserve 
certain invariants and I want the compiler to provide a guarantee that I 
don't accidentally violate them. As it stands, the compiler cannot 
guarantee that if I use tupleof.


I don't really have an issue with read-only access to private fields 
(but arguments could be made against it) and then serialization would 
still be possible. However, if my struct is supposed to maintain 
invariants, then any attempt at deserialization that naively reads from 
a tuple without establishing these invariants should fail to compile.


I wouldn't mind if `tupleof` was not allowed in @safe code, which Walter 
mentions in one of the linked issues. Although it would be a breaking 
change.


Secondly, my serialization library, Orange [1], uses `tupleof` to read 
and write fields. It also supports before and after hooks for both 
serialization and deserialization. This allows to implement any 
invariants that are not covered by just restoring the fields. It also 
supports implementing a method that allows to take full control of the 
(de)serialization of a specific type.


Thirdly, you can do the same thing with pointer arithmetic. Although 
this is not allowed if @safe code.


[1] https://github.com/jacob-carlborg/orange

--
/Jacob Carlborg


Re: sending the address of a struct

2020-09-06 Thread Johann Lermer via Digitalmars-d-learn

On Sunday, 6 September 2020 at 11:10:14 UTC, Simen Kjærås wrote:

auto e = receiveOnly!(shared(Env)*);


Oh, thanks. Seems, that I just missed that bit with the 
pranetheses.


Re: Compile code for PowerNex OS

2020-09-06 Thread Dan Printzell via Digitalmars-d-learn

On Saturday, 5 September 2020 at 12:45:06 UTC, Quantium wrote:
I have a code that I need to compile for PowerNex OS, which 
compiler should I use and how to compile code for PowerNex?


Short version: You can't (right now).

Long version:
PowerNex is currently in broken development state so even if
you could compile code for it (which is not likely) you would
not be able to run it.

PowerNex uses a patched dmd version: 
https://github.com/PowerNex/PowerNex-dmd
and a patched binutils: 
https://github.com/PowerNex/PowerNex-binutils



Question:
What are you trying to compile?


Re: sending the address of a struct

2020-09-06 Thread Simen Kjærås via Digitalmars-d-learn

On Sunday, 6 September 2020 at 09:58:54 UTC, Johann Lermer wrote:

pointer. The error message says:

std.concurrency.MessageMismatch@std/concurrency.d(237): 
Unexpected message type: expected 'shared(Env*)', got 
'shared(test.Env)*'


The error message gives you all the information you need - notice 
the position of the asterisk inside the parens on one, outside on 
the other? The pointer itself is not shared, only the pointee - 
the data pointed to. This works:


auto e = receiveOnly!(shared(Env)*);

--
  Simen


sending the address of a struct

2020-09-06 Thread Johann Lermer via Digitalmars-d-learn

Hi,

I have a struct in a separate thread and want to pass it's 
address back to the main thread. This is how I think it should 
work:


import std.concurrency;

struct Env {}

void run ()
{
shared Env env;
ownerTid.send ();
for (;;) {}
}

void main ()
{
spawn ();
auto e = receiveOnly!(shared Env*);
}

but I'm getting an error when main tries to receive the pointer. 
The error message says:


std.concurrency.MessageMismatch@std/concurrency.d(237): 
Unexpected message type: expected 'shared(Env*)', got 
'shared(test.Env)*'


Now, how can I pass that pointer back to main?