当前位置: 首页>>代码示例>>C++>>正文


C++ PyTypeObject::tp_alloc方法代码示例

本文整理汇总了C++中PyTypeObject::tp_alloc方法的典型用法代码示例。如果您正苦于以下问题:C++ PyTypeObject::tp_alloc方法的具体用法?C++ PyTypeObject::tp_alloc怎么用?C++ PyTypeObject::tp_alloc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyTypeObject的用法示例。


在下文中一共展示了PyTypeObject::tp_alloc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: return

static PyObject *py_bug_camera_grab(PyObject *self, PyObject *args,PyObject *kwds) {
    pyimgObject *pyimg = (pyimgObject *) pyimgType.tp_alloc(&pyimgType, 0);
    Py_BEGIN_ALLOW_THREADS
    bug_camera_grab(&(pyimg->img));
    Py_END_ALLOW_THREADS
    return (PyObject *) pyimg;
}
开发者ID:buglabs,项目名称:FactoryTests,代码行数:7,代码来源:py_bugv4l.c

示例2: PyErr_NoMemory

static PyObject *db_new(PyObject *self, PyObject *args)
{
	nmdbobject *db;

#ifdef PYTHON3
	db = (nmdbobject *) nmdbType.tp_alloc(&nmdbType, 0);
#elif PYTHON2
	db = PyObject_New(nmdbobject, &nmdbType);
#endif
	if (db == NULL)
		return NULL;

	if (!PyArg_ParseTuple(args, ":new")) {
		return NULL;
	}

	db->db = nmdb_init();
	if (db->db == NULL) {
		return PyErr_NoMemory();
	}

	/* XXX: is this necessary? */
	if (PyErr_Occurred()) {
		nmdb_free(db->db);
		return NULL;
	}

	return (PyObject *) db;
}
开发者ID:dolfly,项目名称:nmdb,代码行数:29,代码来源:nmdb_ll.c

示例3: char

/*@[email protected]*/ PyObject *
PyStrListProxy_New(
    /*@[email protected]*/ PyObject* owner,
    Py_ssize_t size,
    Py_ssize_t maxsize,
    char (*array)[72]) {

  PyStrListProxy* self = NULL;

  if (maxsize == 0) {
    maxsize = 68;
  }

  self = (PyStrListProxy*)PyStrListProxyType.tp_alloc(&PyStrListProxyType, 0);
  if (self == NULL) {
    return NULL;
  }

  Py_XINCREF(owner);
  self->pyobject = owner;
  self->size = size;
  self->maxsize = maxsize;
  self->array = array;
  return (PyObject*)self;
}
开发者ID:Cadair,项目名称:astropy,代码行数:25,代码来源:str_list_proxy.c

示例4: return

 template <typename U> static PyObject *c2py(U &&x) {
   PyTypeObject *p = get_type_ptr(typeid(T));
   if (p == nullptr) return NULL;
   py_type *self = (py_type *)p->tp_alloc(p, 0);
   if (self != NULL) { self->_c = new T{std::forward<U>(x)}; }
   return (PyObject *)self;
 }
开发者ID:TRIQS,项目名称:triqs,代码行数:7,代码来源:py_converter.hpp

示例5: execute

    static inline PyObject* execute(Arg& x)
    {
        BOOST_MPL_ASSERT((mpl::or_<is_class<T>, is_union<T> >));

        PyTypeObject* type = Derived::get_class_object(x);

        if (type == 0)
            return python::detail::none();

        PyObject* raw_result = type->tp_alloc(
            type, objects::additional_instance_size<Holder>::value);
          
        if (raw_result != 0)
        {
            python::detail::decref_guard protect(raw_result);
            
            instance_t* instance = (instance_t*)raw_result;
            
            // construct the new C++ object and install the pointer
            // in the Python object.
            Derived::construct(&instance->storage, (PyObject*)instance, x)->install(raw_result);
              
            // Note the position of the internally-stored Holder,
            // for the sake of destruction
            Py_SIZE(instance) = offsetof(instance_t, storage);

            // Release ownership of the python object
            protect.cancel();
        }
        return raw_result;
    }
开发者ID:DD-L,项目名称:lproxy,代码行数:31,代码来源:make_instance.hpp

示例6: return

static PyObject *
BufferSubtype_New(PyTypeObject *subtype,
                  Py_buffer *view_p,
                  int filled,
                  int preserve)
{
    BufferObject *bp = (BufferObject *)Py_buffer_Type.tp_alloc(subtype, 0);
    if (!bp) {
        return 0;
    }
    bp->view_p = view_p;
    bp->flags = 0;
    if (bp->view_p) {
        if (filled) {
            bp->flags |= BUFOBJ_FILLED;
        }
        else {
            bp->view_p->obj = 0;
        }
        if (!preserve) {
            bp->flags |= BUFOBJ_MUTABLE;
        }
    }
    else {
        bp->flags = BUFOBJ_MUTABLE;
    }
    return (PyObject *)bp;
}
开发者ID:Anugrahaa,项目名称:anagrammatic,代码行数:28,代码来源:newbuffer.c

示例7: if

PyObject*
IcePy::createConnectionInfo(const Ice::ConnectionInfoPtr& connectionInfo)
{
    PyTypeObject* type;
    if(Ice::TCPConnectionInfoPtr::dynamicCast(connectionInfo))
    {
        type = &TCPConnectionInfoType;
    }
    else if(Ice::UDPConnectionInfoPtr::dynamicCast(connectionInfo))
    {
        type = &UDPConnectionInfoType;
    }
    else if(Ice::IPConnectionInfoPtr::dynamicCast(connectionInfo))
    {
        type = &IPConnectionInfoType;
    }
    else
    {
        type = &ConnectionInfoType;
    }

    ConnectionInfoObject* obj = reinterpret_cast<ConnectionInfoObject*>(type->tp_alloc(type, 0));
    if(!obj)
    {
        return 0;
    }
    obj->connectionInfo = new Ice::ConnectionInfoPtr(connectionInfo);

    return (PyObject*)obj;
}
开发者ID:pedia,项目名称:zeroc-ice,代码行数:30,代码来源:ConnectionInfo.cpp

示例8: TODO

B_WUR B_FUNC bool
b_py_question_class_set_native_vtable(
    B_BORROW PyTypeObject *type,
    B_BORROW struct B_QuestionVTable const *vtable) {
  struct B_PyQuestionVTable *vtable_py
    = (struct B_PyQuestionVTable *)
      b_py_question_vtable_type_.tp_alloc(
        &b_py_question_vtable_type_, 0);
  if (!vtable_py) {
    return false;
  }
  vtable_py->native_vtable = vtable;
  vtable_py->python_vtable = b_py_python_question_vtable_;
  vtable_py->python_vtable.uuid = vtable->uuid;
  vtable_py->python_vtable.answer_vtable
    = vtable->answer_vtable;  // TODO(strager)
  if (PyDict_SetItemString(
      type->tp_dict,
      b_py_question_vtable_key_,
      (PyObject *) vtable_py) == -1) {
    Py_DECREF(vtable_py);
    return false;
  }
  Py_DECREF(vtable_py);
  return true;
}
开发者ID:strager,项目名称:b-cc,代码行数:26,代码来源:QuestionVTable.c

示例9: CArray_createFromLength

/**
 * Factory function for a CArray used if only the number of items is known given.
 *
 * Note that this method does not increment the reference counter. You are responsible for
 * calling Py_INCREF(obj) in the returned obj yourself
 */
PyObject* CArray_createFromLength(const char* format, int length) {
    PyTypeObject* type = &CArray_Type;
    CArrayObj* self;
    void* items;
    size_t item_size;

    item_size = CArray_getItemSize(format);
    if (item_size <= 0) {
        return NULL;
    }

    items = calloc(item_size, length);
    if (items == NULL) {
        PyErr_SetString(PyExc_MemoryError, "out of memory");
        return NULL;
    }

    if (length <= 0) {
        PyErr_SetString(PyExc_ValueError, "length must be > 0");
        return NULL;
    }

    self = (CArrayObj*) type->tp_alloc(type, 0);
    CArray_initInstance(self, format, items, item_size, length, CArray_releaseElements);
    return (PyObject*) self;
}
开发者ID:bcdev,项目名称:beam-extapi,代码行数:32,代码来源:beampy_carray.c

示例10: return

PyObject *
pygi_struct_new_from_g_type (GType g_type,
                             gpointer      pointer,
                             gboolean      free_on_dealloc)
{
    PyGIStruct *self;
    PyTypeObject *type;

    type = (PyTypeObject *)pygi_type_import_by_g_type (g_type);

    if (!type)
        type = (PyTypeObject *)&PyGIStruct_Type; /* fallback */

    if (!PyType_IsSubtype (type, &PyGIStruct_Type)) {
        PyErr_SetString (PyExc_TypeError, "must be a subtype of gi.Struct");
        return NULL;
    }

    self = (PyGIStruct *) type->tp_alloc (type, 0);
    if (self == NULL) {
        return NULL;
    }

    pyg_pointer_set_ptr (self, pointer);
    ( (PyGPointer *) self)->gtype = g_type;
    self->free_on_dealloc = free_on_dealloc;

    return (PyObject *) self;
}
开发者ID:GNOME,项目名称:pygobject,代码行数:29,代码来源:pygi-struct.c

示例11: assert

/* PycairoFontFace_FromFontFace
 * Create a new PycairoFontFace from a cairo_font_face_t
 * font_face - a cairo_font_face_t to 'wrap' into a Python object.
 *             it is unreferenced if the PycairoFontFace creation fails
 * Return value: New reference or NULL on failure
 */
PyObject *
PycairoFontFace_FromFontFace (cairo_font_face_t *font_face)
{
    PyTypeObject *type = NULL;
    PyObject *o;

    assert (font_face != NULL);

    if (Pycairo_Check_Status (cairo_font_face_status (font_face))) {
	cairo_font_face_destroy (font_face);
	return NULL;
    }

    switch (cairo_font_face_get_type (font_face)) {
    case CAIRO_FONT_TYPE_TOY:
        type = &PycairoToyFontFace_Type;
        break;
    default:
        type = &PycairoFontFace_Type;
        break;
    }
    o = type->tp_alloc (type, 0);
    if (o == NULL)
	cairo_font_face_destroy (font_face);
    else
	((PycairoFontFace *)o)->font_face = font_face;
    return o;
}
开发者ID:dalembertian,项目名称:pycairo,代码行数:34,代码来源:pycairo-font.c

示例12: PyUpb_Message_StartSequence

static upb_sflow_t PyUpb_Message_StartSequence(void *m, upb_value fval) {
  PyObject **seq = PyUpb_Accessor_GetPtr(m, fval);
  PyTypeObject *type = ((PyUpb_MessageType*)Py_TYPE(m))->alt_type;
  if (!*seq) *seq = type->tp_alloc(type, 0);
  upb_stdmsg_sethas(m, fval);
  return UPB_CONTINUE_WITH(*seq);
}
开发者ID:chenbk85,项目名称:upb,代码行数:7,代码来源:upb.c

示例13: KK

static PyObject *
_K_subscript(_K *self, PyObject *key)
{
	int i;
	K kobj = self->kobj;
	char *skey;
	int key_length;
	int value_index = 1;
	if (kobj->t != 5) {
		PyErr_Format(PyExc_TypeError,
			     "k object of type %d is not a dictionary", kobj->t);
		return NULL;
	}
	if (-1 == PyString_AsStringAndSize(key, &skey, &key_length)) {
		return NULL;
	}
	if (skey[key_length-1] == '.') {
		--key_length;
		++value_index;
	}
	for (i=0; i < kobj->n; ++i) {
		K e = KK(kobj)[i];
		if (0 == strncmp(skey,Ks(KK(e)[0]),key_length)) {
			PyTypeObject* type = self->ob_type;
			_K* k = (_K*)type->tp_alloc(type, 0);
			k->kobj = ci(KK(e)[value_index]);
			return (PyObject*)k;
		}
	}
	PyErr_SetObject(PyExc_KeyError, key);
	return NULL;
}
开发者ID:kevinarpe,项目名称:kx,代码行数:32,代码来源:_k20.c

示例14: PyUpb_Message_StartSubmessage

static upb_sflow_t PyUpb_Message_StartSubmessage(void *m, upb_value fval) {
  PyObject **submsg = PyUpb_Accessor_GetPtr(m, fval);
  PyTypeObject *type = Py_TYPE(m);
  if (!*submsg) *submsg = type->tp_alloc(type, 0);
  upb_stdmsg_sethas(m, fval);
  return UPB_CONTINUE_WITH(*submsg);
}
开发者ID:chenbk85,项目名称:upb,代码行数:7,代码来源:upb.c

示例15: if

PyObject*
IcePy::createEndpointInfo(const Ice::EndpointInfoPtr& endpointInfo)
{
    PyTypeObject* type;
    if(Ice::TCPEndpointInfoPtr::dynamicCast(endpointInfo))
    {
        type = &TCPEndpointInfoType;
    }
    else if(Ice::UDPEndpointInfoPtr::dynamicCast(endpointInfo))
    {
        type = &UDPEndpointInfoType;
    }
    else if(Ice::OpaqueEndpointInfoPtr::dynamicCast(endpointInfo))
    {
        type = &OpaqueEndpointInfoType;
    }
    else if(Ice::IPEndpointInfoPtr::dynamicCast(endpointInfo))
    {
        type = &IPEndpointInfoType;
    }
    else
    {
        type = &EndpointInfoType;
    }

    EndpointInfoObject* obj = reinterpret_cast<EndpointInfoObject*>(type->tp_alloc(type, 0));
    if(!obj)
    {
        return 0;
    }
    obj->endpointInfo = new Ice::EndpointInfoPtr(endpointInfo);

    return (PyObject*)obj;
}
开发者ID:2008hatake,项目名称:zeroc-ice,代码行数:34,代码来源:EndpointInfo.cpp


注:本文中的PyTypeObject::tp_alloc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。