@@ -938,12 +938,19 @@ make_compiled_pathname(PyObject *pathstr, int debug)
938938 Py_ssize_t pycache_len = sizeof (CACHEDIR ) - 1 ;
939939 int kind ;
940940 void * data ;
941+ Py_UCS4 lastsep ;
941942
942943 /* Compute the output string size. */
943944 len = PyUnicode_GET_LENGTH (pathstr );
944945 /* If there is no separator, this returns -1, so
945- lastsep will be 0. */
946+ fname will be 0. */
946947 fname = rightmost_sep_obj (pathstr , 0 , len ) + 1 ;
948+ /* Windows: re-use the last separator character (/ or \\) when
949+ appending the __pycache__ path. */
950+ if (fname > 0 )
951+ lastsep = PyUnicode_READ_CHAR (pathstr , fname - 1 );
952+ else
953+ lastsep = SEP ;
947954 ext = fname - 1 ;
948955 for (i = fname ; i < len ; i ++ )
949956 if (PyUnicode_READ_CHAR (pathstr , i ) == '.' )
@@ -965,7 +972,7 @@ make_compiled_pathname(PyObject *pathstr, int debug)
965972 pos = fname ;
966973 for (i = 0 ; i < pycache_len ; i ++ )
967974 PyUnicode_WRITE (kind , data , pos ++ , CACHEDIR [i ]);
968- PyUnicode_WRITE (kind , data , pos ++ , SEP );
975+ PyUnicode_WRITE (kind , data , pos ++ , lastsep );
969976 PyUnicode_CopyCharacters (result , pos , pathstr ,
970977 fname , ext - fname );
971978 pos += ext - fname ;
0 commit comments