コード例 #1
0
ファイル: dd-vec.c プロジェクト: iori11/modc
void cm_vec_free (cm_vector_t * v)
{
  if (v->vector)
    cm_free (v->vector);

  cm_free (v);
}
コード例 #2
0
ファイル: dd-vec.c プロジェクト: iori11/modc
inline
void cm_hash_free_table (cm_hash_tab_t * tbl)
{
  cm_hash_tab_t *tb = tbl;

  if (tb->array)
    cm_free (tb->array);

  cm_free (tb);
}
コード例 #3
0
/* Resize color coefficient matrix */
CMATRIX *
cm_resize(CMATRIX *cm, int nrows)
{
	size_t	old_size, new_size, ra_bounds[2];

	if (nrows == cm->nrows)
		return(cm);
	if (nrows <= 0) {
		cm_free(cm);
		return(NULL);
	}
	old_size = sizeof(CMATRIX) + sizeof(COLOR)*(cm->nrows*cm->ncols - 1);
	adjacent_ra_sizes(ra_bounds, old_size);
	new_size = sizeof(CMATRIX) + sizeof(COLOR)*(nrows*cm->ncols - 1);
	if (nrows < cm->nrows ? new_size <= ra_bounds[0] :
				new_size > ra_bounds[1]) {
		adjacent_ra_sizes(ra_bounds, new_size);
		cm = (CMATRIX *)realloc(cm, ra_bounds[1]);
		if (cm == NULL)
			error(SYSTEM, "out of memory in cm_resize()");
	}
	cm->nrows = nrows;
	return(cm);
}
コード例 #4
0
ファイル: dd-vec.c プロジェクト: iori11/modc
void cm_hash_grow_table (cm_hash_tab_t * tbl)
{
  unsigned int prev_size = tbl->size, size = 0, i;
  cm_hash_entry_t *prev_array = tbl->array, *array;

  size = threshold_alloc (prev_size);
  array = (cm_hash_entry_t*)
    cm_calloc (size, sizeof(cm_hash_entry_t));

  tbl->length = 0;
  tbl->size= size;
  tbl->array= array;

  for (i = 0; i<prev_size; ++i)
    {
      cm_hashval_t h = prev_array[i].hash;
      void *s = prev_array[i].data;

      if (s)
        cm_hash_insert (h, s, tbl);
    }
  if (prev_array)
    cm_free (prev_array);
}
コード例 #5
0
ファイル: rmatrix.c プロジェクト: germolinal/Schedules
/* Load matrix from supported file type */
RMATRIX *
rmx_load(const char *fname)
{
	FILE		*fp = stdin;
	RMATRIX		dinfo;
	RMATRIX		*dnew;

	if (fname == NULL) {			/* reading from stdin? */
		fname = "<stdin>";
#ifdef _WIN32
		_setmode(fileno(stdin), _O_BINARY);
#endif
	} else {
		const char	*sp = fname;	/* check suffix */
		while (*sp)
			++sp;
		while (sp > fname && sp[-1] != '.')
			--sp;
		if (!strcasecmp(sp, "XML")) {	/* assume it's a BSDF */
			CMATRIX	*cm = cm_loadBTDF((char *)fname);
			if (cm == NULL)
				return(NULL);
			dnew = rmx_from_cmatrix(cm);
			cm_free(cm);
			return(dnew);
		}
						/* else open it ourselves */
		if ((fp = fopen(fname, "rb")) == NULL)
			return(NULL);
	}
#ifdef getc_unlocked
	flockfile(fp);
#endif
	dinfo.nrows = dinfo.ncols = dinfo.ncomp = 0;
	dinfo.dtype = DTascii;			/* assumed w/o FORMAT */
	dinfo.info = NULL;
	if (getheader(fp, get_dminfo, &dinfo) < 0) {
		fclose(fp);
		return(NULL);
	}
	if ((dinfo.nrows <= 0) | (dinfo.ncols <= 0)) {
		if (!fscnresolu(&dinfo.ncols, &dinfo.nrows, fp)) {
			fclose(fp);
			return(NULL);
		}
		if (dinfo.ncomp <= 0)
			dinfo.ncomp = 3;
		else if ((dinfo.dtype == DTrgbe) | (dinfo.dtype == DTxyze) &&
				dinfo.ncomp != 3) {
			fclose(fp);
			return(NULL);
		}
	}
	dnew = rmx_alloc(dinfo.nrows, dinfo.ncols, dinfo.ncomp);
	if (dnew == NULL) {
		fclose(fp);
		return(NULL);
	}
	dnew->info = dinfo.info;
	switch (dinfo.dtype) {
	case DTascii:
		if (!rmx_load_ascii(dnew, fp))
			goto loaderr;
		dnew->dtype = DTascii;		/* should leave double? */
		break;
	case DTfloat:
		if (!rmx_load_float(dnew, fp))
			goto loaderr;
		dnew->dtype = DTfloat;
		break;
	case DTdouble:
		if (!rmx_load_double(dnew, fp))
			goto loaderr;
		dnew->dtype = DTdouble;
		break;
	case DTrgbe:
	case DTxyze:
		if (!rmx_load_rgbe(dnew, fp))
			goto loaderr;
		dnew->dtype = dinfo.dtype;
		break;
	default:
		goto loaderr;
	}
	if (fp != stdin)
		fclose(fp);
	return(dnew);
loaderr:					/* should report error? */
	fclose(fp);
	rmx_free(dnew);
	return(NULL);
}
コード例 #6
0
void rph_cm_free(SEXP cmP) {
  CategoryMap *cm = (CategoryMap*)EXTPTR_PTR(cmP);
  phast_unregister_protected(cm);
  cm_free(cm);
}
コード例 #7
0
ファイル: bcast.c プロジェクト: bringhurst/tmpi
int tmpi_bco_bcast(tmpi_BcastObj *bco, int myid, int root, char *data, unsigned int len) {
	register tmpi_BCHandle *curitem;
	tmpi_BCHandle *newitem;
	register tmpi_BCQueue *q;
	int ret;

	if (bco->group_size<2) return 0; /* don't do anything */ 

	q=bco->bco_array[root];

	curitem=(tmpi_BCHandle *)ukey_getval(q->key_curhandle);
	if (!curitem)
		curitem=q->first;

	if (curitem==(tmpi_BCHandle*)8L) {
		/* internal allocation error */
		return -1;
	}

	/* now curitem holds a handle whose avail is not -1 */

	if (myid==root) { /* now avail must be zero, functioning like a lock */
		/* expend the queue by one */
		newitem=tmpi_bch_alloc(bco, root);
		if (!newitem) {
			tmpi_error(DBG_INTERNAL, "bcast failed due to insufficient memory.");
			newitem=(tmpi_BCHandle*)8L;
		}
		else {
			newitem->avail=0;
			newitem->next=NULL;

		}

		curitem->next=newitem;

		/* if ((curitem->data=anl_malloc(len))==NULL) { */
		/* if ((curitem->data=mb_alloc(myid, len))==NULL) { */
		if ((curitem->data=cm_alloc(len))==NULL) { 
			curitem->len=0;
			ret=-2; /* no memory */
		}
		else {
			memcpy(curitem->data, data, len);
			curitem->len=len;
			ret=0;
		}

		thr_mtx_lock(&(curitem->lock));
		curitem->avail=1; /* the buffer is now available */
		thr_cnd_bcast(&(curitem->wait));
		thr_mtx_unlock(&(curitem->lock));

		/* same as curitem->next, but local data will ensure faster access */
		ukey_setval(q->key_curhandle, newitem);

 		/* better signal everybody, but don't do it now for easy debugging */
		/* signalAllFlag(&(curitem->avail), 1); */
		/* oh no, signalAll is too costly, why not just let recver wake by itself */
	}
	else { /* receivers */
		thr_mtx_lock(&(curitem->lock));
		while (!curitem->avail) {
			thr_cnd_wait(&(curitem->wait), &(curitem->lock));
		}
		thr_mtx_unlock(&(curitem->lock));

		if (curitem->data) {
			memcpy(data, curitem->data, MIN(len, curitem->len));
			ret=0;
		}
		else
			ret=-2;

		/* next item must be non-zero now */
		ukey_setval(q->key_curhandle, curitem->next);

		if (anf32(&(curitem->avail), 1)==bco->group_size) { /* last to leave */
			if (!ret)
				cm_free(curitem->data); 
			q->first=curitem->next;
			tmpi_bch_free(bco, root, curitem);
		}
	}

	return ret;
}