本文整理汇总了C++中PyTypeObject类的典型用法代码示例。如果您正苦于以下问题:C++ PyTypeObject类的具体用法?C++ PyTypeObject怎么用?C++ PyTypeObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PyTypeObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: get_type_ptr
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;
}
示例3: reconstruct
static PyObject* reconstruct(PyObject* self, PyObject* args)
{
PyTypeObject* klass;
PyObject* base;
PyObject* state;
if (!PyArg_ParseTuple(args, "OOO", &klass, &base, &state))
return NULL;
if (!PyType_Check(klass)) {
PyErr_SetString(PyExc_TypeError, "argument 1 must be a type object");
return NULL;
}
if (!PyType_Check(base)) {
PyErr_SetString(PyExc_TypeError, "argument 2 must be a type object");
return NULL;
}
if (!PyTuple_Check(state)) {
PyErr_SetString(PyExc_TypeError, "argument 3 must be a tuple");
return NULL;
}
return klass->tp_new(klass, state, NULL);
}
示例4: PycairoFontFace_FromFontFace
/* 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;
}
示例5: 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;
}
示例6: copy
PyObject* GeometryPy::copy(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
Part::Geometry* geom = this->getGeometryPtr();
PyTypeObject* type = this->GetType();
PyObject* cpy = 0;
// let the type object decide
if (type->tp_new)
cpy = type->tp_new(type, this, 0);
if (!cpy) {
PyErr_SetString(PyExc_TypeError, "failed to create copy of geometry");
return 0;
}
Part::GeometryPy* geompy = static_cast<Part::GeometryPy*>(cpy);
// the PyMake function must have created the corresponding instance of the 'Geometry' subclass
// so delete it now to avoid a memory leak
if (geompy->_pcTwinPointer) {
Part::Geometry* clone = static_cast<Part::Geometry*>(geompy->_pcTwinPointer);
delete clone;
}
geompy->_pcTwinPointer = geom->copy();
return cpy;
}
示例7: 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;
}
示例8: 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);
}
示例9: 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);
}
示例10: _K_subscript
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;
}
示例11: pygi_struct_new_from_g_type
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;
}
示例12: 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;
}
示例13: fiber_create_main
/*
* Create main Fiber. There is always a main Fiber for a given (real) thread,
* and it's parent is always NULL.
*/
static Fiber *
fiber_create_main(void)
{
Fiber *t_main;
PyObject *dict = PyThreadState_GetDict();
PyTypeObject *cls = (PyTypeObject *)&FiberType;
if (dict == NULL) {
if (!PyErr_Occurred()) {
PyErr_NoMemory();
}
return NULL;
}
/* create the main Fiber for this thread */
t_main = (Fiber *)cls->tp_new(cls, NULL, NULL);
if (!t_main) {
return NULL;
}
Py_INCREF(dict);
t_main->ts_dict = dict;
t_main->parent = NULL;
t_main->thread_h = stacklet_newthread();
t_main->stacklet_h = NULL;
t_main->initialized = True;
t_main->is_main = True;
return t_main;
}
示例14: PyUpb_Message_StartRepeatedSubmessage
static upb_sflow_t PyUpb_Message_StartRepeatedSubmessage(
void *a, upb_value fval) {
(void)fval;
PyObject **elem = upb_stdarray_append(a, sizeof(void*));
PyTypeObject *type = ((PyUpb_MessageType*)Py_TYPE(a))->alt_type;
if (!*elem) *elem = type->tp_alloc(type, 0);
return UPB_CONTINUE_WITH(*elem);
}
示例15: PycairoSurface_FromSurface
/* PycairoSurface_FromSurface
* Create a new
* PycairoImageSurface,
* PycairoPDFSurface,
* PycairoPSSurface,
* PycairoSVGSurface,
* PycairoWin32Surface, or
* PycairoXlibSurface from a cairo_surface_t.
* surface - a cairo_surface_t to 'wrap' into a Python object.
* It is unreferenced if the PycairoSurface creation fails, or if the
* cairo_surface_t has an error status.
* base - the base object used to create the surface, or NULL.
* It is referenced to keep it alive while the cairo_surface_t is being used.
* Return value: New reference or NULL on failure
*/
PyObject *
PycairoSurface_FromSurface (cairo_surface_t *surface, PyObject *base)
{
PyTypeObject *type = NULL;
PyObject *o;
assert (surface != NULL);
if (Pycairo_Check_Status (cairo_surface_status (surface))) {
cairo_surface_destroy (surface);
return NULL;
}
switch (cairo_surface_get_type (surface)) {
#if CAIRO_HAS_IMAGE_SURFACE
case CAIRO_SURFACE_TYPE_IMAGE:
type = &PycairoImageSurface_Type;
break;
#endif
#if CAIRO_HAS_PDF_SURFACE
case CAIRO_SURFACE_TYPE_PDF:
type = &PycairoPDFSurface_Type;
break;
#endif
#if CAIRO_HAS_PS_SURFACE
case CAIRO_SURFACE_TYPE_PS:
type = &PycairoPSSurface_Type;
break;
#endif
#if CAIRO_HAS_SVG_SURFACE
case CAIRO_SURFACE_TYPE_SVG:
type = &PycairoSVGSurface_Type;
break;
#endif
#if CAIRO_HAS_WIN32_SURFACE
case CAIRO_SURFACE_TYPE_WIN32:
type = &PycairoWin32Surface_Type;
break;
#endif
#if CAIRO_HAS_XLIB_SURFACE
case CAIRO_SURFACE_TYPE_XLIB:
type = &PycairoXlibSurface_Type;
break;
#endif
default:
type = &PycairoSurface_Type;
break;
}
o = type->tp_alloc (type, 0);
if (o == NULL) {
cairo_surface_destroy (surface);
} else {
((PycairoSurface *)o)->surface = surface;
Py_XINCREF(base);
((PycairoSurface *)o)->base = base;
}
return o;
}