2008-05-11 Jürg Billeter <j@bitron.ch>
+ * ccode/valaccodewriter.vala:
+ * gobject/valaccodegeneratorsourcefile.vala:
+
+ Fix crash when opening output file fails, fixes bug 466573
+
+2008-05-11 Jürg Billeter <j@bitron.ch>
+
* gobject/valaccodegenerator.vala: fix freeing nested GLists and
GSLists, fixes bug 443514
}
construct {
_filename = value;
- file_exists = FileUtils.test (_filename, FileTest.EXISTS);
- if (file_exists) {
- temp_filename = "%s.valatmp".printf (_filename);
- stream = FileStream.open (temp_filename, "w");
- } else {
- stream = FileStream.open (_filename, "w");
- }
}
}
public CCodeWriter (string _filename) {
filename = _filename;
}
-
+
+ /**
+ * Opens the file.
+ *
+ * @return true if the file has been opened successfully,
+ * false otherwise
+ */
+ public bool open () {
+ file_exists = FileUtils.test (_filename, FileTest.EXISTS);
+ if (file_exists) {
+ temp_filename = "%s.valatmp".printf (_filename);
+ stream = FileStream.open (temp_filename, "w");
+ } else {
+ stream = FileStream.open (_filename, "w");
+ }
+
+ return (stream != null);
+ }
+
/**
* Closes the file.
*/
}
var writer = new CCodeWriter (source_file.get_cheader_filename ());
+ if (!writer.open ()) {
+ Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
+ return;
+ }
if (comment != null) {
comment.write (writer);
}
writer.close ();
writer = new CCodeWriter (source_file.get_csource_filename ());
+ if (!writer.open ()) {
+ Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
+ return;
+ }
writer.line_directives = context.debug;
if (comment != null) {
comment.write (writer);