Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle zero-size allocations correctly #11635

Merged
merged 1 commit into from
Jan 19, 2014
Merged

handle zero-size allocations correctly #11635

merged 1 commit into from
Jan 19, 2014

Conversation

thestinger
Copy link
Contributor

The malloc family of functions may return a null pointer for a
zero-size allocation, which should not be interpreted as an
out-of-memory error.

If the implementation does not return a null pointer, then handling
this will result in memory savings for zero-size types.

This also switches some code to malloc_raw in order to maintain a
centralized point for handling out-of-memory in rt::global_heap.

Closes #11634

if p.is_null() {
// we need a non-allocating way to print an error here
abort();
if size == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the above malloc should probably have comments explaining why they're explicitly checking for the 0-sized case.

The `malloc` family of functions may return a null pointer for a
zero-size allocation, which should not be interpreted as an
out-of-memory error.

If the implementation does not return a null pointer, then handling
this will result in memory savings for zero-size types.

This also switches some code to `malloc_raw` in order to maintain a
centralized point for handling out-of-memory in `rt::global_heap`.

Closes #11634
bors added a commit that referenced this pull request Jan 19, 2014
The `malloc` family of functions may return a null pointer for a
zero-size allocation, which should not be interpreted as an
out-of-memory error.

If the implementation does not return a null pointer, then handling
this will result in memory savings for zero-size types.

This also switches some code to `malloc_raw` in order to maintain a
centralized point for handling out-of-memory in `rt::global_heap`.

Closes #11634
@bors bors closed this Jan 19, 2014
@bors bors merged commit ae2a5ec into rust-lang:master Jan 19, 2014
@thestinger thestinger deleted the zero-size-alloc branch February 8, 2014 04:58
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
…eykril

Generate enum variant assist

So, this is kind of a weird PR!

I'm a complete newcomer to the `rust-analyzer` codebase, and so I browsed the "good first issue" tag, and found rust-lang#11635. Then I found two separate folks had taken stabs at it, most recently `@maartenflippo` — and there had been a review 3 days ago, but no activity in a little while, and the PR needed to be rebased since the crates were renamed from `snake_case` to `kebab-case`.

So to get acquainted with the codebase I typed this PR by hand, looking at the diff in rust-lang#11995, and I also added a doc-test (that passes).

I haven't taken into account the comments `@Veykril` left in rust-lang#11995, but I don't want to steal any of `@maartenflippo's` thunder! Closing this PR is perfectly fine. Or Maarten could use it as a "restart point"? Or I could finish it up, whichever feels best to everyone.

I think what remains to be done in this PR, at least, is:

  * [x] Only disable the "generate function" assist if the name is `PascalCase`
  * [x] Only enable the "generate variant" assistant if the name is `PascalCase`
  * [x] Simplify with `adt.source()` as mentioned here: rust-lang/rust-analyzer#11995 (comment)
  * [ ] Add more tests for edge cases? Are there cases where simply adding one more indent level than the enum's indent level is not good enough? Some nested trickery I'm not thinking of right now?

Anyway. This PR can go in any direction. You can tell me "no, tackle your own issue!" And I'll go do that and still be happy I got to take a look at rust-analyzer some by doing this. Or you can tell me "okay, now _you_ finish it", and I guess I'll try and finish it :)

Closes rust-lang#11635
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 21, 2023
[`into_iter_without_iter`]: walk up deref impl chain to find `iter` methods

Fixes rust-lang#11635

changelog: [`into_iter_without_iter`]: walk up deref impl chain to find `iter` methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

malloc/realloc with a zero size may return a null pointer on success
3 participants