buffer_result write2buf(buffer *buf, const char *c, size_t l) { size_t newl; char *newbuf; buffer_result ret = WRITE_OK; newl = buf->len + l; if (newl >= buf->buf_size) { buf->buf_size *= 2; if(buf->buf_size <= newl) { buf->buf_size = (int)(newl + 1); } if(buf->buf_size > buf->limit){ buf->buf_size = buf->limit + 1; } newbuf = (char*)ruby_xrealloc(buf->buf, buf->buf_size); buf->buf = newbuf; } if(newl >= buf->buf_size){ l = buf->buf_size - buf->len -1; ret = LIMIT_OVER; } memcpy(buf->buf + buf->len, c , l); buf->len += (int)l; return ret; }
static void *WSF_CALL wsf_realloc_warpper ( axutil_allocator_t * allocator, void *ptr, size_t size) { return ruby_xrealloc(ptr, size); }
/* * call-seq: Fiddle.realloc(addr, size) * * Change the size of the memory allocated at the memory location +addr+ to * +size+ bytes. Returns the memory address of the reallocated memory, which * may be different than the address passed in. */ static VALUE rb_fiddle_realloc(VALUE self, VALUE addr, VALUE size) { void *ptr = NUM2PTR(addr); ptr = (void*)ruby_xrealloc(ptr, NUM2INT(size)); return PTR2NUM(ptr); }
void * ruby_xrealloc2(void *ptr, size_t n, size_t size) { size_t len = size * n; if (n != 0 && size != len / n) { rb_raise(rb_eArgError, "realloc: possible integer overflow"); } return ruby_xrealloc(ptr, len); }
/* * call-seq: DL.realloc(addr, size) * * Change the size of the memory allocated at the memory location +addr+ to * +size+ bytes. Returns the memory address of the reallocated memory, which * may be different than the address passed in. */ VALUE rb_dl_realloc(VALUE self, VALUE addr, VALUE size) { void *ptr = NUM2PTR(addr); rb_secure(4); ptr = (void*)ruby_xrealloc(ptr, NUM2INT(size)); return PTR2NUM(ptr); }