This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [libcpp] maybe canonicalize system paths in line-map


On 26 April 2012 12:12, Dodji Seketeli <dodji@seketeli.org> wrote:
>
> So maybe it'd be better to canonicalize the _cpp_file::path when it's
> first build? ?One drawback of that approach would be that
> _cpp_file::path will then permanently loose the information about the
> current directory, that is indirectly encoded into the way the file path
> is originally built. ?But do we really need that information?

That seems better to me.

>
> +/* Canonicalize the path to FILE. Return the canonical form if it is
> + ? shorter, otherwise return the original. ?This function may free the
> + ? memory pointed by FILE. ?*/
> +
> +static char *
> +maybe_shorter_path (const char * file)
> +{
> + ?const char * file2 = lrealpath (file);
> + ?if (file2 && strlen (file2) < strlen (file))
> + ? ?{
> + ? ? ?/* Unfortunately, it is not safe to delete file, so we may leak
> + ? ? ? ?some memory. ?*/

Why not remove this comment and free file here with XDELETEVEC (file) ?

> + ?canonical_path = maybe_shorter_path (path);
> + ?if (canonical_path != NULL && canonical_path != path)
> + ? ?{
> + ? ? ?/* The canonical path was newly allocated. ?Let's free the
> + ? ? ? ?non-canonical one. ?*/
> + ? ? ?free (path);
> + ? ? ?path = canonical_path;
> + ? ?}
> +

This way you avoid doing all this extra work here.

Cheers,

Manuel.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]