Do some string library work

This commit is contained in:
Justine Tunney 2022-08-20 21:36:07 -07:00
parent 83d41e4588
commit 35203c0551
42 changed files with 1381 additions and 136 deletions

View file

@ -664,7 +664,7 @@ Py_GetProgramFullPath(void)
{
static bool once;
if (_cmpxchg(&once, false, true)) {
progpath = utf8toutf32(GetProgramExecutableName(), -1, 0);
progpath = utf8to32(GetProgramExecutableName(), -1, 0);
__cxa_atexit(free, progpath, 0);
}
return progpath;

View file

@ -3399,7 +3399,7 @@ os__getfinalpathname_impl(PyObject *module, PyObject *path)
int result_length;
PyObject *result;
if (!(path_utf8 = PyUnicode_AsUTF8String(path))) return 0;
path_utf16 = gc(utf8toutf16(PyBytes_AS_STRING(path_utf8), PyBytes_GET_SIZE(path_utf8), 0));
path_utf16 = gc(utf8to16(PyBytes_AS_STRING(path_utf8), PyBytes_GET_SIZE(path_utf8), 0));
Py_DECREF(path_utf8);
if (!path_utf16) return PyErr_NoMemory();
Py_BEGIN_ALLOW_THREADS
@ -3439,7 +3439,7 @@ os__getfinalpathname_impl(PyObject *module, PyObject *path)
buf_size = result_length;
target_path = tmp;
}
final8 = gc(utf16toutf8(target_path, result_length, &final8z));
final8 = gc(utf16to8(target_path, result_length, &final8z));
result = PyUnicode_FromStringAndSize(final8, final8z);
cleanup:
if (target_path != buf) {
@ -3537,7 +3537,7 @@ os__getvolumepathname_impl(PyObject *module, PyObject *path)
size_t buflen;
bool32 ret;
if (!(path_utf8 = PyUnicode_AsUTF8String(path))) return 0;
path_utf16 = gc(utf8toutf16(PyBytes_AS_STRING(path_utf8), PyBytes_GET_SIZE(path_utf8), &buflen));
path_utf16 = gc(utf8to16(PyBytes_AS_STRING(path_utf8), PyBytes_GET_SIZE(path_utf8), &buflen));
Py_DECREF(path_utf8);
if (!path_utf16) return PyErr_NoMemory();
buflen += 1;
@ -3554,7 +3554,7 @@ os__getvolumepathname_impl(PyObject *module, PyObject *path)
Py_SAFE_DOWNCAST(buflen, size_t, uint32_t));
Py_END_ALLOW_THREADS
if (ret) {
mountpath8 = gc(utf16toutf8(mountpath, -1, &buflen));
mountpath8 = gc(utf16to8(mountpath, -1, &buflen));
result = PyUnicode_FromStringAndSize(mountpath8, buflen);
} else {
result = win32_error_object("_getvolumepathname", path);

View file

@ -12,9 +12,9 @@
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/locale.h"
#include "libc/sysv/consts/exit.h"
#include "libc/sysv/consts/s.h"
#include "libc/str/locale.h"
#include "libc/x/x.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/boolobject.h"
@ -1044,7 +1044,7 @@ sys_getwindowsversion(PyObject *self)
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwMinorVersion));
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwBuildNumber));
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwPlatformId));
PyStructSequence_SET_ITEM(version, pos++, PyUnicode_FromString(gc(utf16toutf8(ver.szCSDVersion,-1,0))));
PyStructSequence_SET_ITEM(version, pos++, PyUnicode_FromString(gc(utf16to8(ver.szCSDVersion,-1,0))));
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wServicePackMajor));
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wServicePackMinor));
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wSuiteMask));

View file

@ -125,7 +125,7 @@ main(int argc, char *argv[])
Py_LimitedPath();
if (!(a = PyList_New(argc))) return 127;
for (i = 0; i < argc; ++i) {
if (!(w = utf8toutf32(argv[i], -1, &n))) return 126;
if (!(w = utf8to32(argv[i], -1, &n))) return 126;
if (!(s = PyUnicode_FromWideChar(w, n))) return 125;
PyList_SetItem(a, i, s);
free(w);

View file

@ -17,11 +17,11 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/stat.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/bits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/runtime/gc.internal.h"
@ -125,7 +125,7 @@ main(int argc, char *argv[])
Py_IgnoreEnvironmentFlag++;
Py_FrozenFlag++;
/* Py_VerboseFlag++; */
Py_SetProgramName(gc(utf8toutf32(argv[0], -1, 0)));
Py_SetProgramName(gc(utf8to32(argv[0], -1, 0)));
_Py_InitializeEx_Private(1, 0);
name = gc(xjoinpaths("/zip/.python", StripComponents(inpath, 3)));
code = Py_CompileStringExFlags(p, name, Py_file_input, NULL, optimize);