After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 542920 - Make a Vala.Report per context
Make a Vala.Report per context
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: general
0.3.x
Other All
: Normal normal
: ---
Assigned To: Jürg Billeter
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-07-14 13:01 UTC by Abderrahim Kitouni
Modified: 2009-02-23 20:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Here is a patch for the problem that tries to do minimal changes to the interface (9.73 KB, patch)
2008-07-14 13:10 UTC, Abderrahim Kitouni
none Details | Review
Updated patch : Report.{error,warning} accept only non null source reference (16.43 KB, patch)
2008-07-17 14:29 UTC, Abderrahim Kitouni
needs-work Details | Review
fix (2.83 KB, patch)
2009-01-25 02:42 UTC, Adam Dingle
reviewed Details | Review
latest diff (15.81 KB, patch)
2009-01-28 08:51 UTC, Abderrahim Kitouni
reviewed Details | Review
g_log-like solution (2.83 KB, patch)
2009-02-07 14:18 UTC, Abderrahim Kitouni
reviewed Details | Review

Description Abderrahim Kitouni 2008-07-14 13:01:04 UTC
Please describe the problem:
Vala.Report is now a namespace, which has the problem that multiple CodeContext's in the same application share the same error reporting, besides, one cannot substitute a specific reporting mechanism for the default one.

Attached is a patch that tries to solve the problem with minimal changes

Steps to reproduce:


Actual results:


Expected results:


Does this happen every time?


Other information:
Comment 1 Abderrahim Kitouni 2008-07-14 13:10:00 UTC
Created attachment 114523 [details] [review]
Here is a patch for the problem that tries to do minimal changes to the interface

I've made Report a class, renamed error and warning to err and warn respectively, added a report (construct) property in CodeContext, and added two static methods to Report error and warning that can be used like the old error and warning and call the appropriate instance's err and warn.

The instance is obtained from the context referenced by the SourceReference passed to error or warning.

I've also modified parsers, valac, vapigen, and ccodegenerator to use the new interface for get_errors (since it cannot be made static).
Comment 2 Abderrahim Kitouni 2008-07-17 14:29:59 UTC
Created attachment 114720 [details] [review]
Updated patch : Report.{error,warning} accept only non null source reference

I've also modified all "Report.error (null, ..." to use context.report.err, there remains only three instances that cannot use it because they are in static methods, any ideas about it ?

vala/valasemanticanalyzer.vala:1914
gobject/valaccodecompiler.vala:40
gobject/valaccodegenerator.vala:3976
Comment 3 Tobias Mueller 2008-08-25 12:21:26 UTC
At least it applies on compiles.
Comment 4 Jürg Billeter 2008-10-03 12:18:54 UTC
Thanks for the patch. We can probably change them to instance methods.
Comment 5 Abderrahim Kitouni 2008-12-06 09:45:27 UTC
I'm not sure this is the right way to do it, maybe internal errors (I think this is the only use of Report.error (null, ...)) should use the default instance.
Comment 6 Johannes Schmid 2009-01-05 18:41:05 UTC
Any news on this?
Comment 7 Jürg Billeter 2009-01-11 23:23:21 UTC
I just thought about an alternative solution. What about keeping a context stack around and always report errors and warnings to the current (i.e. topmost) context?

class CodeContext {
    ...
    Report report;
    static List<CodeContext> stack;

    static CodeContext get () {
        return stack.get (stack.size - 1);
    }

    static void push (CodeContext context) {
        stack.add (context);
    }

    static void pop () {
        stack.remove_at (stack.size - 1);
    }
}

class Report {
    ...
    static void error (...) {
        CodeContext.get ().report.err (...);
    }
}

Whenever you want to switch context you do:

CodeContext.push (other_context);
// call other methods
CodeContext.pop ();

This should be flexible and still easy to use. Would this be ok for your usecase?
Comment 8 Abderrahim Kitouni 2009-01-14 13:19:43 UTC
Seems ok to me, All I need is getting error reports for the code context I'm interested in to report them in the GUI.
Comment 9 Adam Dingle 2009-01-24 11:26:43 UTC
I'm highly interested in seeing Vala support in Anjuta, and I'd love to try out Abderrahim's language support plugin described at http://abderrahim.arablug.org/blog/ .  Unfortunately that plugin depends on the patches attached to this bug, and those patches were made last July, so I can't easily apply them to a current version of Vala.

So Vala support in Anjuta is effectively blocked on this bug.  Abderrahim, are you planning to create an updated version of the patches based on Jurg's suggestion above?  If you have no time for this, please let us know and perhaps someone else can help out.
Comment 10 Adam Dingle 2009-01-25 01:22:43 UTC
Other possible solutions:

- We could keep a stack of Report objects around and simply always report to the topmost Report.

- We could simply have a global Report object which can be replaced if the caller wants custom error handling.

None of these solutions (including the CodeContext stack) are thread-safe; they will all fail if more than one thread is trying to invoke the Vala compiler at the same time.  Then again, the compiler evidently wasn't intended to be thread-safe anyway since the code uses statics in many places.

Comment 11 Adam Dingle 2009-01-25 02:42:08 UTC
Created attachment 127179 [details] [review]
fix

Here's a fix that implements the simplest of my suggestions above: it allows the caller to provide a global Report object for custom error handling.  This is a very small change, and should be adequate for the Anjuta plugin's needs.  I personally see no reason to implement a stack of Report or CodeContext objects; that still wouldn't be thread-safe, and I'm not aware that any libvala caller requires such a capability.

Note that even with this patch, the Anjuta plugin still won't build; it's fallen out of date with the Vala codebase for other reasons unrelated to Report objects (e.g. it expects a method Vala.Scope.get_symbol_table(), which does not presently exist).  I hope we can bring the plugin back to life soon.
Comment 12 Abderrahim Kitouni 2009-01-25 14:19:03 UTC
Hi Adam,

I've already fixed the API change, I'll try to push it tomorrow.
About get_symbol_table, I thought I've already sent a patch for it. seems I didn't.
I'll try to post everything needed to have something working tomorrow.

The solution I suggest is something like g_log where one would add a callback to handle the error report.
Comment 13 Abderrahim Kitouni 2009-01-28 08:51:28 UTC
Created attachment 127384 [details] [review]
latest diff

Here is the diff of what I'm using now, you should be able to compile and run the plugin with this and the latest revision from hg
Comment 14 Abderrahim Kitouni 2009-02-07 14:18:56 UTC
Created attachment 128162 [details] [review]
g_log-like solution

Here is a patch trying to solve the issue in another way, it doesn't make
Vala.Report a type, instead one just registers a callback.
Comment 15 Jürg Billeter 2009-02-20 15:05:15 UTC
2009-02-20  Jürg Billeter  <j@bitron.ch>

	* vala/valacodecontext.vala:
	* vala/valareport.vala:

	Support context-specific error reporting and add a context stack,
	based on patch by Abderrahim Kitouni, fixes bug 542920

	* vala/valagenieparser.vala:
	* vala/valaparser.vala:
	* gobject/valaccodebasemodule.vala:
	* compiler/valacompiler.vala:
	* vapigen/valavapigen.vala:

	Adapt to interface changes

Fixed in r2461.
Comment 16 Andrea Del Signore 2009-02-23 20:54:17 UTC
I wish I've seen this bug before, since I'm a multithread user of libvala and this change has a severe impact on the completion engine of Vala Toys for gEdit.

Can we rethink all of this along the lines of comment #14 ?

I used libvala for some time now with two thread and at least the Parser seem thread safe. For Vtg it's pretty useful to use one thread to parse the sources that change frequently during the editing (e.g. the opened ones) and another for all the other project sources and referenced vapis.