Beispiel #1
0
/* fut_free_tbl frees any table regardless of type by checking the magic
 * number in the header.  It will also free a fut_t or a fut_chan_t.
 *
 * fut_free_tbls will free a null terminated list of any type of table,
 * useful for disposing of a set of tables which were used for constructing
 * a fut (which the fut has now absorbed and made shared copies of).
 */
void
	fut_free_tbl (KpGenericPtr_t tbl)
{
	/* Make sure that we do not have a NULL pointer */
	if( tbl == NULL ) {
		return;
	}

	switch (*(KpInt32_p)tbl) {
		case FUT_MAGIC:
		fut_free ((fut_p) tbl);
		break;

		case FUT_CMAGIC:
		fut_free_chan ((fut_chan_p) tbl);
		break;

		case FUT_IMAGIC:
		fut_free_itbl ((fut_itbl_p) tbl);
		break;

		case FUT_OMAGIC:
		fut_free_otbl ((fut_otbl_p) tbl);
		break;

		case FUT_GMAGIC:
		fut_free_gtbl ((fut_gtbl_p) tbl);
		break;
	}
}
Beispiel #2
0
fut_p
	fut_free (fut_p	fut)
{
KpInt32_t	i;

	if ( ! IS_FUT(fut)) {			/* check if defined */
		return (fut);
	}

/*	fut_free_idstr (fut->idstr); */	/* free id string if exists */

	fut_free_itbl_list (fut->itbl);	/* free shared input tables */

	for ( i=0; i<FUT_NOCHAN; i++ ) {	/* free channels */
		fut_free_chan (fut->chan[i]);
		fut->chan[i] = FUT_NULL_CHAN;
	}

	for ( i=0; i<FUT_NMCHAN; i++ ) {	/* free extra reference tables */
		freeBuffer (fut->mabInRefTblHandles[i]);
		fut->mabInTblEntries[i] = 0;
		fut->mabInRefTbl[i]= NULL;
		fut->mabInRefTblHandles[i] = NULL;

		freeBuffer (fut->mabOutRefTblHandles[i]);
		fut->mabOutTblEntries[i] = 0;
		fut->mabOutRefTbl[i]= NULL;
		fut->mabOutRefTblHandles[i] = NULL;
	}
	
	fut->magic = 0;					/* free fut_t structure itself */
	freeBufferPtr ((KpGenericPtr_t)fut);

	return ((fut_p)NULL);
}
Beispiel #3
0
/* fut_defchan defines an output channel for a fut.	Returns FALSE(0) if
 * the output channel is already defined (or fut is NULL), TRUE(1)
 * otherwise.  The size of the grid table (if non-zero) must match those
 * of the corresponding input table.  If they do not, the channel remains
 * undefined and FALSE is returned.
 *
 * If a required input table is missing, the table will be shared
 * with the corresponding one from the list of common itbls.  If there
 * is no such table in the common list, a ramp table is created and
 * inserted into the common itbl list.
 *
 * Since fut_defchan is intended to be used for constructing futs with
 * shared input tables,	if an input table is supplied that conflicts with
 * a table in the common list, an error occurs.
 */
KpInt32_t
	fut_defchan (	fut_p			fut,
					KpInt32_t		iomask,
					fut_itbl_p FAR*	itbls,
					fut_gtbl_p		gtbl,
					fut_otbl_p		otbl)
{
fut_itbl_p	itbl[FUT_NICHAN];
fut_chan_p	chan;
KpInt32_t	imask, i, tIndex;

					/* check for valid fut */
	if ( ! IS_FUT(fut)) {
		return (0);
	}
					/* get input mask */
	imask = (KpInt32_t) FUT_IMASK(iomask);

					/* get args specified by imask */
	for ( i=0, tIndex = 0; i < FUT_NICHAN; i++ ) {
		if ((itbls != NULL) && ((imask & FUT_BIT(i)) != 0)) { 	/* if itbl is in arglist, use it */
			itbl[i] = (fut_itbl_p)itbls[tIndex++];
		}
		else {	/* use itbl from shared itbl list */
			itbl[i] = fut->itbl[i];
		}
	}

	chan = fut_new_chan ((KpInt32_t)(FUT_IN (FUT_ALLIN)), (fut_itbl_p FAR*)itbl, gtbl, otbl);
	if ( ! IS_CHAN(chan)) {
		return (0);
	}

	/* If fut_new_chan created a new itbl (ramp), add it to the
	 * common list.	However, if an itbl in the chan differs from
	 * one in the common list, return an error.
	 */
	for ( i=0; i < FUT_NICHAN; i++ ) {
		if ( chan->itbl[i] == NULL ) {
			continue;
		}
		
		if ( ! IS_ITBL(fut->itbl[i])) {
			fut->itbl[i] = fut_share_itbl(chan->itbl[i]);
			fut->itblHandle[i] = chan->itblHandle[i];
		}
		else {
			if ( fut->itbl[i] != chan->itbl[i] ) {
				DIAG("fut_defchan: conflicting itbls.\n", 0);
				fut_free_chan (chan);
				return (0);
			}
		}
	}

					/* insert channel into fut */
	if ( ! fut_add_chan (fut, iomask, chan) ) {
		fut_free_chan (chan);
		return (0);
	}

	return (1);
}
Beispiel #4
0
/* fut_new_chan allocates and initializes a fut_chan_t data structure.
 * If a required input table is missing, a ramp of the proper grid size
 * will be created.	If a supplied itbl is not required, it will not be
 * inserted into the channel's private itbl list.	All tables which are
 * actually used are copied and so the caller is responsible for
 * freeing the passed tables if necessary.
 *
 * If VARARGS is used, the list of input tables may be relaced by a
 * single array of fut_itbl_t pointers.	This array must then be followed
 * by a fut_gtbl_p and a fut_otbl_p.
 */
fut_chan_p
	fut_new_chan (	KpInt32_t		iomask,
					fut_itbl_p FAR*	itbls,
					fut_gtbl_p		gtbl,
					fut_otbl_p		otbl)
{
fut_itbl_p	itbl[FUT_NCHAN];
fut_chan_p	chan;
KpInt32_t	imask, i, tIndex;

	/* get input mask */
	imask = (KpInt32_t)FUT_IMASK(iomask);

	/* get args specified by imask */
	for ( i=0, tIndex = 0; i<FUT_NCHAN; i++ ) {
		itbl[i] = ((imask & FUT_BIT(i)) && (itbls != NULL)) ? itbls[tIndex++] : NULL;
	}

				/* allocate and clear the fut_chan_t structure */
	chan = fut_alloc_chan ();
	if ( ! IS_CHAN(chan)) {
		return (NULL);
	}

				/* check for valid grid and output tables */
	if (( ! IS_GTBL(gtbl)) || ((otbl != NULL) && ( ! IS_OTBL(otbl))) ) {
		DIAG("fut_new_chan: invalid grid or output table.\n", 0);
		fut_free_chan (chan);
		return (NULL);
	}

	/* get required input channels from gtbl */
	chan->imask = fut_gtbl_imask(gtbl);

				/* insert the required input tables */
	for ( i=0; i<FUT_NICHAN; i++ ) {
		if ( (chan->imask & FUT_BIT(i)) == 0 ) continue;

		if ( itbl[i] == FUT_NULL_ITBL ) {
			chan->itbl[i] = fut_new_itblEx (KCP_REF_TABLES, KCP_FIXED_RANGE, gtbl->size[i], fut_irampEx, NULL);
			if ( chan->itbl[i] == NULL) {
				DIAG("fut_new_chan: can't create itbl.\n",0);
				fut_free_chan (chan);
				return (NULL);
			}

			chan->itblHandle[i] = chan->itbl[i]->handle;
		}
		else {
			if ( ! IS_ITBL (itbl[i])) {
				DIAG("fut_new_chan: invalid input table.\n", 0);
				fut_free_chan (chan);
				return (NULL);
			}
			else {
				if ( itbl[i]->size != gtbl->size[i] ) {
					DIAG("fut_new_chan: gtbl-itbl size mismatch.\n", 0);
					fut_free_chan (chan);
					return (NULL);
				}
				else {
					chan->itbl[i] = fut_share_itbl(itbl[i]);	/* share the input table */
					chan->itblHandle[i] = chan->itbl[i]->handle;
				}
			}
		}
	}

					/* insert grid and output tables */
	chan->gtbl = fut_share_gtbl (gtbl);
	chan->gtblHandle =	(IS_GTBL(chan->gtbl)) ? chan->gtbl->handle : FUT_NULL_HANDLE;
	
	if (IS_OTBL(otbl)) {
		chan->otbl = fut_share_otbl (otbl);
	}
	else {
		chan->otbl = fut_alloc_otbl();
	}

	chan->otblHandle = (IS_OTBL(chan->otbl)) ? chan->otbl->handle : FUT_NULL_HANDLE;

	return (chan);
}
Beispiel #5
0
/* fut_copy_chan makes a copy of an existing fut_chan_t structure.
 */
fut_chan_p
	fut_copy_chan (fut_chan_p chan)
{
fut_chan_p	new_chan;
KpInt32_t		i;
KpHandle_t		h;

	if ( ! IS_CHAN(chan) ) {
		return (FUT_NULL_CHAN);
	}

	new_chan = fut_alloc_chan ();
	if ( new_chan == FUT_NULL_CHAN ) {
		return (FUT_NULL_CHAN);
	}

				/* save handle before copying over old fut */
	h = new_chan->handle;

				/* copy over to new structure */
	*new_chan = *chan;

				/* move handle back to new structure */
	new_chan->handle = h;

	/* copy itbls
	 * if an itbl is shared, share it with the itbl in the new fut
	 */
	for ( i=0; i<FUT_NICHAN; i++ ) {
		new_chan->itbl[i] = (IS_SHARED (chan->itbl[i])) ?
							fut_share_itbl (chan->itbl[i]) : fut_copy_itbl (chan->itbl[i]);
		new_chan->itblHandle[i] = getHandleFromPtr((KpGenericPtr_t)new_chan->itbl[i]);
	}

					/* copy gtbl */
	new_chan->gtbl = fut_copy_gtbl (chan->gtbl);
	new_chan->gtblHandle =  getHandleFromPtr((KpGenericPtr_t)new_chan->gtbl);

					/* copy otbl */
	new_chan->otbl = (IS_SHARED(chan->otbl)) ?
						fut_share_otbl (chan->otbl) : fut_copy_otbl (chan->otbl);
	new_chan->otblHandle = getHandleFromPtr((KpGenericPtr_t)new_chan->otbl);

					/* check for successful copies */
	for ( i=0; i<FUT_NICHAN; i++ ) {
		if ( new_chan->itbl[i] == 0 && chan->itbl[i] != 0 ) {
			goto ErrOut;
		}
	}

	if ( (new_chan->otbl == 0 && chan->otbl != 0) ||
	     (new_chan->gtbl == 0 && chan->gtbl != 0) ) {
		goto ErrOut;
	}

	return (new_chan);
	

ErrOut:
	fut_free_chan (new_chan);
	return (FUT_NULL_CHAN);
}