Hello,

The function meltgc_read_from_val (in melt-runtime.c) takes two arguments, a string value and a second one which is a location. In the comments, it is written that we can pass a NULL pointer if we have no location (it is a direct string). However, this conduct MELT to crash because it doesn't handle correctly the absence of file.

This patch correct this, if there is no file, it create a "virtual" one which is named "stringBuffer".

Pierre Vittet
Index: gcc/melt-runtime.c
===================================================================
--- gcc/melt-runtime.c  (revision 175348)
+++ gcc/melt-runtime.c  (working copy)
@@ -6326,7 +6326,7 @@ melt_linemap_compute_current_location (struct read
 {
   int colnum = 1;
   int cix = 0;
-  if (!rd || !rd->rcurlin) 
+  if (!rd || !rd->rcurlin || !rd->rpfilnam)
     return;
   for (cix=0; cix<rd->rcol; cix++) {
     char c = rd->rcurlin[cix];
@@ -6702,13 +6702,22 @@ static melt_ptr_t
 makesexpr (struct reading_st *rd, int lineno, melt_ptr_t contents_p,
           location_t loc, bool ismacrostring)
 {
-  MELT_ENTERFRAME (4, NULL);
+  MELT_ENTERFRAME (5, NULL);
 #define sexprv  meltfram__.mcfr_varptr[0]
 #define contsv   meltfram__.mcfr_varptr[1]
 #define locmixv meltfram__.mcfr_varptr[2]
 #define sexpclassv meltfram__.mcfr_varptr[3]
+#define locnamv meltfram__.mcfr_varptr[4]
   contsv = contents_p;
   gcc_assert (melt_magic_discr ((melt_ptr_t) contsv) == MELTOBMAG_LIST);
+  /* If there is no filename associated, we create a false one, named
+    "stringBuffer".  */
+  if(rd->rpfilnam == NULL)
+    {
+      locnamv = meltgc_new_string ((meltobject_ptr_t) 
MELT_PREDEF(DISCR_STRING),
+                                   "stringBuffer");
+      rd->rpfilnam = (melt_ptr_t *) &locnamv;
+    }
   if (loc == 0)
     locmixv = meltgc_new_mixint ((meltobject_ptr_t) MELT_PREDEF 
(DISCR_MIXED_INTEGER),
                                    *rd->rpfilnam, (long) lineno);
@@ -6728,6 +6737,7 @@ makesexpr (struct reading_st *rd, int lineno, melt
   meltgc_touch (sexprv);
   MELT_EXITFRAME ();
   return (melt_ptr_t) sexprv;
+#undef locnamv
 #undef sexprv
 #undef contsv
 #undef locmixv
@@ -8414,6 +8424,7 @@ meltgc_read_from_val (melt_ptr_t strv_p, melt_ptr_
   strv = strv_p;
   locnamv = locnam_p;
   rbuf = 0;
+  seqv = meltgc_new_list ((meltobject_ptr_t) MELT_PREDEF (DISCR_LIST));
   strmagic = melt_magic_discr ((melt_ptr_t) strv);
   switch (strmagic)
     {
@@ -8442,7 +8453,10 @@ meltgc_read_from_val (melt_ptr_t strv_p, melt_ptr_
   rds.rlineno = 0;
   rds.rcurlin = rbuf;
   rd = &rds;
-  rds.rpfilnam = (melt_ptr_t *) & locnamv;
+  if(locnamv == NULL)
+    rds.rpfilnam = NULL;
+  else
+    rds.rpfilnam = (melt_ptr_t *) & locnamv;
   while (rdcurc ())
     {
       bool got = FALSE;
2011-06-24  Pierre Vittet  <pier...@pvittet.com>

        * melt-runtime.c (melt_linemap_compute_current_location, makesexpr,
        meltgc_read_from_val): Handle the case of reading a string sexp without
        given location.

Reply via email to