Re: Windows segfault, need brief help

2019-07-12 Thread rikki cattermole via Digitalmars-d-learn

dmd v2.082 cannot reproduce

Needs to be tested on something newer perhaps?


Re: Windows segfault, need brief help

2019-07-12 Thread Stefan Koch via Digitalmars-d-learn

On Friday, 12 July 2019 at 22:46:11 UTC, Anonymouse wrote:
I'm suddenly getting segfaults when running tests on Windows. 
It works fine on Linux. I reduced it to a few lines (plus a 
dependency) with dustmite, but they don't really make sense[1]. 
Nevertheless they do trigger the segfault.


Can someone with Windows 10 and dmd 2.087.0 try the following 
and see if it crashes please?



[...]


If it ends with an assertion failure, okay, darn. If it "exited 
with code -1073741819" I'll have confirmed it happens for more 
than just me and AppVeyor, and thus can go ahead and file a bug 
report.



[...]


[1]: 
https://github.com/zorael/tests/blob/wintestcrash/source/app.dx


maybe you haven't pushed?
I can't see it.


Windows segfault, need brief help

2019-07-12 Thread Anonymouse via Digitalmars-d-learn
I'm suddenly getting segfaults when running tests on Windows. It 
works fine on Linux. I reduced it to a few lines (plus a 
dependency) with dustmite, but they don't really make sense[1]. 
Nevertheless they do trigger the segfault.


Can someone with Windows 10 and dmd 2.087.0 try the following and 
see if it crashes please?


git clone https://github.com/zorael/tests -b wintestcrash && cd 
tests && dub test


If it ends with an assertion failure, okay, darn. If it "exited 
with code -1073741819" I'll have confirmed it happens for more 
than just me and AppVeyor, and thus can go ahead and file a bug 
report.



Running custom 'unittest' configuration.
Performing "unittest" build using C:\D\dmd2\windows\bin\dmd.exe 
for x86_64.
cachetools 0.1.2: target for configuration "library" is up to 
date.

requests 1.0.9: target for configuration "std" is up to date.
test ~wintestcrash: building configuration "unittest"...
Linking...
To force a rebuild of up-to-date targets, run again with 
--force.

Running .\test.exe
Program exited with code -1073741819


[1]: 
https://github.com/zorael/tests/blob/wintestcrash/source/app.dx


Re: Blog Post #0052: MVC V - ComboBox with Integers

2019-07-12 Thread Ron Tarrant via Digitalmars-d-learn

On Friday, 12 July 2019 at 11:29:39 UTC, BoQsc wrote:

Gnome project should just rewrite everything in D language, 
especially the Gnome Shell. At least that would be a right 
direction.


LOL! It would likely take a planet-wide referendum, but I imagine 
you'll get strong support on this forum. :)


Thanks for the texts Ron, it is so nice to see images - 
visuals, showing the result and they fit so nicely with your 
article. The more visuals and working examples - the easier for 
some of us to understand. :)


Thanks for the kind words.


Re: Blog Post #0052: MVC V - ComboBox with Integers

2019-07-12 Thread BoQsc via Digitalmars-d-learn

On Friday, 12 July 2019 at 11:13:31 UTC, Ron Tarrant wrote:
Today's post deals with integers in a ComboBox. It's not 
exactly tricky, but a little clarification never hurts, right?


Here's where you'll find it: 
https://gtkdcoding.com/2019/07/12/0052-mvc-v-int-combobox.html


Gnome project should just rewrite everything in D language, 
especially the Gnome Shell. At least that would be a right 
direction.


Thanks for the texts Ron, it is so nice to see images - visuals, 
showing the result and they fit so nicely with your article. The 
more visuals and working examples - the easier for some of us to 
understand. :)


Blog Post #0052: MVC V - ComboBox with Integers

2019-07-12 Thread Ron Tarrant via Digitalmars-d-learn
Today's post deals with integers in a ComboBox. It's not exactly 
tricky, but a little clarification never hurts, right?


Here's where you'll find it: 
https://gtkdcoding.com/2019/07/12/0052-mvc-v-int-combobox.html


Re: Is there a way to slice non-array type in @safe?

2019-07-12 Thread Stefanos Baziotis via Digitalmars-d-learn

Thank you all for your responses. I understand that the compiler
can't ensure @safe and @trusted is needed.. I'm not familiar 
though with all aspects of D and thought I might have missed 
something.


On Friday, 12 July 2019 at 01:24:06 UTC, Jonathan M Davis wrote:
BTW, if you're implementing memcmp, why are you using byte 
instead of ubyte? byte is signed. Unless you're explicitly 
trying to do arithmetic on integral values from -127 to 127, 
odds are, you shouldn't be using byte. If you're doing 
something like breaking an integer into its 8-bit parts, then 
ubyte is what's appropriate, not byte.




I usually start with the signed version and if in the end there's 
no need for the
signed, I make it unsigned. In this case, at the moment there's 
no actual
need for `byte`. Actually, it only makes difficult to use some 
GDC intrinsics.




Re: Is it possible to execute a function inside .d script that has no main function?

2019-07-12 Thread BoQsc via Digitalmars-d-learn

On Thursday, 11 July 2019 at 10:41:38 UTC, Alex wrote:

On Thursday, 11 July 2019 at 09:43:55 UTC, BoQsc wrote:

Here I have a file named: module.d


[...]


There is no main() function since, I want to import this 
module, into another .d file.


( If I try to import and module.d does have main() function I 
get this error: )

[...]






I would like to launch function "interestingFunction()" 
directly using rdmd.

Is it possible to achieve that by any way?





I tried to launch the whole file, but it gave me some weird 
output:

[...]


If you are trying to test a function separately from other 
functions, e.g. for testing, then you are approaching unit 
testing.
You could write a unit test block just under the function to 
test like

unittest
{
  interestingFunction;
}

and launch it via rdmd... don't know the syntax right now. But 
here is something:

https://stackoverflow.com/questions/10694994/rdmd-is-not-running-unit-tests

So, I assume something like
rdmd -unittest --main module.d


Hmm, maybe I'll just rename module.d to module_library.d and 
place it in a folder,
then create a new module_run.d file that would launch the 
functions of module_library.d



module\module_library.d
module\module_run.d
README.md


Maybe even place a README.md file explaining how I come up with 
this idea.


And when in need of executing it, I'll just type:

rdmd module\module_run.d


Re: Is there a way to slice non-array type in @safe?

2019-07-12 Thread Patrick Schluter via Digitalmars-d-learn
On Thursday, 11 July 2019 at 19:35:50 UTC, Stefanos Baziotis 
wrote:

On Thursday, 11 July 2019 at 18:46:57 UTC, Paul Backus wrote:


Casting from one type of pointer to another and slicing a 
pointer are both @system, by design.


Yes, I'm aware, there are no pointers in the code. The pointer 
was used
here because it was the only way to solve the problem (but not 
in @safe).


What's the actual problem you're trying to solve? There may be 
a different way to do it that's @safe.


I want to make an array of bytes that has the bytes of the 
value passed.
For example, if T = int, then I want an array of 4 bytes that 
has the 4
individual bytes of `s1` let's say. For long, an array of 8 
bytes etc.
Ideally, that would work with `ref` (i.e. the bytes of where 
the ref points to).


imho this cannot be safe on 1st principle basis. You gain access 
to the machine representation of variable, which means you bypass 
the "control" the compiler has on its data. Alone the endianness 
issue is enough to have different behaviour of your program on 
different implementations. While in practice big endian is nearly 
an extinct species (, it is still enough to show why that 
operation is inherently @system and should not be considered 
@safe.
Of course, a @trusted function can be written to take care of 
that, but that's in fact exactly the case as it should be.


Re: Milliseconds

2019-07-12 Thread Giovanni Di Maria via Digitalmars-d-learn

On Friday, 12 July 2019 at 07:21:58 UTC, Jonathan M Davis wrote:
On Friday, July 12, 2019 12:51:28 AM MDT Giovanni Di Maria via 
Digitalmars- d-learn wrote:

[...]


You mean if the time is currently 15:46:52.7205007, you want an 
integer value that's 720?


[...]





Perfect Jonathan .
Thank you very very much!
Giovanni


Re: Milliseconds

2019-07-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 12, 2019 12:51:28 AM MDT Giovanni Di Maria via Digitalmars-
d-learn wrote:
> Hi
> I have read much, before to write here.
> How can i store, to an int variable, the milliseconds of the
> current time?
> It's simple, but i don't find the solution.
> Thank you very much.
>
> Giovanni Di Maria

You mean if the time is currently 15:46:52.7205007, you want an integer
value that's 720?

The way to get the current wall-clock time would be Clock.currTime in
std.datetime.systime (or you can just import the entire package if you
prefer). That returns a SysTime with the current time (and by default, it's
in the current time zone, though you can give it a different time zone if
you want). If you want to get the portion of the time that's less than a
second, that's in the fracSecs property. It returns a Duration (which is
from core.time). If you want the Duration in milliseconds, then you can use
its total property with the template argument "msecs". It does however
return a long, not an int, so if you want an int, then you'll need to cast
or use to!int (though the code would never return more than 999 or less than
-999 for milliseconds, so the extre checks in std.conv.to aren't
particularly useful in this case). So, the code would look something like

SysTime st = Clock.currTime();
Duration fracSecs = st.fracSecs;
immutable msecs = cast(int)fracSecs.total!"msecs";

or

immutable msecs = cast(int)Clock.currTime().fracSecs.total!"msecs";

https://dlang.org/phobos/std_datetime_systime.html#.Clock.currTime
https://dlang.org/phobos/std_datetime_systime.html#.SysTime
https://dlang.org/phobos/core_time.html#Duration
https://dlang.org/phobos/core_time.html#.Duration.total

It probably would have been easier to figure that out on your own
previously, but after I split the module up, the package and module-level
documentation talked like it was a single module and needed to be updated.
So, someone went and ripped most of it out on the theory that what was there
was worse than nothing, meaning that there's a distinct lack of module-level
documentation, and the package-level documentation is rather poor. I've been
meaning to go back and redo that top-level documenation and generally go
over the std.datetime documentation as a whole again, but I haven't gotten
around to it yet.

- Jonathan M Davis





Milliseconds

2019-07-12 Thread Giovanni Di Maria via Digitalmars-d-learn

Hi
I have read much, before to write here.
How can i store, to an int variable, the milliseconds of the 
current time?

It's simple, but i don't find the solution.
Thank you very much.

Giovanni Di Maria