Revert "Qualify C-style memory allocations functions as pure"#1735
Revert "Qualify C-style memory allocations functions as pure"#1735andralex merged 2 commits intodlang:stablefrom
Conversation
|
This is going to break code. Not sure how we need to proceed on this. Can one have an overload of a function based on being able to call in pure code? |
|
BTW, I'm not sure |
|
I can stomach the memory allocation argument for the GC being pure because logically you know that programs that deal with no memory available and no swap correctly only come out of NASA. Plus you know that GC allocated memory's visibility to the programmer is basically null. However, it's much less sound argument when there is a global variable being written to that's accessible from anywhere in the program. A And really, what do we have to gain by marking |
|
int possibleError; /* oh, and this needs to go at the start of the function in C */
void *mem = malloc(size, &possibleError);
Fully disagree. I can live with |
|
Note that https://github.com/dlang/druntime/blob/master/src/gc/impl/conservative/gc.d#L1849 |
That's not what I meant. I mean that adding |
|
Right, but adding pure to ANY weak-pure function doesn't increase the performance. What it does is allow that function to be called from a strong-pure function. Considering any strong-pure function that needs to temporarily allocate memory (like for instance, |
AFAICS 65d9a07 is only part of v2.073.0-b1, so not part of any release, so this is fine.
Well it can be accessed whenever you want. It just doesn't make sense. A slightly more clever compiler could decide that the |
You are right, I have my dates messed up. This was merged just after the release of 2.072. So this is OK to revert IMO. It may break code, but only if that code is depending on building from master. ping @MartinNowak I think we should revert this before releasing 2.073, to give some more time for discussion. |
|
@Geod24 what about this? void *m(size_t bytes) pure { return (new void[bytes).ptr; }
.errno = 0;
auto x = m(512); // can set errno, as I alluded to earlier
assert(.errno == 0);Note that Besides, sane code will not do as you say, as it doesn't make sense to pre-fill In any case, I think we probably should merge this, and then we can examine the ramifications before the 2.074 release. |
|
Note, if we want to merge this before 2.073 is released, this needs to go into stable branch. |
Sane code must do it, actually. EDIT: Sorry, different account, but same person. |
|
Not for Edit: it can return |
| // call @system stuff anyway. | ||
| /// | ||
| void* malloc(size_t size) pure; | ||
| void* malloc(size_t size); |
There was a problem hiding this comment.
OK. Next step, please define a function pureMalloc that sets errno back to where it was for the current thread.
src/core/stdc/stdlib.d
Outdated
There was a problem hiding this comment.
| void* malloc(size_t size); | ||
| /// | ||
| void* calloc(size_t nmemb, size_t size) pure; | ||
| void* calloc(size_t nmemb, size_t size); |
| void* calloc(size_t nmemb, size_t size); | ||
| /// | ||
| void* realloc(void* ptr, size_t size) pure; | ||
| void* realloc(void* ptr, size_t size); |
| int unsetenv(in char*); | ||
|
|
||
| void* valloc(size_t) pure; // LEGACY non-standard | ||
| void* valloc(size_t); // LEGACY non-standard |
There was a problem hiding this comment.
probably these don't need to be wrapped
|
Again, please target stable or else the pure tags will get into 2.073! |
|
cc @MartinNowak |
This reverts commit 65d9a07.
|
Uh, I changed the base branch in git using |
|
Never mind, figured it out |
|
Question for people who know the runtime code better than me: where should these wrapper functions be defined? |
|
import/core/memory.d |
|
Auto-merge toggled on |
|
@MartinNowak merge into stable as well please? |
|
@andralex This is stable :) |
|
Awesome, thanks everyone. Let's work on getting |
|
@JackStouffer who adds I added |
This reverts commit 65d9a07.
See #1718 (comment)