rlib/test/test_rlocale.py::test_libintl
def test_libintl():
if sys.platform != "darwin" and not sys.platform.startswith("linux"):
py.test.skip("there is (maybe) no libintl here")
_gettext = external('gettext', [rffi.CCHARP], rffi.CCHARP)
p = rffi.str2charp("1234")
> res = _gettext(p)
rlib/test/test_rlocale.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
rtyper/lltypesystem/rffi.py:321: in wrapper
res = call_external_function(*real_args)
rtyper/lltypesystem/lltype.py:1384: in __call__
return callb(*args)
rtyper/lltypesystem/ll2ctypes.py:1339: in __call__
self.natural_arity)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
funcptr = <* fn gettext>, calling_conv = 'c', natural_arity = -1
def get_ctypes_callable(funcptr, calling_conv, natural_arity):
if not ctypes:
raise ImportError("ctypes is needed to use ll2ctypes")
def get_on_lib(lib, elem):
""" Wrapper to always use lib[func] instead of lib.func
"""
try:
return lib[elem]
except AttributeError:
pass
old_eci = funcptr._obj.compilation_info
funcname = funcptr._obj._name
if hasattr(old_eci, '_with_ctypes'):
old_eci = old_eci._with_ctypes
try:
eci = _eci_cache[old_eci]
except KeyError:
eci = old_eci.compile_shared_lib(ignore_a_files=True,
defines=['RPYTHON_LL2CTYPES'],
symbolic=True)
_eci_cache[old_eci] = eci
libraries = eci.testonly_libraries + eci.libraries + eci.frameworks
FUNCTYPE = lltype.typeOf(funcptr).TO
cfunc = None
if libraries:
not_found = []
for libname in libraries:
libpath = None
ext = platform.so_ext
prefixes = platform.so_prefixes
for dir in eci.library_dirs:
if libpath:
break
for prefix in prefixes:
tryfile = os.path.join(dir, prefix + libname + '.' + ext)
if os.path.isfile(tryfile):
libpath = tryfile
break
if not libpath:
libpath = ctypes.util.find_library(libname)
if not libpath:
libpath = _findLib_gcc_fallback(libname)
if not libpath and os.path.isabs(libname):
libpath = libname
if libpath:
dllclass = getattr(ctypes, calling_conv + 'dll')
# on ie slackware there was need for RTLD_GLOBAL here.
# this breaks a lot of things, since passing RTLD_GLOBAL
# creates symbol conflicts on C level.
clib = dllclass._dlltype(libpath, **load_library_kwargs)
cfunc = get_on_lib(clib, funcname)
if cfunc is not None:
break
else:
not_found.append(libname)
if cfunc is None:
if _FREEBSD and funcname in ('dlopen', 'fdlopen', 'dlsym', 'dlfunc', 'dlerror', 'dlclose'):
cfunc = rtld_default_lib[funcname]
else:
cfunc = get_on_lib(standard_c_lib, funcname)
# XXX magic: on Windows try to load the function from 'kernel32' too
if cfunc is None and hasattr(ctypes, 'windll'):
cfunc = get_on_lib(ctypes.windll.kernel32, funcname)
if cfunc is None and hasattr(ctypes, 'windll'):
cfunc = get_on_lib(ctypes.cdll.msvcrt, funcname)
if cfunc is None:
# function name not found in any of the libraries
if not libraries:
place = 'the standard C library (missing libraries=...?)'
elif len(not_found) == len(libraries):
if len(not_found) == 1:
raise NotImplementedError(
'cannot find the library %r' % (not_found[0],))
else:
raise NotImplementedError(
'cannot find any of the libraries %r' % (not_found,))
elif len(libraries) == 1:
place = 'library %r' % (libraries[0],)
else:
place = 'any of the libraries %r' % (libraries,)
if not_found:
place += ' (did not find %r)' % (not_found,)
raise NotImplementedError("function %r not found in %s" % (
> funcname, place))
E NotImplementedError: function 'gettext' not found in the standard C library (missing libraries=...?)
rtyper/lltypesystem/ll2ctypes.py:1304: NotImplementedError
(somefailed=True in rlib/test/test_rlocale.py)
builder: rpython-macos-x86-64 build #272
test: rlib/test/test_rlocale/py/test_libintl