Re: Profiling after exit()

2018-03-06 Thread Martin Nowak via Digitalmars-d-learn

On Thursday, 27 July 2017 at 15:16:35 UTC, Eugene Wissner wrote:

Are there profilers that work well with dmd? valgrind? OProfile?


Yes, any sampling profiler works fine, e.g. perf on linux, Intel 
VTune/AMD CodeXL on Windows.
Those directly monitor CPU performance counters and have a 
negligible performance overhead compared with dmd's instrumenting 
profiler, also they don't require rebuilding of binaries.


Re: I want to transmit the class name and the member name in the method

2018-01-15 Thread Martin Nowak via Digitalmars-d-learn

On Monday, 15 January 2018 at 15:28:19 UTC, Martin Nowak wrote:
More concise stuff is possible with heavy compile-time trickery 
(https://dpaste.dzfl.pl/cd375ac594cf) without incurring dreaded 
1+N queries or even any unnecessary SELECT fields.


foreach (u; db.select!User.where!"NOT can_overdraw")
{
sendMail(u.name, u.mail.addr, u.lendings // no 1+N here
.where!"DATEDIFF(NOW(), end_date) >= 7 AND book.amount 
< 20")

.map!(l => l.book.Reminder)); // client side range API
}

This has become even more of a challenge since we plan to make 
it a @safe @nogc poster child.


If anyone wants to help with this project please contact me.

At the moment reworked @safe @nogc database drivers would be 
most helpful.

I'll soon publish a small RC, Uniq, Weak library.
Unbuffered IO foundations are already here 
https://github.com/MartinNowak/io, but not yet practically 
proven, and still lacking vibe-core scheduler/eventcore 
integration.


If someone wants to see this happen, but doesn't have enough time 
to contribute,
you could help to crowdfund this work, so I could afford to spent 
more time working on this.


Get in contact with us for more details.
https://dlang.org/donate.html


Re: Does it have an http2 server/client lib like in golang?

2018-01-15 Thread Martin Nowak via Digitalmars-d-learn

On Monday, 15 January 2018 at 18:07:24 UTC, Cergoo wrote:

subj


WIP but a bit stalled.
https://github.com/vibe-d/vibe.d/tree/http2-botan-cleanup

Unless you really need server-push of assets, HTTP/2 on a reverse 
proxy gets you the same performance benefits as well.


Re: I want to transmit the class name and the member name in the method

2018-01-15 Thread Martin Nowak via Digitalmars-d-learn

On Friday, 5 January 2018 at 07:40:14 UTC, Brian wrote:

auto db = new ORM;
auto users = 
db.select(User).where(email.like("*@hotmail.com")).limit(10);


Expression templates are a dead-end for any non-trivial queries.
You have to embrace SQL to properly use RDMS, at the cost of 
beginners having to learn it.
There is no free lunch and the inefficient queries ppl. are 
running with Rails examplify what happens, when you pretend it's 
possible to use technology without understanding it.


I'm actively working towards a design that allows full 
compile-time typing with plain SQL commands. This will still take 
a while, but I hope we can see an alpha in 2018H1.

http://dconf.org/2016/talks/nowak.html

alias schema = AliasSeq!(User, MailAddress, Book, Lending);
DB!schema db = DB!schema(SQLite("local.db")); // connecting 
checks for missing/additional migrations
db = DB!schema(MySQL("localhost", 3306)); // DB wrapper is driver 
agnostic

// Full ANSI SQL
// driver-specific functions when picking the driver at compile 
time

// You can always exec dynamic queries on the underlying driver

foreach (r; db.exec!(q"SQL
SELECT u.name, m.addr, CONCAT(b.title, ';') books
FROM users u
JOIN mail_addresses m ON m.user_id = u.id AND NOT 
u.can_overdraw
JOIN lendings l ON l.user_id = u.id AND DATEDIFF(NOW(), 
l.end_date) >= 7

JOIN books b ON b.lending_id = l.id
WHERE b.amount < 20
GROUP BY u.id
SQL
)
sendMail(r.name, r.addr, r.books.splitter(';'));

More concise stuff is possible with heavy compile-time trickery 
(https://dpaste.dzfl.pl/cd375ac594cf) without incurring dreaded 
1+N queries or even any unnecessary SELECT fields.


foreach (u; db.select!User.where!"NOT can_overdraw")
{
sendMail(u.name, u.mail.addr, u.lendings // no 1+N here
.where!"DATEDIFF(NOW(), end_date) >= 7 AND book.amount < 
20")

.map!(l => l.book.Reminder)); // client side range API
}

This has become even more of a challenge since we plan to make it 
a @safe @nogc poster child.


If anyone wants to help with this project please contact me.

At the moment reworked @safe @nogc database drivers would be most 
helpful.

I'll soon publish a small RC, Uniq, Weak library.
Unbuffered IO foundations are already here 
https://github.com/MartinNowak/io, but not yet practically 
proven, and still lacking vibe-core scheduler/eventcore 
integration.


Re: Skynet 1M Fiber microbenchmark in D

2017-10-20 Thread Martin Nowak via Digitalmars-d-learn

On Wednesday, 18 October 2017 at 12:32:31 UTC, Nordlöw wrote:
Further, are we forced to use the GC for Fiber allocation or 
can a sub-class of Fibers implement its own allocation strategy?


You could use std.typecons.scoped!Fiber, though it'll easily 
overflow your stack.

Unfortunately Scoped doesn't seem to work with refCounted atm.


Re: Skynet 1M Fiber microbenchmark in D

2017-10-20 Thread Martin Nowak via Digitalmars-d-learn

On Wednesday, 18 October 2017 at 11:01:56 UTC, Per Nordlöw wrote:
On Wednesday, 18 October 2017 at 09:01:30 UTC, Per Nordlöw 
wrote:
Creates an actor (goroutine, whatever), which spawns 10 new 
actors, each of them spawns 10 more actors, etc. until one 
million actors are created on the final level. Then, each of 
them returns back its ordinal number (from 0 to 99), which 
are summed on the previous level and sent back upstream, until 
reaching the root actor. (The answer should be 4950).


See also: https://github.com/atemerev/skynet


I Fibers aren't supposed to take any parameters how are we 
supposed to pass values to it during creation?


Someone should really implement sth. along this line.

```d
  size_t cumsum(Fiber!int fib, size_t val)
  {
size_t sum = val;
foreach (i; 0 .. 10)
{
val = fib.yield(sum); // yield sum, get next val
sum += val;
}
return sum;
  }
  auto fib = fiber!func;
  while (fib.state != Fiber.State.hold)
  writeln(fib.call(random()));
```

There is 
https://dlang.org/library/std/concurrency/generator.this.html, 
but it's not too well designed, relying on an runtime type cast 
in Fiber.yield which will fail if the yielded value isn't exactly 
of the same specified as template parameter.

https://github.com/dlang/phobos/pull/1910#r16965194


Re: About Dub capabilities

2017-07-04 Thread Martin Nowak via Digitalmars-d-learn

On Tuesday, 4 July 2017 at 20:46:33 UTC, Dukc wrote:
Not that I have any need for that right now, I am just 
interested.


preGenerate-/preBuildCommands are your friends to compile C++ 
code using dub.
You'd invoke make or sth. and add the generated libs/objects to 
dub's sourceFiles.

http://code.dlang.org/package-format?lang=json#build-settings

Dub can also generate scripts for other build systems (among them 
cmake), in case that seems more suitable for your needs.


Re: Auto recursive function

2017-01-11 Thread Martin Nowak via Digitalmars-d-learn

On Wednesday, 11 January 2017 at 19:39:17 UTC, Ali Çehreli wrote:
return choose(lengths.length == 1, one!T(alloc, 
lengths[0]), two!T(alloc, lengths));


Well, choose is the right tool when the choice can only be made 
at runtime. That would be uncommon for dimensionality.


Anyhow mentioning ndslice for multi-dim seems like the sanest tip 
here.

https://github.com/libmir/mir


Re: Auto recursive function

2017-01-11 Thread Martin Nowak via Digitalmars-d-learn

On Wednesday, 11 January 2017 at 19:23:10 UTC, Razvan Nitu wrote:
auto makeMultidimensionalArray(T, Allocator)(auto ref Allocator 
alloc, size_t[] lengths)

{
if (lengths.length == 1)


Looks like `static if` would fix your specific problem.



Re: Cannot link with libphobos2.a with GCC 6.2 on Ubuntu 16.10

2016-10-24 Thread Martin Nowak via Digitalmars-d-learn

On Monday, 17 October 2016 at 11:55:03 UTC, Martin Nowak wrote:

Please update the bug report.
https://issues.dlang.org/show_bug.cgi?id=5278


Updated, but do I seriously have to do everything? I'm not even 
an Ubuntu user.




Re: Cannot link with libphobos2.a with GCC 6.2 on Ubuntu 16.10

2016-10-17 Thread Martin Nowak via Digitalmars-d-learn
On Thursday, 13 October 2016 at 18:35:43 UTC, Matthias Klumpp 
wrote:
The new toolchains of Ubuntu (and Debian soon too) default to 
PIE code, so in order to link correctly, the project needs to 
be compiled with PIE/PIC to work.


Please update the bug report.
https://issues.dlang.org/show_bug.cgi?id=5278


Re: How to debug (potential) GC bugs?

2016-10-07 Thread Martin Nowak via Digitalmars-d-learn
On Saturday, 1 October 2016 at 00:06:05 UTC, Matthias Klumpp 
wrote:

So, this problem is:
 A) A compiler / DRuntime bug, or
 B) A bug in my code (not) triggered by a certain compiler / 
DRuntime


We actually did change druntime recently to no longer fail when 
using GC.free from a finalizer (will get ignored now). Maybe 
that's what fixed it for you w/ a newer version, but at a quick 
glance I haven't seen any freeing code in destructors.


Re: How to debug (potential) GC bugs?

2016-10-07 Thread Martin Nowak via Digitalmars-d-learn

On Tuesday, 4 October 2016 at 08:14:37 UTC, Ilya Yaroshenko wrote:
Probably related issue: 
https://issues.dlang.org/show_bug.cgi?id=15939


Crashes in a finalizer, likely not related to the dead-lock bug.



Re: What exactly does the compiler switch -betterC do?

2016-10-06 Thread Martin Nowak via Digitalmars-d-learn

On Wednesday, 5 October 2016 at 12:42:14 UTC
On Wednesday, 5 October 2016 at 12:42:14 UTC, Jacob Carlborg 
wrote:

No. There's a difference between DMD 2.070.0 and 2.071.0:


OK, I'll retry on OSX, the bug report said Linux though. Seems 
like we're dragging in all of the _Dmain stuff. IIRC _Dmain is 
marked as weak in some extra C file, but the problem might be 
unrelated to that.

https://issues.dlang.org/show_bug.cgi?id=16547


Re: What exactly does the compiler switch -betterC do?

2016-10-05 Thread Martin Nowak via Digitalmars-d-learn
On Monday, 19 September 2016 at 21:09:39 UTC, Gary Willoughby 
wrote:

On Monday, 20 June 2016 at 06:35:32 UTC, Jacob Carlborg wrote:

On 2016-06-19 21:53, Gary Willoughby wrote:
If compiled with -betterC, it contains these:

 T _main
 U _printf


I get significantly more symbols than that when compiling the 
following program any idea why?


Because you're linking with druntime/phobos which drags in plenty 
of symbols (including a GC). Also Jakob is showing the symbols of 
the object file, not executable.


Re: Member not accessible in delegate body

2016-09-23 Thread Martin Nowak via Digitalmars-d-learn

On Friday, 23 September 2016 at 07:54:15 UTC, John C wrote:
If I try to call the protected method of a superclass from 
inside the body of a delegate, the compiler won't allow it.


void layoutTransaction(Control c, void delegate() action) {
  // do stuff
  action();
  // do more stuff
}

class Control {
  protected void onTextChanged() {}
}

class Label : Control {
  protected override void onTextChanged() {
layoutTransaction(this, {
  super.onTextChanged(); // <--- Error here
  changeSize();
});
  }
  private void changeSize() {}
}

Output: class Control member onTextChanged is not accessible.

How is it possible that "onTextChanged" isn't accessible but 
the private method "changeSize" *is*?


Please file a bug report issues.dlang.org, shouldn't be difficult 
to fix.


Re: Hooking into GC

2016-06-29 Thread Martin Nowak via Digitalmars-d-learn

On Thursday, 30 June 2016 at 03:03:16 UTC, MMJones wrote:
I need to get more info than just the memory usage. Like what 
is using the memory.


That's what -profile-gc is for, it tracks allocations.
Give it a try, IIIRC it's missing explicit GC.malloc calls atm., 
but those should be rare anyhow and could be added.

http://dlang.org/changelog/2.068.0.html#profile-gc


Re: Hooking into GC

2016-06-29 Thread Martin Nowak via Digitalmars-d-learn

On Wednesday, 29 June 2016 at 02:18:27 UTC, MMJones wrote:
I read somewhere that one can modify the D files from phobos 
and runtime to supply a stub for the GC. I would like to add 
some logging features to the GC.


Does this not require one to recompile phobos? I figured the 
source code was just for debugging?


I'm curious if I can really get away with modifying the source 
code in dmd2's dir and it will actually work. I guess I could 
try but I don't wanna go mess with it if it's not going to do 
anything.


Going to be released with 2.072.0
https://github.com/dlang/druntime/pull/1581


Re: Is there a smart way to process a range of range by front ?

2015-09-23 Thread Martin Nowak via Digitalmars-d-learn

On Wednesday, 23 September 2015 at 21:30:37 UTC, BBasile wrote:

auto interleave(RoR)(RoR r)
{
return r.transposed.join;


If you use joiner it will even be lazy and avoid the allocation.


Re: Trying to compile weather program

2015-08-25 Thread Martin Nowak via Digitalmars-d-learn

On Sunday, 23 August 2015 at 09:54:37 UTC, Tony wrote:

auto loc = getJSON(ipinfo.io/)[loc]
.str.split(,);


BTW, the IP location doesn't work too reliably, if someone knows 
a better alternative...


Re: Trying to compile weather program

2015-08-25 Thread Martin Nowak via Digitalmars-d-learn

On Tuesday, 25 August 2015 at 05:27:16 UTC, Tony wrote:

I happened to notice that among my libcurl*s

libcurl-gnutls.so.3
libcurl-gnutls.so.4
libcurl-gnutls.so.4.3.0
libcurl.so.3
libcurl.so.4
libcurl.so.4.3.0

none were just libcurl.so. So I made a link for libcurl.so to 
the latest version and now I am getting the same link errors I 
got after downloading the -dev version. So apparently my can't 
find -lcurl was because I didn't have a non-versioned 
libcurl.so available as it went away when I created one


Yes, it's not particularly trivial to use libcurl currently, but 
thankfully all the libcurl complications will be gone in about 6 
weeks with 2.069.0.

https://github.com/D-Programming-Language/phobos/pull/3009


(and there was probably one created by the -dev download).


Yes, the -dev packages come with unversioned symlinks and a 
pkg-config file (try `pkg-config --libs libcurl`).


Re: Problem with dmd 2.068 Win 32

2015-08-11 Thread Martin Nowak via Digitalmars-d-learn

On Tuesday, 11 August 2015 at 15:04:29 UTC, MGW wrote:

Hi!

My project has an error link:

Error 42: Symbol Undefined 
_D6object9Exception6__ctorMFNaNbNfAyaAyakC6object9ThrowableZC9Exception


On dmd 2.067.* everything gathered without mistakes. Where to 
look for a mistake?


Try ddemangle (part of the distribution).

ddemangle
_D6object9Exception6__ctorMFNaNbNfAyaAyakC6object9ThrowableZC9Exception

-

pure nothrow @safe Exception 
object.Exception.__ctor(immutable(char)[], immutable(char)[], 
uint, object.Throwable)


In the current release @nogc was added.
https://github.com/D-Programming-Language/druntime/blob/v2.068.0/src/object.d#L1614

You either have a wrong import paths (check which dmd.conf is 
used with 'dmd -v non_existent') or a stable object_.di file.


Re: Subclasses in std.concurrency.receive pattern match

2015-07-31 Thread Martin Nowak via Digitalmars-d-learn

On Friday, 31 July 2015 at 07:35:47 UTC, Marek Janukowicz wrote:
So patten matching only works on type of containing variable, 
not the type of the object itself. Is it possible to work 
around this?


No, it would be very surprising if receive performed a dynamic 
downcast, and it's also somewhat expensive.

If you want that, do the downcast in your handler yourself.

Won't the object get possibly GC'ed when it runs out of scope 
in origin thread while handler thread still uses it?


No, the GC pauses and scans all threads for roots.




Re: static linking

2015-07-26 Thread Martin Nowak via Digitalmars-d-learn
On 07/26/2015 05:19 PM, Laeeth Isharc wrote:
 The former is trickier on arch in particular (not related to Dicebot's
 choice) because they don't distributed static versions of library files
 as a matter of policy.

Yes, quite a few distributions no longer support fully static linking.
Some, e.g. hardened gentoo, don't allow it for security reasons (they
use ASLR on PIE).



Re: static linking

2015-07-26 Thread Martin Nowak via Digitalmars-d-learn
On 07/26/2015 05:19 PM, Laeeth Isharc wrote:
 
 How do I do the same on gdc and ldc ?  Since running times may be a
 matter of seconds, speed and startup time counts especially for lambda. 
 Probably starting via nodejs is an unnecessary tax, but I guess they
 will get rid of that requirement in time.

AFAIK only ldc supports a dynamic phobos library ATM, and it shouldn't
be default. But in both cases -L-l:libphobos2.a should do the job,
though I think it's called libgphobos2.a for gdc and libphobos2-ldc.a
for ldc.


Re: GC stats

2015-07-26 Thread Martin Nowak via Digitalmars-d-learn
On 07/26/2015 04:16 PM, Gary Willoughby wrote:
 
 I thought there is a recently added compiler option that profiles the GC
 and creates a report now?

That's an allocation profiler, the other one mentioned by me reports GC
stats as requested by the OP.


Re: static linking

2015-07-25 Thread Martin Nowak via Digitalmars-d-learn

On Saturday, 25 July 2015 at 18:02:48 UTC, Laeeth Isharc wrote:
I am trying to compile a D binary to run on AWS lambda.  If I 
cannot link statically, which files should I include in the zip 
upload - libphobos2.so, libdruntime-linux64so.o ?


I think dicebot who maitains the arch linux package change dmd to 
dynamically link with phobos by default (we don't yet do that on 
any other platform).
You should be able to link statically using -L-l:libphobos2.a or 
-defaultlib=libphobos2.a.


Re: GC stats

2015-07-25 Thread Martin Nowak via Digitalmars-d-learn

On Saturday, 25 July 2015 at 17:34:26 UTC, Márcio Martins wrote:
What I want is a clean non-intrusive way to log when a 
collection happened, how long my threads were stopped, how much 
total memory and how many blocks were recovered. i.e. how much 
garbage was created in between collections. Are there any hooks 
on the runtime?


http://dlang.org/changelog.html#gc-options
https://github.com/D-Programming-Language/druntime/blob/1e25749cd01ad08dc08319a3853fbe86356c3e62/src/rt/config.d#L14


Re: DUB Build Linker Library Search Path

2015-07-10 Thread Martin Nowak via Digitalmars-d-learn

On Friday, 10 July 2015 at 09:27:19 UTC, Nordlöw wrote:
How do I tell `dub build` where to find libraries in 
non-standard directories?


You're missing the development package libclang-dev, which should 
come with a pkg-config.


Re: Is it safe to reset HOLD fiber?

2015-05-03 Thread Martin Nowak via Digitalmars-d-learn

On Sunday, 3 May 2015 at 12:42:23 UTC, Dzugaru wrote:
Just did another test and it seems its not safe at all. Reusing 
the fibers with reset without properly exiting the function 
leads to eventual stack overflow.


It won't cleanup the old stack, so it may leak resources. It will 
properly reset the stack though, so the fiber should behave like 
a new one.


Re: Is it safe to reset HOLD fiber?

2015-05-03 Thread Martin Nowak via Digitalmars-d-learn

On Sunday, 3 May 2015 at 12:33:36 UTC, Dzugaru wrote:
Documentation says This fiber must be in state TERM. but in 
the core.thread I see In contract only on reset without 
parameters (bug maybe?) and with HOLD condition too:

assert( m_state == State.TERM || m_state == State.HOLD );

Does that mean its ok to reset the fiber if I'm not using 
things like scope(exit)? I don't like adding 
if(fibIsDestroyed) return; snippet after each Fiber.delay() - 
its error-prone.


Actually the documentation answers your question, please help to 
improve it if you don't find it clear enough.

http://dlang.org/phobos/core_thread.html#.Fiber.reset


Re: Ada to D - an array for storing values of each of the six bits which are sufficient

2015-05-03 Thread Martin Nowak via Digitalmars-d-learn

On Friday, 1 May 2015 at 23:22:31 UTC, Dennis Ritchie wrote:
Maybe someone will show a primitive packed array. I really can 
not imagine how to do it on D.


Look at BitArray for an example 
https://github.com/D-Programming-Language/phobos/blob/12187d7be8b15b2f5f8ff6889cdb5ea3afb93dd1/std/bitmanip.d#L702.


Here is an implementation in C++ that could be easily adopted.
http://pempek.net/articles/2013/08/03/bit-packing-with-packedarray/


Re: Startup files for STM32F4xx

2015-04-25 Thread Martin Nowak via Digitalmars-d-learn

On Saturday, 25 April 2015 at 07:04:58 UTC, Jens Bauer wrote:
Things that can be recycled would be carefully written drivers, 
such as LCD drivers that uses the SPI protocol. The SPI 
interface itself cannot be recycled, though, as each device has 
different SPI hardware and different GPIO hardware.


You can very well abstract an SPI, just need to have an 
abstraction for pins.


http://developer.mbed.org/handbook/SPI


Re: Startup files for STM32F4xx

2015-04-25 Thread Martin Nowak via Digitalmars-d-learn

On Saturday, 25 April 2015 at 05:07:04 UTC, Jens Bauer wrote:
I hope to find a good way to use import for microcontroller 
libraries, so it'll be easy for everyone. I'm thinking about 
something like ...


import mcu.stm32f439.all


I think that belongs in the makefile/dub.json as 
-version=STM32F439.

Then you could simply import mcu.gpio or mcu.spi.


Re: Startup files for STM32F4xx

2015-04-25 Thread Martin Nowak via Digitalmars-d-learn

On Saturday, 25 April 2015 at 05:07:04 UTC, Jens Bauer wrote:
While I remember it ... I had to nullify a number of imports in 
stdint. They simply do not belong in there. :)
Eg. I do not want FILE* if I aks for stdint. But FILE* is 
forced upon me, because wchar_t includes it. What does a 
wchar_t need a file-system for ?


You better dismiss the idea of using druntime/phobos. They are 
not optimized for code size and contain a lot of stuff that'll 
never work.
You can replace the core.stdc headers with bindings for nanolib, 
but again it's not necessary for doing useful stuff and should be 
done later.


Re: Startup files for STM32F4xx

2015-04-25 Thread Martin Nowak via Digitalmars-d-learn

On Saturday, 25 April 2015 at 07:31:45 UTC, Jens Bauer wrote:

I wonder if you can get e.g. interfaces and classes working.


I hope I will. ;)
I think classes are really a must. The only thing that I 
(currently) see that could perhaps block this from working, 
would be missing support for static constructors and a missing 
memory allocator.


Static constructors are possible if you strip down ModuleInfo 
(requires compiler hacking).
You should care about that stuff last. It's way more important to 
make things work without dynamic memory allocation first. You can 
still malloc+emplace classes later.


That means 'new' and 'delete' / 'malloc' and 'free' must be 
able to handle multiple RAM locations (because there's also 
external SRAM and external SDRAM).


IIRC then the C/C++ malloc would simply can your sbrk 
implementation, so it only supports a single heap, which should 
be the external if available.


Re: Startup files for STM32F4xx

2015-04-24 Thread Martin Nowak via Digitalmars-d-learn

On Saturday, 25 April 2015 at 01:32:16 UTC, Jens Bauer wrote:
This is most likely where the egg cracks open. i'm pretty sure 
we willl see people migrating to using D (at first a mixture 
between D and C, because of the libraries from the vendors), 
but later, there'll surely be projects which are pure D. -After 
all, it's not difficult to convert a library file from C to D. 
:)


The STM peripheral library really sux, verbose boilerplate for 
the simplest stuff and no type safety for the enums (find the 
difference of GPIO_PIN4 and GPIO_PinSource4 via debugging).
It's also really hard to setup all the startup files, linker 
scripts and debugger configs.


In constrast we could provide a really amazing D experience on 
those platforms.


Re: Structural exhaustive matching

2015-04-21 Thread Martin Nowak via Digitalmars-d-learn

On Tuesday, 21 April 2015 at 15:36:28 UTC, Jadbox wrote:
What's the best equivalent to Rust's structural enum/pattern 
(match)ing? Is it also possible to enforce exhaustive matches? 
Basically, I'm curious on what the best way to do ADTs in D.


If it needs to be really fast, use final switch on the tag of a 
discriminated union.


enum Tag { A, B, C }
struct Val
{
  Tag tag;
  union
  {
A a;
B b;
C c;
  }
}

void too(Val val)
{
  final switch (val.tag)
  {
  case Tag.A: writeln(val.a); break;
  case Tag.B: writeln(val.b); break;
  case Tag.C: writeln(val.c); break;
  }
}


Re: Valgrind

2015-04-20 Thread Martin Nowak via Digitalmars-d-learn

On Monday, 20 April 2015 at 13:28:57 UTC, John Colvin wrote:
The only special thing to take in to account is that valgrind 
will choke on DMD generated floating point code


I actually fixed this problem a while ago.
https://github.com/D-Programming-Language/dmd/pull/4368

An actual problem with valgrind is the GC, because most of it's 
operations appear to valgrind as memory corruptions.
You can GC.disable() collections, use gcstub.d, or help Vladimir 
with his valgrind/GC support to make things work.


http://dlang.org/phobos/core_memory.html#.GC.disable
https://github.com/D-Programming-Language/druntime/blob/master/src/gcstub/gc.d
https://github.com/CyberShadow/druntime/commits/valgrind


Re: Adding pointers to GC with destructers

2015-04-20 Thread Martin Nowak via Digitalmars-d-learn

On Sunday, 19 April 2015 at 23:38:49 UTC, Freddy wrote:

C libraries have a pattern of

HiddenType* getObj();
void freeObj(HiddenType*);

Is there any way I can make the GC search for a HiddenType* 
and run freeObj when the pointer is not found.


You can't turn an arbitrary pointer into a garbage collected 
object.

What you can do, is putting the pointer into a GCed object.

class Wrapper {
  this(HiddenType* p) { _p = p; } }
  ~this() { freeObj(_p); }
  alias _p this;
}

auto obj = new Wrapper(getObj());

Since 2.067.0 we also finalize heap allocated structs, so the 
wrapper can also be a struct.


Re: GC deadlocks on linux

2015-02-27 Thread Martin Nowak via Digitalmars-d-learn
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 02/18/2015 09:27 PM, Byron Heads wrote:
 I have a medium size daemon application that uses several threads,
 libasync, and daemonize.  On windows it runs correctly with GC
 enabled, but on linux the GC causes a deadlock while allocating
 memory.

Have you been able to resolve the issue?
There were a number of suggestions in the thread, but we never heard
back from you.
Meanwhile the author of daemonized came up with another idea, using
exec instead of fork.
https://github.com/NCrashed/daemonize/issues/2
-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iQIcBAEBAgAGBQJU8U14AAoJELJzgRYSuxk5wnEP/R6nFZECdFsNSFK/Bmsys5WI
RmYt8FyS5WJt/2tM/jKgN6k5WJLP+ZniSHPTMdWO4pGxJTaK6zGvMXVYEHPFgIDp
RPcJhZ/J1KXyfOyR3by/23opvGaWqAJXIx3yBfYBhvjNNpjQrGxqQEwdT4sbDvz1
AtUZ+Tc1CoBo+3hRNESyk9FNa3c58adu5SWkpErJezrg4TFzYg7sKytbZEtb5T6U
OWLVlMqY8Q6AyskbEUqxfQt8lba9fM5Eeg8gbzf7ShCZwrzviBkrhdTWrodv8kHo
HeMZmRIBKmz/L0Ce/7NSV+U0htEB+DAB2LSYRKhy/qYwoLHi8UNruqv3pf4PU7Ly
4atq5XTcFNS/ywL8qkP8OMmcdBN0pBQNsDfmG2w1DsWANtK/cLqwS50O8TXCxpv1
hlQ/CgRD6jJWujleaDOhuOZWYzJ0Xwk1a5BGjoO5MkQaHeRZgalSN4rkmoPZQz1t
H2kA03JMTVkEx2AllPKHdQCcNEV0wpI7sJNRWh9kewtdzW0SQtlV2NYM9U2gXPJe
u+zYuWRLGpWOrqItzZGt+Z+NSrNziV0cO/IpogQRjMPtLXsRgaFofzaOO81l7OWk
SWnE3bT2PO2sdZ0Z3uf/c+KAosDJ+5AhD9FXmuEemIc4S4/1yKJSVj7BtsomBxE+
hGfLvRuNjUDQil+WjC0t
=MNgH
-END PGP SIGNATURE-


Re: curl password issue

2015-02-23 Thread Martin Nowak via Digitalmars-d-learn

On Monday, 23 February 2015 at 16:10:42 UTC, Andre wrote:

Curl has some issues with passwords containing special 
characters

like the hash key (#).


I don't found any reference for this issue in curl and the D 
wrapper hardly adds anything. You're sure it isn't an issue with 
your program or how you pass the password?


Re: Is this a bug in dmd 2.067 for struct initializers?

2015-02-22 Thread Martin Nowak via Digitalmars-d-learn

On Thursday, 19 February 2015 at 22:07:55 UTC, stewarth wrote:

I've gone with static this() approach and it works.


You should use shared static this to initialize immutable 
variables.


Re: GC deadlocks on linux

2015-02-20 Thread Martin Nowak via Digitalmars-d-learn

On Wednesday, 18 February 2015 at 20:27:08 UTC, Byron Heads wrote:

Adding core.memory.GC.disable; to main causes the application to
work correctly (and quickly till it runs out of memory :D )


GC.disable shouldn't run OOM, BTW.
http://dlang.org/phobos/core_memory.html#.GC.disable


Re: GC deadlocks on linux

2015-02-20 Thread Martin Nowak via Digitalmars-d-learn

On Wednesday, 18 February 2015 at 20:41:12 UTC, Dicebot wrote:

Any chance you are using gdm-3.12.x?

I was so mad when I have encountered this:
https://issues.dlang.org/show_bug.cgi?id=4890


Indeed, maybe 
http://dlang.org/phobos-prerelease/core_thread.html#.thread_setGCSignals 
might help.
We should probably try to improve druntime to only use a single 
signal for suspending and resuming.


Re: GC deadlocks on linux

2015-02-20 Thread Martin Nowak via Digitalmars-d-learn

On Wednesday, 18 February 2015 at 20:27:08 UTC, Byron Heads wrote:

I have a medium size daemon application that uses several
threads, libasync, and daemonize.  On windows it runs correctly
with GC enabled, but on linux the GC causes a deadlock while
allocating memory.


Can you reliably reproduce the deadlock?
If so please attach a gdb to the deadlocked process and provide 
us back traces of all threads? If you can share the code (maybe 
privately), that would help as well.


Re: GC deadlocks on linux

2015-02-20 Thread Martin Nowak via Digitalmars-d-learn

On 02/18/2015 09:35 PM, Byron Heads wrote:





I am in the daemonize library

https://github.com/NCrashed/daemonize


Might want to try using libasync without multiple threads.
http://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them


Re: vibe.d problem

2014-11-18 Thread Martin Nowak via Digitalmars-d-learn
On Tuesday, 18 November 2014 at 13:37:54 UTC, Lázaro Armando via 
Digitalmars-d-learn wrote:

this is very old. try git HEAD instead, it should help.

How could I do that using dub?


Running `dub upgrade` should be enough as a new version of vibe.d 
was just released.


Re: Making plugin system with shared libraries. Upcast in shared lib

2014-10-20 Thread Martin Nowak via Digitalmars-d-learn

On 10/20/2014 12:32 AM, MrSmith wrote:

Than any module can search for registered modules and try to cast them
to concrete type (upcast).


That can't work because the notion of types only exists during 
compilation. Therefor it's not possible to load new types at runtime and 
use them in code that was compiled without knowing those types.

You should simply use interfaces to achieve your goal.


Re: Is this a bug when creating proxies in classes?

2014-10-16 Thread Martin Nowak via Digitalmars-d-learn

On Monday, 25 August 2014 at 18:10:33 UTC, Gary Willoughby wrote:

class Foo
{
private int foo;

mixin Proxy!(foo);

this(int x)
{
this.foo = x;
}
}


Apparently Proxy doesn't work correctly inside classes.
Is wrapping something inside a class particularly useful?
Please comment on https://issues.dlang.org/show_bug.cgi?id=13623.


Re: What is this ? Howw to solve it ?

2014-10-15 Thread Martin Nowak via Digitalmars-d-learn

On Wednesday, 15 October 2014 at 08:23:29 UTC, Marc Schütz wrote:
Someone else already reported the same problem. I'll add a link 
to your post.


Where, I didn't found any Bugzilla issue, so I opened one.
https://issues.dlang.org/show_bug.cgi?id=13621



Re: A significant performance difference

2014-10-01 Thread Martin Nowak via Digitalmars-d-learn
You're comparing front removal on an ordered vs. an unordered 
container.

Anyhow at least my C++ lib also caches the first used bucket.


Re: vibe.d https_server example fails

2014-09-29 Thread Martin Nowak via Digitalmars-d-learn

On 09/29/2014 06:31 PM, Nordlöw wrote:

What's wrong? Certificates?


Use https instead of http :).
https://localhost:8080/



Turn function into infinite range

2014-09-29 Thread Martin Nowak via Digitalmars-d-learn

Does anyone know a construct to turn a lambda into an infinite range.

import std.random;

unittest
{
Random gen;
foreach(v; xxx!(() = uniform(0, 100, gen)).take(10))
writeln(v);
}

I though I've seen this around somewhere but can no longer find it.


Re: vibe.d https_server example fails

2014-09-29 Thread Martin Nowak via Digitalmars-d-learn

On 09/29/2014 08:20 PM, Nordlöw wrote:

This however crashes the server program as

Error executing command run: Program exited with code -11

Maybe I should use a vibe.d version other than master?


Please report it https://github.com/rejectedsoftware/vibe.d/issues, 
there seems to be some issue with interface/class casting and manual 
class allocation.


Re: vibe.d https_server example fails

2014-09-29 Thread Martin Nowak via Digitalmars-d-learn

On 09/29/2014 11:41 PM, Etienne wrote:

Yes, the ssl_stream should be defined outside the if clause. The
FreeLostRef refcount goes to 0 when it goes out of scope in http/server.d


Well, how about a pull then?
https://github.com/rejectedsoftware/vibe.d/issues/846


Re: core.thread.Fiber --- runtime stack overflow unlike goroutines

2014-09-21 Thread Martin Nowak via Digitalmars-d-learn

Am I missing something? Is there a clean and simple way to get Fiber to
no longer suffer a stack overflow when implementing D-routines?


Simply choose a big enough stack size when creating your fibers.
http://dlang.org/library/core/thread/Fiber.this.html

It's fairly cheap to use a really big stack like 4MB, because memory 
pages are committed lazily by the OS.


Re: core.thread.Fiber --- runtime stack overflow unlike goroutines

2014-09-21 Thread Martin Nowak via Digitalmars-d-learn

On 08/15/2014 05:09 PM, Sean Kelly wrote:

At least on OSX, it appears that mapping memory is constant time
regardless of size, but there is some max total memory I'm allowed to
map, presumably based on the size of a vmm lookup tabe.  The max block
size I can allocate is 1 GB, and I can allocate roughly 131,000 of these
blocks before getting an out of memory error.  If I reduce the block
size to 4 MB I can allocate more than 10M blocks without error.  I think
some default stack size around 4 MB seems about right.  Increasing the
size to 16 MB failed after about 800,000 allocations, which isn't enough
(potential) fibers.


While pages are committed lazily it's not free to map more memory.
For example the kernel will have to allocate and setup more page table 
entries.
Furthermore we might need to use MAP_NORESERVE to not run into 
overcommit limitations, but that's not available on all OSes I think.


It might make sense to raise the stack size again [1] if we had an idea 
what size would avoid common issues (vibe.d uses 64kB). 4MB is too much 
for the default size IMO.


Given that the stack size is configurable let's instead try to improve 
the diagnostic of Fiber stack overflows first, we should also map a 
guard page on posix and add a segfault handler to detect overflows.


[1]: 
https://github.com/D-Programming-Language/druntime/commit/9dca50fe65402fb3cdfbb689f1aca58dc835dce4#diff-8bb12ed976acf0a5132e877ec5a01ea8R3163


Re: request assistance resolving curl related linker error

2014-08-18 Thread Martin Nowak via Digitalmars-d-learn

On Monday, 18 August 2014 at 14:24:54 UTC, Andrew Edwards wrote:

import std.net.curl;

void main(){}

// Output:

Undefined symbols for architecture x86_64:
  _curl_easy_cleanup, referenced from:


The problem here is that std.net.curl is based on libcurl, so you 
need to link your program against it.

Add '-L-lcurl' to your dmd invocation to do this.


Re: request assistance resolving curl related linker error

2014-08-18 Thread Martin Nowak via Digitalmars-d-learn

On Monday, 18 August 2014 at 16:09:04 UTC, Martin Nowak wrote:
The problem here is that std.net.curl is based on libcurl, so 
you need to link your program against it.

Add '-L-lcurl' to your dmd invocation to do this.


I also added an enhancement request to load curl at runtime.
https://issues.dlang.org/show_bug.cgi?id=13324


Re: runtime loading D shared library as a standalone (with it's own GC etc)

2014-05-23 Thread Martin Nowak via Digitalmars-d-learn

Filed as https://issues.dlang.org/show_bug.cgi?id=12792.