Actually initialize __main__.__loader__ with loader instances, not the corresponding type objects
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 970834e..8130cc5 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1355,11 +1355,15 @@
 {
     PyInterpreterState *interp;
     PyThreadState *tstate;
-    PyObject *loader;
+    PyObject *loader_type, *loader;
     /* Get current thread state and interpreter pointer */
     tstate = PyThreadState_GET();
     interp = tstate->interp;
-    loader = PyObject_GetAttrString(interp->importlib, loader_name);
+    loader_type = PyObject_GetAttrString(interp->importlib, loader_name);
+    if (loader_type == NULL) {
+        return -1;
+    }
+    loader = PyObject_CallFunction(loader_type, "ss", "__main__", filename);
     if (loader == NULL ||
         (PyDict_SetItemString(d, "__loader__", loader) < 0)) {
         return -1;