Last active
June 8, 2020 05:47
-
-
Save firejox/a6f2193a5e0820eef7e7e36c937c2330 to your computer and use it in GitHub Desktop.
The changes about prevent leaking container_of globaly
This file contains 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
# channel.cr | |
class Channel(T) | |
struct Sender(T) | |
@link : Crystal::StaticList | |
end | |
Crystal::StaticList.container_of(ptr, Channel::Sender(T), @link) | |
end | |
# crystal/static_list.cr | |
struct Crystal::StaticList | |
macro container_of(ptr, type, member) | |
end | |
end |
This file contains 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
# channel.cr | |
class Channel(T) | |
include Crystal::StaticList::Reflect | |
private struct Sender(T) | |
@link : Crystal::StaticList | |
end | |
container_of(ptr, Sender(T), @link) | |
end | |
# crystal/static_list.cr | |
struct Crystal::StaticList | |
module Reflect | |
private macro container_of(ptr, type, member) | |
end | |
end | |
end |
This file contains 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
# channel.cr | |
class Channel(T) | |
@[Crystal::StaticList::Reflect::Fields(:link)] | |
private struct Sender(T) | |
include Crystal::StaticList::Reflect | |
@link : Crystal::StaticList | |
end | |
Sender(T).from_link(ptr) | |
end | |
# crystal/static_list.cr | |
struct Crystal::StaticList | |
module Reflect | |
annotation Fields; end | |
macro included | |
{% for member in @type.annotation(Crystal::StaticList::Reflect::Fields) %} | |
@[AlwaysInline] | |
def self.from_{{ member.id }}(ptr : Crystal::StaticList*) | |
end | |
{% end %} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment