本文整理汇总了C++中PyTypeObject::tp_new方法的典型用法代码示例。如果您正苦于以下问题:C++ PyTypeObject::tp_new方法的具体用法?C++ PyTypeObject::tp_new怎么用?C++ PyTypeObject::tp_new使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyTypeObject
的用法示例。
在下文中一共展示了PyTypeObject::tp_new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
/* 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: return
/* 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: 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;
}
示例4: 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);
}
示例5: PYGTS_FACE
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: PYGTS_FACE
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: PYGTS_VERTEX
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: stat
/*
* 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:
/*
* 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:
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:
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: memcpy
PyObject *create_ethernet_instance(int caplen,
const unsigned char *pkt)
{
PyObject *obj;
obj = ethernet_type.tp_new(ðernet_type, NULL, NULL);
memcpy(ÐERNET_CAST(obj)->__ethernet, pkt,
sizeof(struct ethernet));
return obj;
}
示例13: return
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: SetStdout
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: return
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;
}