visibility deprecation with last dmd compiler

2017-05-03 Thread jacob via Digitalmars-d-learn

I have 2 files

file abc.d:
==
module my.abc;

class Abc
{
private int x;
this() { this.x = 1; }
}
==

and xyz.d:
==
module my.xyz;
import my.abc;
class Xyz: Abc
{
this() { super(); this.x = 2; }
}
==

Compilation fails with "Deprecation: my.abc.Abc.x is not visible 
from module xyz"


As I understand, the reason is 
https://dlang.org/changelog/2.071.0.html#dip22


But how can I use private fields from descedant class?



Re: Pointer to private structure

2016-12-19 Thread Nikhil Jacob via Digitalmars-d-learn

On Monday, 19 December 2016 at 10:14:49 UTC, Ali wrote:

On Monday, 19 December 2016 at 06:42:27 UTC, Nikhil Jacob wrote:

[...]


What're you trying to do here?

Forward declarations in C++ are used to solve a few different 
things:

1. Reduce build times (unneeded in D AFAIK)
2. Break cyclic references (unneeded in D again?)
3. Give APIs visibility (D's modules and Access layers solve 
this)
4. Maintain binary compatibility while allowing internal data 
changes (aka pimlp idiom) <-- This I believe you cannot do in D 
- https://wiki.dlang.org/Access_specifiers_and_visibility 
(someone correct me if I'm wrong)


I've seen something about .di files in D. But they seem flakey 
a bit.


I was trying to do something similar to pimlp idiom.

But after thinking over it, I found a better way in D.

Thanks for pointing to the wiki


Re: Pointer to private structure

2016-12-18 Thread Nikhil Jacob via Digitalmars-d-learn

On Monday, 19 December 2016 at 06:21:10 UTC, ketmar wrote:
i bet that just trying this with D compiler will take less time 
than writing forum post.


I did try but it seems to give compilation failure... Let me try 
once more and I will get back with more details.


Pointer to private structure

2016-12-18 Thread Nikhil Jacob via Digitalmars-d-learn
In C, we can define a struct without body in an include file and 
use pointer to that structure


For examples in public header file.

struct data;
data* new_data();


We can then define the elements of struct data privately inside 
the implementation of library.


Can we do this in D without using void* ?




Re: How to override impure function from pure function

2016-12-12 Thread Nikhil Jacob via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 05:10:02 UTC, Nicholas Wilson 
wrote:
On Tuesday, 13 December 2016 at 04:48:11 UTC, Nikhil Jacob 
wrote:
In the D spec for pure functions it says that a pure function 
can override


"can override an impure function, but an impure function 
cannot override a pure one"


Can anyone help me how to do this ?


what this means is

class Foo
{
   void foo() { ... }
}

class Bar : Foo
{
override void foo() pure { ... }
}

is allowed. but

int someglobal;
class Foo
{
   void foo() pure { ... }
}

class Bar : Foo
{
override void foo()  { someglobal = 42; }
}

in not.


I mistook the original statement to mean that an impure function 
can be called from a pure function with some manual overrides.


Thank you for the clarification.


How to override impure function from pure function

2016-12-12 Thread Nikhil Jacob via Digitalmars-d-learn
In the D spec for pure functions it says that a pure function can 
override


"can override an impure function, but an impure function cannot 
override a pure one"


Can anyone help me how to do this ?


Re: Check whether function/delegate uses any shared or global variables

2016-12-12 Thread Nikhil Jacob via Digitalmars-d-learn

On Monday, 12 December 2016 at 12:30:42 UTC, Jacob Carlborg wrote:

On 2016-12-12 12:15, Nicholas Wilson wrote:

there is the pure function attribute, how ever this still 
allows you to

use globals *if you pass them as parameters to the function*.


And it can access immutable global data.


Thank you all for the help


Re: Check whether function/delegate uses any shared or global variables

2016-12-12 Thread Nikhil Jacob via Digitalmars-d-learn
On Monday, 12 December 2016 at 11:15:28 UTC, Nicholas Wilson 
wrote:

On Monday, 12 December 2016 at 11:02:21 UTC, Nikhil Jacob wrote:
Is there any way to check whether a function/delegate passed 
to a function uses any shared or global variables ?


I could not find any in std.traits.


there is the pure function attribute, how ever this still 
allows you to use globals *if you pass them as parameters to 
the function*.


see https://dlang.org/spec/function.html#pure-functions


Make sense.. I have two follow up questions

1. What about delegates ?
2. If a function is not explicitly declared as pure but satisfies 
the conditions of a pure function then can i check whether the 
function is pure using functionAttributes in std.traits.





Check whether function/delegate uses any shared or global variables

2016-12-12 Thread Nikhil Jacob via Digitalmars-d-learn
Is there any way to check whether a function/delegate passed to a 
function uses any shared or global variables ?


I could not find any in std.traits.




Re: sending shared pointer to struct. message type mismatch

2016-04-21 Thread jacob via Digitalmars-d-learn

On Thursday, 21 April 2016 at 17:33:32 UTC, ag0aep6g wrote:

On 21.04.2016 19:10, jacob wrote:
I was going to suggest either sending a `shared(TS*)` or 
receiving a `shared(T)*`. But it looks like you can't send a 
shared pointer. When I tried, it got turned into a 
unshared-pointer-to-shared on the way.


Oh that tricky "shared" keyword... Thank you!

http://pastebin.com/YkZ3YzKG fixed version here


sending shared pointer to struct. message type mismatch

2016-04-21 Thread jacob via Digitalmars-d-learn

Hello!

I try to send shared pointer to struct:

[code]
import std.stdio;
import std.concurrency;

shared struct S(T, uint M)
{
T[M] x;
}

shared struct M
{
int x;
}


private void runner(T)()
{
shared(T*) s = receiveOnly!(shared(T*))();
writeln(s.x.length);
writeln(s.x[0]);
send(thisTid, true);
}

int main(string[] argv)
{
alias S!(M, 2) TS;
alias shared(TS*) PS;

Tid runnerTid = spawn(!(TS));

auto s = new shared(TS);
s.x[0] = M(42);
send(runnerTid, s);

bool ok = receiveOnly!bool();

return 0;
}
[/code]

But after evaluating line "shared(T*) s = 
receiveOnly!(shared(T*))();" I get an exception:


"First-chance exception: std.concurrency.MessageMismatch 
Unexpected message type: expected 'shared(S!(M, 2u)*)', got 
'shared(engine.S!(M, 2u).S)*' at std\concurrency.d(224)"


How can I pass shared pointer to "runner" thread correctly?


trying to implement lock-free fixedsize queue

2016-03-31 Thread jacob via Digitalmars-d-learn
I try to implement chunk (something like lock-free fixedsize 
queue)

--
import core.atomic;

shared struct Chunk(T, uint N)
{
shared T[N] data;
shared uint count;
shared uint queueCounter;

@property uint capacity() { return N; }
@property uint count() { return count; }
@property bool full() { return count == N; }

void append(shared T value)
{
atomicOp!("+=")(queueCounter, 1);
while(1)
{
uint c = count;
if(cas(, c, c + 1))
{
data[c] = value;
atomicOp!("-=")(queueCounter, 1);
break;
}
}   
}

bool waitAll()
{
if(!full())
{
return false;
}

while(0 != queueCounter)
{
}

return true;
}
}
--

And call it like:

--
import std.parallelism;

struct S
{
bool dirty;
int time;
int[16] data;
}

int main(string[] argv)
{
const uint N = 14344;

shared Chunk!(S, N) ch;

foreach(i; taskPool.parallel(std.range.iota(N), 10))
{
shared S item;
item.time = i;
ch.append(item);
}
while(!ch.waitAll()) {}

// DONE

return 0;
}
--

It works fine with N == 14343, but fails without any message with 
14344 (value depends on computer).


Why does program fail?

Am I doing correct CAS append?


Re: How to setup mono-D for shared libraries?

2015-09-24 Thread Jacob via Digitalmars-d-learn
On Wednesday, 23 September 2015 at 04:34:45 UTC, Rikki Cattermole 
wrote:

On 23/09/15 8:20 AM, Jacob wrote:
How do I setup mono-D for creating shared libraries and 
including them
into other projects? When I drag the .d files to create the 
library
from, which is not my own, I get undefined references. I have 
the lib
files, which are a bunch of separate libs, that I want to 
include into
one big lib. Once that's done I want to include that lib into 
another

project.

I'd rather not modify si.ini. Are there any tutorials for 
getting

started with Mono-D? (setup, not coding)


Well you could go the route of dub, which configuration files 
can be loaded directly into it as a project.


To create the library, what do I do?

'dub init myLib'

then delete app.d,

and then add all the library.d files?

Then what? Where do I tell it to find the .lib files without 
adding them to sc.ini?


Do I just mess with dub.json to and add all the proper build 
options to get both the lib and the dependent apps working or are 
there other steps I'm missing?








How to setup mono-D for shared libraries?

2015-09-22 Thread Jacob via Digitalmars-d-learn
How do I setup mono-D for creating shared libraries and including 
them into other projects? When I drag the .d files to create the 
library from, which is not my own, I get undefined references. I 
have the lib files, which are a bunch of separate libs, that I 
want to include into one big lib. Once that's done I want to 
include that lib into another project.


I'd rather not modify si.ini. Are there any tutorials for getting 
started with Mono-D? (setup, not coding)