[Python-Dev] Identifier API (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Sat Oct 8 17:43:33 CEST 2011


On Sat, 08 Oct 2011 16:54:06 +0200 "Martin v. Löwis" <martin at v.loewis.de> wrote:

I find the ad-hoc approach of declaring and initializing variables inadequate, in particular since it is difficult to clean up all those string objects at interpreter shutdown. I propose to add an explicit API to deal with such identifiers.

That sounds like a good idea.

With this API,

tmp = PyObjectCallMethod(result, "update", "O", other); would be replaced with PyObject *tmp; Pyidentifier(update); ... tmp = PyObjectCallMethodId(result, &PyIdupdate, "O", other);

Surely there is something missing to initialize the "const char *" in the structure? Or is "Py_identifier()" actually a macro?

string will be initialized by the compiler, next and object on first use. The new API for that will be

PyObject* PyUnicodeFromId(PyIdentifier*); PyObject* PyObjectCallMethodId(PyObject*, PyIdentifier*, char*, ...); PyObject* PyObjectGetAttrId(PyObject*, PyIdentifier*); int PyObjectSetAttrId(PyObject*, PyIdentifier*, PyObject*); int PyObjectHasAttrId(PyObject*, PyIdentifier*);

Do we want to make these APIs public?

Regards

Antoine.



More information about the Python-Dev mailing list