Thanks, Greg; I understand now. +1 on the wrapper/aggregate structure
solution, which is somewhat less clumsy than forcing lots of libraries
to have userdata arguments where they might not otherwise need them.
-K
Greg Stein <gstein@lyra.org> writes:
> Actually, I think it can be summarized pretty simply:
>
> * FOO returns you an object OBJ, expecting you to pass it back to its
> functions at various (later) points in time
>
> * you want associate your own context with OBJ for other purposes
>
> * where does your context pointer go?
>
>
> In Gerald's recommendation, OBJ should have a context pointer in it for this
> purpose. Thus, given an OBJ, you can recover your context.
>
> Another direction is that you are acting as FOO, and need to return an OBJ,
> yet you want some private context. If the definition of OBJ doesn't allow
> this, then it gets trickier.
>
>
> I believe both directions are solved without the embedded context pointer,
> so I'm going to go ahead and back it out. For the first case, you wrap each
> "object" in another object:
>
> typedef struct {
> some_ptr my_data;
> int something_else;
>
> dav_resource *actual_resource;
>
> } my_dav_resource;
>
> ...
> my_dav_resource *rsrc;
>
> rsrc = apr_palloc(r->pool, sizeof(*rsrc));
> rsrc->actual_resoure = hooks->get_resource(...);
> rsrc->my_data = perl_object_wrapper(...);
>
> return rsrc;
> ...
>
>
> For the second case, you use embedded structures:
>
> typedef struct {
> dav_resource actual_resource;
>
> some_ptr my_data;
> int something_else;
> } my_dav_resource;
>
> ...
> my_dav_resource *rsrc;
>
> rsrc = apr_palloc(r->pool, sizeof(*rsrc));
> ...
> return &rsrc->actual_resource;
> ...
>
> void takes_a_resource(const dav_resource *r)
> {
> my_dav_resource *rsrc = (my_dav_resource *)r;
> ...
>
>
> On this second example, you could potentially need more code if the embedded
> structure isn't the first field:
>
> my_dav_resource *rsrc = (my_dav_resource *)((const char *)r -
> offsetof(my_dav_resource, actual_resource));
>
>
> This concept would apply to the mod_dav structures, too.
>
>
> Gerald: do you have any issues with this wrapper structure style?
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Sep 3 22:15:19 2002