[cairo-commit] pycairo/cairo cairomodule.c, 1.27, 1.28 cairogtkmodule.c, 1.15, 1.16 cairosvgmodule.c, 1.2, 1.3 pycairo-surface.c, 1.31, 1.32 pycairo-pattern.c, 1.15, 1.16 pycairo-matrix.c, 1.12, 1.13 pycairo-font.c, 1.11, 1.12 pycairo-context.c, 1.43, 1.44 pycairo-private.h, 1.18, 1.19 pycairosvg-context.c, 1.3, 1.4 pycairosvg-private.h, 1.1, 1.2 pycairo.h, 1.25, 1.26

Steve Chaplin commit at pdx.freedesktop.org
Fri May 6 06:46:15 PDT 2005


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv18616/cairo

Modified Files:
	cairomodule.c cairogtkmodule.c cairosvgmodule.c 
	pycairo-surface.c pycairo-pattern.c pycairo-matrix.c 
	pycairo-font.c pycairo-context.c pycairo-private.h 
	pycairosvg-context.c pycairosvg-private.h pycairo.h 
Log Message:
SC

Index: cairomodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairomodule.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- cairomodule.c	6 May 2005 04:01:42 -0000	1.27
+++ cairomodule.c	6 May 2005 13:46:13 -0000	1.28
@@ -103,19 +103,28 @@
     { NULL, NULL, 0 }
 };
 
-static struct _PyCairo_FunctionStruct api = {
+/* C API.  Clients get at this via PyCairo_IMPORT, defined in pycairo.h.
+ */
+static PyCairo_CAPI_t CAPI = {
+    &PyCairoContext_Type,  
+    &PyCairoFontFace_Type, 
+    &PyCairoMatrix_Type,   
+    &PyCairoPattern_Type,  
+    &PyCairoSurface_Type,  
+
+    PyCairoContext_FromContext,
+    PyCairoFontFace_FromFontFace,
+    PyCairoMatrix_FromMatrix,
+    PyCairoPattern_FromPattern,
+    PyCairoSurface_FromSurface,
+
     pycairo_check_status,
-    &PyCairoContext_Type,  PyCairoContext_FromContext,
-    &PyCairoFontFace_Type, PyCairoFontFace_FromFontFace,
-    &PyCairoMatrix_Type,   PyCairoMatrix_FromMatrix,
-    &PyCairoPattern_Type,  PyCairoPattern_FromPattern,
-    &PyCairoSurface_Type,  PyCairoSurface_FromSurface,
 };
 
 DL_EXPORT(void)
 init_cairo(void)
 {
-    PyObject *mod;
+    PyObject *m;
 
     if (PyType_Ready(&PyCairoContext_Type) < 0)
         return;
@@ -133,22 +142,29 @@
     if (PyType_Ready(&PyCairoPDFSurface_Type) < 0)
         return;
 
-    mod = Py_InitModule("cairo._cairo", cairo_functions);
+    m = Py_InitModule("cairo._cairo", cairo_functions);
 
-    PyModule_AddObject(mod, "Context", (PyObject *)&PyCairoContext_Type);
-    PyModule_AddObject(mod, "FontFace",(PyObject *)&PyCairoFontFace_Type);
-    PyModule_AddObject(mod, "Matrix",  (PyObject *)&PyCairoMatrix_Type);
-    PyModule_AddObject(mod, "Pattern", (PyObject *)&PyCairoPattern_Type);
+    Py_INCREF(&PyCairoContext_Type);
+    PyModule_AddObject(m, "Context", (PyObject *)&PyCairoContext_Type);
+    Py_INCREF(&PyCairoFontFace_Type);
+    PyModule_AddObject(m, "FontFace",(PyObject *)&PyCairoFontFace_Type);
+    Py_INCREF(&PyCairoMatrix_Type);
+    PyModule_AddObject(m, "Matrix",  (PyObject *)&PyCairoMatrix_Type);
+    Py_INCREF(&PyCairoPattern_Type);
+    PyModule_AddObject(m, "Pattern", (PyObject *)&PyCairoPattern_Type);
 
-    PyModule_AddObject(mod, "Surface", (PyObject *)&PyCairoSurface_Type);
-    PyModule_AddObject(mod, "ImageSurface", (PyObject *)&PyCairoImageSurface_Type);
-    PyModule_AddObject(mod, "PDFSurface", (PyObject *)&PyCairoPDFSurface_Type);
+    Py_INCREF(&PyCairoSurface_Type);
+    PyModule_AddObject(m, "Surface", (PyObject *)&PyCairoSurface_Type);
+    Py_INCREF(&PyCairoImageSurface_Type);
+    PyModule_AddObject(m, "ImageSurface", (PyObject *)&PyCairoImageSurface_Type);
+    Py_INCREF(&PyCairoPDFSurface_Type);
+    PyModule_AddObject(m, "PDFSurface", (PyObject *)&PyCairoPDFSurface_Type);
+
+    PyModule_AddObject(m, "pycairo_CAPI", PyCObject_FromVoidPtr(&CAPI, NULL));
 
-    PyModule_AddObject(mod, "_PyCairo_API",
-		       PyCObject_FromVoidPtr(&api, NULL));
 
     /* constants */
-#define CONSTANT(x) PyModule_AddIntConstant(mod, #x, CAIRO_##x)
+#define CONSTANT(x) PyModule_AddIntConstant(m, #x, CAIRO_##x)
     CONSTANT(FORMAT_ARGB32);
     CONSTANT(FORMAT_RGB24);
     CONSTANT(FORMAT_A8);
@@ -198,5 +214,4 @@
     CONSTANT(EXTEND_REPEAT);
     CONSTANT(EXTEND_REFLECT);
 #undef CONSTANT
-
 }

Index: cairogtkmodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairogtkmodule.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- cairogtkmodule.c	13 Apr 2005 10:20:04 -0000	1.15
+++ cairogtkmodule.c	6 May 2005 13:46:13 -0000	1.16
@@ -35,7 +35,6 @@
 #  include <config.h>
 #endif
 #include "pycairo.h"
-#include "pycairo-misc.h"
 #include <cairo-xlib.h>
 
 #include <pygtk/pygtk.h>
@@ -298,7 +297,7 @@
 
     mod = Py_InitModule("cairo.gtk", cairogtk_functions);
 
-    init_pycairo();
+    PyCairo_IMPORT;
     init_pygtk();
 
     mod = PyImport_ImportModule("gtk.gdk");

Index: cairosvgmodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairosvgmodule.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cairosvgmodule.c	11 Mar 2005 17:03:05 -0000	1.2
+++ cairosvgmodule.c	6 May 2005 13:46:13 -0000	1.3
@@ -71,7 +71,7 @@
     if (mod == NULL)
 	return;
 
-    init_pycairo();
+    PyCairo_IMPORT;
 
     Py_INCREF(&PyCairoSVGContext_Type);
     PyModule_AddObject(mod, "Context", (PyObject *)&PyCairoSVGContext_Type);

Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- pycairo-surface.c	6 May 2005 02:00:41 -0000	1.31
+++ pycairo-surface.c	6 May 2005 13:46:13 -0000	1.32
@@ -36,7 +36,6 @@
 #  include <config.h>
 #endif
 #include "pycairo-private.h"
-#include "pycairo-misc.h"
 
 #ifdef HAVE_NUMPY
 #  include <Numeric/arrayobject.h>

Index: pycairo-pattern.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-pattern.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- pycairo-pattern.c	15 Apr 2005 03:25:37 -0000	1.15
+++ pycairo-pattern.c	6 May 2005 13:46:13 -0000	1.16
@@ -35,7 +35,6 @@
 #  include <config.h>
 #endif
 #include "pycairo-private.h"
-#include "pycairo-misc.h"
 
 
 /* PyCairoPattern_FromPattern

Index: pycairo-matrix.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-matrix.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- pycairo-matrix.c	4 May 2005 04:10:00 -0000	1.12
+++ pycairo-matrix.c	6 May 2005 13:46:13 -0000	1.13
@@ -35,7 +35,6 @@
 #  include <config.h>
 #endif
 #include "pycairo-private.h"
-#include "pycairo-misc.h"
 
 
 /* PyCairoMatrix_FromMatrix

Index: pycairo-font.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-font.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- pycairo-font.c	14 Apr 2005 08:55:40 -0000	1.11
+++ pycairo-font.c	6 May 2005 13:46:13 -0000	1.12
@@ -35,7 +35,6 @@
 #  include <config.h>
 #endif
 #include "pycairo-private.h"
-#include "pycairo-misc.h"
 
 
 /* PyCairoFontFace_FromFontFace

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- pycairo-context.c	6 May 2005 02:00:41 -0000	1.43
+++ pycairo-context.c	6 May 2005 13:46:13 -0000	1.44
@@ -36,7 +36,6 @@
 #  include <config.h>
 #endif
 #include "pycairo-private.h"
-#include "pycairo-misc.h"
 
 /* PyCairoContext_FromContext
  * Create a new PyCairoContext from a cairo_t

Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-private.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- pycairo-private.h	27 Apr 2005 07:34:50 -0000	1.18
+++ pycairo-private.h	6 May 2005 13:46:13 -0000	1.19
@@ -40,6 +40,7 @@
 
 #define _INSIDE_PYCAIRO_
 #include "pycairo.h"
+#include "pycairo-misc.h"
 
 
 extern PyTypeObject PyCairoContext_Type;

Index: pycairosvg-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairosvg-context.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- pycairosvg-context.c	25 Mar 2005 03:18:55 -0000	1.3
+++ pycairosvg-context.c	6 May 2005 13:46:13 -0000	1.4
@@ -39,7 +39,6 @@
 #endif
 
 #include "pycairo.h"
-#include "pycairo-misc.h"
 #include "pycairosvg-private.h"
 
 

Index: pycairosvg-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairosvg-private.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pycairosvg-private.h	10 Dec 2004 15:15:46 -0000	1.1
+++ pycairosvg-private.h	6 May 2005 13:46:13 -0000	1.2
@@ -40,6 +40,7 @@
 
 #define _INSIDE_PYCAIROSVG_
 #include <svg-cairo.h>
+#include "pycairo-misc.h"
 
 extern PyTypeObject PyCairoSVGContext_Type;
 

Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- pycairo.h	2 May 2005 02:25:51 -0000	1.25
+++ pycairo.h	6 May 2005 13:46:13 -0000	1.26
@@ -76,58 +76,50 @@
 #define PyCairoImageSurface PyCairoSurface
 #define PyCairoPDFSurface   PyCairoSurface
 
-struct _PyCairo_FunctionStruct {
+/* Define structure for C API. */
+typedef struct {
+    /* type objects */
+    PyTypeObject *Context_Type;
+    PyTypeObject *FontFace_Type;
+    PyTypeObject *Matrix_Type;
+    PyTypeObject *Pattern_Type;
+    PyTypeObject *Surface_Type;
+
+    /* constructors */
+    PyObject *(*Context_FromContext)(cairo_t *ctx);
+    PyObject *(*FontFace_FromFontFace)(cairo_font_face_t *font_face);
+    PyObject *(*Matrix_FromMatrix)(const cairo_matrix_t *matrix);
+    PyObject *(*Pattern_FromPattern)(cairo_pattern_t *pattern);
+    PyObject *(*Surface_FromSurface)(cairo_surface_t *surface, PyObject *base);
+
+    /* misc functions */
     int (* check_status)(cairo_status_t status);
-    PyTypeObject *context_type;
-    PyObject *(* context_wrap)(cairo_t *ctx);
-    PyTypeObject *font_type;
-    PyObject *(* font_wrap)(cairo_font_face_t *font_face);
-    PyTypeObject *matrix_type;
-    PyObject *(* matrix_wrap)(const cairo_matrix_t *matrix);
-    PyTypeObject *pattern_type;
-    PyObject *(* pattern_wrap)(cairo_pattern_t *pattern);
-    PyTypeObject *surface_type;
-    PyObject *(* surface_wrap)(cairo_surface_t *surface, PyObject *base);
-};
+} PyCairo_CAPI_t;
+
 
 #ifndef _INSIDE_PYCAIRO_
 
-#if defined(NO_IMPORT) || defined(NO_IMPORT_PYCAIRO)
-extern struct _PyCairo_FunctionStruct *_PyCairo_API;
-#else
-struct _PyCairo_FunctionStruct *_PyCairo_API;
-#endif
+/* Macros for accessing the C API */
+#define PyCairoContext_Type         *(PyCairo_CAPI->Context_Type)
+#define PyCairoFontFace_Type        *(PyCairo_CAPI->Fontface_Type)
+#define PyCairoMatrix_Type          *(PyCairo_CAPI->Matrix_Type)
+#define PyCairoPattern_Type         *(PyCairo_CAPI->Pattern_Type)
+#define PyCairoSurface_Type         *(PyCairo_CAPI->Surface_Type)
 
-#define pycairo_check_status         (_PyCairo_API->check_status)
-#define PyCairoContext_Type         *(_PyCairo_API->context_type)
-#define PyCairoContext_FromContext   (_PyCairo_API->context_wrap)
-#define PyCairoFontFace_Type        *(_PyCairo_API->font_type)
-#define PyCairoFontFace_FronFontFace (_PyCairo_API->font_wrap)
-#define PyCairoMatrix_Type          *(_PyCairo_API->matrix_type)
-#define PyCairoMatrix_FromMatrix     (_PyCairo_API->matrix_wrap)
-#define PyCairoPattern_Type         *(_PyCairo_API->pattern_type)
-#define PyCairoPattern_FromPattern   (_PyCairo_API->pattern_wrap)
-#define PyCairoSurface_Type         *(_PyCairo_API->surface_type)
-#define PyCairoSurface_FromSurface   (_PyCairo_API->surface_wrap)
+#define PyCairoContext_FromContext   (PyCairo_CAPI->Context_FromContext)
+#define PyCairoFontFace_FromFontFace (PyCairo_CAPI->Fontface_FromFontFace)
+#define PyCairoMatrix_FromMatrix     (PyCairo_CAPI->Matrix_FromMatrix)
+#define PyCairoPattern_FromPattern   (PyCairo_CAPI->Pattern_FromPattern)
+#define PyCairoSurface_FromSurface   (PyCairo_CAPI->Surface_FromSurface)
 
-#define init_pycairo() { \
-    PyObject *pycairo = PyImport_ImportModule("cairo._cairo"); \
-    if (pycairo != NULL) { \
-        PyObject *module_dict = PyModule_GetDict(pycairo); \
-        PyObject *cobject = PyDict_GetItemString(module_dict,"_PyCairo_API"); \
-        if (PyCObject_Check(cobject)) \
-            _PyCairo_API = (struct _PyCairo_FunctionStruct *) \
-                PyCObject_AsVoidPtr(cobject); \
-        else { \
-            PyErr_SetString(PyExc_RuntimeError, \
-                            "could not find _PyCairo_API object"); \
-            return; \
-        } \
-    } else { \
-        return; \
-    } \
-}
+#define pycairo_check_status         (PyCairo_CAPI->check_status)
 
-#endif
+/* Define global variable for the C API and a macro for setting it. */
+static PyCairo_CAPI_t *PyCairo_CAPI;
 
-#endif
+#define PyCairo_IMPORT \
+        PyCairo_CAPI = (PyCairo_CAPI_t*) PyCObject_Import("cairo", \
+                                                          "pycairo_CAPI")
+
+#endif /* ifndef _INSIDE_PYCAIRO_ */
+#endif /* ifndef _PYCAIRO_H_ */




More information about the cairo-commit mailing list