Exemple #1
0
def _create_pyc_function_object(space, method, w_self, w_name, flags):
    flags &= ~(METH_CLASS | METH_STATIC | METH_COEXIST)
    if flags == METH_NOARGS:
        return W_PyCFunctionObjectNoArgs(space, method, w_self, w_name)
    if flags == METH_O:
        return W_PyCFunctionObjectSingleObject(space, method, w_self, w_name)
    return W_PyCFunctionObject(space, method, w_self, w_name)
Exemple #2
0
def convert_method_defs(space, dict_w, methods, w_type, w_self=None, name=None):
    w_name = space.wrap(name)
    methods = rffi.cast(rffi.CArrayPtr(PyMethodDef), methods)
    if methods:
        i = -1
        while True:
            i = i + 1
            method = methods[i]
            if not method.c_ml_name: break

            methodname = rffi.charp2str(method.c_ml_name)
            flags = rffi.cast(lltype.Signed, method.c_ml_flags)

            if w_type is None:
                if flags & METH_CLASS or flags & METH_STATIC:
                    raise OperationError(space.w_ValueError,
                            space.wrap("module functions cannot set METH_CLASS or METH_STATIC"))
                w_obj = space.wrap(W_PyCFunctionObject(space, method, w_self, w_name))
            else:
                if methodname in dict_w and not (flags & METH_COEXIST):
                    continue
                if flags & METH_CLASS:
                    if flags & METH_STATIC:
                        raise OperationError(space.w_ValueError,
                                space.wrap("method cannot be both class and static"))
                    w_obj = PyDescr_NewClassMethod(space, w_type, method)
                elif flags & METH_STATIC:
                    w_func = PyCFunction_NewEx(space, method, None, None)
                    w_obj = PyStaticMethod_New(space, w_func)
                else:
                    w_obj = PyDescr_NewMethod(space, w_type, method)

            dict_w[methodname] = w_obj