PATCH: Parallel compilation of class files

Mark Mitchell mark@codesourcery.com
Mon May 13 17:07:00 GMT 2002



--On Wednesday, May 08, 2002 10:41:37 PM -0300 Alexandre Oliva 
<aoliva@redhat.com> wrote:

> On May  8, 2002, Mark Mitchell <mark@codesourcery.com> wrote:
>
>> !       temporary_file_name = xmalloc (strlen (class_file_name)
>> ! 				     + strlen (".tmp") + 1);
>> !       sprintf (temporary_file_name, "%s.tmp", class_file_name);
>
> Consider using `concat (class_file_name, ".tmp");'
>
>> !       if (rename (temporary_file_name, class_file_name) == -1)
>> ! 	fatal_io_error ("can't create %s", class_file_name);
>
> wouldn't it be appropriate to unlink the temporary file in this case?

This patch, tested on i686-pc-linux-gnu, implements these suggestions.
Applied on the mainline.

Thanks for the ideas,

--
Mark Mitchell                mark@codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com

2002-05-13  Mark Mitchell  <mark@codesourcery.com>

	* jcf-write.c (write_classfile): Unlink the temporary file if it
	cannot be renamed.  Use concat to build up the name of the
	temporary file.

Index: jcf-write.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-write.c,v
retrieving revision 1.103
diff -c -p -r1.103 jcf-write.c
*** jcf-write.c	8 May 2002 19:24:40 -0000	1.103
--- jcf-write.c	13 May 2002 23:50:17 -0000
*************** write_classfile (clas)
*** 3380,3388 ****
        /* The .class file is initially written to a ".tmp" file so that
  	 if multiple instances of the compiler are running at once
  	 they do not see partially formed class files. */
!       temporary_file_name = xmalloc (strlen (class_file_name)
! 				     + strlen (".tmp") + 1);
!       sprintf (temporary_file_name, "%s.tmp", class_file_name);
        stream = fopen (temporary_file_name, "wb");
        if (stream == NULL)
  	fatal_io_error ("can't open %s for writing", temporary_file_name);
--- 3380,3386 ----
        /* The .class file is initially written to a ".tmp" file so that
  	 if multiple instances of the compiler are running at once
  	 they do not see partially formed class files. */
!       temporary_file_name = concat (class_file_name, ".tmp", NULL);
        stream = fopen (temporary_file_name, "wb");
        if (stream == NULL)
  	fatal_io_error ("can't open %s for writing", temporary_file_name);
*************** write_classfile (clas)
*** 3394,3400 ****
        if (fclose (stream))
  	fatal_io_error ("error closing %s", temporary_file_name);
        if (rename (temporary_file_name, class_file_name) == -1)
! 	fatal_io_error ("can't create %s", class_file_name);
        free (temporary_file_name);
        free (class_file_name);
      }
--- 3392,3401 ----
        if (fclose (stream))
  	fatal_io_error ("error closing %s", temporary_file_name);
        if (rename (temporary_file_name, class_file_name) == -1)
! 	{
! 	  remove (temporary_file_name);
! 	  fatal_io_error ("can't create %s", class_file_name);
! 	}
        free (temporary_file_name);
        free (class_file_name);
      }



More information about the Java mailing list