Example #1
0
  /// Copy constructor.
  buffer(buffer const& other)
    : capacity_(other.capacity_)
    , data_(0)
    , size_(other.size_)
  {
    if (other.is_ref())
    {
      data_ = other.data_;
    }
    else if (other.is_small())
    {
      data_ = small_;
    }
    else
    {
      /// large
      data_ = (char*)std::malloc(capacity_);
      if (data_ == 0)
      {
        throw std::bad_alloc();
      }
    }

    if (!is_ref())
    {
      std::memcpy(data_, other.data_, size_);
    }
  }
Example #2
0
void migrate_value(Value* value, Migration* migration)
{
    if (is_ref(value)) {
        set_term_ref(value, migrate_term_pointer(as_term_ref(value), migration));
        
    } else if (is_block(value)) {
        set_block(value, migrate_block_pointer(as_block(value), migration));
    } else if (is_list_based(value)) {
        migrate_list_value(value, migration);

    } else if (is_hashtable(value)) {
        Value oldHashtable;
        move(value, &oldHashtable);

        set_hashtable(value);
        Value* hashtable = value;

        for (int i=0; i < hashtable_slot_count(&oldHashtable); i++) {
            Value* oldKey = hashtable_key_by_index(&oldHashtable, i);
            if (oldKey == NULL || is_null(oldKey))
                continue;

            Value* oldValue = hashtable_value_by_index(&oldHashtable, i);

            Value key;
            copy(oldKey, &key);
            migrate_value(&key, migration);
            Value* newValue = hashtable_insert(hashtable, &key);
            copy(oldValue, newValue);
            migrate_value(newValue, migration);
        }
    }
}
void update_all_code_references_in_value(caValue* value, Branch* oldBranch, Branch* newBranch)
{
    for (ValueIterator it(value); it.unfinished(); it.advance()) {
        caValue* val = *it;
        if (is_ref(val)) {
            set_term_ref(val, translate_term_across_branches(as_term_ref(val),
                oldBranch, newBranch));
            
        } else if (is_branch(val)) {

            // If this is just a reference to 'oldBranch' then simply update it to 'newBranch'.
            if (as_branch(val) == oldBranch)
                set_branch(val, newBranch);

            // Noop on null branch.
            if (as_branch(val) == NULL)
                continue;

            // Noop if branch has no owner.
            Term* oldTerm = as_branch(val)->owningTerm;
            if (oldTerm == NULL)
                continue;

            Term* newTerm = translate_term_across_branches(oldTerm, oldBranch, newBranch);
            if (newTerm == NULL) {
                set_branch(val, NULL);
                continue;
            }

            set_branch(val, newTerm->nestedContents);
        }
    }
}
Example #4
0
BIF_RETTYPE is_reference_1(BIF_ALIST_1)
{
    if (is_ref(BIF_ARG_1)) {
	BIF_RET(am_true);
    }
    BIF_RET(am_false);
}
Example #5
0
  /// Assignment.
  buffer& operator=(buffer const& rhs)
  {
    if (this != &rhs)
    {
      if (rhs.is_ref())
      {
        dealloc();
        capacity_ = 0;
        data_ = rhs.data_;
      }
      else if (rhs.is_small())
      {
        dealloc();
        capacity_ = RESP_SMALL_BUFFER_SIZE;
        data_ = small_;
      }
      else
      {
        /// rhs is large
        if (rhs.capacity_ > capacity_)
        {
          if (is_ref() || is_small())
          {
            data_ = 0;
          }
          data_ = (char*)std::realloc(data_, rhs.capacity_);
          if (data_ == 0)
          {
            throw std::bad_alloc();
          }
          capacity_ = rhs.capacity_;
        }
      }

      size_ = rhs.size_;
      if (!is_ref())
      {
        std::memcpy(data_, rhs.data_, size_);
      }
    }
    return *this;
  }
Example #6
0
bool plComponentBase::IsCurMsgLocal()
{
    // Was the last notification a message propagated up from a target?
    // Ignore it if so.
    if (fTargsPB->LastNotifyParamID() != -1)
        return false;

    // Was the last notification from a ref in the component PB?  If so, assume
    // it was a propagated message from the ref.  Real changes to that ref
    // parameter will be signalled with a user ref message.
    if (fCompPB->LastNotifyParamID() != -1)
    {
        ParamID id = fCompPB->LastNotifyParamID();
        if (is_ref(fCompPB->GetParamDef(id)))
            return false;
    }

    return true;
}
Example #7
0
  /// Reserve memory, may change buffer type(ref, small or large).
  void reserve(size_t capacity)
  {
    if (capacity > capacity_)
    {
      /// Make capacity % RESP_SMALL_BUFFER_SIZE == 0.
      capacity =
        capacity % RESP_SMALL_BUFFER_SIZE == 0 ?
        capacity : RESP_SMALL_BUFFER_SIZE * (capacity / RESP_SMALL_BUFFER_SIZE + 1);

      if (is_ref() || is_small())
      {
        char const* ptr = data_;
        bool is_small_before = is_small();
        if (capacity > RESP_SMALL_BUFFER_SIZE)
        {
          capacity_ = capacity;
          data_ = (char*)std::malloc(capacity_);
          if (data_ == 0)
          {
            throw std::bad_alloc();
          }
        }
        else
        {
          capacity_ = RESP_SMALL_BUFFER_SIZE;
          data_ = small_;
        }

        if (!(is_small_before && is_small()))
        {
          std::memcpy(data_, ptr, size_);
        }
      }
      else
      {
        /// large
        capacity_ = capacity;
        data_ = (char*)std::realloc(data_, capacity_);
      }
    }
  }
Example #8
0
File: erl_nif.c Project: a5an0/otp
int enif_is_ref(ErlNifEnv* env, ERL_NIF_TERM term)
{
    return is_ref(term);
}
Example #9
0
/* markdown • parses the input buffer and renders it into the output buffer */
void
markdown(struct buf *ob, struct buf *ib, const struct mkd_renderer *rndrer) {
	struct link_ref *lr;
	struct buf *text = bufnew(TEXT_UNIT);
	size_t i, beg, end;
	struct render rndr;

	/* filling the render structure */
	if (!rndrer) return;
	rndr.make = *rndrer;
	if (rndr.make.max_work_stack < 1)
		rndr.make.max_work_stack = 1;
	arr_init(&rndr.refs, sizeof (struct link_ref));
	parr_init(&rndr.work);
	for (i = 0; i < 256; i += 1) rndr.active_char[i] = 0;
	if ((rndr.make.emphasis || rndr.make.double_emphasis
						|| rndr.make.triple_emphasis)
	&& rndr.make.emph_chars)
		for (i = 0; rndr.make.emph_chars[i]; i += 1)
			rndr.active_char[(unsigned char)rndr.make.emph_chars[i]]
				= char_emphasis;
	if (rndr.make.codespan) rndr.active_char['`'] = char_codespan;
	if (rndr.make.linebreak) rndr.active_char['\n'] = char_linebreak;
	if (rndr.make.image || rndr.make.link)
		rndr.active_char['['] = char_link;
	rndr.active_char['<'] = char_langle_tag;
	rndr.active_char['\\'] = char_escape;
	rndr.active_char['&'] = char_entity;

	/* first pass: looking for references, copying everything else */
	beg = 0;
	while (beg < ib->size) /* iterating over lines */
		if (is_ref(ib->data, beg, ib->size, &end, &rndr.refs))
			beg = end;
		else { /* skipping to the next line */
			end = beg;
			while (end < ib->size
			&& ib->data[end] != '\n' && ib->data[end] != '\r')
				end += 1;
			/* adding the line body if present */
			if (end > beg) bufput(text, ib->data + beg, end - beg);
			while (end < ib->size
			&& (ib->data[end] == '\n' || ib->data[end] == '\r')) {
				/* add one \n per newline */
				if (ib->data[end] == '\n'
				|| (end + 1 < ib->size
						&& ib->data[end + 1] != '\n'))
					bufputc(text, '\n');
				end += 1; }
			beg = end; }

	/* sorting the reference array */
	if (rndr.refs.size)
		qsort(rndr.refs.base, rndr.refs.size, rndr.refs.unit,
					cmp_link_ref_sort);

	/* adding a final newline if not already present */
	if (text->size
	&&  text->data[text->size - 1] != '\n'
	&&  text->data[text->size - 1] != '\r')
		bufputc(text, '\n');

	/* second pass: actual rendering */
	if (rndr.make.prolog)
		rndr.make.prolog(ob, rndr.make.opaque);
	parse_block(ob, &rndr, text->data, text->size);
	if (rndr.make.epilog)
		rndr.make.epilog(ob, rndr.make.opaque);

	/* clean-up */
	bufrelease(text);
	lr = rndr.refs.base;
	for (i = 0; i < rndr.refs.size; i += 1) {
		bufrelease(lr[i].id);
		bufrelease(lr[i].link);
		bufrelease(lr[i].title); }
	arr_free(&rndr.refs);
	assert(rndr.work.size == 0);
	for (i = 0; i < rndr.work.asize; i += 1)
		bufrelease(rndr.work.item[i]);
	parr_free(&rndr.work); }
Example #10
0
/* markdown • parses the input buffer and renders it into the output buffer */
void
ups_markdown(struct buf *ob, struct buf *ib, const struct mkd_renderer *rndrer, unsigned int extensions) {
	struct link_ref *lr;
	struct buf *text;
	size_t i, beg, end;
	struct render rndr;

	/* filling the render structure */
	if (!rndrer)
		return;

	text = bufnew(TEXT_UNIT);
	if (!text)
		return;

	rndr.make = *rndrer;
	arr_init(&rndr.refs, sizeof (struct link_ref));
	parr_init(&rndr.work);

	for (i = 0; i < 256; i += 1)
		rndr.active_char[i] = 0;

	if (rndr.make.emphasis || rndr.make.double_emphasis || rndr.make.triple_emphasis) {
		rndr.active_char['*'] = char_emphasis;
		rndr.active_char['_'] = char_emphasis;
		if (extensions & MKDEXT_STRIKETHROUGH)
			rndr.active_char['~'] = char_emphasis;
	}

	if (rndr.make.codespan)
		rndr.active_char['`'] = char_codespan;

	if (rndr.make.linebreak)
		rndr.active_char['\n'] = char_linebreak;

	if (rndr.make.image || rndr.make.link)
		rndr.active_char['['] = char_link;

	rndr.active_char['<'] = char_langle_tag;
	rndr.active_char['\\'] = char_escape;
	rndr.active_char['&'] = char_entity;

	if (extensions & MKDEXT_AUTOLINK) {
		rndr.active_char['h'] = char_autolink; // http, https
		rndr.active_char['H'] = char_autolink;

		rndr.active_char['f'] = char_autolink; // ftp
		rndr.active_char['F'] = char_autolink;

		rndr.active_char['m'] = char_autolink; // mailto
		rndr.active_char['M'] = char_autolink;
	}

	/* Extension data */
	rndr.ext_flags = extensions;
	rndr.max_nesting = 16;

	/* first pass: looking for references, copying everything else */
	beg = 0;
	while (beg < ib->size) /* iterating over lines */
		if (is_ref(ib->data, beg, ib->size, &end, &rndr.refs))
			beg = end;
		else { /* skipping to the next line */
			end = beg;
			while (end < ib->size && ib->data[end] != '\n' && ib->data[end] != '\r')
				end += 1;

			/* adding the line body if present */
			if (end > beg)
				expand_tabs(text, ib->data + beg, end - beg);

			while (end < ib->size && (ib->data[end] == '\n' || ib->data[end] == '\r')) {
				/* add one \n per newline */
				if (ib->data[end] == '\n' || (end + 1 < ib->size && ib->data[end + 1] != '\n'))
					bufputc(text, '\n');
				end += 1;
			}

			beg = end;
		}

	/* sorting the reference array */
	if (rndr.refs.size)
		qsort(rndr.refs.base, rndr.refs.size, rndr.refs.unit, cmp_link_ref_sort);

	/* adding a final newline if not already present */
	if (!text->size)
		goto cleanup;

	if (text->data[text->size - 1] != '\n' &&  text->data[text->size - 1] != '\r')
		bufputc(text, '\n');

	/* second pass: actual rendering */
	if (rndr.make.doc_header)
		rndr.make.doc_header(ob, rndr.make.opaque);

	parse_block(ob, &rndr, text->data, text->size);

	if (rndr.make.doc_footer)
		rndr.make.doc_footer(ob, rndr.make.opaque);

	/* clean-up */
cleanup:
	bufrelease(text);
	lr = rndr.refs.base;
	for (i = 0; i < (size_t)rndr.refs.size; i += 1) {
		bufrelease(lr[i].id);
		bufrelease(lr[i].link);
		bufrelease(lr[i].title);
	}

	arr_free(&rndr.refs);

	assert(rndr.work.size == 0);

	for (i = 0; i < (size_t)rndr.work.asize; i += 1)
		bufrelease(rndr.work.item[i]);

	parr_free(&rndr.work);
}
Example #11
0
bool Type::is_boolifiable() const {
    return is_top() || is_primitive() || is_ref();
}