2011/10/11 Hrvoje Niksic <hrvoje.niksic@avl.com>
An alternative I am fond of is to to avoid introducing a new type, and simply initialize a PyObject * and register its address. For example:
PyObject *tmp; static PyObject *s_update; // pick a naming convention
PY_IDENTIFIER_INIT(update); tmp = PyObject_CallMethodObj(result, s_update, "O", other);
(but also PyObject_GetAttr(o, s_update), etc.)
PY_IDENTIFIER_INIT(update) might expand to something like:
if (!s_update) { s_update = PyUnicode_InternFromString("**update"); _Py_IdentifierAdd(&s_update); }
It should also check for errors; in this case the initialization is a bit more verbose: if (PY_IDENTIFIER_INIT(update) < 0) <return NULL or return -1 or goto error>; -- Amaury Forgeot d'Arc