Re: Add a precompiled c++ obj file to dub

2017-10-07 Thread user1234 via Digitalmars-d-learn

On Sunday, 8 October 2017 at 02:58:36 UTC, Fra Mecca wrote:

On Saturday, 7 October 2017 at 23:54:50 UTC, user1234 wrote:

On Saturday, 7 October 2017 at 19:56:52 UTC, Fra Mecca wrote:

Hi all,
I am writing a backend that is partly Vibe.d and partly 
clucene in c++.
I have some object files written in c++ and compiled with g++ 
that are not considered by dub during the linking phase and 
throws `function undefined error ` every time.


Is there a way to tell dub to let dmd handle that .o files?


Yes, add this to your JSON:

  "sourceFiles-linux-x86_64" : [
"somepath/yourobject.o"
  ],


I tried the sourceFiles approach, it failed and I could 
reproduce that in some days.


At the end I added them as linking options (lflags) but it is 
kinda odd that it works given that everything is supplied to 
dmd as -Lobj.o


Huh, i'm surprised but well, if it works for you.
My advice was based on 
https://github.com/BBasile/dbeaengine/blob/master/dub.json 
(object file is passed to dmd) which works, I often use it.


Re: Add a precompiled c++ obj file to dub

2017-10-07 Thread Fra Mecca via Digitalmars-d-learn

On Saturday, 7 October 2017 at 23:54:50 UTC, user1234 wrote:

On Saturday, 7 October 2017 at 19:56:52 UTC, Fra Mecca wrote:

Hi all,
I am writing a backend that is partly Vibe.d and partly 
clucene in c++.
I have some object files written in c++ and compiled with g++ 
that are not considered by dub during the linking phase and 
throws `function undefined error ` every time.


Is there a way to tell dub to let dmd handle that .o files?


Yes, add this to your JSON:

  "sourceFiles-linux-x86_64" : [
"somepath/yourobject.o"
  ],


I tried the sourceFiles approach, it failed and I could reproduce 
that in some days.


At the end I added them as linking options (lflags) but it is 
kinda odd that it works given that everything is supplied to dmd 
as -Lobj.o


Re: Double ended arrays?

2017-10-07 Thread Ali Çehreli via Digitalmars-d-learn

On 10/07/2017 05:02 PM, Steven Schveighoffer wrote:

> 
https://github.com/schveiguy/dcollections/blob/master/dcollections/Deque.d

>
> It's implemented by maintaining 2 dynamic arrays, one that is "reversed"
> at the front, and one that is normal at the back. When you prepend, it
> appends to the "reverse" array.
>
> It's probably not the most efficient, but it does maintain the correct
> complexities.

I stole the idea from one of Chuck Allison's DConf talks[1] and used as 
the example for the Indexing Operators section here:



http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.opIndex

> Note: that code is many years old, so it may not compile with the latest
> compiler.

Mine is supposed to compile with 2.076.

> -Steve

Ali

[1] He knows about the theft. :)



Re: Double ended arrays?

2017-10-07 Thread Steven Schveighoffer via Digitalmars-d-learn

On 10/7/17 3:38 AM, Chirs Forest wrote:
I have some data that I want to store in a dynamic 2d array... I'd like 
to be able to add elements to the front of the array and access those 
elements with negative integers as well as add numbers to the back that 
I'd acess normally with positive integers. Is this something I can do, 
or do I have to build a container to handle what I want?


Dcollections has something like this, a deque. It doesn't use negative 
integers to access the prepended elements, but I suppose it could be 
made to do this.


See here:

https://github.com/schveiguy/dcollections/blob/master/dcollections/Deque.d

It's implemented by maintaining 2 dynamic arrays, one that is "reversed" 
at the front, and one that is normal at the back. When you prepend, it 
appends to the "reverse" array.


It's probably not the most efficient, but it does maintain the correct 
complexities.


Note: that code is many years old, so it may not compile with the latest 
compiler.


-Steve


Re: Add a precompiled c++ obj file to dub

2017-10-07 Thread user1234 via Digitalmars-d-learn

On Saturday, 7 October 2017 at 19:56:52 UTC, Fra Mecca wrote:

Hi all,
I am writing a backend that is partly Vibe.d and partly clucene 
in c++.
I have some object files written in c++ and compiled with g++ 
that are not considered by dub during the linking phase and 
throws `function undefined error ` every time.


Is there a way to tell dub to let dmd handle that .o files?


Yes, add this to your JSON:

  "sourceFiles-linux-x86_64" : [
"somepath/yourobject.o"
  ],


Add a precompiled c++ obj file to dub

2017-10-07 Thread Fra Mecca via Digitalmars-d-learn

Hi all,
I am writing a backend that is partly Vibe.d and partly clucene 
in c++.
I have some object files written in c++ and compiled with g++ 
that are not considered by dub during the linking phase and 
throws `function undefined error ` every time.


Is there a way to tell dub to let dmd handle that .o files?


exclude members at compile time

2017-10-07 Thread Alex via Digitalmars-d-learn

Ok, what I'm trying to do is the following:
take a type and a value of its type; given a known member of the 
type, (re?)create a similar type, without this very known member.


What does work is this:

/// --- code ---
void main()
{
S s;
s.i = 42;
s.d = 73.0;
s.s.length = 5;
s.s[] = 1024;
s.c = 'c';

auto n = exclude!"i"(s);
static assert(!__traits(compiles, n.i));
assert(n.d == s.d);
assert(n.s == s.s);
assert(n.c == s.c);
n.s[0] = 55;
assert(n.s == s.s); // works, even by reference.
}

struct S
{
int i;
double d;
size_t[] s;
char c;

//auto fun(){} // <-- a function does not work, line 26
}

auto exclude(string without, T)(T t)
{
immutable b = [ __traits(allMembers, T) ];

struct Result
{
static foreach(i, _; b)
{
static if(without != b[i])
{
mixin(
typeof(__traits(getMember, T, 
b[i])).stringof ~
" " ~
__traits(getMember, T, b[i]).stringof ~
";"
);

}
}   
}
Result res;
static foreach(i, _; b)
{
static if(without != b[i])
{
__traits(getMember, res, b[i]) = __traits(getMember, t, 
b[i]);
}
}
return res;
}
/// --- code ---

And the problem lies in line 26: If there is a method inside the 
type, it won't work this way.


I assume, there should be a way, to copy the original type first 
and to hide a member afterwards. Is there a simple approach for 
this?


I think, the problem with my approach is, that if the member is 
not a "data" member, than there are a plenty of possibilities to 
check, like... function, template, well... there could be very 
much types of indirections, as checking for "isCallable" is not 
enough for recreation(?)
If these checks are the only way to handle this, than the answer 
to my whole question is:

"recreation is restricted to PODs".

Then, I have to consider which checks to implement, and which 
restrictions have to be applied to the input...


Re: Infuriating DUB/DMD build bug.

2017-10-07 Thread WhatMeForget via Digitalmars-d-learn

On Friday, 6 October 2017 at 23:02:56 UTC, Laeeth Isharc wrote:

On Thursday, 5 October 2017 at 21:48:20 UTC, WhatMeWorry wrote:


I've got a github project and using DUB with DMD and I keep 
running into this problem. I've tried deleting the entire 
...\AppData\Roaming\dub\packages folder, but the

problem repeats the very next build attempt.

[...]


See my post in learn on dmd path.  The dmd path code was 
written in 1987 and could do with an update to process longer 
windows paths properly.  We are working on this and I guess a 
chance a pull request on Monday but it depends on what else 
comes up.  In any case it's a trivial fix.


Presuming I am right about it being a path length problem.


I did! But i didn't say anything because i wasn't sure if they 
were related. I'm pretty sure it is path related because the 
exact same dub.sdl files work fine on Linux and MacOS. (It's a 
cross platform project)


Glad it is a trivial fix. Curious what it involves.  Let me know 
if I can help out in any way.  Mike Parker was kind enough to 
show me a manual dub local workaround for this issue. But I'll 
hold off now and see if your change does the fix.


If it does, it will be the best timed bug fix ever :)


Re: Implementing swap for user-defined swaps

2017-10-07 Thread ag0aep6g via Digitalmars-d-learn

On 10/07/2017 07:55 PM, Balagopal Komarath wrote:
   I was implement my own range type that forwards all accesses to 
another range. I tried to write a `swap` function so that sort etc. 
could be called on my range. However, I cannot get 
`hasSwappableElements!ARange` to evaluate to true. But, when I copy 
pasted the definition of `hasSwappableElements` into my module and 
evaluated it, it was true. I assume this is something to do with how 
name lookup works in D. Here's simplified code that reproduces the same 
problem.


https://dpaste.dzfl.pl/48a420cce261


You can't provide your own swap function. `sort` etc. use 
std.algorithm.swap, so your range has to work with that.


Re: @nogc formattedWrite

2017-10-07 Thread jmh530 via Digitalmars-d-learn

On Saturday, 7 October 2017 at 18:14:00 UTC, Nordlöw wrote:


It would be nice to be able to formatted output in -betterC...


Agreed. If you know the size of the buffer, you can use sformat, 
which might be @nogc, but I don't know if it's compatible with 
betterC. Also, you might check out Ocean, which might have nogc 
formatting.

https://github.com/sociomantic-tsunami/ocean


@nogc formattedWrite

2017-10-07 Thread Nordlöw via Digitalmars-d-learn
Is it currently possible to somehow do @nogc formatted output to 
string?


I'm currently using my `pure @nogc nothrow` array-container 
`CopyableArray` as


@safe pure /*TODO nothrow @nogc*/ unittest
{
import std.format : formattedWrite;
const x = "42";
alias A = CopyableArray!(char);
A a;
a.formattedWrite!("x : %s")(x);
assert(a == "x : 42");
}

but I can't tag the unittest as `nothrow @nogc` because of the 
call to `formattedWrite`. Is this because `formattedWrite` 
internally uses the GC for buffer allocations or because it may 
throw?


It would be nice to be able to formatted output in -betterC...


Implementing swap for user-defined swaps

2017-10-07 Thread Balagopal Komarath via Digitalmars-d-learn

Hello,

  I was implement my own range type that forwards all accesses to 
another range. I tried to write a `swap` function so that sort 
etc. could be called on my range. However, I cannot get 
`hasSwappableElements!ARange` to evaluate to true. But, when I 
copy pasted the definition of `hasSwappableElements` into my 
module and evaluated it, it was true. I assume this is something 
to do with how name lookup works in D. Here's simplified code 
that reproduces the same problem.


https://dpaste.dzfl.pl/48a420cce261

Thanks,
Balagopal.


Re: DLL hell :S

2017-10-07 Thread Ian Hatch via Digitalmars-d-learn
On Saturday, 7 October 2017 at 15:30:30 UTC, rikki cattermole 
wrote:
A little from column a, a little from column b, but most 
because he might be able to do something for you.


Thanks, I'll send him an email.


Re: DLL hell :S

2017-10-07 Thread rikki cattermole via Digitalmars-d-learn

On 07/10/2017 4:29 PM, Ian Hatch wrote:

On Saturday, 7 October 2017 at 15:14:01 UTC, rikki cattermole wrote:

Email Walter directly.

I intend to campaign for next years (basically a soft TODO list) plan 
for what we want done. But until then, he and Andrei need to hear that 
this is the biggest limitation that D faces currently, not memory 
management.


Hm, are you saying "if you email Walter he can tell you how to sort it" 
or "please make sure Walter knows this problem is important" (or both)?  
Definitely happy to give my feedback.


A little from column a, a little from column b, but most because he 
might be able to do something for you.


"not memory management" gives me an idea actually - if I ditch the GC, 
which I may want to do eventually anyway, I guess I won't have this issue.




Re: DLL hell :S

2017-10-07 Thread Ian Hatch via Digitalmars-d-learn
On Saturday, 7 October 2017 at 15:14:01 UTC, rikki cattermole 
wrote:

Email Walter directly.

I intend to campaign for next years (basically a soft TODO 
list) plan for what we want done. But until then, he and Andrei 
need to hear that this is the biggest limitation that D faces 
currently, not memory management.


Hm, are you saying "if you email Walter he can tell you how to 
sort it" or "please make sure Walter knows this problem is 
important" (or both)?  Definitely happy to give my feedback.


"not memory management" gives me an idea actually - if I ditch 
the GC, which I may want to do eventually anyway, I guess I won't 
have this issue.


Re: DLL hell :S

2017-10-07 Thread rikki cattermole via Digitalmars-d-learn

Email Walter directly.

I intend to campaign for next years (basically a soft TODO list) plan 
for what we want done. But until then, he and Andrei need to hear that 
this is the biggest limitation that D faces currently, not memory 
management.


DLL hell :S

2017-10-07 Thread Ian Hatch via Digitalmars-d-learn

Hello!

I'm Ian, and I've been a programmer in games for 10 years.  I've 
been poking at D for a year or so and I'm absolutely in love with 
the compile-time execution and inline unit testing in particular.


I've been trying for a while to set up a project that I intend to 
build a lot of my future code on top of, but I'm stumbling at one 
of the first hurdles at the moment so I'm hoping I can straighten 
this out and be able to keep using D.


My framework is supposed to load plugin dlls (and later 
sharedobjects) which operate on memory allocated by the 
executable, and sadly I've hit roadblock after roadblock trying 
to get this set up.


Following https://wiki.dlang.org/Win32_DLLs_in_D I've gotten to a 
stage where I successfully load the DLL, find my functions, and 
call them passing the objects to be modified.


Initially this was crashing immediately.  After a lot of digging 
I found https://issues.dlang.org/show_bug.cgi?id=17326, so now 
I've added the gcopt to my dll to set the gc to manual, and I'm 
passing over my gc pointer and trying to set it as the proxy.


Unfortunately this results in the DLL getting stuck in a spinlock 
in addRange within gc_setProxy() :(


DLL side:
https://pastebin.com/yBPs0A30

EXE side:
https://pastebin.com/h2qLBqXA

Thread lock call stack:
https://pastebin.com/zUvH3Cnb

I'm not really sure where to go from here.  I'm doing this in my 
spare time and I've been stuck for months on something I know how 
to do in C++ (I really should have asked for help earlier).  Is 
there an up to date example someone can point me to of how to set 
this up correctly so that the DLL uses the exe's runtime and/or 
garbage collector?


Re: Need importing dcompute.lib into my project

2017-10-07 Thread kerdemdemir via Digitalmars-d-learn

On Saturday, 7 October 2017 at 12:12:10 UTC, kinke wrote:

On Saturday, 7 October 2017 at 09:04:26 UTC, kerdemdemir wrote:

Error: static assert  "Need to use a DCompute enabled compiler"


Are you using latest LDC 1.4? The CUDA backend wasn't enabled 
for earlier versions.


Yes I am. Actually I can build dcompute's source code so I am 
sure LDC version is good. Now I am trying to use dcompute within 
my project.


Re: Need importing dcompute.lib into my project

2017-10-07 Thread kinke via Digitalmars-d-learn

On Saturday, 7 October 2017 at 09:04:26 UTC, kerdemdemir wrote:

Error: static assert  "Need to use a DCompute enabled compiler"


Are you using latest LDC 1.4? The CUDA backend wasn't enabled for 
earlier versions.


Re: Need importing dcompute.lib into my project

2017-10-07 Thread kerdemdemir via Digitalmars-d-learn
do you set "-mdcompute-targets=cuda-xxx" in the dflags for your 
dub.json for your project?


I have added now after your comment.

But it seems it didn't changed anything.

Here is the dub.json file I have:
{
"name": "dsharpear",
"authors": [
"Erdem"
],
"dflags" : ["-mdcompute-targets=cuda-210" ,"-oq", "-betterC"],
"dependencies": {
"dcompute": ">=0.0.0-alpha0 <0.1.0"
},
"description": "Beamforming with D ",
"copyright": "Copyright © 2017, Erdem",
"license": "proprietary"
}

And running "dub build --compiler=D:\LDCDownload\bin\ldc2.exe 
--force"  fails with:


Performing "debug" build using D:\LDCDownload\bin\ldc2.exe for 
x86.

derelict-util 2.1.0: building configuration "library"...
derelict-cl 2.0.0: building configuration "library"...
derelict-cuda 2.0.1: building configuration "library"...
..\..\..\..\..\AppData\Roaming\dub\packages\derelict-cuda-2.0.1\derelict-cuda\source\derelict\cuda\runtimeapi.d(816,5):
 Deprecation: constructor derelict.cuda.runtimeapi.dim3.this
all parameters have default arguments, but structs cannot have 
default constructors.

dcompute 0.0.0-alpha0: building configuration "library"...
Targeting 'i686-pc-windows-msvc' (CPU 'pentium4' with features '')
Building type: real
Building type: uint
Building type: char
Building type: ubyte
Building type: ulong
Building type: int
Building type: double
Building type: long
Building type: ushort
Building type: wchar
Building type: byte
Building type: short
Building type: float
Building type: dchar
..\..\..\..\..\AppData\Roaming\dub\packages\dcompute-0.0.0-alpha0\dcompute\source\dcompute\std\package.d(6,5):
 Error: static assert  "Need to use a DCompute enabled compiler
See https://github.com/thewilsonator/ldc/tree/dcompute;
D:\LDCDownload\bin\ldc2.exe failed with exit code 1.


Re: Need importing dcompute.lib into my project

2017-10-07 Thread Nicholas Wilson via Digitalmars-d-learn

On Saturday, 7 October 2017 at 09:04:26 UTC, kerdemdemir wrote:

You should add DCompute as a DUB dependancy.


Hi,

I inited my project with Dub by unsing  "dub init DSharpEar" 
and I added dependency "dcompute".


Even I give extra parameters for using ldc.

 dub build --compiler=D:\LDCDownload\bin\ldc2.exe --force

I am getting :

Error: static assert  "Need to use a DCompute enabled compiler"

Any suggestions?

Regards
Erdem


do you set "-mdcompute-targets=cuda-xxx" in the dflags for your 
dub.json for your project?


Re: Need importing dcompute.lib into my project

2017-10-07 Thread kerdemdemir via Digitalmars-d-learn

You should add DCompute as a DUB dependancy.


Hi,

I inited my project with Dub by unsing  "dub init DSharpEar" and 
I added dependency "dcompute".


Even I give extra parameters for using ldc.

 dub build --compiler=D:\LDCDownload\bin\ldc2.exe --force

I am getting :

Error: static assert  "Need to use a DCompute enabled compiler"

Any suggestions?

Regards
Erdem


Re: Double ended arrays?

2017-10-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 07, 2017 07:38:47 Chirs Forest via Digitalmars-d-learn 
wrote:
> I have some data that I want to store in a dynamic 2d array...
> I'd like to be able to add elements to the front of the array and
> access those elements with negative integers as well as add
> numbers to the back that I'd acess normally with positive
> integers. Is this something I can do, or do I have to build a
> container to handle what I want?

Dynamic arrays only support concatenating to the end, and they use size_t
for indices and length, and size_t is unsigned. The standard library does
the same with any containers that it has as do most 3rd party libraries.

You'll need to either implement what you want yourself or use something from
somewhere like code.dlang.org. Based on Ilya's post, it sounds like you may
be able to use Mir for what you want, but I'd be very surprised to see any
libraries use negative indices for anything - especially since most
everything uses size_t for indices.

- Jonathan M Davis



Re: Double ended arrays?

2017-10-07 Thread Ilya Yaroshenko via Digitalmars-d-learn

On Saturday, 7 October 2017 at 07:38:47 UTC, Chirs Forest wrote:
I have some data that I want to store in a dynamic 2d array... 
I'd like to be able to add elements to the front of the array 
and access those elements with negative integers as well as add 
numbers to the back that I'd acess normally with positive 
integers. Is this something I can do, or do I have to build a 
container to handle what I want?


Mir Algorithm [1] has 2D arrays. Elements can be added to the 
front/back of each dimension using `concatenation` routine [2]. 
In the same time it does not support negative indexes.


[1] https://github.com/libmir/mir-algorithm

[2] 
http://docs.algorithm.dlang.io/latest/mir_ndslice_concatenation.html#.concatenation


Best regards,
Ilya Yaroshenko


Double ended arrays?

2017-10-07 Thread Chirs Forest via Digitalmars-d-learn
I have some data that I want to store in a dynamic 2d array... 
I'd like to be able to add elements to the front of the array and 
access those elements with negative integers as well as add 
numbers to the back that I'd acess normally with positive 
integers. Is this something I can do, or do I have to build a 
container to handle what I want?