This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients eric.snow, ncoghlan, serhiy.storchaka, vstinner
Date 2017-03-23.13:07:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1490274431.05.0.200398725258.issue29881@psf.upfronthosting.co.za>
In-reply-to
Content
> * do we ever declare non-statics this way? (OTOH, if we do, this could be an opportunity to hide them behind read-only accessor functions)
> * do we ever declare more specific types than PyObject * this way? (OTOH, if that's the uncommon case, requiring a cast to the more specific type probably wouldn't hurt)

Well, with my 2nd API, I'm not sure that the macro to declare a variable is very simple:

+/* Declare a static PyObject* variable which is only initialized once.
+   _PyOnceVar_Fini() will clear the variable at Python finalization. */
+#define _Py_ONCEVAR(var) \
+    static PyObject* var = NULL

Technically, the variable doesn't have to be static. But do we want to use this API for global variables initialized once? It would increase the memory usage, whereas currently we have specialized code like _PyUnicode_Fini() which clears its unicode_empty singleton. I don't want to touch this code. At least, not yet.

If you want to support other types than PyObject*, _PY_ONCEVAR_INIT() macro can cast the first argument to PyObject*.

I would prefer to start with something simpler, and discuss case by case for other variables.
History
Date User Action Args
2017-03-23 13:07:11vstinnersetrecipients: + vstinner, ncoghlan, eric.snow, serhiy.storchaka
2017-03-23 13:07:11vstinnersetmessageid: <1490274431.05.0.200398725258.issue29881@psf.upfronthosting.co.za>
2017-03-23 13:07:11vstinnerlinkissue29881 messages
2017-03-23 13:07:10vstinnercreate