Beispiel #1
0
static strm_string
str_new(const char* p, strm_int len, int foreign)
{
  strm_value tag;
  strm_value val;
  char* s;

  if (!p) goto mkbuf;
  if (len < 6) {
    tag = STRM_TAG_STRING_I;
    val = 0;
    s = VAL_PTR(val)+1;
    memcpy(s, p, len);
    s[-1] = len;
  }
  else if (len == 6) {
    tag = STRM_TAG_STRING_6;
    val = 0;
    s = VAL_PTR(val);
    memcpy(s, p, len);
  }
  else {
    struct strm_string* str;

    if (p && (foreign || readonly_data_p(p))) {
      tag = STRM_TAG_STRING_F;
      str = malloc(sizeof(struct strm_string));
      str->ptr = p;
    }
    else {
      char *buf;

    mkbuf:
      tag = STRM_TAG_STRING_O;
      str = malloc(sizeof(struct strm_string)+len+1);
      buf = (char*)&str[1];
      if (p) {
        memcpy(buf, p, len);
      }
      else {
        memset(buf, 0, len);
      }
      buf[len] = '\0';
      str->ptr = buf;
    }
    str->len = len;
    val = strm_tag_vptr(str, 0);
  }
  return tag | (val & STRM_VAL_MASK);
}
Beispiel #2
0
strm_value
strm_ptr_value(void* p)
{
  return strm_tag_vptr(p, STRM_TAG_PTR);
}
Beispiel #3
0
strm_value
strm_foreign_value(void* p)
{
  return strm_tag_vptr(p, STRM_TAG_FOREIGN);
}
Beispiel #4
0
strm_value
strm_cfunc_value(strm_cfunc f)
{
  return strm_tag_vptr(f, STRM_TAG_CFUNC);
}