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


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

本文整理汇总了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;
}
开发者ID:gdos,项目名称:pgreloaded.sdl12,代码行数:32,代码来源:cdrom.c

示例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;
}
开发者ID:gdos,项目名称:pgreloaded.sdl12,代码行数:31,代码来源:event.c

示例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;
}
开发者ID:DevJohan,项目名称:FreeCAD_sf_master,代码行数:26,代码来源:GeometryPyImp.cpp

示例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);
}
开发者ID:Jintram,项目名称:egfrd,代码行数:26,代码来源:pickle_support.hpp

示例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);
}
开发者ID:Azeko2xo,项目名称:woodem,代码行数:30,代码来源:segment.cpp

示例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);
}
开发者ID:Azeko2xo,项目名称:woodem,代码行数:35,代码来源:face.cpp

示例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);
}
开发者ID:Azeko2xo,项目名称:woodem,代码行数:35,代码来源:vertex.cpp

示例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 );
}
开发者ID:norouzi4d,项目名称:sector,代码行数:37,代码来源:SectorModule.cpp

示例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;
}
开发者ID:Dmdv,项目名称:python-fibers,代码行数:32,代码来源:fibers.c

示例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;
}
开发者ID:BeeswaxIO,项目名称:aerospike-client-python,代码行数:9,代码来源:type.c

示例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;
}
开发者ID:rob-blackbourn,项目名称:PyTibrv,代码行数:10,代码来源:PyTibrvNetTransport.cpp

示例12: memcpy

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;
}
开发者ID:Magnus932,项目名称:_packet,代码行数:10,代码来源:ethernet.c

示例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;
}
开发者ID:ConchLikeSun,项目名称:pyuv,代码行数:10,代码来源:request.c

示例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);
}
开发者ID:IndraVikas,项目名称:expressPython,代码行数:11,代码来源:emb.cpp

示例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;
}
开发者ID:vrai,项目名称:Fudge-PyC,代码行数:11,代码来源:field.c


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