static void __Pyx_Generator_dealloc(PyObject *self) { __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; PyObject_GC_UnTrack(gen); if (gen->gi_weakreflist != NULL) PyObject_ClearWeakRefs(self); PyObject_GC_Track(self); if (gen->resume_label > 0) { /* Generator is paused, so we need to close */ Py_TYPE(gen)->tp_del(self); if (self->ob_refcnt > 0) return; /* resurrected. :( */ } PyObject_GC_UnTrack(self); Py_CLEAR(gen->closure); Py_CLEAR(gen->classobj); Py_CLEAR(gen->exc_type); Py_CLEAR(gen->exc_value); Py_CLEAR(gen->exc_traceback); PyObject_GC_Del(gen); }
static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, PyObject* qualname, PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type); if (op == NULL) return NULL; op->flags = flags; __Pyx_CyFunction_weakreflist(op) = NULL; op->func.m_ml = ml; op->func.m_self = (PyObject *) op; Py_XINCREF(closure); op->func_closure = closure; Py_XINCREF(module); op->func.m_module = module; op->func_dict = NULL; op->func_name = NULL; Py_INCREF(qualname); op->func_qualname = qualname; op->func_doc = NULL; op->func_classobj = NULL; op->func_globals = globals; Py_INCREF(op->func_globals); Py_XINCREF(code); op->func_code = code; // Dynamic Default args op->defaults_pyobjects = 0; op->defaults = NULL; op->defaults_tuple = NULL; op->defaults_kwdict = NULL; op->defaults_getter = NULL; op->func_annotations = NULL; PyObject_GC_Track(op); return (PyObject *) op; }
static PyObject * _gc_track(PyObject *self, PyObject *ob) { PyObject_GC_Track(ob); Py_INCREF(Py_None); return Py_None; }
static PyObject* compose_new(PyObject* type, PyObject* args, PyObject* kwargs) { static char* argnames[] = {"initial", "stepping"}; PyObject* initial = NULL; PyObject* stepping = Py_False; if(!PyArg_ParseTupleAndKeywords( // borrowed refs args, kwargs, "O|O:compose", argnames, &initial, &stepping)) return NULL; if(!is_generator(initial)) { PyErr_SetString(PyExc_TypeError, "compose() argument 1 must be generator"); return NULL; } PyComposeObject* cmps = PyObject_GC_New(PyComposeObject, &PyCompose_Type); if(cmps == NULL) return NULL; _compose_initialize((PyComposeObject*) cmps); if(stepping) cmps->stepping = stepping == Py_True; if(!generators_push(cmps, initial)) return NULL; PyObject_GC_Track(cmps); return (PyObject*) cmps; }
static PyObject *CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, /*PyObject *closure,*/ PyObject *self, PyObject *module, PyObject* code) { CyFunctionObject *op = PyObject_GC_New(CyFunctionObject, type); if (op == NULL) return NULL; op->flags = flags; op->func_weakreflist = NULL; op->func.m_ml = ml; /* op->func.m_self = (PyObject *) op;*/ Py_XINCREF(self); op->func.m_self = self; /*Py_XINCREF(closure); op->func_closure = closure;*/ op->func_closure = NULL; Py_XINCREF(module); op->func.m_module = module; op->func_dict = NULL; op->func_name = NULL; op->func_doc = NULL; op->func_classobj = NULL; Py_XINCREF(code); op->func_code = code; /* Dynamic Default args */ op->defaults_pyobjects = 0; op->defaults = NULL; op->defaults_tuple = NULL; op->defaults_getter = NULL; PyObject_GC_Track(op); return (PyObject *) op; }
PyObject * init_repository(PyObject *self, PyObject *args) { git_repository *repo; Repository *py_repo; const char *path; unsigned int bare; int err; if (!PyArg_ParseTuple(args, "sI", &path, &bare)) return NULL; err = git_repository_init(&repo, path, bare); if (err < 0) return Error_set_str(err, path); py_repo = PyObject_GC_New(Repository, &RepositoryType); if (py_repo) { py_repo->repo = repo; py_repo->index = NULL; PyObject_GC_Track(py_repo); return (PyObject*)py_repo; } git_repository_free(repo); return NULL; };
static CThunkObject* CThunkObject_new(Py_ssize_t nArgs) { CThunkObject *p; Py_ssize_t i; p = PyObject_GC_NewVar(CThunkObject, &PyCThunk_Type, nArgs); if (p == NULL) { return NULL; } p->pcl_write = NULL; p->pcl_exec = NULL; memset(&p->cif, 0, sizeof(p->cif)); p->flags = 0; p->converters = NULL; p->callable = NULL; p->restype = NULL; p->setfunc = NULL; p->ffi_restype = NULL; for (i = 0; i < nArgs + 1; ++i) p->atypes[i] = NULL; PyObject_GC_Track((PyObject *)p); return p; }
PyObject *SibPair_New(PyObject *head, PyObject *tail) { // checked SibPair *self = NULL; if (! (head && tail)) { PyErr_SetString(PyExc_TypeError, "pair requires a head and a tail"); return NULL; } if (pair_free_list) { // printf("reusing existing SibPair, count=%i\n", pair_free_count); self = pair_free_list; pair_free_list = (SibPair *) SibPair_CDR(self); pair_free_count--; Py_INCREF(self); } else { // printf("no spare SibPair, allocating fresh\n"); self = PyObject_GC_New(SibPair, &SibPairType); } self->position = NULL; Py_INCREF(head); self->head = head; Py_INCREF(tail); self->tail = tail; PyObject_GC_Track((PyObject *) self); return (PyObject *) self; }
static void __Pyx_Generator_dealloc(PyObject *self) { __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; PyObject_GC_UnTrack(gen); if (gen->gi_weakreflist != NULL) PyObject_ClearWeakRefs(self); if (gen->resume_label > 0) { // Generator is paused, so we need to close PyObject_GC_Track(self); #if PY_VERSION_HEX >= 0x030400a1 if (PyObject_CallFinalizerFromDealloc(self)) #else Py_TYPE(gen)->tp_del(self); if (self->ob_refcnt > 0) #endif { // resurrected. :( return; } PyObject_GC_UnTrack(self); } __Pyx_Generator_clear(self); PyObject_GC_Del(gen); }
PyObject * Repository_config__get__(Repository *self, void *closure) { int err; git_config *config; Config *py_config; assert(self->repo); if (self->config == NULL) { err = git_repository_config(&config, self->repo); if (err < 0) return Error_set(err); py_config = PyObject_GC_New(Config, &ConfigType); if (!py_config) { git_config_free(config); return NULL; } Py_INCREF(self); py_config->repo = self; py_config->config = config; PyObject_GC_Track(py_config); self->config = (PyObject*)py_config; } Py_INCREF(self->config); return self->config; }
PyObject * PyModule_NewObject(PyObject *name) { PyModuleObject *m; m = PyObject_GC_New(PyModuleObject, &PyModule_Type); if (m == NULL) return NULL; m->md_def = NULL; m->md_state = NULL; m->md_dict = PyDict_New(); if (m->md_dict == NULL) goto fail; if (PyDict_SetItemString(m->md_dict, "__name__", name) != 0) goto fail; if (PyDict_SetItemString(m->md_dict, "__doc__", Py_None) != 0) goto fail; if (PyDict_SetItemString(m->md_dict, "__package__", Py_None) != 0) goto fail; PyObject_GC_Track(m); return (PyObject *)m; fail: Py_DECREF(m); return NULL; }
PyObject * Repository_index__get__(Repository *self, void *closure) { int err; git_index *index; Index *py_index; assert(self->repo); if (self->index == NULL) { err = git_repository_index(&index, self->repo); if (err < 0) return Error_set(err); py_index = PyObject_GC_New(Index, &IndexType); if (!py_index) { git_index_free(index); return NULL; } Py_INCREF(self); py_index->repo = self; py_index->index = index; PyObject_GC_Track(py_index); self->index = (PyObject*)py_index; } Py_INCREF(self->index); return self->index; }
static PyObject * slpmodule_new(char *name) { PySlpModuleObject *m; PyObject *nameobj; m = PyObject_GC_New(PySlpModuleObject, PySlpModule_TypePtr); if (m == NULL) return NULL; m->__channel__ = NULL; m->__tasklet__ = NULL; nameobj = PyString_FromString(name); m->md_dict = PyDict_New(); if (m->md_dict == NULL || nameobj == NULL) goto fail; if (PyDict_SetItemString(m->md_dict, "__name__", nameobj) != 0) goto fail; if (PyDict_SetItemString(m->md_dict, "__doc__", Py_None) != 0) goto fail; Py_DECREF(nameobj); PyObject_GC_Track(m); return (PyObject *)m; fail: Py_XDECREF(nameobj); Py_DECREF(m); return NULL; }
/** * pygi_resulttuple_new: * @subclass: A PyGIResultTuple_Type subclass which will be the type of the * returned instance. * @len: Length of the returned tuple * * Like PyTuple_New(). Return an uninitialized tuple of the given @length. * * Returns: An instance of @subclass or %NULL on error. */ PyObject * pygi_resulttuple_new(PyTypeObject *subclass, Py_ssize_t len) { PyObject *self; Py_ssize_t i; /* Check the free list for a tuple object with the needed size; * clear it and change the class to ours. */ if (len > 0 && len < PyGIResultTuple_MAXSAVESIZE) { self = free_list[len]; if (self != NULL) { free_list[len] = PyTuple_GET_ITEM (self, 0); numfree[len]--; for (i=0; i < len; i++) { PyTuple_SET_ITEM (self, i, NULL); } Py_TYPE (self) = subclass; Py_INCREF (subclass); _Py_NewReference (self); PyObject_GC_Track (self); return self; } } /* For zero length tuples and in case the free list is empty, alloc * as usual. */ return subclass->tp_alloc (subclass, len); }
PyObject * PyModule_New(char *name) { PyModuleObject *m; PyObject *nameobj; m = PyObject_GC_New(PyModuleObject, &PyModule_Type); if (m == NULL) return NULL; nameobj = PyString_FromString(name); m->md_dict = PyDict_New(); if (m->md_dict == NULL || nameobj == NULL) goto fail; if (PyDict_SetItemString(m->md_dict, "__name__", nameobj) != 0) goto fail; if (PyDict_SetItemString(m->md_dict, "__doc__", Py_None) != 0) goto fail; Py_DECREF(nameobj); PyObject_GC_Track(m); return (PyObject *)m; fail: Py_XDECREF(nameobj); Py_DECREF(m); return NULL; }
/* * Factory */ static PyObject * PyMemorySimpleView_FromObject(PyObject *base) { PyMemorySimpleViewObject *mview = NULL; Py_buffer view; if (Py_TYPE(base)->tp_as_buffer == NULL || Py_TYPE(base)->tp_as_buffer->bf_getbuffer == NULL) { PyErr_SetString(PyExc_TypeError, "cannot make memory view because object does " "not have the buffer interface"); return NULL; } memset(&view, 0, sizeof(Py_buffer)); if (PyObject_GetBuffer(base, &view, PyBUF_FULL_RO) < 0) return NULL; mview = (PyMemorySimpleViewObject *) PyObject_GC_New(PyMemorySimpleViewObject, &PyMemorySimpleView_Type); if (mview == NULL) { PyBuffer_Release(&view); return NULL; } memcpy(&mview->view, &view, sizeof(Py_buffer)); mview->base = base; Py_INCREF(base); PyObject_GC_Track(mview); return (PyObject *)mview; }
PyObject *Example_FromExample(PyTypeObject *type, PExample example, POrange lock) { TPyExample *self=PyObject_GC_New(TPyExample, type); self->example.init(); self->lock.init(); self->example = example; self->lock = lock; PyObject_GC_Track(self); return (PyObject *)self; }
/** Create a new parameter collection object. */ ParamsObject *Params_New(LPXObject *py_lp) { ParamsObject *p = (ParamsObject*)PyObject_GC_New(ParamsObject, &ParamsType); if (p==NULL) return p; Py_INCREF(py_lp); p->py_lp = py_lp; p->weakreflist = NULL; PyObject_GC_Track(p); return p; }
static PyWeakReference * new_weakref(PyObject *ob, PyObject *callback) { PyWeakReference *result; result = PyObject_GC_New(PyWeakReference, &_PyWeakref_RefType); if (result) { init_weakref(result, ob, callback); PyObject_GC_Track(result); } return result; }
PyDocumentFragmentObject *DocumentFragment_New(PyDocumentObject *ownerDocument) { PyDocumentFragmentObject *self; self = Node_NewContainer(PyDocumentFragmentObject, &DomletteDocumentFragment_Type, ownerDocument); PyObject_GC_Track(self); return self; }
static PyObject * add_regex(SymbolObject *self, PyObject *args) { PyObject *charset; int min, max, line_no; void *newobj; if (self->type != SYM_TYPE_REGEX) { PyErr_Format(PyExc_RuntimeError, "Expecting regex symbol in add_regex(), got type %d for symbol %s (L%d)", self->type, self->name, self->line_no); return NULL; } if (!PyArg_ParseTuple(args, "Siii", &charset, &min, &max, &line_no)) { PyObject *unicode; PyErr_Clear(); if (!PyArg_ParseTuple(args, "Uiii", &unicode, &min, &max, &line_no)) return NULL; charset = PyUnicode_AsEncodedString(unicode, "utf-8", "strict"); if (!charset) return NULL; } else { Py_INCREF(charset); } PyObject_GC_UnTrack(self); self->data.regex.n_parts++; newobj = realloc(self->data.regex.parts, self->data.regex.n_parts * sizeof(regex_pt_t)); if (!newobj) { self->data.regex.n_parts--; PyObject_GC_Track(self); Py_DECREF(charset); PyErr_NoMemory(); return NULL; } self->data.regex.parts = (regex_pt_t *)newobj; self->data.regex.parts[self->data.regex.n_parts-1].charset = charset; self->data.regex.parts[self->data.regex.n_parts-1].min_count = min; self->data.regex.parts[self->data.regex.n_parts-1].max_count = max; PyObject_GC_Track(self); ODBGN(D_PRS, " \\(%s regex) [%s]{%d,%d}\n", self->name, PyBytes_AS_STRING(charset), min, max); Py_RETURN_NONE; }
PyObject *newEulerObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype) { EulerObject *self= (EulerObject *)newEulerObject(NULL, order, Py_NEW, NULL); if(self) { Py_INCREF(cb_user); self->cb_user= cb_user; self->cb_type= (unsigned char)cb_type; self->cb_subtype= (unsigned char)cb_subtype; PyObject_GC_Track(self); } return (PyObject *)self; }
/* Allocates memory for a new node object of the given type and initializes * part of it. */ NodeObject *_Node_New(PyTypeObject *type) { const size_t size = _PyObject_SIZE(type); PyObject *obj = _PyObject_GC_Malloc(size); if (obj == NULL) PyErr_NoMemory(); else { memset(obj, '\0', size); PyObject_INIT(obj, type); PyObject_GC_Track(obj); } return (NodeObject *)obj; }
static btsort_pyobject * copy_tree(btsort_pyobject *tree) { btsort_pyobject *result = PyObject_GC_New( btsort_pyobject, &btsort_pytypeobj); PyObject_GC_Track(result); result->order = tree->order; result->depth = tree->depth; result->flags = 0; result->root = copy_node(tree->root, 0, tree->depth, tree->order); result->flags = BT_FLAG_INITED; return result; }
static PyWeakReference * new_weakref(PyObject *ob, PyObject *callback) { PyWeakReference *result; // Pyston change: We can't use PyObject_GC_New because it will conservatively scan the memory. // result = PyObject_GC_New(PyWeakReference, &_PyWeakref_RefType); result = (PyWeakReference*)_PyWeakref_RefType.tp_alloc(&_PyWeakref_RefType, 0); if (result) { init_weakref(result, ob, callback); PyObject_GC_Track(result); } return result; }
PyObject *Quaternion_CreatePyObject_cb(PyObject *cb_user, unsigned char cb_type, unsigned char cb_subtype) { QuaternionObject *self = (QuaternionObject *)Quaternion_CreatePyObject(NULL, Py_NEW, NULL); if (self) { Py_INCREF(cb_user); self->cb_user = cb_user; self->cb_type = cb_type; self->cb_subtype = cb_subtype; PyObject_GC_Track(self); } return (PyObject *)self; }
PyObject *Euler_CreatePyObject_cb(PyObject *cb_user, const short order, unsigned char cb_type, unsigned char cb_subtype) { EulerObject *self = (EulerObject *)Euler_CreatePyObject(NULL, order, Py_NEW, NULL); if (self) { Py_INCREF(cb_user); self->cb_user = cb_user; self->cb_type = cb_type; self->cb_subtype = cb_subtype; PyObject_GC_Track(self); } return (PyObject *)self; }
/* * Constructor for Connection objects * * Arguments: ctx - An SSL Context to use for this connection * sock - The socket to use for transport layer * Returns: The newly created Connection object */ ssl_ConnectionObj * ssl_Connection_New(ssl_ContextObj *ctx, PyObject *sock) { ssl_ConnectionObj *self; self = PyObject_GC_New(ssl_ConnectionObj, &ssl_Connection_Type); if (self == NULL) { return NULL; } self = ssl_Connection_init(self, ctx, sock); if (self == NULL) { return NULL; } PyObject_GC_Track((PyObject *)self); return self; }
static PyObject *ffi_new_handle(FFIObject *self, PyObject *arg) { CDataObject *cd; cd = (CDataObject *)PyObject_GC_New(CDataObject, &CDataOwningGC_Type); if (cd == NULL) return NULL; Py_INCREF(g_ct_voidp); // <ctype 'void *'> cd->c_type = g_ct_voidp; Py_INCREF(arg); cd->c_data = ((char *)arg) - 42; cd->c_weakreflist = NULL; PyObject_GC_Track(cd); return (PyObject *)cd; }
static DeepinLunarObject *m_init_deepin_lunar_object() { DeepinLunarObject *self = NULL; self = (DeepinLunarObject *) PyObject_GC_New(DeepinLunarObject, m_DeepinLunar_Type); if (!self) return NULL; PyObject_GC_Track(self); self->dict = NULL; self->handle = NULL; return self; }