コード例 #1
0
ファイル: eval.c プロジェクト: zbenjamin/vmscheme
// eval_sequence may return an object with a refcount of zero.
// This is because it's the interface to the interpreter and so the
// return value may be the result of a computation that only has
// one reference inside the created vm context.  On the other hand
// it may return an object with multiple references (if the object
// returned is referenced in the passed environment, for example).
struct object *
eval_sequence(struct pair *forms, struct environment *env)
{
  struct code *prog = compile(forms);
  INC_REF(&prog->obj);
  struct codeptr *pc = make_codeptr(prog, 0);
  INC_REF(&pc->obj);
  struct stack *stk = make_stack(1024);
  // push magic "end of instructions" return address
  stack_push(stk, NULL);
  stack_push(stk, &env->obj);
  INC_REF(&env->obj);
  struct vm_context *ctx = make_vm_context(pc, stk, env);
  INC_REF(&ctx->obj);
  struct vm_context **pctx = &ctx;

  eval_instructions(pctx);
  struct object *value = stack_pop((*pctx)->stk);

  // decrement the refcount if it's positive, but don't deallocate
  // the object
  if (value->refcount > 0) {
    --(value->refcount);
  }

  DEC_REF(&prog->obj);
  assert(stack_empty((*pctx)->stk));
  DEC_REF(&ctx->obj);
  return value;
}
コード例 #2
0
ファイル: continuation.c プロジェクト: zbenjamin/vmscheme
void
dealloc_continuation(struct vm_context *cont)
{
  if (cont->pc) {
    DEC_REF(&cont->pc->obj);
  }
  dealloc_stack(cont->stk);
  DEC_REF(&cont->env->obj);
  free(cont);
}
コード例 #3
0
static void broker_decrement_ref(BROKER_HANDLE broker)
{
    /*Codes_SRS_BROKER_13_058: [If `broker` is NULL the function shall do nothing.]*/
    if (broker != NULL)
    {
        /*Codes_SRS_BROKER_13_111: [Otherwise, Broker_Destroy shall decrement the internal ref count of the message.]*/
        /*Codes_SRS_BROKER_13_112: [If the ref count is zero then the allocated resources are freed.]*/
        if (DEC_REF(BROKER_HANDLE_DATA, broker) == DEC_RETURN_ZERO)
        {
            BROKER_HANDLE_DATA* broker_data = (BROKER_HANDLE_DATA*)broker; 
            if (singlylinkedlist_get_head_item(broker_data->modules) != NULL)
            {
                LogError("WARNING: There are still active modules attached to the broker and the broker is being destroyed.");
            }
            /* May want to do nn_shutdown first for cleanliness. */
            nn_close(broker_data->publish_socket);
            STRING_delete(broker_data->url);
            singlylinkedlist_destroy(broker_data->modules);
            Lock_Deinit(broker_data->modules_lock);
            free(broker_data);
        }
    }
    else
    {
        LogError("broker handle is NULL");
    }
}
コード例 #4
0
ファイル: Thread.cpp プロジェクト: AndroDevcd/Sharp
void Thread::exit() {

    if(this->exceptionThrown) {
        this->exitVal = -800;
        cout << throwable.stackTrace.str();
        cout << endl << throwable.throwable->name.str() << " "
             << throwable.message.str() << "\n";
    } else {
        if(!daemon && dataStack)
            this->exitVal = (int)dataStack[0].var;
        else
            this->exitVal = 0;
    }

    if(dataStack != NULL) {
        StackElement *p = dataStack;
        for(size_t i = 0; i < stack_lmt; i++)
        {
            if(p->object.object) {
                DEC_REF(p->object.object);
                p->object.object=NULL;
            }
            p++;
        }
    }

    free(this->callStack); callStack = NULL;
    this->state = THREAD_KILLED;
    this->exited = true;
}
コード例 #5
0
ファイル: widget_general.c プロジェクト: 12019/mtktest
/*****************************************************************************
 * FUNCTION
 *  HDIa_widgetRelease
 * DESCRIPTION
 *  
 * PARAMETERS
 *  handle      [IN]        
 * RETURNS
 *  
 *****************************************************************************/
int HDIa_widgetRelease(MSF_UINT32 handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    widget_header_struct *node;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!handle)
    {
        return 0;
    }
    if (IS_FLAG_STATIC(handle))
    {
        return 0;
    }

    if (IS_ACCESSKEY_TYPE(handle))
    {
        WAP_DBG_ASSERT(0);
        return 0;
    }

    /*
     * Prevent HDIa_widgetRelease the same widgets for more than one time
     * (Teleca code might HDIa_widgetRelease the same widget twice.)
     *
     * Note: this only reduce the chance of memory corruption, but not eliminate it.
     * It is possible to allocate another widget at the same memory address, which is HDIa_widgetRelease()-ed
     * for the previous widget.
     *
     */
    if (_H(handle)->data_type == WIDGET_MAX_TYPE)
    {
        WAP_DBG_ASSERT(0);
        return 1;
    }

    /* a screen and window only have one parent */
    if (IS_SCREEN_TYPE(handle) || IS_WINDOW_TYPE(handle))
    {
        NO_REF(handle);
    }
    DEC_REF(handle);
    if (HAS_REF(handle))
    {
        return 1;
    }

    widget_pause_paint();

    // TODO: should we do this in widget_free?
    foreach_childs(handle, node,
                   {
                   if (!IS_FLAG_STATIC(node)) widget_remove_childs(_H(handle), node);}
    );
BLEIO_SEQ_RESULT schedule_write(
    BLEIO_SEQ_HANDLE_DATA* handle_data,
    BLEIO_SEQ_INSTRUCTION* instruction,
    ON_INTERNAL_IO_COMPLETE on_internal_read_complete
)
{
    BLEIO_SEQ_RESULT result;
    WRITE_CONTEXT* context = (WRITE_CONTEXT*)malloc(sizeof(WRITE_CONTEXT));

    /*Codes_SRS_BLEIO_SEQ_13_014: [ BLEIO_Seq_Run shall return BLEIO_SEQ_ERROR if an underlying platform call fails. ]*/
    if (context == NULL)
    {
        LogError("malloc failed");
        result = BLEIO_SEQ_ERROR;
    }
    else
    {
        context->handle_data = handle_data;
        context->instruction = instruction;
        context->on_internal_read_complete = on_internal_read_complete;

        const unsigned char* buffer = BUFFER_u_char(instruction->data.buffer);
        size_t buffer_size = BUFFER_length(instruction->data.buffer);

        // add ref to the handle data object since we now will have an
        // outstanding I/O operation; the reason why we increment the
        // reference here as opposed to when we know that BLEIO_gatt_read_char_by_uuid
        // was successful is because the operation could potentially complete
        // even before we hit the if check after this call and 'on_read_complete'
        // might have run by then in which case it would have done a DEC_REF and
        // the ref counts will be out of whack
        INC_REF(BLEIO_SEQ_HANDLE_DATA, handle_data);

        int write_result = BLEIO_gatt_write_char_by_uuid(
            handle_data->bleio_gatt_handle,
            STRING_c_str(instruction->characteristic_uuid),
            buffer,
            buffer_size,
            on_write_complete,
            context
        );
        if (write_result != 0)
        {
            /*Codes_SRS_BLEIO_SEQ_13_014: [ BLEIO_Seq_Run shall return BLEIO_SEQ_ERROR if an underlying platform call fails. ]*/
            result = BLEIO_SEQ_ERROR;
            free(context);
            DEC_REF(BLEIO_SEQ_HANDLE_DATA, handle_data);
            LogError("BLEIO_gatt_write_char_by_uuid failed with %d.", write_result);
        }
        else
        {
            result = BLEIO_SEQ_OK;
        }
    }

    return result;
}
コード例 #7
0
void Pos_Destroy(POS_HANDLE posHandle)
{
    if (posHandle != NULL)
    {
        pos* p = posHandle;
        if (DEC_REF(pos, p) == DEC_RETURN_ZERO)
        {
            free(p);
        }
    }
}
コード例 #8
0
ファイル: instruction.c プロジェクト: zbenjamin/vmscheme
void
dealloc_bytecode(struct instruction *stream)
{
  struct instruction *pc = stream;
  while (pc->op != END) {
    if (pc->arg) {
      DEC_REF(pc->arg);
    }
    ++pc;
  };

  free(stream);
}
コード例 #9
0
void CONSTBUFFER_Destroy(CONSTBUFFER_HANDLE constbufferHandle)
{
    /*Codes_SRS_CONSTBUFFER_02_015: [If constbufferHandle is NULL then CONSTBUFFER_Destroy shall do nothing.]*/
    if (constbufferHandle != NULL)
    {
        /*Codes_SRS_CONSTBUFFER_02_016: [Otherwise, CONSTBUFFER_Destroy shall decrement the refcount on the constbufferHandle handle.]*/
        if (DEC_REF(CONSTBUFFER_HANDLE_DATA, constbufferHandle) == DEC_RETURN_ZERO)
        {
            /*Codes_SRS_CONSTBUFFER_02_017: [If the refcount reaches zero, then CONSTBUFFER_Destroy shall deallocate all resources used by the CONSTBUFFER_HANDLE.]*/
            CONSTBUFFER_HANDLE_DATA* constbufferHandleData = constbufferHandle;
            free((void*)constbufferHandleData->alias.buffer);
            free(constbufferHandleData);
        }
    }
}
コード例 #10
0
ファイル: constmap.c プロジェクト: ZiTAL/arduino
void ConstMap_Destroy(CONSTMAP_HANDLE handle)
{
	/*Codes_SRS_CONSTMAP_17_005: [If parameter handle is NULL then ConstMap_Destroy shall take no action.]*/
	if (handle == NULL)
	{
		LOG_CONSTMAP_ERROR(CONSTMAP_INVALIDARG);
	}
	else
    {
		/*Codes_SRS_CONSTMAP_17_049: [ConstMap_Destroy shall decrement the internal reference count of the immutable map.]*/
		if (DEC_REF(CONSTMAP_HANDLE_DATA, handle) == DEC_RETURN_ZERO)
		{
			/*Codes_SRS_CONSTMAP_17_004: [If the reference count is zero, ConstMap_Destroy shall release all resources associated with the immutable map.]*/
			Map_Destroy(((CONSTMAP_HANDLE_DATA *)handle)->map);
			free(handle);
		}

    }
}
コード例 #11
0
ファイル: message.c プロジェクト: Eclo/azure-iot-gateway-sdk
void Message_Destroy(MESSAGE_HANDLE message)
{
    /*Codes_SRS_MESSAGE_02_017: [If message is NULL then Message_Destroy shall do nothing.] */
    if (message == NULL)
    {
        LogError("invalid arg: message is NULL");
    }
    else
    {
        MESSAGE_HANDLE_DATA* messageData = (MESSAGE_HANDLE_DATA*)message;
		/*Codes_SRS_MESSAGE_17_002: [Message_Destroy shall destroy the CONSTMAP properties.]*/
		ConstMap_Destroy(messageData->properties);
		/*Codes_SRS_MESSAGE_17_005: [Message_Destroy shall destroy the CONSTBUFFER.]*/
		CONSTBUFFER_Destroy(messageData->content);
        /*Codes_SRS_MESSAGE_02_020: [Otherwise, Message_Destroy shall decrement the internal ref count of the message.]*/
        if (DEC_REF(MESSAGE_HANDLE_DATA, message) == DEC_RETURN_ZERO)
        {
            /*Codes_SRS_MESSAGE_02_021: [If the ref count is zero then the allocated resources are freed.]*/
            free(message);
        }
    }
}
コード例 #12
0
void constbuffer_array_dec_ref(CONSTBUFFER_ARRAY_HANDLE constbuffer_array_handle)
{
    if (constbuffer_array_handle == NULL)
    {
        /*Codes_SRS_CONSTBUFFER_ARRAY_02_039: [ If constbuffer_array_handle is NULL then constbuffer_array_dec_ref shall return. ]*/
        LogError("invalid argument CONSTBUFFER_ARRAY_HANDLE constbuffer_array_handle=%p", constbuffer_array_handle);
    }
    else
    {
        /* Codes_SRS_CONSTBUFFER_ARRAY_01_016: [ Otherwise `constbuffer_array_dec_ref` shall decrement the reference count for `constbuffer_array_handle`. ]*/
        if (DEC_REF(CONSTBUFFER_ARRAY_HANDLE_DATA, constbuffer_array_handle) == DEC_RETURN_ZERO)
        {
            uint32_t i;

            /*Codes_SRS_CONSTBUFFER_ARRAY_02_038: [ If the reference count reaches 0, `constbuffer_array_dec_ref` shall free all used resources. ]*/
            for (i = 0; i < constbuffer_array_handle->nBuffers; i++)
            {
                CONSTBUFFER_Destroy(constbuffer_array_handle->buffers[i]);
            }

            REFCOUNT_TYPE_DESTROY(CONSTBUFFER_ARRAY_HANDLE_DATA, constbuffer_array_handle);
        }
    }
}
コード例 #13
0
ファイル: eval.c プロジェクト: zbenjamin/vmscheme
int
eval_instruction(struct vm_context **ctx)
{
  struct symbol *sym;
  struct object *value;
  struct compound_proc *template;

  switch (INS_AT((*ctx)->pc)->op) {
  case NONE:
    printf("Error: tried to execute a NONE op\n");
    exit(1);
    break;
  case PUSH:
    /* printf("PUSH instruction\n"); */
    stack_push((*ctx)->stk, INS_AT((*ctx)->pc)->arg);
    INC_REF(INS_AT((*ctx)->pc)->arg);
    ++(*ctx)->pc->offset;
    break;
  case POP:
    /* printf("POP instruction\n"); */
    value = stack_pop((*ctx)->stk);
    DEC_REF(value);
    ++(*ctx)->pc->offset;
    break;
  case LOOKUP:
    /* printf("LOOKUP instruction\n"); */
    assert(INS_AT((*ctx)->pc)->arg->type->code == SYMBOL_TYPE);
    sym = container_of(INS_AT((*ctx)->pc)->arg, struct symbol, obj);
    value = env_lookup((*ctx)->env, sym->value);
    if (! value) {
      char buf[1024];
      debug_loc_str(INS_AT((*ctx)->pc)->arg, buf, 1024);
      printf("%s: unbound name: %s\n", buf, sym->value);
      exit(1);
    }
    stack_push((*ctx)->stk, value);
    INC_REF(value);
    ++(*ctx)->pc->offset;
    break;
  case CALL:
  case TAILCALL:
    /* printf("CALL instruction @ %p\n", *pc); */
    eval_call(ctx);
    break;
  case RET:
    value = stack_pop((*ctx)->stk);
    struct object *orig_env = stack_pop((*ctx)->stk);
    assert(orig_env->type->code == ENVIRONMENT_TYPE);
    DEC_REF(orig_env);
    struct object *retaddr = stack_pop((*ctx)->stk);
    /* printf("RET instruction @ %p to %p\n", *pc, retaddr->cval); */
    stack_push((*ctx)->stk, value);
    DEC_REF(&(*ctx)->env->obj);
    (*ctx)->env = container_of(orig_env, struct environment, obj);
    if (retaddr == NULL) {
      (*ctx)->pc = NULL;
      return 1;
    }
    assert(retaddr->type->code == CODEPTR_TYPE);
    *(*ctx)->pc = *container_of(retaddr, struct codeptr, obj);
    /* XXX: */
    /* DEC_REF(retaddr); */
    break;
  case DEFINE:
    /* printf("DEFINE instruction\n"); */
    value = stack_pop((*ctx)->stk);
    assert(INS_AT((*ctx)->pc)->arg->type->code == SYMBOL_TYPE);
    sym = container_of(INS_AT((*ctx)->pc)->arg, struct symbol, obj);
    env_define((*ctx)->env, sym->value, value);
    DEC_REF(value);
    ++(*ctx)->pc->offset;
    break;
  case SET:
    value = stack_pop((*ctx)->stk);
    assert(INS_AT((*ctx)->pc)->arg->type->code == SYMBOL_TYPE);
    sym = container_of(INS_AT((*ctx)->pc)->arg, struct symbol, obj);
    env_set((*ctx)->env, sym->value, value);
    DEC_REF(value);
    ++(*ctx)->pc->offset;
    break;
  case LAMBDA:
    /* printf("LAMBDA instruction\n"); */
    value = INS_AT((*ctx)->pc)->arg;
    assert(INS_AT((*ctx)->pc)->arg->type->code == PROCEDURE_TYPE);
コード例 #14
0
ファイル: bv_decl_plugin.cpp プロジェクト: NikolajBjorner/z3
void bv_decl_plugin::finalize() {
#define DEC_REF(FIELD) dec_range_ref(FIELD.begin(), FIELD.end(), *m_manager)
    if (m_bit0) { m_manager->dec_ref(m_bit0); }
    if (m_bit1) { m_manager->dec_ref(m_bit1); }
    if (m_carry) { m_manager->dec_ref(m_carry); }
    if (m_xor3) { m_manager->dec_ref(m_xor3); }
    if (m_int_sort) { m_manager->dec_ref(m_int_sort); }

    DEC_REF(m_bv_sorts);

    DEC_REF(m_bv_neg);
    DEC_REF(m_bv_add);
    DEC_REF(m_bv_sub);
    DEC_REF(m_bv_mul);

    DEC_REF(m_bv_sdiv);
    DEC_REF(m_bv_udiv);
    DEC_REF(m_bv_srem);
    DEC_REF(m_bv_urem);
    DEC_REF(m_bv_smod);

    DEC_REF(m_bv_sdiv0);
    DEC_REF(m_bv_udiv0);
    DEC_REF(m_bv_srem0);
    DEC_REF(m_bv_urem0);
    DEC_REF(m_bv_smod0);

    DEC_REF(m_bv_sdiv_i);
    DEC_REF(m_bv_udiv_i);
    DEC_REF(m_bv_srem_i);
    DEC_REF(m_bv_urem_i);
    DEC_REF(m_bv_smod_i);

    DEC_REF(m_bv_uleq);
    DEC_REF(m_bv_sleq);
    DEC_REF(m_bv_ugeq);
    DEC_REF(m_bv_sgeq);
    DEC_REF(m_bv_ult);
    DEC_REF(m_bv_slt);
    DEC_REF(m_bv_ugt);
    DEC_REF(m_bv_sgt);

    DEC_REF(m_bv_and);
    DEC_REF(m_bv_or);
    DEC_REF(m_bv_not);
    DEC_REF(m_bv_xor);
    DEC_REF(m_bv_nand);
    DEC_REF(m_bv_nor);
    DEC_REF(m_bv_xnor);

    DEC_REF(m_bv_redor);
    DEC_REF(m_bv_redand);
    DEC_REF(m_bv_comp);

    DEC_REF(m_bv_mul_ovfl);
    DEC_REF(m_bv_smul_ovfl);
    DEC_REF(m_bv_smul_udfl);

    DEC_REF(m_bv_shl);
    DEC_REF(m_bv_lshr);
    DEC_REF(m_bv_ashr);

    DEC_REF(m_ext_rotate_left);
    DEC_REF(m_ext_rotate_right);

    DEC_REF(m_int2bv);
    DEC_REF(m_bv2int);
    vector<ptr_vector<func_decl> >::iterator it  = m_bit2bool.begin();
    vector<ptr_vector<func_decl> >::iterator end = m_bit2bool.end();
    for (; it != end; ++it) {
        ptr_vector<func_decl> & ds = *it;
        DEC_REF(ds);
    }
    DEC_REF(m_mkbv);
}
コード例 #15
0
ファイル: widget_editor.c プロジェクト: 12019/mtktest
/*****************************************************************************
 * FUNCTION
 *  HDIa_widgetEditorCreate
 * DESCRIPTION
 *  
 * PARAMETERS
 *  modId               [IN]        
 *  initialString       [IN]        
 *  inputString         [IN]        
 *  type                [IN]        
 *  maxSize             [IN]        
 *  singleLine          [IN]        
 *  size                [?]         
 *  propertyMask        [IN]        
 *  defaultStyle        [IN]        
 * RETURNS
 *  
 *****************************************************************************/
MsfWindowHandle HDIa_widgetEditorCreate(
                    MSF_UINT8 modId,
                    MsfStringHandle initialString,
                    MsfStringHandle inputString,
                    MsfTextType type,
                    int maxSize,
                    int singleLine,
                    MsfSize *size,
                    int propertyMask,
                    MsfStyleHandle defaultStyle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    widget_editor_struct *w = widget_create_editor(modId);
    MsfStringHandle str;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    w->module_id = modId;

    /* widget_set_attrib(w,prompt,initialString); */

    if (inputString)
    {
        str = widget_copy_string(modId, inputString);
    }
    else
    {
        str = HDIa_widgetStringCreate(modId, "", MsfUtf8, 1, 0);
    }

    widget_set_attrib(w, text, str);
    DEC_REF(w->text);   /* need it to automatic free */

    if (maxSize <= 0)
    {
        maxSize = WIDGET_MAX_INPUT_LEN;
    }

    widget_resize_string(_STR(w->text), maxSize);
    /* DEC_REF(w->text); // TODO: ref count of w->text is 0! Wrong? */

    WAP_DBG_ASSERT(_STR(w->text)->parent_cnt == 1);
    WAP_DBG_ASSERT(_STR(w->text)->raw->parent_cnt == 1);

    w->text_type = type;
    w->input_max_size = maxSize;
    w->is_single_line = singleLine ? KAL_TRUE : KAL_FALSE;

    if (size)
    {
        w->size = *size;
    }
    else
    {
        w->size = WGUI_CTX->default_display_size;
    }

    w->property_mask = propertyMask;
    w->index = -1;  /* default no index */

    widget_set_attrib(w, style, defaultStyle);
    return (MsfWindowHandle) w;
}