Re: How to pass a null pointer to a C function

2013-11-30 Thread Craig Dillabaugh
On Sunday, 1 December 2013 at 04:11:57 UTC, Simen Kjærås wrote: On 2013-12-01 04:46, Craig Dillabaugh wrote: Since questions about calling C from D seem to be popular today, I thought I would throw this one out there. I am trying to call a C function which takes as parameters several arrays o

Re: How to pass a null pointer to a C function

2013-11-30 Thread Simen Kjærås
On 2013-12-01 04:46, Craig Dillabaugh wrote: Since questions about calling C from D seem to be popular today, I thought I would throw this one out there. I am trying to call a C function which takes as parameters several arrays of doubles. It is valid to have some arrays passed a NULL pointers

Re: How to pass a null pointer to a C function

2013-11-30 Thread Mike Parker
On 12/1/2013 12:46 PM, Craig Dillabaugh wrote: Is there an accepted 'proper' way of passing NULL pointers to C functions from D? shape_ptrs ~= SHPCreateSimpleObject( SHPT_POLYGON, to!int(x1.length), x1.ptr, y1.ptr, null );

How to pass a null pointer to a C function

2013-11-30 Thread Craig Dillabaugh
Since questions about calling C from D seem to be popular today, I thought I would throw this one out there. I am trying to call a C function which takes as parameters several arrays of doubles. It is valid to have some arrays passed a NULL pointers in the C code. To call this from D I've com

Re: How to convert these constructs to D?

2013-11-30 Thread Craig Dillabaugh
On Saturday, 30 November 2013 at 14:53:35 UTC, Gary Willoughby wrote: I'm porting some C headers and wondered how would i convert the following to D: #define pthread_self() GetCurrentThreadId() #define pthread_handler_t void * __cdecl typedef void * (__cdecl *pthread_handler)(void *); #defin

Re: non-determinant object lifetime and memory management

2013-11-30 Thread bioinfornatics
On Saturday, 30 November 2013 at 08:35:23 UTC, Frustrated wrote: I need to pass around some objects(specifically int[]) that may be used by several other objects at the same time. While I could clone these and free them when the parent object is done this wastes memory for no real reason except

function with is own lamda expression

2013-11-30 Thread bioinfornatics
I write a function with Lambda expression + safe + pure wich do same (close) as countUntil http://www.dpaste.dzfl.pl/63d03540 but i fail to use lambda expression into my function. I try by two way - alias this pred … (to get a default lambda) - function(…) pred both way i fail, could you tak

Re: non-determinant object lifetime and memory management

2013-11-30 Thread Frustrated
On Saturday, 30 November 2013 at 12:51:46 UTC, Rene Zwanenburg wrote: On Saturday, 30 November 2013 at 08:35:23 UTC, Frustrated wrote: I need to pass around some objects(specifically int[]) that may be used by several other objects at the same time. While I could clone these and free them when

Re: alias this leads to compilation error in one of two similar contexts

2013-11-30 Thread Carl Sturtivant
I just confirmed the same behavior on Ubuntu amd64. dmd 2.063.2 compiles the example and dmd 2.064.2 produces the same error as the Windows 32 bit version.

alias this leads to compilation error in one of two similar contexts

2013-11-30 Thread Carl Sturtivant
The following is boiled down from a real world context. I'm using dmd 2.064.2 Windows. Can someone please explain what's going on. struct my_integer { int val = 99; alias val this; //this( int n) { val = n; } } struct blah { my_integer Integer; this( int

Re: Destructors calling sequence

2013-11-30 Thread Michael
class A { bool reset; void delegate dtor(); ~this() { if (!reset) dtor(); } } class B { A a; bool run; ~this() { if (!run) a.reset = true; run = true; } } A a = new A; B b = new B; b.a = a; b.a.dtor = & b.__dtor; relying on to "bool reset" it's no good id

Re: How to convert these constructs to D?

2013-11-30 Thread Gary Willoughby
Thanks all.

Re: Calling a C Function with C-style Strings

2013-11-30 Thread Dicebot
On Saturday, 30 November 2013 at 18:58:30 UTC, Ali Çehreli wrote: However, I doubt that .dup copies that '\0' character. Although the literal has the termination, we are in slice land beyond that literal so the termination must somehow be ensured. Ali Hm, yes, this also sounds like a valid c

Re: Calling a C Function with C-style Strings

2013-11-30 Thread Ali Çehreli
On 11/30/2013 07:59 AM, Adam D. Ruppe wrote: tempBuffer[name.length] = 0; // make sure it is zero terminated yourself Because char.init is not 0 in D: :) assert(tempBuffer[name.length + 1] == '\xff'); Ali

Re: Calling a C Function with C-style Strings

2013-11-30 Thread Ali Çehreli
On 11/30/2013 07:58 AM, Dicebot wrote: > char[] name = "alpha".dup; > mktemp(name.ptr); > > D literals are zero-terminated so toStringz is only needed if you want > to pass to C function slice of literal or some runtime input. However, I doubt that .dup copies that '\0' character. Although the

std.math.atan2 -- range of output

2013-11-30 Thread Joseph Rushton Wakeling
I've run into an interesting little issue with respect to std.math.atan2. This is used to calculate the "argument" of complex numbers, that is, the angle in polar coordinates. atan2(y, x) gives the argument of the complex number x + iy. Now, theoretically, atan2 ought to return a value in the

Re: How to convert these constructs to D?

2013-11-30 Thread Rémy Mouëza
For the two first ones, I would use an alias: alias GetCurrentThreadId pthread_self; alias void * pthread_handler_t; The third one is a function pointer alias: alias void * function (void *) pthread_handler; For the last one, I am not sure, being rusty with the C preprocessor rule

Re: How to convert these constructs to D?

2013-11-30 Thread Adam D. Ruppe
Just doing these by eyeball... On Saturday, 30 November 2013 at 14:53:35 UTC, Gary Willoughby wrote: #define pthread_self() GetCurrentThreadId() That's simply alias pthread_self = GetCurrentThreadId; #define pthread_handler_t void * __cdecl This depends on the text replacement and won't

Re: TypeInfo.compare is not implemented

2013-11-30 Thread Leandro Motta Barros
I am terribly sorry, this was a completely lazy question. So far, I couldn't reproduce the problem in a small example. I'll look deeper into this before posting again about it. LMB On Sat, Nov 30, 2013 at 12:07 PM, Shammah Chancellor wrote: > On 2013-11-30 13:39:15 +, Leandro Motta Barro

Re: Calling a C Function with C-style Strings

2013-11-30 Thread Dicebot
On Saturday, 30 November 2013 at 15:59:38 UTC, Adam D. Ruppe wrote: This is because mktemp needs to write to the string. Ah disregard my post then, I thought it is yet another C function that misses `const` in signature :)

Re: Calling a C Function with C-style Strings

2013-11-30 Thread Adam D. Ruppe
On Saturday, 30 November 2013 at 15:48:28 UTC, Nordlöw wrote: /home/per/Work/justd/fs.d(1042): Error: function core.sys.posix.stdlib.mktemp (char*) is not callable using argument types (immutable(char)*) This is because mktemp needs to write to the string. From mktemp(3): The last six

Re: Calling a C Function with C-style Strings

2013-11-30 Thread Dicebot
On Saturday, 30 November 2013 at 15:48:28 UTC, Nordlöw wrote: I think I've read somewhere that string literals (`const` or `immutable`) are implicitly convertible to zero (null)-terminated strings. AFAIR, this should work: char[] name = "alpha".dup; mktemp(name.ptr); D literals are zero-term

Calling a C Function with C-style Strings

2013-11-30 Thread Nordlöw
I'm struggling to call mktemp in D: import core.sys.posix.stdlib; import std.string: toStringz; auto name = "alpha"; auto tmp = mktemp(name.toStringz); but I can't figure out how to use it so DMD complains: /home/per/Work/justd/fs.d(1042): Error: function core.sys.posix.std

How to convert these constructs to D?

2013-11-30 Thread Gary Willoughby
I'm porting some C headers and wondered how would i convert the following to D: #define pthread_self() GetCurrentThreadId() #define pthread_handler_t void * __cdecl typedef void * (__cdecl *pthread_handler)(void *); #define set_timespec_nsec(ABSTIME,NSEC) { \ GetSystemTimeAsFileTime(&((ABST

Re: TypeInfo.compare is not implemented

2013-11-30 Thread Shammah Chancellor
On 2013-11-30 13:39:15 +, Leandro Motta Barros said: Hello, I my FewDee game prototyping library (https://bitbucket.org/lmb/fewdee) I ignored most of the usual reccomendations like "be careful with the GC, it's slow" and "associative arrays are buggy in D, so avoid them". I just used wha

TypeInfo.compare is not implemented

2013-11-30 Thread Leandro Motta Barros
Hello, I my FewDee game prototyping library (https://bitbucket.org/lmb/fewdee) I ignored most of the usual reccomendations like "be careful with the GC, it's slow" and "associative arrays are buggy in D, so avoid them". I just used whatever I found convenient to have my stuff running with minimal

Re: non-determinant object lifetime and memory management

2013-11-30 Thread Rene Zwanenburg
On Saturday, 30 November 2013 at 08:35:23 UTC, Frustrated wrote: I need to pass around some objects(specifically int[]) that may be used by several other objects at the same time. While I could clone these and free them when the parent object is done this wastes memory for no real reason except

Re: non-determinant object lifetime and memory management

2013-11-30 Thread bearophile
Frustrated: I need to pass around some objects(specifically int[]) that may be used by several other objects at the same time. While I could clone these and free them when the parent object is done this wastes memory for no real reason except ease of use. Since many objects may contain a ptr

non-determinant object lifetime and memory management

2013-11-30 Thread Frustrated
I need to pass around some objects(specifically int[]) that may be used by several other objects at the same time. While I could clone these and free them when the parent object is done this wastes memory for no real reason except ease of use. Since many objects may contain a ptr to the array,