Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-117398: Isolate _datetime (3.13.0a6 PoC) with AC #118337

Draft
wants to merge 53 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4a418cb
import poc313a5 diff
neonene Apr 26, 2024
80084da
import poc313a5 diff
neonene Apr 26, 2024
23bf9b4
module, classes
neonene Apr 26, 2024
286a284
timedelta_total_seconds()
neonene Apr 26, 2024
8ba2af7
date.fromtimestamp() update
neonene Apr 26, 2024
b21bded
date.fromordinal()
neonene Apr 26, 2024
c1f6a75
date.fromisocalendar() with converter
neonene Apr 26, 2024
bd99b42
date.strftime()
neonene Apr 26, 2024
126b652
date.isocalendar()
neonene Apr 26, 2024
8e31f9d
date.replace() update
neonene Apr 26, 2024
109bea7
date.__replace__()
neonene Apr 26, 2024
25bf57b
tzinfo.fromutc()
neonene Apr 26, 2024
82c65ce
timezone.tzname()
neonene Apr 26, 2024
25dbfe9
timezone.utcoffset()
neonene Apr 26, 2024
af1eaf5
timezone.dst()
neonene Apr 26, 2024
0b5c97c
timezone.fromutc()
neonene Apr 26, 2024
903d26f
time.utcoffset()
neonene Apr 26, 2024
e4f6b7c
time.dst()
neonene Apr 26, 2024
569bc03
time.tzname()
neonene Apr 26, 2024
d0556d0
time.isoformat()
neonene Apr 26, 2024
faf3772
time.strftime()
neonene Apr 26, 2024
489f173
time.replace() update
neonene Apr 26, 2024
fcf8c32
time.__replace__()
neonene Apr 26, 2024
af9c28e
time.fromisoformat()
neonene Apr 26, 2024
0138f9b
datetime.now() update
neonene Apr 26, 2024
991b858
datetime.fromtimestamp()
neonene Apr 26, 2024
a2cff70
datetime_fromtimestamp_capi()
neonene Apr 26, 2024
3811a3f
datetime.strptime()
neonene Apr 26, 2024
a48202b
datetime.combine()
neonene Apr 26, 2024
492fe6f
datetime.fromisoformat()
neonene Apr 26, 2024
92e6ed2
datetime.tzname()
neonene Apr 26, 2024
5c89a91
datetime.utcoffset()
neonene Apr 26, 2024
de23ca5
datetime.dst()
neonene Apr 26, 2024
c2b315e
datetime.isoformat()
neonene Apr 26, 2024
2c23667
datetime.replace() upadte
neonene Apr 26, 2024
e5b1db0
datetime.__replace__()
neonene Apr 26, 2024
0c237bc
datetime.astimezone()
neonene Apr 26, 2024
e210cc8
datetime.timetuple()
neonene Apr 26, 2024
86bbbab
datetime.timestamp()
neonene Apr 26, 2024
610b30b
datetime.date()
neonene Apr 26, 2024
a3b75f9
datetime.time()
neonene Apr 26, 2024
a9f821d
datetime.timetz()
neonene Apr 26, 2024
5188e7b
datetime.utctimetuple()
neonene Apr 26, 2024
7823d6b
update _datetimemodule.c.h
neonene Apr 26, 2024
0720cf9
regen
neonene Apr 26, 2024
f474feb
Update ignored.tsv
neonene Apr 26, 2024
1ed62de
fix gil-disabled test
neonene Apr 28, 2024
ccb230f
Merge branch 'main' into poc313clinic
neonene Apr 28, 2024
cc0c974
add missing docstr for *.__replace__()
neonene Apr 28, 2024
49b16c0
apply PR: Access C-API via PyInterpreterState
neonene May 1, 2024
163b209
Merge branch 'main' into poc313clinic
neonene May 1, 2024
2637e04
edit fix
neonene May 1, 2024
54ea8a6
Merge branch 'main' into poc313clinic
neonene May 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 18 additions & 5 deletions Include/datetime.h
Expand Up @@ -186,18 +186,31 @@ typedef struct {
} PyDateTime_CAPI;

#define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI"

#define PyDateTime_INTERNAL_CAPSULE_NAME "datetime.datetime_CAPI_INTERNAL"

/* This block is only used as part of the public API and should not be
* included in _datetimemodule.c, which does not use the C API capsule.
* See bpo-35081 for more details.
* */
#ifndef _PY_DATETIME_IMPL
/* Define global variable for the C API and a macro for setting it. */
static PyDateTime_CAPI *PyDateTimeAPI = NULL;
static PyDateTime_CAPI *
_PyDateTimeAPI_not_ready(void)
{
return NULL;
}
static PyDateTime_CAPI *(*_PyDateTimeAPI_Get)(void) = _PyDateTimeAPI_not_ready;

static inline void
_PyDateTimeAPI_Import(void)
{
void *(*func)(void) = PyCapsule_Import(PyDateTime_INTERNAL_CAPSULE_NAME, 0);
if (func) {
_PyDateTimeAPI_Get = func();
}
}

#define PyDateTime_IMPORT \
PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)
#define PyDateTimeAPI _PyDateTimeAPI_Get()
#define PyDateTime_IMPORT _PyDateTimeAPI_Import()

/* Macro for access to the UTC singleton */
#define PyDateTime_TimeZone_UTC PyDateTimeAPI->TimeZone_UTC
Expand Down
4 changes: 4 additions & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Include/internal/pycore_global_strings.h
Expand Up @@ -370,6 +370,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(d)
STRUCT_FOR_ID(data)
STRUCT_FOR_ID(database)
STRUCT_FOR_ID(date)
STRUCT_FOR_ID(day)
STRUCT_FOR_ID(decode)
STRUCT_FOR_ID(decoder)
Expand Down Expand Up @@ -743,8 +744,11 @@ struct _Py_global_strings {
STRUCT_FOR_ID(text)
STRUCT_FOR_ID(threading)
STRUCT_FOR_ID(throw)
STRUCT_FOR_ID(time)
STRUCT_FOR_ID(timeout)
STRUCT_FOR_ID(times)
STRUCT_FOR_ID(timespec)
STRUCT_FOR_ID(timestamp)
STRUCT_FOR_ID(timetuple)
STRUCT_FOR_ID(top)
STRUCT_FOR_ID(trace_callback)
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_interp.h
Expand Up @@ -234,6 +234,7 @@ struct _is {
// more comments.
struct _obmalloc_state *obmalloc;

void *datetime_capi;
PyObject *audit_hooks;
PyType_WatchCallback type_watchers[TYPE_MAX_WATCHERS];
PyCode_WatchCallback code_watchers[CODE_MAX_WATCHERS];
Expand Down
4 changes: 4 additions & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Lib/test/datetimetester.py
Expand Up @@ -91,7 +91,7 @@ def test_name_cleanup(self):
if not name.startswith('__') and not name.endswith('__'))
allowed = set(['MAXYEAR', 'MINYEAR', 'date', 'datetime',
'datetime_CAPI', 'time', 'timedelta', 'timezone',
'tzinfo', 'UTC', 'sys'])
'tzinfo', 'UTC', 'sys', 'datetime_CAPI_INTERNAL'])
self.assertEqual(names - allowed, set([]))

def test_divide_and_round(self):
Expand Down
17 changes: 17 additions & 0 deletions Lib/test/test_capi/test_misc.py
Expand Up @@ -2282,6 +2282,23 @@ def test_module_state_shared_in_global(self):
subinterp_attr_id = os.read(r, 100)
self.assertEqual(main_attr_id, subinterp_attr_id)

@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
def test_datetime_capi_client(self):
script = textwrap.dedent("""
import importlib.machinery
import importlib.util
fullname = '_test_datetime_capi_client'
origin = importlib.util.find_spec('_testmultiphase').origin
loader = importlib.machinery.ExtensionFileLoader(fullname, origin)
spec = importlib.util.spec_from_loader(fullname, loader)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
""")
exec(script) # run main interp first
exec(script) # run main interp twice
ret = support.run_in_subinterp(script)
self.assertEqual(ret, 0)


@requires_subinterpreters
class InterpreterConfigTests(unittest.TestCase):
Expand Down
@@ -0,0 +1 @@
Apply :pep:`687` to :mod:`datetime`. Patch by Erlend Aasland.