w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

load.c File Reference
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <mruby/dump.h>
#include <mruby/irep.h>
#include <mruby/proc.h>
#include <mruby/debug.h>
#include <mruby/error.h>
#include <mruby/data.h>
#include <mruby/endian.h>
Include dependency graph for load.c:

Go to the source code of this file.

Macros

#define FLAG_SRC_MALLOC   1
 
#define FLAG_SRC_STATIC   0
 
#define SIZE_ERROR_MUL(nmemb, size)   ((size_t)(nmemb) > SIZE_MAX / (size))
 
#define DEFINE_READ_IREP_FUNC(funcdecl, basecall)
 

Functions

static double str_to_double (mrb_state *mrb, const char *p)
 
mrb_value mrb_str_len_to_inum (mrb_state *mrb, const char *str, size_t len, mrb_int base, int badcheck)
 
static mrb_bool read_irep_record_1 (mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flags, mrb_irep **irepp)
 
static mrb_bool read_irep_record (mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flags, mrb_irep **irepp)
 
static mrb_irepread_section_irep (mrb_state *mrb, const uint8_t *bin, uint8_t flags, struct RProc **proc)
 
static int read_debug_record (mrb_state *mrb, const uint8_t *start, mrb_irep *irep, size_t *record_len, const mrb_sym *filenames, size_t filenames_len)
 
static int read_section_debug (mrb_state *mrb, const uint8_t *start, mrb_irep *irep, uint8_t flags)
 
static int read_lv_record (mrb_state *mrb, const uint8_t *start, mrb_irep *irep, size_t *record_len, mrb_sym const *syms, uint32_t syms_len)
 
static int read_section_lv (mrb_state *mrb, const uint8_t *start, mrb_irep *irep, uint8_t flags)
 
static int read_binary_header (const uint8_t *bin, size_t bufsize, size_t *bin_size, uint8_t *flags)
 
static struct RProcread_irep (mrb_state *mrb, const uint8_t *bin, size_t bufsize, uint8_t flags)
 
static struct RProcmrb_proc_read_irep (mrb_state *mrb, const uint8_t *bin)
 
mrb_irepmrb_read_irep (mrb_state *mrb, const uint8_t *bin)
 
static struct RProcmrb_proc_read_irep_buf (mrb_state *mrb, const void *buf, size_t bufsize)
 
mrb_irepmrb_read_irep_buf (mrb_state *mrb, const void *buf, size_t bufsize)
 
void mrb_exc_set (mrb_state *mrb, mrb_value exc)
 
static void irep_error (mrb_state *mrb)
 
void mrb_codedump_all (mrb_state *, struct RProc *)
 
static mrb_value load_irep (mrb_state *mrb, struct RProc *proc, mrbc_context *c)
 
mrb_value mrb_load_irep_cxt (mrb_state *mrb, const uint8_t *bin, mrbc_context *c)
 
mrb_value mrb_load_irep_buf_cxt (mrb_state *mrb, const void *buf, size_t bufsize, mrbc_context *c)
 
mrb_value mrb_load_irep (mrb_state *mrb, const uint8_t *bin)
 
mrb_value mrb_load_irep_buf (mrb_state *mrb, const void *buf, size_t bufsize)
 
mrb_value mrb_load_proc (mrb_state *mrb, const struct RProc *proc)
 
static struct RProcmrb_proc_read_irep_file (mrb_state *mrb, FILE *fp)
 
mrb_irepmrb_read_irep_file (mrb_state *mrb, FILE *fp)
 
mrb_value mrb_load_irep_file_cxt (mrb_state *mrb, FILE *fp, mrbc_context *c)
 
mrb_value mrb_load_irep_file (mrb_state *mrb, FILE *fp)
 

Macro Definition Documentation

◆ DEFINE_READ_IREP_FUNC

#define DEFINE_READ_IREP_FUNC (   funcdecl,
  basecall 
)
Value:
funcdecl \
{ \
int ai = mrb_gc_arena_save(mrb); \
struct RProc *proc = basecall; \
struct mrb_irep *irep = (mrb_irep*)(proc ? proc->body.irep : NULL); \
if (irep) proc->body.irep = NULL; \
mrb_gc_arena_restore(mrb, ai); \
return irep; \
}
#define NULL
Definition: ftobjs.h:61
static int mrb_gc_arena_save(mrb_state *mrb)
Definition: mruby.h:1233
Definition: proc.h:41
Definition: obx.h:103
Definition: irep.h:56

Definition at line 29 of file load.c.

◆ FLAG_SRC_MALLOC

#define FLAG_SRC_MALLOC   1

Definition at line 24 of file load.c.

◆ FLAG_SRC_STATIC

#define FLAG_SRC_STATIC   0

Definition at line 25 of file load.c.

◆ SIZE_ERROR_MUL

#define SIZE_ERROR_MUL (   nmemb,
  size 
)    ((size_t)(nmemb) > SIZE_MAX / (size))

Definition at line 27 of file load.c.

Function Documentation

◆ irep_error()

static void irep_error ( mrb_state mrb)
static

Definition at line 619 of file load.c.

References E_SCRIPT_ERROR, mrb_exc_new_lit, and mrb_exc_set().

Referenced by load_irep().

◆ load_irep()

static mrb_value load_irep ( mrb_state mrb,
struct RProc proc,
mrbc_context c 
)
static

◆ mrb_codedump_all()

void mrb_codedump_all ( mrb_state mrb,
struct RProc proc 
)

Definition at line 573 of file codedump.c.

Referenced by load_irep().

◆ mrb_exc_set()

void mrb_exc_set ( mrb_state mrb,
mrb_value  exc 
)

Definition at line 171 of file error.c.

Referenced by irep_error().

◆ mrb_load_irep()

mrb_value mrb_load_irep ( mrb_state mrb,
const uint8_t bin 
)

load mruby bytecode functions Please note! Currently due to interactions with the GC calling these functions will leak one RProc object per function call. To prevent this save the current memory arena before calling and restore the arena right after, like so int ai = mrb_gc_arena_save(mrb); mrb_value status = mrb_load_irep(mrb, buffer); mrb_gc_arena_restore(mrb, ai);

Definition at line 654 of file load.c.

References mrb_load_irep_cxt(), and NULL.

◆ mrb_load_irep_buf()

mrb_value mrb_load_irep_buf ( mrb_state mrb,
const void buf,
size_t  bufsize 
)

Definition at line 660 of file load.c.

References buf, bufsize, mrb_load_irep_buf_cxt(), and NULL.

◆ mrb_load_irep_buf_cxt()

mrb_value mrb_load_irep_buf_cxt ( mrb_state mrb,
const void buf,
size_t  bufsize,
mrbc_context c 
)

Definition at line 648 of file load.c.

References buf, bufsize, c, load_irep(), and mrb_proc_read_irep_buf().

Referenced by mrb_load_detect_file_cxt(), and mrb_load_irep_buf().

◆ mrb_load_irep_cxt()

mrb_value mrb_load_irep_cxt ( mrb_state mrb,
const uint8_t bin,
mrbc_context c 
)

Definition at line 640 of file load.c.

References c, load_irep(), mrb_proc_read_irep(), and mrb_undef_value().

Referenced by mrb_load_irep().

◆ mrb_load_irep_file()

mrb_value mrb_load_irep_file ( mrb_state mrb,
FILE fp 
)

Definition at line 718 of file load.c.

References fp, mrb_load_irep_file_cxt(), and NULL.

Referenced by main().

◆ mrb_load_irep_file_cxt()

mrb_value mrb_load_irep_file_cxt ( mrb_state mrb,
FILE fp,
mrbc_context c 
)

Definition at line 712 of file load.c.

References c, fp, load_irep(), and mrb_proc_read_irep_file().

Referenced by main(), and mrb_load_irep_file().

◆ mrb_load_proc()

mrb_value mrb_load_proc ( mrb_state mrb,
const struct RProc proc 
)

Definition at line 666 of file load.c.

References mrb_top_self(), and mrb_vm_run().

◆ mrb_proc_read_irep()

static struct RProc* mrb_proc_read_irep ( mrb_state mrb,
const uint8_t bin 
)
static

Definition at line 591 of file load.c.

References FLAG_SRC_MALLOC, FLAG_SRC_STATIC, flags, mrb_ro_data_p, and read_irep().

Referenced by mrb_load_irep_cxt().

◆ mrb_proc_read_irep_buf()

static struct RProc* mrb_proc_read_irep_buf ( mrb_state mrb,
const void buf,
size_t  bufsize 
)
static

Definition at line 607 of file load.c.

References buf, bufsize, FLAG_SRC_MALLOC, and read_irep().

Referenced by mrb_load_irep_buf_cxt().

◆ mrb_proc_read_irep_file()

static struct RProc* mrb_proc_read_irep_file ( mrb_state mrb,
FILE fp 
)
static

◆ mrb_read_irep()

mrb_irep* mrb_read_irep ( mrb_state mrb,
const uint8_t bin 
)

Definition at line 604 of file load.c.

◆ mrb_read_irep_buf()

mrb_irep* mrb_read_irep_buf ( mrb_state mrb,
const void buf,
size_t  bufsize 
)

Definition at line 614 of file load.c.

◆ mrb_read_irep_file()

mrb_irep* mrb_read_irep_file ( mrb_state mrb,
FILE fp 
)

Definition at line 709 of file load.c.

Referenced by strip().

◆ mrb_str_len_to_inum()

mrb_value mrb_str_len_to_inum ( mrb_state mrb,
const char *  str,
size_t  len,
mrb_int  base,
int  badcheck 
)

◆ read_binary_header()

static int read_binary_header ( const uint8_t bin,
size_t  bufsize,
size_t bin_size,
uint8_t flags 
)
static

◆ read_debug_record()

◆ read_irep()

◆ read_irep_record()

static mrb_bool read_irep_record ( mrb_state mrb,
const uint8_t bin,
size_t len,
uint8_t  flags,
mrb_irep **  irepp 
)
static

Definition at line 235 of file load.c.

References FALSE, flags, i, len, mrb_calloc(), mrb_gc_arena_restore(), mrb_gc_arena_save(), read_irep_record_1(), and TRUE.

Referenced by read_section_irep().

◆ read_irep_record_1()

◆ read_lv_record()

static int read_lv_record ( mrb_state mrb,
const uint8_t start,
mrb_irep irep,
size_t record_len,
mrb_sym const syms,
uint32_t  syms_len 
)
static

◆ read_section_debug()

◆ read_section_irep()

static mrb_irep* read_section_irep ( mrb_state mrb,
const uint8_t bin,
uint8_t  flags,
struct RProc **  proc 
)
static

Definition at line 267 of file load.c.

References flags, len, mrb_proc_new(), NULL, and read_irep_record().

Referenced by read_irep().

◆ read_section_lv()

◆ str_to_double()

static double str_to_double ( mrb_state mrb,
const char *  p 
)
static

Definition at line 42 of file load.c.

References f, i, littleendian, memcpy, p, s, and u.

Referenced by read_irep_record_1().