public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, MELT] correct meltgc_read_from_val without location
@ 2011-06-24 17:36 Pierre Vittet
  2011-06-29 20:50 ` Pierre
  0 siblings, 1 reply; 3+ messages in thread
From: Pierre Vittet @ 2011-06-24 17:36 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 463 bytes --]

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

[-- Attachment #2: correct_read_from_val_without_location-175348.diff --]
[-- Type: text/plain, Size: 2264 bytes --]

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;

[-- Attachment #3: correct_read_from_val_without_location-175348.ChangeLog --]
[-- Type: text/plain, Size: 209 bytes --]

2011-06-24  Pierre Vittet  <piervit@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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-29 19:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-24 17:36 [PATCH, MELT] correct meltgc_read_from_val without location Pierre Vittet
2011-06-29 20:50 ` Pierre
2011-06-29 20:51   ` Basile Starynkevitch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).