[cairo] pycairo fails with python 3.2

Steve stevech1097 at yahoo.com.au
Sun Mar 27 05:51:53 PDT 2011


On Thu, 2011-03-24 at 12:00 -0700, cairo-request at cairographics.org
wrote:

FA,
Thanks for the patch, its been applied to git.
I had a problem with waf configure with Python 3.2 also - I think it may
be a waf bug.
Steve

> Hello all,
> 
> Pycairo fails with Python 3.2 since it is still using the now
> deprecated PyCObject interface.
> 
> I managed to get the current release (1.8.10) working with
> the two patches added at the end of this message.
> 
> Apart from those I also had to use the standard Python
> distutils as the waf scripts failed at the configure stage.
> 
> 
> ****************************
> 
> --- cairomodule-orig.c  2011-03-23 16:44:59.000000000 +0100
> +++ cairomodule.c   2011-03-23 16:52:54.000000000 +0100
> @@ -70,7 +70,7 @@
>  }
>  
>  
> -/* C API.  Clients get at this via Pycairo_IMPORT, defined in
> pycairo.h.
> +/* C API.  Clients get at this via inport_cairo(), defined in
> pycairo.h.
>   */
>  static Pycairo_CAPI_t CAPI = {
>    &PycairoContext_Type,
> @@ -376,8 +376,11 @@
>    PyModule_AddObject(m, "XlibSurface",
>              (PyObject *)&PycairoXlibSurface_Type);
>  #endif
> -
> -  PyModule_AddObject(m, "CAPI", PyCObject_FromVoidPtr(&CAPI, NULL));
> + 
> +/* Create a Capsule containing the CAPI pointer */
> +  PyObject *T;
> +  T = PyCapsule_New((void *)(&CAPI), "cairo.CAPI", 0);
> +  if (T) PyModule_AddObject(m, "CAPI", T);
>  
>      /* constants */
>  #if CAIRO_HAS_ATSUI_FONT
> 
> 
> *****************************
> 
> --- py3cairo-orig.h 2010-05-29 07:21:37.000000000 +0200
> +++ py3cairo.h  2011-03-23 22:44:58.000000000 +0100
> @@ -193,13 +193,18 @@
>  #define Pycairo_Check_Status         (Pycairo_CAPI->Check_Status)
>  
>  
> -/* To access the Pycairo C API, edit the client module file to:
> - * 1) Add the following line to define a global variable for the C
> API
> - *    static Pycairo_CAPI_t *Pycairo_CAPI;
> - * 2) Add 'Pycairo_IMPORT;' to the init<module> function
> - */
> -#define Pycairo_IMPORT \
> -        Pycairo_CAPI = (Pycairo_CAPI_t*) PyCObject_Import("cairo",
> "CAPI")
> +/* To access the Pycairo C API, the client module should
> +   call 'import_cairo()' from the init<module> function,
> +   and check the return value, < 0 means the import failed.
> +*/
> +
> +static Pycairo_CAPI_t *Pycairo_CAPI;
> +
> +static int import_cairo(void)
> +{
> +  Pycairo_CAPI = (Pycairo_CAPI_t*) PyCapsule_Import("cairo.CAPI", 0);
> +  return (Pycairo_CAPI != 0) ? 0 : -1;
> +}
>  
>  #endif /* ifndef _INSIDE_PYCAIRO_ */
> 
> ********************************
> 
> 
> Ciao,
> 
> -- 
> FA 



More information about the cairo mailing list