static PyObject* tp_new (PyTypeObject* type, PyObject* args, PyObject* kwds) { SELF self; soyatomsPosition* position = NULL; float radius = 1.0; soymaterialsMaterial* material = NULL; // Ensure no keywords were given if (!_PyArg_NoKeywords("soy.bodies.Sphere", kwds)) return NULL; // Parse arguments // TODO optional position radius and material parameters if (!PyArg_ParseTuple(args, "")) { return NULL; } // inherit base type self = (SELF) PyType_GenericNew(type, args, kwds); if (!self) return NULL; // new gobject self->g = soy_bodies_sphere_new(position, radius, material); // return self return (PyObject*) self; }
static PyObject * reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { Py_ssize_t n; PyObject *seq; reversedobject *ro; if (type == &PyReversed_Type && !_PyArg_NoKeywords("reversed()", kwds)) return NULL; if (!PyArg_UnpackTuple(args, "reversed", 1, 1, &seq) ) return NULL; if (PyObject_HasAttrString(seq, "__reversed__")) return PyObject_CallMethod(seq, "__reversed__", NULL); if (!PySequence_Check(seq)) { PyErr_SetString(PyExc_TypeError, "argument to reversed() must be a sequence"); return NULL; } n = PySequence_Size(seq); if (n == -1) return NULL; ro = (reversedobject *)type->tp_alloc(type, 0); if (ro == NULL) return NULL; ro->index = n-1; Py_INCREF(seq); ro->seq = seq; return (PyObject *)ro; }
Box* frozensetNew(Box* _cls, Box* container, BoxedDict* kwargs) { RELEASE_ASSERT(_cls->cls == type_cls, ""); BoxedClass* cls = static_cast<BoxedClass*>(_cls); RELEASE_ASSERT(isSubclass(cls, frozenset_cls), ""); if (_cls == frozenset_cls && !_PyArg_NoKeywords("frozenset()", kwargs)) { throwCAPIException(); } if (_cls != frozenset_cls) { return makeNewSet(cls, container); } if (container != NULL) { if (container->cls == frozenset_cls) return incref(container); BoxedSet* result = makeNewSet(cls, container); if (result->s.size() != 0) { return result; } Py_DECREF(result); } static Box* emptyfrozenset = NULL; if (!emptyfrozenset) { emptyfrozenset = new (frozenset_cls) BoxedSet(); PyGC_RegisterStaticConstant(emptyfrozenset); } Py_INCREF(emptyfrozenset); return emptyfrozenset; }
static PyObject* tp_new (PyTypeObject* type, PyObject* args, PyObject* kwds) { SELF self; float a, b, c = 0; // Ensure no keywords were given if (!_PyArg_NoKeywords("soy.atoms.Rotation", kwds)); // Try to parse 2 or 3 dimensions if (!PyArg_ParseTuple(args, "(ff)", &a, &b)) { PyErr_Clear(); if (!PyArg_ParseTuple(args, "(fff)", &a, &b, &c)) return NULL; } // inherit base type self = (SELF) PyType_GenericNew(type, args, kwds); if (!self) return NULL; // new gobject self->g = soy_atoms_rotation_new(a, b, c); // return self return (PyObject*) self; }
static SELF tp_new (PyTypeObject* type, PyObject* args, PyObject* kwds) { SELF self; soyatomsPosition* position = NULL; // Ensure no keywords were given if (!_PyArg_NoKeywords("soy.bodies.Mesh", kwds)) return NULL; // Parse arguments // TODO optional position /*if (!PyArg_ParseTuple(args, "")) { return NULL; }*/ // inherit base type self = (SELF) PyType_GenericNew(type, args, kwds); if (!self) return NULL; // new gobject self->g = soy_bodies_mesh_new(position); return self; }
static PyObject* tp_new (PyTypeObject* type, PyObject* args, PyObject* kwds) { SELF self; float width, height, depth = 0; // Ensure no keywords were given if (!_PyArg_NoKeywords("soy.atoms.Size", kwds)); // Try to parse 2 or 3 dimensions if (!PyArg_ParseTuple(args, "(ff)", &width, &height)) { PyErr_Clear(); if (!PyArg_ParseTuple(args, "(fff)", &width, &height, &depth)) return NULL; } // inherit base type self = (SELF) PyType_GenericNew(type, args, kwds); if (!self) return NULL; // new gobject self->g = soy_atoms_size_new(width, height, depth); // return self return (PyObject*) self; }
static SELF tp_new (PyTypeObject* type, PyObject* args, PyObject* kwds) { SELF self; const gchar* name = NULL; // Ensure no keywords were provided if (!_PyArg_NoKeywords("soy.materials.Wireframed", kwds)) return NULL; // Parse arguments if (!PyArg_ParseTuple(args, "s", &name)) { PyErr_Clear(); if (!PyArg_ParseTuple(args, "")) return NULL; } // inherit base type self = (SELF) PyType_GenericNew(type, args, kwds); if (!self) return NULL; // new gobject self->g = soy_materials_wireframed_new(name); // return self return self; }
Box* setInit(Box* _self, Box* container, BoxedDict* kwargs) { RELEASE_ASSERT(PySet_Check(_self), ""); if (PySet_Check(_self) && !_PyArg_NoKeywords("set()", kwargs)) { throwCAPIException(); } if (!container) return incref(None); BoxedSet* self = static_cast<BoxedSet*>(_self); setClearInternal(self); if (PyAnySet_Check(container)) { for (auto&& elt : ((BoxedSet*)container)->s) { self->s.insert(incref(elt)); } } else if (PyDict_CheckExact(container)) { for (auto&& elt : ((BoxedDict*)container)->d) { self->s.insert(incref(elt.first)); } } else { for (auto elt : container->pyElements()) { _setAddStolen(self, elt); } } return incref(None); }
/* XXX(nnorwitz): should we error check if the user passes any empty ranges? range(-10) range(0, -5) range(0, 5, -1) */ static PyObject * range_new(PyTypeObject *type, PyObject *args, PyObject *kw) { rangeobject *obj; PyObject *start = NULL, *stop = NULL, *step = NULL; if (!_PyArg_NoKeywords("range()", kw)) return NULL; if (PyTuple_Size(args) <= 1) { if (!PyArg_UnpackTuple(args, "range", 1, 1, &stop)) return NULL; stop = PyNumber_Index(stop); if (!stop) return NULL; start = PyLong_FromLong(0); if (!start) { Py_DECREF(stop); return NULL; } step = PyLong_FromLong(1); if (!step) { Py_DECREF(stop); Py_DECREF(start); return NULL; } } else { if (!PyArg_UnpackTuple(args, "range", 2, 3, &start, &stop, &step)) return NULL; /* Convert borrowed refs to owned refs */ start = PyNumber_Index(start); if (!start) return NULL; stop = PyNumber_Index(stop); if (!stop) { Py_DECREF(start); return NULL; } step = validate_step(step); /* Caution, this can clear exceptions */ if (!step) { Py_DECREF(start); Py_DECREF(stop); return NULL; } } obj = make_range_object(type, start, stop, step); if (obj != NULL) return (PyObject *) obj; /* Failed to create object, release attributes */ Py_XDECREF(start); Py_XDECREF(stop); Py_XDECREF(step); return NULL; }
static PyObject * py_sha3_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { SHA3object *self = NULL; Py_buffer buf = {NULL, NULL}; HashReturn res; PyObject *data = NULL; if (!_PyArg_NoKeywords(_PyType_Name(type), kwargs)) { return NULL; } if (!PyArg_UnpackTuple(args, _PyType_Name(type), 0, 1, &data)) { return NULL; } self = newSHA3object(type); if (self == NULL) { goto error; } if (type == &SHA3_224type) { res = Keccak_HashInitialize_SHA3_224(&self->hash_state); } else if (type == &SHA3_256type) { res = Keccak_HashInitialize_SHA3_256(&self->hash_state); } else if (type == &SHA3_384type) { res = Keccak_HashInitialize_SHA3_384(&self->hash_state); } else if (type == &SHA3_512type) { res = Keccak_HashInitialize_SHA3_512(&self->hash_state); #ifdef PY_WITH_KECCAK } else if (type == &Keccak_224type) { res = Keccak_HashInitialize(&self->hash_state, 1152, 448, 224, 0x01); } else if (type == &Keccak_256type) { res = Keccak_HashInitialize(&self->hash_state, 1088, 512, 256, 0x01); } else if (type == &Keccak_384type) { res = Keccak_HashInitialize(&self->hash_state, 832, 768, 384, 0x01); } else if (type == &Keccak_512type) { res = Keccak_HashInitialize(&self->hash_state, 576, 1024, 512, 0x01); #endif } else if (type == &SHAKE128type) { res = Keccak_HashInitialize_SHAKE128(&self->hash_state); } else if (type == &SHAKE256type) { res = Keccak_HashInitialize_SHAKE256(&self->hash_state); } else { PyErr_BadInternalCall(); goto error; } if (data) { GET_BUFFER_VIEW_OR_ERROR(data, &buf, goto error); if (buf.len >= HASHLIB_GIL_MINSIZE) { /* invariant: New objects can't be accessed by other code yet, * thus it's safe to release the GIL without locking the object. */ Py_BEGIN_ALLOW_THREADS res = SHA3_process(&self->hash_state, buf.buf, buf.len * 8); Py_END_ALLOW_THREADS } else {
static PyObject * reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { Py_ssize_t n; PyObject *seq, *reversed_meth; static PyObject *reversed_cache = NULL; reversedobject *ro; if (type == &PyReversed_Type && !_PyArg_NoKeywords("reversed()", kwds)) return NULL; if (!PyArg_UnpackTuple(args, "reversed", 1, 1, &seq) ) return NULL; if (PyInstance_Check(seq)) { reversed_meth = PyObject_GetAttrString(seq, "__reversed__"); if (reversed_meth == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) PyErr_Clear(); else return NULL; } } else { reversed_meth = _PyObject_LookupSpecial(seq, "__reversed__", &reversed_cache); if (reversed_meth == NULL && PyErr_Occurred()) return NULL; } if (reversed_meth != NULL) { PyObject *res = PyObject_CallFunctionObjArgs(reversed_meth, NULL); Py_DECREF(reversed_meth); return res; } if (!PySequence_Check(seq)) { PyErr_SetString(PyExc_TypeError, "argument to reversed() must be a sequence"); return NULL; } n = PySequence_Size(seq); if (n == -1) return NULL; ro = (reversedobject *)type->tp_alloc(type, 0); if (ro == NULL) return NULL; ro->index = n-1; Py_INCREF(seq); ro->seq = seq; return (PyObject *)ro; }
Box* setNew(Box* _cls, Box* container, BoxedDict* kwargs) { RELEASE_ASSERT(_cls->cls == type_cls, ""); BoxedClass* cls = static_cast<BoxedClass*>(_cls); RELEASE_ASSERT(isSubclass(cls, set_cls), ""); if (_cls == set_cls && !_PyArg_NoKeywords("set()", kwargs)) { throwCAPIException(); } // Note: set.__new__ explicitly ignores the container argument. return makeNewSet(cls, NULL); }
static int cm_init(PyObject *self, PyObject *args, PyObject *kwds) { classmethod *cm = (classmethod *)self; PyObject *callable; if (!PyArg_UnpackTuple(args, "classmethod", 1, 1, &callable)) return -1; if (!_PyArg_NoKeywords("classmethod", kwds)) return -1; Py_INCREF(callable); cm->cm_callable = callable; return 0; }
static int sm_init(PyObject *self, PyObject *args, PyObject *kwds) { staticmethod *sm = (staticmethod *)self; PyObject *callable; if (!PyArg_UnpackTuple(args, "staticmethod", 1, 1, &callable)) return -1; if (!_PyArg_NoKeywords("staticmethod", kwds)) return -1; Py_INCREF(callable); sm->sm_callable = callable; return 0; }
static PyObject * rangeiter_new(PyTypeObject *type, PyObject *args, PyObject *kw) { long start, stop, step; if (!_PyArg_NoKeywords("rangeiter()", kw)) return NULL; if (!PyArg_ParseTuple(args, "lll;rangeiter() requires 3 int arguments", &start, &stop, &step)) return NULL; return fast_range_iter(start, stop, step); }
static PyObject * buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw) { PyObject *ob; int offset = 0; int size = Py_END_OF_BUFFER; if (!_PyArg_NoKeywords("buffer()", kw)) return NULL; if (!PyArg_ParseTuple(args, "O|ii:buffer", &ob, &offset, &size)) return NULL; return PyBuffer_FromObject(ob, offset, size); }
static PyObject * bool_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *x = Py_False; long ok; if (!_PyArg_NoKeywords("bool", kwds)) return NULL; if (!PyArg_UnpackTuple(args, "bool", 0, 1, &x)) return NULL; ok = PyObject_IsTrue(x); if (ok < 0) return NULL; return PyBool_FromLong(ok); }
static PyObject * buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw) { PyObject *ob; Py_ssize_t offset = 0; Py_ssize_t size = Py_END_OF_BUFFER; if (PyErr_WarnPy3k("buffer() not supported in 3.x", 1) < 0) return NULL; if (!_PyArg_NoKeywords("buffer()", kw)) return NULL; if (!PyArg_ParseTuple(args, "O|nn:buffer", &ob, &offset, &size)) return NULL; return PyBuffer_FromObject(ob, offset, size); }
static PyObject* tp_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { SELF self; soyscenesScene* scene; PySoy_scenes_Scene_Object* pyscene; PySoy_bodies_Body_Object* bodyOne; PySoy_bodies_Body_Object* bodyTwo; // ensure no keywords were given if (!_PyArg_NoKeywords("soy.joints.Joint", kwds)) return NULL; if (PyArg_ParseTuple(args, "O!O!", &PySoy_bodies_Body_Type, &bodyOne, &PySoy_bodies_Body_Type, &bodyTwo)) scene = bodyTwo->g->scene; else { PyErr_Clear(); if (PyArg_ParseTuple(args, "O!O!", &PySoy_bodies_Body_Type, &bodyOne, &PySoy_scenes_Scene_Type, &pyscene)) scene = pyscene->g; else return NULL; } // Ensure bodies are in the same scene if (bodyOne->g->scene != scene) { PyErr_SetString(PyExc_ValueError, "Bodies must be in the same scene"); return NULL; } self = (SELF) PyType_GenericNew(type, args, NULL); if(!self) return NULL; if(!bodyTwo) self->g = soy_joints_joint_new(scene, bodyOne->g, NULL, NULL, NULL, NULL, NULL); else self->g = soy_joints_joint_new(scene, bodyOne->g, bodyTwo->g, NULL, NULL, NULL, NULL); return (PyObject*) self; }
static PyObject * instancemethod_new(PyTypeObject* type, PyObject* args, PyObject *kw) { PyObject *func; if (!_PyArg_NoKeywords("instancemethod", kw)) return NULL; if (!PyArg_UnpackTuple(args, "instancemethod", 1, 1, &func)) return NULL; if (!PyCallable_Check(func)) { PyErr_SetString(PyExc_TypeError, "first argument must be callable"); return NULL; } return PyInstanceMethod_New(func); }
static PyObject * cell_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyObject *return_value = NULL; PyObject *obj = NULL; if (!_PyArg_NoKeywords("cell", kwargs)) { goto exit; } /* min = 0: we allow the cell to be empty */ if (!PyArg_UnpackTuple(args, "cell", 0, 1, &obj)) { goto exit; } return_value = PyCell_New(obj); exit: return return_value; }
static PyObject * range_new(PyTypeObject *type, PyObject *args, PyObject *kw) { rangeobject *obj; long ilow = 0, ihigh = 0, istep = 1; long n; if (!_PyArg_NoKeywords("xrange()", kw)) return NULL; if (PyTuple_Size(args) <= 1) { if (!PyArg_ParseTuple(args, "l;xrange() requires 1-3 int arguments", &ihigh)) return NULL; } else { if (!PyArg_ParseTuple(args, "ll|l;xrange() requires 1-3 int arguments", &ilow, &ihigh, &istep)) return NULL; } if (istep == 0) { PyErr_SetString(PyExc_ValueError, "xrange() arg 3 must not be zero"); return NULL; } if (istep > 0) n = get_len_of_range(ilow, ihigh, istep); else n = get_len_of_range(ihigh, ilow, -istep); if (n < 0) { PyErr_SetString(PyExc_OverflowError, "xrange() result has too many items"); return NULL; } obj = PyObject_New(rangeobject, &PyRange_Type); if (obj == NULL) return NULL; obj->start = ilow; obj->len = n; obj->step = istep; return (PyObject *) obj; }
static int exc_init (zbarException *self, PyObject *args, PyObject *kwds) { if(!_PyArg_NoKeywords(self->base.ob_type->tp_name, kwds)) return(-1); PyBaseExceptionObject *super = (PyBaseExceptionObject*)self; Py_CLEAR(super->args); Py_INCREF(args); super->args = args; if(PyTuple_GET_SIZE(args) == 1) { Py_CLEAR(self->obj); self->obj = PyTuple_GET_ITEM(args, 0); Py_INCREF(self->obj); } return(0); }
static PyObject * slice_new(PyTypeObject *type, PyObject *args, PyObject *kw) { PyObject *start, *stop, *step; start = stop = step = NULL; if (!_PyArg_NoKeywords("slice()", kw)) return NULL; if (!PyArg_UnpackTuple(args, "slice", 1, 3, &start, &stop, &step)) return NULL; /* This swapping of stop and start is to maintain similarity with range(). */ if (stop == NULL) { stop = start; start = NULL; } return PySlice_New(start, stop, step); }
static PyObject * handler_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { HandlerObject *handler; if (!_PyArg_NoKeywords("Handler", kwds)) return NULL; if (!PyArg_ParseTuple(args,":Handler")) { return NULL; } handler = (HandlerObject *)type->tp_alloc(type, 0); if (handler != NULL) { handler->handler = ExpatHandler_New(handler, &handler_handlers); handler->new_namespaces = PyDict_New(); if (handler->new_namespaces == NULL) { Py_DECREF(handler); return NULL; } } return (PyObject *)handler; }
static PyObject* tp_new (PyTypeObject* type, PyObject* args, PyObject* kwds) { SELF self; const gchar* name = NULL; unsigned char r, g, b, a = 255; // Ensure no keywords were given if (!_PyArg_NoKeywords("soy.atoms.Color", kwds)); // Try name string argument first, // then 3-tuple uchars, // then 4-tuple uchars. if (!PyArg_ParseTuple(args, "s", &name)) { PyErr_Clear(); if (!PyArg_ParseTuple(args, "(bbb)", &r, &g, &b)) { PyErr_Clear(); if (!PyArg_ParseTuple(args, "(bbbb)", &r, &g, &b, &a)) { return NULL; } } } // inherit base type self = (SELF) PyType_GenericNew(type, args, kwds); if (!self) return NULL; // new gobject by name if (name) self->g = soy_atoms_color_new_named(name); // new gobject by uchars else self->g = soy_atoms_color_new(r, g, b, a); // return self return (PyObject*) self; }
static PyObject *Nuitka_Method_tp_new( PyTypeObject* type, PyObject* args, PyObject *kw ) { PyObject *func; PyObject *self; PyObject *klass = NULL; if ( !_PyArg_NoKeywords( "instancemethod", kw ) ) { return NULL; } else if ( !PyArg_UnpackTuple( args, "compiled_method", 2, 3, &func, &self, &klass ) ) { return NULL; } else if ( !PyCallable_Check( func ) ) { PyErr_Format( PyExc_TypeError, "first argument must be callable" ); return NULL; } else { if ( self == Py_None ) { self = NULL; } if ( self == NULL && klass == NULL ) { PyErr_Format( PyExc_TypeError, "unbound methods must have non-NULL im_class" ); return NULL; } } assert( Nuitka_Function_Check( func ) ); return Nuitka_Method_New( (struct Nuitka_FunctionObject *)func, self, klass ); }
static PyObject * method_new(PyTypeObject* type, PyObject* args, PyObject *kw) { PyObject *func; PyObject *self; if (!_PyArg_NoKeywords("method", kw)) return NULL; if (!PyArg_UnpackTuple(args, "method", 2, 2, &func, &self)) return NULL; if (!PyCallable_Check(func)) { PyErr_SetString(PyExc_TypeError, "first argument must be callable"); return NULL; } if (self == NULL || self == Py_None) { PyErr_SetString(PyExc_TypeError, "self must not be None"); return NULL; } return PyMethod_New(func, self); }
static PyObject * pysqlite_row_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { pysqlite_Row *self; PyObject* data; pysqlite_Cursor* cursor; assert(type != NULL && type->tp_alloc != NULL); if (!_PyArg_NoKeywords("Row()", kwargs)) return NULL; if (!PyArg_ParseTuple(args, "OO", &cursor, &data)) return NULL; if (!PyObject_TypeCheck((PyObject*)cursor, &pysqlite_CursorType)) { PyErr_SetString(PyExc_TypeError, "instance of cursor required for first argument"); return NULL; } if (!PyTuple_Check(data)) { PyErr_SetString(PyExc_TypeError, "tuple required for second argument"); return NULL; } self = (pysqlite_Row *) type->tp_alloc(type, 0); if (self == NULL) return NULL; Py_INCREF(data); self->data = data; Py_INCREF(cursor->description); self->description = cursor->description; return (PyObject *) self; }
static PyObject* tp_new (PyTypeObject* type, PyObject* args, PyObject* kwds) { SELF self; GError* error = NULL; const gchar* filename = NULL; PySoy_textures_Texture_Object* texture; gboolean png=0; // Ensure no keywords were provided if (!_PyArg_NoKeywords("soy.textures.Bumpmap", kwds)) return NULL; // Parse arguments if (!PyArg_ParseTuple(args, "s", &filename)) { PyErr_Clear(); if (!PyArg_ParseTuple(args, "")) { PyErr_Clear(); if (!PyArg_ParseTuple(args, "O!", &PySoy_textures_Texture_Type, &texture)) { return NULL; } } } if (filename) { png = g_str_has_suffix(filename, ".png"); if (!png) { PyErr_SetString(PyExc_ValueError, "Unrecognized mime-type"); return NULL; } } // inherit base type self = (SELF) PyType_GenericNew(type, args, kwds); if (!self) return NULL; // new gobject for PNG file if (png) self->g = soy_textures_bumpmap_new_from_png(filename, &error); // new gobject for texture else if (texture) self->g = soy_textures_bumpmap_new_emboss(texture->g); // new gobject else self->g = soy_textures_bumpmap_new(); // Check if error is raised (FILE_NOT_FOUND) if (error != NULL) { if(error->domain == IO_ERROR) { PyErr_SetString(PyExc_IOError, error->message); } else if (error->domain == MEMORY_ERROR) { PyErr_SetString(PyExc_MemoryError, error->message); } else { PyErr_SetString(PyExc_Exception, error->message); } g_clear_error (&error); return NULL; } // return self return (PyObject*) self; }