Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-40052: Fix alignment issue in PyVectorcall_Function() #19133

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

Closed
wants to merge 1 commit into from

Conversation

cryptomilk
Copy link

@cryptomilk cryptomilk commented Mar 24, 2020

In file included from /usr/include/python3.8/Python.h:147:
In file included from /usr/include/python3.8/abstract.h:837:
/usr/include/python3.8/cpython/abstract.h:91:11: error: cast from 'char *' to 'vectorcallfunc *'
(aka 'struct _object *(**)(struct _object *, struct _object *const *, unsigned long, struct _object *)')
increases required alignment from 1 to 8 [-Werror,-Wcast-align]

    ptr = (vectorcallfunc*)(((char *)callable) + offset);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

https://bugs.python.org/issue40052

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@cryptomilk

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@cryptomilk
Copy link
Author

I've added my github username to my account on bugs.python.org and signed the CA. However I think it might take some time till the system gets the update.

In file included from /usr/include/python3.8/Python.h:147:
In file included from /usr/include/python3.8/abstract.h:837:
/usr/include/python3.8/cpython/abstract.h:91:11: error: cast from 'char *' to 'vectorcallfunc *'
(aka 'struct _object *(**)(struct _object *, struct _object *const *, unsigned long, struct _object *)')
increases required alignment from 1 to 8 [-Werror,-Wcast-align]

    ptr = (vectorcallfunc*)(((char *)callable) + offset);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Signed-off-by: Andreas Schneider <[email protected]>
ptr = (vectorcallfunc *)(((char *)callable) + offset);
return *ptr;
vc.data = (char *)callable + offset;
return *vc.ptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is better. The correct, idiomatic solution is something like:

    vectorcallfunc *ptr;
    memcpy(ptr, (char *) callable + offset, sizeof(ptr));
    return *ptr;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also, note that any decent compiler will optimize the memcpy call away)

@@ -215,7 +219,8 @@ PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
Py_TYPE(callable)->tp_name);
return NULL;
}
vectorcallfunc func = *(vectorcallfunc *)(((char *)callable) + offset);
vc.data = (char *)callable + offset;
vectorcallfunc func = *vc.ptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

@vstinner
Copy link
Member

In my experience, memcpy() is good solution for such problem.

@encukou
Copy link
Member

encukou commented Dec 29, 2020

I've made a PR with the suggested memcpy at #23999

@pitrou
Copy link
Member

pitrou commented Dec 29, 2020

Closing in favour of #23999.

@pitrou pitrou closed this Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants