[Python-3000] Help replacing Py_FindMethod
Amaury Forgeot d'Arc
amauryfa at gmail.com
Tue Jul 22 00:48:59 CEST 2008
Jesus Cea wrote:
> Good night everybody!.
>
> Working on the Python3.0 support for bsddb I see that "Py_FindMethod"
> was just removed in Python last beta.
>
> Most uses of "Py_FindMethod" can be resolved as (as far as I know):
>
> 1. Delete the getattr routine.
> 2. Put a "0" in the getattr slot in the type object.
> 3. Use the "methods" slot. [*]
>
> This is not documented anywhere, so I needed to "diff" modules between
> 2.6 and 3.0 trees :-(
>
> But I have some code I don't know how to "upgrade". Can you possibly
> help me?
>
> The full sourcecode:
>
> """
> static PyObject*
> DBEnv_getattr(DBEnvObject* self, char *name)
> {
> ~ if (!strcmp(name, "db_home")) {
> ~ const char *home = NULL;
> ~ CHECK_ENV_NOT_CLOSED(self);
> #if (DBVER >= 42)
> ~ self->db_env->get_home(self->db_env, &home);
> #else
> ~ home=self->db_env->db_home;
> #endif
> ~ if (home == NULL) {
> ~ RETURN_NONE();
> ~ }
> ~ return PyBytes_FromString(home);
> ~ }
>
> ~ return Py_FindMethod(DBEnv_methods, (PyObject* )self, name);
> }
> """
>
> What can I do?.
>
> Moreover, is this "Py_FindMethod" removal strategy valid for old Python
> releases?. I need to support Python 2.3 and up.
>
> [*] Using this change, the code doesn't work :-(. Compiling under
> Python2.6 I get a lot of errors: "AttributeError: 'DB' object has no
> attribute 'XXX'."
>
> Example of "diff" I'm doing:
>
> 1. Delete the "DBSequence_getattr" routine.
> 2. Change the DBSequence_Type as:
>
> """
> @@ -6800,7 +6785,7 @@
> ~ /* methods */
> ~ (destructor)DBSequence_dealloc, /*tp_dealloc*/
> ~ 0, /*tp_print*/
> - - (getattrfunc)DBSequence_getattr,/*tp_getattr*/
> + 0, /*tp_getattr*/
> ~ 0, /*tp_setattr*/
> ~ 0, /*tp_compare*/
> ~ 0, /*tp_repr*/
> @@ -6823,6 +6808,10 @@
> ~ 0, /* tp_clear */
> ~ 0, /* tp_richcompare */
> ~ offsetof(DBSequenceObject, in_weakreflist),/*tp_weaklistoffset*/
> + 0, /*tp_iter*/
> + 0, /*tp_iternext*/
> + DBSequence_methods, /*tp_methods*/
> + 0, /*tp_members*/
> ~ };
> ~ #endif
> """
>
> What am I doing wrong?.
>
> Thanks in advance.
>
> PS: Four hours of hard working and bsddb "almost" compiles under
> Python3.0b2!.
The best is to look at the change that suppressed Py_FindMethod (and I
am guilty):
http://svn.python.org/view?rev=64672&view=rev
I even modified (an older version of?) the _bsddb module! You could
start with it...
I think you were close, you just have to be careful to call
PyType_Ready in the module init function,
to create the descriptors for each tp_methods and tp_members entries.
--
Amaury Forgeot d'Arc
More information about the Python-3000
mailing list