-
Notifications
You must be signed in to change notification settings - Fork 33
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
BUG: cffi type parsers for g-object, g-boxed-foreign, etc... create new types for every binding, every parameter #69
Comments
I don't think CFFI gives any guarantees about it, at least searching for
You're right though for That said, it sounds to me like it would be okay to cache them, just Edit: Oh you wrote CFFI introspection tools - if you want that guarantee |
Hmm. It may be a cffi issue, but it makes no sense at all. If a type parser creates a new type every time it encounters a parameter of say |
I will defend my idea of type equality, and conjecture that this is a cl-cffi-gtk bug. I think CFFI idea of foreign types represented by a compound designator such as There are many different c structures possible, and each one is indeed a different type! However, every instance of As @Ferada points out, simple parsers just instantiate new types. This makes sense for 'metatypes' like cstruct - every time you define a new cstruct it is in fact a new type, since we do this to define a new type with different slots. This parser is not suitable for compound type descriptors, which is probably why it's called simple. This makes sense for gobject types, since each gobject type has different slots. This however does not make sense for gobject instances. It makes even less sense to create a new type every time a type is mentioned or parsed. A type parser sees `(G-OBJECT GTK-TEXT-BUFFER), and creates a new type every time. THIS IS COMPLETELY WRONG. This should only happen when a new kind of g-object is being defined. As I mentioned, this is a subtle bug that eats your resources. The behaviour of all these thousands of GTK-TEXT-BUFFER types is identical, and no one uses CFFI types for typechecking based on identity (except me!). So unless you open the hood and climb inside wearing insane hacker glasses you would never see it. So yes, I think it is a cl-cffi-gtk bug that should be fixed. |
This is a confusion between creating an instance of a type and an instance of an object of that type. And this is especially a problem when you don't want to create any instances at all, but pass an existing foreign object as a pointer to a C function that expects a pointer. You certainly don't need a different CFFI type for every such a pointer parameter. |
Also: are any of these redundant types ever deleted? There is also a slew of activity involving creating types in gobject.boxed-lisp.lisp, for instance, that is simply impossible to follow. It looks like there is a whole other layer of translation involving creating new types... And for slotted objects, this is done for every slot?
|
And CLOS dispatches translate-to-foreign and free-translated-object using these correctly, since each of these foreign type instances has the same CL type. |
Just out of curiosity I created a patch here that caches these before giving them to CFFI. I can't measure any noticeable difference (neither in memory usage, nor in speed of loading), maybe you can. |
This is not what I expect from a type parser! Compare this behaviour with:
This implies that every mention of a cl-cffi-gtk-managed type in defcfun bindings likely creates a new type inside CFFI machinery. This means thousands of unnecessary types are generated, and type equality is not consistent.
@Ferada - have you come across this?
Edit: implemented in gobject/gobject.base.lisp DEFINE-PARSE-METHOD...
cffi parses types to convert parameters to and from foreign...
I suppose this can go unnoticed since all these types do the same thing... I would have missed it myself - but my CFFI introspection tools use the actual cffi types to reason about parameter types...
The text was updated successfully, but these errors were encountered: