[m-rev.] for review: fix library intialisers / finalisers

Julien Fischer juliensf at cs.mu.OZ.AU
Wed May 17 15:26:35 AEST 2006


On Wed, 17 May 2006, Zoltan Somogyi wrote:

> > -    if (need_initialization_code) {
> > -        printf("#define MR_MAY_NEED_INITIALIZATION\n\n");
> > +    if (num_errors > 0) {
> > +        fputs("/* Force syntax error, since there were */\n", stdout);
> > +        fputs("/* errors in the generation of this file */\n", stdout);
> > +        fputs("#error \"You need to remake this file\"\n", stdout);
> > +        if (output_file_name != NULL) {
> > +            (void) fclose(stdout);
> > +            (void) remove(output_file_name);
> > +        }
> > +        return EXIT_FAILURE;
> > +    }
> > +
> > +    return EXIT_SUCCESS;
>
> How do you force a syntax error in a .init file?
>
> I think this could should be in output_init_program, and some more tailored
> technique should be employed in output_lib_init_file.
>
> Otherwise that looks fine, though I don't know about the -use-mmc-make to
> check the changes to that part of the diff in detail.

Here's an interdiff addressing the review comments:

diff -u compiler/modules.m compiler/modules.m
--- compiler/modules.m	16 May 2006 06:40:22 -0000
+++ compiler/modules.m	17 May 2006 04:33:36 -0000
@@ -5,10 +5,10 @@
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
-
+%
 % File: modules.m.
 % Main author: fjh.
-
+%
 % This module contains all the code for handling module imports and exports,
 % for computing module dependencies, and for generating makefile fragments to
 % record those dependencies.
@@ -37,6 +37,7 @@
 % file gives the last time the .int0 file was checked.
 %
 %-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- module parse_tree.modules.
 :- interface.
@@ -5273,7 +5274,7 @@
         "\techo > ", InitFileName, "\n"
     ], !IO),
     io.write_strings(DepStream, [
-        "\t$(MKLIBINIT) -k ", "$(", MakeVarName, ".cs)", " >> ",
+        "\t$(MKLIBINIT) ", "$(", MakeVarName, ".cs)", " >> ",
         InitFileName, "\n"
     ], !IO),

diff -u scripts/Mmake.vars.in scripts/Mmake.vars.in
--- scripts/Mmake.vars.in	16 May 2006 06:17:39 -0000
+++ scripts/Mmake.vars.in	17 May 2006 04:55:32 -0000
@@ -360,7 +360,7 @@

 # Program used to create the .init file for a library.
 # This is usually just mkinit invoked with the `-k' option.
-MKLIBINIT	= mkinit
+MKLIBINIT	= mkinit -k

 # These only have an effect with `mmc --make'.
 LINKAGE = shared
diff -u util/mkinit.c util/mkinit.c
--- util/mkinit.c	15 May 2006 06:42:43 -0000
+++ util/mkinit.c	17 May 2006 04:50:39 -0000
@@ -516,8 +516,8 @@
                     const char **func_names, int num_func_names);
 static  void    output_main_init_function(Purpose purpose, int num_bunches);
 static  void    output_main(void);
-static  void    output_lib_init_file(void);
-static  void    output_init_program(void);
+static  int     output_lib_init_file(void);
+static  int     output_init_program(void);
 static  void    process_file(const char *filename);
 static  void    process_init_file(const char *filename);
 static  void    output_init_function(const char *func_name,
@@ -568,7 +568,8 @@
 {

     MR_progname = argv[0];
-
+    int exit_status;
+
     parse_options(argc, argv);

 #ifdef  CHECK_GET_LINE
@@ -578,24 +579,13 @@

     set_output_file();

-    if (output_lib_init == MR_TRUE) {
-        output_lib_init_file();         /* Output a .init file. */
+    if (output_lib_init) {
+        exit_status = output_lib_init_file();  /* Output a .init file. */
     } else {
-        output_init_program();          /* Output a _init.c file. */
+        exit_status = output_init_program();   /* Output a _init.c file. */
     }

-    if (num_errors > 0) {
-        fputs("/* Force syntax error, since there were */\n", stdout);
-        fputs("/* errors in the generation of this file */\n", stdout);
-        fputs("#error \"You need to remake this file\"\n", stdout);
-        if (output_file_name != NULL) {
-            (void) fclose(stdout);
-            (void) remove(output_file_name);
-        }
-        return EXIT_FAILURE;
-    }
-
-    return EXIT_SUCCESS;
+    return exit_status;
 }

 /*---------------------------------------------------------------------------*/
@@ -603,7 +593,7 @@
 /*
 ** Output the initialisation file for a Mercury library, the .init file.
 */
-static void
+static int
 output_lib_init_file(void)
 {
     int filenum;
@@ -624,6 +614,15 @@
     for (i = 0; i < req_final_module_next; i++) {
         printf("REQUIRED_FINAL %s\n", req_final_modules[i]);
     }
+
+    if (num_errors > 0) {
+        fprintf(stderr, "%s: error while creating .init file.\n",
+            MR_progname);
+        return EXIT_FAILURE;
+    } else {
+        return EXIT_SUCCESS;
+    }
+
 }

 /*---------------------------------------------------------------------------*/
@@ -632,7 +631,7 @@
 ** Output the initialisation program for a Mercury executable, the *_init.c
 ** file.
 */
-static void
+static int
 output_init_program(void)
 {
     int filenum;
@@ -690,6 +689,19 @@
     output_main_init_function(PURPOSE_REQ_FINAL, num_bunches);

     output_main();
+
+    if (num_errors > 0) {
+        fputs("/* Force syntax error, since there were */\n", stdout);
+        fputs("/* errors in the generation of this file */\n", stdout);
+        fputs("#error \"You need to remake this file\"\n", stdout);
+        if (output_file_name != NULL) {
+            (void) fclose(stdout);
+            (void) remove(output_file_name);
+        }
+        return EXIT_FAILURE;
+    }
+
+    return EXIT_SUCCESS;
 }

 /*---------------------------------------------------------------------------*/
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list