@@ -1038,14 +1038,21 @@ static void ffi_stamp_path(const char *python_exe, char *out, size_t n) {
10381038 snprintf (out , n , "%s/omnipkg/ffi_ok/%lu.stamp" , get_tmp_dir (), h );
10391039}
10401040
1041- static int ffi_stamp_exists (const char * python_exe ) {
1041+
1042+
1043+ static void ffi_stamp_write (const char * python_exe ) {
1044+ char dir1 [MAX_PATH ], dir2 [MAX_PATH ];
1045+ snprintf (dir1 , sizeof (dir1 ), "%s/omnipkg" , get_tmp_dir ());
1046+ snprintf (dir2 , sizeof (dir2 ), "%s/omnipkg/ffi_ok" , get_tmp_dir ());
1047+ mkdir_compat (dir1 , 0755 );
1048+ mkdir_compat (dir2 , 0755 );
10421049 char stamp [MAX_PATH ];
10431050 ffi_stamp_path (python_exe , stamp , sizeof (stamp ));
1044- struct stat st ;
1045- return stat ( stamp , & st ) == 0 ;
1051+ FILE * f = fopen ( stamp , "w" ) ;
1052+ if ( f ) { fputs ( python_exe , f ); fclose ( f ); }
10461053}
10471054
1048- static void ffi_stamp_write (const char * python_exe ) {
1055+ static void ffi_stamp_write_so (const char * python_exe , const char * so_path ) {
10491056 char dir1 [MAX_PATH ], dir2 [MAX_PATH ];
10501057 snprintf (dir1 , sizeof (dir1 ), "%s/omnipkg" , get_tmp_dir ());
10511058 snprintf (dir2 , sizeof (dir2 ), "%s/omnipkg/ffi_ok" , get_tmp_dir ());
@@ -1054,7 +1061,23 @@ static void ffi_stamp_write(const char *python_exe) {
10541061 char stamp [MAX_PATH ];
10551062 ffi_stamp_path (python_exe , stamp , sizeof (stamp ));
10561063 FILE * f = fopen (stamp , "w" );
1057- if (f ) { fputs (python_exe , f ); fclose (f ); }
1064+ if (f ) { fputs (so_path , f ); fclose (f ); }
1065+ }
1066+
1067+ static int ffi_stamp_exists (const char * python_exe ) {
1068+ char stamp [MAX_PATH ];
1069+ ffi_stamp_path (python_exe , stamp , sizeof (stamp ));
1070+ struct stat st ;
1071+ if (stat (stamp , & st ) != 0 ) return 0 ;
1072+ /* read the .so path recorded in the stamp and verify it still exists */
1073+ FILE * f = fopen (stamp , "r" );
1074+ if (!f ) return 0 ;
1075+ char so_path [MAX_PATH ] = {0 };
1076+ fgets (so_path , sizeof (so_path ), f );
1077+ fclose (f );
1078+ so_path [strcspn (so_path , "\n" )] = 0 ;
1079+ if (so_path [0 ] == '/' && stat (so_path , & st ) != 0 ) return 0 ;
1080+ return 1 ;
10581081}
10591082
10601083/*
@@ -1127,7 +1150,7 @@ static int ensure_uv_ffi_for_python(
11271150 }
11281151
11291152 if (debug ) fprintf (stderr , "[C-DISPATCH] uv_ffi installed for %s\n" , target_python );
1130- ffi_stamp_write ( target_python ); /* fast path on all future calls */
1153+ /* stamp written by find_or_install_uv_ffi_so with verified .so path */
11311154
11321155 /* Tell the daemon worker to reload its FFI handle for this interpreter.
11331156 * Fire-and-forget via daemon_connect (handles tcp:// on Windows, unix:// on POSIX). */
@@ -1195,6 +1218,7 @@ static int find_or_install_uv_ffi_so(
11951218 so_path_out [so_path_n - 1 ] = '\0' ;
11961219 pclose (_pp );
11971220 if (debug ) fprintf (stderr , "[C-DISPATCH] Found uv_ffi.so via Python: %s\n" , so_path_out );
1221+ ffi_stamp_write_so (target_python , so_path_out );
11981222 return 1 ;
11991223 }
12001224 }
@@ -1209,21 +1233,32 @@ static int find_or_install_uv_ffi_so(
12091233#ifdef _WIN32
12101234 if (!home ) home = getenv ("USERPROFILE" );
12111235#endif
1236+ /* derive target interpreter prefix for ABI-correct .so lookup */
1237+ char _target_prefix [MAX_PATH ] = {0 };
1238+ {
1239+ char _tp_cmd [MAX_PATH * 2 ];
1240+ snprintf (_tp_cmd , sizeof (_tp_cmd ),
1241+ "\"%s\" -c \"import sys; print(sys.prefix)\"" , target_python );
1242+ FILE * _tp_fp = popen (_tp_cmd , "r" );
1243+ if (_tp_fp ) { fgets (_target_prefix , sizeof (_target_prefix ), _tp_fp ); pclose (_tp_fp ); }
1244+ _target_prefix [strcspn (_target_prefix , "\n" )] = 0 ;
1245+ }
1246+ const char * _search_root = _target_prefix [0 ] ? _target_prefix : venv_root ;
12121247 /* standard installed: uv_ffi/_native/ */
12131248 snprintf (patterns [0 ], MAX_PATH ,
1214- "%s/lib/python3.*/site-packages/uv_ffi/_native/*.pyd" , venv_root );
1249+ "%s/lib/python3.*/site-packages/uv_ffi/_native/*.pyd" , _search_root );
12151250 snprintf (patterns [1 ], MAX_PATH ,
1216- "%s/lib/python3.*/site-packages/uv_ffi/_native/*.so" , venv_root );
1251+ "%s/lib/python3.*/site-packages/uv_ffi/_native/*.so" , _search_root );
12171252 /* flat install: uv_ffi/*.pyd / *.so */
12181253 snprintf (patterns [2 ], MAX_PATH ,
1219- "%s/lib/python3.*/site-packages/uv_ffi/*.pyd" , venv_root );
1254+ "%s/lib/python3.*/site-packages/uv_ffi/*.pyd" , _search_root );
12201255 snprintf (patterns [3 ], MAX_PATH ,
1221- "%s/lib/python3.*/site-packages/uv_ffi/*.so" , venv_root );
1256+ "%s/lib/python3.*/site-packages/uv_ffi/*.so" , _search_root );
12221257 /* dev/vendor install: omnipkg/_vendor/uv_ffi/ */
12231258 snprintf (patterns [4 ], MAX_PATH ,
1224- "%s/lib/python3.*/site-packages/omnipkg/_vendor/uv_ffi/*.pyd" , venv_root );
1259+ "%s/lib/python3.*/site-packages/omnipkg/_vendor/uv_ffi/*.pyd" , _search_root );
12251260 snprintf (patterns [5 ], MAX_PATH ,
1226- "%s/lib/python3.*/site-packages/omnipkg/_vendor/uv_ffi/*.so" , venv_root );
1261+ "%s/lib/python3.*/site-packages/omnipkg/_vendor/uv_ffi/*.so" , _search_root );
12271262 /* user local */
12281263 snprintf (patterns [6 ], MAX_PATH ,
12291264 "%s/.local/lib/python3.*/site-packages/uv_ffi/_native/*.pyd" ,
@@ -1239,6 +1274,7 @@ static int find_or_install_uv_ffi_so(
12391274 so_path_out [so_path_n - 1 ] = '\0' ;
12401275 globfree (& globbuf );
12411276 if (debug ) fprintf (stderr , "[C-DISPATCH] Found uv_ffi.so: %s\n" , so_path_out );
1277+ ffi_stamp_write_so (target_python , so_path_out );
12421278 return 1 ;
12431279 }
12441280 globfree (& globbuf );
@@ -1315,6 +1351,7 @@ static int find_or_install_uv_ffi_so(
13151351 so_path_out [so_path_n - 1 ] = '\0' ;
13161352 globfree (& globbuf );
13171353 if (debug ) fprintf (stderr , "[C-DISPATCH] uv_ffi.so post-install: %s\n" , so_path_out );
1354+ ffi_stamp_write_so (target_python , so_path_out );
13181355 return 1 ;
13191356 }
13201357 globfree (& globbuf );
@@ -1699,6 +1736,10 @@ int main(int argc, char **argv) {
16991736 if (is_foreign ) {
17001737 ensure_uv_ffi_for_python (target_python , venv_root ,
17011738 daemon_sock , debug );
1739+ /* locate and stamp the .so so future calls skip install check */
1740+ char _stamp_so [MAX_PATH ];
1741+ find_or_install_uv_ffi_so (venv_root , target_python ,
1742+ _stamp_so , sizeof (_stamp_so ));
17021743 }
17031744 }
17041745
0 commit comments