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 704685 - EvDocument uri and info not set
EvDocument uri and info not set
Status: RESOLVED FIXED
Product: evince
Classification: Core
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: Evince Maintainers
Evince Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-07-22 14:14 UTC by Alessandro Campagni
Modified: 2013-07-24 11:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
tentative patch (1.17 KB, patch)
2013-07-22 14:14 UTC, Alessandro Campagni
needs-work Details | Review
code moved in helper functions (3.11 KB, patch)
2013-07-23 11:55 UTC, Alessandro Campagni
needs-work Details | Review
now freeing uri when no more needed (3.20 KB, patch)
2013-07-24 10:31 UTC, Alessandro Campagni
committed Details | Review

Description Alessandro Campagni 2013-07-22 14:14:11 UTC
Created attachment 249809 [details] [review]
tentative patch

Using ev_document_get_uri and ev_document_get_title I noticed that (always null returned from the first and always segmentation fault calling the second) priv->uri and priv->info are not set when loading a document from a GFile through ev_document_load_gfile (while ev_document_load sets them correctly).

Alessandro
Comment 1 Carlos Garcia Campos 2013-07-22 17:11:17 UTC
Review of attachment 249809 [details] [review]:

Good catch, the problem also happens when loading from a stream, in that case we can't set a uri, but we can definitely load the info. Thanks.

::: libdocument/ev-document.c
@@ +418,3 @@
+	priv = document->priv;
+	priv->uri = g_file_get_uri (file);
+	priv->info = _ev_document_get_info (document);

I think we can move the info initialization to ev_document_setup_cache() so that it's also done for other load methods. I think we should also do the syntex initialization in this case, we could probably move it to a helper function and call it from here and ev_document_load.
Comment 2 Alessandro Campagni 2013-07-23 10:04:21 UTC
OK moving priv->info initialization in ev_document_setup_cache.
priv->synctex init should be done only when a uri is given someway and of course the document supports it, so we'll have a ev_document_setup_cache_for_uri (maybe with a better name!) called from ev_document_load and ev_document_load_gfile after ev_document_setup_cache to set priv->uri and priv->synctex_scanner when supported? Is this correct?

Thanks
Comment 3 Alessandro Campagni 2013-07-23 11:55:28 UTC
Created attachment 249887 [details] [review]
code moved in helper functions
Comment 4 Carlos Garcia Campos 2013-07-23 16:44:30 UTC
(In reply to comment #2)
> OK moving priv->info initialization in ev_document_setup_cache.
> priv->synctex init should be done only when a uri is given someway and of
> course the document supports it, so we'll have a
> ev_document_setup_cache_for_uri (maybe with a better name!) called from
> ev_document_load and ev_document_load_gfile after ev_document_setup_cache to
> set priv->uri and priv->synctex_scanner when supported? Is this correct?
> 
> Thanks

Not really, the syntex is not a cache but an initialization, so I would use a different method for that and call it in load and load_form_gfile. ev_document_initialize_syntex (document, uri); for example.
Comment 5 Carlos Garcia Campos 2013-07-23 16:48:38 UTC
Review of attachment 249887 [details] [review]:

Thanks.

::: libdocument/ev-document.c
@@ +424,2 @@
         ev_document_setup_cache (document);
+	ev_document_setup_cache_for_uri (document, g_file_get_uri (file));

g_file_get_uri returns a new allocated string, so you are leaking it here because ev_document_setup_cache_for_uri call g_strdup. As I said I think it's better to initializa the uri directly here and rename ev_document_setup_cache_for_uri to ev_document_initialize_syntex or something like that.
Comment 6 Alessandro Campagni 2013-07-24 10:30:52 UTC
(In reply to comment #5)
> Review of attachment 249887 [details] [review]:
> g_file_get_uri returns a new allocated string, so you are leaking it here
> because ev_document_setup_cache_for_uri call g_strdup. As I said I think it's
> better to initializa the uri directly here and rename
> ev_document_setup_cache_for_uri to ev_document_initialize_syntex or something
> like that.

You're right! thanks :) now I'm freeing it!
I moved synctex initialization code in a new function. I'm attaching the patch
Comment 7 Alessandro Campagni 2013-07-24 10:31:51 UTC
Created attachment 250015 [details] [review]
now freeing uri when no more needed
Comment 8 Carlos Garcia Campos 2013-07-24 11:12:56 UTC
Review of attachment 250015 [details] [review]:

Fixed the issues mentioned below and pushed to git master, thanks!

::: libdocument/ev-document.c
@@ +277,3 @@
+	priv = document->priv;
+
+	priv->uri = g_strdup (uri);

I don't think we need a helper function for a single line, and in this case makes things more complicated, see below.

@@ +289,3 @@
+		filename = g_filename_from_uri (uri, NULL, NULL);
+		if (filename != NULL) {
+			priv->synctex_scanner =

This doesn't build, priv hasn't been declared here.

@@ +433,3 @@
+	ev_document_setup_cache_for_uri (document, uri);
+	ev_document_initialize_synctex (document, uri);
+	g_free (uri);

We don't need to duplicate the uri if we initialize it directly here with:

priv->uri = g_file_get_uri (file);
Comment 9 Alessandro Campagni 2013-07-24 11:29:14 UTC
(In reply to comment #8)
> Review of attachment 250015 [details] [review]:
> 
> Fixed the issues mentioned below and pushed to git master, thanks!
> 
> ::: libdocument/ev-document.c
> @@ +277,3 @@
> +    priv = document->priv;
> +
> +    priv->uri = g_strdup (uri);
> 
> I don't think we need a helper function for a single line, and in this case
> makes things more complicated, see below.
> 
> @@ +289,3 @@
> +        filename = g_filename_from_uri (uri, NULL, NULL);
> +        if (filename != NULL) {
> +            priv->synctex_scanner =
> 
> This doesn't build, priv hasn't been declared here.

I'm sorry! I feel so stupid :) I was getting mad in squashing and cherry-picking to organize everything in a single commit that I forgot to build it! :)
Sorry and thanks for your patience.

> 
> @@ +433,3 @@
> +    ev_document_setup_cache_for_uri (document, uri);
> +    ev_document_initialize_synctex (document, uri);
> +    g_free (uri);
> 
> We don't need to duplicate the uri if we initialize it directly here with:
> 
> priv->uri = g_file_get_uri (file);

Cool!