Пример #1
0
/*
 * This function generates a CREATE TABLE statement from
 * `tbl' and writes it to the file specified by `fd'.
 */
void table_desc_to_sql(int fd, const struct table_desc *tbl)
{
	char *buff;
	size_t size;
	long stored;
	const struct column_desc *col;

	size = DEF_BUFF_SIZE;
	buff = alloc_buff(size);
	stored = sprintf(buff, "CREATE TABLE %s (\n", tbl->t_name);
	for (col = tbl->c_head; col; col = col->next) {
		buff = ensure_capacity(buff, &size, (size_t) stored);
		stored += sprint_column(buff + stored, col);
	}

	buff = ensure_capacity(buff, &size, (size_t) stored);
	if (tbl->t_pkname && strlen(tbl->t_pkname) > 0) {
		strcpy(buff + stored, "\n);\n\n");
		stored += strlen("\n);\n\n");
		sprint_named_pk(buff + stored, tbl);
	} else {
		stored += sprint_anon_pk(buff + stored, tbl->c_head);
		strcpy(buff + stored, "\n);\n");
	}

	write_file(fd, buff);
	free_buff(buff);
}
Пример #2
0
// Append the specified component to the end of the op.
static void append(text_op *op, const text_op_component c) {
  if (c.type == NONE
      || ((c.type == SKIP || c.type == DELETE) && c.num == 0)
      || (c.type == INSERT && !c.str.mem && c.str.chars[0] == '\0')) {
    // We're not inserting any actual data. Skip.
    return;
  } else if (op->components == NULL) {
    // Small op.
    if (op->content.type == NONE) {
      if (c.type == SKIP) {
        op->skip += c.num;
      } else {
        op->content = copy_component(c);
      }
      return;
    } else if (op->content.type == c.type) {
      if (c.type == DELETE) {
        op->content.num += c.num;
        return;
      } else if (c.type == INSERT) {
        str_append(&op->content.str, &c.str);
        return;
      }
    }
    
    // Fall through here if the small op can't hold the new component. Expand it and append.
    ensure_capacity(op);
    op->components[op->num_components++] = copy_component(c);
  } else {
    // Big op.
    if (op->num_components == 0) { // This will basically never happen.
      // The list is empty. Create a new node.
      ensure_capacity(op);
      op->components[0] = copy_component(c);
      op->num_components++;
    } else {
      text_op_component *lastC = &op->components[op->num_components - 1];
      if (lastC->type == c.type) {
        if (c.type == DELETE || c.type == SKIP) {
          // Extend the delete / skip component.
          lastC->num += c.num;
        } else {
          // Extend the insert component.
          str_append(&lastC->str, &c.str);
        }
      } else {
        ensure_capacity(op);
        op->components[op->num_components++] = copy_component(c);
      }
    }
  }
}
Пример #3
0
DirectResult
fusion_vector_insert( FusionVector *vector,
                      void         *element,
                      int           index )
{
     D_MAGIC_ASSERT( vector, FusionVector );
     D_ASSERT( element != NULL );
     D_ASSERT( index >= 0 );
     D_ASSERT( index <= vector->count );

     /* Make sure there's a free entry left. */
     if (!ensure_capacity( vector ))
          return D_OOSHM();

     /* Move elements from insertion point one up. */
     memmove( &vector->elements[ index + 1 ],
              &vector->elements[ index ],
              (vector->count - index) * sizeof(void*) );

     /* Insert the element into the vector. */
     vector->elements[index] = element;

     /* Increase the element counter. */
     vector->count++;

     return DR_OK;
}
Пример #4
0
void mpfx_manager::allocate(mpfx & n) {
    SASSERT(n.m_sig_idx == 0);
    unsigned sig_idx = m_id_gen.mk();
    ensure_capacity(sig_idx);
    n.m_sig_idx = sig_idx;
    SASSERT(::is_zero(m_total_sz, words(n)));
}
Пример #5
0
 inline T *alloc_ck(intptr_t &inout_ckb_offset)
 {
   intptr_t ckb_offset = inout_ckb_offset;
   kernels::inc_ckb_offset<T>(inout_ckb_offset);
   ensure_capacity(inout_ckb_offset);
   return reinterpret_cast<T *>(m_data + ckb_offset);
 }
Пример #6
0
GArray*
g_array_insert_vals (GArray *array,
		     guint index_,
		     gconstpointer data,
		     guint len)
{
	GArrayPriv *priv = (GArrayPriv*)array;
	guint extra = (priv->zero_terminated ? 1 : 0);

	g_return_val_if_fail (array != NULL, NULL);

	ensure_capacity (priv, array->len + len + extra);
  
	/* first move the existing elements out of the way */
	memmove (element_offset (priv, index_ + len),
		 element_offset (priv, index_),
		 element_length (priv, array->len - index_));

	/* then copy the new elements into the array */
	memmove (element_offset (priv, index_),
		 data,
		 element_length (priv, len));

	array->len += len;

	if (priv->zero_terminated) {
		memset (element_offset (priv, priv->array.len),
			0,
			priv->element_size);
	}

	return array;
}
Пример #7
0
		/// Set at element at index, enlarge the vector if necessary.
		void set_at(size_t i, const T& element) {
			if (i >= m_size) {
				ensure_capacity(i + 1);	
				m_size = i + 1;
			}
			m_elements[i] = element;
		}
Пример #8
0
deque::iterator deque::insert(deque::iterator pos, std::string const& x) {
	if (_size + 1 == (size_t)capacity) {
		int num = pos - begin();
		ensure_capacity(_size+1);
		pos = begin() + num;
	}
	size_t left = pos - begin();
	size_t right = end() - pos;
	iterator ret;
	if (left < right) {
		int off = (int(_first - head) - 1 + capacity) % capacity;
		iterator cur = begin();
		new (head + off) std::string(x);
		while (cur != pos) {
			std::swap(*cur, *(cur-1));
			++cur;
		}
		_first = head + off;
		ret = (pos-1);
	} else {
		new (head + (_first - head + size()) % capacity) std::string(x); // end()
		iterator cur = end();
		while (cur != pos) {
			std::swap(*(cur - 1), *cur);
			--cur;
		}
		ret = pos;
	}
	++_size;
	return ret;
}
Пример #9
0
GArray *
g_array_append_vals (GArray *array,
		     gconstpointer data,
		     guint len)
{
	GArrayPriv *priv = (GArrayPriv*)array;

	g_return_val_if_fail (array != NULL, NULL);

	ensure_capacity (priv, priv->array.len + len + (priv->zero_terminated ? 1 : 0));
  
	memmove (element_offset (priv, priv->array.len),
		 data,
		 element_length (priv, len));

	priv->array.len += len;

	if (priv->zero_terminated) {
		memset (element_offset (priv, priv->array.len),
			0,
			priv->element_size);
	}

	return array;
}
/*
 * Inserts item to the queue.
 * Returns TRUE on success, FALSE otherwise.
 */
int priority_queue_insert( priority_queue *pq, void *item )
{
        if ( pq == NULL )
        {
                printf( "Priority queue is uninitialized.\n" );
                return FALSE;
        }
        else if ( item == NULL )
        {
                printf( "Item pointer is NULL.\n" );
                return FALSE;
        }
        else
        {
                /* 2 = 1 for spare item in array + 1 for next item */
                if( ensure_capacity( pq, pq->heap_size + 2 ) == FALSE )
                {
                        printf( "\nPriority queue out of memory.\n" );
                        return FALSE;
                }

                pq->heap_size += 1;
                pq->heap_array[ pq->heap_size ] = item;
                repair_bottom( pq, pq->heap_size );

                return TRUE;
        }
        return FALSE;
}
Пример #11
0
static inline bool append_buf_c(struct result_buf *buf, char v) {
  if (ensure_capacity(buf, 1)) {
    buf->output[buf->len++] = v;
    return true;
  } else {
    return false;
  }
}
Пример #12
0
Buffer<Allocator>& Buffer<Allocator>::zero_terminate()
{
	ensure_capacity(1);

	*_pos = '\0';

	return *this;
}
Пример #13
0
Buffer<Allocator>& Buffer<Allocator>::write(char c)
{
	ensure_capacity(1);

	*_pos++ = c;

	return *this;
}
Пример #14
0
ResizeableBuffer& ResizeableBuffer::write_ptr(const void* aptr,size_t alen) {
	if(1>alen)
		ThrowInternalError("invalid length");
	ensure_capacity(alen);
	memcpy(ptr+len,aptr,alen);
	len += alen;
	return *this;
}
Пример #15
0
static inline bool append_buf(struct result_buf *buf, const char* input, int len) {
  if (ensure_capacity(buf, len)) {
    memcpy(buf->output + buf->len, input, len);
    buf->len += len;
    return true;
  } else {
    return false;
  }
}
Пример #16
0
GByteArray *
g_byte_array_new ()
{
	GByteArray *rv = g_new0 (GByteArray, 1);

	ensure_capacity (rv, INITIAL_CAPACITY);

	return rv;
}
Пример #17
0
void stack::push( double d )
	// Use ensure_capacity, so that
	// pushing is always possible, as
	// long as memory is not full.
{
	ensure_capacity(current_size + 1);
	tab[current_size] = d;
	//tab[current_size++] = d; ???
	current_size++;
}
Пример #18
0
Buffer<Allocator>& Buffer<Allocator>::write(const char *cs, size_t sz)
{
	ensure_capacity(sz);

	memcpy(_pos, cs, sizeof(char) * sz);

	_pos += sz;

	return *this;
}
Пример #19
0
		/// Assignment operator.
		Vector<T>& operator=(const Vector<T>& other) {
			if (this != &other) {
				clear();
				m_size = other.m_size;
				ensure_capacity(other.m_capacity);
				if (m_size != NULL)
					copy_from(other.m_elements, m_size);
			}
			return *this;
		}
Пример #20
0
		/// Resize the vector (cannot increase the size).
		void resize(size_t new_size) {
			if (new_size == m_size)
				return;
			else if (new_size < m_size) {
				m_size = new_size;
				return;
			} else {
				ensure_capacity(new_size);
			}
		}
Пример #21
0
int
xm_strbuf_catb(xm_strbuf *dest, char *src, size_t len)
{
	if (ensure_capacity(dest, len) < 0)
		return -1;

	memcpy(dest->buf + dest->len, src, len);
	dest->len += len;

	return 0;
}
Пример #22
0
void mpff_manager::allocate(mpff & n) {
    SASSERT(n.m_sig_idx == 0);
    unsigned sig_idx = m_id_gen.mk();
    ensure_capacity(sig_idx);
    n.m_sig_idx = sig_idx;
    DEBUG_CODE({
            unsigned * s = sig(n);
            for (unsigned i = 0; i < m_precision; i++) {
                SASSERT(s[i] == 0);
            }
        });
Пример #23
0
ResizeableBuffer& ResizeableBuffer::nprintf(size_t maxlen,const char* const fmt,...) {
	va_list args;
	va_start(args,fmt);
	ensure_capacity(maxlen);
	const int used = vsnprintf(ptr+len,maxlen,fmt,args);
	va_end(args);
	check(used);
	if(used==(int)maxlen)
		ThrowInternalError("buffer overflow");
	len += used;
	return *this;
}
Пример #24
0
		uint32_t Scene::push_node(Node node, MaterialId material) {
			ensure_capacity(_node_count + 1);
			_nodes[_node_count] = node;
			_materials[_node_count] = material;
			_node_count += 1;

			//if the object is emitting add it in the lights
			Material& color = _material_bucket[material];
			if (color.emitted.x > 0.f || color.emitted.y > 0.f || color.emitted.z > 0.f) {
				_light_sources.push_back(_node_count - 1);
			}
			return _node_count;
		}
Пример #25
0
    // returns 0 on success or GenesisErrorNoMem
    int __attribute__((warn_unused_result)) push(T item) {
        OsMutexLocker locker(_mutex);

        int err = ensure_capacity(_length + 1);
        if (err)
            return err;

        _length += 1;
        _items[_end] = item;
        _end = (_end + 1) % _capacity;
        os_cond_signal(_cond, _mutex);
        return 0;
    }
Пример #26
0
		/// Insert an element after a specific index. Resize if necessary.
		void insert_at(size_t i, const T& element) {
			ensure_capacity(m_size + 1);
			if (i > m_size)
				m_size = i+1;
			else {
				size_t elements_to_move = m_size - i;
				if (elements_to_move != 0) {
					std::memmove(m_elements + i + 1, m_elements + i, elements_to_move*sizeof(T));
					std::memset(m_elements + i, 0, sizeof(T));
				}
				++ m_size;
			}
			m_elements[i] = element;
		}
Пример #27
0
Buffer<Allocator>& Buffer<Allocator>::write_dot_to_slash(Utf8String u) {
	ensure_capacity(u.size());

	const char* src = u.begin();
	const char* end = u.end();

	for ( ; src != end; ++_pos, ++src ) {
		char c = *src;

		*_pos = (c == '.') ? '/' : c;
	}

	return *this;
}
Пример #28
0
/**
 * append some data to a bytebuffer. If there's not enough room in the buffer then the buffer will be extended to
 * accomodate the data
 * 
 * @param b     bytebuffer
 * @param src   source
 * @param len   length
 * @return 0 if added, 1 if error
 */
int bytebuffer_put(struct bytebuffer *b, void *src, int len) {
    if (0 != pthread_mutex_lock(&b->mutex)) {
        return BYTEBUFFER_ERROR;
    }

    if(ensure_capacity(b, b->pos + len)==BYTEBUFFER_ERROR)
        return BYTEBUFFER_ERROR;
    
    memcpy(b->buffer + b->pos, src, len);
    b->pos += len;

    pthread_mutex_unlock(&b->mutex);
    return BYTEBUFFER_OK;
}
Пример #29
0
    pointer emplace_back(Args&& ... args)
    {
        if (!ensure_capacity())
        {
            // Indicate error by returning null pointer
            return nullptr;
        }

        // Construct new element at the end of the collection
        collection_.emplace_back(args...);

        // Return pointer to newly created element
        return &collection_.back();
    }
Пример #30
0
GArray *
g_array_new (gboolean zero_terminated,
	     gboolean clear_,
	     guint element_size)
{
	GArrayPriv *rv = g_new0 (GArrayPriv, 1);
	rv->zero_terminated = zero_terminated;
	rv->clear_ = clear_;
	rv->element_size = element_size;

	ensure_capacity (rv, INITIAL_CAPACITY);

	return (GArray*)rv;
}