Skip to content

Commit

Permalink
use GC.malloc_atomic to allocate objects without pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
kostya committed Feb 26, 2017
1 parent c2c2276 commit a2f588f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/base64.cr
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ module Base64
# This will decode either the normal or urlsafe alphabets.
def decode(data) : Bytes
slice = data.to_slice
buf = Pointer(UInt8).malloc(decode_size(slice.size))
buf = GC.malloc_atomic(decode_size(slice.size)).as(UInt8*)
appender = buf.appender
from_base64(slice) { |byte| appender << byte }
Slice.new(buf, appender.size.to_i32)
Expand Down
2 changes: 1 addition & 1 deletion src/big/lib_gmp.cr
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ lib LibGMP
end

LibGMP.set_memory_functions(
->(size) { GC.malloc(size) },
->(size) { GC.malloc_atomic(size) },
->(ptr, old_size, new_size) { GC.realloc(ptr, new_size) },
->(ptr, size) { GC.free(ptr) }
)
2 changes: 1 addition & 1 deletion src/regex.cr
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class Regex
return ($~ = nil) if byte_index > str.bytesize

ovector_size = (@captures + 1) * 3
ovector = Pointer(Int32).malloc(ovector_size)
ovector = GC.malloc_atomic(ovector_size).as(Int32*)
ret = LibPCRE.exec(@re, @extra, str, str.bytesize, byte_index, (options | Options::NO_UTF8_CHECK), ovector, ovector_size)
if ret > 0
match = MatchData.new(self, @re, str, byte_index, ovector, @captures)
Expand Down

0 comments on commit a2f588f

Please sign in to comment.