Method: CGLM::Base#initialize

Defined in:
lib/cglm/base.rb

#initialize(addr: CGLM.alloc(self.class).tap { |ptr| # Init malloc'd values to 0; there is a PR to fiddle for this, then we # can delete this code. https://github.com/ruby/fiddle/pull/14 ptr[0, self.class.size] = "\x00".b * self.class.size }) ⇒ Base

Returns a new instance of Base.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
# File 'lib/cglm/base.rb', line 8

def initialize(addr: CGLM.alloc(self.class).tap { |ptr|
  # Init malloc'd values to 0; there is a PR to fiddle for this, then we
  # can delete this code. https://github.com/ruby/fiddle/pull/14
  ptr[0, self.class.size] = "\x00".b * self.class.size
})
  # Even if addr is present, but points to NULL, this is a problem that
  # will lead to segfaults. If not present, `nil.to_i == 0`.
  raise ArgumentError, 'BUG: object initialized without a backing store?' if addr.to_i == 0
  self.addr = addr
end