This is on top of #1648.
Update emscripten to 2.0.27. This is on top of #1648.
From d9b55121e5e0671efaa850096d3f816cee18479a Mon Sep 17 00:00:00 2001
From: Hood <hood@mit.edu>
Date: Wed, 23 Jun 2021 13:47:30 -0700
Subject: [PATCH 06/10] Don't dereference function pointer

Ctypes thinks that the result of dlsym is a pointer to the function pointer, so
it should call it like `result = (*f)(args)`. Probably this is true for the
native dlsym, but our dlsym returns an index into the indirect call table
"wasmTable", in particular it isn't even aligned like a pointer should be.
This patch fixes it so that it calls it like `result = f(args)` instead.
---
 Modules/_ctypes/_ctypes.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 5f8a723f63..379aa8a7d5 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -778,7 +778,11 @@ CDataType_in_dll(PyObject *type, PyObject *args)
         return NULL;
     }
 #endif
-    return PyCData_AtAddress(type, address);
+    CDataObject *ob = (CDataObject *)GenericPyCData_new(type, NULL, NULL);
+    if (ob == NULL)
+        return NULL;
+    *(void **)ob->b_ptr = address;
+    return (PyObject*)ob;
 }
 
 static const char from_param_doc[] =
-- 
2.25.1


From d9b55121e5e0671efaa850096d3f816cee18479a Mon Sep 17 00:00:00 2001
From: Hood <hood@mit.edu>
Date: Wed, 23 Jun 2021 13:47:30 -0700
Subject: [PATCH 06/10] Don't dereference function pointer

Ctypes thinks that the result of dlsym is a pointer to the function pointer, so
it should call it like `result = (*f)(args)`. Probably this is true for the
native dlsym, but our dlsym returns an index into the indirect call table
"wasmTable", in particular it isn't even aligned like a pointer should be.
This patch fixes it so that it calls it like `result = f(args)` instead.
---
 Modules/_ctypes/_ctypes.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 5f8a723f63..379aa8a7d5 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -778,7 +778,11 @@ CDataType_in_dll(PyObject *type, PyObject *args)
         return NULL;
     }
 #endif
-    return PyCData_AtAddress(type, address);
+    CDataObject *ob = (CDataObject *)GenericPyCData_new(type, NULL, NULL);
+    if (ob == NULL)
+        return NULL;
+    *(void **)ob->b_ptr = address;
+    return (PyObject*)ob;
 }
 
 static const char from_param_doc[] =
-- 
2.25.1

