Git Product home page Git Product logo

Comments (5)

williamcroberts avatar williamcroberts commented on June 3, 2024 1

I thought you we're going to write a parser that generates all of the boring parts. Couldn't it just write a little program and execute it to get the system size during build time?

#include <stdio.h>

int main(int argc, char *argv[]) {
        printf("%zu\n", sizeof(SIZEOF_TYPE));
        return 0;
}
gcc -o sizeofprog -D'SIZEOF_TYPE=int' sizeof_prog.c
./sizeofprog
4

A simple way if you're doing it by hand would be to just drop that in via a placeholder? You could probably just markup the CYTHON with something like
SIZEOF_MYTYPE and then sed -i it with the value from the little program.

So you just need to add a little build time preprocessing.

An alternative would be to use autoconf's AC_CHECK_SIZEOF. So generate that with the unknown types and then pass them via a generated python file. That macro would create things like SIZEOF_INT_P, which you could output to the config.h and then sed from that.

from tpm2-pytss.

pdxjohnny avatar pdxjohnny commented on June 3, 2024

Cython has an issue where it can't do VLA's: cython/cython#1305

This results in issue with the way many of the TPMX_* structs are defined:

TPM2_MAX_AC_CAPABILITIES = (TPM2_MAX_CAP_BUFFER / sizeof(TPMS_AC_OUTPUT))

cdef extern from "<tss2/tss2_tpm2_types.h>":
    # Definition of TPML_AC_CAPABILITIES Structure <OUT> 
    struct TPML_AC_CAPABILITIES:
        UINT32 count # Number of values in the acCapabilities list. May be 0
        TPMS_AC_OUTPUT acCapabilities[TPM2_MAX_AC_CAPABILITIES] # List of AC values
[1/1] Cythonizing /home/pdxjohnny/Documents/python/cython-pytss/tpm2_pytss/tss2_tpm2_types.pyx

Error compiling Cython file:
------------------------------------------------------------
...

cdef extern from "<tss2/tss2_tpm2_types.h>":
    # Definition of TPML_AC_CAPABILITIES Structure <OUT>
    struct TPML_AC_CAPABILITIES:
        UINT32 count # Number of values in the acCapabilities list. May be 0
        TPMS_AC_OUTPUT acCapabilities[TPM2_MAX_AC_CAPABILITIES] # List of AC values
                                     ^
------------------------------------------------------------

tpm2_pytss/tss2_tpm2_types.pyx:16:38: Not allowed in a constant expression

Error compiling Cython file:
------------------------------------------------------------
...

cdef extern from "<tss2/tss2_tpm2_types.h>":
    # Definition of TPML_AC_CAPABILITIES Structure <OUT>
    struct TPML_AC_CAPABILITIES:
        UINT32 count # Number of values in the acCapabilities list. May be 0
        TPMS_AC_OUTPUT acCapabilities[TPM2_MAX_AC_CAPABILITIES] # List of AC values
                                     ^
------------------------------------------------------------

tpm2_pytss/tss2_tpm2_types.pyx:16:38: Array dimension not integer

Error compiling Cython file:
------------------------------------------------------------
...

cdef extern from "<tss2/tss2_tpm2_types.h>":
    # Definition of TPML_AC_CAPABILITIES Structure <OUT>
    struct TPML_AC_CAPABILITIES:
        UINT32 count # Number of values in the acCapabilities list. May be 0
        TPMS_AC_OUTPUT acCapabilities[TPM2_MAX_AC_CAPABILITIES] # List of AC values
                                    ^
------------------------------------------------------------

tpm2_pytss/tss2_tpm2_types.pyx:16:37: Variable type 'TPMS_AC_OUTPUT []' is incomplete
Traceback (most recent call last):
  File "setup.py", line 82, in <module>
    compiler_directives={"language_level": "3"},
  File "/home/pdxjohnny/.pyenv/versions/3.7.6/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 1102, in cythonize
    cythonize_one(*args)
  File "/home/pdxjohnny/.pyenv/versions/3.7.6/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 1225, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: /home/pdxjohnny/Documents/python/cython-pytss/tpm2_pytss/tss2_tpm2_types.pyx

from tpm2-pytss.

pdxjohnny avatar pdxjohnny commented on June 3, 2024

As far as I can tell this ends up being a show stopper for Cython usage. Since those sizeofs are platform dependent and not something we can calculate ahead of time and put in static values for.

from tpm2-pytss.

pdxjohnny avatar pdxjohnny commented on June 3, 2024

https://github.com/pdxjohnny/tpm2-pytss/tree/rewrite

from tpm2-pytss.

williamcroberts avatar williamcroberts commented on June 3, 2024

Went with CFFI, started.

from tpm2-pytss.

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.