Пример #1
0
/* C API */
PyObject*
PyCD_New (int _index)
{
    PyCD *cd;
    SDL_CD *cdrom;
    
    ASSERT_CDROM_INIT(NULL);
    
    if (_index < 0 || _index > SDL_CDNumDrives ())
    {
        PyErr_SetString (PyExc_ValueError, "invalid cdrom drive index");
        return NULL;
    }

    cd = (PyCD*) PyCD_Type.tp_new (&PyCD_Type, NULL, NULL);
    if (!cd)
        return NULL;

    cdrom = SDL_CDOpen (_index);
    if (!cdrom)
    {
        Py_DECREF (cd);
        PyErr_SetString (PyExc_PyGameError, SDL_GetError ());
        return NULL;
    }
    
    cd->cd = cdrom;
    cd->index = _index;
    cdrommod_add_drive (_index, cdrom);
    return (PyObject*) cd;
}
Пример #2
0
/* C API */
PyObject*
PyEvent_NewInternal (SDL_Event *event, int release)
{
    PyObject *dict;
    PyEvent *ev;

    ev = (PyEvent*) PyEvent_Type.tp_new (&PyEvent_Type, NULL, NULL);
    if (!ev)
        return NULL;

    if (!event)
    {
        ev->type = SDL_NOEVENT;
        return (PyObject*) ev;
    }

    Py_XDECREF (ev->dict);
    dict = _create_dict_from_event (event, release);
    if (!dict)
    {
        Py_DECREF (ev);
        return NULL;
    }


    ev->dict = dict;
    ev->type = event->type;

    return (PyObject*) ev;
}
Пример #3
0
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;
}
Пример #4
0
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);
}
Пример #5
0
PygtsSegment * 
pygts_segment_new(GtsSegment *s)
{
  PyObject *args, *kwds;
  PygtsObject *segment;

  /* Check for Segment in the object table */
  if( (segment=PYGTS_OBJECT(g_hash_table_lookup(obj_table,GTS_OBJECT(s))))
      != NULL ) {
    Py_INCREF(segment);
    return PYGTS_FACE(segment);
  }

  /* Build a new Segment */
  args = Py_BuildValue("OO",Py_None,Py_None);
  kwds = Py_BuildValue("{s:O}","alloc_gtsobj",Py_False);
  segment = PYGTS_SEGMENT(PygtsSegmentType.tp_new(&PygtsSegmentType, 
						  args, kwds));
  Py_DECREF(args);
  Py_DECREF(kwds);
  if( segment == NULL ) {
    PyErr_SetString(PyExc_MemoryError,"could not create Segment");
    return NULL;
  }
  segment->gtsobj = GTS_OBJECT(s);

  /* Register and return */
  pygts_object_register(segment);
  return PYGTS_SEGMENT(segment);
}
Пример #6
0
PygtsFace *
pygts_face_new(GtsFace *f)
{
  PyObject *args, *kwds;
  PygtsObject *face;

  /* Check for Face in the object table */
  if( (face=PYGTS_OBJECT(g_hash_table_lookup(obj_table,GTS_OBJECT(f))))
      != NULL ) {
    Py_INCREF(face);
    return PYGTS_FACE(face);
  }

  /* Build a new Face */
  args = Py_BuildValue("OOO",Py_None,Py_None,Py_None);
  kwds = Py_BuildValue("{s:O}","alloc_gtsobj",Py_False);
  face = PYGTS_OBJECT(PygtsFaceType.tp_new(&PygtsFaceType, args, kwds));
  Py_DECREF(args);
  Py_DECREF(kwds);
  if( face == NULL ) {
    PyErr_SetString(PyExc_MemoryError, "could not create Face");
    return NULL;
  }
  face->gtsobj = GTS_OBJECT(f);

  /* Attach the parent */
  if( (face->gtsobj_parent = parent(f)) == NULL ) {
    Py_DECREF(face);
    return NULL;
  }
  
  /* Register and return */
  pygts_object_register(face);
  return PYGTS_FACE(face);
}
Пример #7
0
PygtsVertex *
pygts_vertex_new(GtsVertex *v)
{
  PyObject *args, *kwds;
  PygtsObject *vertex;

  /* Check for Vertex in the object table */
  if( (vertex = PYGTS_OBJECT(g_hash_table_lookup(obj_table,GTS_OBJECT(v)))) 
      !=NULL ) {
    Py_INCREF(vertex);
    return PYGTS_VERTEX(vertex);
  }

  /* Build a new Vertex */
  args = Py_BuildValue("ddd",0,0,0);
  kwds = Py_BuildValue("{s:O}","alloc_gtsobj",Py_False);
  vertex = PYGTS_VERTEX(PygtsVertexType.tp_new(&PygtsVertexType, args, kwds));
  Py_DECREF(args);
  Py_DECREF(kwds);
  if( vertex == NULL ) {
    PyErr_SetString(PyExc_MemoryError,"could not create Vertex");
    return NULL;
  }
  vertex->gtsobj = GTS_OBJECT(v);

  /* Attach the parent */
  if( (vertex->gtsobj_parent=parent(v)) == NULL ) {
	Py_DECREF(vertex);
	return NULL;
  }

  /* Register and return */
  pygts_object_register(vertex);
  return PYGTS_VERTEX(vertex);
}
Пример #8
0
/*
 * Return an object containing info on a path in the Sector filesystem.
 *
 * path is the full path of the file/dir to get info on.
 *
 * Returns: on success an object encapsulating the info for the path. On
 * failure None.
 */
static PyObject* stat( PyObject* self, PyObject* args )
{
    const char* path;
    SNode attr;
    
    if( !PyArg_ParseTuple( args, "s", &path ) ) {
        return( NULL );
    }
    
    int status = Sector::stat( path, attr );
    if( status < 0 ) {
        PyErr_SetString( PyExc_IOError, "stat failed, status=" + status );
        return( NULL );
    }

    StatInfo* s =
        (StatInfo*)StatInfoType.tp_new( &StatInfoType, NULL, NULL );
    if( s < 0 ) {
        return( NULL );
    }

//    Py_DECREF( s->name );
    s->name = PyString_FromString( attr.m_strName.c_str() );
    s->isDir = attr.m_bIsDir;
    s->timestamp = attr.m_llTimeStamp;
    s->size = attr.m_llSize;
    
    return( (PyObject*)s );
}
Пример #9
0
/*
 * 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;
}
Пример #10
0
AerospikeGlobalHosts * AerospikeGobalHosts_New(aerospike* as)
{
	AerospikeGlobalHosts * self = (AerospikeGlobalHosts *) AerospikeGlobalHosts_Type.tp_new(&AerospikeGlobalHosts_Type, Py_None, Py_None);
	self->as = as;
	self->shm_key = as->config.shm_key;
	self->ref_cnt = 1;
	Py_INCREF((PyObject*) self);
	return self;
}
Пример #11
0
PyObject *
PyTibrvNetTransport_FromTransport(TibrvNetTransport *transport)
{
	PyTibrvNetTransportObject *t = (PyTibrvNetTransportObject*)PyTibrvNetTransport_Type.tp_new(&PyTibrvNetTransport_Type, NULL, NULL);
	if (t != NULL)
	{
		t->transport = transport;
	}
	return (PyObject *) t;
}
Пример #12
0
PyObject *create_ethernet_instance(int caplen,
                                   const unsigned char *pkt)
{
    PyObject *obj;

    obj = ethernet_type.tp_new(&ethernet_type, NULL, NULL);
    memcpy(&ETHERNET_CAST(obj)->__ethernet, pkt,
           sizeof(struct ethernet));
    return obj;
}
Пример #13
0
static PyObject *
WorkRequest_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
    WorkRequest *self = (WorkRequest *)RequestType.tp_new(type, args, kwargs);
    if (!self) {
        return NULL;
    }
    UV_REQUEST(self) = (uv_req_t *)&self->req;
    return (PyObject *)self;
}
Пример #14
0
void SetStdout(StdOutWriteType write) {
  if (!gStdOut) {
    gStdOutSaved = PySys_GetObject("stdout");
    gStdErrSaved = PySys_GetObject("stderr");
    gStdOut = StdoutType.tp_new(&StdoutType, 0, 0);
  }
  StdOut *impl = reinterpret_cast<StdOut *>(gStdOut);
  impl->write = write;
  PySys_SetObject("stdout", gStdOut);
  PySys_SetObject("stderr", gStdOut);
}
Пример #15
0
extern PyObject * Field_create ( FudgeField field, Message * parent )
{
    Field * obj = ( Field * ) FieldType.tp_new ( &FieldType, 0, 0 );
    if ( obj )
    {
        Py_INCREF( ( PyObject * ) parent );
        obj->parent = parent;
        obj->field = field;
    }
    return ( PyObject * ) obj;
}
Пример #16
0
AerospikeKey * AerospikeKey_New(AerospikeClient * client, PyObject * args, PyObject * kwds)
{
	Py_INCREF(client);
	Py_INCREF(args);

    AerospikeKey * self = (AerospikeKey *) AerospikeKey_Type.tp_new(&AerospikeKey_Type, args, kwds);
    self->client = client;
	self->key = args;
    AerospikeKey_Type.tp_init((PyObject *) self, args, kwds);
	return self;
}
Пример #17
0
void Redirector::set_stdout(stdout_write_type write)
{
    if (!m_stdout)
    {
        m_stdout_saved = PySys_GetObject(const_cast<char*>("stdout")); // borrowed
        m_stdout = StdoutType.tp_new(&StdoutType, 0, 0);
    }

    Stdout* impl = reinterpret_cast<Stdout*>(m_stdout);
    impl->write = write;
    PySys_SetObject(const_cast<char*>("stdout"), m_stdout);
}
Пример #18
0
void ssipylog_stdout_set(ssipylog_stdout_write_type write)
{
    if (!ssipylog_g_stdout)
    {
		ssipylog_g_stdout_saved = PySys_GetObject("stdout"); // borrowed
		ssipylog_g_stdout = ssipylog_stdout_Type.tp_new(&ssipylog_stdout_Type, 0, 0);
    }

	ssipylog_stdout *impl = (ssipylog_stdout *)ssipylog_g_stdout;
    impl->write = write;
    PySys_SetObject("stdout", ssipylog_g_stdout);
}
Пример #19
0
static PyObject *
FSRequest_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
    FSRequest *self = (FSRequest *)RequestType.tp_new(type, args, kwargs);
    if (!self) {
        return NULL;
    }
    UV_REQUEST(self) = (uv_req_t *)&self->req;
    self->path = NULL;
    self->result = NULL;
    self->error = NULL;
    return (PyObject *)self;
}
Пример #20
0
PyObject* CameraInfoObj_Create(const mve::CameraInfo& cam)
{
  PyObject* args = PyTuple_New(0);
  PyObject* kwds = PyDict_New();
  PyObject* obj = CameraInfoType.tp_new(&CameraInfoType, args, kwds);
  Py_DECREF(args);
  Py_DECREF(kwds);

  if (obj) {
    ((CameraInfoObj*) obj)->instance = cam;
  }

  return obj;
}
Пример #21
0
static PyObject *
Struct_copy(PyObject *self)
{
    PyObject *copy;
    PyTypeObject *mytype;

    mytype = self->ob_type;
    copy = mytype->tp_new(mytype, NULL, NULL);

    if (copy == NULL)
        return NULL;
    if (0 == PyDict_Merge(copy, self, 1))
        return copy;
    Py_DECREF(copy);
    return NULL;
}
Пример #22
0
static PyObject *xslt_newobj(PyObject *module, PyObject *args)
{
  PyObject *cls, *newargs, *obj;
  PyTypeObject *type;
  Py_ssize_t n;

  n = PyTuple_Size(args);
  if (n < 1) {
    PyErr_SetString(PyExc_TypeError, "__newobj__ takes at least 1 argument");
    return NULL;
  }

  cls = PyTuple_GET_ITEM(args, 0);
  if (!PyType_Check(cls)) {
    PyErr_Format(PyExc_TypeError,
                 "__newobj__ argument 1 must be %.50s, not %.50s",
                 PyType_Type.tp_name,
                 cls == Py_None ? "None" : cls->ob_type->tp_name);
    return NULL;
  }

  type = (PyTypeObject *) cls;
  if (type->tp_new == NULL) {
    PyErr_Format(PyExc_TypeError, "type '%.100s' has NULL tp_new slot",
                 type->tp_name);
    return NULL;
  }

  /* create the argument tuple for the __new__ method */
  newargs = PyTuple_New(n - 1);
  if (newargs == NULL)
    return NULL;
  while (n > 1) {
    PyObject *item = PyTuple_GET_ITEM(args, n--);
    Py_INCREF(item);
    PyTuple_SET_ITEM(newargs, n, item);
  }

  /* call __new__ */
  obj = type->tp_new(type, newargs, NULL);
  Py_DECREF(newargs);

  return obj;
}
Пример #23
0
PyObject *
pyorbit_poamanager_new(PortableServer_POAManager poamanager)
{
    PyCORBA_Object *self;
    PyTypeObject *type;
    PyObject *args;

    if (!poamanager) {
	Py_INCREF(Py_None);
	return Py_None;
    }
    type = &PyPortableServer_POAManager_Type;
    args = PyTuple_New(0);
    self = (PyCORBA_Object *)type->tp_new(type, args, NULL);
    Py_DECREF(args);
    if (!self) return NULL;
    self->objref = (CORBA_Object)poamanager;
    return (PyObject *)self;
}
Пример #24
0
Ice::ValuePtr
IcePy::DefaultValueFactory::create(const string& id)
{
    AdoptThread adoptThread; // Ensure the current thread is able to call into Python.

    Ice::ValuePtr v;

    //
    // Give the application-provided default factory a chance to create the object first.
    //
    if(_delegate)
    {
        v = _delegate->create(id);
        if(v)
        {
            return v;
        }
    }

    //
    // Get the type information.
    //
    ValueInfoPtr info = getValueInfo(id);

    if(!info)
    {
        return 0;
    }

    //
    // Instantiate the object.
    //
    PyTypeObject* type = reinterpret_cast<PyTypeObject*>(info->pythonType.get());
    PyObjectHandle args = PyTuple_New(0);
    PyObjectHandle obj = type->tp_new(type, args.get(), 0);
    if(!obj.get())
    {
        assert(PyErr_Occurred());
        throw AbortMarshaling();
    }

    return new ObjectReader(obj.get(), info);
}
Пример #25
0
/* C API */
PyObject*
PySources_New (PyObject *context, ALsizei count)
{
    ALuint *buf;
    PyObject *sources;

    if (!context || !PyContext_Check (context))
    {
        PyErr_SetString (PyExc_TypeError, "context is not a valid Context");
        return NULL;
    }

    if (count < 1)
    {
        PyErr_SetString (PyExc_ValueError, "cannot create less than 1 sources");
        return NULL;
    }

    sources = PySources_Type.tp_new (&PySources_Type, NULL, NULL);
    if (!sources)
        return NULL;
    ((PySources*)sources)->context = context;
    ((PySources*)sources)->count = count;
    ((PySources*)sources)->sources = NULL;

    buf = PyMem_New (ALuint, count);
    if (!buf)
    {
        Py_DECREF (sources);
        return NULL;
    }
    CLEAR_ALERROR_STATE ();
    alGenSources (count, buf);
    if (SetALErrorException (alGetError (), 0))
    {
        Py_DECREF (sources);
        PyMem_Free (buf);
        return NULL;
    }

    ((PySources*)sources)->sources = buf;
    return sources;
}
Пример #26
0
AerospikeClient * AerospikeClient_New(PyObject * parent, PyObject * args, PyObject * kwds)
{
	AerospikeClient * self = (AerospikeClient *) AerospikeClient_Type.tp_new(&AerospikeClient_Type, args, kwds);
	if ( AerospikeClient_Type.tp_init((PyObject *) self, args, kwds) == 0 ){
		// Initialize connection flag
		self->is_conn_16 = false;
		return self;
	}
	else {
		as_error err;
		as_error_init(&err);
		as_error_update(&err, AEROSPIKE_ERR_PARAM, "Parameters are incorrect");
		PyObject * py_err = NULL;
		error_to_pyobject(&err, &py_err);
		PyObject *exception_type = raise_exception(&err);
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		return NULL;
	}
}
Пример #27
0
/* C API */
PyObject*
PyDevice_New (const char* name)
{
    ALCdevice *dev;
    PyObject *device = PyDevice_Type.tp_new (&PyDevice_Type, NULL, NULL);

    if (!device)
        return NULL;

    CLEAR_ALCERROR_STATE ();
    dev = alcOpenDevice (name);
    if (!dev)
    {
        SetALCErrorException (alcGetError (NULL), 1);
        Py_DECREF (device);
        return NULL;
    }
    ((PyDevice*)device)->device = dev;
    return device;
}
Пример #28
0
AerospikeLList * AerospikeLList_New(AerospikeClient * client, PyObject * args, PyObject * kwds)
{
	AerospikeLList * self = (AerospikeLList *) AerospikeLList_Type.tp_new(&AerospikeLList_Type, args, kwds);
	self->client = client;
	Py_INCREF(client);

	if (AerospikeLList_Type.tp_init((PyObject *)self, args, kwds) == 0) {
		return self;
	} else {
		as_error err;
		as_error_init(&err);
		as_error_update(&err, AEROSPIKE_ERR_PARAM, "Parameters are incorrect");
		PyObject * py_err = NULL;
		PyObject * py_key = NULL;
		PyObject *exception_type = raise_exception(&err);
		error_to_pyobject(&err, &py_err);
		if(PyObject_HasAttrString(exception_type, "key")) {
			if(&self->key) {
				key_to_pyobject(&err, &self->key, &py_key);
				PyObject_SetAttrString(exception_type, "key", py_key);
				Py_DECREF(py_key);
			} else {
				PyObject_SetAttrString(exception_type, "key", Py_None);
			}
		} 
		if(PyObject_HasAttrString(exception_type, "bin")) {
			if(&self->bin_name) {
				PyObject *py_bins = PyStr_FromString((char *)&self->bin_name);
				PyObject_SetAttrString(exception_type, "bin", py_bins);
				Py_DECREF(py_bins);
			} else {
				PyObject_SetAttrString(exception_type, "bin", Py_None);
			}
		}
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		return NULL;
	}
}
Пример #29
0
/*
    Function: py_AudioFrame_new
        Creates an AudioFrame and gets a pointer to its audio_frame structure.
        Internal use only.

    Parameters:
        min_sample - Minimum sample for this frame.
        max_sample - Maximum sample for this frame.
        channels - Number of channels for this frame.
        frame - Optional pointer to a variable to receive the actual frame.
            Everything but the current data window will be set.

    Returns:
        A reference to the new object if successful, or NULL on an error (an
        exception will be set).
*/
PyObject *
py_AudioFrame_new( int min_sample, int max_sample, int channels, audio_frame **frame ) {
    if( max_sample < min_sample ) {
        PyErr_SetString( PyExc_ValueError, "max_sample was less than min_sample." );
        return NULL;
    }

    if( channels < 0 ) {
        PyErr_SetString( PyExc_ValueError, "channels was less than zero." );
        return NULL;
    }

    PyObject *tuple = PyTuple_New( 0 ), *dict = PyDict_New();

    PyObject *result = py_type_AudioFrame.tp_new( &py_type_AudioFrame, tuple, dict );

    Py_CLEAR(tuple);
    Py_CLEAR(dict);

    if( !result )
        return NULL;

    PRIV(result)->full_min_sample = min_sample;
    PRIV(result)->full_max_sample = max_sample;
    PRIV(result)->channels = channels;

    PRIV(result)->data = PyMem_Malloc( sizeof(float) * (max_sample - min_sample + 1) * channels );

    if( !PRIV(result)->data ) {
        Py_DECREF(result);
        return PyErr_NoMemory();
    }

    if( frame )
        *frame = PRIV(result);

    return result;
}
Пример #30
0
static PyObject *newobj_call(PyObject *module, PyObject *args)
{
  PyObject *cls, *newargs, *obj;
  PyTypeObject *type;
  Py_ssize_t len;

  assert(PyTuple_Check(args));
  len = PyTuple_GET_SIZE(args);
  if (len < 1)
    return PyErr_Format(PyExc_TypeError,
                        "__newobj__() takes at least 1 argument (%zd given)",
                        len);
  cls = PyTuple_GET_ITEM(args, 0);
  if (!PyType_Check(cls))
    return PyErr_Format(PyExc_TypeError,
                        "__newobj__() argument 1 must be type, not %s",
                        cls == Py_None ? "None" : cls->ob_type->tp_name);
  type = (PyTypeObject *)cls;
  if (type->tp_new == NULL)
    return PyErr_Format(PyExc_TypeError, "cannot create '%s' instances",
                        type->tp_name);

  /* create the argument tuple for the __new__ method */
  newargs = PyTuple_New(--len);
  if (newargs == NULL)
    return NULL;
  while (len > 0) {
    PyObject *item = PyTuple_GET_ITEM(args, len);
    Py_INCREF(item);
    PyTuple_SET_ITEM(newargs, --len, item);
  }

  /* call __new__ */
  obj = type->tp_new(type, newargs, NULL);
  Py_DECREF(newargs);
  return obj;
}