Esempio n. 1
0
void rjs_file_unmap(rstr_t *buf)
{
	if (buf) {
		r_free(buf->str);
		r_free(buf);
	}
}
Esempio n. 2
0
/*
 *  GEN_write assembles the generic operator to a binary file pointed
 *  to by fp.  This is done by repeated evaluation of the coordinate
 *  vector p[i]=1 for i=0,..,neq.
 *
 *  row_data points to the row-space r_data and col_data points to the
 *  column-space r_data.
 */
int GEN_write(FILE* fp, GEN_operator* A_ptr,
              r_data* row_data, r_data* col_data)
{
  r_vector r1,r2;
  int rows,cols;
  int i;

  if(!r_allocate(&r2,row_data))
    return 0;
  if(!r_allocate(&r1,col_data))
    return 0;

  rows=row_data->neq;
  cols=col_data->neq;

  fwrite(&rows,sizeof(int),1,fp);
  fwrite(&cols,sizeof(int),1,fp);

  for(i=0;i<cols;i++)
  {
    r1.vec[i]=1.0;
    GEN_eval(&r2,&r1,A_ptr);
    fwrite(r2.vec,sizeof(double),rows,fp);
    r1.vec[i]=0.0;
    r_zero(&r2);
  }
  fflush(fp);

  r_free(&r1);
  r_free(&r2);

  return 1;
}
Esempio n. 3
0
static void
r_task_queue_free (RTaskQueue * queue)
{
  if (queue != NULL) {
    ruint i;

    for (i = 0; i < queue->ctxcount; i++) {
      r_mutex_lock (&queue->ctx[i].mutex);
      R_LOG_TRACE ("TQ: %p [%p] - stop", queue, &queue->ctx[i]);
      queue->ctx[i].running = FALSE;
      r_cond_broadcast (&queue->ctx[i].cond);
      r_mutex_unlock (&queue->ctx[i].mutex);
    }

    r_thread_pool_join (queue->pool);
    r_thread_pool_unref (queue->pool);

    for (i = 0; i < queue->ctxcount; i++) {
      r_queue_free (queue->ctx[i].q, r_task_unref);
      r_cond_clear (&queue->ctx[i].cond);
      r_mutex_clear (&queue->ctx[i].mutex);
    }

    r_cond_clear (&queue->wait_cond);
    r_mutex_clear (&queue->wait_mutex);

    r_free (queue->ctx);
    r_free (queue);
  }
}
Esempio n. 4
0
int main() {
#define MB 7
#define R_MALLOC_MAX 1024*1024*MB

#if R_ALLOC_USE_STACK
	char B[R_MALLOC_MAX];
#endif
#if R_ALLOC_USE_MMAP
	int fd = open (".mem", O_CREAT|O_RDWR, 0600);
	ftruncate (fd, R_MALLOC_MAX);
	char *B = mmap (NULL, R_MALLOC_MAX, PROT_WRITE|PROT_READ,
		MAP_FILE|MAP_PRIVATE, fd, 0);
	unlink (".mem");
	close (fd);
#endif

//char *B = sbrk (1024*1024*MB);
	InitMem (B, R_MALLOC_MAX);

	char *a = r_malloc (1024);
	if (!a) {
		printf ("cant malloc\n");
		return 1;
	}
	strcpy (a, "hello");
	char *b = r_malloc (1024);
	strcpy (b, "world");
	printf ("%s %s\n", a, b);
	r_free (b);
	r_free (a);
	return 0;
}
Esempio n. 5
0
void PCG_free(void* A_ptr)
{
  PCG_operator *PCG_ptr=A_ptr;

  if(!(PCG_ptr->ow))
    r_free(&PCG_ptr->r);
  r_free(&PCG_ptr->p);
  r_free(&PCG_ptr->z);
  free(PCG_ptr);
}
Esempio n. 6
0
File: rmac.c Progetto: ieei/rlib
void
r_hmac_free (RHmac * hmac)
{
  if (hmac != NULL) {
    r_hash_free (hmac->inner);
    r_hash_free (hmac->outer);
    r_free (hmac->keyblock);
    r_free (hmac);
  }
}
Esempio n. 7
0
void r_buffer_destroy(rbuffer_t *buffer)
{
	if (buffer) {
		if (buffer->alt_destroy) {
			buffer->alt_destroy(buffer);
			return;
		} else {
			r_free(buffer->s);
			r_free(buffer);
		}
	}
}
Esempio n. 8
0
void rex_dfasimulator_destroy(rex_dfasimulator_t *si)
{
	if (si) {
		r_array_destroy(si->accepts);
		r_free(si);
	}
}
Esempio n. 9
0
/**
 * @brief Open a new resource descriptor function
 *
 * @param mrl The filesystem path of the resource.
 * @param dmx The demuxer to use to open the resource.
 */
static Resource *r_open_direct(gchar *mrl, const Demuxer *dmx)
{
    Resource *r;
    struct stat filestat;

    if (stat(mrl, &filestat) < 0 ) {
        xlog(LOG_ERR, "stat");
        return NULL;
    }

    if ( S_ISFIFO(filestat.st_mode) ) {
        xlog(LOG_ERR, "%s: not a file", mrl);
        return NULL;
    }

    r = g_slice_new0(Resource);

    r->mrl = mrl;
    r->mtime = filestat.st_mtime;
    r->seekable = (dmx->seek != NULL);

    r->demuxer = dmx;

    if (r->demuxer->init(r)) {
        r_free(r);
        return NULL;
    }
    /* Now that we have opened the actual resource we can proceed with
     * the extras */

    r->lock = g_mutex_new();

    return r;
}
Esempio n. 10
0
rstr_t *rjs_file_map(const char *filename)
{
	rstr_t *buf = NULL;
	char *pMappedView = NULL;
	HANDLE hFile = INVALID_HANDLE_VALUE;
	HANDLE hMapping = 0;
	unsigned __int64 fileSize;
	DWORD sizeLo, sizeHi;

	buf = (rstr_t*)r_malloc(sizeof(*buf));
	if (!buf)
		return NULL;
	hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, 0);
	if (INVALID_HANDLE_VALUE == hFile)
		goto error;
	sizeLo = GetFileSize(hFile, &sizeHi);
	fileSize = (UINT64)sizeLo | ((UINT64)sizeHi << 32);
	hMapping = CreateFileMapping(hFile, 0, PAGE_READONLY, sizeHi, sizeLo, 0);
	if (!hMapping)
		goto error;
	pMappedView = (char*)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);
	if (NULL == pMappedView)
		goto error;
	buf->size = (unsigned long)fileSize;
	buf->str = (char*)r_zmalloc((unsigned long)fileSize + 1);
	if (!buf->str)
		goto error;
	r_memcpy(buf->str, pMappedView, (unsigned long)fileSize);
	if (hMapping)
		CloseHandle(hMapping);
	if (hFile != INVALID_HANDLE_VALUE)
		CloseHandle(hFile);
	if (pMappedView)
		UnmapViewOfFile(pMappedView);
	return buf;

error:
	if (hMapping)
		CloseHandle(hMapping);
	if (hFile != INVALID_HANDLE_VALUE)
		CloseHandle(hFile);
	if (pMappedView)
		UnmapViewOfFile(pMappedView);
	r_free(buf->str);
	r_free(buf);
	return NULL;
}
Esempio n. 11
0
File: rthreads.c Progetto: ieei/rlib
void
r_cond_clear (RCond * cond)
{
#if defined (HAVE_PTHREAD_H)
  pthread_cond_destroy ((pthread_cond_t *)*cond);
#endif
  r_free (*cond);
}
Esempio n. 12
0
File: rthreads.c Progetto: ieei/rlib
static void
r_thread_free (RThread * thread)
{
  if (R_LIKELY (thread != NULL)) {
#ifdef RLIB_HAVE_THREADS
#if defined (R_OS_WIN32)
    CloseHandle ((HANDLE)thread->thread);
#elif defined (HAVE_PTHREAD_H)
    if (R_UNLIKELY (!thread->joined))
      pthread_detach (thread->thread);
    r_mutex_clear (&thread->join_mutex);
#endif
#endif
    r_free (thread->name);
    r_free (thread);
  }
}
Esempio n. 13
0
File: rclock.c Progetto: ieei/rlib
static void
r_test_clock_free (RTestClock * clock)
{
  r_clock_clear (clock);

  r_cond_clear (&clock->cond);
  r_mutex_clear (&clock->mutex);
  r_free (clock);
}
Esempio n. 14
0
void rex_compiler_destroy(rexcompiler_t *co)
{
	if (co) {
		r_array_destroy(co->stack);
		r_array_destroy(co->temptrans);
		r_free(co);
	}

}
Esempio n. 15
0
void rpa_compiler_destroy(rpa_compiler_t *co)
{
	if (co) {
		rvm_codegen_destroy(co->cg);
		rvm_scope_destroy(co->scope);
		r_object_destroy((robject_t*)co->ruleprefs);
		r_object_destroy((robject_t*)co->expressions);
		r_free(co);
	}
}
Esempio n. 16
0
File: rthreads.c Progetto: ieei/rlib
void
r_rmutex_clear (RRMutex * mutex)
{
#if defined (R_OS_WIN32)
  DeleteCriticalSection ((LPCRITICAL_SECTION)*mutex);
#elif defined (HAVE_PTHREAD_H)
  pthread_mutex_destroy ((pthread_mutex_t *)*mutex);
#endif
  r_free (*mutex);
}
Esempio n. 17
0
static void
r_task_free (RTask * task)
{
  if (R_LIKELY (task != NULL)) {
    if (task->datanotify != NULL)
      task->datanotify (task->data);
    r_slist_destroy_full (task->dep, r_task_unref);
    r_free (task);
  }
}
Esempio n. 18
0
void mg_vector_free(mg_vector* mgp)
{
  int i,i0,i1;

  i0=mgp->i0;
  i1=mgp->i1;

  for(i=i0;i<=i1;i++)
    r_free(&mgp->r_list[i]);
  free(mgp->r_list);
}
Esempio n. 19
0
void UdpSend_deinit(udp_send_module_handle *p_udp_send)
{
	if(NULL == p_udp_send) {
		ERR_PRINTF("p_udp_send = [%p]", p_udp_send);
	}

	if(NULL != p_udp_send->udp_hand.src_data) {
		r_free(p_udp_send->udp_hand.src_data);
		p_udp_send->udp_hand.src_data = NULL;
	}

	if(0 < p_udp_send->udp_hand.snd_fd) {
		close_socket(p_udp_send->udp_hand.snd_fd);
		p_udp_send->udp_hand.snd_fd = -1;
	}

	UdpSend_rtp_build_uninit(&p_udp_send->rtp_hand);
	r_free(p_udp_send);
	p_udp_send = NULL;
}
Esempio n. 20
0
void r_carray_cleanup(robject_t *obj)
{
	unsigned long i;
	rcarray_t *carray = (rcarray_t *)obj;
	if (carray->oncleanup)
		carray->oncleanup(carray);
	for (i = 0; i < r_array_length(carray->array); i++)
		r_free(r_carray_get_chunk(carray, i));
	r_object_destroy((robject_t*)carray->array);
	r_object_cleanup((robject_t*)carray);
}
Esempio n. 21
0
void r_hash_fini(struct r_hash_table *ht)
{
	uint32_t i;

	if (ht->ht_chain != NULL) {
		for (i = 0; i < (1 << ht->ht_order); ++i)
			R_ASSERT(ht->ht_chain[i] == NULL);
		r_free(ht->ht_chain);
		ht->ht_chain = NULL;
	}
}
Esempio n. 22
0
void r_state_free (RState* r)
{
    r->last_error          = R_UNDEFINED;
    r->current_input_port  = R_UNDEFINED;
    r->current_output_port = R_UNDEFINED;
    r->current_error_port  = R_UNDEFINED;

    vm_finish (r);
    gc_finish (r);

    r_free (r, r);
}
Esempio n. 23
0
void *test_busy_work(void *t) {
	ruint32 i;
	RDummy *pDummy;
	long tid = (long)t;

	printf("Thread %ld starting...\n", tid);
	for (i = 0; i < NUM_ITERATIONS; i++) {
		pDummy = (RDummy*)r_malloc(sizeof(*pDummy));
		r_free(pDummy);
	}
	printf("Thread %ld done. \n", tid);
	pthread_exit((void*) t);
}
Esempio n. 24
0
/**
 * Set the value (text) for this Text entity. If the text is currently empty
 * and we are trying to set another empty value, just return.
 */
void
text_set_value(Text *text, char *value)
{
	if (value[0] == '\0' && text->length == 0)
		return;

	text->length = strlen((char *)value);
	r_free(text->value);
	text->value = r_malloc(text->length + 1);
	strlcpy((char *)text->value, (char *)value, text->length + 1);

	text_calculate_size(text);
}
Esempio n. 25
0
File: rdsa.c Progetto: ieei/rlib
static void
r_dsa_pub_key_free (rpointer data)
{
  RDsaPubKey * key;

  if ((key = data) != NULL) {
    r_mpint_clear (&key->p);
    r_mpint_clear (&key->q);
    r_mpint_clear (&key->g);
    r_mpint_clear (&key->y);
    r_crypto_key_destroy ((RCryptoKey *)key);
    r_free (key);
  }
}
Esempio n. 26
0
void del_head_node(node_t **head)
{
	node_t *tmp_next = NULL;
	node_t *free_node = *head;

	if(NULL == free_node->next) {
		return;
	}

	tmp_next =  free_node->next;
	r_free(free_node);
	free_node = NULL;
	*head = tmp_next;
}
Esempio n. 27
0
void del_part_list(node_t **head, node_t *curnode)
{
	node_t *temp = *head;

	while(curnode != temp && NULL != temp) {
		temp =  temp->next;
		free(*head);
		*head = temp;
	}

	*head = (node_t *)curnode->next;
	//nslog(NS_INFO, "[del_part_list]++++++++++++++++++ temp : [%p] *head : [%p]\n", t);
	r_free(curnode);
	curnode = NULL;
}
Esempio n. 28
0
int rex_dfa_hash(rexdfa_t *dfa, unsigned int hbytes, unsigned int hbits)
{
	if ((REX_DFA_HASHBITS(hbytes, hbits) - 3) > 24)
		return -1;
	if (!dfa)
		return -1;
	if (dfa->bits)
		r_free(dfa->bits);
	dfa->hbytes = hbytes;
	dfa->hbits = hbits;
	dfa->hsize = REX_DFA_HASHSIZE(hbytes, hbits) >> 3;
	dfa->bits = (unsigned char*)r_malloc(dfa->hsize);
	rex_dfa_statehash(dfa, REX_DFA_STARTSTATE, hbytes - 1, hbits, 0);
	return 0;
}
Esempio n. 29
0
rbuffer_t *r_buffer_create(unsigned long size)
{
	rbuffer_t *buffer;

	buffer = (rbuffer_t *)r_malloc(sizeof(rbuffer_t));
	if (!buffer)
		return (void*)0;
	r_memset(buffer, 0, sizeof(*buffer));
	if (!(buffer->s = (char *)r_malloc((size + 1) * sizeof(char)))) {
		r_free(buffer);
		return (void*)0;
	}
	r_memset(buffer->s, 0, size + 1);
	buffer->size = size;
	return buffer;
}
Esempio n. 30
0
SDL_Surface *
cube_get_surface(Cube *cube)
{
	SDL_Surface *s;
	SDL_Rect src;
	SDL_Rect *dst = NULL;
	int fs = cube->fade_status;
	
	/* All cubes are fixed size. Set DestRect and SourceRect. */
	src.w = BSIZE;
	src.h = BSIZE;
	src.y = cube->current_position * BSIZE;
	src.x = (cube->type - 1) * BSIZE;

	s = SDL_CreateRGBSurface(0, BSIZE, BSIZE, screen->format->BitsPerPixel,
			0, 0, 0, 0);
	SDL_FillRect(s, NULL, key);
	SDL_SetColorKey(s, SDL_SRCCOLORKEY|SDL_RLEACCEL, key);

	/* If we have a fade_status, we need to crop a smaller area. */
	if (fs > 0) {
		dst = r_malloc(sizeof(SDL_Rect));
		dst->x = dst->y = fs;
		dst->w = dst->h = fs * 2;
		src.x += fs;
		src.y += fs;
		src.w -= fs * 2;
		src.h -= fs * 2;
	}

	SDL_BlitSurface(sprites, &src, s, dst);

	/* If this cube has water, find the water mask 64px lower or 128px
	 * if this is type 2 water (from the right side). */
	if (cube->water) {
		src.y += BSIZE * 4 * cube->water;
		SDL_BlitSurface(sprites, &src, s, dst);
	}
	
	r_free(dst);

	/* Once again, if we are fading this dude, we should greyscale him */
	if (fs > 0)
		gfx_greyscale(s);

	return s;
}