def test_unicode_identifiers(source): """Test unicode function/variable names.""" delayed_skip_if_unsupported("Unicode identifiers", gcc=(10, ), tcc=False, pcc=False, clang=(3, 3), pgcc=False) slug = CSlug(anchor(name()), source) slug.make() assert slug.dll.㟐(5) == 4
from cslug import CSlug, anchor slug = CSlug(anchor("person.c")) slug.make()
def test_string_count_make(): slug = CSlug(DEMOS / "strings" / "strings-demo.c") slug.make() global string_count string_count = slug
def test_remake(): from cslug._stdlib import dlclose, null_free_dll, stdlib assert dlclose is not null_free_dll, \ "A `dlclose()` function hasn't been found for this platform. It "\ "should be added to `_cslug._stdlib.py`." slug = CSlug(anchor(name(), RESOURCES / "basic.c")) path = slug.dll._name # Having the DLL open should block writing to it on Windows. ref = ctypes.CDLL(path) try: slug.make() except exceptions.LibraryOpenElsewhereError as ex: # This will happen only on Windows. assert path in str(ex) if platform.system() == "FreeBSD": # dlclose() seems to complain no matter what I do with it. stdlib.dlerror.restype = ctypes.c_char_p # This fails with an unhelpful b"Service unavailable". # assert dlclose(ctypes.c_void_p(ref._handle)) == 0, stdlib.dlerror() # dlclosing is mainly for Windows, which causes Permission errors if # you forget it. As far as I know, this issue is harmless. else: assert dlclose(ctypes.c_void_p(ref._handle)) == 0 # With the DLL closed make() should work. slug.make() # Each slug gets registered in `_slug_refs`. Check that this has happened. # `slug` should be the only one registered under this filename. from cslug._cslug import _slug_refs assert slug.path in _slug_refs assert len(_slug_refs[slug.path]) == 1 assert _slug_refs[slug.path][0]() is slug # Create another slug with the same filename. It should join the 1st in the # register. other = CSlug(slug.name, *slug.sources) assert other.path == slug.path assert len(_slug_refs[slug.path]) == 2 assert _slug_refs[slug.path][1]() is other # Get `other` to open its DLL. other_dll = other.dll assert other_dll.add_1(2) == 3 # Make `slug` try to rebuild the DLL which is already opened by `other`. # This would normally cause mayhem but doesn't because `slug.make()` # implicitly calls`other.close()` so that it doesn't try to overwrite an # open file. slug.make() # `other.dll` should re-open automatically. assert other.dll is not other_dll # `other` is weakref-ed and should still be garbage-collectable despite # being in `_slug_refs`. del other_dll, other # Test the link in `_slug_refs` is dead. assert _slug_refs[slug.path][1]() is None # `_slug_refs` should be cleared of dead links on calling `close()`. slug.close() assert len(_slug_refs[slug.path]) == 1