Re: Missing library dependencies compiling app with importC

2024-02-22 Thread Danny Arends via Digitalmars-d-learn

On Thursday, 22 February 2024 at 01:23:36 UTC, ptcute wrote:

Greeings!

My c to d header wrapper file curl_d.c (just 2 lines):
...
So what's the real issue behind?

Anyone help on this would be appreciated.



According to the windows documentation, you'll need: Kernel32.lib

See: 
https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-interlockedexchange






Re: How to use Dub and Digger to build Pull Requests?

2023-05-24 Thread Danny Arends via Digitalmars-d-learn

On Tuesday, 23 May 2023 at 13:51:29 UTC, Quirin Schroll wrote:

On Tuesday, 23 May 2023 at 13:50:09 UTC, Quirin Schroll wrote:

The dlang-bot writes a message to every PR:

 Testing this PR locally

If you don't have a local development environment setup, you 
can use Digger to test this PR:

```bash
dub run digger -- build "master + dmd#<>"
```


I installed the current DMD (version 2.103.1) and executed the 
above command; I’m getting the following error:


For the record, I tried multiple PRs and plain `"master"`. It 
doesn’t seem to be related to the particular PR.


Seems to be a version conflict...
You mentioned that you used: version 2.103.1
However the DMD being called is in:

Documents\\d\\mydmd\\work\\dl\\dmd-2.079.0

so it seems to be 2.079.0




Re: request assistance resolving a std.net.curl segmentation fault

2023-05-19 Thread Danny Arends via Digitalmars-d-learn

On Friday, 19 May 2023 at 11:07:01 UTC, anonymouse wrote:

What am I doing wrong here?

```D
import std.net.curl: Curl, CurlOption, CurlException;
import std.file: exists;
import std.stdio: File, writefln;
import core.thread: Thread;

void downloadFile(string url, string filename)
{
while (true) {
try {
File fp;
if (filename.exists())
fp.open(filename, "a");
else
fp.open(filename, "w");
Curl curl;
curl.initialize();
curl.onProgress = delegate int(size_t dltotal, 
size_t dlnow, size_t ultotal, size_t ulnow)

{
writefln("Progress: %s of %s", dlnow, dltotal);
return 0;
};
curl.set(CurlOption.url, url~filename);
curl.set(CurlOption.resume_from_large, fp.size());

// Start the download
curl.set(CurlOption.writedata, );
curl.perform();

// Close the file
fp.close();
writefln("Download as %s complete.", filename);
break;
} catch (CurlException e) {
writefln("Error while downloading: %s", e.msg);

// Wait for a bit before retrying
Thread.sleep(imported!"core.time".seconds(10));
}
}
}

void main()
{
string url = 
"https://downloads.dlang.org/releases/2.x/2.103.1/;;

string filename = "dmd.2.103.1.dmg";

downloadFile(url, filename);
}
```
Output:
```
./download_file
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
Progress: 0 of 0
zsh: segmentation fault  ./download_file
```

Thanks.

--anonymouse


You're running the whole thing in a while(TRUE) loop, recreating 
the curl object re-initiating the transfer and file pointer, etc. 
furthermore, the  curl.set(CurlOption.writedata, 
); doesn't work as you expect..


After fiddling a bit, this works:

```D
import std.net.curl: Curl, CurlOption, CurlException;
import std.file: exists;
import std.stdio: File, writefln;
import core.thread: Thread;

void downloadFile(string url, string filename){
  try {
File fp;
fp.open(filename, "w");
Curl curl;
curl.initialize();
curl.onProgress = delegate int(size_t dltotal, size_t dlnow, 
size_t ultotal, size_t ulnow){

  writefln("Progress: %s of %s", dlnow, dltotal);
  return 0;
};
curl.onReceive = (ubyte[] data) { fp.rawWrite(data); return 
data.length;};


curl.set(CurlOption.url, url~filename);
// Start the download
curl.perform();

writefln("Download as %s complete.", filename);
  } catch (CurlException e) {
writefln("Error while downloading: %s", e.msg);
  }
}

void main(){
  string url = 
"https://downloads.dlang.org/releases/2.x/2.103.1/;;

  string filename = "dmd.2.103.1.dmg";
  downloadFile(url, filename);
}
```


DUB issues

2022-04-17 Thread Danny Arends via Digitalmars-d-learn

Hey All,

For some reason I cannot reset my password to get into dub 
(https://code.dlang.org/), after trying I never receive the email 
to reset my password.


I was unsure at first if I had signed up at all, but trying to 
make a new account tells me my email address is already in use.


Any ideas how to get into contact/fix this issue ?




Re: Sort bug / strangeness

2021-10-01 Thread Danny Arends via Digitalmars-d-learn
On Friday, 1 October 2021 at 17:53:24 UTC, Steven Schveighoffer 
wrote:
I think your struct is different than this, because this only 
happens if aliasing is inside the struct being sorted (i.e. it 
has pointers). Your presented struct doesn't have pointers, and 
the code you linked to is completely parameterized on the 
struct type.


If it does have pointers, you are not allowed to swap the 
values if either points to each other (or themselves).


Thanks Steve for saving Friday,

The struct has indeed a parent pointer, It's a pretty big struct 
so just posted the excerpt (sorry). So that's the cause then.


So how to sort this N[] object by f() then ?

The pointer is only used to be traversed back after the search 
has finished. Is there a sort() algorithm that avoids swapping 
the items themselves and e.g. just returns the indexes so I can 
reorder the original array myself ?


Danny


Sort bug / strangeness

2021-10-01 Thread Danny Arends via Digitalmars-d-learn

Hey all,

Using a modified 3D A* tile searching algorithm, full code see:

https://github.com/DannyArends/CalderaD/blob/master/src/math/search.d

I get the following AssertError, 'sometimes' but not always on 
running the code:


mutation.d(2816): Swap: rhs points to lhs.

the first time I hit Phobos is because I call the 
std.algorithm.sorting.sort function to sort my open list (just an 
array of search node objects);


```
search.openlist.sort!("a.f < b.f")();
```

sneakily f here is a @property function of the object, which just 
computes and returns a float:


```
// sum of cumulative cost of this node + predecessors + heuristic
struct Node {
  float g; // cost of this node + it's predecessors
  float h; // heuristic estimate of distance to goal
  @nogc @property float f() nothrow const { return(this.g + 
this.h); }

}
```

For the life of me I cannot fathom, how 2 function calls would 
end up pointing to the same memory location ?


To mention (might be relevant or not, I'm lost badly), the search 
struct around the map is parameterized. because I want to give 
objects the ability to have their own map walker definition (eg. 
ground, ground+air, ground+shallow water ). I am using the 
following wrapper struct:


```
struct Search(M, N) {
  N[] openlist; // Astar open list
  N[] closedlist; // Astar closed list
}
```

Anyone got some idea what I'm doing wrong, or explain me why I am 
messing up my Dijkstra here ?


Thanks,

Danny

Full stack trace/ dump below:

```
core.exception.AssertError@C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\mutation.d(2816):
 Swap: rhs points to lhs.

0x00014008A2E3 in d_assert_msg
0x000140056F35 in 
std.algorithm.mutation.swap!(searchnode.Node).swap at 
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\mutation.d(2816)
0x000140057A07 in 
std.algorithm.mutation.swapAt!(searchnode.Node[]).swapAt at 
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\mutation.d(3090)
0x0001400582BE in std.algorithm.sorting.medianOf!(binaryFun, 
Flag.no, searchnode.Node[], ulong, ulong, ulong).medianOf at 
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\sorting.d(4237)
0x000140057DF4 in std.algorithm.sorting.getPivot!(binaryFun, 
searchnode.Node[]).getPivot at 
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\sorting.d(1620)
0x000140057112 in 
std.algorithm.sorting.quickSortImpl!(binaryFun, 
searchnode.Node[]).quickSortImpl at 
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\sorting.d(2124)
0x000140056FB5 in std.algorithm.sorting.sort!("a.f < b.f", 
SwapStrategy.unstable, searchnode.Node[]).sort at 
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\sorting.d(1905)
0x000140050C1F in search.step!(search.Search!(Map, Node), 
searchnode.Node).step at C:\Github\CalderaD\src\math\search.d(119)
0x00014005012E in search.performSearch!(map.Map, 
searchnode.Node).performSearch at 
C:\Github\CalderaD\src\math\searchnode.d(11)
0x00014004723B in map.testGenMap at 
C:\Github\CalderaD\src\game\map.d(125)
0x00014004CD9E in main.run at 
C:\Github\CalderaD\src\main.d(32)

0x00014004CD3E in D main at C:\Github\CalderaD\src\main.d(25)
```


Re: Trivial simple OpenGl working example

2021-07-10 Thread Danny Arends via Digitalmars-d-learn

On Saturday, 10 July 2021 at 12:41:19 UTC, Виталий Фадеев wrote:

On Saturday, 10 July 2021 at 08:36:07 UTC, Danny Arends wrote:

On Thursday, 8 July 2021 at 13:51:51 UTC, Виталий Фадеев wrote:

[...]


OpenGL is being replaced by vulcan, just to plug my little 
project:


http://github.com/DannyArends/CalderaD

Pretty beafy, but well vulkan is a lot more verbose compared 
to OpenGL


Thank, Danny Arends! I see you.

I got error:

# glslc app/src/main/assets/data/shaders/wavefront.vert -o 
app/src/main/assets/data/shaders/vert.spv


# glslc app/src/main/assets/data/shaders/wavefront.frag -o 
app/src/main/assets/data/shaders/frag.spv


# dub
Performing "debug" build using /usr/bin/dmd for x86_64.
bindbc-loader 0.3.2: target for configuration "yesBC" is up to 
date.
bindbc-sdl 0.21.4: target for configuration "dynamicBC" is up 
to date.

calderad ~master: building configuration "default"...
Running pre-build commands...
/bin/sh: 1: glslc.exe: not found
Command failed with exit code 127: glslc.exe 
app/src/main/assets/data/shaders/wavefront.vert -o 
app/src/main/assets/data/shaders/vert.spv


Just disable shader compilation using dub, the shader only needs 
to be compiled once. Since you're on linux it fails to execute 
glslc.exe (the windows executable). If you compiled them yourself 
you can remove it from dub prebuild commands


Re: Trivial simple OpenGl working example

2021-07-10 Thread Danny Arends via Digitalmars-d-learn

On Thursday, 8 July 2021 at 13:51:51 UTC, Виталий Фадеев wrote:

Hi!

I searching trivial simple D/OpenGL working in 2021 year 
example.


It may be triangle.
It may be based on any library: SDL, GLFW, Derelict, etc.

Can you help me ?


OpenGL is being replaced by vulcan, just to plug my little 
project:


http://github.com/DannyArends/CalderaD

Pretty beafy, but well vulkan is a lot more verbose compared to 
OpenGL




Re: SDL2 Android vulkan question

2021-05-14 Thread Danny Arends via Digitalmars-d-learn

On Sunday, 2 May 2021 at 13:43:11 UTC, evilrat wrote:
Anyway, I might try to look at this next weekend. Do you have 
this project available on github/google drive?


Open-sourced the code see:

https://github.com/DannyArends/CalderaD

Danny


Re: SDL2 Android vulkan question

2021-05-02 Thread Danny Arends via Digitalmars-d-learn

On Sunday, 2 May 2021 at 16:42:07 UTC, evilrat wrote:

On Sunday, 2 May 2021 at 16:06:10 UTC, Danny Arends wrote:

On Sunday, 2 May 2021 at 12:35:51 UTC, evilrat wrote:

As for SDL2, are you sure it was built with Vulkan support?


That's the thing I worry about, since the SDL2 libraries are 
locally build using android studio and I'm kind of a noob in 
that.





Ok, since this is potentially the case, just to clarify, 
building C/C++ with CMake for Android these days is basically 
one extra parameter pointing to CMake toolchain file in your 
local NDK location when configuring your build.


https://developer.android.com/ndk/guides/cmake#file

(from the docs)
```
$ cmake \

-DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake 
\

-DANDROID_ABI=$ABI \
-DANDROID_NATIVE_API_LEVEL=$MINSDKVERSION \
$OTHER_ARGS

```

Then I would probably use gradle for the rest of the process to 
produce apk, including copy libraries step.


Thanks, but the APK builds fine, and installs. OpenGLES and SDL 
work like a charm, it's just the SDL_Vulkan_LoadLibrary call 
crashing. I think it might have to do with the bindbc-sdl 
dependency compiling with SDL_201 support, while Vulkan needs 
SDL_206 minimum. Even though I set SDL_2014 in DUB, it seems not 
to get picked up in some way.


I also found this: 
https://developer.android.com/guide/topics/manifest/uses-feature-element


So it might be the manifest needs to be updated as well.
A real puzzle,

Danny







Re: SDL2 Android vulkan question

2021-05-02 Thread Danny Arends via Digitalmars-d-learn

On Sunday, 2 May 2021 at 13:43:11 UTC, evilrat wrote:

On Sunday, 2 May 2021 at 12:35:51 UTC, evilrat wrote:

On Sunday, 2 May 2021 at 08:58:30 UTC, Danny Arends wrote:

Any thoughts on why loading the Vulkan library using SDL2 
would not work ?

thoughts in general about the process ?


Just few tips.
GC "crashes" since you have custom main, D default main has 
runtime initialization code so it "just works", in you custom 
main function try to do this before any call to D code.




Oops, nevermind. I thought you've missed runtime initialization 
at all but you have rt_init.
In that case you can try disable parallel collection, or it 
could be a bug.


https://dlang.org/spec/garbage.html#gc_config
https://dlang.org/spec/garbage.html#gc_parallel


As for SDL2, are you sure it was built with Vulkan support?
Do you have any other Vulkan apps to test if it actually 
supported by your device?


SDL2 docs also says vulkan load library should be called only 
after you created window surface. It is hard to say from 
provided code if you have that too.




Yeah, it's tricky to create an SDL window sometimes, like on 
android SDL_CreateWindow not being allowed to have it 
SDL_WINDOWPOS_CENTERED


I thought they meant use it like after SDL_Init(), but before you 
create the window. I think the function pointer might not be 
loaded since the SDL_Init returns a which means 2.0.1 for some 
reason.


I think something is going wrong and nothing is doing a dlopen() 
on vulkan.so


Anyway, I might try to look at this next weekend. Do you have 
this project available on github/google drive?


well it's just a bunch of files atm, but with a serious 
dependency chain, I'll try to minimize it. Guess for now the 
deprecated openGL has to be the fallback




Re: SDL2 Android vulkan question

2021-05-02 Thread Danny Arends via Digitalmars-d-learn

On Sunday, 2 May 2021 at 12:35:51 UTC, evilrat wrote:

On Sunday, 2 May 2021 at 08:58:30 UTC, Danny Arends wrote:

Any thoughts on why loading the Vulkan library using SDL2 
would not work ?

thoughts in general about the process ?


Just few tips.
GC "crashes" since you have custom main, D default main has 
runtime initialization code so it "just works", in you custom 
main function try to do this before any call to D code.


https://dlang.org/phobos/core_runtime.html#.Runtime.initialize

```d
extern(C) main()
{
import core.runtime;
Runtime.initialize();
scope(exit)
  Runtime.terminate();
}
```



Yeah, I just use the rt_init() and disable it, no real issue. 
Most of the code is @nogc code anyway.



As for SDL2, are you sure it was built with Vulkan support?


That's the thing I worry about, since the SDL2 libraries are 
locally build using android studio and I'm kind of a noob in that.


I use the provided android_project (from the sdl zip) and make 
symbolic links in the app/jni folder to:


SDL, SDL2_Image, SDL2_Mixer, Etc

I delete the creation of the libmain.so by removing the src/ 
folder


Do you have any other Vulkan apps to test if it actually 
supported by your device?


It's android 10 so it should be, but I could try creating a c 
minimal example in vulkan, although that's gonna be 500 LoC as 
well.




SDL2 Android vulkan question

2021-05-02 Thread Danny Arends via Digitalmars-d-learn

Dear all,

I've written a 2D/3D engine in D before which runs on windows, 
linux and android using SDL2 as the window manager and uses 
Modern OpenGL /OpenGLES for rendering. It compiles fine for 
android using ldc and works like a charm, although the garbage 
collection under android has multi-threading issues.


Since OpenGL is abandoned, I am currently adding Vulkan support 
to future proof it.


I have done this in D with the help of the bindbc-sdl and erupted 
packages and managed to get the whole vulkan-tutorial.com example 
working under windows without much hassle. (I bet it would run on 
linux without much issues as well)


So I have now been stuck for a week on getting the tutorial 
example to successfully run on android. To do this I get a DLL 
compiled with ldc, I have setup the SDL2 toolchain for android, 
with symlinks to SDL2/IMAGE/TTF/etc, I hook the call to SDL_main 
from the JNI:


```D
/* Main entry point to the program */
version (Android) {
  import core.memory;
  import core.runtime : rt_init;

  extern(C) int SDL_main(int argc, char* argv) { // Hijack the 
SDL main

rt_init();
GC.disable(); // The GC crashes on android
run(["android"]);
return(0);
  }
// Other OS can just call run() directly (No known issues with 
garbage collection)

} else { void main (string[] args) { run(args); } }
```

I create my APK using Android Studio, and load it onto my phone. 
The hook succeeds, I can do:


```D
loadSDL();
SDL_Log("SDL loaded");
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
SDL_Log("SDL init");
SDL_Vulkan_LoadLibrary();
SDL_Log("SDL_Vulkan_LoadLibrary");
```

I see SDL being loaded and initialized (successfully) on my 
phone. However, the SDL_Vulkan_LoadLibrary call just crashes the 
whole thing dead, with a:


```cmd
I/SDL/APP: SDL loaded
I/SDL/APP: SDL init
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault 
addr 0x0 in tid 25878 (SDLThread), pid 25794 (SDLActivity)

```

I was wondering if I am missing something obvious. Since it works 
for SDL2 and opengles


Any thoughts on why loading the Vulkan library using SDL2 would 
not work ?

thoughts in general about the process ?

Danny





Re: How to get output of piped process?

2021-03-03 Thread Danny Arends via Digitalmars-d-learn

On Monday, 22 February 2021 at 14:52:22 UTC, frame wrote:

On Monday, 22 February 2021 at 13:23:40 UTC, Danny Arends wrote:


https://github.com/DannyArends/DaNode/blob/master/danode/process.d

Danny


This example shows how easy it is to implement a non-blocking 
stream. Phobos knows this for sockets but not for pipes?


Sockets seem to be more OS independent and are way more mature in 
Phobos.


Pipes seem to have been added as an afterthought in std.process 
and std.stdio


I had to add code for windows to deal with non-blocking/buffering 
pipes, Linux uses fcntl/fileno to enable non-blocking


No idea why non-blocking pipes aren't in Phobos, but pipes should 
not be an afterthought but a first class citizen imho


Re: How to get output of piped process?

2021-03-03 Thread Danny Arends via Digitalmars-d-learn

On Tuesday, 23 February 2021 at 10:07:03 UTC, Imperatorn wrote:

On Monday, 22 February 2021 at 13:23:40 UTC, Danny Arends wrote:

On Friday, 19 February 2021 at 15:39:25 UTC, kdevel wrote:

[...]


Perhaps a bit late, but this is how I deal with pipes and 
spawnShell.

Read one byte at a time from stdout and stderr:

https://github.com/DannyArends/DaNode/blob/master/danode/process.d

Danny


Interesting, do you have any benchmarks for DaNode?


I used to run Apache bench on the code to make sure it was as 
fast as possible, for static files it is pretty performant since 
it buffers the files, and serves them directly from memory.


The main overhead comes from the external process booting up, 
rdmd is nice since it only does the compile once then reuses the 
compiled binary for external scripts. PHP and such are always hit 
with the additional overhead.


Feel free to run your own tests, the development branch has the 
latest version with some additional bug fixes not yet available 
in the master branch, and feedback is welcome and can be posted 
as an issue in Github


Re: How to get output of piped process?

2021-03-03 Thread Danny Arends via Digitalmars-d-learn

On Thursday, 25 February 2021 at 15:28:25 UTC, kdevel wrote:

On Monday, 22 February 2021 at 13:23:40 UTC, Danny Arends wrote:

On Friday, 19 February 2021 at 15:39:25 UTC, kdevel wrote:


[...]

Fortunately the D runtime /does/ take care and it throws---if 
the signal

is ignored beforehand. I filed issue 21649.


[...]


Perhaps a bit late,


It's never too late.™ :-)


but this is how I deal with pipes and spawnShell.
Read one byte at a time from stdout and stderr:

https://github.com/DannyArends/DaNode/blob/master/danode/process.d


Is this immune to SIGPIPE and is this design able to serve 
infinite

streams?


No I have linked up a signal handler to just ignore sigpipe, the 
web server closes connections after not seeing a valid output 
from the script for 5min (e.g. no header)



BTW: Why does run use spawnShell and not spawnProcess (would
save one File object).


I tried different approaches, this one worked for me™ and I just 
went with it. I need the stdin (for the get/post/cookies) stdout 
(php/d/brainf*ck script output) and stderr for the error stream 
from he external script




If the design is not intended to serve infinite streams I would
suggest to open two temporary files "out" and "err", delete 
them,

and let the child process write stdout/stderr into those files.


I used to do that, but it generated a lot of temporary files, and 
I would need to parse in the files after the process is done to 
serve the output to the client. Using pipes is cleaner code wise, 
since I can just stream back the output to the client (e.g. in 
keepalive connections)



IFAICS this avoid threads, sleep, pipe and reading with fgetc.





Re: How to get output of piped process?

2021-02-22 Thread Danny Arends via Digitalmars-d-learn

On Friday, 19 February 2021 at 15:39:25 UTC, kdevel wrote:
On Friday, 19 February 2021 at 13:42:46 UTC, Steven 
Schveighoffer wrote:


[...]


[...]


Sure.


[...]


As application programmer I don't want to check any error codes.
Thankfully I don't have to in D. There is a nice off-topic 
example

from the linux kernel [1] what happens when people do not check
return values [1].


[...]


Fortunately the D runtime /does/ take care and it throws---if 
the signal

is ignored beforehand. I filed issue 21649.

[1] 
move RLIMIT_NPROC check from set_user() to 
do_execve_common()


Perhaps a bit late, but this is how I deal with pipes and 
spawnShell.

Read one byte at a time from stdout and stderr:

https://github.com/DannyArends/DaNode/blob/master/danode/process.d

Danny


Re: dub: Is it possible to have a library target and depend on it in the same dub config?

2020-09-18 Thread Danny Arends via Digitalmars-d-learn

On Friday, 18 September 2020 at 11:38:14 UTC, wjoe wrote:

Something like this:

configuration "lib" {
  targetType "dynamicLibrary"
  sourceDir "source/lib/"
}

configuration "app" {
  targetType "executable"
  sourceFiles "source/app.d"
  linkWith "lib"
}

I found subConfiguration in the docs but that seems to be 
related to external dependencies.


app.d merely provides a CLI to the library as well as an option 
to run as a server. I don't want to have the overhead of an 
entire git repo and such for something that is a single file 
and also closely related to the library.


yes just add 2 configurations, use mainSourceFile to specify the 
file with main()



"configurations": [
{
"name": "default",
"targetPath": "bin",
"targetType": "executable",
"mainSourceFile": "main/main.d"
"sourcePaths": ["src/"],
},{
"name": "lib",
"targetType": "dynamicLibrary",
"sourcePaths": ["src/"],
}]


Re: bindbc OpenGL ES

2020-09-09 Thread Danny Arends via Digitalmars-d-learn

On Monday, 31 August 2020 at 22:25:48 UTC, Mike Parker wrote:

On Monday, 31 August 2020 at 14:04:19 UTC, Danny Arends wrote:
Don't know exactly where to post this, so I hope the bindbc 
team will see the post here in learn.


I was wondering if it would be possible to have bindbc OpenGL 
ES bindings ?




I can make time for it sometime this week.


Hey Mike,

Started with OpenGL ES bindings in bindbc style, find them here:

https://github.com/DannyArends/bindbc-gles

Danny


Re: GC.LDC2 on Android

2020-09-08 Thread Danny Arends via Digitalmars-d-learn

On Tuesday, 8 September 2020 at 13:20:24 UTC, kinke wrote:
On Tuesday, 8 September 2020 at 12:47:11 UTC, Danny Arends 
wrote:
How can I figure out which linker is used ? When performing a 
dub build, it just mentions that ldc2 is used for linking


You can add -v as dub 'linker' flag, that will make LDC show 
the actual cmdline. LDC v1.23 defaults to `-linker=bfd` for 
Android targets though. And now I actually remember that you 
should get a startup error in case the linker sections 
arrangement is a problem, so it's most likely not the linker.


The good feedback mentioned earlier, where the GC was 
apparently no problem: 
https://github.com/ldc-developers/ldc/issues/3461#issuecomment-648599814


Hmmm, very strange that I get crashes in the 
_D2gc4impl12conservativeQw3Gcx11fullcollectMFNbbZm...


I am using the SDL android-project as my project structure in 
Android studio. I am replacing the libmain.so which would 
normally be build from c/c++ with a libmain.so file created by D.


Everything compiles, deploys, and seems to work as expected.

Except for random crashes which went away after disabling the GC. 
It might be an interplay between Java, the SDL C trampoline code, 
and D threads or any of the other packages I am using (SDL_Mixer, 
SDL_Net, jni, d_android).


The weirdest thing is that after a segfault, the app closes, but 
swiping up will show the app as still running, clicking on it 
will re-start the app from scratch




Re: GC.LDC2 on Android

2020-09-08 Thread Danny Arends via Digitalmars-d-learn

On Tuesday, 8 September 2020 at 12:53:43 UTC, Adam D. Ruppe wrote:
On Tuesday, 8 September 2020 at 12:47:11 UTC, Danny Arends 
wrote:
How can I figure out which linker is used ? When performing a 
dub build, it just mentions that ldc2 is used for linking


If you are using the d_android setup thing, it actually edits 
ldc2.conf so it uses the linker from the NDK. Did you do that 
step?


I manually updated the ldc2.conf file, to point to the right NDK



Re: GC.LDC2 on Android

2020-09-08 Thread Danny Arends via Digitalmars-d-learn

On Tuesday, 8 September 2020 at 12:23:43 UTC, kinke wrote:
On Tuesday, 8 September 2020 at 11:17:45 UTC, Danny Arends 
wrote:
Does anyone have any experience with using D on android, and 
using the garbage collector ???


I've never run anything on Android myself, but I've gotten good 
feedback on AArch64 at least. Make sure to use a recent LDC, 
and especially to use the bfd linker, not gold or lld, as 
mentioned in various places.


Thanks,

I compile for AArch64, and am using the latest version 1.23.0


How can I figure out which linker is used ? When performing a dub 
build, it just mentions that ldc2 is used for linking



Linking...
C:\ldc2-1.23.0-windows-multilib\bin\ldc2.exe 
-of.dub\build\android-debug-linux.posix.android-aarch64.arm_hardfloat-ldc_2093-555146BAEC3641EAD156A00213211307\libmain.so .dub\build\android-debug-linux.posix.android-aarch64.arm_hardfloat-ldc_2093-555146BAEC3641EAD156A00213211307\main.o C:\Users\Arends\AppData\Local\dub\packages\arsd-official-8.4.0\arsd-official\.dub\build\library-debug-linux.posix.android-aarch64.arm_hardfloat-ldc_2093-FB68B3ECD76B5B393C4A14B20D11A5C9\libarsd-official_jni.a ..\bindbc-gles\.dub\build\dynamicBC-debug-linux.posix.android-aarch64.arm_hardfloat-ldc_2093-B2DF1F93BE637030294C2E6219F2659F\libBindBC_GLES.a C:\Users\Arends\AppData\Local\dub\packages\bindbc-sdl-0.19.1\bindbc-sdl\.dub\build\dynamicBC-debug-linux.posix.android-aarch64.arm_hardfloat-ldc_2093-E89B5B92EC516794E9D7694E40626205\libBindBC_SDL.a C:\Users\Arends\AppData\Local\dub\packages\bindbc-loader-0.3.2\bindbc-loader\.dub\build\yesBC-debug-linux.posix.android-aarch64.arm_hardfloat-ldc_2093-44C0A0E484E57B7F1481E669A0811B65\libBindBC_Loade!

r.a -L--no-as-needed -L-landroid -L-ldl -mtriple=aarch64--linux-android -shared 
-g





GC.LDC2 on Android

2020-09-08 Thread Danny Arends via Digitalmars-d-learn

Hey all,

I'm porting my 3D engine to Android (so far most of the work is 
going smoothly). However, I had random crashes which I first 
suspected was due to how I do multi-threading, but after 
debugging it turns out that the Garbage Collector is the issue.


The crash always happens after entering the function:

_D2gc4impl12conservativeQw3Gcx11fullcollectMFNbbZm

The critical sections of the 3D engine are @nogc, but for some 
non-critical parts of the application I still use the GC.


Does anyone have any experience with using D on android, and 
using the garbage collector ???


Re: bindbc OpenGL ES

2020-08-31 Thread Danny Arends via Digitalmars-d-learn

On Monday, 31 August 2020 at 22:25:48 UTC, Mike Parker wrote:

On Monday, 31 August 2020 at 14:04:19 UTC, Danny Arends wrote:
Don't know exactly where to post this, so I hope the bindbc 
team will see the post here in learn.


I was wondering if it would be possible to have bindbc OpenGL 
ES bindings ?




I can make time for it sometime this week.


Thanks so much Mike,

I really appreciate it, your contributions to D and the ecosystem
are really amazing. I think OpenGL ES will be a very useful
addition. Especially, now that it's easier than ever to use LDC2
to compile for Android.

Danny



Re: bindbc OpenGL ES

2020-08-31 Thread Danny Arends via Digitalmars-d-learn

On Monday, 31 August 2020 at 15:16:40 UTC, Ferhat Kurtulmuş wrote:

On Monday, 31 August 2020 at 14:04:19 UTC, Danny Arends wrote:
Don't know exactly where to post this, so I hope the bindbc 
team will see the post here in learn.


I was wondering if it would be possible to have bindbc OpenGL 
ES bindings ?


I'm working on porting my 3D Engine to Android, and well 
Android doesn't support anything else but OpenGL ES... I saw 
that derelict has OpenGL ES bindings, but would rather not 
migrate back to using derelict (since it took me a couple of 
hours to migrating everything to bindbc)


Thanks for all your solid bindings and hard work!

Kind regards,
Danny


I have never tried, but this repo may help. I know that it 
supports d.


https://github.com/Dav1dde/glad

You can create your modules online too.
https://glad.dav1d.de/


Thanks, it seems to generate most of the bindings, even though 
the D branch of the repo is 5 years stale.


It doesn't provide an example on how to load them (only c and 
c++), and since the (generated) loader isn't implemented, but 
just an alias to some unknown function:


alias Loader = void* delegate(const(char)*);

I really love to have the bindings in bindbc, due to their nogc 
and nothrow attributes.


It might be a useful addition to make D more compatible with the 
android eco-system


Danny




bindbc OpenGL ES

2020-08-31 Thread Danny Arends via Digitalmars-d-learn
Don't know exactly where to post this, so I hope the bindbc team 
will see the post here in learn.


I was wondering if it would be possible to have bindbc OpenGL ES 
bindings ?


I'm working on porting my 3D Engine to Android, and well Android 
doesn't support anything else but OpenGL ES... I saw that 
derelict has OpenGL ES bindings, but would rather not migrate 
back to using derelict (since it took me a couple of hours to 
migrating everything to bindbc)


Thanks for all your solid bindings and hard work!

Kind regards,
Danny


Re: Dub - vibe.d - hunt framework ... problems

2020-02-01 Thread Danny Arends via Digitalmars-d-learn

On Saturday, 1 February 2020 at 20:06:42 UTC, seany wrote:

On Saturday, 1 February 2020 at 14:42:58 UTC, Seb wrote:

On Saturday, 1 February 2020 at 10:35:52 UTC, seany wrote:

Hi
I want to start a small server, that will be accessible form 
outside. Not a huge deal right?

Not quite.

[...]


What version of dub did you install? 1.19 should be the latest.


PS:
As suggested, i try to build dub from github, following: 
https://github.com/dlang/dub/releases


I call ./build.d - and everything stops, and machine crashes.

Same for the master branch


Hey Seany,

A quick follow up post. I think/suspect that something might be 
broken in your dub installation if the mean import is not found. 
This is the first import from the phobos standard library in the 
project.


Could you try compiling the DaNode web server without using dub ?

git clone https://github.com/DannyArends/DaNode.git
cd DaNode
rdmd danode/server.d -p=8080

This should work, when you have a working D+Phobos standard 
library installation. If this throws error of being unable to 
find the canFind import (now the first one) then somehing in your 
dub/dmd installation is broken and you will probably have to 
reinstall dmd+dub


Kind regards,
Danny


Re: Dub - vibe.d - hunt framework ... problems

2020-02-01 Thread Danny Arends via Digitalmars-d-learn

On Saturday, 1 February 2020 at 10:35:52 UTC, seany wrote:

Hi
I want to start a small server, that will be accessible form 
outside. Not a huge deal right?

Not quite.

My machine: 4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09 
UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


DMD : DMD64 D Compiler v2.090.0
Copyright (C) 1999-2019 by The D Language Foundation, All 
Rights Reserved written by Walter Bright



Now, I try to install dub from the official repo.
Then I do

* dub init server -t vibe.d
* cd server
* dub

I hit this issue : https://github.com/dlang/dub/issues/1712

As suggested, i try to build dub from github, following: 
https://github.com/dlang/dub/releases


I call ./build.d - and everything stops, and machine crashes.

I then try to install DaNode: 
https://github.com/DannyArends/DaNode


It breaks with : module std.algorithm import 'mean' not found

Then I try to install the Hunt Framework. It breaks with : 
basic type

expected, not foreach


Please help. I really want this issue to be resolved-


Hey Seany,

DaNode author here, the mean function is only used to compute 
some server statistics. I am sorry to hear it didn't compile out 
of the box with the latest DMD compiler, I only tested up-to 
2.088.0


I just installed the latest version 2.090.0 but also using this 
version it compiles fine. Looking into the dlang docs it seems it 
was moved from std.algorithm to std.algorithm.iteration, I wonder 
why it doesn't find this function.


However I just added a mean function to the web server since it 
should always find this function.


Could you pull the latest master branch and try compiling it 
again ?


dub -- -p=8080

then see if the web server works by navigating to

http://localhost:8080/

let me know if you run into any other issues

Kind regards,
Danny


Re: Program exited with code -11

2019-09-18 Thread Danny Arends via Digitalmars-d-learn

On Wednesday, 18 September 2019 at 13:36:30 UTC, Arjan wrote:
On Wednesday, 18 September 2019 at 13:22:03 UTC, Danny Arends 
wrote:

Hey all,

"Program exited with code -11"


Not signal 11? On unix/linux I assume?


It's on linux yes...

No idea if it is a signal or an exitcode, the only indication is 
the text:

"Program exited with code -11"



Program exited with code -11

2019-09-18 Thread Danny Arends via Digitalmars-d-learn

Hey all,

I have written some code to analyze massive gzipped files (using 
std.iopipe), tested it on small subsets of the gzip files, and 
everything works using small 20 to 50 Mb files.


However when I try to run the code on 2.7 Gb file sizes the 
program always crashes with the following error:


"Program exited with code -11"

No other messages, did anyone ever encounter something like this 
before / got any ideas on how to figure out what is wrong ?


Danny




Re: Performance of tables slower than built in?

2019-05-25 Thread Danny Arends via Digitalmars-d-learn

On Wednesday, 22 May 2019 at 00:22:09 UTC, JS wrote:
I am trying to create some fast sin, sinc, and exponential 
routines to speed up some code by using tables... but it seems 
it's slower than the function itself?!?


[...]


I'll just leave this here:

https://www.dannyarends.nl/Using%20CTFE%20in%20D%20to%20speed%20up%20Sine%20and%20Cosine?



Re: is there a way to embed python 3.7 code in D program?

2019-05-13 Thread Danny Arends via Digitalmars-d-learn

On Monday, 13 May 2019 at 09:03:02 UTC, evilrat wrote:

On Monday, 13 May 2019 at 03:06:07 UTC, evilrat wrote:


https://github.com/Superbelko/pyd-min

Here. Super minimal example, ptvsd can be commented out as 
well, it is there entirely for debugging.




Pardon me, somehow I was completely misread the original 
question...

Well, maybe someone else will find this useful...


Hey there,

I was looking for an embedded language to use within D and your 
example
looks interesting. Unfortunately I am unable to run it, since it 
keeps

complaining about:

"ImportError: No module named 'stuff'"

How do I make the py_import file from pyd find the stuff.py file ?

Kind regards,
Danny

ps. I removed the vs debugger stuff since I'm on Linux
pps. I am using python 3.4.3, and set the subConfigurations using 
dub to "pyd" : "python34"


Re: Full precision double to string conversion

2018-11-03 Thread Danny Arends via Digitalmars-d-learn
On Saturday, 3 November 2018 at 12:27:19 UTC, Ecstatic Coder 
wrote:

import std.conv;
import std.stdio;
void main()
{
double value = -12.000123456;
writeln( value.sizeof );
writeln( value );
writeln( value.to!string() );
writeln( value.to!dstring() );
}

/*
8
-12.0001
-12.0001
-12.0001
*/

In Dart, value.toString() returns "-12.000123456".

In C#, value.ToString() returns "-12.000123456".

In D, value.to!string() returns "-12.0001" :(

How can I convert a double value -12.000123456 to its string 
value "-12.000123456", i.e. without loosing double-precision 
digits ?


Specify how many digits you want with writefln:

writefln("%.8f", value);



Re: Process Pipes

2018-10-10 Thread Danny Arends via Digitalmars-d-learn

On Wednesday, 10 October 2018 at 09:16:43 UTC, Gorker wrote:

On Wednesday, 10 October 2018 at 08:31:36 UTC, Kagamin wrote:
Maybe read them with parallelism? 
http://dpldocs.info/experimental-docs/std.parallelism.parallel.2.html


thanks, but I'd rather avoid having to use threads just for 
this reason.

some other suggestion?


This might be a way to do it under Linux / Posix systems (it 
reads byte by byte), adapted from my web server which uses it to 
read the output from php/perl/cgi scripts:


https://github.com/DannyArends/DaNode/blob/master/danode/process.d

It uses fcntl to make sure the pipe is non-blocking
you can read 1 byte from the stdout pipe, then 1 byte from stderr 
pipe


bool nonblocking(ref File file) {
  version(Posix) {
return(fcntl(fileno(file.getFP()), F_SETFL, O_NONBLOCK) != 
-1);

  }else{
return(false);
  }
}

int readpipe(ref Pipe pipe, int verbose = NORMAL){
  File fp = pipe.readEnd;
  try{
if(fp.isOpen()){
  if(!nonblocking(fp) && verbose >= DEBUG) writeln("[WARN]   
unable to create nonblocking pipe for command");

  return(fgetc(fp.getFP()));
}
  }catch(Exception e){
writefln("[WARN]   Exception during readpipe command: %s", 
e.msg);

fp.close();
  }
  return(EOF);
}


pStdIn = File(inputfile, "r");
pStdOut = pipe();
pStdErr = pipe();
auto cpid = spawnShell(command, pStdIn, pStdOut.writeEnd, 
pStdErr.writeEnd, null);

while(true){
  ch = readpipe(pStdOut);
  outbuffer.put(cast(char)ch);
  ch = readpipe(pStdErr);
  errbuffer.put(cast(char)ch);
}

Hope this works for your usecase


Re: getOpt with shared

2018-05-11 Thread Danny Arends via Digitalmars-d-learn

On Friday, 11 May 2018 at 17:49:17 UTC, Jonathan M Davis wrote:
On Friday, May 11, 2018 17:25:44 Danny Arends via 
Digitalmars-d-learn wrote:

[...]


getopt is designed to be single-threaded. The keyword shared is 
not used a single type in that module. If you want to use 
shared with anything in D, you have three options:


[...]


Hey Jonathan,

Thanks for the long and insightful answer.
The object is indeed constructed from the main thread, but 
afterwards multiple threads need to read the values given via the 
command line. since everything in the object is read only I was 
hoping to get away with making it shared.


I should just define tls variables to use with getopt and then 
set the corresponding variables in the shared object.


Danny


Re: getOpt with shared

2018-05-11 Thread Danny Arends via Digitalmars-d-learn

On Friday, 11 May 2018 at 17:25:44 UTC, Danny Arends wrote:

Hey all,

I have been working on creating a multi-threaded application, 
so I have a shared configuration object which hold several 
command line parameters (which I fill using getopt).


The problem is that I get deprecation warnings when trying to 
set numerical values:


/usr/include/dmd/phobos/std/getopt.d(895,36): Deprecation: 
read-modify-write operations are not allowed for shared 
variables. Use core.atomic.atomicOp!"+="(*receiver, 1) instead.


using getopt with a shared object and boolean values seems 
completely broken:


/usr/include/dmd/phobos/std/getopt.d(895,34): Error: operation 
not allowed on bool *receiver += 1
/usr/include/dmd/phobos/std/getopt.d(751,46): Error: template 
instance `std.getopt.handleOption!(shared(bool)*)` error 
instantiating
/usr/include/dmd/phobos/std/getopt.d(435,15):6 
recursive instantiations from here: getoptImpl!(string, 
shared(string)*, string, shared(string)*, string, 
shared(VSync)*, string, shared(ulong)*, string, shared(bool)*, 
string, shared(Verbose)*)


Is getopt not supposed to be used with shared structs ?


small example:

import std.getopt : getopt;

struct Settings {
  size_t myvalue = 0;
}

shared(Settings) config;

int main(string[] args) {
  getopt(args, "m|myvalue", &(config.myvalue));
  return(0);
}

Changing size_t to bool, results in the compilation error 
mentioned in the previous post


getOpt with shared

2018-05-11 Thread Danny Arends via Digitalmars-d-learn

Hey all,

I have been working on creating a multi-threaded application, so 
I have a shared configuration object which hold several command 
line parameters (which I fill using getopt).


The problem is that I get deprecation warnings when trying to set 
numerical values:


/usr/include/dmd/phobos/std/getopt.d(895,36): Deprecation: 
read-modify-write operations are not allowed for shared 
variables. Use core.atomic.atomicOp!"+="(*receiver, 1) instead.


using getopt with a shared object and boolean values seems 
completely broken:


/usr/include/dmd/phobos/std/getopt.d(895,34): Error: operation 
not allowed on bool *receiver += 1
/usr/include/dmd/phobos/std/getopt.d(751,46): Error: template 
instance `std.getopt.handleOption!(shared(bool)*)` error 
instantiating
/usr/include/dmd/phobos/std/getopt.d(435,15):6 recursive 
instantiations from here: getoptImpl!(string, shared(string)*, 
string, shared(string)*, string, shared(VSync)*, string, 
shared(ulong)*, string, shared(bool)*, string, shared(Verbose)*)


Is getopt not supposed to be used with shared structs ?



Help debugging an core.exception.OutOfMemoryError

2018-03-22 Thread Danny Arends via Digitalmars-d-learn

Hey all,

When running a D program that i wrote (32bit mode, windows10), an 
OutOfMemory exception being thrown when executing the program:


core.exception.OutOfMemoryError@src\core\exception.d(702): Memory 
allocation failed


However there is no stack trace being generated (due to the 
program being out of memory).


How do I figure out where in the user code the out of memory 
error is coming from/occurring ?


Thanks in advance,
Danny

ps. Using Linux 64bit, this error does not occur