Not sure what lltype to use in this case

I have a rather strange use-case for a data type in a rpython interpreter. What I need is a raw malloc, but with a custom GC hook. I understand how to setup the GC hook, but what I can't figure out is what lltype to use with malloc. This type will inherit directly from object so I don't need any polymorphism. However I do need the struct to be of a variable size. So something like the C struct hack: struct MyObject { Type* header; char data[0]; } Thanks, Timothy

Hi Timothy, On 10 March 2018 at 01:26, Timothy Baldridge <tbaldridge@gmail.com> wrote:
I have a rather strange use-case for a data type in a rpython interpreter. What I need is a raw malloc, but with a custom GC hook.
GC hooks make no sense with non-GC structures. Try to describe more what you're trying to achieve. For example, maybe you have some GC object that itself contains a pointer to the raw variable-sized structure, and you want the GC to follow references from this GC object to other GC objects via the raw variable-sized structure. Then you'd put the GC hook on this GC object. A bientôt, Armin.

Sorry about that, let me explain it at a higher level. I'm looking to make a runtime-defined GC'd struct. Some members will be GC'd others will be primitive. So I have a definition that says: Foo {member1=int, member2=Object, member3=float}
Timothy On Sat, Mar 10, 2018 at 12:26 AM, Armin Rigo <armin.rigo@gmail.com> wrote:
-- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth)

One thing I forgot to mention that I'm also trying to keep this as low-overhead as possible. So I'd like a struct of type MyStruct {member1=int} to be two words wide. One for the pointer to the StructDefinition, and the other for the (unwrapped) int. On Sat, Mar 10, 2018 at 6:37 AM, Timothy Baldridge <tbaldridge@gmail.com> wrote:
-- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth)

Hi Timothy, On 10 March 2018 at 16:02, Timothy Baldridge <tbaldridge@gmail.com> wrote:
Ok, that makes sense. But you have to consider also where such a raw MyStruct would live; that is, who has got the raw pointer to the MyStruct data? I would imagine that you want this pointer to be inside another GC object of a specific class. It's this GC object there that needs to have a custom GC hook. If you really want no such thing, then you still need to make an artificial GC object in order to have a place where you can stick the custom GC hook. Also, remember that the GC assumes 'x.custom_gc_hook()' always returns the same list by default; you need to manually call 'rgc.write_barrier(x)' whenever the custom GC hook on object 'x' would give a different answer. A bientôt, Armin.

Hi Timothy, On 10 March 2018 at 01:26, Timothy Baldridge <tbaldridge@gmail.com> wrote:
I have a rather strange use-case for a data type in a rpython interpreter. What I need is a raw malloc, but with a custom GC hook.
GC hooks make no sense with non-GC structures. Try to describe more what you're trying to achieve. For example, maybe you have some GC object that itself contains a pointer to the raw variable-sized structure, and you want the GC to follow references from this GC object to other GC objects via the raw variable-sized structure. Then you'd put the GC hook on this GC object. A bientôt, Armin.

Sorry about that, let me explain it at a higher level. I'm looking to make a runtime-defined GC'd struct. Some members will be GC'd others will be primitive. So I have a definition that says: Foo {member1=int, member2=Object, member3=float}
Timothy On Sat, Mar 10, 2018 at 12:26 AM, Armin Rigo <armin.rigo@gmail.com> wrote:
-- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth)

One thing I forgot to mention that I'm also trying to keep this as low-overhead as possible. So I'd like a struct of type MyStruct {member1=int} to be two words wide. One for the pointer to the StructDefinition, and the other for the (unwrapped) int. On Sat, Mar 10, 2018 at 6:37 AM, Timothy Baldridge <tbaldridge@gmail.com> wrote:
-- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth)

Hi Timothy, On 10 March 2018 at 16:02, Timothy Baldridge <tbaldridge@gmail.com> wrote:
Ok, that makes sense. But you have to consider also where such a raw MyStruct would live; that is, who has got the raw pointer to the MyStruct data? I would imagine that you want this pointer to be inside another GC object of a specific class. It's this GC object there that needs to have a custom GC hook. If you really want no such thing, then you still need to make an artificial GC object in order to have a place where you can stick the custom GC hook. Also, remember that the GC assumes 'x.custom_gc_hook()' always returns the same list by default; you need to manually call 'rgc.write_barrier(x)' whenever the custom GC hook on object 'x' would give a different answer. A bientôt, Armin.
participants (2)
-
Armin Rigo
-
Timothy Baldridge