Esempio n. 1
0
File: dump.c Progetto: Zyxwvu/mruby
static int
calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section)
{
  char *buf, *buf_top;
  uint32_t buf_size;
  int type = DUMP_TYPE_BIN;

  switch (section) {
  case DUMP_IREP_HEADER: buf_size = get_irep_header_size(mrb, irep, type); break;
  case DUMP_ISEQ_BLOCK:  buf_size = get_iseq_block_size(mrb, irep, type); break;
  case DUMP_POOL_BLOCK:  buf_size = get_pool_block_size(mrb, irep, type); break;
  case DUMP_SYMS_BLOCK:  buf_size = get_syms_block_size(mrb, irep, type); break;
  default: return MRB_DUMP_GENERAL_FAILURE;
  }

  if ((buf = mrb_malloc(mrb, buf_size)) == 0)
    return MRB_DUMP_GENERAL_FAILURE;

  buf_top = buf;
  memset(buf, 0, buf_size);

  switch (section) {
  case DUMP_IREP_HEADER: buf += write_irep_header(mrb, irep, buf, type); break;
  case DUMP_ISEQ_BLOCK: buf += write_iseq_block(mrb, irep, buf, type); break;
  case DUMP_POOL_BLOCK: buf += write_pool_block(mrb, irep, buf, type); break;
  case DUMP_SYMS_BLOCK: buf += write_syms_block(mrb, irep, buf, type); break;
  default: break;
  }

  *crc = calc_crc_16_ccitt((unsigned char*)buf_top, (int)(buf - buf_top));

  mrb_free(mrb, buf_top);

  return MRB_DUMP_OK;
}
Esempio n. 2
0
static size_t
get_irep_record_size_1(mrb_state *mrb, mrb_irep *irep)
{
  uint32_t size = 0;

  size += get_irep_header_size(mrb);
  size += get_iseq_block_size(mrb, irep);
  size += get_pool_block_size(mrb, irep);
  size += get_syms_block_size(mrb, irep);
  return size;
}
Esempio n. 3
0
static int
calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section)
{
  char *buf, *buf_top;
  uint32_t buf_size;
  int type = DUMP_TYPE_BIN;
  int result;

  switch (section) {
  case DUMP_IREP_HEADER: buf_size = get_irep_header_size(mrb, type); break;
  case DUMP_ISEQ_BLOCK:  buf_size = get_iseq_block_size(mrb, irep, type); break;
  case DUMP_POOL_BLOCK:  buf_size = get_pool_block_size(mrb, irep, type); break;
  case DUMP_SYMS_BLOCK:  buf_size = get_syms_block_size(mrb, irep, type); break;
  default: return MRB_DUMP_GENERAL_FAILURE;
  }

  buf = (char *)mrb_calloc(mrb, 1, buf_size);
  if (buf == NULL)
    return MRB_DUMP_GENERAL_FAILURE;

  buf_top = buf;

  switch (section) {
  case DUMP_IREP_HEADER:
    result = write_irep_header(mrb, irep, buf, type);
    break;
  case DUMP_ISEQ_BLOCK:
    result = write_iseq_block(mrb, irep, buf, type);
    break;
  case DUMP_POOL_BLOCK:
    result = write_pool_block(mrb, irep, buf, type);
    break;
  case DUMP_SYMS_BLOCK:
    result = write_syms_block(mrb, irep, buf, type);
    break;
  default:
    result = MRB_DUMP_GENERAL_FAILURE;
    break; /* Already checked above. */
  }
  if (result < 0) {
    goto error_exit;
  }
  buf += result;

  *crc = calc_crc_16_ccitt((unsigned char*)buf_top, (int)(buf - buf_top));

  mrb_free(mrb, buf_top);

  result = MRB_DUMP_OK;
 error_exit:
  return result;
}
Esempio n. 4
0
File: dump.c Progetto: Hozum/mruby
static size_t
get_irep_record_size(mrb_state *mrb, mrb_irep *irep)
{
  uint32_t size = 0;

  //size += sizeof(uint16_t); /* rlen */
  size += get_irep_header_size(mrb);
  size += get_iseq_block_size(mrb, irep);
  size += get_pool_block_size(mrb, irep);
  size += get_syms_block_size(mrb, irep);

  return size;
}
Esempio n. 5
0
static uint32_t
get_irep_record_size(mrb_state *mrb, int irep_no, int type)
{
  uint32_t size = 0;
  mrb_irep *irep = mrb->irep[irep_no];

  size += DUMP_SIZE(MRB_DUMP_SIZE_OF_LONG, type); /* rlen */
  size += get_irep_header_size(mrb, type);
  size += get_iseq_block_size(mrb, irep, type);
  size += get_pool_block_size(mrb, irep, type);
  size += get_syms_block_size(mrb, irep, type);

  return size;
}