[m-rev.] diff: workaround problems with cairo binding in LLDS grades

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Sep 8 00:04:02 AEST 2010


The problem here is caused by the fact that in low-level C grades the
.mh file for a parent module is not #included in the .c file for a child
module until after the .mh file for the child is #included in the .c file
for the child.  This doesn't occur with the high-level C grades because
the .mih files are #included in the correct order.

The reference manual doesn't spell out whether the contents of a parent
module's foreign_decl pragmas should be visible to
foreign_{decl,type,export} pragmas in its children.
(It does suggest using pragma foreign_import_module, but that doesn't
work for the case below as the resulting #includes still occur too late.)

For the high-level C backend the parent's foreign_decl pragmas are
visible in the children.  This is a consequence of the order in which
.mih files are #included in child .c files.

I propose that we alter the order in which .mh files are #included in
low-level C grade, so that the parents .mh file is first.  The current
lack of consistency between the two backends is a bit of a pain.

Additionally, we could specify that for C foreign_decl pragmas in
a parent module are automatically visible in C foreign_decl pragmas
in a child.

Thoughts?

-------------------

Workaround a problem that prevented the cairo binding from compiling
in low-level C grades.

extras/graphics/mercury_cairo/cairo.image.m:
extras/graphics/mercury_cairo/cairo.pdf.m:
extras/graphics/mercury_cairo/cairo.ps.m:
extras/graphics/mercury_cairo/cairo.svg.m:
 	Ensure that C data structures defined in foreign_decl pragmas in the
 	parent of the above modules are visible before they are used in the
 	above modules.

Julien.

Index: cairo.image.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/graphics/mercury_cairo/cairo.image.m,v
retrieving revision 1.1
diff -u -r1.1 cairo.image.m
--- cairo.image.m	5 Sep 2010 14:31:44 -0000	1.1
+++ cairo.image.m	7 Sep 2010 13:34:04 -0000
@@ -56,6 +56,8 @@

  :- implementation.

+:- pragma foreign_decl("C", "#include \"cairo.mh\"").
+
  :- pragma foreign_type("C", image_surface, "MCAIRO_surface *",
  	[can_pass_as_mercury_type]).

Index: cairo.pdf.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/graphics/mercury_cairo/cairo.pdf.m,v
retrieving revision 1.1
diff -u -r1.1 cairo.pdf.m
--- cairo.pdf.m	5 Sep 2010 14:31:44 -0000	1.1
+++ cairo.pdf.m	7 Sep 2010 13:34:04 -0000
@@ -51,6 +51,8 @@

  :- pragma foreign_decl("C", "

+#include \"cairo.mh\"
+
  #if defined(CAIRO_HAS_PDF_SURFACE)
    #include <cairo-pdf.h>
  #endif
Index: cairo.ps.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/graphics/mercury_cairo/cairo.ps.m,v
retrieving revision 1.1
diff -u -r1.1 cairo.ps.m
--- cairo.ps.m	5 Sep 2010 14:31:44 -0000	1.1
+++ cairo.ps.m	7 Sep 2010 13:34:05 -0000
@@ -62,6 +62,8 @@

  :- pragma foreign_decl("C", "

+#include \"cairo.mh\"
+
  #if defined(CAIRO_HAS_PS_SURFACE)
    #include <cairo-ps.h>
  #endif
Index: cairo.svg.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/graphics/mercury_cairo/cairo.svg.m,v
retrieving revision 1.1
diff -u -r1.1 cairo.svg.m
--- cairo.svg.m	5 Sep 2010 14:31:44 -0000	1.1
+++ cairo.svg.m	7 Sep 2010 13:34:05 -0000
@@ -54,6 +54,8 @@

  :- pragma foreign_decl("C", "

+#include \"cairo.mh\"
+
  #if defined(CAIRO_HAS_SVG_SURFACE)
    #include <cairo-svg.h>
  #endif

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list