weird formattedRead

2021-04-09 Thread Oleg B via Digitalmars-d-learn
Hello, I have some doubts about working `formattedRead` with 
space chars.


Example:
```d
import std : formattedRead, DateTime, stderr, each;

DateTime parseDT(string str)
{
int d,mo,y, h,m,s;
formattedRead!"%d/%d/%d %d:%d:%d"(str, d,mo,y, h,m,s);
return DateTime(y,mo,d, h,m,s);
}

void tryParse(string s)
{
try
{
auto dt = parseDT(s);
stderr.writefln!"valid '%s': %s"(s, dt);
}
catch (Exception e)
stderr.writefln!"INVALID '%s': %s"(s, e.msg);
}

void main()
{
auto vs = [
"",
"1",
"1/1",
"1/1/1",
"1/1/1 1",
"1/1/1 1:1",
"1/1/1 1:1:1",
];
vs.each!tryParse;
}
```

outputs:

```
INVALID '': 0 is not a valid month of the year.
INVALID '1': parseToFormatSpec: Cannot find character '/' in the 
input string.
INVALID '1/1': parseToFormatSpec: Cannot find character '/' in 
the input string.

valid '1/1/1': 0001-Jan-01 00:00:00 <<< see here
INVALID '1/1/1 1': parseToFormatSpec: Cannot find character ':' 
in the input string.
INVALID '1/1/1 1:1': parseToFormatSpec: Cannot find character ':' 
in the input string.

valid '1/1/1 1:1:1': 0001-Jan-01 01:01:01
```

Is space a special char for `formattedRead` and it simple stop 
parse without throwing exception if not found space (that 
represented in fmt string)?

Have `formattedRead` any other special chars?
Or it's bug?


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.


isPOD is broken?

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

Hi all!

class Foo
{
private int val;

this(int v) { val = v; }
int vv() { return val*2; }
~this() { }
}

class Bar : Foo
{
this(int v) { super(v); }
override int vv() { return val*3; }
}

pragma(msg, __traits(isPOD, Foo));
pragma(msg, __traits(isPOD, Bar));

prints

true
true


example1
https://run.dlang.io/is/Fvru18

example2
https://run.dlang.io/is/GrXdGy

May be POD is not what I mean? Bad docs? 
https://dlang.org/glossary.html#pod


Re: How to define delegate what returns ref?

2020-08-28 Thread Oleg B via Digitalmars-d-learn

On Friday, 28 August 2020 at 11:50:35 UTC, kinke wrote:

On Friday, 28 August 2020 at 11:46:15 UTC, Oleg B wrote:

How to do this more clearly?


alias Dg = ref int delegate();
Dg foo;


Thanks!


How to define delegate what returns ref?

2020-08-28 Thread Oleg B via Digitalmars-d-learn

Hello all!

syntax

ref int delegate() foo0;

or

ref(int) delegate() foo1;

or

int delegate() ref foo2;

are not valid.

if I try alias

alias refint = ref int;
refint delegate() foo3;

foo3 have type `int delegate()` (without `ref`)
and it can't store delegate from object method that have `int 
delegate() ref` (that can be printed if we use 
`typeof().stringof`)


I found only one ugly way to do this

interface Foo { ref int func(); }
typeof() foo4;

How to do this more clearly?


Re: Overload comparison operators for "nullable" types

2020-08-01 Thread Oleg B via Digitalmars-d-learn

On Thursday, 30 July 2020 at 14:52:17 UTC, H. S. Teoh wrote:
On Thu, Jul 30, 2020 at 01:41:05PM +, Oleg B via 
Digitalmars-d-learn wrote: [...]
Logically we can compare versions, but what must return 
`opCmp` if one of versions has 'not comparible' state?

[...]

opCmp is allowed to return float; so you could return float.nan 
in this case.



T


Thank you! Simple answer but not in documentation...


Overload comparison operators for "nullable" types

2020-07-30 Thread Oleg B via Digitalmars-d-learn

Hello!

For example we can imagine struct Version.
Version can be old or new and can be 'badly formed' or 
'undefined' or other 'not comparible' ('uncompatible') state.


Logically we can compare versions, but what must return `opCmp` 
if one of versions has 'not comparible' state?


I think strategy of throwing exception in `opCmp` is bad because 
some types can be 'not comparible' not because they is `null` or 
`undefined`, 'not comparible' can be two objects in some working 
states.


If we add `opEquals` we can check 'not comparible' and return 
`false`, but operators `a <= b` and `a >= b` not expands under 
the hood as `a < b || a == b`, they only call `opCmp` and if it 
returns 0 considered arguments are equals.


Rewrite `a <= b` as `a < b || a == b` is not intuitive and can 
get bugs if new user will use code (or old user forgot about 
this). Checking 'not comparible' state before `a <= b` is not 
intuitive too.


`opBinary` can't overload comparison.

We have same type of problem if wrap simple `double` into struct 
and try overload comparison (double.nan has own behavior).


Problem can be solved if we add new `opCmpEx` into language spec 
that return 4 states: more, less, equal, not equal.

Or if we allow `opBinary` overload comparisons.

May be I don't understand something important and this problem is 
not exists?


May be in cases where can be 'not comparible' state we should not 
use overload of comparison operators? But it looks like 
overloading conception isn't completed and can be improved.


must scope for delegates restrict compilation?

2019-10-03 Thread Oleg B via Digitalmars-d-learn

Hello all

I think this code must get compilation error, but it didn't, 
furthermore result program get UB.


https://run.dlang.io/is/Qpr278

Is this correct behavior and why?


Re: Is betterC affect to compile time?

2019-07-25 Thread Oleg B via Digitalmars-d-learn

On Thursday, 25 July 2019 at 12:34:15 UTC, rikki cattermole wrote:

Those restrictions don't stop at runtime.


It's vary sad.

What reason for such restrictions? It's fundamental idea or 
temporary implementation?


Re: Is betterC affect to compile time?

2019-07-25 Thread Oleg B via Digitalmars-d-learn

On Thursday, 25 July 2019 at 12:20:04 UTC, Mike Franklin wrote:


If you read the documentation for betterC 
(https://dlang.org/spec/betterc.html#consequences) you'll see 
that there are features of the D language which are not 
supported. Therefore, libraries that use such features (e.g. 
std.format, std.array) are also not supported, and that is why 
you are encountering such errors.


There are some features of Phobos which can be used in betterC 
builds, but you're going to find that it's hit-and-miss.


Mike


You don't understand my question and don't read code. I ask about 
compile time evaluation (`format` used inside `mixin` that means 
it must be computed at compile time). I know that I can't use 
many features with betterC at runtime.


Is betterC affect to compile time?

2019-07-25 Thread Oleg B via Digitalmars-d-learn

Hello everyone!

I try build this code with betterC

import core.stdc.stdio;
import std.format : format;

extern(C) int main()
{
mixin(format!`enum str = "%s\0";`("hello"));
fprintf(stderr, "%s\n", str.ptr);
return 0;
}

but compilation fails

/dlang/dmd/linux/bin64/../../src/phobos/std/format.d(6278): 
Error: Cannot use try-catch statements with -betterC
/dlang/dmd/linux/bin64/../../src/phobos/std/format.d(6308): 
Error: template instance `std.format.checkFormatException!("enum 
str = \"%s\\0\";", string)` error instantiating
onlineapp.d(6):instantiated from here: format!("enum str 
= \"%s\\0\";", string)
/dlang/dmd/linux/bin64/../../src/phobos/std/format.d(6311):   
 while evaluating: static assert(!e)
/dlang/dmd/linux/bin64/../../src/phobos/std/array.d(3204): Error: 
TypeInfo cannot be used with -betterC


Is this a bug?

https://run.dlang.io/is/TG1uhg


betterC and noboundscheck

2017-11-22 Thread Oleg B via Digitalmars-d-learn

Hello. I try compile simple example:

import core.stdc.stdio;
import std.algorithm : min;

extern (C) void main()
{
char[256] buf;
buf[] = '\0';

auto str = "hello world";
auto ln = min(buf.length, str.length);
buf[0..ln] = str[0..ln];
printf("%s\n", buf.ptr);
}

rdmd -betterC bettercarray2.d

and get error:

/tmp/.rdmd-1000/rdmd-bettercarray2.d-435C14EC3DAF09FFABF8ED6919B624C1/objs/bettercarray2.o:
 In function `main':
bettercarray2.d:(.text.main[main]+0xbc): undefined reference to 
`_d_arraycopy'

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

If I understand correctly _d_arraycopy is part of druntime and it 
check bounds of array access.


If I add -noboundscheck flag all works fine.

dmd version is 2.076.1

Why -betterC flag not 'include' -noboundscheck flag?
It's bug or in some cases it's useful?


Re: call Pascal DLL functions from D

2017-10-25 Thread Oleg B via Digitalmars-d-learn
On Wednesday, 25 October 2017 at 03:36:54 UTC, Adam D. Ruppe 
wrote:
I'd suggest just trying it and seeing if the functions return 
what you expect.


Unfortunately they returns unexpected codes. Otherwise I wouldn't 
post question here. I go here then I have no idea to resolve 
problem.


Re: call Pascal DLL functions from D

2017-10-25 Thread Oleg B via Digitalmars-d-learn

On Wednesday, 25 October 2017 at 04:30:12 UTC, Basile B. wrote:

On Wednesday, 25 October 2017 at 03:12:56 UTC, Oleg B wrote:

2. `array[A..B] of TFoo` is `TFoo[B-A+1]` (static array)


No A-B. In Pascal the upper bound of a range (like here but i'm 
not sure this i called like that in the grammar) or of a slice 
is inclusive.



alias HarmonicArray = OneHarmonic[49];


48 !

Most likely the problem is the array length.


If I wrote `array[5..7] of ...` I get array that can be indexed 
by `5`, `6` and `7`, right? It means that array have 3 elements. 
If A=5, B=7 then length of array is B-A+1, 7-5+1=3. In my case I 
have [1..49] and [2..50] ranges: 49-1+1=49, 50-2+1=49. I don't 
understand why length must be 48...
In any case I tried 48 and CheckSignalData function returns other 
error code, but it point to current field too (incorrect value of 
coefs - it can be if floating point value is badly read).


call Pascal DLL functions from D

2017-10-24 Thread Oleg B via Digitalmars-d-learn
Hello. I have DLL written on Pascal and "headers" for use it 
(types and functions signatures definitions). How I can port 
"headers" to D?


Calling convention is `stdcall` (`extern (Windows)` for D), 
arguments of some functions is structs of structs and etc with 
static array fields:


```Pascal
type
  TOneHarmonic = record
Koef: Single;
Angle: Single;
  end;

  THarmonicsArray = array[2..50] of TOneHarmonic;
  TInterharmonicsArray = array[1..49] of TOneHarmonic;

  TVoltageCurrentOneFaza = record
KalibKoef: Single;
IncludeMainFreq: Boolean;
MainFreqVoltCur: TOneHarmonic;
Harmonics: THarmonicsArray;
Interharmonics: TInterharmonicsArray;
  end;

  TVoltageCurrent = record
Enable: Boolean;
NominalID: Byte;
Faza_A: TVoltageCurrentOneFaza;
Faza_B: TVoltageCurrentOneFaza;
Faza_C: TVoltageCurrentOneFaza;
  end;

  TSignal = record
HasInterharmonics: Boolean;
Voltage: TVoltageCurrent;
Current: TVoltageCurrent;
...
  end;
  ...
```

in other file

```Pascal
function CheckSignalData(SignalData: PUserSignalData): Word;
  stdcall; external SIGNALK2MDLL;
```
PUserSignalData is pointer to TUserSignalData, first field of 
TUserSignalData is Signal, other fields is pointers to other types


If I understand correctly
1. `Single` is `float` in D, `Byte` is `byte`, `Boolean` is 
`bool`, `Word` is `ushort`

2. `array[A..B] of TFoo` is `TFoo[B-A+1]` (static array)

Can I rewrite records to structs like this?

```d
alias Word = short;
alias Single = float;
alias Byte = byte;
alias Boolean = bool;

struct OneHarmonic
{
Single coef;
Single angle;
}

alias HarmonicArray = OneHarmonic[49];

// TVoltageCurrentOneFaza
struct PhaseInfo
{
// Must I align fields and/or structs?
Single calibCoef;
Boolean includeMainFreq;
OneHarmonic mainFreqVoltCur;
HarmonicArray harmonics; // Can I replace Pascal static 
arrays with D static arrays?

HarmonicArray interharmonics;
}

// TVoltageCurrent
struct ChannelInfo
{
Boolean enable;
Byte nominalID;
PhaseInfo[3] phase; // Can I replace 3 fields to static array?
}

struct Signal
{
Boolean hasInterharmonics;
ChannelInfo voltage;
ChannelInfo current; // #1
...
}
```

In this case I have error about current values (#1) and I think I 
badly rewrite Pascal records to D structs (ChannelInfo, 
PhaseInfo, OneHarmonic) and lose alignments and/or something else.


PS original pascal naming is very bad, I know


Re: non-block reading from pipe stdout

2017-10-03 Thread Oleg B via Digitalmars-d-learn

On Tuesday, 3 October 2017 at 12:32:43 UTC, kdevel wrote:
IMHO a program should sleep (consume 0 CPU time and 0 energy) 
if there is nothing to process. This is best accomplished by 
not polling on a file descriptor in order to check if data has 
arrived. If your program must yield() there's probably 
something wrong with the design. I would suggest you put all 
the filedescriptors into a fd_set an then select(3) on the set.


Programs based on fibers can't sleep while wait data and it's not 
a design problem.




Re: non-block reading from pipe stdout

2017-10-03 Thread Oleg B via Digitalmars-d-learn

On Tuesday, 3 October 2017 at 10:45:21 UTC, kdevel wrote:

On Tuesday, 3 October 2017 at 00:22:28 UTC, Oleg B wrote:

but get error "Resource temporarily unavailable".


You get EAGAIN because there is no data available at the time 
of reading.


From the manpage of read:

ERRORS
   EAGAIN Non-blocking  I/O has been selected using 
O_NONBLOCK and no data

  was immediately available for reading.


I found only one way: C-style

auto pp = pipeShell(updaterScriptCommand, Redirect.all,
null, Config.none, workDir);

import core.sys.posix.unistd : read;
import core.stdc.errno;
import core.sys.posix.fcntl;

int fd = pp.stdout.fileno;
int flags = fcntl(fd, F_GETFL, 0);
flags |= O_NONBLOCK;
fcntl(fd, F_SETFL, flags); // C-style setting file config

char[256] buf;
while (!tryWait(pp.pid).terminated)
{
auto cnt = read(fd, buf.ptr, buf.length); // C-style 
reading
if (cnt == -1 && errno == EAGAIN) // C-style error 
checking

yield();
else if (cnt > 0)
{
doSomething(buf[0..cnt]);
yield();
}
}


Re: non-block reading from pipe stdout

2017-10-03 Thread Oleg B via Digitalmars-d-learn

On Tuesday, 3 October 2017 at 10:45:21 UTC, kdevel wrote:

On Tuesday, 3 October 2017 at 00:22:28 UTC, Oleg B wrote:

but get error "Resource temporarily unavailable".


You get EAGAIN because there is no data available at the time 
of reading.


From the manpage of read:

ERRORS
   EAGAIN Non-blocking  I/O has been selected using 
O_NONBLOCK and no data

  was immediately available for reading.


And I can't check this without using exception handling?


non-block reading from pipe stdout

2017-10-02 Thread Oleg B via Digitalmars-d-learn
Hello. I run program through std.process.pipeShell and want to 
read from it stdout in loop. How do this non-blocking?


I try

int fd = p.stdout.fileno;
int flags = fcntl(fd, F_GETFL, 0);
flags |= O_NONBLOCK;
fcntl(fd, F_SETFL, flags);

but get error "Resource temporarily unavailable".


betterC and struct destructors

2017-09-11 Thread Oleg B via Digitalmars-d-learn
Hello. I try using destructor in betterC code and it's work if 
outer function doesn't return value (void). Code in `scope 
(exit)` works as same (if func is void all is ok).


In documentation I found 
https://dlang.org/spec/betterc.html#consequences 12 paragraph: 
Struct deconstructors.


Why struct destructor need Druntime? Compiler must simply past 
call of destructor before exit from scope or return statement. 
Where is Druntime here (dynamic allocations, pointers to scopes 
and other)?


I think struct destructor must work in betterC code. Otherwise it 
will be one step to be likeC, not betterC.


Re: Automatic function body writing howto?

2017-08-17 Thread Oleg B via Digitalmars-d-learn

On Wednesday, 16 August 2017 at 22:48:59 UTC, Meta wrote:
It's hard to tell offhand but I would recommend that you 
extract the inner string into a function that generates that 
string, allowing you to print out the finished product before 
mixing it in.


It's have a same result...


Automatic function body writing howto?

2017-08-16 Thread Oleg B via Digitalmars-d-learn
I want declare only signature of function and build body code by 
CTFE.


module mdl;
import std.stdio;
import std.traits;
import std.string;

enum autofnc;

@autofnc
{
int foo(int);
int bar(int);
}

void main()
{
writeln(foo(12));
}

mixin cfuncR;

mixin template cfuncR()
{
mixin impl!(getSymbolsByUDA!(mdl, autofnc));

mixin template impl(funcs...)
{
static if (funcs.length == 1)
{
mixin("pragma(msg, typeof(%1$s)); // !!! here I get 
_error_
			ReturnType!%1$s %1$s(Parameters!%1$s vals) { return vals[0] * 
2; }".format(__traits(identifier, funcs[0]));

}
else
{
mixin impl!(funcs[0..$/2]);
mixin impl!(funcs[$/2..$]);
}
}
}

I get this output:

/usr/include/dmd/phobos/std/traits.d-mixin-7671(7671): 
Deprecation: mdl.object is not visible from module traits
/usr/include/dmd/phobos/std/traits.d-mixin-7671(7671): 
Deprecation: mdl.std is not visible from module traits
mdl.d-mixin-29(30): Error: template instance 
std.traits.ReturnType!(foo) does not match template declaration 
ReturnType(func...) if (func.length == 1 && isCallable!func)
mdl.d-mixin-29(30): Error: template instance Parameters!foo does 
not match template declaration Parameters(func...) if 
(func.length == 1 && isCallable!func)

_error_
mdl.d(34): Error: mixin mdl.cfuncR!().impl!(foo, bar).impl!(foo) 
error instantiating
mdl.d-mixin-29(30): Error: template instance 
std.traits.ReturnType!(bar) does not match template declaration 
ReturnType(func...) if (func.length == 1 && isCallable!func)
mdl.d-mixin-29(30): Error: template instance Parameters!bar does 
not match template declaration Parameters(func...) if 
(func.length == 1 && isCallable!func)

_error_
mdl.d(35): Error: mixin mdl.cfuncR!().impl!(foo, bar).impl!(bar) 
error instantiating
mdl.d(23): Error: mixin mdl.cfuncR!().impl!(foo, bar) error 
instantiating

mdl.d(19): Error: mixin mdl.cfuncR!() error instantiating
Failed: ["dmd", "-v", "-o-", "mdl.d", "-I."]

I think 'template instance std.traits.ReturnType!(foo) does not 
match template declaration' because 'foo' is '_error_' on it's 
instancing moment. But I don't understand why 'foo' is '_error_'.


But if I replace '%1$s' in building function name to '_%1$s' 
pragma(msg, foo) works normal and compiler behavior is 
predictable (defined '_foo', but 'foo' has no body and can't 
linked):


/usr/include/dmd/phobos/std/traits.d-mixin-7671(7671): 
Deprecation: mdl.object is not visible from module traits
/usr/include/dmd/phobos/std/traits.d-mixin-7671(7671): 
Deprecation: mdl.std is not visible from module traits

int(int)
int(int)
/usr/include/dmd/phobos/std/traits.d-mixin-7671(7671): 
Deprecation: mdl.object is not visible from module traits
/usr/include/dmd/phobos/std/traits.d-mixin-7671(7671): 
Deprecation: mdl.std is not visible from module traits

int(int)
int(int)
/tmp/.rdmd-1000/rdmd-mdl.d-9F3ADBC813DCE463C0EFA2CA038B009E/objs/mdl.o: In 
function `_Dmain':
mdl.d:(.text._Dmain+0xa): undefined reference to `_D3mdl3fooFiZi'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

But if I wrote this code by hands:

ReturnType!foo foo(Parameters!foo vals) { return vals[0] * 2; }
ReturnType!bar bar(Parameters!bar vals) { return vals[0] * 2; }

all works fine!!

What am I doing wrong?

dmd 2.074
ldc 1.3.0 (main compiler, because can cross compile to arm)


Re: ushort calls byte overload

2017-05-30 Thread Oleg B via Digitalmars-d-learn

On Tuesday, 30 May 2017 at 21:42:03 UTC, Daniel Kozak wrote:

Compiler do many assumptions (it is sometimes useful).


but if compiler find one-to-one correspondence it don't make 
assumptions, like here?



import std.stdio;

void f(ushort u)
{
writeln("ushort");
}

void f(ubyte u)
{
writeln("ubyte");
}

void main()
{
ushort y = 0;
immutable ushort x = 0;

f(y);
f(x);
}

RESULT IS:
ushort
ushort


or it can?


Re: ushort calls byte overload

2017-05-30 Thread Oleg B via Digitalmars-d-learn

and this is unexpected for me too

immutable ushort y = 0;
foo(y); // byte


ushort calls byte overload

2017-05-30 Thread Oleg B via Digitalmars-d-learn

Hello. I have this code

import std.stdio;

void foo(byte a) { writeln(typeof(a).stringof); }
void foo(short a) { writeln(typeof(a).stringof); }
void foo(int a) { writeln(typeof(a).stringof); }

void main()
{
foo(0); // int, and byte if not define foo(int)
foo(ushort(0)); // byte (unexpected for me)
foo(cast(ushort)0); // byte (unexpected too)

foo(cast(short)0); // short
foo(short(0)); // short

ushort x = 0;
foo(x); // short
}

Is this a bug or I don't understand something?


Enums and immutables

2017-03-18 Thread Oleg B via Digitalmars-d-learn
Hello. I found strange behavior while casting enum array and 
immutable array.


import std.stdio;

void main()
{
enum arr = cast(ubyte[])[0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4];

auto arr1 = cast(void[])arr;
immutable arr2 = cast(immutable(void)[])arr;
enum arr3 = cast(void[])arr;

writeln(cast(ushort[])arr1); // [0, 256, 0, 512, 0, 768, 0, 
1024]
writeln(cast(ushort[])arr2); // [0, 256, 0, 512, 0, 768, 0, 
1024]
writeln(cast(ushort[])arr3); // [0, 0, 0, 1, 0, 0, 0, 2, 0, 
0, 0, 3, 0, 0, 0, 4]

}

I think it's related to representation of enums by compiler as 
#define.

It's right? It's behavior by design?


getSymbolsByUDA toSymbols error instantiating

2017-02-27 Thread Oleg B via Digitalmars-d-learn

Hello. I have this code:

```d
import std.traits;

enum myuda;

class A { @myuda int x; }

class B : A
{
@myuda int some;
void foo() { foreach (s; getSymbolsByUDA!(typeof(this), 
myuda)) {} }

}

void main() { (new B).foo(); }
```

And have this error:

```
% rdmd uda_symbols.d
/usr/include/dmd/phobos/std/traits.d-mixin-7250(7250): Error: 
template instance AliasSeq!(some, x) AliasSeq!(some, x) is nested 
in both B and A
/usr/include/dmd/phobos/std/traits.d(7259): Error: template 
instance std.traits.getSymbolsByUDA!(B, myuda).toSymbols!("some", 
"x") error instantiating
uda_symbols.d(10):instantiated from here: 
getSymbolsByUDA!(B, myuda)

```

If I understand correctly it's happens because code in std.traits 
can't choose between A.x and B.x, but I don't understand why. 
It's a bug or it's has a more complex base?


Package visibility strange behaviour

2017-02-27 Thread Oleg B via Digitalmars-d-learn
Hello. Is this behavior normal, or it's a bug? And if it's normal 
why it's normal? I want to use function with `package` visibility 
in same package where it's defined, but I don't.


```d
module package_visible;
package void foo() { }
void main() { foo(); }
```

```
% rdmd package_visible.d
package_visible.d(3): Error: function package_visible.foo is not 
accessible from module package_visible

Failed: ["dmd", "-v", "-o-", "package_visible.d", "-I."]
```

dmd version v2.073.1


Re: How to get the name for a Tid

2017-02-27 Thread Oleg B via Digitalmars-d-learn
On Wednesday, 23 November 2016 at 21:04:38 UTC, Christian Köstlin 
wrote:
std.concurrency contains the register function to associate a 
name with
a Tid. This is stored internally in an associative array 
namesByTid.
I see no accessors for this. Is there a way to get to the 
associated

names of a Tid?

Thanks,
Christian


I have a same problem and I use workaround with manualy register 
threads and my own list of threads names. I think it's a little 
mistake and can be changed in dmd updates in the near future.


Re: Cross-compile with LDC

2017-02-08 Thread Oleg B via Digitalmars-d-learn

On Wednesday, 8 February 2017 at 16:21:49 UTC, kinke wrote:

On Wednesday, 8 February 2017 at 14:57:41 UTC, Oleg B wrote:
Hello all! I want to build ldc cross compiller. I found this 
instruction  
https://wiki.dlang.org/LDC_cross-compilation_for_ARM_GNU/Linux, but I have some doubts: will it works with ldc-1.1.0? Particularly interested in the patch https://gist.githubusercontent.com/claudemr/3367c13095b15d449b1591eb38d098d9/raw/3517a5db2228e57da9dd8880a82d6bfe6f0e38f1/ldc_1.0.0_gnu_arm. It's for ldc-1.0.0 and sources can be changed.

Maybe somewhere I found patch for ldc-1.1.0?
Maybe someone already build cross ldc for linux x86_64?))


Hi Oleg,

first of all, we have an LDC forum/NG 
(http://forum.dlang.org/group/ldc) which would be more 
appropriate for your question. The referenced LDC patch is 
derived from https://github.com/ldc-developers/ldc/pull/1317, 
which hasn't been merged yet (but will be in not-too-distant 
future).
As you haven't explicitly specified what your target platform 
is, I can only assume that it's 32-bit ARM. With a vanilla LDC, 
cross-compiling to ARM with its double-precision reals will 
only work correctly if your LDC host compiler uses 
double-precision reals too, which isn't the case for Linux 
x86(_64), but for Windows. My LDC PR would make it work with a 
non-Windows x86(_64) host too, but only if the target (not the 
host) uses at most double-precision reals.


Thank you, in future I create new question about ldc in special 
forum. Yes, my target arch is ARMv7 (rpi2 and beaglebone) and 
ARMv8 (rpi3). If I understand correctly with vanilla LDC I can't 
cross-compiling from host linux-x86_64, but with your patch I 
can. Right? Maximum precision for ARMv7(8) is 64bit doubles, for 
x86_64 is 80bit reals. If I use your patch must I use in my 
programs only double or I can stay real in existing code?


Cross-compile with LDC

2017-02-08 Thread Oleg B via Digitalmars-d-learn
Hello all! I want to build ldc cross compiller. I found this 
instruction  
https://wiki.dlang.org/LDC_cross-compilation_for_ARM_GNU/Linux, 
but I have some doubts: will it works with ldc-1.1.0? 
Particularly interested in the patch 
https://gist.githubusercontent.com/claudemr/3367c13095b15d449b1591eb38d098d9/raw/3517a5db2228e57da9dd8880a82d6bfe6f0e38f1/ldc_1.0.0_gnu_arm. It's for ldc-1.0.0 and sources can be changed.

Maybe somewhere I found patch for ldc-1.1.0?
Maybe someone already build cross ldc for linux x86_64?))


new XML and JSON libs and replacement of std.net.curl

2016-08-15 Thread Oleg B via Digitalmars-d-learn

Hello.
In std.xml docs I read that is deprecated, and std.net.curl can 
be deprecated too (not remember here I read about std.net.curl). 
About std.json I read what it's has slow (de)serialization.


What I must use at this time?
vibe.data.json has evolution 
https://github.com/s-ludwig/std_data_json, but, if I correctly 
understood, they are not compatible and I can't use 
stdx.data.json in vibe.


For XML I found this project 
https://github.com/lodo1995/experimental.xml. Is this really 
candidate to std, or author just called it as he want?


As replacement of std.net.curl I found 
https://github.com/ikod/dlang-requests. Who know's about this 
lib? Is this good replacement of std.net.curl?


Maybe if I need json and http requests I must fully use vibe for 
these things? Vibe not resolve xml question =(

I want to use minimal count of dependencies...


const and mutable opApply's

2016-06-19 Thread Oleg B via Digitalmars-d-learn

Hello

struct WTable
{
...
private enum opApply_body = q{
if( smt )
{
foreach( f; 0 .. size-1 )
foreach( t; f+1 .. size )
if( auto r = dlg(f,t,data[getIndex(f,t)]) ) 
return r;

}
else
{
foreach( f; 0 .. size )
foreach( t; 0 .. size )
{
if( f == t ) continue;
if( auto r = dlg(f,t,data[getIndex(f,t)]) )
return r;
}
}
return 0;
};

int opApply( int delegate(size_t,size_t,T val) dlg ) const { 
mixin( opApply_body ); }
int opApply( int delegate(size_t,size_t,ref T val) dlg ) { 
mixin( opApply_body ); }

}

How I can rewrite this code without mixin's and with one (maybe 
inout) opApply?


rt_finalize question

2015-06-09 Thread Oleg B via Digitalmars-d-learn
Hello. In object.di rt_finalize calls for class objects in 
destroy func.
I not found it in dmd source on github and not found in druntime 
sources.
I think rt_finalize must call dtors for object and base classes, 
but I think that's not all. Or if it all has it code logic 
problems?


void myDestroy(T)( T obj ) if( is( T == class ) )
{
mixin( callDtor!( obj.stringof, 
TypeTuple!(T,BaseClassesTuple!T) ) );

}

string callDtor( string name, BCT... )() @property
{
import std.string;
static if( BCT.length == 1 ) return ; // Object has no dtor
else
return format( %s.%s.__dtor();\n, name, 
BCT[0].stringof.split(.)[$-1] ) ~

   callDtor!(name, BCT[1..$]);
}

function callDtor generate string like this

obj.C.__dtor();
obj.B.__dtor();
obj.A.__dtor();

for class model

class A{}
class B : A {}
class C : B {}

I want understand why destroy for class objects call extern(C) 
function rt_finalize (not pure, with gc, can except), and how it 
works (rt_finalize gets void*).


Re: rt_finalize question

2015-06-09 Thread Oleg B via Digitalmars-d-learn

I found it

https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L1350

Creates new questions.
Why it's extern(C)?
What must do collectHandler function?
If I understand correctly monitor relates to multithreading 
control (Mutex?).


Re: using D without GC

2015-06-08 Thread Oleg B via Digitalmars-d-learn

On Monday, 8 June 2015 at 13:37:40 UTC, Marc Schütz wrote:

On Monday, 8 June 2015 at 12:24:56 UTC, Oleg B wrote:

I guess you should follow andrei's post about new allocators!


Can you get link to this post?


These are some of his posts:

http://forum.dlang.org/thread/mku0n4$s35$1...@digitalmars.com
http://forum.dlang.org/thread/mkl1eh$1mdl$2...@digitalmars.com
http://forum.dlang.org/thread/mjig8h$2rgi$1...@digitalmars.com
http://forum.dlang.org/thread/mjdcep$11ri$1...@digitalmars.com
http://forum.dlang.org/thread/mj3p2j$2qva$1...@digitalmars.com
http://forum.dlang.org/thread/mir0lg$2l74$1...@digitalmars.com
http://forum.dlang.org/thread/min9k8$9r9$1...@digitalmars.com


Thank! Can you say how long wait (on average) to experimental 
modules will cease be an experimental and will be part of phobos? 
At next release or it unknown?


unclear compile error for struct with string template

2014-08-25 Thread Oleg B via Digitalmars-d-learn

[code]
void doSome(size_t N, T, string AS)( vec!(N,T,AS) v ) { }
struct vec(size_t N, T, string AS) { T[N] data; }
void main() { doSome( vec!(3,float,xyz)([1,2,3]) ); }
[/code]

compile with new dmd v2.066.0 and get error:

Error: template opbin.doSome(ulong N, T, string AS)(vec!(N, T, 
AS) v) specialization not allowed for deduced parameter AS


what does it mean?

on dmd v2.065 it worked well

code without string template parameter work well on dmd v2.066.0

[code]
void doSome(size_t N, T)( vec!(N,T) v ) { }
struct vec(size_t N, T) { T[N] data; }
void main() { doSome( vec!(3,float)([1,2,3]) ); }
[/code]


Re: unclear compile error for struct with string template

2014-08-25 Thread Oleg B via Digitalmars-d-learn

On Monday, 25 August 2014 at 11:41:28 UTC, bearophile wrote:

Oleg B:


[code]
void doSome(size_t N, T, string AS)( vec!(N,T,AS) v ) { }
struct vec(size_t N, T, string AS) { T[N] data; }
void main() { doSome( vec!(3,float,xyz)([1,2,3]) ); }
[/code]

compile with new dmd v2.066.0 and get error:

Error: template opbin.doSome(ulong N, T, string AS)(vec!(N, T, 
AS) v) specialization not allowed for deduced parameter AS


what does it mean?


See also:


struct Vec(size_t N, T, alias string AS) {
T[N] data;
}

void doSome(size_t N, T, alias string AS)(Vec!(N, T, AS) v) {}

void main() {
auto v = Vec!(3, float, xyz)([1, 2, 3]);
doSome(v);
}


(Note that in D the names of types and structs start with an 
upper case).


Bye,
bearophile


Does it mean that I need write alias for all arrays in template 
parameters or only strings?


Re: unclear compile error for struct with string template

2014-08-25 Thread Oleg B via Digitalmars-d-learn
and when I minimal fix my libs with this issue compiler fails 
without any output... =(


% gdb dmd
(gdb) run -unittest matrix.d vector.d
Starting program: /usr/bin/dmd -unittest matrix.d vector.d
[Thread debugging using libthread_db enabled]
Using host libthread_db library /lib64/libthread_db.so.1.
[New Thread 0x77ec9700 (LWP 29224)]
[Thread 0x77ec9700 (LWP 29224) exited]

Program received signal SIGSEGV, Segmentation fault.
0x0046c39a in ctfeInterpret(Expression*) ()
(gdb) bt
#0  0x0046c39a in ctfeInterpret(Expression*) ()
#1  0x00457012 in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long)::DeduceType::visit(TypeInstance*) ()
#2  0x0044e304 in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long) ()
#3  0x0045224f in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long)::DeduceType::visit(TypeStruct*) ()
#4  0x00455e80 in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long)::DeduceType::visit(Expression*) ()
#5  0x0044e32c in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long) ()
#6  0x00458251 in 
TemplateDeclaration::deduceFunctionTemplateMatch(TemplateInstance*, 
Scope*, FuncDeclaration*, Type*, ArrayExpression**) ()
#7  0x0045caf1 in functionResolve(Match*, Dsymbol*, Loc, 
Scope*, ArrayRootObject**, Type*, 
ArrayExpression**)::ParamDeduce::fp(void*, Dsymbol*) ()
#8  0x004dd577 in overloadApply(Dsymbol*, void*, int 
(*)(void*, Dsymbol*)) ()
#9  0x0045c401 in functionResolve(Match*, Dsymbol*, Loc, 
Scope*, ArrayRootObject**, Type*, ArrayExpression**) ()
#10 0x004e0343 in resolveFuncCall(Loc, Scope*, Dsymbol*, 
ArrayRootObject**, Type*, ArrayExpression**, int) ()

#11 0x004d9522 in CallExp::semantic(Scope*) ()
#12 0x004eef56 in ExpInitializer::inferType(Scope*) ()
#13 0x004b08ad in VarDeclaration::semantic(Scope*) ()
#14 0x004c1f7a in DeclarationExp::semantic(Scope*) ()
#15 0x0043cd3b in ExpStatement::semantic(Scope*) ()
#16 0x004479a6 in CompoundStatement::semantic(Scope*) ()
#17 0x004e5e2a in FuncDeclaration::semantic3(Scope*) ()
#18 0x00407b28 in Module::semantic3() ()
#19 0x004051bc in tryMain(unsigned long, char const**) ()
#20 0x00338be21b45 in __libc_start_main (main=0x406e60 
main, argc=4, ubp_av=0x7fffdc28, init=optimized out, 
fini=optimized out, rtld_fini=optimized out,

stack_end=0x7fffdc18) at libc-start.c:274
#21 0x00402739 in _start ()