Commit d57e5625 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

remove Error out parameters, use exceptions

2007-07-12  Juerg Billeter  <j@bitron.ch>

	* ccode/valaccodewriter.vala, gobject/valaccodecompiler.vala,
	  compiler/valacompiler.vala, vapi/glib-2.0.vala,
	  gobject-introspection/gidl.vala, vapigen/valagidlparser.vala,
	  vapigen/valavapigen.vala: remove Error out parameters, use exceptions

svn path=/trunk/; revision=352
parent ab1d99cd
2007-07-12 Jürg Billeter <j@bitron.ch>
* ccode/valaccodewriter.vala, gobject/valaccodecompiler.vala,
compiler/valacompiler.vala, vapi/glib-2.0.vala,
gobject-introspection/gidl.vala, vapigen/valagidlparser.vala,
vapigen/valavapigen.vala: remove Error out parameters, use exceptions
2007-07-12 Jürg Billeter <j@bitron.ch>
* gobject/valacodegenerator.vala: support exception handling in
......
......@@ -77,17 +77,21 @@ public class Vala.CCodeWriter {
if (file_exists) {
var changed = true;
var old_file = new MappedFile (_filename, false, null);
var new_file = new MappedFile (temp_filename, false, null);
var len = old_file.get_length ();
if (len == new_file.get_length ()) {
if (Memory.cmp (old_file.get_contents (), new_file.get_contents (), len) == 0) {
changed = false;
try {
var old_file = new MappedFile (_filename, false);
var new_file = new MappedFile (temp_filename, false);
var len = old_file.get_length ();
if (len == new_file.get_length ()) {
if (Memory.cmp (old_file.get_contents (), new_file.get_contents (), len) == 0) {
changed = false;
}
}
old_file = null;
new_file = null;
} catch (FileError e) {
// assume changed if mmap comparison doesn't work
}
old_file = null;
new_file = null;
if (changed) {
FileUtils.rename (temp_filename, _filename);
......
......@@ -122,15 +122,19 @@ class Vala.Compiler {
var deps_filename = Path.build_filename (Path.get_dirname (package_path), "%s.deps".printf (pkg));
if (FileUtils.test (deps_filename, FileTest.EXISTS)) {
string deps_content;
long deps_len;
FileUtils.get_contents (deps_filename, out deps_content, out deps_len, null);
foreach (string dep in deps_content.split ("\n")) {
if (dep != "") {
if (!add_package (context, dep)) {
Report.error (null, "%s, dependency of %s, not found in specified Vala API directories".printf (dep, pkg));
try {
string deps_content;
long deps_len;
FileUtils.get_contents (deps_filename, out deps_content, out deps_len);
foreach (string dep in deps_content.split ("\n")) {
if (dep != "") {
if (!add_package (context, dep)) {
Report.error (null, "%s, dependency of %s, not found in specified Vala API directories".printf (dep, pkg));
}
}
}
} catch (FileError e) {
Report.error (null, "Unable to read dependency file: %s".printf (e.message));
}
}
......@@ -255,15 +259,13 @@ class Vala.Compiler {
}
static int main (string[] args) {
Error err = null;
var opt_context = new OptionContext ("- Vala Compiler");
opt_context.set_help_enabled (true);
opt_context.add_main_entries (options, null);
opt_context.parse (out args, out err);
if (err != null) {
stdout.printf ("%s\n", err.message);
try {
var opt_context = new OptionContext ("- Vala Compiler");
opt_context.set_help_enabled (true);
opt_context.add_main_entries (options, null);
opt_context.parse (out args);
} catch (OptionError e) {
stdout.printf ("%s\n", e.message);
stdout.printf ("Run '%s --help' to see a full list of available command line options.\n", args[0]);
return 1;
}
......
......@@ -24,7 +24,7 @@
namespace GLib {
[CCode (cheader_filename = "gidlparser.h")]
public struct Idl {
public static List<IdlModule> parse_file (string! filename, out Error error);
public static List<IdlModule> parse_file (string! filename) throws MarkupError;
}
[CCode (cheader_filename = "gidlmodule.h")]
......
......@@ -49,12 +49,14 @@ public class Vala.CCodeCompiler {
}
string pkgflags;
int exit_status;
Error err = null;
if (!Process.spawn_command_line_sync (pc, out pkgflags, null, ref exit_status, out err)) {
Report.error (null, err.message);
return;
} else if (exit_status != 0) {
Report.error (null, "pkg-config exited with status %d".printf (exit_status));
try {
Process.spawn_command_line_sync (pc, out pkgflags, null, out exit_status);
if (exit_status != 0) {
Report.error (null, "pkg-config exited with status %d".printf (exit_status));
return;
}
} catch (SpawnError e) {
Report.error (null, e.message);
return;
}
......@@ -80,7 +82,14 @@ public class Vala.CCodeCompiler {
}
}
bool success = Process.spawn_command_line_sync (cmdline, null, null, ref exit_status, out err);
try {
Process.spawn_command_line_sync (cmdline, null, null, out exit_status);
if (exit_status != 0) {
Report.error (null, "cc exited with status %d".printf (exit_status));
}
} catch (SpawnError e) {
Report.error (null, e.message);
}
/* remove generated C source and header files */
foreach (SourceFile file in source_files) {
......@@ -89,11 +98,5 @@ public class Vala.CCodeCompiler {
FileUtils.unlink (file.get_cheader_filename ());
}
}
if (!success) {
Report.error (null, err.message);
} else if (exit_status != 0) {
Report.error (null, "cc exited with status %d".printf (exit_status));
}
}
}
This diff is collapsed.
......@@ -50,38 +50,40 @@ public class Vala.GIdlParser : CodeVisitor {
}
private void parse_file (SourceFile! source_file) {
Error error = null;
string metadata_filename = "%s.metadata".printf (source_file.filename.ndup (source_file.filename.size () - ".gidl".size ()));
codenode_attributes_map = new HashTable.full (str_hash, str_equal, g_free, g_free);
if (FileUtils.test (metadata_filename, FileTest.EXISTS)) {
string metadata;
long metadata_len;
FileUtils.get_contents (metadata_filename, out metadata, out metadata_len, out error);
foreach (string line in metadata.split ("\n")) {
var line_parts = line.split (" ", 2);
if (line_parts[0] == null) {
continue;
}
try {
string metadata;
long metadata_len;
FileUtils.get_contents (metadata_filename, out metadata, out metadata_len);
codenode_attributes_map.insert (line_parts[0], line_parts[1]);
foreach (string line in metadata.split ("\n")) {
var line_parts = line.split (" ", 2);
if (line_parts[0] == null) {
continue;
}
codenode_attributes_map.insert (line_parts[0], line_parts[1]);
}
} catch (FileError e) {
Report.error (null, "Unable to read metadata file: %s".printf (e.message));
}
}
var modules = Idl.parse_file (source_file.filename, out error);
if (error != null) {
stdout.printf ("error parsing GIDL file: %s\n", error.message);
}
current_source_reference = new SourceReference (source_file);
foreach (IdlModule module in modules) {
var ns = parse_module (module);
source_file.add_namespace (ns);
try {
var modules = Idl.parse_file (source_file.filename);
current_source_reference = new SourceReference (source_file);
foreach (IdlModule module in modules) {
var ns = parse_module (module);
source_file.add_namespace (ns);
}
} catch (MarkupError e) {
stdout.printf ("error parsing GIDL file: %s\n", e.message);
}
}
......
......@@ -172,17 +172,17 @@ class Vala.VAPIGen {
}
static int main (string[] args) {
Error err = null;
var opt_context = new OptionContext ("- Vala API Generator");
opt_context.set_help_enabled (true);
opt_context.add_main_entries (options, null);
opt_context.parse (out args, out err);
if (err != null) {
try {
var opt_context = new OptionContext ("- Vala API Generator");
opt_context.set_help_enabled (true);
opt_context.add_main_entries (options, null);
opt_context.parse (out args);
} catch (OptionError e) {
stdout.printf ("%s\n", e.message);
stdout.printf ("Run '%s --help' to see a full list of available command line options.\n", args[0]);
return 1;
}
if (sources == null) {
stderr.printf ("No source file specified.\n");
return 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment