Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
/*@null@*/ PyObject *
PyStrListProxy_New(
    /*@shared@*/ 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;
}
Пример #4
0
 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;
 }
Пример #5
0
    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;
    }
Пример #6
0
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;
}
Пример #7
0
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;
}
Пример #8
0
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;
}
Пример #9
0
/**
 * 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;
}
Пример #10
0
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;
}
Пример #11
0
/* 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;
}
Пример #12
0
Файл: upb.c Проект: chenbk85/upb
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);
}
Пример #13
0
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;
}
Пример #14
0
Файл: upb.c Проект: chenbk85/upb
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);
}
Пример #15
0
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;
}
Пример #16
0
static PyObject *PyImage_cnew(Image *im)
{
    PyImage *self;
    self = (PyImage *)PyImageType.tp_alloc(&PyImageType, 0);
    self->x = im;
    self->dict = PyDict_New();
    return (PyObject *)self;
}
Пример #17
0
static PyObject *pydega_create(void) {
	Dega *dega = (Dega *)pydega_type.tp_alloc(&pydega_type, 0);
	dega->input = uchararray_create(MastInput, sizeof(MastInput));
	dega->ram = uchararray_create(pMastb->Ram, sizeof(pMastb->Ram));
	dega->battery = uchararray_create(pMastb->Sram, sizeof(pMastb->Sram));
	dega->readonly = 0;
	return (PyObject *)dega;
}
Пример #18
0
Файл: upb.c Проект: chenbk85/upb
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);
}
Пример #19
0
static PyObject*
FibonacciHeap_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
{
    FibonacciHeap *fh;

    fh = (FibonacciHeap *)FibonacciHeapType.tp_alloc(&FibonacciHeapType, 0);
    return (PyObject *)fh;
}
Пример #20
0
/* 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;
}
Пример #21
0
// ---------------------------------------------------------------------------------
static PyObject *
Mixer_GetControls( PyMixerObject* obj)
{
	// Populate list of destinations first
	PyObject* cRes= PyList_New( 0 );
	if( !cRes )
		return NULL;

	// Scan all destinations
	for( int i= 0; i< obj->cObj->GetDestinationsCount(); i++ )
	{
		//
		char* sDest= obj->cObj->GetDestinationName( i );

		// Scan all sources for destination
		for( int j= 0; j< obj->cObj->GetConnectionsCount( i ); j++ )
		{
			// Set connection wise data
			char* sConn= obj->cObj->GetConnectionName( i, j );

			// Create lines under connections
			for( int k= 0; k< obj->cObj->GetControlsCount( i, j ); k++ )
			{
				// Create the mixer control object
				PyMixerControlObject* cControl= (PyMixerControlObject*)MixerControlType.tp_alloc( &MixerControlType, 0);
				if( !cControl )
				{
					Py_DECREF( cRes );
					return NULL;
				}

				// Set line wise data
				cControl->cObj= obj;
				Py_INCREF( obj );
				cControl->iDest= i;
				cControl->iConn= j;
				cControl->iControl= k;
				strcpy( cControl->sName, obj->cObj->GetControlName( i, j, k ) );
				obj->cObj->GetControlValues( i, j, k,
					&cControl->iMinValue, &cControl->iMaxValue, &cControl->iStep, &cControl->iType, &cControl->iChannels );

				if( cControl->iChannels== 0 )
					cControl->iChannels= 1;

				// Create dictionary with all names and controls
				PyObject *cTmp= Py_BuildValue( "{sssssssisN}",
						"destination", sDest,
						"connection", sConn,
						"name", obj->cObj->GetControlName( i, j, k ),
						"active", obj->cObj->IsActive( i, j, k ),
						"control", cControl );
				PyList_Append( cRes, cTmp );
				Py_DECREF( cTmp );
			}
		}
	}
	return cRes;
}
Пример #22
0
PyObject*
PyFeasibilitySet_create(lp_feasibility_set_t* S) {
  FeasibilitySet *self;
  self = (FeasibilitySet*)FeasibilitySetType.tp_alloc(&FeasibilitySetType, 0);
  if (self != NULL) {
    self->S = S;
  }
  return (PyObject *)self;
}
Пример #23
0
static PyObject*
Camera_new(Camera* obj) {
	CameraWrap* self;

	self = (CameraWrap*)cameraType.tp_alloc(&cameraType, 0);
	self->camObj = obj;

	return (PyObject*)self;
}
Пример #24
0
inline PyObject* create_SizeObject(const Size& d) {
  PyTypeObject* t = get_SizeType();
  if (t == 0)
    return 0;
  SizeObject* so;
  so = (SizeObject*)t->tp_alloc(t, 0);
  so->m_x = new Size(d);
  return (PyObject*)so;
}
Пример #25
0
/* Create a python quad from a C quad */
PyObject*
PyQuad_FromQuad(qdouble x)
{
    PYQUAD_PRIVATE* p = (PYQUAD_PRIVATE*)PyQuad_Type.tp_alloc(&PyQuad_Type, 0);
    if (p) {
        p->obval = x;
    }
    return (PyObject*)p;
}
Пример #26
0
inline PyObject* create_RegionMapObject(const RegionMap& d) {
  PyTypeObject* t = get_RegionMapType();
  if (t == 0)
    return 0;
  RegionMapObject* so;
  so = (RegionMapObject*)t->tp_alloc(t, 0);
  so->m_x = new RegionMap(d);
  return (PyObject*)so;
}
Пример #27
0
inline PyObject* create_RegionObject(const Region& d) {
  PyTypeObject* t = get_RegionType();
  if (t == 0)
    return 0;
  RegionObject* so;
  so = (RegionObject*)t->tp_alloc(t, 0);
  ((RectObject*)so)->m_x = new Region(d);
  return (PyObject*)so;
}
Пример #28
0
inline PyObject* create_RGBPixelObject(const RGBPixel& d) {
  PyTypeObject* t = get_RGBPixelType();
  if (t == 0)
    return 0;
  RGBPixelObject* so;
  so = (RGBPixelObject*)t->tp_alloc(t, 0);
  so->m_x = new RGBPixel(d);
  return (PyObject*)so;
}
Пример #29
0
inline PyObject* create_FloatPointObject(const FloatPoint& d) {
  PyTypeObject* t = get_FloatPointType();
  if (t == 0)
    return 0;
  FloatPointObject* so;
  so = (FloatPointObject*)t->tp_alloc(t, 0);
  so->m_x = new FloatPoint(d);
  return (PyObject*)so;
}
Пример #30
0
inline PyObject* create_DimObject(const Dim& d) {
  PyTypeObject* t = get_DimType();
  if (t == 0)
    return 0;
  DimObject* so;
  so = (DimObject*)t->tp_alloc(t, 0);
  so->m_x = new Dim(d);
  return (PyObject*)so;
}