/* * This function returns a NEW reference, i.e. caller must decref it in the end. * Should do the same as JyNI_AllocVar with nitems == -1. */ inline PyObject* JyNI_Alloc(TypeMapEntry* tme) { size_t size = (tme->flags & JY_TRUNCATE_FLAG_MASK) ? sizeof(PyObject)+tme->truncate_trailing : _PyObject_SIZE(tme->py_type); ALLOC_FULL(size, tme->flags, tme, tme->py_type) /* We cannot use PyType_Check here, because obj->ob_type might not be fully * initialized and not yet recognized as a Type-subclass. * (e.g. <type 'java.lang.Class'> from Jython-side can cause problems here) */ if (tme == &builtinTypes[TME_INDEX_Type]) ((PyTypeObject*) obj)->tp_flags |= Py_TPFLAGS_HEAPTYPE; //In contrast to var variant of this method, no decision needed here: PyObject_INIT(obj, tme->py_type); Py_TYPE(obj)->tp_flags |= Jy_TPFLAGS_DYN_OBJECTS; if (tme->py_type->tp_flags & Py_TPFLAGS_HEAPTYPE) Py_INCREF(tme->py_type); if (PyType_IS_GC(tme->py_type)) _JyNI_GC_TRACK(obj); return obj; }
PyObject * PyCell_New(PyObject *obj) { PyCellObject *op; op = (PyCellObject *)PyObject_GC_New(PyCellObject, &PyCell_Type); if (op == NULL) return NULL; op->ob_ref = obj; Py_XINCREF(obj); _JyNI_GC_TRACK(op); return (PyObject *)op; }
PyObject* JySync_Init_PyProperty_From_JyProperty(jobject src, PyTypeObject* nonNativeSubtype) { env(NULL); propertyobject* result = PyObject_GC_New(propertyobject, &PyProperty_Type); if (result != NULL) { result->prop_get = JyNI_PyObject_FromJythonPyObject( (*env)->GetObjectField(env, src, pyProperty_fgetField)); result->prop_set = JyNI_PyObject_FromJythonPyObject( (*env)->GetObjectField(env, src, pyProperty_fsetField)); result->prop_del = JyNI_PyObject_FromJythonPyObject( (*env)->GetObjectField(env, src, pyProperty_fdelField)); result->prop_doc = JyNI_PyObject_FromJythonPyObject( (*env)->GetObjectField(env, src, pyProperty_docField)); result->getter_doc = (*env)->GetBooleanField(env, src, pyProperty_docFromGetterField); _JyNI_GC_TRACK(result); } return (PyObject *) result; }
PyObject * PyTuple_New(register Py_ssize_t size) { register PyTupleObject *op; Py_ssize_t i; if (size < 0) { PyErr_BadInternalCall(); return NULL; } #if PyTuple_MAXSAVESIZE > 0 if (size == 0 && free_list[0]) { //jputs("EmptyTuple!"); //jputsLong(free_list[0]); op = free_list[0]; Py_INCREF(op); #ifdef COUNT_ALLOCS tuple_zero_allocs++; #endif return (PyObject *) op; } if (size < PyTuple_MAXSAVESIZE && (op = free_list[size]) != NULL) { free_list[size] = (PyTupleObject *) op->ob_item[0]; numfree[size]--; #ifdef COUNT_ALLOCS fast_tuple_allocs++; #endif /* Inline PyObject_InitVar */ #ifdef Py_TRACE_REFS Py_SIZE(op) = size; Py_TYPE(op) = &PyTuple_Type; #endif _PyObject_GC_InitJy(op, &(builtinTypes[TME_INDEX_Tuple])); _Py_NewReference((PyObject *)op); // jputs(__FUNCTION__); // jputsLong(__LINE__); // jputsLong(size); // jputsLong((jlong) op); //jputsLong(Py_TYPE(op)); //jputsLong(&PyTuple_Type); JyNIDebug(JY_NATIVE_ALLOC_GC | JY_INLINE_MASK, op, AS_JY_WITH_GC(op), size, PyTuple_Type.tp_name); } else #endif { Py_ssize_t nbytes = size * sizeof(PyObject *); /* Check for overflow */ if (nbytes / sizeof(PyObject *) != (size_t)size || (nbytes > PY_SSIZE_T_MAX - sizeof(PyTupleObject) - sizeof(PyObject *))) { return PyErr_NoMemory(); } op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size); if (op == NULL) return NULL; } for (i=0; i < size; i++) op->ob_item[i] = NULL; #if PyTuple_MAXSAVESIZE > 0 if (size == 0) { free_list[0] = op; ++numfree[0]; JyNIDebug(JY_NATIVE_INCREF | JY_IMMORTAL_MASK | JY_PRE_MASK, op, AS_JY_WITH_GC(op), size, PyTuple_Type.tp_name); Py_INCREF(op); /* extra INCREF so that this is never freed */ } #endif #ifdef SHOW_TRACK_COUNT count_tracked++; #endif //_JyNI_GC_TRACK_NoExplore(op); _JyNI_GC_TRACK(op); return (PyObject *) op; }