Re: Exceptions on Windows being "swallowed"

2019-11-26 Thread Rainer Schuetze via Digitalmars-d-learn



On 27/11/2019 06:55, cartland wrote:
> On Wednesday, 27 November 2019 at 05:43:33 UTC, Mike Parker wrote:
>> On Wednesday, 27 November 2019 at 05:15:10 UTC, cartland wrote:
>> *snip*
>>
>> dmd -m32mscoff -debug -g x.d
>>
>> And see what happens.
> 
> No difference between "dmd -m32mscoff -debug -g x.d" and "dmd -m32mscoff
> x.d"
> 
> 
> C:\tmp\x>dmd -m32mscoff -debug -g x.d
> 
> C:\tmp\x>x
> hello
> 
> C:\tmp\x>dmd x.d
> 
> C:\tmp\x>x
> hello
> finally
> catch first
> done
> --
> 
> x.d contents
> 
> import std.stdio;
> void main() {
>     writeln("hello");
>     try {
>     try {
>     throw new Exception("first");
>     } finally{
>     writeln("finally");
>     throw new Exception("second");
>     }
>     } catch (Exception e) {
>     writeln("catch ", e.msg);
>     }
>     writeln("done");
> }
> ---
> 

In a debugger, I get:

Unhandled exception at 0x004010EF in x.exe: 0xC1A5: An invalid
exception handler routine has been detected (parameters: 0x0001).

This seems to happen when lld is used instead of the Microsoft linker.

Maybe related: https://bugs.llvm.org/show_bug.cgi?id=42221

Using lld from LLVM 9 spits out errors "not compatible with SEH", but
links using /SAFESEH:NO. The resulting executable then works.

I have created an issue: https://issues.dlang.org/show_bug.cgi?id=20421


Re: Exceptions on Windows being "swallowed"

2019-11-26 Thread cartland via Digitalmars-d-learn

On Wednesday, 27 November 2019 at 05:43:33 UTC, Mike Parker wrote:

On Wednesday, 27 November 2019 at 05:15:10 UTC, cartland wrote:
*snip*

dmd -m32mscoff -debug -g x.d

And see what happens.


No difference between "dmd -m32mscoff -debug -g x.d" and "dmd 
-m32mscoff x.d"



C:\tmp\x>dmd -m32mscoff -debug -g x.d

C:\tmp\x>x
hello

C:\tmp\x>dmd x.d

C:\tmp\x>x
hello
finally
catch first
done
--

x.d contents

import std.stdio;
void main() {
writeln("hello");
try {
try {
throw new Exception("first");
} finally{
writeln("finally");
throw new Exception("second");
}
} catch (Exception e) {
writeln("catch ", e.msg);
}
writeln("done");
}
---



Re: Exceptions on Windows being "swallowed"

2019-11-26 Thread Mike Parker via Digitalmars-d-learn

On Wednesday, 27 November 2019 at 05:15:10 UTC, cartland wrote:


No MS installed. Just using DMD.
-
dub -a x86_mscoff --force -v
:


So please try it without dub

dmd -m32mscoff x.d

If that works, add some debug flags like dub does:

dmd -m32mscoff -debug -g x.d

And see what happens.


Re: Exceptions on Windows being "swallowed"

2019-11-26 Thread cartland via Digitalmars-d-learn
This works (once I installed Microsoft Visual C++ 2010  x64 
Redistributable) :


dub --force -v

Seems the issue is with "x86_mscoff"

--
:
Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for 
x86_64.

x ~master: building configuration "application"...
C:\D\dmd2\windows\bin\dmd.exe -m64 -c 
-of.dub\build\application-debug-windows-x86_64-dmd_2089-1DF706DBEDBB125C8784D2CAFEE4D94A\x.obj -debug -g -w -version=Have_x -Isource source\app.d -vcolumns

Linking...
C:\D\dmd2\windows\bin\dmd.exe 
-of.dub\build\application-debug-windows-x86_64-dmd_2089-1DF706DBEDBB125C8784D2CAFEE4D94A\x.exe .dub\build\application-debug-windows-x86_64-dmd_2089-1DF706DBEDBB125C8784D2CAFEE4D94A\x.obj -m64 -g
Copying target from 
C:\tmp\x\.dub\build\application-debug-windows-x86_64-dmd_2089-1DF706DBEDBB125C8784D2CAFEE4D94A\x.exe to C:\tmp\x

Running .\x.exe
finally
catch %sfirst
done






Re: Exceptions on Windows being "swallowed"

2019-11-26 Thread cartland via Digitalmars-d-learn

On Wednesday, 27 November 2019 at 04:11:44 UTC, Mike Parker wrote:

On Wednesday, 27 November 2019 at 02:48:53 UTC, cartland wrote:
Trying out exception handling. When an exception occurs, 
program seems to just exit.


dub -a x86_mscoff



I compiled it with dmd and ran it directly from the command 
line and it worked fine:



hmmm!


Did you try that? And do you have the MS linker installed or 
are you using the lld that ships with DMD?


No MS installed. Just using DMD.
-
dub -a x86_mscoff --force -v
:
Generating using build
Configuring dependent x, deps:
Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for 
x86, x86_mscoff.

x ~master: building configuration "application"...
C:\D\dmd2\windows\bin\dmd.exe -m32mscoff -c 
-of.dub\build\application-debug-windows-x86.x86_mscoff-dmd_2089-6ACE9C396DEB2C31A239A4E275587962\x.obj -debug -g -w -version=Have_x -Isource source\app.d -vcolumns

Linking...
C:\D\dmd2\windows\bin\dmd.exe 
-of.dub\build\application-debug-windows-x86.x86_mscoff-dmd_2089-6ACE9C396DEB2C31A239A4E275587962\x.exe .dub\build\application-debug-windows-x86.x86_mscoff-dmd_2089-6ACE9C396DEB2C31A239A4E275587962\x.obj -m32mscoff -g
Copying target from 
C:\tmp\x\.dub\build\application-debug-windows-x86.x86_mscoff-dmd_2089-6ACE9C396DEB2C31A239A4E275587962\x.exe to C:\tmp\x

Running .\x.exe
Program exited with code -532414463




Two things regarding your code:



Thanks for the advice. It was just a quick cut and paste from the 
sample code to test.





Re: Exceptions on Windows being "swallowed"

2019-11-26 Thread Mike Parker via Digitalmars-d-learn

On Wednesday, 27 November 2019 at 02:48:53 UTC, cartland wrote:
Trying out exception handling. When an exception occurs, 
program seems to just exit.


dub -a x86_mscoff



I compiled it with dmd and ran it directly from the command line 
and it worked fine:


C:\dev\D\scratch>ex
finally
catch %sfirst
done

Did you try that? And do you have the MS linker installed or are 
you using the lld that ships with DMD?


Two things regarding your code:

writeln does no formatting. You want writefln for that. But with 
writeln, you can provide multiple string arguments and they will 
be concatenated into the final output, like this:


writeln("catch ", e.msg);

Also, you don't need the `int main` signature if you don't 
actually need the return value to signify anyting:


void main() { }}

is just fine.


Exceptions on Windows being "swallowed"

2019-11-26 Thread cartland via Digitalmars-d-learn
Trying out exception handling. When an exception occurs, program 
seems to just exit.


dub -a x86_mscoff

Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for 
x86, x86_mscoff.

x ~master: target for configuration "application" is up to date.
To force a rebuild of up-to-date targets, run again with --force.
Running .\x.exe
Program exited with code -532414463

---
//from https://dlang.org/spec/statement.html#try-statement
import std.stdio;
int main(){
try{
try   {
throw new Exception("first");
} finally  {
writeln("finally");
throw new Exception("second");
}
} catch (Exception e){
writeln("catch %s", e.msg);
}
writeln("done");
return 0;
}
---


Re: Simple casting?

2019-11-26 Thread Timon Gehr via Digitalmars-d-learn

On 26.11.19 23:08, Taylor R Hillegeist wrote:

On Tuesday, 26 November 2019 at 16:33:06 UTC, Timon Gehr wrote:

    int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;



how did you know to do that?



chunkBy with a binary predicate returns a range of ranges. So if I want 
an array of arrays I have to convert both the inner ranges and the outer 
range.


Re: Simple casting?

2019-11-26 Thread Taylor R Hillegeist via Digitalmars-d-learn

On Tuesday, 26 November 2019 at 23:29:12 UTC, Ali Çehreli wrote:
On 11/26/19 2:08 PM, Taylor R Hillegeist wrote:> On Tuesday, 26 
November 2019 at 16:33:06 UTC, Timon Gehr wrote:

>> int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;
>
>
> how did you know to do that?
std.array.array pulls all elemenst of a range and places them 
inside an array. That is eager but sometimes necessary work. 
For example, std.algorithm.sort cannot sort just any range 
because it needs the elements to be layed out as array elements:


  someAlgorithmRange.sort;  <-- Does not work
  someAlgorithmRange.array.sort <-- Works

Ali


I suppose I'm asking here how did he know to use:
.map!array.array

I in my mind I thought that
.array
would have been enough, it seems like it when looking at the 
original error:


GetAllTriplesExtractFileIrqSplit.d(83):

Error: cannot implicitly convert expression 
`chunkBy(irqSortedSet)` of type


`ChunkByImpl!(__lambda4, ProbePoint[3][])`  

Re: Simple casting?

2019-11-26 Thread Ali Çehreli via Digitalmars-d-learn
On 11/26/19 2:08 PM, Taylor R Hillegeist wrote:> On Tuesday, 26 November 
2019 at 16:33:06 UTC, Timon Gehr wrote:

>> int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;
>
>
> how did you know to do that?

Ranges don't have elements. They either generate elements according to 
an algorithm, provide access to elements (or copies of elements) that 
belong to other containers.


In this case, chunkBy() is like an engine that knows how to present the 
input range in chunks but does not start working automatically. This is 
a great feature because you can start accessing chunks, deciding it's 
enough, and stop; potentially avoiding a lot of eager work (potentially 
infinite).


std.array.array pulls all elemenst of a range and places them inside an 
array. That is eager but sometimes necessary work. For example, 
std.algorithm.sort cannot sort just any range because it needs the 
elements to be layed out as array elements:


  someAlgorithmRange.sort;  <-- Does not work
  someAlgorithmRange.array.sort <-- Works

Ali



Re: Simple casting?

2019-11-26 Thread Taylor R Hillegeist via Digitalmars-d-learn

On Tuesday, 26 November 2019 at 16:33:06 UTC, Timon Gehr wrote:

int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;



how did you know to do that?



Re: How to create DDoc for string mixin generated functions?

2019-11-26 Thread Adam D. Ruppe via Digitalmars-d-learn

On Tuesday, 26 November 2019 at 19:27:55 UTC, ParticlePeter wrote:
In may case I use the string mixin to forward outer struct 
property calls to members of an inner struct.


Did you try opDispatch btw? It might be simpler to implement and 
to document.



btw there might be a hacky solution to the stirng mixin thing i 
just haven't tried yet so im not sure


Re: How to create DDoc for string mixin generated functions?

2019-11-26 Thread ParticlePeter via Digitalmars-d-learn
On Tuesday, 26 November 2019 at 13:02:39 UTC, Jonathan M Davis 
wrote:
On Monday, November 25, 2019 9:25:08 AM MST ParticlePeter via 
...

- Jonathan M Davis


Thanks for that thorough explanation. In may case I use the 
string mixin to forward outer struct property calls to members of 
an inner struct. I'll try to refactor the string mixin as 
template mixin.
From top of my head I see one complication. The parameter name to 
the property would change and that means its name in the doc 
comment should change as well. Any ideas how to solve that? Or 
would it be possible only with same param name for all the 
property instantiations?





Re: Simple casting?

2019-11-26 Thread Timon Gehr via Digitalmars-d-learn

On 26.11.19 06:05, Taylor R Hillegeist wrote:

I'm attempting to do a segment group.

details:
alias ProbePoint[3]=triple;
triple[] irqSortedSet = UniqueTriples.keys
     .sort!("a[1].irqid < b[1].irqid",SwapStrategy.stable)
     .array;
83:triple[][] irqSortedSets = irqSortedSet.chunkBy!((a,b) => a[1].irqid 
== b[1].irqid);



GetAllTriplesExtractFileIrqSplit.d(83): Error: cannot implicitly convert 
expression `chunkBy(irqSortedSet)` of type `ChunkByImpl!(__lambda4, 
ProbePoint[3][])` to `ProbePoint[3][][]`


I have something that looks like a triple[][] but I can't seem to get 
that type out.
when I add .array it converts to a Group which doesn't make sense to me 
because I'm not using a unary comparison. Any thought?


import std;
void main(){
int[] x=[1,1,2,3,4,4];
int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;
writeln(y);
}


Re: Simple casting?

2019-11-26 Thread Taylor R Hillegeist via Digitalmars-d-learn

On Tuesday, 26 November 2019 at 06:45:19 UTC, Alex wrote:
On Tuesday, 26 November 2019 at 05:17:54 UTC, Taylor R 
Hillegeist wrote:

[...]


What exactly is the problem, as this works for me if I 
understood your goal correctly:


´´´
void main()
{
import std.algorithm.comparison : equal;
import std.array;
import std;
// Grouping by particular attribute of each element:
uint[3][] data = [
[1, 1,0],
[1, 2,0],
[2, 2,0],
[2, 3,0]
];

auto r1 = data.chunkBy!((a,b) => a[0] == b[0]);
}
´´´

If it is the type of the return value --> the return value of 
chunkBy has a different one compared to the input. Instead, you 
get an abstracted range whereas the input data serves as a 
source.


I like auto and all. But I wanted the return of the respective 
type. I can't figure out how to get the type uint[3][][]; that is 
the type my function takes but I can't figure out how to get it 
converted.


Re: How to create DDoc for string mixin generated functions?

2019-11-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 25, 2019 9:25:08 AM MST ParticlePeter via Digitalmars-d-
learn wrote:
> I am producing a bunch of functions/methods through string
> mixins. I also generated DDoc comments for those functions, in
> the hope that they would produce proper documentation, but they
> don't. So how can this be accomplished?

Right now, you don't. The ddoc and function signature have to be directly in
the source code for them to be seen for ddoc generation. The closest I'm
aware of to being able to do anything along the lines of mixing in
documentation is to use template mixins, and IIRC, you not only have to have
ddoc on the mixed in symbols, but you need to put at least an empty ddoc
comment on the statement that mixes in the template. e.g. std.exception has

/++
...
  +/
mixin template basicExceptionCtors()
{
/++
Params:
msg  = The message for the exception.
file = The file where the exception occurred.
line = The line number where the exception occurred.
next = The previous exception in the chain of exceptions, if 
any.
+/
this(string msg, string file = __FILE__, size_t line = __LINE__,
 Throwable next = null) @nogc @safe pure nothrow
{
super(msg, file, line, next);
}

/++
Params:
msg  = The message for the exception.
next = The previous exception in the chain of exceptions.
file = The file where the exception occurred.
line = The line number where the exception occurred.
+/
this(string msg, Throwable next, string file = __FILE__,
 size_t line = __LINE__) @nogc @safe pure nothrow
{
super(msg, file, line, next);
}
}

and to have those constructors show up in the documentation when mixed in,
you have to do something like:

/++
My exception class.
  +/
class MyException : Exception
{
///
mixin basicExceptionCtors;
}

Without the empty ddoc comment, the documentation on the mixed in symbols
does not show up, but either way, nothing like that can currently be done
with string mixins.

There's on open bug report / enhancement request somewhere on bugzilla to
fix it so that you can document string mixins, but unless someone has done
something to fix that very recently, no one has yet to implement a fix.

- Jonathan M Davis





Blog Post #91: Where's My Window?

2019-11-26 Thread Ron Tarrant via Digitalmars-d-learn
Today's post was inspired by a reader request, even though it 
wasn't specifically requested. It's about finding a Window's 
position and can be found here: 
https://gtkdcoding.com/2019/11/26/0091-window-stats-i-position.html


I'd also like to take this opportunity to announce that my 
posting schedule is changing. Starting today, and for the next 
while, posts will be made once per week. Other demands on my time 
during the holidays and for the foreseeable future has made this 
necessary. Thank you for your patience and understanding.


Re: static assert(version(x)) ?

2019-11-26 Thread Dennis via Digitalmars-d-learn
On Tuesday, 26 November 2019 at 10:24:00 UTC, Robert M. Münch 
wrote:
How can I write something like this to check if any of a set of 
specific versions is used?


```
version(a) {}
else version(b) {}
else version(c) {}
else {
   static assert(0, "only versions a, b and c are supported");
}
```

```
version(a) version = supported;
version(b) version = supported;
version(c) version = supported;
version(supported) {
// good to go
} else {
static assert(0, "not a supported version");
}
```


static assert(!(version(a) | version(b) | version(c)):


That seems to be the opposite of what you describe.
If you want that, then:
```
version(a) static assert(0, "version a not supported");
version(b) static assert(0, "version b not supported");
version(c) static assert(0, "version c not supported");
```



Re: static assert(version(x)) ?

2019-11-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, November 26, 2019 4:29:18 AM MST S.G via Digitalmars-d-learn 
wrote:
> On Tuesday, 26 November 2019 at 10:24:00 UTC, Robert M. Münch
>
> wrote:
> > How can I write something like this to check if any of a set of
> > specific versions is used?
> >
> > static assert(!(version(a) | version(b) | version(c)):
> >
> > The problem is that I can use version(a) like a test, and the
> > symbol a is not accessbile from assert (different,
> > non-accessible namespace).
>
> BTW D language designers are against boolean eval of version.
> It's not a technical restriction, it's just that they don't want
> this to work.

Basically, Walter considers it to be a prime source of bugs in C/C++ code.
druntime, Phobos, etc. consistently do stuff like

version(Posix)
{
}
else version(Windows)
{
}
else
static assert(false, "platform unsupported);

when it needs code to differ depending on platform or architecture or
whatever. And if that means duplicating some code in each version block,
then it means duplicating some code in each version block. static if can be
used instead of version blocks to get boolean conditions, and local version
identifiers can be defined which combine some set of version identifiers,
but such practices are discouraged for D programmers in general, and they're
basically forbidden in official source code. The only case I'm aware of
where anything like that is used in druntime or Phobos is for darwin stuff,
since darwin isn't a predefined identifier.

- Jonathan M Davis






Re: static assert(version(x)) ?

2019-11-26 Thread S.G via Digitalmars-d-learn
On Tuesday, 26 November 2019 at 10:24:00 UTC, Robert M. Münch 
wrote:
How can I write something like this to check if any of a set of 
specific versions is used?


static assert(!(version(a) | version(b) | version(c)):

The problem is that I can use version(a) like a test, and the 
symbol a is not accessbile from assert (different, 
non-accessible namespace).


BTW D language designers are against boolean eval of version.
It's not a technical restriction, it's just that they don't want 
this to work.


Re: static assert(version(x)) ?

2019-11-26 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 26 November 2019 at 10:24:00 UTC, Robert M. Münch 
wrote:
How can I write something like this to check if any of a set of 
specific versions is used?


static assert(!(version(a) | version(b) | version(c)):

The problem is that I can use version(a) like a test, and the 
symbol a is not accessbile from assert (different, 
non-accessible namespace).


version(A) { enum isA = true; } else { enum isA = false; }
version(B) { enum isB = true; } else { enum isB = false; }

static assert(!(isA || isB));


static assert(version(x)) ?

2019-11-26 Thread Robert M. Münch via Digitalmars-d-learn
How can I write something like this to check if any of a set of 
specific versions is used?


static assert(!(version(a) | version(b) | version(c)):

The problem is that I can use version(a) like a test, and the symbol a 
is not accessbile from assert (different, non-accessible namespace).


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster