Skip to content

Commit d0ed838

Browse files
committed
Using is_fd field to determin a path_t is an fd or not
1 parent bac84ce commit d0ed838

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

Modules/posixmodule.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,8 @@ get_posix_state(PyObject *module)
12801280
* Contains a file descriptor if path.accept_fd was true
12811281
* and the caller provided a signed integer instead of any
12821282
* sort of string.
1283+
* path.is_fd
1284+
* True if path was provided as a file descriptor.
12831285
*
12841286
* WARNING: if your "path" parameter is optional, and is
12851287
* unspecified, path_converter will never get called.
@@ -1332,6 +1334,7 @@ typedef struct {
13321334
const wchar_t *wide;
13331335
const char *narrow;
13341336
int fd;
1337+
bool is_fd;
13351338
int value_error;
13361339
Py_ssize_t length;
13371340
PyObject *object;
@@ -1341,7 +1344,7 @@ typedef struct {
13411344
#define PATH_T_INITIALIZE(function_name, argument_name, nullable, nonstrict, \
13421345
make_wide, suppress_value_error, allow_fd) \
13431346
{function_name, argument_name, nullable, nonstrict, make_wide, \
1344-
suppress_value_error, allow_fd, NULL, NULL, -1, 0, 0, NULL, NULL}
1347+
suppress_value_error, allow_fd, NULL, NULL, -1, false, 0, 0, NULL, NULL}
13451348
#ifdef MS_WINDOWS
13461349
#define PATH_T_INITIALIZE_P(function_name, argument_name, nullable, \
13471350
nonstrict, suppress_value_error, allow_fd) \
@@ -1475,6 +1478,7 @@ path_converter(PyObject *o, void *p)
14751478
}
14761479
path->wide = NULL;
14771480
path->narrow = NULL;
1481+
path->is_fd = true;
14781482
goto success_exit;
14791483
}
14801484
else {
@@ -1609,12 +1613,6 @@ follow_symlinks_specified(const char *function_name, int follow_symlinks)
16091613
return 1;
16101614
}
16111615

1612-
static bool
1613-
path_is_fd(const path_t *path)
1614-
{
1615-
return path->allow_fd && path->object != NULL && PyIndex_Check(path->object);
1616-
}
1617-
16181616
static int
16191617
path_and_dir_fd_invalid(const char *function_name, path_t *path, int dir_fd)
16201618
{
@@ -14334,7 +14332,7 @@ os_pathconf_impl(PyObject *module, path_t *path, int name)
1433414332

1433514333
errno = 0;
1433614334
#ifdef HAVE_FPATHCONF
14337-
if (path_is_fd(path)) {
14335+
if (path->is_fd) {
1433814336
limit = fpathconf(path->fd, name);
1433914337
}
1434014338
else

0 commit comments

Comments
 (0)