New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameter list mismatches (portation problem) #44525
Comments
On the system I'm porting to(*), an application will trap if the caller does not pass the exact parameter list that the callee requires. This is causing problems running Python. One common instance where this appears to be causing problems is where functions are registered as METH_NOARGS methods. For example, in Obejcts/dictobject.c, dict_popitem() is declared: static PyObject *dict_popitem(dictobject *mp); However, as it is declared in the method array as METH_NOARGS, it will be called by Objects/methodobject.c:PyCFunction_Call() as "(*meth)(self, NULL)" (i.e., an extra NULL parameter is passed for some reason). This will fail on my target system. I've no problem submitting a patch for this (dictobject.c is by no means the only place this is happening - it's just the first one encountered because it's used so much - though some places _do_ correctly declare a second, ignored parameter). However, I'd like to get agreement on the correct form it should be changed to before I put the effort in to produce a patch (it's going to be a fairly tedious process to identify and fix all these). In various modules, the functions are called internally as well as being registered as METH_NOARGS methods. Therefore, the change can either be: static PyObject *foo(PyObject *self) static PyObject *foo_noargs(PyObject *self, void *noargs_null)
{
return foo(self);
} ... where 'foo' is called internally and 'foo_noargs' is registered as a METH_NOARGS method. or: static PyObject *foo(PyObject *self, void *noargs_null) ... and any internal calls in the module have to pass a second, NULL, argument in each call. The former favours internal module calls over METH_NOARGS calls, the latter penalises them. Which is preferred? Should this be raised on a different forum? Does anyone care? ;) Thanks, Kev. (*) Details on request. |
The current specification says that these should be PyCFunction pointers, see http://docs.python.org/api/common-structs.html My initial implementation of METH_NOARGS had it differently, and nobody ever bothered fixing them all when this was changed. Please do submit a patch to correct all such errors, both in code and documentation. |
File Added: tested.diff |
Hi, I am submitting two patches (both against the 2.5 release sources). One The second contains a set of changes to source files that are not being used The nature of the fixes themselves are discussed below. -----------------------------------
==== Miscellaneous individual fixes:
----------------------------------- All in all, that was a pretty tedious process! Hopefully these changes can Regards, Kev. File Added: untested.diff |
Kev, I would be interested to know the platform this was a problem on. I haven't looked at the patch much (a little of tested.diff), primarily Martin's msg on python-dev. I'm in favor of fixing this in concept. I tend to agree with Thomas that the parameter name in ALL_CAPS seems a bit annoying. I don't have a better suggestion and would rather see the patch applied with ALL_CAPS than not applied. I would also like to remove the casts to PyCFunction for all the functions that are stored in the various static structures. That will help ensure we don't copy bad examples and propagate the problem in the future. |
It appears that in principle this patch is acceptable but I believe that it will need pretty thorough checking from a core developer before going anywhere. It's certainly not in my league, anyone up for it? |
This issue has been partially (for METH_NOARGS methods) fixed in bpo-33012. |
This appears to be fixed for |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: