This repository was archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 411
implement druntime side of DIP1008 #1804
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /** | ||
| * Exception allocation, cloning, and release compiler support routines. | ||
| * | ||
| * Copyright: Copyright (c) 2017 by D Language Foundation | ||
| * License: Distributed under the | ||
| * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). | ||
| * (See accompanying file LICENSE) | ||
| * Authors: Walter Bright | ||
| * Source: $(DRUNTIMESRC src/rt/_dwarfeh.d) | ||
| */ | ||
|
|
||
| module rt.ehalloc; | ||
|
|
||
| //debug = PRINTF; | ||
|
|
||
| debug(PRINTF) | ||
| { | ||
| import core.stdc.stdio; | ||
| } | ||
|
|
||
| /********************************************** | ||
| * Allocate an exception of type `ci` from the exception pool. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. But there could be - without changing the interface. |
||
| * It has the same interface as `rt.lifetime._d_newclass()`. | ||
| * The class type must be Throwable or derived from it, | ||
| * and cannot be a COM or C++ class. The compiler must enforce | ||
| * this. | ||
| * Returns: | ||
| * default initialized instance of the type | ||
| */ | ||
|
|
||
| extern (C) Throwable _d_newThrowable(const TypeInfo_Class ci) | ||
| { | ||
| debug(PRINTF) printf("_d_newThrowable(ci = %p, %s)\n", ci, cast(char *)ci.name); | ||
|
|
||
| assert(!(ci.m_flags & TypeInfo_Class.ClassFlags.isCOMclass)); | ||
| assert(!(ci.m_flags & TypeInfo_Class.ClassFlags.isCPPclass)); | ||
|
|
||
| import core.stdc.stdlib : malloc; | ||
| void* p = malloc(ci.initializer.length); | ||
| if (!p) | ||
| { | ||
| import core.exception : onOutOfMemoryError; | ||
| onOutOfMemoryError(); | ||
| } | ||
|
|
||
| debug(PRINTF) printf(" p = %p\n", p); | ||
|
|
||
| // initialize it | ||
| p[0 .. ci.initializer.length] = ci.initializer[]; | ||
|
|
||
| if (!(ci.m_flags & TypeInfo_Class.ClassFlags.noPointers)) | ||
| { | ||
| // Inform the GC about the pointers in the object instance | ||
| import core.memory : GC; | ||
|
|
||
| GC.addRange(p, ci.initializer.length, ci); | ||
| } | ||
|
|
||
| debug(PRINTF) printf("initialization done\n"); | ||
| Throwable t = cast(Throwable)p; | ||
| t.refcount() = 1; | ||
| return t; | ||
| } | ||
|
|
||
|
|
||
| /******************************************** | ||
| * Delete exception instance `t` from the exception pool. | ||
| * Must have been allocated with `_d_newThrowable()`. | ||
| * This is meant to be called at the close of a catch block. | ||
| * It's nothrow because otherwise any function with a catch block could | ||
| * not be nothrow. | ||
| * Input: | ||
| * t = Throwable | ||
| */ | ||
|
|
||
| nothrow extern (C) void _d_delThrowable(Throwable t) | ||
| { | ||
| if (t) | ||
| { | ||
| debug(PRINTF) printf("_d_delThrowable(%p)\n", t); | ||
|
|
||
| /* If allocated by the GC, don't free it. | ||
| * Let the GC handle it. | ||
| * Supporting this is necessary while transitioning | ||
| * to this new scheme for allocating exceptions. | ||
| */ | ||
| auto refcount = t.refcount(); | ||
| if (refcount == 0) | ||
| return; // it was allocated by the GC | ||
|
|
||
| if (refcount == 1) | ||
| assert(0); // no zombie objects | ||
|
|
||
| t.refcount() = --refcount; | ||
| if (refcount > 1) | ||
| return; | ||
|
|
||
| TypeInfo_Class **pc = cast(TypeInfo_Class **)t; | ||
| if (*pc) | ||
| { | ||
| TypeInfo_Class ci = **pc; | ||
|
|
||
| if (!(ci.m_flags & TypeInfo_Class.ClassFlags.noPointers)) | ||
| { | ||
| // Inform the GC about the pointers in the object instance | ||
| import core.memory : GC; | ||
| GC.removeRange(cast(void*) t); | ||
| } | ||
| } | ||
|
|
||
| try | ||
| { | ||
| import rt.lifetime : rt_finalize; | ||
| rt_finalize(cast(void*) t); | ||
| } | ||
| catch (Throwable t) | ||
| { | ||
| assert(0); // should never happen since Throwable.~this() is nothrow | ||
| } | ||
| import core.stdc.stdlib : free; | ||
| debug(PRINTF) printf("free(%p)\n", t); | ||
| free(cast(void*) t); | ||
| } | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your also forgetting to update dwarfeh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to check it in. Done.