Re: Freeing memory from C

2013-12-03 Thread Chris
On Tuesday, 3 December 2013 at 16:52:29 UTC, Ali Çehreli wrote: On 12/03/2013 06:45 AM, Chris wrote: > I became aware of uninitialized variable. I think that the latter > behavior is the correct one (segfault > crash). But why did it work > correctly in the other D program, how did the C variabl

Re: Freeing memory from C

2013-12-03 Thread Ali Çehreli
On 12/03/2013 06:45 AM, Chris wrote: > I became aware of uninitialized variable. I think that the latter > behavior is the correct one (segfault > crash). But why did it work > correctly in the other D program, how did the C variable get initialized? Undefined behavior sometimes manifests itself

Re: Freeing memory from C

2013-12-03 Thread Adam D. Ruppe
On Tuesday, 3 December 2013 at 12:43:08 UTC, bearophile wrote: You can file an enhancement request for the documentation, or fix the docs yourself. https://github.com/D-Programming-Language/dlang.org/pull/427

Re: Freeing memory from C

2013-12-03 Thread Chris
On Tuesday, 3 December 2013 at 14:18:35 UTC, John Colvin wrote: On Tuesday, 3 December 2013 at 13:05:20 UTC, Mike Parker wrote: On 12/3/2013 9:31 PM, John Colvin wrote: You should be fine to free in that way as long as you haven't done anything crazy like separately static linking libc. I

Re: Freeing memory from C

2013-12-03 Thread Chris
On Tuesday, 3 December 2013 at 13:05:20 UTC, Mike Parker wrote: On 12/3/2013 9:31 PM, John Colvin wrote: You should be fine to free in that way as long as you haven't done anything crazy like separately static linking libc. I wouldn't advise this in the general case. When you have complet

Re: Freeing memory from C

2013-12-03 Thread John Colvin
On Tuesday, 3 December 2013 at 13:05:20 UTC, Mike Parker wrote: On 12/3/2013 9:31 PM, John Colvin wrote: You should be fine to free in that way as long as you haven't done anything crazy like separately static linking libc. I wouldn't advise this in the general case. When you have complet

Re: Freeing memory from C

2013-12-03 Thread Mike Parker
On 12/3/2013 9:31 PM, John Colvin wrote: You should be fine to free in that way as long as you haven't done anything crazy like separately static linking libc. I wouldn't advise this in the general case. When you have complete end-to-end control, sure. But if, for example, you're using a dyn

Re: Freeing memory from C

2013-12-03 Thread bearophile
Chris: std.c.stdlib.free() is mentioned on the "How to interface to C" page (http://dlang.org/interfaceToC.html). So maybe that needs an update. You can file an enhancement request for the documentation, or fix the docs yourself. I'll file a little bug report for the other library deprecat

Re: Freeing memory from C

2013-12-03 Thread Chris
On Tuesday, 3 December 2013 at 12:31:16 UTC, John Colvin wrote: On Tuesday, 3 December 2013 at 10:57:51 UTC, Chris wrote: I have a C module that dynamically allocates memory for a string like so: char *result = (char*)malloc(length + 1); // 'length' has been calculated When I call it from D

Re: Freeing memory from C

2013-12-03 Thread John Colvin
On Tuesday, 3 December 2013 at 10:57:51 UTC, Chris wrote: I have a C module that dynamically allocates memory for a string like so: char *result = (char*)malloc(length + 1); // 'length' has been calculated When I call it from D (via extern (C)), is it ok to free it from there like so: voi