コード例 #1
0
ファイル: awk-signal.c プロジェクト: takubo/awk-posix-signal
static void
handler(int signo)
{
	SigTable *sig_tbl;
	AWKNUM ret;
	static INSTRUCTION *code;
	extern int exiting;

	sig_tbl = sig2ptr(signo);

	/* make function call instructions */
	code = bcalloc(Op_func_call, 2, 0);
	code->func_name = NULL;		/* not needed, func_body will assign */
	code->nexti = bcalloc(Op_stop, 1, 0);

	code->func_body = sig_tbl->user_handler;
	(code + 1)->expr_count = 1;	/* function takes one argument */

	PUSH(make_number((AWKNUM) signo));

	interpret(code);
	if (exiting)	/* do not assume anything about the user-defined function! */
		gawk_exit(exit_val);

	POP_NUMBER(ret);

	bcfree(code->nexti);            /* Op_stop */
	bcfree(code);                   /* Op_func_call */

	return;
}
コード例 #2
0
ファイル: bcalloc.c プロジェクト: sauliusg/starta
ssize_t bccollect( cexception_t *ex )
{
    alloccell_t *curr, *prev, *next;
    ssize_t reclaimed = 0;

    prev = NULL;
    curr = allocated;
    while( curr != NULL ) {
        next = curr->next;
	/* printf( "%p %ld\n", curr, curr->rcount ); */
	if( thrcode_heapdebug_is_on()) {
	    if( (curr->flags & AF_USED) == 0 ) {
		printf( "collecting " );
	    } else {
		printf( "leaving    " );
	    }
	    printf( "%p (%p) (size = %ld bytes)\n",
		    curr, curr+1, (long)curr->size );
	}
        if( (curr->flags & AF_USED) == 0 ) {
	    if( curr != allocated ) {
	        prev->next = next;
		if( prev->next )
		    prev->next->prev = prev;
	    } else {
	        prev = allocated = next;
	    }
	    reclaimed += curr->size;
            thrcode_run_destructor_if_needed( &istate, curr, ex );
	    bcfree( curr );
	} else {
	    curr->prev = prev;
	    prev = curr;
	}
        curr = next;
    }
    total_allocated_bytes -= reclaimed;
    if( total_allocated_bytes < 0 ) {
	assert( total_allocated_bytes >= 0 );
	total_allocated_bytes = 0;
    }
    return reclaimed;
}