user data (was Re: [cairo] Patch improving fallbacks)

Owen Taylor otaylor at redhat.com
Tue Feb 1 06:57:51 PST 2005


On Mon, 2005-01-31 at 18:09 -0500, Kristian Høgsberg wrote:

> > My current thought for user data for surfaces is something pretty
> > generic:
> > 
> >  cairo_key_t cairo_key_alloc (void);
> 
> What about just using a void pointer as key?
> 
> 	static int pdf_backend_data_key;
> 
> 	cairo_surface_set_data (&pdf_backend_data_key,
> 				some_pdf_data,
> 				destroy_some_pdf_data);

Not a bad idea. It doesn't make for very readable header file or
code to  me, however. (I guess I'm calling the kettle black here
on mysterious void * arguments.)

What if we did something like:

 typedef struct {
    int dummy;
 } cairo_key_t;

 void cairo_surface_set_data (const cairo_key_t   *key, 
                              void                *data,
                              cairo_destroy_func_t destroy);

It does prevent you from just using some random existing pointer
(well, without a cast...) but makes things a bit more self-documenting.

 static const cairo_key_t pdf_data_key;

Regards,
						Owen


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050201/45350ab0/attachment.pgp


More information about the cairo mailing list