Example #1
0
NUITKA_MAY_BE_UNUSED static bool BINARY_OPERATION_MUL_INPLACE( PyObject **operand1, PyObject *operand2 )
{
    assert( operand1 );
    CHECK_OBJECT( *operand1 );
    CHECK_OBJECT( operand2 );

    if ( Py_REFCNT( *operand1 ) == 1 )
    {
        if ( PyFloat_CheckExact( *operand1 ) &&
             PyFloat_CheckExact( operand2 ) )
        {
            return FLOAT_MUL_INCREMENTAL( operand1, operand2 );

        }
    }

    PyObject *result = PyNumber_InPlaceMultiply( *operand1, operand2 );

    if (unlikely( result == NULL ))
    {
        return false;
    }

    // We got an object handed, that we have to release.
    Py_DECREF( *operand1 );

    // That's our return value then. As we use a dedicated variable, it's
    // OK that way.
    *operand1 = result;

    return true;
}
Example #2
0
static PyObject *
BBox__mul__(PyObject *a, PyObject *b)
{
    PlanarBBoxObject *box;
    PlanarAffineObject *t;
	PyObject *p, *p_xform;
	int rectilinear;
    double ta, tb, tc, td, te, tf;
	planar_vec2_t p0, p1;

    if (PlanarBBox_Check(a) && PlanarAffine_Check(b)) {
		box = (PlanarBBoxObject *)a;
		t = (PlanarAffineObject *)b;
    } else if (PlanarBBox_Check(b) && PlanarAffine_Check(a)) {
		box = (PlanarBBoxObject *)b;
		t = (PlanarAffineObject *)a;
    } else {
		/* We support only transform operations */
		Py_INCREF(Py_NotImplemented);
		return Py_NotImplemented;
    }
    ta = t->a;
    tb = t->b;
    tc = t->c;
    td = t->d;
    te = t->e;
    tf = t->f;

	rectilinear = ((almost_eq(ta, 0.0) && almost_eq(te, 0.0))
        || (almost_eq(td, 0.0) && almost_eq(tb, 0.0)));
	if (rectilinear) {
		p0.x = box->min.x*ta + box->min.y*td + tc;
		p0.y = box->min.x*tb + box->min.y*te + tf;
		p1.x = box->max.x*ta + box->max.y*td + tc;
		p1.y = box->max.x*tb + box->max.y*te + tf;
		box = (PlanarBBoxObject *)BBox_alloc(Py_TYPE(box), 0);
		if (box != NULL) {
			box->min.x = MIN(p0.x, p1.x);
			box->min.y = MIN(p0.y, p1.y);
			box->max.x = MAX(p0.x, p1.x);
			box->max.y = MAX(p0.y, p1.y);
		}
		return (PyObject *)box;
	} else {
		p = (PyObject *)BBox_to_polygon(box);
		if (p == NULL) {
			return NULL;
		}
		p_xform = PyNumber_InPlaceMultiply(p, (PyObject *)t);
		Py_DECREF(p);
		return p_xform;
	}
}
static PyObject *Proxy_inplace_multiply(
        ProxyObject *self, PyObject *other)
{
    PyObject *object = NULL;

    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);

    object = PyNumber_InPlaceMultiply(self->wrapped, other);

    if (!object)
        return NULL;

    Py_DECREF(self->wrapped);
    self->wrapped = object;

    Py_INCREF(self);
    return (PyObject *)self;
}