Exemplo n.º 1
0
    def __init__(self, space, pto):
        bases_w = space.fixedview(from_ref(space, pto.c_tp_bases))
        dict_w = {}

        add_operators(space, dict_w, pto)
        convert_method_defs(space, dict_w, pto.c_tp_methods, self)
        convert_getset_defs(space, dict_w, pto.c_tp_getset, self)
        convert_member_defs(space, dict_w, pto.c_tp_members, self)

        name = rffi.charp2str(pto.c_tp_name)
        flag_heaptype = pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE
        if flag_heaptype:
            minsize = rffi.sizeof(PyHeapTypeObject.TO)
        else:
            minsize = rffi.sizeof(PyObject.TO)
        new_layout = (pto.c_tp_basicsize > minsize or pto.c_tp_itemsize > 0)

        W_TypeObject.__init__(self, space, name,
            bases_w or [space.w_object], dict_w, force_new_layout=new_layout,
            is_heaptype=flag_heaptype)
        self.flag_cpytype = True
        # if a sequence or a mapping, then set the flag to force it
        if pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_item:
            self.flag_map_or_seq = 'S'
        elif (pto.c_tp_as_mapping and pto.c_tp_as_mapping.c_mp_subscript and
              not (pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_slice)):
            self.flag_map_or_seq = 'M'
        if pto.c_tp_doc:
            self.w_doc = space.wrap(rffi.charp2str(pto.c_tp_doc))
Exemplo n.º 2
0
    def __init__(self, space, pto):
        bases_w = space.fixedview(from_ref(space, pto.c_tp_bases))
        dict_w = {}

        add_operators(space, dict_w, pto)
        convert_method_defs(space, dict_w, pto.c_tp_methods, self)
        convert_getset_defs(space, dict_w, pto.c_tp_getset, self)
        convert_member_defs(space, dict_w, pto.c_tp_members, self)

        name = rffi.charp2str(cts.cast('char*', pto.c_tp_name))
        flag_heaptype = pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE
        if flag_heaptype:
            minsize = rffi.sizeof(PyHeapTypeObject.TO)
        else:
            minsize = rffi.sizeof(PyObject.TO)
        new_layout = (pto.c_tp_basicsize > minsize or pto.c_tp_itemsize > 0)

        W_TypeObject.__init__(self, space, name,
            bases_w or [space.w_object], dict_w, force_new_layout=new_layout,
            is_heaptype=flag_heaptype)
        self.flag_cpytype = True
        # if a sequence or a mapping, then set the flag to force it
        if pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_item:
            self.flag_map_or_seq = 'S'
        elif (pto.c_tp_as_mapping and pto.c_tp_as_mapping.c_mp_subscript and
              not (pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_slice)):
            self.flag_map_or_seq = 'M'
        if pto.c_tp_doc:
            self.w_doc = space.newtext(
                rffi.charp2str(cts.cast('char*', pto.c_tp_doc)))
Exemplo n.º 3
0
def attach_legacy_methods(space, pymethods, w_obj, modname=None):
    """
    pymethods is passed as a void*, but it is expected to be a PyMethodDef[].
    Wrap its items into the proper cpyext.W_*Function objects, and attach them
    to w_obj (which can be either a module or a type).
    """
    pymethods = cpyts.cast('PyMethodDef*', pymethods)
    dict_w = {}
    convert_method_defs(space, dict_w, pymethods, None, w_obj, modname)
    for key, w_func in dict_w.items():
        space.setattr(w_obj, space.newtext(key), w_func)
Exemplo n.º 4
0
    def __init__(self, space, pto):
        bases_w = space.fixedview(from_ref(space, pto.c_tp_bases))
        dict_w = {}

        add_operators(space, dict_w, pto)
        convert_method_defs(space, dict_w, pto.c_tp_methods, self)
        convert_getset_defs(space, dict_w, pto.c_tp_getset, self)
        convert_member_defs(space, dict_w, pto.c_tp_members, self)

        name = rffi.charp2str(pto.c_tp_name)

        W_TypeObject.__init__(self, space, name, bases_w or [space.w_object], dict_w)
        if not space.is_true(space.issubtype(self, space.w_type)):
            self.flag_cpytype = True
        self.flag_heaptype = False
        if pto.c_tp_doc:
            self.w_doc = space.wrap(rffi.charp2str(pto.c_tp_doc))
Exemplo n.º 5
0
    def __init__(self, space, pto):
        bases_w = space.fixedview(from_ref(space, pto.c_tp_bases))
        dict_w = {}

        add_operators(space, dict_w, pto)
        convert_method_defs(space, dict_w, pto.c_tp_methods, self)
        convert_getset_defs(space, dict_w, pto.c_tp_getset, self)
        convert_member_defs(space, dict_w, pto.c_tp_members, self)

        name = rffi.charp2str(pto.c_tp_name)

        W_TypeObject.__init__(self, space, name, bases_w or [space.w_object],
                              dict_w)
        if not space.is_true(space.issubtype(self, space.w_type)):
            self.flag_cpytype = True
        self.flag_heaptype = False
        if pto.c_tp_doc:
            self.w_doc = space.wrap(rffi.charp2str(pto.c_tp_doc))
Exemplo n.º 6
0
    def __init__(self, space, pto):
        bases_w = space.fixedview(from_ref(space, pto.c_tp_bases))
        dict_w = {}

        add_operators(space, dict_w, pto)
        convert_method_defs(space, dict_w, pto.c_tp_methods, self)
        convert_getset_defs(space, dict_w, pto.c_tp_getset, self)
        convert_member_defs(space, dict_w, pto.c_tp_members, self)

        full_name = rffi.charp2str(pto.c_tp_name)
        if '.' in full_name:
            module_name, extension_name = rsplit(full_name, ".", 1)
            dict_w["__module__"] = space.wrap(module_name)
        else:
            extension_name = full_name

        W_TypeObject.__init__(self, space, extension_name,
            bases_w or [space.w_object], dict_w)
        if not space.is_true(space.issubtype(self, space.w_type)):
            self.flag_cpytype = True
        self.flag_heaptype = False
Exemplo n.º 7
0
    def __init__(self, space, pto):
        bases_w = space.fixedview(from_ref(space, pto.c_tp_bases))
        dict_w = {}

        add_operators(space, dict_w, pto)
        convert_method_defs(space, dict_w, pto.c_tp_methods, self)
        convert_getset_defs(space, dict_w, pto.c_tp_getset, self)
        convert_member_defs(space, dict_w, pto.c_tp_members, self)

        full_name = rffi.charp2str(pto.c_tp_name)
        if '.' in full_name:
            module_name, extension_name = rsplit(full_name, ".", 1)
            dict_w["__module__"] = space.wrap(module_name)
        else:
            extension_name = full_name

        W_TypeObject.__init__(self, space, extension_name,
            bases_w or [space.w_object], dict_w)
        if not space.is_true(space.issubtype(self, space.w_type)):
            self.flag_cpytype = True
        self.flag_heaptype = False
        if pto.c_tp_doc:
            self.w_doc = space.wrap(rffi.charp2str(pto.c_tp_doc))
Exemplo n.º 8
0
    def __init__(self, space, pto):
        bases_w = space.fixedview(from_ref(space, pto.c_tp_bases))
        dict_w = {}

        name = rffi.charp2str(cts.cast('char*', pto.c_tp_name))
        add_operators(space, self, dict_w, pto, name)
        convert_method_defs(space, dict_w, pto.c_tp_methods, self)
        convert_getset_defs(space, dict_w, pto.c_tp_getset, self)
        convert_member_defs(space, dict_w, pto.c_tp_members, self)

        w_dict = from_ref(space, pto.c_tp_dict)
        if w_dict is not None:
            dictkeys_w = space.listview(w_dict)
            for w_key in dictkeys_w:
                key = space.text_w(w_key)
                dict_w[key] = space.getitem(w_dict, w_key)

        flag_heaptype = pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE
        if flag_heaptype:
            minsize = rffi.sizeof(PyHeapTypeObject.TO)
        else:
            minsize = rffi.sizeof(PyObject.TO)
        new_layout = (pto.c_tp_basicsize > minsize or pto.c_tp_itemsize > 0)

        self.flag_cpytype = True
        W_TypeObject.__init__(self, space, name,
            bases_w or [space.w_object], dict_w, force_new_layout=new_layout,
            is_heaptype=flag_heaptype)
        # if a sequence or a mapping, then set the flag to force it
        if pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_item:
            self.flag_map_or_seq = 'S'
        elif pto.c_tp_as_mapping and pto.c_tp_as_mapping.c_mp_subscript:
            self.flag_map_or_seq = 'M'
        if pto.c_tp_doc:
            rawdoc = rffi.charp2str(cts.cast('char*', pto.c_tp_doc))
            self.w_doc = space.newtext_or_none(extract_doc(rawdoc, name))
            self.text_signature = extract_txtsig(rawdoc, name)