@@ -502,6 +502,45 @@ getpath_realpath(PyObject *Py_UNUSED(self) , PyObject *args)
502
502
PyMem_Free ((void * )path );
503
503
PyMem_Free ((void * )narrow );
504
504
return r ;
505
+ #elif defined(MS_WINDOWS )
506
+ HANDLE hFile ;
507
+ wchar_t resolved [MAXPATHLEN + 1 ];
508
+ int len = 0 , err ;
509
+ PyObject * result ;
510
+
511
+ wchar_t * path = PyUnicode_AsWideCharString (pathobj , NULL );
512
+ if (!path ) {
513
+ return NULL ;
514
+ }
515
+
516
+ Py_BEGIN_ALLOW_THREADS
517
+ hFile = CreateFileW (path , 0 , 0 , NULL , OPEN_EXISTING , FILE_FLAG_BACKUP_SEMANTICS , NULL );
518
+ if (hFile != INVALID_HANDLE_VALUE ) {
519
+ len = GetFinalPathNameByHandleW (hFile , resolved , MAXPATHLEN , VOLUME_NAME_DOS );
520
+ err = len ? 0 : GetLastError ();
521
+ CloseHandle (hFile );
522
+ } else {
523
+ err = GetLastError ();
524
+ }
525
+ Py_END_ALLOW_THREADS
526
+
527
+ if (err ) {
528
+ return PyErr_SetFromWindowsErr (GetLastError ());
529
+ }
530
+ if (len <= MAXPATHLEN ) {
531
+ const wchar_t * p = resolved ;
532
+ if (0 == wcsncmp (p , L"\\\\?\\" , 4 )) {
533
+ if (GetFileAttributesW (& p [4 ]) != INVALID_FILE_ATTRIBUTES ) {
534
+ p += 4 ;
535
+ len -= 4 ;
536
+ }
537
+ }
538
+ result = PyUnicode_FromWideChar (p , len );
539
+ } else {
540
+ result = Py_NewRef (pathobj );
541
+ }
542
+ PyMem_Free (path );
543
+ return result ;
505
544
#endif
506
545
507
546
return Py_NewRef (pathobj );
@@ -898,7 +937,7 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
898
937
!library_to_dict (dict , "library" ) ||
899
938
!wchar_to_dict (dict , "executable_dir" , NULL ) ||
900
939
!wchar_to_dict (dict , "py_setpath" , _PyPathConfig_GetGlobalModuleSearchPath ()) ||
901
- !funcs_to_dict (dict , 1 ) || // config->pathconfig_warnings) ||
940
+ !funcs_to_dict (dict , config -> pathconfig_warnings ) ||
902
941
#ifndef MS_WINDOWS
903
942
PyDict_SetItemString (dict , "winreg" , Py_None ) < 0 ||
904
943
#endif
0 commit comments