コード例 #1
0
ファイル: convert.c プロジェクト: KaneVanguard/pyparted
_ped_Constraint *PedConstraint2_ped_Constraint(PedConstraint *constraint) {
    _ped_Constraint *ret = NULL;
    _ped_Alignment *start_align = NULL;
    _ped_Alignment *end_align = NULL;
    _ped_Geometry *start_range = NULL;
    _ped_Geometry *end_range = NULL;
    PyObject *args = NULL;

    if (constraint == NULL) {
        PyErr_SetString(PyExc_TypeError, "Empty PedConstraint()");
        return NULL;
    }

    ret = (_ped_Constraint *) _ped_Constraint_Type_obj.tp_new(&_ped_Constraint_Type_obj, NULL, NULL);
    if (!ret)
        return (_ped_Constraint *) PyErr_NoMemory();

    if ((start_align = PedAlignment2_ped_Alignment(constraint->start_align)) == NULL)
        goto error;

    if ((end_align = PedAlignment2_ped_Alignment(constraint->end_align)) == NULL)
        goto error;

    if ((start_range = PedGeometry2_ped_Geometry(constraint->start_range)) == NULL)
        goto error;

    if ((end_range = PedGeometry2_ped_Geometry(constraint->end_range)) == NULL)
        goto error;

    args = Py_BuildValue("OOOOLL", start_align, end_align, start_range, end_range, constraint->min_size, constraint->max_size);
    if (args == NULL) {
        goto error;
    }

    if (_ped_Constraint_Type_obj.tp_init((PyObject *) ret, args, NULL)) {
        goto error;
    }

    Py_DECREF(args);
    Py_DECREF(start_align);
    Py_DECREF(end_align);
    Py_DECREF(start_range);
    Py_DECREF(end_range);

    return ret;

error:
    Py_XDECREF(args);
    Py_XDECREF(start_align);
    Py_XDECREF(end_align);
    Py_XDECREF(start_range);
    Py_XDECREF(end_range);
    Py_DECREF(ret);
    return NULL;
}
コード例 #2
0
ファイル: pynatmath.c プロジェクト: axaxs/pyparted
/* 1:1 function mappings for natmath.h in libparted */
PyObject *py_ped_alignment_duplicate(PyObject *s, PyObject *args) {
    PedAlignment *alignment = NULL, *align = NULL;
    _ped_Alignment *ret = NULL;

    alignment = _ped_Alignment2PedAlignment(s);
    if (alignment == NULL) {
        return NULL;
    }

    align = ped_alignment_duplicate(alignment);

    ped_alignment_destroy(alignment);

    if (align) {
        ret = PedAlignment2_ped_Alignment(align);
    }
    else {
        PyErr_SetString(CreateException, "Could not duplicate alignment");
        return NULL;
    }

    ped_alignment_destroy(align);

    return (PyObject *) ret;
}
コード例 #3
0
ファイル: pydevice.c プロジェクト: rhinstaller/pyparted
PyObject *py_ped_device_get_optimum_alignment(PyObject *s, PyObject *args) {
    PedDevice *device = NULL;
    PedAlignment *alignment = NULL;
    _ped_Alignment *ret = NULL;

    device = _ped_Device2PedDevice(s);
    if (device == NULL) {
        return NULL;
    }

    alignment = ped_device_get_optimum_alignment(device);
    if (!alignment) {
        PyErr_SetString(CreateException, "Could not get alignment for device");
        return NULL;
    }

    ret = PedAlignment2_ped_Alignment(alignment);
    ped_alignment_destroy(alignment);

    return (PyObject *) ret;
}
コード例 #4
0
ファイル: pynatmath.c プロジェクト: axaxs/pyparted
PyObject *py_ped_alignment_intersect(PyObject *s, PyObject *args) {
    PyObject *in_b = NULL;
    PedAlignment *out_a = NULL, *out_b = NULL, *align = NULL;
    _ped_Alignment *ret = NULL;

    if (!PyArg_ParseTuple(args, "O!", &_ped_Alignment_Type_obj, &in_b)) {
        return NULL;
    }

    out_a = _ped_Alignment2PedAlignment(s);
    if (out_a == NULL) {
        return NULL;
    }

    out_b = _ped_Alignment2PedAlignment(in_b);
    if (out_b == NULL) {
        return NULL;
    }

    align = ped_alignment_intersect(out_a, out_b);

    ped_alignment_destroy(out_a);
    ped_alignment_destroy(out_b);

    if (align) {
        ret = PedAlignment2_ped_Alignment(align);
    }
    else {
        PyErr_SetString(PyExc_ArithmeticError, "Could not find alignment intersection");
        return NULL;
    }

    ped_alignment_destroy(align);

    return (PyObject *) ret;
}