3737 */
3838
3939#include "py_nif.h"
40- #include "py_asgi.h"
41- #include "py_wsgi.h"
4240#include "py_event_loop.h"
4341#include "py_channel.h"
4442#include "py_buffer.h"
@@ -290,8 +288,6 @@ static int is_inline_schedule_marker(PyObject *obj);
290288#include "py_callback.c"
291289#include "py_thread_worker.c"
292290#include "py_event_loop.c"
293- #include "py_asgi.c"
294- #include "py_wsgi.c"
295291#include "py_worker_pool.h"
296292#include "py_worker_pool.c"
297293#include "py_subinterp_pool.c"
@@ -1168,20 +1164,6 @@ static ERL_NIF_TERM nif_py_init(ErlNifEnv *env, int argc, const ERL_NIF_TERM arg
11681164 return make_error (env , "event_loop_module_creation_failed" );
11691165 }
11701166
1171- /* Initialize ASGI scope key cache for optimized marshalling */
1172- if (asgi_scope_init () < 0 ) {
1173- Py_Finalize ();
1174- atomic_store (& g_runtime_state , PY_STATE_STOPPED );
1175- return make_error (env , "asgi_scope_init_failed" );
1176- }
1177-
1178- /* Initialize WSGI scope key cache for optimized marshalling */
1179- if (wsgi_scope_init () < 0 ) {
1180- Py_Finalize ();
1181- atomic_store (& g_runtime_state , PY_STATE_STOPPED );
1182- return make_error (env , "wsgi_scope_init_failed" );
1183- }
1184-
11851167 /* Initialize ReactorBuffer Python type for zero-copy read handling */
11861168 if (ReactorBuffer_init_type () < 0 ) {
11871169 Py_Finalize ();
@@ -1416,9 +1398,6 @@ static ERL_NIF_TERM nif_finalize(ErlNifEnv *env, int argc, const ERL_NIF_TERM ar
14161398 if (g_main_thread_state != NULL ) {
14171399 PyEval_RestoreThread (g_main_thread_state );
14181400
1419- asgi_scope_cleanup ();
1420- wsgi_scope_cleanup ();
1421-
14221401 /* Clean up numpy type cache */
14231402 Py_XDECREF (g_numpy_ndarray_type );
14241403 g_numpy_ndarray_type = NULL ;
@@ -1431,8 +1410,6 @@ static ERL_NIF_TERM nif_finalize(ErlNifEnv *env, int argc, const ERL_NIF_TERM ar
14311410 } else {
14321411 /* Fallback to PyGILState if no main thread state saved */
14331412 PyGILState_STATE gstate = PyGILState_Ensure ();
1434- asgi_scope_cleanup ();
1435- wsgi_scope_cleanup ();
14361413 Py_XDECREF (g_numpy_ndarray_type );
14371414 g_numpy_ndarray_type = NULL ;
14381415#ifdef HAVE_SUBINTERPRETERS
@@ -2353,124 +2330,6 @@ static ERL_NIF_TERM nif_parallel_execute(ErlNifEnv *env, int argc, const ERL_NIF
23532330 return enif_make_tuple2 (env , ATOM_OK , result_list );
23542331}
23552332
2356- /**
2357- * @brief Run an ASGI application in a subinterpreter
2358- *
2359- * Args: WorkerRef, Runner, Module, Callable, ScopeMap, Body
2360- *
2361- * This runs ASGI in a subinterpreter with its own GIL for true parallelism.
2362- */
2363- static ERL_NIF_TERM nif_subinterp_asgi_run (ErlNifEnv * env , int argc , const ERL_NIF_TERM argv []) {
2364- if (argc < 6 ) {
2365- return make_error (env , "badarg" );
2366- }
2367-
2368- py_subinterp_worker_t * worker ;
2369- if (!enif_get_resource (env , argv [0 ], SUBINTERP_WORKER_RESOURCE_TYPE , (void * * )& worker )) {
2370- return make_error (env , "invalid_worker" );
2371- }
2372-
2373- ErlNifBinary runner_bin , module_bin , callable_bin , body_bin ;
2374- if (!enif_inspect_binary (env , argv [1 ], & runner_bin )) {
2375- return make_error (env , "invalid_runner" );
2376- }
2377- if (!enif_inspect_binary (env , argv [2 ], & module_bin )) {
2378- return make_error (env , "invalid_module" );
2379- }
2380- if (!enif_inspect_binary (env , argv [3 ], & callable_bin )) {
2381- return make_error (env , "invalid_callable" );
2382- }
2383- if (!enif_inspect_binary (env , argv [5 ], & body_bin )) {
2384- return make_error (env , "invalid_body" );
2385- }
2386-
2387- /* Lock mutex for thread-safe access */
2388- pthread_mutex_lock (& worker -> mutex );
2389-
2390- /* Enter the sub-interpreter with proper GIL acquisition (safe for OWN_GIL) */
2391- PyEval_RestoreThread (worker -> tstate );
2392-
2393- char * runner_name = binary_to_string (& runner_bin );
2394- char * module_name = binary_to_string (& module_bin );
2395- char * callable_name = binary_to_string (& callable_bin );
2396- if (runner_name == NULL || module_name == NULL || callable_name == NULL ) {
2397- enif_free (runner_name );
2398- enif_free (module_name );
2399- enif_free (callable_name );
2400- PyEval_SaveThread ();
2401- pthread_mutex_unlock (& worker -> mutex );
2402- return make_error (env , "alloc_failed" );
2403- }
2404-
2405- ERL_NIF_TERM result ;
2406-
2407- /* Build scope dict from Erlang map */
2408- PyObject * scope = asgi_scope_from_map (env , argv [4 ]);
2409- if (scope == NULL ) {
2410- result = make_py_error (env );
2411- goto cleanup ;
2412- }
2413-
2414- /* Convert body binary to Python bytes */
2415- PyObject * body = PyBytes_FromStringAndSize ((const char * )body_bin .data , body_bin .size );
2416- if (body == NULL ) {
2417- Py_DECREF (scope );
2418- result = make_py_error (env );
2419- goto cleanup ;
2420- }
2421-
2422- /* Import the ASGI runner module */
2423- PyObject * runner_module = PyImport_ImportModule (runner_name );
2424- if (runner_module == NULL ) {
2425- Py_DECREF (body );
2426- Py_DECREF (scope );
2427- result = make_py_error (env );
2428- goto cleanup ;
2429- }
2430-
2431- /* Call _run_asgi_sync(module_name, callable_name, scope, body)
2432- * or run_asgi(module_name, callable_name, scope, body) depending on runner */
2433- PyObject * run_result = PyObject_CallMethod (
2434- runner_module , "run_asgi" , "ssOO" ,
2435- module_name , callable_name , scope , body );
2436-
2437- /* Fallback to _run_asgi_sync if run_asgi doesn't exist */
2438- if (run_result == NULL && PyErr_ExceptionMatches (PyExc_AttributeError )) {
2439- PyErr_Clear ();
2440- run_result = PyObject_CallMethod (
2441- runner_module , "_run_asgi_sync" , "ssOO" ,
2442- module_name , callable_name , scope , body );
2443- }
2444-
2445- Py_DECREF (runner_module );
2446- Py_DECREF (body );
2447- Py_DECREF (scope );
2448-
2449- if (run_result == NULL ) {
2450- result = make_py_error (env );
2451- goto cleanup ;
2452- }
2453-
2454- /* Convert result to Erlang term using optimized extraction */
2455- ERL_NIF_TERM term_result = extract_asgi_response (env , run_result );
2456- Py_DECREF (run_result );
2457-
2458- result = enif_make_tuple2 (env , ATOM_OK , term_result );
2459-
2460- cleanup :
2461- enif_free (runner_name );
2462- enif_free (module_name );
2463- enif_free (callable_name );
2464-
2465- /* Exit the sub-interpreter with proper GIL release (safe for OWN_GIL) */
2466- PyEval_SaveThread ();
2467-
2468- /* Unlock mutex */
2469- pthread_mutex_unlock (& worker -> mutex );
2470-
2471- return result ;
2472- }
2473-
24742333#else /* !HAVE_SUBINTERPRETERS */
24752334
24762335/* Stub implementations for older Python versions */
@@ -2498,12 +2357,6 @@ static ERL_NIF_TERM nif_parallel_execute(ErlNifEnv *env, int argc, const ERL_NIF
24982357 return make_error (env , "subinterpreters_not_supported" );
24992358}
25002359
2501- static ERL_NIF_TERM nif_subinterp_asgi_run (ErlNifEnv * env , int argc , const ERL_NIF_TERM argv []) {
2502- (void )argc ;
2503- (void )argv ;
2504- return make_error (env , "subinterpreters_not_supported" );
2505- }
2506-
25072360#endif /* HAVE_SUBINTERPRETERS */
25082361
25092362/* ============================================================================
@@ -7381,22 +7234,9 @@ static int load(ErlNifEnv *env, void **priv_data, ERL_NIF_TERM load_info) {
73817234 ATOM_SPAN_END = enif_make_atom (env , "span_end" );
73827235 ATOM_SPAN_EVENT = enif_make_atom (env , "span_event" );
73837236
7384- /* ASGI scope atoms */
7385- ATOM_ASGI_PATH = enif_make_atom (env , "path" );
7386- ATOM_ASGI_HEADERS = enif_make_atom (env , "headers" );
7387- ATOM_ASGI_CLIENT = enif_make_atom (env , "client" );
7388- ATOM_ASGI_QUERY_STRING = enif_make_atom (env , "query_string" );
7389- ATOM_ASGI_METHOD = enif_make_atom (env , "method" );
7390-
73917237 /* Worker pool atoms */
73927238 pool_atoms_init (env );
73937239
7394- /* ASGI buffer resource type for zero-copy body handling */
7395- ASGI_BUFFER_RESOURCE_TYPE = enif_open_resource_type (
7396- env , NULL , "asgi_buffer" ,
7397- asgi_buffer_resource_dtor ,
7398- ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER , NULL );
7399-
74007240 /* Reactor buffer resource type for zero-copy read handling */
74017241 REACTOR_BUFFER_RESOURCE_TYPE = enif_open_resource_type (
74027242 env , NULL , "reactor_buffer" ,
@@ -7514,7 +7354,6 @@ static ErlNifFunc nif_funcs[] = {
75147354 {"subinterp_worker_destroy" , 1 , nif_subinterp_worker_destroy , 0 },
75157355 {"subinterp_call" , 5 , nif_subinterp_call , ERL_NIF_DIRTY_JOB_CPU_BOUND },
75167356 {"parallel_execute" , 2 , nif_parallel_execute , ERL_NIF_DIRTY_JOB_CPU_BOUND },
7517- {"subinterp_asgi_run" , 6 , nif_subinterp_asgi_run , ERL_NIF_DIRTY_JOB_CPU_BOUND },
75187357
75197358 /* OWN_GIL subinterpreter thread pool (true parallelism) */
75207359 {"subinterp_thread_pool_start" , 0 , nif_subinterp_thread_pool_start , 0 },
@@ -7623,17 +7462,6 @@ static ErlNifFunc nif_funcs[] = {
76237462 {"set_isolation_mode" , 1 , nif_set_isolation_mode , 0 },
76247463 {"set_shared_worker" , 1 , nif_set_shared_worker , 0 },
76257464
7626- /* ASGI optimizations */
7627- {"asgi_build_scope" , 1 , nif_asgi_build_scope , ERL_NIF_DIRTY_JOB_IO_BOUND },
7628- {"asgi_run" , 5 , nif_asgi_run , ERL_NIF_DIRTY_JOB_IO_BOUND },
7629- #ifdef ASGI_PROFILING
7630- {"asgi_profile_stats" , 0 , nif_asgi_profile_stats , 0 },
7631- {"asgi_profile_reset" , 0 , nif_asgi_profile_reset , 0 },
7632- #endif
7633-
7634- /* WSGI optimizations */
7635- {"wsgi_run" , 4 , nif_wsgi_run , ERL_NIF_DIRTY_JOB_IO_BOUND },
7636-
76377465 /* Worker pool */
76387466 {"pool_start" , 1 , nif_pool_start , 0 },
76397467 {"pool_stop" , 0 , nif_pool_stop , 0 },
0 commit comments