Coder Social home page Coder Social logo

Comments (3)

fpf3 avatar fpf3 commented on June 8, 2024

Seconding this. I have found a similar issue. Furthermore, if I am attempting to create an unpacked structure, it does not set _pack_ = False, as it should.

It seems that that clang2py has knowledge of how they are configured in the header file, and ignores it. You get something like:

class myStruct(Structure):
    _pack_ = True # source:False
    _fields_ = ...

I can only assume what "source:" refers to is the .h file.

from ctypeslib.

trolldbois avatar trolldbois commented on June 8, 2024

Short version: It's the result of the cross-architecture ability of ctypeslib.

My recollection is that pack and alignment are different attributes returned by clang.
In ctypeslib, pack will always be True to ensure that python ctypes fields are actually in the correct index.
If the alignment provided by tells clang says a field is not packed next the the previous one, a Padding field will be inserted in-between.

Given that ctypeslib is aware of multi-architecture issues, it's a requirement.
You just have to trust that the code & alignment, issued for the platform chosen by clang is correct.

You cannot ask a python 2.7 ctypes lib on a x86 arch to know how to pack a structure for a arm 128 arch.

E.g: the python source file can be used on any other system with possibly a different architecture for the python binary, and still work for the targeted arch. You can read x64 memory bytes from x86, and vice-versa.

from ctypeslib.

jpvolkmann avatar jpvolkmann commented on June 8, 2024

My understanding is that pack expects an integer number, not a boolean expression (according https://docs.python.org/2/library/ctypes.html#structure-union-alignment-and-byte-order ).
Because Python casts "True" to the integer 1 this works for ctypes library. Setting it to False will lead to a integer of 0 which is not valid

from ctypeslib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.