module Bootsnap::CompileCache::Native

Public Class Methods

compile_option_crc32=(p1) click to toggle source

Bootsnap’s ruby code registers a hook that notifies us via this function when compile_option changes. These changes invalidate all existing caches.

Note that on 32-bit platforms, a CRC32 can’t be represented in a Fixnum, but can be represented by a uint.

static VALUE
bs_compile_option_crc32_set(VALUE self, VALUE crc32_v)
{
  if (!RB_TYPE_P(crc32_v, T_BIGNUM) && !RB_TYPE_P(crc32_v, T_FIXNUM)) {
    Check_Type(crc32_v, T_FIXNUM);
  }
  uint32_t crc32 = (uint32_t)NUM2UINT(crc32_v);
  current_ruby_version_digest = fnv1a_64_iter(base_ruby_version_digest, (unsigned char *)&crc32, sizeof(crc32));
  return Qnil;
}
fetch(p1, p2, p3, p4, p5) click to toggle source

Entrypoint for Bootsnap::CompileCache::Native.fetch. The real work is done in bs_fetch; this function just performs some basic typechecks and conversions on the ruby VALUE arguments before passing them along.

static VALUE
bs_rb_fetch(VALUE self, VALUE cachedir_v, VALUE namespace_v, VALUE path_v, VALUE handler, VALUE args)
{
  char cache_path[MAX_CACHEPATH_SIZE];

  /* generate cache path to cache_path */
  bs_cache_path(cachedir_v, namespace_v, path_v, &cache_path);

  return bs_fetch(RSTRING_PTR(path_v), path_v, cache_path, handler, args);
}
precompile(p1, p2, p3, p4) click to toggle source

Entrypoint for Bootsnap::CompileCache::Native.precompile. Similar to fetch, but it only generate the cache if missing and doesn’t return the content.

static VALUE
bs_rb_precompile(VALUE self, VALUE cachedir_v, VALUE namespace_v, VALUE path_v, VALUE handler)
{
  char cache_path[MAX_CACHEPATH_SIZE];
  /* generate cache path to cache_path */
  bs_cache_path(cachedir_v, namespace_v, path_v, &cache_path);

  return bs_precompile(RSTRING_PTR(path_v), path_v, cache_path, handler);
}
readonly=(p1) click to toggle source
static VALUE
bs_readonly_set(VALUE self, VALUE enabled)
{
  readonly = RTEST(enabled);
  return enabled;
}
revalidation=(p1) click to toggle source
static VALUE
bs_revalidation_set(VALUE self, VALUE enabled)
{
  revalidation = RTEST(enabled);
  return enabled;
}