Re: deimos libX11 undefined reference
Am 12.07.2012 08:17, schrieb Jacob Carlborg: On 2012-07-12 01:50, cal wrote: Hmm, looking at the .c header, the function is not even defined. I think it is not used, and in this case turning macros into functions in the binding generates linker errors. I don't know the best way to fix this in the binding (I have simply commented out the functions in my repo, as they don't seem to be used). But its worth noting. If a macro is turned into a function it needs to have an implementation. when marcos are turned into functions they introduce new symbols. it's a pity, but in that case you have to link to deimos. so deimos will become a wrapper rather than a binding.
Re: why is string not implicit convertable to const(char*) ?
Your answers are remarkable elaborated. Thanks for your great effort, Jonathan!! ;-)
why is string not implicit convertable to const(char*) ?
does anyone know why string not implicit convertable to const(char*) ? --- import core.sys.posix.unistd; void main() { // ok unlink(foo.txt); // failed string file = bar.txt; unlink(file); } test.d(10): Error: function core.sys.posix.unistd.unlink (const(char*)) is not callable using argument types (string) test.d(10): Error: cannot implicitly convert expression (file) of type string to const(char*)
Re: foreach_reverse error
group returns a lazy forward range. use foreach(i; group(retro(ints))) Yet another reason foreach_reverse needs to go. T No please don't! There are hundred and ten very usefull cases.
Re: ptrace (process trace system call) on Linux from D
(2) Is it more D-ish to use something like enum PTRequest { traceMe = 0, ... } instead of the fully capitalised originals? It doesn't seem to affect the working of things. Yes, that's more D-ish. In new D code I prefer the camelcased ones, but there are cases where you'd like to use the original ones. it's up to! ;-) (3) wait() is declared as returning a pid_t in the manpage, and is declared as such in core.sys.posix.sys.wait. In std.c.process however, it returns an int. I can't even find a process.h in my Linux install. What am I supposed to use? I know it essentially doesn't matter, as pid_t is aliased as int. Are there D alternatives to wait() and fork() that I could use with ptrace() instead of the C posix system functions? (4) Some things are declared only in core.*, not in std.*. Will they be added at some point or is this how it's supposed to be? I thing core.* (druntime) is the right place for _all_ bindings to libc. But yeha, there are still some relicts in std.c.* of the good old days. What do you meant by D alternatives to wait() and fork() that could be used with ptrace(). Maybe I don't understand your intention.
Re: ptrace (process trace system call) on Linux from D
Am 25.04.2012 18:36, schrieb Matej Nanut: Hello everyone, I would like to know how to call ptrace (the system call) from D. I don't know what to import or link. If my understanding is correct, I need to create a .di file of some sort with stuff declared in it. How would I do this? Thanks, Matej Hello Matej, I guess you're asking for http://linux.die.net/man/2/ptrace. normally it's somewhere deep in druntime but I couldn't find it. Maybe someone is able to add it for you. But neverthenless, you can just put some declaration in your D file and call it. import core.stdc.stdio; import core.sys.posix.sys.types; enum __ptrace_request { PTRACE_TRACEME = 0, PTRACE_PEEKTEXT = 1, PTRACE_PEEKDATA = 2, PTRACE_PEEKUSER = 3, PTRACE_POKETEXT = 4, PTRACE_POKEDATA = 5, PTRACE_POKEUSER = 6, PTRACE_CONT = 7, PTRACE_KILL = 8, PTRACE_SINGLESTEP = 9, PTRACE_GETREGS = 12, PTRACE_SETREGS = 13, PTRACE_GETFPREGS = 14, PTRACE_SETFPREGS = 15, PTRACE_ATTACH = 16, PTRACE_DETACH = 17, PTRACE_GETFPXREGS = 18, PTRACE_SETFPXREGS = 19, PTRACE_SYSCALL = 24, PTRACE_SETOPTIONS = 0x4200, PTRACE_GETEVENTMSG = 0x4201, PTRACE_GETSIGINFO = 0x4202, PTRACE_SETSIGINFO = 0x4203 } extern(C) long ptrace(__ptrace_request request, pid_t pid, void *addr, void *data); void main() { // just call ptrace like you would do in C }
Re: Does D supply basic error codes?
import core.stdc.stdlib; int main() { return EXIT_FAILURE; // EXIT_SUCCESS works here too. } Am 30.01.2012 00:21, schrieb NewName: Hello all. C has EXIT_FAILURE and EXIT_SUCCESS to be returned from main(). Does D have similar predefined values?
Re: char* to long
Why not just go the good old way? you char* should be zero terminated when coming from c. private import core.stdc.stdlib, std.stdio; void main() { const(char)* str = 1234567890.ptr; long lng = atoll(str); writeln(lng); }
Re: newbie question: Can D do this?
In PHP frameworks often use $option arrays which are some kind of key value pairs. they are merged with the default valuzes inside the function. pro: - you can pass an argument by name - you only need to pass those who needed. cons: - hash arrays it should be possible to create a similar method in d. but I really don't like this solution in d. it feels bad and looks ugly. ?php $model-query(array( 'firstname' = 'John', 'country' = 'France', 'order' = 'asc' )); class Model { function query($options = array()) { // merge with defaults $options = array_merge(array( 'deep' = true, 'order' = 'desc', 'type' = 'sql', 'backend' = 'mysql' ... ), $options); } } ?
Re: Restrict access to critical functions
Maybe you should use a VM to run your restricted applications. Or have a look a chroot, dchroot or schroot, to setup such stuff. The Programming Language will not help you in this case!
Re: dup method const or not?
Okay, what about this hack? --- import std.bitmanip; import core.stdc.string; void main() { const(BitArray) foo; BitArray bar; bar.len = foo.len; bar.ptr = foo.ptr[0 .. foo.dim].dup.ptr; } ---
Re: dup method const or not?
that's a real good question. it fails with the following error: Error: function std.bitmanip.BitArray.dup () is not callable using argument types () const here is a hack: --- import std.bitmanip; import core.stdc.string; void main() { const(BitArray) foo; BitArray bar; memcpy(bar, foo, BitArray.sizeof); } ---
Re: auto
Did you know that auto is not auto in the way auto behalfs. it's just a placeholder so the compiler can determine that a variable follows. but you can use any other keyword for type interfering, too. void main() { const a = FunctionThatReturnsSomething(); static b = 5.0; scope c = hey; }
Re: DFastCGI
IIRC there are two version of fastcgi / fgci ? The one is using stdin, stdout for communication and the application is running as a child of the webserver. And the other is running as a standalone application using unix sockets for communcation. Is DFastCGI able to handle both?
Re: What is shared functions?
void main() { shared s1 = cast(shared)new S(); s1.onlyShared(); // ok //s1.notShared(); // error: not callable using argument types () shared auto s2 = new S(); //s2.onlyShared(); // error: not callable using argument types () s2.notShared(); // ok } I would rather prefer auto s1 = new shared(S); because shared s1 = new S(); seems to allocate a TLS variable which is then casted to shared which is actually non-TLS.