#endif
#include "Python.h"
+#include "pycore_critical_section.h" // _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED()
#include "pycore_long.h" // _PyLong_GetOne()
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
}
}
+/*[clinic input]
+@critical_section
+@classmethod
+zoneinfo.ZoneInfo.__new__
+
+ key: object
+
+Create a new ZoneInfo instance.
+[clinic start generated code]*/
+
static PyObject *
-zoneinfo_new(PyTypeObject *type, PyObject *args, PyObject *kw)
+zoneinfo_ZoneInfo_impl(PyTypeObject *type, PyObject *key)
+/*[clinic end generated code: output=95e61dab86bb95c3 input=ef73d7a83bf8790e]*/
{
- PyObject *key = NULL;
- static char *kwlist[] = {"key", NULL};
- if (PyArg_ParseTupleAndKeywords(args, kw, "O", kwlist, &key) == 0) {
- return NULL;
- }
-
zoneinfo_state *state = zoneinfo_get_state_by_self(type);
PyObject *instance = zone_from_strong_cache(state, type, key);
if (instance != NULL || PyErr_Occurred()) {
}
/*[clinic input]
+@critical_section
@classmethod
zoneinfo.ZoneInfo.clear_cache
static PyObject *
zoneinfo_ZoneInfo_clear_cache_impl(PyTypeObject *type, PyTypeObject *cls,
PyObject *only_keys)
-/*[clinic end generated code: output=114d9b7c8a22e660 input=e32ca3bb396788ba]*/
+/*[clinic end generated code: output=114d9b7c8a22e660 input=35944715df26d24e]*/
{
zoneinfo_state *state = zoneinfo_get_state_by_cls(cls);
PyObject *weak_cache = get_weak_cache(state, type);
/*[clinic end generated code: output=556712fc709deecb input=6ac8c73eed3de316]*/
{
if (from_cache) {
- PyObject *val_args = PyTuple_Pack(1, key);
- if (val_args == NULL) {
- return NULL;
- }
-
- PyObject *rv = zoneinfo_new(type, val_args, NULL);
-
- Py_DECREF(val_args);
+ PyObject *rv;
+ Py_BEGIN_CRITICAL_SECTION(type);
+ rv = zoneinfo_ZoneInfo_impl(type, key);
+ Py_END_CRITICAL_SECTION();
return rv;
}
else {
0, seconds, 0, 1, PyDateTimeAPI->DeltaType);
if (tmp != NULL) {
- rv = PyDict_SetDefault(state->TIMEDELTA_CACHE, pyoffset, tmp);
- Py_XINCREF(rv);
+ PyDict_SetDefaultRef(state->TIMEDELTA_CACHE, pyoffset, tmp, &rv);
Py_DECREF(tmp);
}
}
static void
remove_from_strong_cache(zoneinfo_state *state, StrongCacheNode *node)
{
+ _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(state->ZoneInfoType);
if (state->ZONEINFO_STRONG_CACHE == node) {
state->ZONEINFO_STRONG_CACHE = node->next;
}
return 0;
}
+ _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(state->ZoneInfoType);
StrongCacheNode *cache = state->ZONEINFO_STRONG_CACHE;
StrongCacheNode *node = find_in_strong_cache(cache, key);
if (node != NULL) {
return NULL; // Strong cache currently only implemented for base class
}
+ _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(state->ZoneInfoType);
StrongCacheNode *cache = state->ZONEINFO_STRONG_CACHE;
StrongCacheNode *node = find_in_strong_cache(cache, key);
return;
}
+ _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(state->ZoneInfoType);
StrongCacheNode *new_node = strong_cache_node_new(key, zone);
if (new_node == NULL) {
return;
{Py_tp_getattro, PyObject_GenericGetAttr},
{Py_tp_methods, zoneinfo_methods},
{Py_tp_members, zoneinfo_members},
- {Py_tp_new, zoneinfo_new},
+ {Py_tp_new, zoneinfo_ZoneInfo},
{Py_tp_dealloc, zoneinfo_dealloc},
{Py_tp_traverse, zoneinfo_traverse},
{Py_tp_clear, zoneinfo_clear},
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
+#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
+PyDoc_STRVAR(zoneinfo_ZoneInfo__doc__,
+"ZoneInfo(key)\n"
+"--\n"
+"\n"
+"Create a new ZoneInfo instance.");
+
+static PyObject *
+zoneinfo_ZoneInfo_impl(PyTypeObject *type, PyObject *key);
+
+static PyObject *
+zoneinfo_ZoneInfo(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 1
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(key), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"key", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "ZoneInfo",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[1];
+ PyObject * const *fastargs;
+ Py_ssize_t nargs = PyTuple_GET_SIZE(args);
+ PyObject *key;
+
+ fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
+ if (!fastargs) {
+ goto exit;
+ }
+ key = fastargs[0];
+ Py_BEGIN_CRITICAL_SECTION(type);
+ return_value = zoneinfo_ZoneInfo_impl(type, key);
+ Py_END_CRITICAL_SECTION();
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(zoneinfo_ZoneInfo_from_file__doc__,
"from_file($type, file_obj, /, key=None)\n"
"--\n"
}
only_keys = args[0];
skip_optional_kwonly:
+ Py_BEGIN_CRITICAL_SECTION(type);
return_value = zoneinfo_ZoneInfo_clear_cache_impl(type, cls, only_keys);
+ Py_END_CRITICAL_SECTION();
exit:
return return_value;
exit:
return return_value;
}
-/*[clinic end generated code: output=2a15f32fdd2ab6cd input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b4fdc0b30247110a input=a9049054013a1b77]*/