File: test_ztranslation.py

package info (click to toggle)
pypy3 7.3.11%2Bdfsg-2%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 201,024 kB
  • sloc: python: 1,950,308; ansic: 517,580; sh: 21,417; asm: 14,419; cpp: 4,263; makefile: 4,228; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 11; awk: 4
file content (62 lines) | stat: -rw-r--r-- 2,762 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pytest
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.translator.c.test.test_standalone import StandaloneTests
from rpython.config.translationoption import get_combined_translation_config
from pypy.config.pypyoption import get_pypy_config
from pypy.objspace.std.typeobject import W_TypeObject
from pypy.objspace.fake.checkmodule import checkmodule
from pypy.objspace.fake.objspace import FakeObjSpace
from pypy.module._hpy_universal.state import State
from pypy.module.cpyext.api import cts as cpyts


def attach_dict_strategy(space):
    # this is needed for modules which do e.g. "isinstance(w_obj,
    # W_DictMultiObject)", like _hpy_universal. Make sure that the
    # annotator sees a concrete class, like W_DictObject, else lots of
    # operations are blocked.
    from pypy.objspace.std.dictmultiobject import W_DictObject, ObjectDictStrategy
    strategy = ObjectDictStrategy(space)
    storage = strategy.get_empty_storage()
    w_obj = W_DictObject(space, strategy, storage)

def make_cpyext_struct():
    # create a dummy Sturct which includes the eci from CpyextTypeSpace: this
    # way, we convince the translator to include the proper .h files, which
    # are needed to complete the C compilation because
    # e.g. attach_legacy_slots_to_type needs to dereference PyType_Slot.
    #
    # NOTE: that these are not the headers which are used in the real
    # translation: structs like PyType_Slot are defined by Python.h, which we
    # do NOT include here. By using cts.build_eci() we are including the
    # headers in cpyext/parse/, which are good enough to make C compilation
    # succeeding.
    eci = cpyts.build_eci()
    return lltype.Struct('DUMMY_CPYEXT_STRUCT', hints={'eci': eci})


@pytest.mark.dont_track_allocations()
def test_checkmodule():
    DUMMY_CPYEXT_STRUCT = make_cpyext_struct()
    def extra_func(space):
        from pypy.objspace.std.unicodeobject import W_UnicodeObject
        state = State.get(space)
        state.setup(space)
        attach_dict_strategy(space)
        p = lltype.malloc(DUMMY_CPYEXT_STRUCT, flavor='raw')
        lltype.free(p, flavor='raw')
        W_TypeObject(space, 'foo', [], {}).hasmro = False
        W_UnicodeObject("abc", 3) # unfortunately needed

    rpython_opts = {'translation.gc': 'boehm'}
    # it isn't possible to ztranslate cpyext easily, so we check _hpy_universal
    # WITHOUT the cpyext parts
    pypy_opts = {'objspace.std.withliststrategies': False,
                 'objspace.hpy_cpyext_API': False}
    checkmodule('_hpy_universal',
                extra_func=extra_func,
                c_compile=True,
                rpython_opts=rpython_opts,
                pypy_opts=pypy_opts,
                show_pdbplus=False,
                )