Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-17 Thread nazriel via Digitalmars-d-learn

On Wednesday, 16 October 2019 at 15:52:22 UTC, nazriel wrote:
On Friday, 11 October 2019 at 11:38:27 UTC, Jacob Carlborg 
wrote:

...

Should we bump 
https://github.com/dlang/dmd/blob/master/src/posix.mak#L143 ?


BR,
Damian


I made two PRs, lets see how it plays out:
- https://github.com/dlang/dmd/pull/10489
- https://github.com/Homebrew/homebrew-core/pull/45456

BR,
Damian


Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-16 Thread nazriel via Digitalmars-d-learn

On Friday, 11 October 2019 at 11:38:27 UTC, Jacob Carlborg wrote:

On 2019-10-10 20:12, Robert M. Münch wrote:
I have two project I want to compile and both times get this 
error:


Undefined symbols for architecture x86_64:
  "_dyld_enumerate_tlv_storage", referenced from:
  __d_dyld_getTLSRange in libphobos2.a(osx_tls.o)

I'm wondering where this comes from as I didn't see it in the 
past. Any idea?




Any D application needs to be compiled with DMD 2.087.1 or 
later or the corresponding version of LDC to be able to run on 
macOS Catalina. That includes DMD itself. The oldest version of 
DMD that runs on Catalina is 2.088.0, since any given version 
of DMD is compiled with the previous version.


That means that all D applications out there for macOS needs to 
be recompiled.


When I tried to build DMD from source (via updated brew tap) it 
failed due to fact that DMD_HOST is stuck on dmd.2.079.1 which 
seems to still use old symbols.


Should we bump 
https://github.com/dlang/dmd/blob/master/src/posix.mak#L143 ?


BR,
Damian


Re: Mac IDE with Intellisense

2015-09-27 Thread nazriel via Digitalmars-d-learn

On Saturday, 26 September 2015 at 09:17:10 UTC, Mike McKee wrote:
I've tried Sublime Text 3 editor on the Mac, but even it 
doesn't seem to have the D2 language in it yet (only D), and 
doesn't have intellisense for components in the imports that I 
do, even after saving the file after adding the import 
statements.


What OSX editor do you recommend that would have intellisense?

In all reality, I don't like intellisense -- it's annoying. 
However, I need it because the documentation for me is still a 
little hard to read and hard for me to search for a class 
method here or there. For instance, I was doing 
toHexString(myByteArray) instead of simply doing 
myByteArray.toHexString(). (That was on an md5 example, by the 
way.) Intellisense would have helped me realize this.


Mono-D works really well.

Also it integrates well with dub so you can simply "import" 
projects by opening dub.json file - pure awesomeness.


Re: [video tutorial] hello world using dmd, rdmd, dub and vibe.d

2014-02-16 Thread nazriel

On Saturday, 15 February 2014 at 13:28:24 UTC, simendsjo wrote:

http://youtu.be/8TV9ZZteYEU

The content wasn't planned, and English is not my native tongue.
Hopefully it can still be useful for newbies.

This is pretty much a response to a recent discussion on the 
lack of documentation/tutorials: 
http://forum.dlang.org/post/spdddifmaacihlcum...@forum.dlang.org


PS: The many delays are X going black, forcing me to switch to 
a different terminal and back again.


Really awesome!

I had plans to create something similar to Gynvael Coldwind's 
ReverseCraft series[1] but dedicated to D generally (not really D 
as a tool for reversing but basics *G*) Unfortunately,  recently 
my time was limited. Good to see that others also think it is a 
good idea!


Your english was very good in my opinion. I understood everything 
and I'm not using English on a daily basis.


You've got my respects simendsjo and I am definitely looking for 
more of this!


Best regards,
Damian Ziemba


Re: Reading input from piped stdin.

2014-02-14 Thread nazriel

On Friday, 14 February 2014 at 19:05:02 UTC, Thomas wrote:

I'm new to D, and I find it quite enjoyable so far.
I have however stumbled upon a problem which I can't seem to
figure out.

I am trying to make a program that creates a child process,
writes something to the child process stdin and reading from its
stdout. I am going to use it later for testing out process pair
redundancy.

Appearently the child blocks at s = stdin.readln(). If I 
remove

all writing to the child, and instead just read its output,
everything works fine. My code is attached below:

import std.process,std.stdio,std.getopt,core.thread;

void main(string[] args){
bool backup = false;
getopt(args, backup, backup);
writeln(Something worked!);
string s = test;
if (backup){
writeln(Backup up  running);
while(true){
s = stdin.readln();
writeln(s);
}
}
auto pipes = pipeProcess([./pipetest, --backup],
Redirect.all);
for(int j = 0; j5; j++){
writeln(j);
pipes.stdin.writeln(j);
writeln(pipes.stdout.readln());
Thread.sleep(500.msecs);
}
while(true){}

}



If anyone could spot what rudimentary mistake I have done, I
would greatly appreciate it. Alternatively, suggesting another
way to implement inter-process communication would also be
appreciated :D


Maybe try closing stdin pipe after you are done writing to child.

pipes.stdin.close();

Or try flushing after writing to childs stdin, IIRC:

pipes.stdin.flush();





Re: Reading input from piped stdin.

2014-02-14 Thread nazriel

On Friday, 14 February 2014 at 19:09:06 UTC, nazriel wrote:

On Friday, 14 February 2014 at 19:05:02 UTC, Thomas wrote:

I'm new to D, and I find it quite enjoyable so far.
I have however stumbled upon a problem which I can't seem to
figure out.

I am trying to make a program that creates a child process,
writes something to the child process stdin and reading from 
its

stdout. I am going to use it later for testing out process pair
redundancy.

Appearently the child blocks at s = stdin.readln(). If I 
remove

all writing to the child, and instead just read its output,
everything works fine. My code is attached below:

import std.process,std.stdio,std.getopt,core.thread;

void main(string[] args){
bool backup = false;
getopt(args, backup, backup);
writeln(Something worked!);
string s = test;
if (backup){
writeln(Backup up  running);
while(true){
s = stdin.readln();
writeln(s);
}
}
auto pipes = pipeProcess([./pipetest, --backup],
Redirect.all);
for(int j = 0; j5; j++){
writeln(j);
pipes.stdin.writeln(j);
writeln(pipes.stdout.readln());
Thread.sleep(500.msecs);
}
while(true){}

}



If anyone could spot what rudimentary mistake I have done, I
would greatly appreciate it. Alternatively, suggesting another
way to implement inter-process communication would also be
appreciated :D


Maybe try closing stdin pipe after you are done writing to 
child.


pipes.stdin.close();


Ok, nvm.
You are reading from child after each write.
So naa, closing pipe won't do it.

So we are back to flushing :)

Or try flushing after writing to childs stdin, IIRC:

pipes.stdin.flush();




Re: How to launch a Windows compiled exe without showing a console?

2014-01-11 Thread nazriel
On Saturday, 11 January 2014 at 15:13:45 UTC, Gary Willoughby 
wrote:

How to launch a Windows compiled exe without showing a console?

I've tried the following two ways and when i execute the 
resulting *.exe file a console is shown alongside the dialog 
box. How can i suppress the console?


import std.string;
import core.sys.windows.windows;

void main(string[] args)
{
	MessageBoxA(null, Hello.toStringz(), Error, MB_OK | 
MB_ICONEXCLAMATION);

}

and

import std.string;
import core.runtime;
import core.sys.windows.windows;

extern (Windows) int WinMain(HINSTANCE hInstance, HINSTANCE 
hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

{
Runtime.initialize();

	MessageBoxA(null, Hello.toStringz(), Error, MB_OK | 
MB_ICONEXCLAMATION);


Runtime.terminate();
return 0;
}

Compiler flags: dmd -release source.d


Tell the linker that application is PE GUI
IIRC it was -L/subsystem:windows  ?


Re: getting __DIR__ and __TIME__ of compilation?

2013-12-26 Thread nazriel

On Friday, 27 December 2013 at 06:39:54 UTC, Ravn wrote:

Hi, I'm trying get the directory path and time at which the
compilation was made (not when the program is run), something
similar like this example in Haxe
http://haxe.org/manual/macros#macro-functions

Is it possible to do so in D?
Something like __DIR__ and __DATE__ or __TIME__ in D traits 
maybe?

( http://dlang.org/traits.html#specialkeywords )

Thanks in advance
-Ravn-


Hello.

Maybe this will work for you?
http://dpaste.dzfl.pl/3ad4aa3a

---
void main()
{
import std.path: dirName;

pragma(msg, dirName(__FILE__) ~   ~ __DATE__ ~   ~ __TIME__);
}
---


Re: Generating assembly from dmd

2013-12-22 Thread nazriel
On Sunday, 22 December 2013 at 14:17:50 UTC, Joseph Rushton 
Wakeling wrote:

Hi all,

Can someone walk me through in a friendly way how to check the 
assembly produced by dmd?  The application in this case is 
checking some new patches to Phobos. It's something I'm not 
familiar with doing in general and particularly not with dmd 
(which doesn't seem to have an assembly-output switch), so I'm 
hoping someone can advise :-)


Thanks  best wishes,

-- Joe


dmd -c ./file.d  objdump ./file.o -D -M intel

or drop -M intel if you prefer att



Re: I/O related question, and ini parsing

2013-12-07 Thread nazriel

On Friday, 6 December 2013 at 04:43:44 UTC, Mineko wrote:
So, it's my first time implementing something like logging and 
ini parsing/creating, and it appears to work perfectly, but I'm 
not neccessarily a master of D yet..


So, I wanted some advice from my seniors if there's anything I 
should improve on such, I might be missing out on some D-only 
features, so I'd appreciate it.


The important stuff is in /src/breaker/utility: 
https://github.com/ICGCC/Breaker-3D-Game-Engine


I'm a bit curious if my shader loading model is appropriate 
too, that's in /src/breaker/utility/render.d, but you don't 
have to worry about that if you're not interested.


Anyways, thank you for you time and advice!


imports are private by default.

Also I noticed few overlaping private declarations, for example 
here:

https://github.com/MinekoRox/Breaker-3D-Game-Engine/blob/master/src/breaker/utility/belt.d#L54


Re: Disassembly Tool

2013-11-14 Thread nazriel

On Thursday, 14 November 2013 at 10:14:05 UTC, Namespace wrote:

On Thursday, 14 November 2013 at 09:55:02 UTC, Tourist wrote:

On Thursday, 14 November 2013 at 09:53:42 UTC, Namespace wrote:
On Thursday, 14 November 2013 at 09:48:38 UTC, Namespace 
wrote:
Since the disassembly on Dpaste doesn't work for me anymore, 
I'm looking for an alternative. Is there one? And I don't 
want obj2asm, I'm not willing to pay 15$.


Forget to say: I'm on Windows.


OllyDbg, highly recommended.


Looks good, I'll give it a try later.
Is there a reason why obj2asm is free for linux and osx, but 
not for windows?


Maybe they charge it for compiling  packaging it on Windows.
AFAIK same thing happened with Xchat for Windows


Re: Disassembly Tool

2013-11-14 Thread nazriel

On Thursday, 14 November 2013 at 10:42:06 UTC, Namespace wrote:
On Thursday, 14 November 2013 at 10:35:26 UTC, dennis luehring 
wrote:

Am 14.11.2013 10:48, schrieb Namespace:
Since the disassembly on Dpaste doesn't work for me anymore, 
I'm

looking for an alternative. Is there one? And I don't want
obj2asm, I'm not willing to pay 15$.



maybe:

distorm:
http://www.ragestorm.net/distorm/

ida freeware:
https://www.hex-rays.com/products/ida/support/download_freeware.shtml
(32bit only)

agner fogs:
http://www.agner.org/optimize/#objconv


Are these compatible with the dmd obj files and the dmd format?


IDA supports tones of object formats and architectures.

Problems may come when it comes to free version of it.
AFAIK it supports only x86 up to 32bits.

DPASTE disassembly support will be back at some point, when we
figure out how to save bandwidth


Re: D Program code on CLS

2013-11-14 Thread nazriel

On Thursday, 14 November 2013 at 03:35:59 UTC, Vincent wrote:

how can I clear the screen for example I input first letter (A)
and second letter (B) and show the result AB then after pressing
enter it will clear the screen before it display again the Input
first letter


Input first letter : A
Input second letter: B
result: AB
Input first letter: _

it should not be displaying the previous output like this...
After showing the result it should be cleared the previous 
output

before it shows the input first letter again...


You mean something like that:

---

import std.stdio;
import core.thread;

void main() {
foreach (i; 0..10) {
write(\r, i);
stdout.flush();
Thread.sleep(250.msecs);

}

}

---

If yes, you want to play with carriage return and flushing 
terminal.


Re: DMD crashes without giving any info

2013-09-13 Thread nazriel

On Friday, 13 September 2013 at 12:41:44 UTC, simendsjo wrote:
What should I do when DMD keeps crashing and doesn't give me 
any output?

I'm using dmd 2.063.2 on win8.

This is all that -v gives me before crashing..

binaryC:\dmd\windows\bin\dmd.exe
version   v2.063.2
configC:\dmd\windows\bin\sc.ini
parse app

I've tried compiling just object files, and an exe and removed 
all -debug -g etc.


Is there any way to get more verbose info from dmd?


Run it via GDB, OllyDBG, [putyourfavouritedebugerhere]

Example:
gdb /c/d/dmd2/bin/dmd.exe
gdb r /path/to/your/code.d


[VibeD] Hand made proxy

2013-08-11 Thread nazriel

Greetings.

I am trying to learn Vibe.D and rewrite using it, my old project 
I've wrote with my (already rotting) personal framework


Project been written as commercial project for one of my clients 
so I can't really release source code here, but in tl;dr it is:


Proxy that gets file from remote server (process of getting file 
itself is rather complicated) and then serves it to the connected 
client.


In my old project I used threads because there are no more than 
15 clients connected same time. There was main thread listening 
for connections, and 15 worker threads that were making bridge 
between client and remote server.


Now I tried few different approaches with Vibe.d but all had some 
issues.

The far I could get was this:
http://dpaste.dzfl.pl/d4dabd0a [1]

But it still has some issues. It works great for small files but 
for larger
(~150MB) VibeD just closes remote connection and web browsers 
just keep trying to receive something until it timeouts.


Another issue which will probably come is the fact that Vibe.D 
won't be able to serve more than 1 client at the same time. At 
least my attempts with 2MB file resulted with: 1st client 
downloading file, 2nd client getting 500 from vibe.d


Question is then: How to properly handle it with VibeD? How do 
you handle more threads with VibeD?


Aha, and please don't get into details like your buffer is too 
small etc. It isn't important at this stage.


Thanks in advance!

[1]


import vibe.d;

import std.stdio;


void handle(HTTPServerRequest, HTTPServerResponse res)
{
string link = http://yourdomain.com/file_here;;

requestHTTP(link, null,
(scope HTTPClientResponse r)
{
enum BUFF_SIZE = 1024;
ubyte[BUFF_SIZE] buff;
ulong last_read = 0;

res.headers = r.headers;
res.headers[Content-Disposition] = `attachment; 
filename=fname.gz`;


while (r.bodyReader().empty == false)
{
last_read = r.bodyReader().leastSize;
if (last_read  BUFF_SIZE)
r.bodyReader().read(buff);
else
r.bodyReader().read(buff[0..last_read]);

res.bodyWriter.write(buff[0..(last_read  
BUFF_SIZE ? 1024 : last_read)]);


if (last_read  BUFF_SIZE)
{
break;
}
}
}
);
}

static this()
{
setLogLevel(LogLevel.trace);

auto settings = new HTTPServerSettings;
settings.hostName = localhost;
settings.port = 8004;
settings.bindAddresses = [127.0.0.1];

auto router = new URLRouter;
router.get(/download/*, toDelegate(handle));

listenHTTP(settings, router);
}
---


Re: Segfault on simple program?

2013-06-11 Thread nazriel

On Friday, 31 May 2013 at 17:14:46 UTC, Shriramana Sharma wrote:

import std.stdio ;

void foo ( int[] array ) {
foreach ( i ; array ) { writeln ( i ) ; }
}

void main () {
foo ( [ 1, 2, 3 ] ) ;
}

On both DMD 2.062 and 2.063 this compiles OK but causes a 
segfault.

I'm running Kubuntu Raring 64-bit. Any hints?


If you can attach your test-case program that segfaults compiled 
on that Kubuntu x86_64 I would be grateful.


It will allow to see if it is OS problem, hardware problem or it 
is DMD that is producing bad code in some specific scenarios.


Also it is easier to debug and reverse program when binary is 
given.

Thanks in advance.


Re: geting stack trace from signal handlers

2013-06-07 Thread nazriel

On Thursday, 6 June 2013 at 21:50:58 UTC, Timothee Cour wrote:

Great!
two issues (on OSX at least):

A)
it seems the top-most element of the call stack gets chopped 
off; eg in
your code, the main_module.main symbol will not appear in the 
stack trace.

Any idea why or how to fix that?
Is that some inlining issue ? I tried with dmd -g, or -gs or 
-gc.
This can be annoying when the top-most function is a large 
function and

it's not at all clear where the code stopped.

I haven't got Mac OSX to test it out but I fixed it a little bit 
so it is less hacky:


http://dpaste.dzfl.pl/241c6fb5

Compiler switches you may want to consider are:
-gc -L--export-dynamic -O0


B)
there are no line numbers. I did a complex workaround by 
launching a
process and calling atos to get those, but isn't there a better 
way?


Yeah, it is a complex issue. There are 2 ways to fix it from what 
I know.

1) pipe addresses to addr2line - easier
2) use libdwarf - more complex but also more out-of-box solution




Re: Is the -property compiler flag broken/bad idea?

2013-06-06 Thread nazriel

On Wednesday, 5 June 2013 at 18:09:30 UTC, Gary Willoughby wrote:
I've been using the -property compiler flag when i compile 
programs and thought it was pretty cool but i've recently had a 
conversation with someone who has informed me it's broken and a 
bad idea.


Never, ever, ever use -property. Its implementation is totally 
wrong
and based on a flawed idea to begin with. Using it just breaks 
good
code and gives nothing in return. From the ng discussions 
looks like
I'm going to get my way soon and it will be removed and buried 
like it

deserves. If you remove that, everything else works.


Can someone point me to the discussion on this or quickly fill 
me in as to why this is the case. I have no opinion on the 
subject as i'm ignorant of this topic.


Thanks.


It is useful as get that ruby out of my code warning ;)


Re: geting stack trace from signal handlers

2013-06-06 Thread nazriel

On Wednesday, 5 June 2013 at 21:05:53 UTC, Timothee Cour wrote:

how do i get a stacktrace inside handleTermination?

If not currently possible, could we have a compile flag that 
would enable
this kind of feature? (making code slower would be OK, its an 
opt in

feature)
Ideally we'd also be able to walk up or down the stack trace 
(kind of what
gdb would do, but I'd like to be able to do that without 
resorting to gdb,

using a language/library solution)



import core.sys.posix.signal;
import std.c.stdlib;
import std.stdio;

void main(string[] args)
{
bsd_signal(SIGINT, handleTermination);

while (true)
{

}
}

extern(C) void handleTermination(int signal)
{
writefln(Caught signal: %s, signal);
exit(signal);
}

-


You mean call stack?
Maybe something like this:
http://dpaste.dzfl.pl/99f217be

---
import core.sys.posix.signal;
import std.c.stdlib;
import std.stdio;
import std.conv;

void main(string[] args)
{
   bsd_signal(SIGINT, handleTermination);

   while (true)
   {

   }
}

extern(C) void handleTermination(int signal)
{
   writefln(Caught signal: %s, signal);
   getTrace();
   exit(signal);
}

extern (C) void* thread_stackBottom();
extern (C) char** backtrace_symbols(void**, int size);

void getTrace() {
void*[10] callstack;
void** stackTop;
void** stackBottom = cast(void**) thread_stackBottom();

asm {
mov [stackTop], RBP;
}

auto curr = stackTop;

size_t i;
for (i = 0; stackTop = curr 
curr  stackBottom  i  10;)
{
callstack[i++] = *(curr+1);
curr = cast(void**) *curr;
}

auto ret = backtrace_symbols(callstack.ptr, cast(int) i);
for (; i  0; i--) {
writeln((*ret).to!string());
ret++;
}
}
---


Re: How do you guys debug large programs?

2013-05-28 Thread nazriel

On Monday, 27 May 2013 at 19:55:57 UTC, Gary Willoughby wrote:
This is quite an open ended question but i wondered how you 
guys debug your D programs (i'm talking about stepping through 
code, setting breakpoints, etc). The lack of nice IDE's with 
integrated debuggers is worrying when working with D but up 
until now i haven't need one.


Now i've started to write much larger programs, i'm wondering 
which debuggers do you use? Especially using Linux.


If I suspect what block of code may be causing a problem:

1) printf's / asserts
2) comment out
3) Duck partner

When it is getting worse:
4) GDB


GDB plays nice with D so it is smooth.


DVM + DMD git-master

2013-05-23 Thread nazriel

Greetings.

Does DVM [1] supports building DMD from git-master tree?
If yes, how does it name resulting binary? dmd-master?

Best regards,
Damian Ziemba

[1] https://github.com/jacob-carlborg/dvm


Re: Can't instantiate SimpleTimeZone

2013-05-16 Thread nazriel

On Thursday, 16 May 2013 at 14:01:13 UTC, Andrej Mitrovic wrote:
I was using the AE[1] library, but recently it started to fail 
to

compile due to essentially this:


import std.datetime;

void main()
{
Duration dur;
auto x = new SimpleTimeZone(dur);
}


test.d(8): Error: immutable method 
std.datetime.SimpleTimeZone.this is not callable using a 
mutable object

test.d(8): Error: no constructor for SimpleTimeZone


The only constructors available for that class are all 
immutable.


Why the breaking change? Did it break on purpose? And why is 
the error

message so awful?


I believe it may be related to this:
http://forum.dlang.org/post/517e4196.9090...@outerproduct.org

http://forum.dlang.org/post/CAFDvkctF-_A=jpp7a+qo43vsqlbg_upnusjjj01vkaeqwbj...@mail.gmail.com


Re: dmd asm output

2013-04-01 Thread nazriel

On Monday, 1 April 2013 at 01:54:10 UTC, John Colvin wrote:
I've been learning assembler a bit and I decided to have a look 
at what dmd spits out. I tried a simple function with arrays to 
see what vectorization gets done


void addto(int[] a, int[] b) {
a[] += b[];
}

dmd -O -release -inline -noboundscheck -gc -c test.d

disassembled with gdb:
_D3sse5addtoFAiAiZv:
0x0040 +0:  push   rbp
0x0041 +1:  movrbp,rsp
0x0044 +4:  subrsp,0x30
0x0048 +8:  movQWORD PTR [rbp-0x20],rdi
0x004c +12:movQWORD PTR [rbp-0x18],rsi
0x0050 +16:movQWORD PTR [rbp-0x10],rdx
0x0054 +20:movQWORD PTR [rbp-0x8],rcx
0x0058 +24:movrcx,QWORD PTR [rbp-0x18]
0x005c +28:movrax,QWORD PTR [rbp-0x20]
0x0060 +32:movrdx,rax
0x0063 +35:movQWORD PTR [rbp-0x28],rdx
0x0067 +39:movrdx,QWORD PTR [rbp-0x8]
0x006b +43:movrdi,QWORD PTR [rbp-0x10]
0x006f +47: movrsi,rdx
0x0072 +50:movrdx,QWORD PTR [rbp-0x28]
0x0076 +54:call   0x7b 
_D3sse5addtoFAiAiZv+59

0x007b +59:movrsp,rbp
0x007e +62:poprbp
0x007f +63: ret

This looks nothing like what I expected. At first I thought 
maybe it was due to a crazy calling convention, but adding 
extern(C) changed nothing.


Can anyone explain what on earth is going on here? All that 
moving things on and off the stack, a call to the next line 
(strange) and then we're done bar the cleanup?  I feel i must 
be missing something.


It just looks like wrong snippet. Probably GDB isn't best 
assembly level debugger.


.text._D4test5addtoFAiAiZAi:0844 public 
_D4test5addtoFAiAiZAi
.text._D4test5addtoFAiAiZAi:0844 _D4test5addtoFAiAiZAi proc 
near

.text._D4test5addtoFAiAiZAi:0844
.text._D4test5addtoFAiAiZAi:0844 arg_0   = dword ptr  
8
.text._D4test5addtoFAiAiZAi:0844 arg_8   = dword ptr  
10h
.text._D4test5addtoFAiAiZAi:0844 arg_C   = dword ptr  
14h

.text._D4test5addtoFAiAiZAi:0844
.text._D4test5addtoFAiAiZAi:0844 pushebp
.text._D4test5addtoFAiAiZAi:0845 mov ebp, 
esp
.text._D4test5addtoFAiAiZAi:0847 push
dword ptr [esp+0Ch]
.text._D4test5addtoFAiAiZAi:084B push
[ebp+arg_0]
.text._D4test5addtoFAiAiZAi:084E push
[ebp+arg_C]
.text._D4test5addtoFAiAiZAi:0851 push
[ebp+arg_8]
.text._D4test5addtoFAiAiZAi:0854 call
_arraySliceSliceAddass_i
.text._D4test5addtoFAiAiZAi:0859 add esp, 
10h

.text._D4test5addtoFAiAiZAi:085C pop ebp
.text._D4test5addtoFAiAiZAi:085D retn10h
.text._D4test5addtoFAiAiZAi:085D _D4test5addtoFAiAiZAi endp

Pardon 32bits, my IDA free doesn't handle 64bit too well.
The only difference is the fact that arguments here are passed on 
stack instead of rdi, rsi etc like it takes place on System V 
AMD64 calling convention


Pointers to methods

2013-03-03 Thread nazriel

Greetings.

While playing with D code (http://dpaste.dzfl.pl/c6d9e5bd) I 
noticed that I have no idea how to write equivalent to this C++ 
code:


http://dpaste.dzfl.pl/ae182695 *[1]

Could somebody point me out how to achieve same thing? Maybe I am 
missing something obvious? Thanks!


*[1] - code for lazy people :
#include cstdio

class A
{
int x;

public:
A(int y) : x(y){}

void foo()
{
printf(::foo(), x: %d\n, x);
}
};

class B : public A
{
public:
B(int y) : A(y)
{}  
};

int main(void)
{
void (A::*fp)() = A::foo;

A a(3);
B b(4);

(a.*fp)();
(b.*fp)();

return 0;
}


iasm, call and dolar sign

2013-03-03 Thread nazriel

Greetings.

While using D iasm I noticed something interesting.

I was trying to get instruction pointer by using call trick and 
noticed that in opposite to nasm (and probably others assemblers) 
D iasm uses $ as next instruction pointer.


Documentation mentions that dolar sign is usable in Jcc (or jmp 
only? not sure) and call instructions.


It doesn't work.
http://dpaste.dzfl.pl/5c9c3d6b

call $ ; this should jump to next instruction and store RIP on 
stack

   ; if I understand correctly?
pop RAX;

Compiler slaps me with information that $ is bad operand for call 
instruction.


Am I doing something wrong or it is a bug?
Thanks!


Re: Pointers to methods

2013-03-03 Thread nazriel

On Monday, 4 March 2013 at 03:28:30 UTC, bearophile wrote:

nazriel:

While playing with D code (http://dpaste.dzfl.pl/c6d9e5bd) I 
noticed that I have no idea how to write equivalent to this 
C++ code:


I think the answer to this so common question should go here 
(unless already present):

http://dlang.org/faq.html



If that question was asked before then I am very sorry.
Documentation doesn't mention this particular case.
All it mentions are delegates:

A a = new A();
auto fp = a.func; // - Not what I am asking about.

Also if you know the answer please, feel free to tell me.
It would speed up work with stuff I have to do hehe


Bye,
bearophile




Re: Pointers to methods

2013-03-03 Thread nazriel

On Monday, 4 March 2013 at 03:28:30 UTC, bearophile wrote:

nazriel:

While playing with D code (http://dpaste.dzfl.pl/c6d9e5bd) I 
noticed that I have no idea how to write equivalent to this 
C++ code:


I think the answer to this so common question should go here 
(unless already present):

http://dlang.org/faq.html



Oh, I also tried all variations of

(obj.*fpp)()
(obj).*fpp()
(obj).(*fpp)()
obj.*fpp()

Of course everything fails, either with parsing errors or 
resolution errors



Bye,
bearophile




Re: Pointers to methods

2013-03-03 Thread nazriel

On Monday, 4 March 2013 at 03:44:20 UTC, Ali Çehreli wrote:

On 03/03/2013 07:21 PM, nazriel wrote:

 *[1] - code for lazy people :

Thank you very much for doing that. It is the only way to 
ensure that these threads will remain complete.


Here are two ways depending on what you need:

import std.stdio;

class A
{
int x;

public:
this (int y) { x = y; }

void foo()
{
writefln(::foo(), x: %s, x);
}
};

class B : A
{
public:
this(int y)
{ super(y); }
};

void main()
{
{
auto a = new A(3);
auto b = new B(4);

// When objects are available up front, initialize the 
function

// pointer by an object:
auto fp = a.foo;
fp();
fp = b.foo;
fp();
}

{
// When no object is available up front, use a function 
literal to be

// called with objects later on:
auto fp = ((A o) = o.foo());

auto a = new A(5);
auto b = new B(6);

fp(a);
fp(b);
}
}



The 2nd one is what I was looking for.
Thanks a lot Ali.



Re: iasm, call and dolar sign

2013-03-03 Thread nazriel

On Monday, 4 March 2013 at 03:30:30 UTC, nazriel wrote:

Greetings.

While using D iasm I noticed something interesting.

I was trying to get instruction pointer by using call trick and 
noticed that in opposite to nasm (and probably others 
assemblers) D iasm uses $ as next instruction pointer.


Documentation mentions that dolar sign is usable in Jcc (or jmp 
only? not sure) and call instructions.


It doesn't work.
http://dpaste.dzfl.pl/5c9c3d6b

call $ ; this should jump to next instruction and store RIP on 
stack

   ; if I understand correctly?
pop RAX;

Compiler slaps me with information that $ is bad operand for 
call instruction.


Am I doing something wrong or it is a bug?
Thanks!


Will answer myself :p
s/call $/call near ptr $
fixed the thing.

Sorry for distributions



Re: Strange behaviour with mmfile

2013-01-28 Thread nazriel

On Tuesday, 29 January 2013 at 00:49:07 UTC, bioinfornatics wrote:

I missed to show the code

$ cat test_mmap.d
import std.stdio;
import std.mmfile;

void main(string[] args ){
MmFile m = new MmFile( args[0] );
foreach( ulong c; 0..m.length )
writeln( m[c],  , cast(dchar) m[c] );
}


 MmFile m = new MmFile( args[0] ); ?
Didn't you mean args[1] or something?
Because now you are reading your binary file and output is 
correct, its spits out elf header info.


My guess is your are passing file with DNA (or whatever it is) 
via command line arguments


Re: Reading Standard Input

2013-01-23 Thread nazriel
On Wednesday, 23 January 2013 at 17:59:04 UTC, Kenneth Sills 
wrote:

Hello everyone! I'm pretty new to the D world, and just started
playing around with it. To start off with the language, I was
going to write a little game (as I usually do). I wanted to use
pure D (no ncurses) and not have to import any libraries (no
anything else) for the project. So I set out to make it a CLI
game.

I've written myself a nice little library for formatting the
output and doing all that lovely stuff with the terminal -
however I'm having trouble with input. You see, I need
nonblocking (which I've set up) input that can read character by
character (so when the user presses r, it immediately takes it
in, not waiting for an enter) and I need to be able to see 
things

like arrow keys, shift keys, and control keys.

I've looked around extensively, but I have yet to find anything
on how to set up character by character input NOR have I found
anything on receiving those special characters in D. I know it's
quite possible in C, but again, half the point of this project 
is

being pure D.So how would I go about implementing this?

Thank you in advance!


Adam Ruppe is working on very nice terminal handler. Maybe you 
can look into this: 
https://github.com/robik/ConsoleD/blob/master/terminal.d


It's rather complete solution.

Myself I was using this simple function, not sure if it will be 
usable for you:

char ReadKey()
{
version(Posix)
{
int getch()
{
int ch;
termios oldt;
termios newt;

tcgetattr(0, oldt);
newt = oldt;
newt.c_lflag = ~(ICANON | ECHO);
tcsetattr(0, TCSANOW, newt);
ch = getchar();
tcsetattr(0, TCSANOW, oldt);
return ch;
}
}
else version(Windows)
{
alias _getch getch;
}

return cast(char) getch();
}


Re: Assembly - 64-bit registers supported?

2013-01-19 Thread nazriel

On Saturday, 19 January 2013 at 12:45:06 UTC, deed wrote:

void main()
{
asm
{
movRAX, 3;
}
}

results in:
Error: undefined identifier 'RAX'

AX and EAX work.

Anything missing or isn't it yet implemented?


http://dpaste.dzfl.pl/0f79b5ba

Missing -m64 or something?


Re: Assembly - 64-bit registers supported?

2013-01-19 Thread nazriel

On Saturday, 19 January 2013 at 13:12:47 UTC, deed wrote:

Missing -m64 or something?


Probably. I am on Windows using dmd 2.061 and optlink 8.00.12

dmd main.d -m64
Con't run 'bin\amd64\link.exe', check PATH

Setting LINKCMD64 to the same path as for LINKCMD in sc.ini:

dmd main.d -m64
OPTLINK : Warning 9: Unknown Option : MERGE
OPTLINK : Error 8: Illegal Filename
/NOLOGO prog   /MERGE:.minfobg=.minfodt 
/MERGE:.minfoen=.minfodt /MERGE:._deh_bg=._deh_eh 
/MERGE:._deh_en=._deh_eh


--- errorlevel 1


Do I need another linker?


Ach, Windows.

Yeah, you need VS Linker when compiling for 64bits on Windows.
Can't help you more with this. I think there is somewhere 
step-by-step guide for 64bits+windows. (wiki.dlang.org maybe? not 
sure)




Re: How to use a function without their sources

2013-01-18 Thread nazriel

On Friday, 18 January 2013 at 17:02:51 UTC, Jordi Sayol wrote:
Is there a way to use a function from a static D library 
without importing their D sources nor their DI interface?


lib.d:

extern(C) void printf(const char*, ...);

void foo() {
printf(%s.ptr, hi.ptr); 
}

test.d:

extern(C) void _D3lib3fooFZv();

void main() {
_D3lib3fooFZv();
}

Hehe.

Now, to be honest that is a good question. How to handle name 
mangling?

Maybe pragma(mangleOf, ) by Alex Petterson could help.


Re: How to use a function without their sources

2013-01-18 Thread nazriel

On Friday, 18 January 2013 at 18:10:35 UTC, Maxim Fomin wrote:

On Friday, 18 January 2013 at 17:47:42 UTC, nazriel wrote:

On Friday, 18 January 2013 at 17:02:51 UTC, Jordi Sayol wrote:
Is there a way to use a function from a static D library 
without importing their D sources nor their DI interface?


lib.d:

extern(C) void printf(const char*, ...);

void foo() {
printf(%s.ptr, hi.ptr); 
}

test.d:

extern(C) void _D3lib3fooFZv();

void main() {
_D3lib3fooFZv();
}

Hehe.

Now, to be honest that is a good question. How to handle name 
mangling?

Maybe pragma(mangleOf, ) by Alex Petterson could help.


lib.d
extern(C) void printf(const char*, ...);

extern(C) void foo() {
printf(%s\n.ptr, hi.ptr);
}
main.d
extern extern(C) void foo();

void main() {
foo();
}
--

# dmd mylib.d -lib -oflibmylib.a
# dmd main.d -L-lmylib -L-L.

This is possible if inside library non-member functions are 
marked as extern(C). Otherwise a .di file is needed.


Nice!
This should be mentioned at Language Reference, so it won't get 
lost.




Re: How to use a function without their sources

2013-01-18 Thread nazriel

On Friday, 18 January 2013 at 18:18:07 UTC, Andrej Mitrovic wrote:

On 1/18/13, nazriel s...@dzfl.pl wrote:

extern(C) void _D3lib3fooFZv();

void main() {
_D3lib3fooFZv();
}


That's a *terrible* idea, you are calling a D function using 
the C
convention, you're going to have all sorts of problems. 
extern(D) is

not just used for mangling, it's also used for designating how
parameters are passed to and results are returned from a 
function (via

stack/registers). E.g.:



Oh really?
Thanks, I didn't know.


Re: How to use a function without their sources

2013-01-18 Thread nazriel

On Friday, 18 January 2013 at 18:23:03 UTC, Johannes Pfau wrote:

Am Fri, 18 Jan 2013 19:17:33 +0100
schrieb nazriel s...@dzfl.pl:


[...]

Nice!
This should be mentioned at Language Reference, so it won't 
get lost.




Isn't this documented? I thought it was well known that you can 
mark D

functions as extern(C). It's needed when implementing callback
functions for C, for example.

I mean, some kind of pointer how to achieve such thing (Question 
in first post).


To be honest, I did think that there is some other way than using 
extern (C) way.


You also get all the problems of unmangled C names, I remember 
some
nice segfaults in Derelict related to this (fixed some time ago 
in

derelict.)


Re: How to use a function without their sources

2013-01-18 Thread nazriel

On Friday, 18 January 2013 at 18:23:57 UTC, nazriel wrote:
On Friday, 18 January 2013 at 18:18:07 UTC, Andrej Mitrovic 
wrote:

On 1/18/13, nazriel s...@dzfl.pl wrote:

extern(C) void _D3lib3fooFZv();

void main() {
_D3lib3fooFZv();
}


That's a *terrible* idea, you are calling a D function using 
the C
convention, you're going to have all sorts of problems. 
extern(D) is

not just used for mangling, it's also used for designating how
parameters are passed to and results are returned from a 
function (via

stack/registers). E.g.:



Oh really?
Thanks, I didn't know.


As a disclaimer, I did know about this.
I wasn't serious by posting this example. So don't take this 
serious.


I just used objdump to get mangled name. ^^


Re: How to use a function without their sources

2013-01-18 Thread nazriel

On Friday, 18 January 2013 at 18:34:24 UTC, Jordi Sayol wrote:

Al 18/01/13 18:47, En/na nazriel ha escrit:

On Friday, 18 January 2013 at 17:02:51 UTC, Jordi Sayol wrote:
Is there a way to use a function from a static D library 
without importing their D sources nor their DI interface?


lib.d:

extern(C) void printf(const char*, ...);

void foo() {
printf(%s.ptr, hi.ptr);   }

test.d:

extern(C) void _D3lib3fooFZv();

void main() {
_D3lib3fooFZv();
}

Hehe.

Now, to be honest that is a good question. How to handle name 
mangling?

Maybe pragma(mangleOf, ) by Alex Petterson could help.



Thanks!

Why it works with extern(C), but not works with extern(D)?


I shouldn't paste this code in first place.

As far as I know and other folks mentioned there is no clean 
way to call function from D library without using .DI files or 
marking function in library as extern (C).


You can always look up symbol table like I did for this example.

Summary:
If you write library - you can mark function as extern (C) to 
call it later from other app without .DI fil.

You need to create .DI file if you use someone else library.


Re: How to use a function without their sources

2013-01-18 Thread nazriel

On Friday, 18 January 2013 at 18:44:29 UTC, Andrej Mitrovic wrote:

On 1/18/13, nazriel s...@dzfl.pl wrote:

So don't take this serious.


This is D.learn, so people expect to get valid information here 
and
they don't know if you're showing an invalid example or not 
unless you

tell them.


It's valid example as long as you objump object file.

Show me a working solution to question from first post.

How to use existing static D library *WITHOUT* using .DI files.
You can't edit library itself, so adding extern(C) to functions 
won't work.
You can't create .DI file - which is the main question from first 
post.


Re: How to use a function without their sources

2013-01-18 Thread nazriel

On Friday, 18 January 2013 at 20:33:04 UTC, Andrej Mitrovic wrote:

On 1/18/13, nazriel s...@dzfl.pl wrote:

Show me a working solution to question from first post.

How to use existing static D library *WITHOUT* using .DI 
files.

You can't edit library itself, so adding extern(C) to functions
won't work.
You can't create .DI file - which is the main question from 
first

post.


That formulation makes no sense. If it's not his library the 
provider
will either give the .d files or autogenerated/handwritten .di 
files.
He won't just get a naked static library without supporting 
files.


And if he controls the library, he will either have to 
autogenerate
.di files, or handwrite them. Even if he uses extern(C) he will 
still
have to provide a .d file with all extern(C) functions and 
types.


Still doesn't answers question from first post.

So let me quote it for you:
Is there a way to use a function from a static D library without 
importing their D sources nor their DI interface?


There were 2 types of answers in this topic:
1) Yes, you can if functions in library are marked as extern(C)
2) Yes, you can even if functions are not marked as extern(C) 
with little hack which is dumping object file.


Whatever you think it is *terrible* idea or not, it seems to be 
the only one working idea in this, specific scenario.


Re: Troublemaker dmd 2.061 - Templates?

2013-01-07 Thread nazriel

On Saturday, 5 January 2013 at 18:45:26 UTC, David wrote:

LOL
mixin template get_packets_mixin(alias Module) {
template get_packets() {
alias NoDuplicates!(get_packets_impl!(get_members!())) 
get_packets;

}

template get_members() {
alias TypeTuple!(__traits(allMembers, Module)) 
get_members;

}

private template get_packets_impl(T...) {
static if(__traits(compiles, mixin(T[0]).id)) {
// pragma(msg, PacketTuple!(mixin(T[0]), 
mixin(T[0]).id));

// pragma(msg, get_packets_impl!(T[1..$]));
alias TypeTuple!(PacketTuple!(mixin(T[0]), 
mixin(T[0]).id),

get_packets_impl!(T[1..$])) get_packets_impl;
} else {
// pragma(msg, get_packets_impl!(T[1..$])); // 
--
alias TypeTuple!(get_packets_impl!(T[1..$])) 
get_packets_impl;

}
}

private template get_packets_impl() {
alias TypeTuple!() get_packets_impl;
}

template PacketTuple(T, ubyte b) {
alias T cls;
alias b id;
}

auto parse_packet(ubyte id)(Stream s) {
alias staticIndexOf!(id, staticMap!(extract_id, 
get_packets!()))

id_index;
static if(id_index  0) {
static assert(false, Invalid packet with id:  ~
toStringNow!id);
} else {
return get_packets!()[id_index].cls.recv(s);
}
}

pragma(msg, get_packets_impl!(__traits(allMembers, 
Module)));

}

With this pragma: pragma(msg, get_packets_impl!(T[1..$]));
outcommented, I get _error_, but if I let it in, everything 
compiles.


I have no idea if I should laugh or cry.


Report a bug and mark it as regression if it is one.


Re: read single characters from stdin

2012-09-28 Thread nazriel

On Friday, 28 September 2012 at 09:45:30 UTC, Thomas Koch wrote:


nazriel wrote:

http://dpaste.dzfl.pl/eb1387cc
Thank you. Your solution does not seem to work with multibyte 
characters, so

I extended it:



Nice, I didn't need multibyte support as I was using it mainly 
for getting keycode




import core.sys.posix.termios;
import core.stdc.stdio;

char getch()
{
int ch;
termios oldt;
termios newt;

tcgetattr(0, oldt);
newt = oldt;
newt.c_lflag = ~(ICANON | ECHO);
tcsetattr(0, TCSANOW, newt);
ch = getchar();
tcsetattr(0, TCSANOW, oldt);

return cast(char) ch;
}

import std.utf;

char readChar()
{
char[4] buffer;

buffer[0] = getch();
auto len = stride(buffer,0);

foreach (i ; 1 .. len)
buffer[i] = getch();

size_t i;
return cast(char) decode(buffer, i);
}


I think it should return dchar then, and cast(char) should be 
dropped otherwise you will lose visual representation of anything 
that is bigger than 8bits


std.regex - ctRegex

2012-08-25 Thread nazriel

Greetings.

I was using ctRegex in 2.059 without any issue, but since 2.060 
came out some problems raised.


First of all:
*First read whole message before compiling*
http://dpaste.dzfl.pl/cfb9710d - takes 8senonds to compile on 
8CPU Xeon with 16gb RAM, freezes my local computer - same happens 
to other folks on #d


Is it some kind of regression or my regexp is somehow corrupted?

Thanks in advance!
Best Regards,
Damian Ziemba


Re: std.regex - ctRegex

2012-08-25 Thread nazriel

On Saturday, 25 August 2012 at 15:20:10 UTC, David wrote:

Am 25.08.2012 17:17, schrieb nazriel:

First of all:
*First read whole message before compiling*
http://dpaste.dzfl.pl/cfb9710d - takes 8senonds to compile on 
8CPU Xeon
with 16gb RAM, freezes my local computer - same happens to 
other folks

on #d


a ctRegex kills my computer, it makes dmd use up all my ram. 
But that was already the case with 2.059 (well I just have 4 
Cores and 32 bit, with 4gb ram installed)


Hmm, I had no problems with it in 2.059 on my local notebook (i5, 
4gb ram, 64bit Arch Linux/Gentoo Linux)


Re: Reading bytes and converting to int

2012-08-25 Thread nazriel

On Saturday, 25 August 2012 at 15:23:45 UTC, joao wrote:

Hello everyone, I recently discovered the D language.
So, I want to open a file a read 4 bytes and get the int value.

string bytes = f.read(4)

I tried to cast but give me message it was deprecated.

uint value = cast (uint) bytes

If bytes was for example, \x24\x00\x00\x00 I would like to 
value to be 0x24.

I know how to do this in Python, it is done with struct.unpack.
Thanks.


Maybe std.bitmanip.peek could help?



Re: Sudoku Py / C++11 / D?

2012-08-24 Thread nazriel
On Friday, 24 August 2012 at 19:32:53 UTC, maarten van damme 
wrote:
I've distiled what I understood from your source and the 
resulting
executable managed to solve the impossible one in 27 seconds 
while

your source takes 41 seconds.

I've probably violated every D guideline concerning the use of 
static,

pure, nothrow,... but it works perfectly :)
It does fail to compile on dpaste, I have no idea why. It does 
compile

on my machine though...

http://dpaste.dzfl.pl/8a2aef5b

2012/8/21, Timon Gehr timon.g...@gmx.ch:

On 08/21/2012 05:52 PM, maarten van damme wrote:
 On 08/20/2012 11:49 PM, Timon Gehr wrote: On 08/20/2012 
 10:43 PM,

maarten van damme wrote:


Still it comes nowhere near beating timons solution. Is the 
logic of

that documented somewhere because I don't understand it.



Try this:
http://dpaste.dzfl.pl/23b1b6e2


Thank you very much, this makes everything more clearer. I'm 
not very

familiar with binary operators so the comments help out a lot.
Would you mind it if I shamelessly copy your solution of 
using shorts

to store possibilities in?



Not at all.

I'm also a bit confused. How come the int's you change from a 
square
passed from squ are stilled referenced to the original array? 
I
thought it lost that reference as soon as you did any 
operations (like

concenating) on it?



The used ranges just express patterns of iteration. They 
replace manual
for-loops. The data source has assignable elements, and the 
relevant
range operations in Phobos all propagate this capability to 
their

result.


Your code is 32bitish, while you picked 64bit mode on dpaste.

Here's your code with m32: http://dpaste.dzfl.pl/b4a01f57
Working nice!


Re: std.json

2012-07-04 Thread nazriel

On Wednesday, 4 July 2012 at 16:55:19 UTC, Ali Çehreli wrote:

On 07/04/2012 08:25 AM, Alexsej wrote:
 On Monday, 26 March 2012 at 07:14:50 UTC, Ali Çehreli wrote:

 // Assumes UTF-8 file
 auto content = to!string(read(json_file));

 Your example only works if the json file in UTF-8 (BOM), how
to make
 sure that it worked with the files in UTF-8 without BOM.

I am pretty sure that I have tested it without BOM, which is 
not recommended nor needed for UTF-8 anyway.


If anything, the file should not have any BOM because it is 
being converted to a string and is being passed to parseJSON(). 
I don't think parseJSON() expects a BOM either. Does it?


Ali


Ali, I allowed myself to copy-modify.a.little-paste your example 
to dpaste.dzfl.pl


Hope you don't mind!
Here it is http://dpaste.dzfl.pl/a76157cf



Re: Help translating C/C++ snippet to D

2012-07-02 Thread nazriel

On Tuesday, 3 July 2012 at 02:34:04 UTC, Dustin wrote:

Hello,
I'm trying to follow along with a C++ tutorial and translate it 
to D but I don't know C/C++ well enough to understand this 
#Define statement:


#define ARRAY_COUNT( array ) (sizeof( array ) / (sizeof( 
array[0] ) * (sizeof( array ) != sizeof(void*) || sizeof( 
array[0] ) = sizeof(void*


Can anyone help me understand this and translate it to a D 
function? Thanks for your time.


http://dpaste.dzfl.pl/481e26b6

It's quite simple.
Macros in C++, should be replaced with their successor - 
templates.
In case of D, we haven't got macros per se, so we need to use 
template.


In example above I just used template'd function.