These are chat archives for dropbox/pyston

30th
Jul 2015
Sun
@Daetalus
Jul 30 2015 03:51

Hi, I'm add a coerce to builtin.cpp. Here is the code:

// Modified from CPython
Box* coerceFunc(Box* self, Box* args)
{
    PyObject *v, *w;
    Box* res;

    if (PyErr_WarnPy3k("coerce() not supported in 3.x", 1) < 0)
        return NULL;

    if (!PyArg_UnpackTuple(args, "coerce", 2, 2, &v, &w))
        return NULL;
    if (PyNumber_Coerce(&v, &w) < 0)
        throwCAPIException();
    res = PyTuple_Pack(2, v, w);
    Py_DECREF(v);
    Py_DECREF(w);
    return res;
}

    builtins_module->giveAttr("coerce",
                              new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)coerceFunc, UNKNOWN, 2), "coerce"));

But when I call it. Pyston report an error:

pyston_dbg: ../../src/runtime/objmodel.cpp:3839: pyston::Box *pyston::callCLFunc(...) [S = 1]: Assertion `S == CAPI' failed.

Any tips?

Kevin Modzelewski
@kmod
Jul 30 2015 07:37
ah ok assertion doesn't give the best error message
basically it's saying that you returned NULL from a pyston-style function
but returning NULL is only allowed from capi-style functions
Sun
@Daetalus
Jul 30 2015 07:38
Got it...
Thanks!
Kevin Modzelewski
@kmod
Jul 30 2015 07:38
probably instead of return NULL you should have throwCAPIException()
Sun
@Daetalus
Jul 30 2015 07:52
This message was deleted

Speaking of coercion, there's a few coercion behavior that we don't support at the moment if you're interested. Like Int + Complex or Float + Complex

But I can't find coerce support in int or float, in CPython, they called by tp_as_number->nb_coerce

Kevin Modzelewski
@kmod
Jul 30 2015 08:43
oh, yeah I think this is what the CHECKTYPES flag is for
if that's not set (the old behavior) then the runtime would call the coercion function
I think it's fine to just add those to the methods directly instead of trying to match the old behavior
but who knows we might run into something that relies on it :)
Sun
@Daetalus
Jul 30 2015 08:58
Hi, I opened a PR #787, if it pass the CI, please give your suggestion if you have time.
And I don't complete understand your last message for now. But I will chew it.
Sun
@Daetalus
Jul 30 2015 09:32
Thanks!
Kevin Modzelewski
@kmod
Jul 30 2015 09:32
I think that class-level flag specifies whether you want the old (nb_coerce) or new (function itself does the checking) behavior
my understanding of this is pretty spotty though