Re: Anybody know about SDL and particularly SDL_TTF initialization?

2024-05-23 Thread Jerry via Digitalmars-d-learn

On Sunday, 12 May 2024 at 20:13:04 UTC, WhatMeWorry` wrote:


INFO: SDL loaded v2.30.2
INFO: SDL initialized: 0
INFO: TTF loaded: v2.0.14
Error Program exited with code -1073741819


Something hit a null pointer, time to fire up the debugger :)




Re: allocated object address as high as 46th bit (i.e in the 131072 GB range)

2023-10-11 Thread Jerry via Digitalmars-d-learn
The reason high bits are often set is because an address layout 
is actually 4 indicies into the page table and a page byte 
offset. So all the way to bit 48 there is index info the cpu uses.


Re: Trying to cross compile from windows to android

2022-01-21 Thread Jerry via Digitalmars-d-learn

On Friday, 21 January 2022 at 09:52:10 UTC, Jerry wrote:

On Thursday, 20 January 2022 at 19:31:06 UTC, H. S. Teoh wrote:

T


Found ld linker as you described.
Slapped on the --linker=ld flag and now everything is working. 
Thanks! :D


Or atleast that's what I thought, it links, but won't run, 
apparently bfd linker is required. So I installed that one.


Re: Trying to cross compile from windows to android

2022-01-21 Thread Jerry via Digitalmars-d-learn

On Thursday, 20 January 2022 at 19:31:06 UTC, H. S. Teoh wrote:

T


Found ld linker as you described.
Slapped on the --linker=ld flag and now everything is working. 
Thanks! :D


Re: Trying to cross compile from windows to android

2022-01-21 Thread Jerry via Digitalmars-d-learn

On Thursday, 20 January 2022 at 19:31:06 UTC, H. S. Teoh wrote:
On Thu, Jan 20, 2022 at 07:10:40PM +, Jerry via 
Digitalmars-d-learn wrote:


You're trying to use bfd as your linker, and I think that only 
exists on the Linux version of the NDK. Maybe try looking 
somewhere under 
ldc_android/android_ndk/toolchains/x86_64-*/prebuilt/windows-x86_64/bin to see what linkers are shipped with your NDK, and specify that instead?


On Linux, I see a bunch of binaries named 
x86_64-linux-android-*, including *-ld, *-ld.bfd, *-ld.gold, 
which are the 3 linkers that can be used via -fuse-ld=bfd, 
-fuse-ld=gold, etc..  I'm not sure how it works on Windows, but 
there should be corresponding binaries that might give a hint 
as to what's the correct -fuse-ld=... option you need to use.



T


Thank you mate, got it working now. With the ld linker.


Trying to cross compile from windows to android

2022-01-20 Thread Jerry via Digitalmars-d-learn
Hello, followed the guide at 
https://wiki.dlang.org/Build_D_for_Android

but got stuck on figuring out what linker to use.

"../ldc_android/ldc/bin/ldc2.exe" -mtriple=armv7a--linux-andro
ideabi main.d
clang: error: invalid linker name in argument '-fuse-ld=bfd'
Error: 
ldc_android/android_ndk/toolchains/llvm/prebuilt/windows-x86_64/bin

/aarch64-linux-android21-clang.cmd failed with status: 1

Do I need to install a GNU linker with cross compile 
compatabilities or is my system not configured properly?


Re: How to call stop from parallel foreach

2021-06-24 Thread Jerry via Digitalmars-d-learn

On Thursday, 24 June 2021 at 18:23:01 UTC, seany wrote:
I have seen 
[this](https://forum.dlang.org/thread/akhbvvjgeaspmjntz...@forum.dlang.org).


I can't call break form parallel foreach.

Okey, Is there a way to easily call .stop() from such a  case?

Here is a case to consider:

outer: foreach(i, a; parallel(array_of_a)) {
   foreach(j, b; parallel(array_of_b)) {
 auto c = myFunction0(i,j);
 auto d = myFunction1(a,b);
 auto f = myFunction2(i,b);
 auto g = myFunction3(a,j);

 if(someConditionCheck(c,d,f,g)) {
   // stop the outer foreach loop here
 }

   }
}

Thank you


Maybe I'm wrong here, but I don't think there is any way to do 
that with parallel.
What I would do is negate someConditionCheck and instead only do 
work when there is work to be done.

Obviously that may or may not be suitable.
But with parallel I don't see any way to make it happen.



Re: Recommendations on avoiding range pipeline type hell

2021-05-19 Thread Jerry via Digitalmars-d-learn

On Saturday, 15 May 2021 at 11:51:11 UTC, Adam D. Ruppe wrote:
Meh, don't listen to that nonsense, just write what works for 
you. D's strength is that it adapts to different styles and 
meets you where you are. Listening to dogmatic sermons about 
idiomatic one true ways is throwing that strength away and 
likely to kill your personal productivity as you're fighting 
your instincts instead of making it work.


+1


Re: Disallow implicit "conversion" from alias-types

2020-11-10 Thread Jerry via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 11:38:30 UTC, Vladimirs Nordholm 
wrote:

Hello.

I am unsure if I am going about this the right way, and if my 
question even makes sense.


In essence what I want is to have two "types" represented by a 
size_t. Here is an example of what I want think I want (but 
might be completely off)


alias Foo = size_t;
alias Bar = size_t;

Foo foo = 4;
Bar bar = foo; // i want some error like
   // "cannot implicitly convert from type Foo 
to Bar"


My best solution is to have the types as classes to force type 
checking.


Is there a better way to do what I want here?


https://dlang.org/library/std/typecons/typedef.html


Re: Is it possible to modify shared struct array in a function.

2019-02-07 Thread Jerry via Digitalmars-d-learn

On Friday, 8 February 2019 at 04:51:08 UTC, Sudhi wrote:
On Friday, 8 February 2019 at 04:30:23 UTC, Arun Chandrasekaran 
wrote:

On Friday, 8 February 2019 at 04:13:39 UTC, Sudhi wrote:

[...]


Works fine for me with DMD64 D Compiler v2.083.1. 
https://run.dlang.io/is/RRM8GU



My example code was wrong. Below is the right one.

struct Company
{
string name;
string location;
}

struct Racks
{
int number;
int location;
}

struct Metadata
{
string name;
Company[] companies;
Racks[] racks;
}

struct Item
{
Metadata[] met;
int count;
}

shared (Item) item;

void main()
{
   updateMetadata();
}

void updateMetadata()
{
   Company company;
   company.name = "Hello";
   company.location = "Bangalore";
   item.met.companies ~= company;
   import std.stdio: writeln;
   writeln(item);
}

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


You have to cast away shared:

auto loc_item = cast(Item) item;
loc_item.met ~= m;
item = cast(shared) loc_item;

Just to be clear, this is not threadsafe and require a mutex if 
you do this other than as init in main.


Re: Linker error

2019-01-21 Thread Jerry via Digitalmars-d-learn

On Monday, 21 January 2019 at 22:31:15 UTC, H. S. Teoh wrote:
On Mon, Jan 21, 2019 at 10:19:00PM +, Jerry via 
Digitalmars-d-learn wrote:

On Monday, 21 January 2019 at 21:37:22 UTC, H. S. Teoh wrote:

[...]

> Looks like a problem with stale cached object files.  Try:
> 
> 	rm dub.selections.json

>dub build --force
> 
> (Be sure to back up dub.selections.json before doing this, 
> if you

> have customized it by hand.)

[...]

Still same error, on both 2.78 and 2.84.


Hmm.  OK, then I've no idea what's wrong, sorry.


T


Thank you for all the effort!


Re: Linker error

2019-01-21 Thread Jerry via Digitalmars-d-learn
On Monday, 21 January 2019 at 21:02:23 UTC, Steven Schveighoffer 
wrote:

On 1/21/19 3:37 PM, Jerry wrote:

[...]


I had a similar problem that I fixed myself actually last dconf:

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

This looks almost identical as the issue was in the generated 
xtoHash function.


What version of the compiler are you using? My issue was fixed 
in 2.080.1, and then a followup fix in 2.081.1.


-Steve


Ok, I get the same linker error down to version 2.74. Below that 
my eventcore version does not compile. Atleast LDC can compile so 
I can move forward. I will try to dustmite this tomorrow.


Re: Linker error

2019-01-21 Thread Jerry via Digitalmars-d-learn

On Monday, 21 January 2019 at 21:37:22 UTC, H. S. Teoh wrote:
On Mon, Jan 21, 2019 at 04:02:23PM -0500, Steven Schveighoffer 
via Digitalmars-d-learn wrote:

On 1/21/19 3:37 PM, Jerry wrote:
> [...]

[...]

> [...]

[...]

Looks like a problem with stale cached object files.  Try:

rm dub.selections.json
dub build --force

(Be sure to back up dub.selections.json before doing this, if 
you have

customized it by hand.)


T


Still same error, on both 2.78 and 2.84.


Re: Linker error

2019-01-21 Thread Jerry via Digitalmars-d-learn
On Monday, 21 January 2019 at 21:02:23 UTC, Steven Schveighoffer 
wrote:
What version of the compiler are you using? My issue was fixed 
in 2.080.1, and then a followup fix in 2.081.1.


-Steve



Hello!
I am using 2.084.
Interestingly it works with LDC 1.9 (frontend 2.79) and that just 
works fine.


Bisecting dmd versions.

- Jerry


Linker error

2019-01-21 Thread Jerry via Digitalmars-d-learn
Hello, I am trying to compile a 1 year old project of mine which 
uses htmld and vibed. But I get this weird linker error which 
does not make any sense to me atleast. I am using Windows 7 and 
dub.


htmld 0.3.6: target for configuration "library" is up to date.
taggedalgebraic 0.10.12: target for configuration "library" is up 
to date.

eventcore 0.8.40: target for configuration "winapi" is up to date.
stdx-allocator 2.77.5: target for configuration "library" is up 
to date.

vibe-core 1.5.0: target for configuration "winapi" is up to date.
vibe-d:utils 0.8.4: target for configuration "library" is up to 
date.
vibe-d:data 0.8.4: target for configuration "library" is up to 
date.
mir-linux-kernel 1.0.1: target for configuration "library" is up 
to date.
vibe-d:crypto 0.8.4: target for configuration "library" is up to 
date.

diet-ng 1.5.0: target for configuration "library" is up to date.
vibe-d:stream 0.8.4: target for configuration "library" is up to 
date.
vibe-d:textfilter 0.8.4: target for configuration "library" is up 
to date.
vibe-d:inet 0.8.4: target for configuration "library" is up to 
date.
vibe-d:tls 0.8.4: target for configuration "openssl-mscoff" is up 
to date.
vibe-d:http 0.8.4: target for configuration "library" is up to 
date.
vibe-d:mail 0.8.4: target for configuration "library" is up to 
date.
vibe-d:mongodb 0.8.4: target for configuration "library" is up to 
date.
vibe-d:redis 0.8.4: target for configuration "library" is up to 
date.
vibe-d:web 0.8.4: target for configuration "library" is up to 
date.

vibe-d 0.8.4: target for configuration "vibe-core" is up to date.
my_stuff ~master: building configuration "updater-local"...
Linking...
vibe-d_web.lib(common.obj) : warning LNK4255: library contain 
multiple objects of the same name; lin

king object as if no debug info
eventcore.lib(driver.obj) : warning LNK4255: library contain 
multiple objects of the same name; link

ing object as if no debug info
eventcore.lib(driver.obj) : warning LNK4255: library contain 
multiple objects of the same name; link

ing object as if no debug info
eventcore.lib(core.obj) : warning LNK4255: library contain 
multiple objects of the same name; linkin

g object as if no debug info
my_stuff.obj : error LNK2019: unresolved external symbol 
_D60TypeInfo_xS4html3dom__T15ChildrenForwar
dTCQBfQBd4NodeVnnZQBi6__initZ referenced in function 
_D8typecons__T11ThrowOnNullTS4html3dom__T15Chil

drenForwardTCQBfQBd4NodeVnnZQBiZQCn9__xtoHashFNbNeKxSQDu__TQDoTQDeZQDwZm
.dub\build\updater-local-debug-windows-x86_64-dmd_2083-F0ADCB72FF986B7D6354817AF1E3A045\my_stuff.exe
 : fatal error LNK1120: 1 unresolved externals
Error: linker exited with status 1120
dmd failed with exit code 1.

I tried to find the typecons.ThrowOnNull thing in the standard 
library but that one does not exist. So I am pretty confused 
about what is going on here.


Thank you.


Re: DlangUI and android

2018-09-12 Thread Jerry via Digitalmars-d-learn

On Monday, 10 September 2018 at 09:19:52 UTC, Josphe Brigmo wrote:
Is there an emulator that can run the apks? Android emulator 
does not work, I suppose, because it isn't java. Complains 
about a missing classes.dex file.


I'd rather have an emulator version if possible for quicker dev.


For APKs I usually use Bluestacks [0]. Works great for Unity 
builds atleast.


0: https://www.bluestacks.com/


Re: Casting a pointer and length value as a dynamic array

2018-07-30 Thread Jerry via Digitalmars-d-learn

On Monday, 30 July 2018 at 22:22:39 UTC, solidstate1991 wrote:
I need this to port a C++ code to D (a compression algorithm 
known as LZHAM), and the easiest way to deal with it would be 
that. The ADLER32 and CRC32 algorithms had to be ditched, and 
while I could rewrite the former to make sense (used some form 
of "vectorization") I would like to use the standard library's 
implementation for the latter.


   int[] as_array(int* ptr, size_t len) {
  return ptr[0 .. len];
   }


Re: Call different member functions on object sequence with a generic handler function?

2018-06-30 Thread Jerry via Digitalmars-d-learn

On Friday, 29 June 2018 at 20:23:47 UTC, Timoses wrote:

void handler(alias func, T)(T[] ts) {

}


Btw this is pretty much std.algorithm.each

import std.algorithm;

void main() {
  auto cs = [ new C(), new C() ];
  cs.each!(o => o.A());
}

https://dlang.org/phobos/std_algorithm_iteration.html#.each




Re: debugging in vs code on Windows

2017-10-14 Thread Jerry via Digitalmars-d-learn

On Saturday, 14 October 2017 at 19:01:52 UTC, piotrklos wrote:

On Saturday, 14 October 2017 at 13:12:51 UTC, Jerry wrote:

On Friday, 13 October 2017 at 12:55:09 UTC, piotrklos wrote:

(...)


If you use generate a 32-bit binary using DMD, it generates it 
in a format that the C/C++ extension doesn't understand. You 
need to compile -m32mscoff or -m64, and you need to make sure 
the /DEBUG is passed to the linker, as I don't think dmd 
passes it that. You can do that by passing "-L/DEBUG" to DMD 
(when using -m32mscoff or -m64). There should be a .pdb file 
that gets generated, when you start the debugger it should say 
that symbols were loaded for the exe.


I also can't say for certain if debug information is even 
generated for the unittests, so that might be something worth 
looking into to make sure it does.


I have added this to dub.json:
"dmd-flags":[
"-g", "-m64", "-L/DEBUG"
]
but I don't see a pdb file generated when I build. What am I 
doing wrong?


Are you sure it's not dflags? I don't use dub but a quick search 
shows there's dflags, but no flags setting.


https://code.dlang.org/package-format?lang=json

Also using verbose flag with dub should show you the commands 
that are executed for building.


Re: debugging in vs code on Windows

2017-10-14 Thread Jerry via Digitalmars-d-learn

On Saturday, 14 October 2017 at 14:23:34 UTC, piotrklos wrote:

On Saturday, 14 October 2017 at 13:20:27 UTC, Jerry wrote:

On Saturday, 14 October 2017 at 10:15:53 UTC, evilrat wrote:
webfreak's NativeDebug extension to be able to click to set 
breakpoint on lines(only for that).




You can just use VS Code setting, put the following into your 
settings.json:


"debug.allowBreakpointsEverywhere": true


But I can already click on the edge of editor and red bubble 
appears. Its just that the execution doesn't stop on those.


That comment wasn't for you, the other one was.


Re: debugging in vs code on Windows

2017-10-14 Thread Jerry via Digitalmars-d-learn

On Saturday, 14 October 2017 at 10:15:53 UTC, evilrat wrote:
webfreak's NativeDebug extension to be able to click to set 
breakpoint on lines(only for that).




You can just use VS Code setting, put the following into your 
settings.json:


"debug.allowBreakpointsEverywhere": true


Re: debugging in vs code on Windows

2017-10-14 Thread Jerry via Digitalmars-d-learn

On Friday, 13 October 2017 at 12:55:09 UTC, piotrklos wrote:
I have windows 10, VS Code with code-d and C/C++ language 
extensions. I try to debug but it doesn't work. In particular, 
the debugging doesn't stop on breakpoints. It exits 
immediately. I recompile with -m64 and -g. I use dub to build 
the project. I use unit-threaded and I'm trying to debug a 
unittest build.


Has anyone been able to debug in VS code on Windows? What am I 
doing wrong?


(Rhetorical) Why is dlang community provide so many options 
(see https://wiki.dlang.org/Debuggers) and **every single one** 
of them is faulty in some way? I tried windbg and mago-mi but 
didn't gen anywhere.


If you use generate a 32-bit binary using DMD, it generates it in 
a format that the C/C++ extension doesn't understand. You need to 
compile -m32mscoff or -m64, and you need to make sure the /DEBUG 
is passed to the linker, as I don't think dmd passes it that. You 
can do that by passing "-L/DEBUG" to DMD (when using -m32mscoff 
or -m64). There should be a .pdb file that gets generated, when 
you start the debugger it should say that symbols were loaded for 
the exe.


I also can't say for certain if debug information is even 
generated for the unittests, so that might be something worth 
looking into to make sure it does.


Iterating over functions in module in order?

2017-10-04 Thread Jerry via Digitalmars-d-learn
Any ideas on how someone could iterate over functions in a module 
as they appear, rather than any random order, without having to 
manually label them?


Re: Does D support nested Templates aka Higher Kinded Polymorphism?

2017-10-03 Thread Jerry via Digitalmars-d-learn

On Tuesday, 3 October 2017 at 12:58:47 UTC, sighoya wrote:
On Tuesday, 3 October 2017 at 12:09:04 UTC, rikki cattermole 
wrote:

On 03/10/2017 1:05 PM, sighoya wrote:

Especially, I mean something like

T foo(S,T)(T i)
{
     ...
}


struct Foo(T) {
T value;
}

T!S foo(S, alias T)(T!S v) { return v; }


void main() {
import std.stdio;   
writeln(foo!(int, Foo)(Foo!int(1)));
}


Cool, but it seems that only a nesting of two is allowed, right?
This one gives an error:

T!S!R bar(alias T,alias S,R)(T!S!R v) {return v;}
Error: multiple ! arguments are not allowed


That is because you have to wrap multiple with ().
Use
  T!(S!R)
instead.


Re: scope(exit) and destructor prioity

2017-09-18 Thread Jerry via Digitalmars-d-learn

On Monday, 18 September 2017 at 20:26:05 UTC, Sasszem wrote:
I'm currently working on a project and for that I've created a 
thin OO-wrapper on top of derelict-sdl. However, when I close 
my app, the program terminates with a segfault. I've managed to 
track down the source, and found that the destructors of my 
objects are called AFTER the scope(exit) statements. This 
causes my program to call TTF_CloseFont() after TTF_Quit(), 
resulting in a segfault.

My questions:
 - Can I force D to call the destructors BEFORE the scope(exit) 
statements?

 - If not, is there a way around?


It's called inbetween the destructors of wherever you put the 
scope(exit).


import std.stdio;

struct De
{
~this() { writeln("De"); }
}

void main()
{
De a;
scope(exit) writeln("scope exit");
De b;
}


Output:
De
scope exit
De


Re: How to implement Timeout function

2017-08-27 Thread Jerry via Digitalmars-d-learn

On Sunday, 27 August 2017 at 15:56:14 UTC, Saigon wrote:

Hi,

Can I have Timeout function like this one [1] in Ruby? I want 
to check if a TCP service is running, and the check would 
return error if timeout occurs.


Thanks a lot

[1] https://github.com/ruby/ruby/blob/trunk/lib/timeout.rb


Can it be blocking?



Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread Jerry via Digitalmars-d-learn

On Sunday, 21 May 2017 at 19:58:32 UTC, Stefan Koch wrote:

On Sunday, 21 May 2017 at 19:33:06 UTC, ParticlePeter wrote:
I am statically linking to ImGui [1] on Win 10 x64, quite 
successfully till this issue came up. The noticed error so far 
comes when an ImGui function returns an ImVec2, a simple POD 
struct of two float members. I can use this struct as argument 
to functions but when it is returned from a function I get a 
0xC005: Access violation reading location 
0x. I can even debug the process with Visual 
Studion, mixed d and c++ sources. The functions I tested 
return data from some internal global ImGui data, which I can 
fully examine, the crash happens on the return statement. 
Moreover, some functions have variations which return only one 
component from that ImVec2 POD, which do work as expected, 
e.g.:


[...]


are you aware of https://github.com/Extrawurst/DerelictImgui ?


Not everyone likes the set of 'derelict' libraries. Especially if 
you need to statically link to a library.


Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread Jerry via Digitalmars-d-learn

Note that you also probably need extern(C++) on the struct ImVec2.

https://github.com/ParticlePeter/imgui_lib/blob/master/source/imgui/types.d#L84


Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-22 Thread Jerry via Digitalmars-d-learn

On Sunday, 21 May 2017 at 19:33:06 UTC, ParticlePeter wrote:
I am statically linking to ImGui [1] on Win 10 x64, quite 
successfully till this issue came up. The noticed error so far 
comes when an ImGui function returns an ImVec2, a simple POD 
struct of two float members. I can use this struct as argument 
to functions but when it is returned from a function I get a 
0xC005: Access violation reading location 
0x. I can even debug the process with Visual 
Studion, mixed d and c++ sources. The functions I tested return 
data from some internal global ImGui data, which I can fully 
examine, the crash happens on the return statement. Moreover, 
some functions have variations which return only one component 
from that ImVec2 POD, which do work as expected, e.g.:


ImVec2  GetCursorPos();   // crash
float   GetCursorPosX();  // works
float   GetCursorPosY();  // works

The latter do basically the same as the first one, but return 
ImVec.x or .y respectively.


How could I further debug this?
If somebody would be willing to look at the source, the binding 
is here [2].



[1] https://github.com/ocornut/imgui
[2] https://github.com/ParticlePeter/imgui_lib


IIRC the problem is that it isn't a POD type. ImVec2 has its own 
default constructor. The problem now is that because it no longer 
is POD, Window's ABI handles it different and doesn't put the 
value in a register. Now with D is that you aren't allowed to 
specify your own default constructor, so there's no equivalent 
way for it to know that it isn't a POD. A way around this is to 
specify your own destructor or copy constructor in the D ImVec2. 
I forget what the rules are for it, but I think that should do it.


Re: Atomicity of file-copying/moving

2017-05-17 Thread Jerry via Digitalmars-d-learn

On Tuesday, 16 May 2017 at 08:32:56 UTC, Nordlöw wrote:
What's the status of atomicity of file-copying and -moving 
(renaming) using std.file on different platforms?


Niall has a good talk about this on youtube:
https://www.youtube.com/watch?v=uhRWMGBjlO8


Re: alias can't find symbol or can't use symbol

2017-04-30 Thread Jerry via Digitalmars-d-learn

To me this seems like a bug.



Re: refRange with non copyable struct

2017-04-17 Thread Jerry via Digitalmars-d-learn

On Monday, 17 April 2017 at 18:07:36 UTC, Jonathan M Davis wrote:
In this particular case, it looks like the main problem is 
RefRange's opAssign. For it to work, the type needs to be 
copyable. It might be reasonable for RefRange to be enhanced so 
that it doesn't compile in opAssign if the range isn't 
copyable, but I'd have to study RefRange in depth to know what 
the exact consequences of that would be, since it's been quite 
a while since I did anything with it. My guess is that such a 
change would be reasonable, but I don't know without studying 
it.


- Jonathan M Davis


I took a look on RefRange and the reasoning is clearly explained 
in the docs like this:


This does not assign the pointer of $(D rhs) to this $(D 
RefRange).
Rather it assigns the range pointed to by $(D rhs) to the range 
pointed

to by this $(D RefRange). This is because $(I any) operation on a
RefRange) is the same is if it occurred to the original range. The
exception is when a $(D RefRange) is assigned $(D null) either
or because $(D rhs) is $(D null). In that case, $(D RefRange)
longer refers to the original range but is $(D null).



But what I do not understand is why this is important.


Re: refRange with non copyable struct

2017-04-17 Thread Jerry via Digitalmars-d-learn

On Monday, 17 April 2017 at 18:07:36 UTC, Jonathan M Davis wrote:

Non-copyable types tend to wreak havoc with things
- Jonathan M Davis


Basicly what I use this for is to combine RAII with ranges.
Which I find quite useful when doing DB queries and the data is 
lazily fetched
since this allows me to guarantee that the query is "closed" and 
another query can take place.




refRange with non copyable struct

2017-04-17 Thread Jerry via Digitalmars-d-learn

Hello guys, so I wanted to have a noncopyable range on the stack.
So my thoughts was to make it non copyable and use refRange 
whenever I want to use it with map and others.


But I got a compiler warning when doing so like this:

import std.range;

void main() {
NonCopyable v;

refRange();
}

struct NonCopyable
{
@disable this(this);

int data;

enum empty = false;
void popFront() {}
int front() { return data; }
}





With the error message:

C:\D\dmd2\windows\bin\..\..\src\phobos\std\range\package.d(8941): 
Error: struct reproduction.NonCopyable is not copyable because it 
is annotated with @disable
C:\D\dmd2\windows\bin\..\..\src\phobos\std\range\package.d(8982): 
Error: mutable method reproduction.NonCopyable.front is not 
callable using a const object
C:\D\dmd2\windows\bin\..\..\src\phobos\std\range\package.d(9649): 
Error: template instance std.range.RefRange!(NonCopyable) error 
instantiating
reproduction.d(6):instantiated from here: 
refRange!(NonCopyable)





Is there any workaround?
Is this a bug?


Re: List Comprehension equivalent

2017-03-17 Thread Jerry via Digitalmars-d-learn

On Friday, 17 March 2017 at 17:13:48 UTC, Russel Winder wrote:

I have a bit of code:

string[] returnValue;
foreach(string key, string[] value; groups) {
		returnValue ~= 
value.sort!debianPackageNumberComparator()[0..$-1].array;

}
return returnValue;

[...]


You forgot a ! on the map call.

.map!((Tuple!(string, string[]) a) => 
a[1].sort!debianPackageNumberComparator()[0..$-1])


Re: Template specialisation for range of types

2017-03-12 Thread Jerry via Digitalmars-d-learn

On Sunday, 12 March 2017 at 18:49:22 UTC, data pulverizer wrote:

Hello all,

I am attempting to write templates for differently qualified 
types using specialisations. Below is an example for const and 
non-const outlining my approach:



``
import std.stdio : writeln;
import std.traits : ConstOf;

auto max(T)(T x, T y)
{
writeln("General template");
return x > y ? x : y;
}


auto max(T: ConstOf!U, U)(T* x, T* y)
{
writeln("Const template");
return *x > *y ? x : y;
}


void main(){
const double p = 2.4, q = 3;
writeln(max(, ));
}
``

I get this output:

General template
7FFE5B3759A8


In this case would like to use the ConstOf specialisation 
instead of the default implementation for the inputs which are 
const.


Thanks for you answers in advance


Wouldn't just putting const infront work?


Re: DMD + Dynamic Library.

2017-03-07 Thread Jerry via Digitalmars-d-learn
You have to use "export" for any symbol to be visible from a dll. 
On Windows by default nothing is exported.


Re: Debugging D applications from VS code with webfreak.debug

2017-02-23 Thread Jerry via Digitalmars-d-learn
You can use the C++ plugin, which provides a debugger. Just make 
sure you aren't using optlink, I don't think it generates 
compatible files. Also you might need to use "-gc" which 
generates debug names to be in C format.


https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools

You might also need to enable breakpoints anywhere in VS code 
user setting file.


Re: opApply with Type Inference and Templates?

2017-02-16 Thread Jerry via Digitalmars-d-learn

On Thursday, 16 February 2017 at 04:09:18 UTC, Basile B. wrote:

No, by any chance do you ask this for the tuple unpacking PR ?
If so I've also tried and failed.


Was just trying to use a container I created in functions with 
and without @nogc/nothrow.





opApply with Type Inference and Templates?

2017-02-15 Thread Jerry via Digitalmars-d-learn
I am trying to do opApply to work when the delegate passed when 
it is and isn't nogc/nothrow. As soon as you involve a template 
though, type inference goes out the door. I want to be able to 
use opApply with templates (to get the auto @nogc/nothrow 
deducation passed on the delegate passed) but still be able to 
use type inference. Is there any way to do this?


Re: Why is [0] @safer than array.ptr?

2017-01-25 Thread Jerry via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 12:01:35 UTC, Jonathan M Davis 
wrote:
So, while it makes sense to say that .ptr can't be used in 
@safe code, it really doesn't make sense to suggest [0] as 
an alternative.


- Jonathan M Davis


Sure I see your point. But I feel like deprecations should also 
list what one can do instead. So in that regard the suggestion 
makes sense.






Re: @nogc and opengl errors check

2017-01-21 Thread Jerry via Digitalmars-d-learn

On Friday, 20 January 2017 at 22:47:17 UTC, Xavier Bigand wrote:

Hi,

I am writing some code with opengl commands that I want to 
check in debug, so I am using the function checkgl (from 
glamour lib).


The issue is that checkgl throw exception and can't be @nogc, I 
had try to use std.experimental.logger in place of exceptions, 
but it doesn't work either.


I mostly want to be able to check the opengl errors only in 
debug in a way that can make the debugger breaks.


On an other part as I will certainly have to log some events 
(even in release) I would appreciate that the logger be able to 
be used in @nogc functions, maybe with allocators?


Don't use checkgl, it just bloats you code and there's an actual 
debug feature in OpenGL now. It provides more information than 
just an enum as well. So when a function has multiple errors that 
use the same enum, you can actually know what the error was 
rather than guessing.


https://www.khronos.org/opengl/wiki/Debug_Output


Re: Adding linker paths with spaces using dmd and msvc toolchain

2016-12-30 Thread Jerry via Digitalmars-d-learn

On Friday, 30 December 2016 at 05:24:56 UTC, Jeremy DeHaan wrote:

On Friday, 30 December 2016 at 04:56:59 UTC, Jerry wrote:
On Friday, 30 December 2016 at 03:51:13 UTC, Jeremy DeHaan 
wrote:

How does one correctly add a linker path that has spaces?


The quotes get consumed by the command line. The way DMD 
spawns the linker by creating a new string with all the flags. 
So it smashes everything into a new string, ignoring how the 
string was passed into DMD. I think you can use triple quotes, 
"""string with space""", and it should make the string passed 
to DMD include the string. Might be different for powershell.


You mean I could do -L/LIBPATH:"""path"""?


My mistake that's for powershell, I'm not sure what the cmd.exe 
way is.


Re: Adding linker paths with spaces using dmd and msvc toolchain

2016-12-30 Thread Jerry via Digitalmars-d-learn

On Friday, 30 December 2016 at 05:24:56 UTC, Jeremy DeHaan wrote:

On Friday, 30 December 2016 at 04:56:59 UTC, Jerry wrote:
On Friday, 30 December 2016 at 03:51:13 UTC, Jeremy DeHaan 
wrote:

How does one correctly add a linker path that has spaces?


The quotes get consumed by the command line. The way DMD 
spawns the linker by creating a new string with all the flags. 
So it smashes everything into a new string, ignoring how the 
string was passed into DMD. I think you can use triple quotes, 
"""string with space""", and it should make the string passed 
to DMD include the string. Might be different for powershell.


You mean I could do -L/LIBPATH:"""path"""?


Yah you can try it with echo.

echo "test with space"
prints: test with space

echo """test with space"""
prints: "test with space"


Re: [question] Access from UDA constructor to parent symbol

2016-12-27 Thread Jerry via Digitalmars-d-learn

On Monday, 26 December 2016 at 21:15:03 UTC, Adam D. Ruppe wrote:

On Monday, 26 December 2016 at 20:07:56 UTC, crimaniak wrote:
 // I want to see Foo here and use it's reflection to 
iterate fields and methods.


then pass foo to it

What do you mean parent symbol? I assumed you mean subclass but 
your example shows one class and one struct. So is it the 
structure containing the class? Or what?



But, the answer of just passing the argument is probably the 
best one anyway. You can use a factory function, or pass the 
type from a constructor to a super method, or something like 
that.


I think he wants the symbol that the UDA is attached to.

So instead of doing:

struct attribN(I, T) { }

@attrib1!(Implement1, MyStructName)
@attrib2!(Implement2, MyStructName)
struct MyStructName
{
}


you could instead possibly add a feature to do this:

struct attribN(I, T = __UDA__)
{
}

// or possibly

class attribN(I) : Attribute // Attribute then contains the 
symbol its connected to

{
}


@attrib1!Implement1
@attrib2!Implement2
struct MyStructName
{
}

Not likely a feature to be added though.



Re: Range of uncopyable elements

2016-12-09 Thread Jerry via Digitalmars-d-learn
On Thursday, 8 December 2016 at 23:08:35 UTC, Jonathan M Davis 
wrote:
I've seen that in C++ code all the time, especially if you're 
dealing with
smart pointers, because otherwise you have to do stuff like 
(*iter)->foo()

instead of just var->foo().


Smart pointers weren't introduced until C++11. I'm talking about 
std library code that would have to be generic. Not user code 
where the type in the iterator is known.



Except that C++ _does_ have special iterators. They're just not 
as common.


Still not as common and C++ has a way to

With the upcoming improvements to @safe and return ref, it 
_might_ happen that there will be a way for a function to 
accept rvalues by ref. Andrei has indicated that a really good 
proposal might be accepted. But that's a separate issue from 
having ref on local variables, which is what would be required 
for what you're suggesting, and both Walter and Andrei have 
been adamant that that is not worth it - even without getting 
rvalue references into the mix. I don't know that it would be 
impossible to convince them otherwise, but I would be _very_ 
surprised if anyone managed to talk them into it.


Exactly, the problem will continue to persist even if rvalue 
references are included into D. It's not well thought out, 
isInputRange reflects that.


And for the most part, with ranges, this is pretty much a 
non-issue. It does become an issue when you start worrying 
about ranges with a non-copyable front, but this is literally 
only the second or third thread that I have ever seen where 
anyone complained about it. Much as it is annoying when someone 
runs int ito, it's not a big complaint that folks have. And 
given how much of a pain it would be to deal with in general, I 
seriously question that it's worth it - especially when simply 
using pointers fixes the problem.


That's not an acceptable workaround. It complicates code for no 
reason. If that's the decision that is going to be accepted. Then 
there should be helper functions included in the standard to 
reflect that.




Re: Range of uncopyable elements

2016-12-08 Thread Jerry via Digitalmars-d-learn
On Thursday, 8 December 2016 at 21:46:26 UTC, Jonathan M Davis 
wrote:

However, at least as of C++98, non-copyable elements in a
container were not allowed IIRC, so it would have been pretty
rare to have a C++ iterator that returned a non-copyable value
when you dereferenced it.


Even if it was uncommon, i doubt anyone actually made a copy of 
the dereferenced iterator.
There were also no restrictions in place that every algorithm 
needed it to be copyable, only the ones that actually needed it.

In the case of C++, dereferencing an iterator was basically free.
As an iterator was essentially a pointer and there were no 
special iterators.



Also, it pretty much _is_ assumed that

auto h = r.front;

is cheap, and there are plenty of cases where calling front
multiple times for the same range would incur additional
overhead, because front is calculated rather than simply
returning a value (e.g. this is what happens with map).
So, it could be a definite performance hit in general to start
insisting that r.front be called without the value being
assigned somewhere.


No one suggested calling front multiple times as a fix. Part of 
the problem with D is an old one and one that comes up often.
There are no rvalue references. This means it's a pain in the ass 
to write generic code. There's no easy way to write code that

will work for both references and values.

As an example you can write the following in C++:

int  foo0() { return 10; }
int& foo1() { static int i; return i; }

const int& a = foo0(); // a copy is made on the stack, this 
ref points to it
const int& b = foo1(); // this ref points to the global 
variable in foo1()


in D:

int foo0() { ... }
ref int foo1() { ... }

auto a = foo0();  // a copy is made
auto b = foo1();  // a copy is made
auto c = (); // need to write different code to get the 
result we want


void callback(ref int);

callback(a); // ok
callback(b); // ok
callback(c); // nope

The problem lies with D's inability to write generic code that 
works in boths instances. This means writing the same code twice

in some instances, or just not supporting one of the methods.



Yes, not allowing copyable elements for ranges is a problem.
But allowing them would also be a big problem.


Not if one of the biggest and most reoccurring complaints with D 
was fixed.



What we should ultimately do about it, I don't know, but I
think that it's pretty clear that the majority of code would be
better off if non-copyable elements for ranges were not
allowed. And it _is_ possible to work around the problem by
doing as H.S. Teoh suggested and using ranges of pointers.


I don't think so. There's a lot of functions that work with 
non-copyable
elements. Without modifying any code, the only blockage is caused 
by isInputRange.

Oh well, custom build of phobos it is.




Re: Range of uncopyable elements

2016-12-08 Thread Jerry via Digitalmars-d-learn

On Thursday, 8 December 2016 at 17:29:42 UTC, H. S. Teoh wrote:
The problem is that most range algorithms won't work if `auto h 
= r.front;` doesn't compile.  Random chunks of std.algorithm 
won't work for such a range.


One may argue, of course, that std.algorithm ought to be 
fixed... but the root of the problem really is a conceptual 
one. The definition of a range was made as an extension of a 
C++ iterator, which is basically a wrapped pointer. So `auto h 
= r.front;` is assumed to be a cheap copy of a *reference* to 
the underlying data, rather than copying the data itself. This 
is why most of std.algorithm is written the way it is, and why 
isInputRange is defined the way it is.  A range of non-copyable 
elements in this sense is a poor fit for the range concept; a 
better fit would be a range of references to an underlying 
container of non-copyable elements. Hence my suggestion of 
using pointers.


(In any case, conflating a range with a container is usually a 
red flag that there's a conceptual mismatch somewhere. 
Unfortunately built-in arrays aren't helping by hiding the fact 
that the container is actually GC-managed memory, which isn't 
directly visible to the user, thus perpetuating the 
misconception that range == container.)



T


Well it's exactly like that for C++ as well. std::copy(Iter, ...) 
won't compile if the values aren't copyable. There's no 
constraints in C++ either so you get some cryptic error message. 
The entire std library is like that.


Assuming that is wrong though, as you aren't copying an iterator 
or range you are copying the actual value. What you are confusing 
"auto h = r.front;" for is this: "auto rcopy = r;". The D code 
"auto h = r.front" is not a cheap operation and the equivalent in 
C++ is actually this: "auto h = *iterator;" and one should not 
assume it is cheap, cause it isn't. Anyways your comparison with 
C++ is off.


Re: Range of uncopyable elements

2016-12-08 Thread Jerry via Digitalmars-d-learn

On Thursday, 8 December 2016 at 16:48:07 UTC, H. S. Teoh wrote:
On Thu, Dec 08, 2016 at 04:35:02PM +, Jerry via 
Digitalmars-d-learn wrote:
The problem is with how isInputRange is defined, requires that 
front be copyable.


auto h = r.front; // can get the front of the range

https://github.com/dlang/phobos/blob/v2.072.1/std/range/primitives.d#L168

It doesn't take into consideration that front exists and that 
it's a reference to a struct that can't be copied. There was a 
discussion a while back to change it but it seems nothing came 
of it.


A possible workaround, which is somewhat ugly but should work, 
is to have the range return pointers to the elements instead of 
the elements themselves. For the most part, this should be 
mostly transparent because the . operator automatically 
dereferences.



T


It's not something that you should have to workaround, 
isInputRange is not defined properly and should be fixed. You end 
up complicating your code for no reason other than isInputRange 
is poorly defined.


Re: Range of uncopyable elements

2016-12-08 Thread Jerry via Digitalmars-d-learn
The problem is with how isInputRange is defined, requires that 
front be copyable.


auto h = r.front; // can get the front of the range

https://github.com/dlang/phobos/blob/v2.072.1/std/range/primitives.d#L168

It doesn't take into consideration that front exists and that 
it's a reference to a struct that can't be copied. There was a 
discussion a while back to change it but it seems nothing came of 
it.


Re: How to serialize a double.

2016-11-30 Thread Jerry via Digitalmars-d-learn

On Thursday, 1 December 2016 at 00:36:30 UTC, Jake Pittis wrote:

How do I convert a double to a ubyte[]?

I've tried all sorts of things including converting the double 
to a ulong and trying to serialize the ulong. For example test 
bellow fails.



unittest {
double d = 3.14;
ulong l = *cast(ulong*)();
double after = *cast(double*)());
assert(after == d); // This fails.
}



That test passes for me, are you sure there isn't something else 
wrong with your code? Check to see if it works for just a ulong 
that has values in it's upper 32-bits?


Re: Use class template as a type

2016-11-29 Thread Jerry via Digitalmars-d-learn

On Tuesday, 29 November 2016 at 15:56:23 UTC, Jerry wrote:

abstract class MyClass {}
abstract class MyClassImpl(T)



Oops, forgot MyClassImpl should extend from MyClass.

abstract class MyClassImpl(T) : MyClass {
...
}



Re: Use class template as a type

2016-11-29 Thread Jerry via Digitalmars-d-learn

On Monday, 28 November 2016 at 11:26:41 UTC, dm wrote:

```
abstract class MyClass(T)
{
  public:
   @property const(T) value(){return _value;}
   @property void value(T val){_value = val;}
...
  private:
   T _value;
...
}


To avoid having to use the Object class directly you can make an 
base class of the class template.

Like:

```
abstract class MyClass {}
abstract class MyClassImpl(T)
{
public:
@property const(T) value(){return _value;}
@property void value(T val){_value = val;}
 ...
   private:
T _value;
 ...
}

MyClassInt and float inherits from MyClassImpl
```

And use it like:

```
void main() {
   MyClass[] objs;
   objs ~= new MyClassFloat();
   objs ~= new MyClassInt();
}
```



Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Jerry via Digitalmars-d-learn

On Monday, 7 November 2016 at 21:37:50 UTC, Picaud Vincent wrote:

  static if ( isIntegralConstant!(typeof(required_capacity()) )
{
}
else
{
}

}


Premature post send by error sorry Well something like:

   static if ( isIntegralConstant!(typeof(required_capacity()) )
 ElementType[required_capacity()] data_;
   else
 ElementType[] data_;
}

For that, at least in C++, I need integral_constant<> type with 
compile-time arithmetic and smooth integration with "usual" 
size_t/ptrdiff_t types.


2/ I also would like to test some implementations concerning 
automatic differentiation.

I have my own C++ libs, inspired, but ~20% faster than Adept:
http://www.met.reading.ac.uk/clouds/adept/
and I would like to know how I can do that in D

Well... That is the idea... I hope I will get some results and 
I will be happy to share if it is something interesting.


Vincent


Ah I get what you mean, you can do that without using a special 
type.


struct Vector(T, Args...) if(Args.length == 1)
{
static if(is(Args[0] == size_t))
{
size_t size;
}
else static if(Args[0] != 0) // would error if it's a 
type that's not size_t

{
enum size = Args[0];
}
else
{
static assert(0);
}
}

Vector!(int, 10) a;
Vector!(int, size_t) b; // both work with IntegralConstant

could use __traits(compiles) to see if it's not a type, for that 
second static if. Which would probably be better, so if you pass 
a float or something, it won't give a weird error.


Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Jerry via Digitalmars-d-learn

On Monday, 7 November 2016 at 18:42:37 UTC, Picaud Vincent wrote:

template isIntegralConstant(ANY)
{
enum bool 
isIntegralConstant=__traits(identifier,ANY)=="IntegralConstant";

}


A bit more elegant way of doing that would be:

enum isIntegralConstant(T) = is(T : IntegralConstant!U, U...);


I would be very graceful for any help/advice that explains the 
right way to implement C++ std::integral_constant in 
the D language.


Vincent


Now the question is, do you really need IntegralConstant? I've 
never used it in C++ so I don't really know any of the use cases 
for it. But generally in D if you need something to be a compile 
time constant value you can just use "enum". It can be any type 
as well, so long as it can be evaluated at compile time.


enum long someConstant = 1 << 32;




Re: Judy Arrays

2016-08-27 Thread Jerry via Digitalmars-d-learn

On Thursday, 25 August 2016 at 20:42:42 UTC, Illuminati wrote:

http://judy.sourceforge.net/downloads/10minutes.htm

Would be nice to have such an implementation. Supposedly one of 
the best all around data structures in existence? Maybe D could 
be used to make them work with arbitrary cache-sizes?


Anyone up for the challenge?


There is a version of it on dub.

http://code.dlang.org/packages/judy


Re: Remove stuff from a template mixin

2016-07-26 Thread Jerry via Digitalmars-d-learn

On Tuesday, 26 July 2016 at 19:02:32 UTC, Gorge Jingale wrote:
I might want to actually use Add internally in B so I can add 
some elements behind the scenes, I do not want to expose it to 
the outside world though.


There are no way to remove things from an template directly. But 
you could however generate a new type which does not carry the 
specified members.


This requires two steps:
*The member filtering part
*Generation part

For the masking part take a look at
https://forum.dlang.org/post/nn8gj8$6s5$1...@digitalmars.com

What you basicly do is that you iterate the members and based on 
some condition filters out the members you don't want.


Then for generating you have to handle functions and fields.
For fields a string concatenated with other strings fields is 
probably good enough.

Something like this:
 "typeof(" ~ fullyQualifiedName!Aggregate ~ "." ~ memberName 
~ ") " ~ member;"





Re: unittests not being run

2016-07-15 Thread Jerry via Digitalmars-d-learn

Unittests have to be inside a module to be run on DMD atleast.
So putting module foo at top should fix it.


Re: Result Types and void usage

2016-07-15 Thread Jerry via Digitalmars-d-learn

On Friday, 15 July 2016 at 08:11:13 UTC, nik wrote:

//unittest
//{
//  auto result_1 = Result!(void, string)(void);
//  auto result_2 = Result!(void, string)(void);
//  assert(result_1.is_result);
//  assert(result_1 == result_2);
//}


You wanted to handle the void case?

Because there are no void type you have to check the type at 
compile time.

Enter static if...

static if(!is(T == void)) {
T result() const pure nothrow @safe @property
{
return _result;
}
}

static if(!is(T == void))
T _result;

static if(!is(T == void)) {
this(inout T result) inout
{
_result = result;
_is_result = true;
}
} else {
this() {
_is_result = true;
 //Or whatever semantics Rust use for void result
}
}


And about conditional compilation (static if, version etc...):
https://dlang.org/spec/version.html



Re: VibeCustomMain not working

2016-04-07 Thread Jerry via Digitalmars-d-learn

On Thursday, 7 April 2016 at 13:17:32 UTC, Jerry wrote:

On Thursday, 7 April 2016 at 13:13:14 UTC, Suliman wrote:

dup upgdare

dub upgdare


Tried that. I have to say this is odd.


I generated a visuald project and tried that. Now suddenly it is 
working as expected. So I guess it's a bug in dub.


Re: VibeCustomMain not working

2016-04-07 Thread Jerry via Digitalmars-d-learn

On Thursday, 7 April 2016 at 13:13:14 UTC, Suliman wrote:

dup upgdare

dub upgdare


Tried that. I have to say this is odd.


VibeCustomMain not working

2016-04-07 Thread Jerry via Digitalmars-d-learn

Hello, I am trying to use vibe with DMD 2.67, dub and windows.
But in some way the default main function is sneaking in my build 
system even when I'm using VibeCustomMain version.


Main file:

import vibe.vibe;

void main() {
   writeln("Hello world");
}


And dub file:

{
"targetType": "executable",
"versions": [ "VibeCustomMain" ],
"dependencies": {
"luad": "~master",
"kxml": "~>1.0.1",
"jsonizer": "~>0.5.2",
"vibe-d": "==0.7.23"
}
}


I also tried this on DMD 2.71, 2.69 with same results. And I even 
tryed passing in VibeCustomMain manually.


Any ideas?


Re: Trying to use Dustmite on windows

2016-03-22 Thread Jerry via Digitalmars-d-learn
On Tuesday, 22 March 2016 at 09:19:27 UTC, Vladimir Panteleev 
wrote:

On Tuesday, 22 March 2016 at 09:11:52 UTC, Jerry wrote:

So I want to pass my DUB project to Dustmite and use findstr


For reducing dub projects, try the "dub dustmite" command, e.g.
 "--compiler-regex=Assertion failure".


Thanks that works nice. But now my Initial run fails.
Using
dub dustmite ../testReduction --compiler-regex="Assertion failure"

However when I navigate to the testReduction directory and runs 
dub I get error message:

Assertion failure: '0' on line 1942 in file 'glue.c'


Trying to use Dustmite on windows

2016-03-22 Thread Jerry via Digitalmars-d-learn

I am really not used to bash scripts.
I am trying to use Dustmite on my project since I have started 
getting an
"Assertion failure: '0' in glue.c on line 1492" and really can 
not find any issue about it in the issue tracker.


So I want to pass my DUB project to Dustmite and use findstr bash 
command to figure out result. So what I come up with was this:


dustmite source "dub run | findstr /b /C:\"Assertion failure\""


But findstr is failing with error message:

"Can not open failure"

/Jerry


Sort using Uniform call syntax

2016-03-14 Thread Jerry via Digitalmars-d-learn
I have a small problem with using UCS when sorting arrays. This 
pops a warning telling me to use the algorithm sort instead of 
the property sort. Which I understand why it works that way. 
However that means I can not have syntactic sugar. So is there 
any way around this or do I just have to live with it?


Re: SIGSEGV when using D DLL with Qt MinGW

2016-02-23 Thread Jerry via Digitalmars-d-learn

On Tuesday, 23 February 2016 at 11:10:30 UTC, Mike Parker wrote:


I'm surprised you're able to get an executable when linking 
with the import library.


I actually just tried a bunch of extern(?), extern "?" 
combinations and it compiled.


If you want 32-bit COFF output from DMD, you'll need to make 
sure you have the Microsoft compiler tools installed (Visual 
Studio Community Edition is an easy way to get everything you 
need) and use the -m32mscoff command line switch with DMD when 
compiling your DLL. However, there are often incompatibilities 
between MinGW's COFF and Microsoft's COFF, so you may still get 
no joy.


I guess I should switch C++ compiler then. Just to stay on the 
safe side. Maybe Clang. Tryed to Google for the format but didn't 
find it. Also it seems someone has compiled Qt using it.


SIGSEGV when using D DLL with Qt MinGW

2016-02-23 Thread Jerry via Digitalmars-d-learn
Hello guys, as the title says I'm getting a SIGSEGV when trying 
to use a D DLL.


Let's take a look on this C++ code:


extern "C" __declspec(dllimport) void D_user_fillEngine(const 
char* workDir, void* engine);

extern "C" __declspec(dllimport) int D_user_startUp();
extern "C" __declspec(dllimport) int D_user_terminate();

int main(int argc, char *argv[])
{
D_user_startUp();
D_user_fillEngine("path", nullptr);
QApplication app(argc, argv);

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

int res = app.exec();
D_user_terminate();
return res;
}


Just normal Qt startup code with some external DLL 
loading/calling by OS.
The D_user_* calls just have to be there to cause the SIGSEGV, 
not being executed. So I guess something is wrong with the way 
this DLL is loaded.


And the D code:

export extern(C) void D_user_fillEngine(char* c_workDir, void* 
c_qmlEngine) {

 //Foo
}

export extern(C) int D_user_startUp() {
 //Intended for rt_init();
}

export extern(C) int D_user_terminate() {
//Intended for rt_term();
}


I am using the following environment:

Windows 7
Qt 5.5
MinGW 4.9
DMD 2.69.1
DUB (with dynamicLibrary option)

Everything is x86.

I am really stuck here. Thanks on beforehand.


Formatted read of tokens?

2014-06-17 Thread Jerry via Digitalmars-d-learn
Hi all,

I'm porting some C++ code into D that uses istream to read lines like

label 3

where there can spaces or tabs between the 2 fields.  In c++, this is:

string l;
int i;
istr  l  i;

What's the equivalent in D?  It appears that D formatted read for
strings grabs everything up to a newline and doesn't support whitespace
tokenization.

If I do

f.readf(%s %s, l, i);

it fails if the whitespace is a tab.

Thanks
Jerry


Re: Formatted read of tokens?

2014-06-17 Thread Jerry via Digitalmars-d-learn
bearophile bearophileh...@lycos.com writes:

 Jerry:

 If I do

 f.readf(%s %s, l, i);

 it fails if the whitespace is a tab.

 In you can use byLine, followed by a split, and then assignment of the pieces,
 followed by to!int where necessary.

I actually can't use byLine in this instance.  I'm really wanting the %s
behavior of scanf().


Re: Formatted read of tokens?

2014-06-17 Thread Jerry via Digitalmars-d-learn
John Colvin john.loughran.col...@gmail.com writes:

 On Tuesday, 17 June 2014 at 13:16:38 UTC, Jerry wrote:
 bearophile bearophileh...@lycos.com writes:

 Jerry:

 If I do

 f.readf(%s %s, l, i);

 it fails if the whitespace is a tab.

 In you can use byLine, followed by a split, and then assignment of the
 pieces,
 followed by to!int where necessary.

 I actually can't use byLine in this instance.  I'm really wanting the %s
 behavior of scanf().

 If you really need/want fscanf behaviour then just use it:

 import core.stdc.stdio : fscanf;

Thanks, I forgot the obvious.

It would be nice to have a way to do the same thing in D formatted
reading.  Does it seem like it would be useful to specify this kind of
thing?

For example, you could have:

%' ' grabs all isWhite() chars
%t   reads a single token - all chars !isWhite()

Any takers?

Jerry