Example #1
0
NodeQueue* ServeQueue(Queue* ApQ) {
	NodeQueue *aux = ApQ->head;
	
	if(EmptyQueue(ApQ) == FALSE) {
		ApQ->head = ApQ->head->next;
		
		if(EmptyQueue(ApQ) == TRUE)	
			ApQ->tail = NULL;
	}
	
	return aux;
}
void DbgGdb::DoCleanup()
{
#ifdef __WXMSW__
    if(GetIsRemoteDebugging()) {
        SetConsoleCtrlHandler((PHANDLER_ROUTINE)SigHandler, FALSE);
        FreeConsole(); // Disconnect any existing console window.
    }
#endif

    wxDELETE(m_gdbProcess);
    SetIsRecording(false);
    m_reverseDebugging = false;
    m_goingDown = false;
    m_attachedMode = false;

    SetIsRemoteDebugging(false);
    SetIsRemoteExtended(false);
    EmptyQueue();
    m_gdbOutputArr.Clear();
    m_bpList.clear();
    m_debuggeeProjectName.Clear();

    // Clear any bufferd output
    m_gdbOutputIncompleteLine.Clear();

    // Free allocated console for this session
    m_consoleFinder.FreeConsole();
}
Example #3
0
File: nMsg.c Project: zenbaku/nano
void *nReceive(nTask *ptask, int timeout)
{
  void *msg;
  nTask send_task;

  START_CRITICAL();
  pending_receives++;
  { nTask this_task= current_task;

    if (EmptyQueue(this_task->send_queue) && timeout!=0)
    {
      if (timeout>0)
      {
        this_task->status= WAIT_SEND_TIMEOUT;
        ProgramTask(timeout);
        /* La tarea se despertara automaticamente despues de timeout */
      }
      else this_task->status= WAIT_SEND; /* La tarea espera indefinidamente */

      ResumeNextReadyTask(); /* Se suspende indefinidamente hasta un nSend */
    }

    send_task= GetTask(this_task->send_queue);
    if (ptask!=NULL) *ptask= send_task;
    msg= send_task==NULL ? NULL : send_task->send.msg;
  }
  pending_receives--;
  END_CRITICAL();

  return msg;
}    
Example #4
0
int BFSTraverse(MGraph G,int(*Visit)(char v))
{
	LinkQueue Q;
	int v,w,u;
	for(v=0;v<G.vexnum;v++)
		visited[v]=0;
	InitQueue(Q);
	for(v=0;v<G.vexnum;v++)
	{
		if(!visited[v])
		{
			visited[v]=1;
			Visit(G.dingdian[v]);
			EnQueue(Q,v);
			while(!EmptyQueue(Q))
			{
				DeQueue(Q,u);
				w=FirstAdjVex(G,G.dingdian[u]);
				for(;w>=0;w=NextAdjVex(G,G.dingdian[u],G.dingdian[w]))
					if(!visited[w])
					{
						visited[w]=1;
						Visit(G.dingdian[w]);
						EnQueue(Q,w);
					}
			}
		}
	}
	return OK;
}
BOOL Piezo_Driver::Tone( UINT32 Frequency_Hertz, UINT32 Duration_Milliseconds )
{
    // Not sure why this is neccessary.  Calling the Piezo::Tone function from with-in an ISR
    // should be a valid scenario.  Lorenzo and I (Zach) can not determine
    // why this assert is needed; therefore, it is being commented out (for now).
    //ASSERT(!SystemState_Query( SYSTEM_STATE_ISR ));

    GLOBAL_LOCK(irq);

    // special to clear queue
    if(Frequency_Hertz == TONE_CLEAR_BUFFER)
    {
        // let active note to finish on it's own
        EmptyQueue();
    }
    else
    {
        // 0 length tone isn't wrong persay, but if a NULL op, so drop it gracefully, as a success
        if(Duration_Milliseconds > 0)
        {
            PIEZO_TONE* Tone = g_Piezo_Driver.m_ToneToRelease.ExtractFirstNode();

            if(Tone == NULL)
            {
                //
                // Re-enable interrupts when allocating memory.
                //
                irq.Release();

                Tone = (PIEZO_TONE*)private_malloc( sizeof(PIEZO_TONE) );

                Tone->Initialize();

                irq.Acquire();
            }

            if(Tone == NULL)
            {
                // No memory, just drop this tone and fail the call
                ASSERT(0);
                return FALSE;
            }

            Tone->Frequency_Hertz       = Frequency_Hertz;
            Tone->Duration_Milliseconds = Duration_Milliseconds;

            DEBUG_TRACE3(0, "Tone(%4d,%4d)=%d\r\n", Frequency_Hertz, Duration_Milliseconds, g_Piezo_Driver.m_ToneToPlay.NumOfNodes() );

            g_Piezo_Driver.m_ToneToPlay.LinkAtBack( Tone );

            if(g_Piezo_Driver.m_TonePlaying == NULL)
            {
                StartNext();
            }
        }
    }

    return TRUE;
}
Example #6
0
TTSQueue::~TTSQueue()
{
	CloseHandle(mutex);
	CloseHandle(empty);
	CloseHandle(full);

	EmptyQueue();
}
ScheduledTickQueue::~ScheduledTickQueue()
{
    if( 0 != m_Queue.size() )
    {
        ASSERT_DEBUG(false);
        EmptyQueue();
    }
}
BOOL PolyphonicPiezo_Driver::Tone( const PIEZO_POLY_TONE& ToneRef )
{
    ASSERT(!SystemState_Query(SYSTEM_STATE_ISR));

    GLOBAL_LOCK(irq);

    // special to clear queue
    if(ToneRef.Period[0] == TONE_CLEAR_BUFFER)
    {
        // let active note to finish on it's own
        EmptyQueue();
    }
    else
    {
        // 0 length tone isn't wrong persay, but if a NULL op, so drop it gracefully, as a success
        if(ToneRef.Duration_MicroSeconds > 0)
        {
            PIEZO_POLY_TONE* Tone = g_PolyphonicPiezo_Driver.m_ToneToRelease.ExtractFirstNode();

            if(Tone == NULL)
            {
                //
                // Re-enable interrupts when allocating memory.
                //
                irq.Release();

                Tone = (PIEZO_POLY_TONE*)private_malloc( sizeof(PIEZO_POLY_TONE) );

                irq.Acquire();
            }

            if(Tone == NULL)
            {
                // No memory, just drop this tone and fail the call
                ASSERT(0);
                return FALSE;
            }

            *Tone = ToneRef;

            Tone->Initialize();

            DEBUG_TRACE2( 0, "Tone(%4d)=%d\r\n", ToneRef.Duration_MicroSeconds, g_PolyphonicPiezo_Driver.m_ToneToPlay.NumOfNodes() );

            g_PolyphonicPiezo_Driver.m_ToneToPlay.LinkAtBack( Tone );

            if(g_PolyphonicPiezo_Driver.m_TonePlaying == NULL)
            {
                StartNext();
            }
        }
    }

    return TRUE;
}
Example #9
0
void AppendQueue(Queue* ApQ, NodeQueue* new_node) {
	
	if(EmptyQueue(ApQ) == TRUE) {
		ApQ->head = new_node;
		ApQ->tail = new_node;
	}
	else {
		ApQ->tail->next = new_node;
		ApQ->tail = new_node;
	}

	new_node->next = NULL;
}
Example #10
0
/**
 * The run method, this loops, executing actions, until we're told to
 * terminate.
 */
void *ConsumerThread::Run() {
  m_mutex->Lock();
  while (true) {
    EmptyQueue();
    // Mutex is held here
    if (*m_shutdown) {
      m_mutex->Unlock();
      break;
    }

    m_condition_var->Wait(m_mutex);
  }
  return NULL;
}
Example #11
0
NS_IMETHODIMP
nsPrefetchService::Observe(nsISupports     *aSubject,
                           const char      *aTopic,
                           const PRUnichar *aData)
{
    LOG(("nsPrefetchService::Observe [topic=%s]\n", aTopic));

    if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
        StopPrefetching();
        EmptyQueue();
        mDisabled = PR_TRUE;
    }
    else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
        nsCOMPtr<nsIPrefBranch> prefs(do_QueryInterface(aSubject));
        PRBool enabled;
        nsresult rv = prefs->GetBoolPref(PREFETCH_PREF, &enabled);
        if (NS_SUCCEEDED(rv) && enabled) {
            if (mDisabled) {
                LOG(("enabling prefetching\n"));
                mDisabled = PR_FALSE;
                AddProgressListener();
            }
        } 
        else {
            if (!mDisabled) {
                LOG(("disabling prefetching\n"));
                StopPrefetching();
                EmptyQueue();
                mDisabled = PR_TRUE;
                RemoveProgressListener();
            }
        }
    }

    return NS_OK;
}
Example #12
0
void
nsPrefetchService::StopPrefetching()
{
    mStopCount++;

    LOG(("StopPrefetching [stopcount=%d]\n", mStopCount));

    // only kill the prefetch queue if we've actually started prefetching.
    if (!mCurrentNode)
        return;

    mCurrentNode->CancelChannel(NS_BINDING_ABORTED);
    mCurrentNode = nsnull;
    EmptyQueue();
}
Example #13
0
bool DbgGdb::Stop()
{
	if (m_gdbProcess) {
		delete m_gdbProcess;
		m_gdbProcess = NULL;
	}

	//free allocated console for this session
	m_consoleFinder.FreeConsole();

	//return control to the program
	m_observer->UpdateGotControl(DBG_DBGR_KILLED);
	EmptyQueue();
	m_gdbOutputArr.Clear();
	m_bpList.clear();
	return true;
}
Example #14
0
void ICACHE_FLASH_ATTR user_uart_task(void *pvParameters)
{
	CusUartIntrPtr uartptrData;
	u32 sys_time_value = system_get_time();

	while (1)
	{
		
		if (EmptyQueue() == false && (system_get_time() - sys_time_value) >= 100) {

			ESP_DBG(("***heap_size %d\n", system_get_free_heap_size()));

			frame_t frame;

			if (Dequeue(&frame)) {
				uart0_tx_buffer((uint8_t *)&frame, frame.len);
			}
			sys_time_value = system_get_time();
		}
		
		if (xQueueReceive(xQueueCusUart, (void *)&uartptrData, (portTickType)20/*portMAX_DELAY*/)) // wait about 20msec 
		{
			ESP_DBG(("data uart recv.."));
			debug_print_hex_data(uartptrData.rx_buf, uartptrData.rx_len);

			if (uartptrData.rx_len>0x00) {
				cus_uart_data_handle(uartptrData.rx_buf, uartptrData.rx_len, NULL);
			}
		}
		/*
		if ((system_get_time() - sys_time_value) >= (60 * 1000 * 1000))  //about 1min, send data to uart0, demo beat data
		{
			ESP_DBG(("uart beat data***heap_size %d\n", system_get_free_heap_size()));
			
			//uart0_write_data(uart_beat_data, sizeof(uart_beat_data));//heatbeat sent to MCU
			
			sys_time_value = system_get_time();
		}
		*/
		
	}

	vTaskDelete(NULL);

}
Example #15
0
void QueueType<ItemType>::Dequeue(ItemType &i)
{
    if(IsEmpty())
    {
        throw EmptyQueue();
    }

    else
    {
        NodeType<ItemType> *temp;
        temp = front;
        i = front->info;
        front = front->next;

        if(front == NULL)
            rear == NULL;

        delete temp;
    }
}
Example #16
0
void QueType::Dequeue(ItemType& item)
// Removes front item from the queue and returns it in item.
// Pre:  Queue has been initialized and is not empty.
// Post: If (queue is not empty) the front of the queue has been 
//       removed and a copy returned in item; 
//       othersiwe a EmptyQueue exception has been thrown.
{
  if (IsEmpty())
    throw EmptyQueue();
  else
  {
    NodeType* tempPtr;

    tempPtr = front;
    item = front->info;
    front = front->next;
    if (front == NULL)
      rear = NULL;
    delete tempPtr;
  }
}
void PolyphonicPiezo_Driver::Uninitialize()
{
    {
        GLOBAL_LOCK(irq);

        EmptyQueue();

        //
        // This purges the currently playing tone.
        //
        StartNext();
    }

    bool fEnabled = INTERRUPTS_ENABLED_STATE();

    if(!fEnabled) ENABLE_INTERRUPTS();

    ToneRelease( NULL );

    if(!fEnabled) DISABLE_INTERRUPTS();
}
Example #18
0
void DbgGdb::DoCleanup()
{
    if ( m_gdbProcess ) {
        delete m_gdbProcess;
        m_gdbProcess = NULL;
    }

    m_goingDown = false;
    m_attachedMode = false;

    SetIsRemoteDebugging( false );
    SetIsRemoteExtended( false );
    EmptyQueue();
    m_gdbOutputArr.Clear();
    m_bpList.clear();
    m_debuggeeProjectName.Clear();

    // Clear any bufferd output
    m_gdbOutputIncompleteLine.Clear();

    // Free allocated console for this session
    m_consoleFinder.FreeConsole();
}
void Piezo_Driver::Uninitialize()
{
    g_Piezo_Driver.m_ToneDone   .Abort();
    g_Piezo_Driver.m_ToneRelease.Abort();


    {
        GLOBAL_LOCK(irq);

        EmptyQueue();

        //
        // This purges the currently playing tone.
        //
        StartNext();
    }


    bool fEnabled = INTERRUPTS_ENABLED_STATE();

    if(!fEnabled) ENABLE_INTERRUPTS();

    ToneRelease( NULL );

    if(!fEnabled) DISABLE_INTERRUPTS();

    // restore the hardware to proper default state
    for(int i = 0; i < 2; i++)
    {
        PWM_CONFIG* PWM_Config = &g_pPIEZO_Config->PWM_Config[i];

        if(PWM_Config->PWM_Output.Pin != GPIO_PIN_NONE)
        {
            CPU_GPIO_EnableInputPin( PWM_Config->PWM_Output.Pin, FALSE, NULL, GPIO_INT_NONE, RESISTOR_PULLDOWN );
        }
    }
}
Example #20
0
ppw(pword *pw)				/* print prolog words */
          
{

    int arity = 1;
    pword *queue_head = (pword *) 0;
    pword *queue_tail = (pword *) 0;

    for (;;)
    {
	char region;
	int t = TagType(pw->tag);

	if (t < TFORWARD || t > TBUFFER)
	    t = TUNKNOWN;

	if (TG_ORIG <= pw && pw < TG) region = 'g';
	else if (SP <= pw && pw < SP_ORIG) region = 'l';
	else if (B_ORIG <= pw && pw < B.args) region = 'c';
	else if (TT <= (pword **) pw && (pword **) pw < TT_ORIG) region = 't';
	else if (address_in_heap(&global_heap, (generic_ptr) pw)) region = 'h';
	else region = '?';

	p_fprintf(current_output_, "%c 0x%08x:  0x%08x 0x%08x  %s ", region,
			pw, pw->val.all, pw->tag.all, tag_string[t-TUNKNOWN]);
	switch (t)
	{
	case TFORWARD:
	case TMETA:
	case TNAME:
	    if (pw != pw->val.ptr)
	    {
		ec_outfs(current_output_, "--->");
		EnQueue_(pw->val.ptr, 1);
	    }
	    else
	    {
		ec_outfs(current_output_, IsNamed(pw->tag.kernel) ?
					DidName(TagDid(pw->tag.kernel)) : "_");
	    }
	    break;
	case TVAR_TAG:
	    if (pw != pw->val.ptr)
	    {
		ec_outfs(current_output_, "--->");
		EnQueue_(pw->val.ptr, 1);
	    }
	    else
		ec_outfs(current_output_, "_");
	    break;
	case TLIST:
	    EnQueue_(pw->val.ptr, 2);
	    break;
	case TCOMP:
	    if (pw->val.ptr)
		EnQueue_(pw->val.ptr, DidArity(pw->val.ptr->val.did)+1);
	    break;
	case TSTRG:
	    ec_outfs(current_output_, StringStart(pw->val));
	    break;
	case TSUSP:
	    break;
	case TDE:
	    break;
	case THANDLE:
	    break;
	case TNIL:
	    break;
	case TINT:
	    p_fprintf(current_output_, "%d", pw->val.nint);
	    break;
	case TDICT:
	    ec_outfs(current_output_, DidName(pw->val.did));
	    if (DidArity(pw->val.did))
		p_fprintf(current_output_, "/%d", DidArity(pw->val.did));
	    break;
	case TPTR:
	    break;
	case TPROC:
	case TEND:
	case TVARNUM:
	case TGRS:
	case TGRL:
	case TEXTERN:
	case TBUFFER:
	    break;
	case TDBL:
	    p_fprintf(current_output_, "%f", Dbl(pw->val));
	    break;
	case TBIG:
	case TRAT:
	default:
	    if (t >= 0 && t <= NTYPES)
	    {
		(void) tag_desc[t].write(QUOTED, current_output_,
			    pw->val, pw->tag);
	    }
	    break;
	}
	ec_newline(current_output_);
	if (--arity > 0)
	{
	    pw++;
	    continue;
	}
	ec_newline(current_output_);
	if (EmptyQueue())
	    break;
	DeQueue_(pw, arity);
    }
    Succeed_;
}
Example #21
0
void ClearQueue(Queue* ApQ) {
	
	while(EmptyQueue(ApQ) == FALSE) {
		free(ServeQueue(ApQ));
	}
}
avtDatasetOnDemandFilter::~avtDatasetOnDemandFilter()
{
   EmptyQueue();
}
Example #23
0
nsPrefetchService::~nsPrefetchService()
{
    // cannot reach destructor if prefetch in progress (listener owns reference
    // to this service)
    EmptyQueue();
}
pword *
term_to_dbformat(pword *parg, dident mod)
{
    pword **save_tt = TT;
    register word arity = 1, len;
    register word curr_offset = 0, top_offset = 2;	/* in 'word's */
    register pword *queue_tail = (pword *) 0;
    pword *queue_head = (pword *) 0;
    register pword *pw;
    register char *dest, *stop;
    pword *header;
    temp_area	meta_attr;
    int		flag = 0;

    Temp_Create(meta_attr, 4 * ATTR_IO_TERM_SIZE * sizeof(pword));
    header = TG;
    dest = (char *) (header + 1) + 4;	/* space for the TBUFFER pword and for
					 * the external format header	*/

    for(;;)	/* handle <arity> consecutive pwords, starting at <parg> */
    {
	do	/* handle the pword pointed to by parg */
	{
	    pw = parg;

	    /* I need here a slightly modified version of Dereference_(pw)
	     * that stops also at MARKed words. Not very nice, I know.
	     */
	    while (IsRef(pw->tag) && !(pw->tag.kernel & MARK) && !IsSelfRef(pw))
		pw = pw->val.ptr;

	    Reserve_Space(6);

	    if (pw->tag.kernel & MARK)
	    {
		if (SameTypeC(pw->tag,TDE))		/* a suspension */
		{
		    Store_Byte(Tag(pw->tag.kernel));
		    Store_Int32((pw[SUSP_FLAGS].tag.kernel & ~MARK));
		    if (SuspDead(pw)) {
			curr_offset += Words(SUSP_HEADER_SIZE-1);
			parg += SUSP_HEADER_SIZE-1;
			arity -= SUSP_HEADER_SIZE-1;
		    } else {
			Store_Byte(SuspPrio(pw) + (SuspRunPrio(pw) << 4));
			curr_offset += Words(SUSP_GOAL-1);
			parg += SUSP_GOAL-1;
			arity -= SUSP_GOAL-1;
		    }
		}
		else if (pw->val.nint == curr_offset)	/* a nonstd variable */
		{
		    Store_Byte(Tag(pw->tag.kernel));
		    Store_Int(pw->val.nint);
		    if (!IsNamed(pw->tag.kernel))
		    {
			Store_Byte(0);
		    }
		    else		/* store its name */
		    {
			dident vdid = TagDid(pw->tag.kernel);
			len = DidLength(vdid);
			Store_Int(len);
			Reserve_Space(len);
			Store_String(len, DidName(vdid));
		    }
		}
		else	/* just a reference to an already encountered variable */
		{
		    Store_Byte(Tag(TVAR_TAG));
		    Store_Int(pw->val.nint);
		}
	    }
	    else switch (TagType(pw->tag))
	    {
	    case TINT:
#if SIZEOF_CHAR_P > 4
		if (pw->val.nint <  WSUF(-2147483648) || WSUF(2147483648) <= pw->val.nint)
		{
		    /* store as a bignum (to be readable on 32bit machines) */
		    len = tag_desc[pw->tag.kernel].string_size(pw->val, pw->tag, 1);
		    Store_Byte(TBIG);
		    Store_Int(len);
		    Reserve_Space(len+1);
		    stop = dest+len;
		    dest += tag_desc[pw->tag.kernel].to_string(pw->val, pw->tag,
			dest, 1);
		    while (dest <= stop)	/* pad and terminate */
		    	*dest++ = 0;
		    break;
		}
#endif
		Store_Byte(TINT);
#ifdef OLD_FORMAT
		Store_Int32(pw->val.nint);
#else
		Store_Int(pw->val.nint);
#endif
		break;

	    case TNIL:
		Store_Byte(Tag(pw->tag.kernel));
		break;

	    case TDICT:
		len = DidLength(pw->val.did);
		Store_Byte(TDICT);
		Store_Int(DidArity(pw->val.did));
		Store_Int(len);
		Reserve_Space(len);
		Store_String(len, DidName(pw->val.did));
		break;

	    case TDBL:
	    {
		ieee_double d;
		d.as_dbl = Dbl(pw->val);
		Store_Byte(TDBL);
		Store_Byte(sizeof(double)-1);	/* backward compat */
		Reserve_Space(sizeof(double));
		Store_Int32(d.as_struct.mant1);
		Store_Int32(d.as_struct.mant0);
		break;
	    }

	    case TIVL:
	    {
		ieee_double dlwb, dupb;
		dlwb.as_dbl = IvlLwb(pw->val.ptr);
		dupb.as_dbl = IvlUpb(pw->val.ptr);
		Store_Byte(TIVL);
		Reserve_Space(2*sizeof(double));
		Store_Int32(dlwb.as_struct.mant1);
		Store_Int32(dlwb.as_struct.mant0);
		Store_Int32(dupb.as_struct.mant1);
		Store_Int32(dupb.as_struct.mant0);
		break;
	    }

	    case TSTRG:
		len = StringLength(pw->val);
		Store_Byte(TSTRG);
		Store_Int(len);
		Reserve_Space(len);
		Store_String(len, StringStart(pw->val));
		break;

	    case TVAR_TAG:	/* standard variable */
		Store_Byte(Tag(TVAR_TAG));
		Store_Int(curr_offset);
		Trail_(pw);
		pw->val.nint = curr_offset;
		pw->tag.kernel |= MARK;
		break;

	    case TNAME:
	    case TUNIV:
		Store_Byte(Tag(TVAR_TAG));
		Store_Int(top_offset);
		Trail_Tag(pw);
		pw->val.nint = top_offset;
		pw->tag.kernel |= MARK;
		top_offset += 2;
		EnQueue_(pw, 1, 0);
		break;

	    case TMETA:
		Store_Byte(Tag(TVAR_TAG));
		Store_Int(top_offset);
		Trail_Tag(pw);
		pw->val.nint = top_offset;
		pw->tag.kernel |= MARK;
		top_offset += 4;
		EnQueue_(pw, 2, QUEUE_MASK_META);
		break;

	    case TSUSP:
		Store_Byte(Tag(TSUSP));
		pw = pw->val.ptr;
		if (pw->tag.kernel & MARK)	/* not the first encounter */
		{
		    Store_Int(pw->val.nint);
		}
		else
		{
		    Store_Int(top_offset);
		    Trail_Pword(pw);
		    pw->tag.kernel |= MARK;
		    pw->val.nint = top_offset;
		    if (SuspDead(pw))
		    {
			top_offset += Words(SUSP_HEADER_SIZE);	/* for TDE */
			EnQueue_(pw, SUSP_HEADER_SIZE, 0);
		    }
		    else
		    {
			top_offset += Words(SUSP_SIZE);	/* for TDE */
			EnQueue_(pw, SUSP_SIZE, 0);
		    }
		}
		break;

	    case TLIST:
		Store_Byte(Tag(TLIST));
		Store_Int(top_offset);
		top_offset += 4;
		EnQueue_(pw->val.ptr, 2, 0);
		break;

	    case TCOMP:
		Store_Byte(Tag(TCOMP));
		Store_Int(top_offset);
		if (flag) {
		    pword pw_out;
		    (void) transf_meta_out(pw->val, pw->tag,
			    (pword *) TempAlloc(meta_attr, ATTR_IO_TERM_SIZE * sizeof(pword)),
			    D_UNKNOWN, &pw_out);
		    pw = pw_out.val.ptr;
		    len = 1 + DidArity(pw->val.did);
		    EnQueue_(pw, len, 0);
		} else {
		    len = 1 + DidArity(pw->val.ptr->val.did);
		    EnQueue_(pw->val.ptr, len, 0);
		}
		top_offset += 2*len;
		break;

	    default:
		if (TagType(pw->tag) >= 0 && TagType(pw->tag) <= NTYPES)
		{
		    len = tag_desc[TagType(pw->tag)].string_size(pw->val, pw->tag, 1);
		    Store_Byte(Tag(pw->tag.kernel));
		    Store_Int(len);
		    Reserve_Space(len+1);
		    stop = dest+len;
		    dest += tag_desc[TagType(pw->tag)].to_string(pw->val, pw->tag,
			dest, 1);
		    while (dest <= stop)	/* pad and terminate */
		    	*dest++ = 0;
		}
		else
		{
		    p_fprintf(current_err_,
			"bad type in term_to_dbformat: 0x%x\n",
			pw->tag.kernel);
		}
		break;
	    }
	    curr_offset += Words(1);
	    ++parg;
	} while (--arity);
	if (EmptyQueue())
	    break;
	DeQueue_(parg, arity, flag);
    }
					/* # bytes of external representation */
    Store_Byte(0);			/* add a terminating 0		*/
    Set_Buffer_Size(header, dest - (char*) header - sizeof(pword));
    header->tag.kernel = TBUFFER;
    Align();				/* align the global stack pointer */
    TG = (pword *) dest;
    dest = (char *) (header + 1);	/* fill in the external format header */
    Store_Int32(top_offset);		/* (size of term after restoring) */
    Untrail_Variables(save_tt);
    Temp_Destroy(meta_attr);
    return header;
}