Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ae2e171
Add `null_embeddable`
nineteendo Apr 27, 2024
0625bf1
Add `make_wide`
nineteendo Apr 28, 2024
28b4b6e
📜🤖 Added by blurb_it.
blurb-it[bot] Apr 28, 2024
19209c6
Fix typo & add type casts
nineteendo Apr 28, 2024
7ca6036
Add test for fast paths
nineteendo Apr 28, 2024
55c1883
Build tuple faster
nineteendo Apr 29, 2024
a9b7bdd
Merge branch 'main' into generalize-path_t
nineteendo Apr 29, 2024
42b2ca1
Merge branch 'main' into generalize-path_t
nineteendo Apr 30, 2024
5b44245
Resolve merge conflicts
nineteendo Apr 30, 2024
1c93617
Support `make_wide=False` on Windows
nineteendo May 3, 2024
dc36f2e
Update generated code
nineteendo May 3, 2024
0a9d497
Add `suppress`
nineteendo May 4, 2024
14d711e
Fix `allow_fd`
nineteendo May 4, 2024
89e83fa
Allow paths of any length
nineteendo May 4, 2024
d6a174e
Update generated files
nineteendo May 4, 2024
4e8b713
Simplify bytes conversion
nineteendo May 4, 2024
0777a31
Remove leftovers
nineteendo May 4, 2024
46059d1
Update conditions to use `PyBytes_Check()`
nineteendo May 4, 2024
f95da67
Fix access violation attempt 1
nineteendo May 4, 2024
e8ab7d7
Fix segmentation fault
nineteendo May 4, 2024
3b21f5d
Fix segmentation fault attempt 2
nineteendo May 4, 2024
7b3a785
Fix access violation attempt 1
nineteendo May 4, 2024
a94c852
Clear ValueError
nineteendo May 4, 2024
5f717c9
Apply suggestions from code review
nineteendo May 4, 2024
b76774b
Same docstring for python fallback
nineteendo May 4, 2024
f2537a1
Revert newline
nineteendo May 4, 2024
aa0df5c
Merge branch 'main' into generalize-path_t
nineteendo May 22, 2024
8f67225
Merge branch 'main' into generalize-path_t
nineteendo May 22, 2024
360326d
Fix pointers
nineteendo May 22, 2024
3514bdb
Return false in case of value error
nineteendo May 22, 2024
e362054
Add null check
nineteendo May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow paths of any length
  • Loading branch information
nineteendo committed May 4, 2024
commit 89e83fac23549a182af33c70ff8b0ddce7796ea4
59 changes: 30 additions & 29 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1108,8 +1108,9 @@ get_posix_state(PyObject *module)
* Input fields:
* path.nullable
* If nonzero, the path is permitted to be None.
* path.null_embeddable
* If nonzero, the path is permitted to contain embedded null characters.
* path.nonstrict
* If nonzero, the path is permitted to contain
* embedded null characters and have any length.
* path.make_wide
* If nonzero, the path is decoded to Unicode, encoded to bytes otherwise.
Comment thread
nineteendo marked this conversation as resolved.
Outdated
* path.suppress
Expand Down Expand Up @@ -1180,7 +1181,7 @@ typedef struct {
const char *function_name;
const char *argument_name;
int nullable;
int null_embeddable;
int nonstrict;
int make_wide;
int suppress;
int allow_fd;
Expand All @@ -1194,20 +1195,20 @@ typedef struct {
PyObject *cleanup;
} path_t;

#define PATH_T_INITIALIZE(function_name, argument_name, nullable, \
null_embeddable, make_wide, suppress, allow_fd) \
{function_name, argument_name, nullable, null_embeddable, make_wide, \
suppress, allow_fd, NULL, NULL, -1, 0, 0, NULL, NULL}
#define PATH_T_INITIALIZE(function_name, argument_name, nullable, nonstrict, \
make_wide, suppress, allow_fd) \
{function_name, argument_name, nullable, nonstrict, make_wide, suppress, \
allow_fd, NULL, NULL, -1, 0, 0, NULL, NULL}
#ifdef MS_WINDOWS
#define PATH_T_INITIALIZE_P(function_name, argument_name, nullable, \
null_embeddable, suppress, allow_fd) \
PATH_T_INITIALIZE(function_name, argument_name, nullable, \
null_embeddable, 1, suppress, allow_fd)
nonstrict, suppress, allow_fd) \
PATH_T_INITIALIZE(function_name, argument_name, nullable, nonstrict, 1, \
suppress, allow_fd)
#else
#define PATH_T_INITIALIZE_P(function_name, argument_name, nullable, \
null_embeddable, suppress, allow_fd) \
PATH_T_INITIALIZE(function_name, argument_name, nullable, \
null_embeddable, 0, suppress, allow_fd)
nonstrict, suppress, allow_fd) \
PATH_T_INITIALIZE(function_name, argument_name, nullable, nonstrict, 0, \
suppress, allow_fd)
#endif

static void
Expand Down Expand Up @@ -1300,12 +1301,12 @@ path_converter(PyObject *o, void *p)
goto error_exit;
}
#ifdef MS_WINDOWS
if (length > 32767) {
if (!path->nonstrict && length > 32767) {
FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows");
goto error_exit;
}
#endif
if (!path->null_embeddable && wcslen(wide) != (size_t)length) {
if (!path->nonstrict && wcslen(wide) != (size_t)length) {
FORMAT_EXCEPTION(PyExc_ValueError,
"embedded null character in %s");
goto error_exit;
Expand All @@ -1317,7 +1318,7 @@ path_converter(PyObject *o, void *p)
wide = NULL;
goto success_exit;
}
if (!_PyUnicode_FSConverter(o, &bytes, path->null_embeddable)) {
if (!_PyUnicode_FSConverter(o, &bytes, path->nonstrict)) {
goto error_exit;
}
}
Expand Down Expand Up @@ -1349,7 +1350,7 @@ path_converter(PyObject *o, void *p)

length = PyBytes_GET_SIZE(bytes);
narrow = PyBytes_AS_STRING(bytes);
if (!path->null_embeddable && strlen(narrow) != (size_t)length) {
if (!path->nonstrict && strlen(narrow) != (size_t)length) {
FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character in %s");
goto error_exit;
}
Expand All @@ -1366,12 +1367,12 @@ path_converter(PyObject *o, void *p)
goto error_exit;
}
#ifdef MS_WINDOWS
if (length > 32767) {
if (!path->nonstrict && length > 32767) {
FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows");
goto error_exit;
}
#endif
if (!path->null_embeddable && wcslen(wide) != (size_t)length) {
if (!path->nonstrict && wcslen(wide) != (size_t)length) {
FORMAT_EXCEPTION(PyExc_ValueError,
"embedded null character in %s");
goto error_exit;
Expand Down Expand Up @@ -2928,8 +2929,8 @@ class path_t_converter(CConverter):

converter = 'path_converter'

def converter_init(self, *, allow_fd=False, make_wide=None, nullable=False,
null_embeddable=False, suppress=False):
def converter_init(self, *, allow_fd=False, make_wide=None,
nonstrict=False, nullable=False, suppress=False):
# right now path_t doesn't support default values.
# to support a default value, you'll need to override initialize().
if self.default not in (unspecified, None):
Expand All @@ -2939,7 +2940,7 @@ class path_t_converter(CConverter):
raise RuntimeError("Can't specify a c_default to the path_t converter!")

self.nullable = nullable
self.null_embeddable = null_embeddable
self.nonstrict = nonstrict
self.make_wide = make_wide
self.suppress = suppress
self.allow_fd = allow_fd
Expand All @@ -2956,7 +2957,7 @@ class path_t_converter(CConverter):
self.function.name,
self.name,
strify(self.nullable),
strify(self.null_embeddable),
strify(self.nonstrict),
strify(self.suppress),
strify(self.allow_fd),
)
Expand All @@ -2965,7 +2966,7 @@ class path_t_converter(CConverter):
self.function.name,
self.name,
strify(self.nullable),
strify(self.null_embeddable),
strify(self.nonstrict),
strify(self.make_wide),
strify(self.suppress),
strify(self.allow_fd),
Expand Down Expand Up @@ -3048,7 +3049,7 @@ class sysconf_confname_converter(path_confname_converter):
converter="conv_sysconf_confname"

[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=9bfc716d9f7ad345]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=e859625395de8933]*/

/*[clinic input]

Expand Down Expand Up @@ -5492,7 +5493,7 @@ os__path_islink_impl(PyObject *module, path_t *path)
/*[clinic input]
os._path_splitroot_ex

path: path_t(null_embeddable=True, make_wide=True)
path: path_t(make_wide=True, nonstrict=True)

Split a pathname into drive, root and tail.

Expand All @@ -5501,7 +5502,7 @@ The tail contains anything after the root.

static PyObject *
os__path_splitroot_ex_impl(PyObject *module, path_t *path)
/*[clinic end generated code: output=4b0072b6cdf4b611 input=fa388b51979a2f57]*/
/*[clinic end generated code: output=4b0072b6cdf4b611 input=8f29a719fd480028]*/
{
Py_ssize_t drvsize, rootsize;
PyObject *drv = NULL, *root = NULL, *tail = NULL, *result = NULL;
Expand Down Expand Up @@ -5538,14 +5539,14 @@ os__path_splitroot_ex_impl(PyObject *module, path_t *path)
/*[clinic input]
os._path_normpath

path: path_t(null_embeddable=True, make_wide=True)
path: path_t(make_wide=True, nonstrict=True)

Normalize path, eliminating double slashes, etc.
[clinic start generated code]*/

static PyObject *
os__path_normpath_impl(PyObject *module, path_t *path)
/*[clinic end generated code: output=d353e7ed9410c044 input=4842c54b2fbdfc83]*/
/*[clinic end generated code: output=d353e7ed9410c044 input=b8d62d498aa0a8db]*/
{
PyObject *result;
Py_ssize_t norm_len;
Expand Down
4 changes: 2 additions & 2 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3790,7 +3790,7 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)


int
_PyUnicode_FSConverter(PyObject* arg, void* addr, int null_embeddable)
_PyUnicode_FSConverter(PyObject* arg, void* addr, int nonstrict)
{
PyObject *path = NULL;
PyObject *output = NULL;
Expand Down Expand Up @@ -3819,7 +3819,7 @@ _PyUnicode_FSConverter(PyObject* arg, void* addr, int null_embeddable)

size = PyBytes_GET_SIZE(output);
data = PyBytes_AS_STRING(output);
if (!null_embeddable && (size_t)size != strlen(data)) {
if (!nonstrict && (size_t)size != strlen(data)) {
PyErr_SetString(PyExc_ValueError, "embedded null byte");
Py_DECREF(output);
return 0;
Expand Down