Skip to content
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

python2.7.3 struct misaligned when returned #60321

Closed
iroli mannequin opened this issue Oct 3, 2012 · 3 comments
Closed

python2.7.3 struct misaligned when returned #60321

iroli mannequin opened this issue Oct 3, 2012 · 3 comments

Comments

@iroli
Copy link
Mannequin

iroli mannequin commented Oct 3, 2012

BPO 16117
Nosy @amauryfa, @mdickinson, @abalkin, @meadori, @zware

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:

assignee = None
closed_at = <Date 2020-04-27.02:22:18.911>
created_at = <Date 2012-10-03.09:30:39.765>
labels = ['ctypes']
title = 'python2.7.3 struct misaligned when returned'
updated_at = <Date 2020-04-27.02:22:18.910>
user = 'https://bugs.python.org/iroli'

bugs.python.org fields:

activity = <Date 2020-04-27.02:22:18.910>
actor = 'zach.ware'
assignee = 'none'
closed = True
closed_date = <Date 2020-04-27.02:22:18.911>
closer = 'zach.ware'
components = ['ctypes']
creation = <Date 2012-10-03.09:30:39.765>
creator = 'iroli'
dependencies = []
files = []
hgrepos = []
issue_num = 16117
keywords = []
message_count = 3.0
messages = ['171876', '222153', '367354']
nosy_count = 6.0
nosy_names = ['amaury.forgeotdarc', 'mark.dickinson', 'belopolsky', 'meador.inge', 'zach.ware', 'iroli']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue16117'
versions = ['Python 2.7']

@iroli
Copy link
Mannequin Author

iroli mannequin commented Oct 3, 2012

class Int(ctypes.Structure):
           _fields_ = [ ("_i", ctypes.c_uint64),
                                   ("undef", ctypes.c_bool)]

class Int {
public:
Int();
Int(uint64_t i);

            uint64_t \_i;
            bool undef;

};

extern "C" Int foo(const Int& a , const Int& b , const Int& c)
{
    ret = ...
    return Int(ret);
}

(gdb) p ret
$3 = 16
(gdb) fin
Run till exit from #0 BVSignExtend (a=..., b=..., c=...) at foo.hpp:130
0x00007ffff784eea4 in ffi_call_unix64 () from /usr/lib/python2.7/lib-dynload/_ctypes.so
Value returned is $4 = {_i = 18577824, undef = 16}

My guess: The value 18577824 was not expected to be on the stack.

The following actions "solve" the problem:

  1. add another int the class Int (after bool) and adopt _fields_ accordingly.
  2. in foo C++ function:
    Int reti = Int(ret);
    return reti;

Because of the "above" solutions I strongly suspect a bug in ctypes.

@iroli iroli mannequin added the topic-ctypes label Oct 3, 2012
@BreamoreBoy
Copy link
Mannequin

BreamoreBoy mannequin commented Jul 3, 2014

@roland please accept our apologies for the delay in getting back to you.

Can someone else take a look please as I know nothing about ctypes, thanks.

@zware
Copy link
Member

zware commented Apr 27, 2020

As Python 2.7 has now reached end-of-life, I'm closing the issue. If you can still reproduce this issue in a modern version of Python (3.6-3.8), please reopen it and hopefully we can get someone who understands what's going on to actually look at it :)

@zware zware closed this as completed Apr 27, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant