Help with asmmemmgr.py:_copy_to_raw_memory()

Hi, I'm trying to call a C function from the asmmemmgr.py:_copy_to_raw_memory() function now. I tried following an example for malloc() and used llexternal() to make the call work. Here is what I tried: from rpython.translator.tool.cbuild import ExternalCompilationInfo info = ExternalCompilationInfo(includes=["pthread.h"]) write_protect = rffi.llexternal("pthread_jit_write_protect_np", [lltype.Bool], lltype.Void) This results in this error: [translation:ERROR] Exception: A function calling locals() is not RPython. Note that if you're translating code outside the PyPy repository, a likely cause is that py.test's --assert=rewrite mode is getting in the way. You should copy the file pytest.ini from the root of the PyPy repository into your own project. What am I doing wrong?

Hi, On Tue, 19 Oct 2021 at 20:47, M A <teammember0x01@gmail.com> wrote:
[translation:ERROR] Exception: A function calling locals() is not RPython. Note that if you're translating code outside the PyPy repository, a likely cause is that py.test's --assert=rewrite mode is getting in the way. You should copy the file pytest.ini from the root of the PyPy repository into your own project.
Hard to know for sure, but maybe you've put these lines inside a function that is getting translated? Put them at module level instead. Also note that rffi.llexternal() probably needs an argument to tell it not to release the GIL. This is necessary in the backend because there are some assumptions that this code generation and patching is atomic. If you forget, you should get another clean error, though. In this case the safest is to say ``rffi.llexternal(..., _nowrapper=True)``. A bientôt, Armin.

Hi, On Tue, 19 Oct 2021 at 20:47, M A <teammember0x01@gmail.com> wrote:
[translation:ERROR] Exception: A function calling locals() is not RPython. Note that if you're translating code outside the PyPy repository, a likely cause is that py.test's --assert=rewrite mode is getting in the way. You should copy the file pytest.ini from the root of the PyPy repository into your own project.
Hard to know for sure, but maybe you've put these lines inside a function that is getting translated? Put them at module level instead. Also note that rffi.llexternal() probably needs an argument to tell it not to release the GIL. This is necessary in the backend because there are some assumptions that this code generation and patching is atomic. If you forget, you should get another clean error, though. In this case the safest is to say ``rffi.llexternal(..., _nowrapper=True)``. A bientôt, Armin.
participants (2)
-
Armin Rigo
-
M A