@@ -1421,8 +1421,9 @@ _set_encodings_path(PyObject *mod) {
1421
1421
goto exit ;
1422
1422
}
1423
1423
const PyConfig * config = _Py_GetConfig ();
1424
- /* standard stdlib dir */
1425
1424
if (config -> stdlib_dir != NULL ) {
1425
+ // standard library directory
1426
+
1426
1427
// os.path.join(stdlib_dir, "encodings")
1427
1428
wchar_t * encodings_dirw = _Py_join_relfile (
1428
1429
config -> stdlib_dir , L"encodings" );
@@ -1438,9 +1439,8 @@ _set_encodings_path(PyObject *mod) {
1438
1439
if (PyList_Append (path , encodings_dir ) < 0 ) {
1439
1440
goto exit ;
1440
1441
}
1441
- }
1442
- // Additional search paths, required for embedding
1443
- if (config -> module_search_paths_set ) {
1442
+ } else if (config -> module_search_paths_set ) {
1443
+ // No stdlib_dir, search module_search paths
1444
1444
for (Py_ssize_t i = 0 ; i < config -> module_search_paths .length ; ++ i ) {
1445
1445
wchar_t * encodings_dirw = _Py_join_relfile (
1446
1446
config -> module_search_paths .items [i ], L"encodings" );
@@ -1470,14 +1470,15 @@ _set_encodings_path(PyObject *mod) {
1470
1470
}
1471
1471
}
1472
1472
}
1473
- // set and override __path__
1474
- if (PyObject_SetAttrString (mod , "__path__" , path ) < 0 ) {
1475
- goto exit ;
1473
+ if (PyObject_IsTrue (path )) {
1474
+ // set and override __path__
1475
+ if (PyObject_SetAttrString (mod , "__path__" , path ) < 0 ) {
1476
+ goto exit ;
1477
+ }
1476
1478
}
1477
1479
rc = 0 ;
1478
1480
exit :
1479
1481
Py_XDECREF (path );
1480
-
1481
1482
return rc ;
1482
1483
}
1483
1484
0 commit comments