Skip to content

Generating bindings are not always reproducible (ordering of classes and code is different) #145

@faisal-shah

Description

@faisal-shah

I've noticed that the ordering of the class definitions and code is not always identical for the same header file. This is causing problems with version management of the generated code. My assumption was that the generated ctypes code follows the order of the C header file. I can't share the exact example here, but I'll try to show a sort of equivalent below.

#include "STRUCT1.h"
#include "STRUCT2.h"

typedef struct { .. } STRUCT3;

typedef struct {
  STRUCT1 var1;
  STRUCT2 var2;
  STRUCT3 var3;
} COMBINED_STRUCT

In the generated .py code I expect to see the generated code in the same order that they are referenced above:

STRUCT3
STRUCT1
STRUCT2
COMBINED_STRUCT

However, sometimes I see:
STRUCT3
STRUCT2
STRUCT1
COMBINED_STRUCT

In both cases the code the functional, but like I said - it's causing a problem for reproducible builds and thus the version control system.
I thought maybe a dictionary is being used to store the various nodes for code generation, and the code is generated by iterating thru the keys in the dictionary. However, since Python 3.7, dictionaries preserve insertion order (and I'm using 3.10.x) - so that shouldn't be the root cause.

Could this be an issue with the clang package? Is there any intermediate data structures I could provide to determine the root cause of this?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions