Exemple #1
0
/*
 * 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;
}
Exemple #2
0
PyObject *
_PyObject_GC_New(PyTypeObject *tp)
{
	PyObject *op = _PyObject_GC_Malloc(_PyObject_SIZE(tp));
	if (op != NULL)
		op = PyObject_INIT(op, tp);
	return op;
}
Exemple #3
0
static PyObject *
parser_sizeof(PyST_Object *st, void *unused)
{
    Py_ssize_t res;

    res = _PyObject_SIZE(Py_TYPE(st)) + _PyNode_SizeOf(st->st_node);
    return PyLong_FromSsize_t(res);
}
Exemple #4
0
PyObject *
_PyObject_New(PyTypeObject *tp)
{
	PyObject *op;
	op = (PyObject *) PyObject_MALLOC(_PyObject_SIZE(tp));
	if (op == NULL)
		return PyErr_NoMemory();
	return PyObject_INIT(op, tp);
}
Exemple #5
0
static PyObject *
mmap__sizeof__method(mmap_object *self, void *unused)
{
    Py_ssize_t res;

    res = _PyObject_SIZE(Py_TYPE(self));
    if (self->tagname)
        res += strlen(self->tagname) + 1;
    return PyLong_FromSsize_t(res);
}
static PyObject *
code_sizeof(PyCodeObject *co, void *unused)
{
    Py_ssize_t res;

    res = _PyObject_SIZE(Py_TYPE(co));
    if (co->co_cell2arg != NULL && co->co_cellvars != NULL)
        res += PyTuple_GET_SIZE(co->co_cellvars) * sizeof(unsigned char);
    return PyLong_FromSsize_t(res);
}
Exemple #7
0
/* 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;
}
Exemple #8
0
static PyObject *
code_sizeof(PyCodeObject *co, void *unused)
{
    Py_ssize_t res = _PyObject_SIZE(Py_TYPE(co));
    _PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra*) co->co_extra;

    if (co->co_cell2arg != NULL && co->co_cellvars != NULL) {
        res += PyTuple_GET_SIZE(co->co_cellvars) * sizeof(Py_ssize_t);
    }
    if (co_extra != NULL) {
        res += sizeof(_PyCodeObjectExtra) +
               (co_extra->ce_size-1) * sizeof(co_extra->ce_extras[0]);
    }
    return PyLong_FromSsize_t(res);
}