cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Positional parameter p1[0].file contains temporarily munged filename, not original
@ 2018-12-18 21:36 Timur Tabi
  2018-12-18 22:07 ` Julia Lawall
  0 siblings, 1 reply; 9+ messages in thread
From: Timur Tabi @ 2018-12-18 21:36 UTC (permalink / raw)
  To: cocci

I added this line to my Python code:

    print >>sys.stderr, 'Warning: missing \\n on line %s in %s' %
(p1[0].line, p1[0].file)

and this is what it prints:

Warning: missing \n on line 813 in
/tmp/cocci_small_output-11011-b5932b-grgf100.c

So it looks like spatch is copying the file to the /tmp directory
before processing it.  Is there any way to get the original file name,
grgf100.c?
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Cocci] Positional parameter p1[0].file contains temporarily munged filename, not original
  2018-12-18 21:36 [Cocci] Positional parameter p1[0].file contains temporarily munged filename, not original Timur Tabi
@ 2018-12-18 22:07 ` Julia Lawall
  2018-12-19  0:39   ` Timur Tabi
  0 siblings, 1 reply; 9+ messages in thread
From: Julia Lawall @ 2018-12-18 22:07 UTC (permalink / raw)
  To: Timur Tabi; +Cc: cocci



On Tue, 18 Dec 2018, Timur Tabi wrote:

> I added this line to my Python code:
>
>     print >>sys.stderr, 'Warning: missing \\n on line %s in %s' %
> (p1[0].line, p1[0].file)
>
> and this is what it prints:
>
> Warning: missing \n on line 813 in
> /tmp/cocci_small_output-11011-b5932b-grgf100.c
>
> So it looks like spatch is copying the file to the /tmp directory
> before processing it.  Is there any way to get the original file name,
> grgf100.c?

When you make a change in a file, Coccinelle subsequently works on a file
in /tmp for the changed part.  The line numbers are also not reliable.  It
is better to collect this information before making any changes.

In OCaml, to get the name of the current file you can also use
Coccilib.files(). This returns a list of the files being processed, eg if
you put multiple files on the command line.  I don't know if this is
offerent in python too.

julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Cocci] Positional parameter p1[0].file contains temporarily munged filename, not original
  2018-12-18 22:07 ` Julia Lawall
@ 2018-12-19  0:39   ` Timur Tabi
  2018-12-19  6:21     ` Julia Lawall
  0 siblings, 1 reply; 9+ messages in thread
From: Timur Tabi @ 2018-12-19  0:39 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci, Timur Tabi

On Tue, Dec 18, 2018 at 4:08 PM Julia Lawall <julia.lawall@lip6.fr> wrote:
> When you make a change in a file, Coccinelle subsequently works on a file
> in /tmp for the changed part.  The line numbers are also not reliable.  It
> is better to collect this information before making any changes.

I've noticed that the line number is not reliable.  I guess the only
reliable piece of information is the function name.
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Cocci] Positional parameter p1[0].file contains temporarily munged filename, not original
  2018-12-19  0:39   ` Timur Tabi
@ 2018-12-19  6:21     ` Julia Lawall
  2018-12-19 13:32       ` Timur Tabi
  2019-01-22 18:36       ` Timur Tabi
  0 siblings, 2 replies; 9+ messages in thread
From: Julia Lawall @ 2018-12-19  6:21 UTC (permalink / raw)
  To: Timur Tabi; +Cc: cocci



On Tue, 18 Dec 2018, Timur Tabi wrote:

> On Tue, Dec 18, 2018 at 4:08 PM Julia Lawall <julia.lawall@lip6.fr> wrote:
> > When you make a change in a file, Coccinelle subsequently works on a file
> > in /tmp for the changed part.  The line numbers are also not reliable.  It
> > is better to collect this information before making any changes.
>
> I've noticed that the line number is not reliable.  I guess the only
> reliable piece of information is the function name.

Before you change a given function, everything is reliable.  Afterwards,
only the function name and the column start and end would be reliable.

julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Cocci] Positional parameter p1[0].file contains temporarily munged filename, not original
  2018-12-19  6:21     ` Julia Lawall
@ 2018-12-19 13:32       ` Timur Tabi
  2019-01-22 18:36       ` Timur Tabi
  1 sibling, 0 replies; 9+ messages in thread
From: Timur Tabi @ 2018-12-19 13:32 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

On 12/19/18 12:21 AM, Julia Lawall wrote:
> Before you change a given function, everything is reliable.  Afterwards,
> only the function name and the column start and end would be reliable.

Hmmm.  I'll see if I can move my Python code to a new rule at the top of 
the file.
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Cocci] Positional parameter p1[0].file contains temporarily munged filename, not original
  2018-12-19  6:21     ` Julia Lawall
  2018-12-19 13:32       ` Timur Tabi
@ 2019-01-22 18:36       ` Timur Tabi
  2019-01-22 18:43         ` Julia Lawall
  1 sibling, 1 reply; 9+ messages in thread
From: Timur Tabi @ 2019-01-22 18:36 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

On Wed, Dec 19, 2018 at 12:22 AM Julia Lawall <julia.lawall@lip6.fr> wrote:
>
> Before you change a given function, everything is reliable.  Afterwards,
> only the function name and the column start and end would be reliable.

Is there any way you can enhance spatch so that it correctly remembers
the real name of the file that it's modifying, not just the mangled
temporary file name?
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Cocci] Positional parameter p1[0].file contains temporarily munged filename, not original
  2019-01-22 18:36       ` Timur Tabi
@ 2019-01-22 18:43         ` Julia Lawall
  2019-01-23  0:05           ` Timur Tabi
  0 siblings, 1 reply; 9+ messages in thread
From: Julia Lawall @ 2019-01-22 18:43 UTC (permalink / raw)
  To: Timur Tabi; +Cc: cocci



On Tue, 22 Jan 2019, Timur Tabi wrote:

> On Wed, Dec 19, 2018 at 12:22 AM Julia Lawall <julia.lawall@lip6.fr> wrote:
> >
> > Before you change a given function, everything is reliable.  Afterwards,
> > only the function name and the column start and end would be reliable.
>
> Is there any way you can enhance spatch so that it correctly remembers
> the real name of the file that it's modifying, not just the mangled
> temporary file name?

You can use List.hd (Coccilib.files()) in OCaml.  I guess some similar
function exists for python.

julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Cocci] Positional parameter p1[0].file contains temporarily munged filename, not original
  2019-01-22 18:43         ` Julia Lawall
@ 2019-01-23  0:05           ` Timur Tabi
  2019-01-23  6:29             ` Julia Lawall
  0 siblings, 1 reply; 9+ messages in thread
From: Timur Tabi @ 2019-01-23  0:05 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci, Timur Tabi

On Tue, Jan 22, 2019 at 12:44 PM Julia Lawall <julia.lawall@lip6.fr> wrote:
>
> You can use List.hd (Coccilib.files()) in OCaml.  I guess some similar
> function exists for python.

Can you expand on that?  I took at look at
https://github.com/coccinelle/coccinelle/tree/master/python/coccilib,
which I presume is the coccilib that you're talking about.  I don't
see a files() anywhere in there.  I tried to instantiate the Location
object:

import coccilib
cocci = coccilib.Location()
print >>sys.stderr, cocci

But that just gave me:

Traceback (most recent call last):
  File "<string>", line 44, in <module>
AttributeError: 'module' object has no attribute 'Location'
Error in Python script, line 130, file "/home/ttabi/nv_printf.cocci":
Python failure

The "import" statement didn't fail, so I presume that coccilib is a
real library, but I think I'm calling it wrong.  My Python isn't good
enough to read a library implementation and know how to use it.
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Cocci] Positional parameter p1[0].file contains temporarily munged filename, not original
  2019-01-23  0:05           ` Timur Tabi
@ 2019-01-23  6:29             ` Julia Lawall
  0 siblings, 0 replies; 9+ messages in thread
From: Julia Lawall @ 2019-01-23  6:29 UTC (permalink / raw)
  To: Timur Tabi; +Cc: cocci



On Tue, 22 Jan 2019, Timur Tabi wrote:

> On Tue, Jan 22, 2019 at 12:44 PM Julia Lawall <julia.lawall@lip6.fr> wrote:
> >
> > You can use List.hd (Coccilib.files()) in OCaml.  I guess some similar
> > function exists for python.
>
> Can you expand on that?  I took at look at
> https://github.com/coccinelle/coccinelle/tree/master/python/coccilib,
> which I presume is the coccilib that you're talking about.  I don't
> see a files() anywhere in there.  I tried to instantiate the Location
> object:
>
> import coccilib
> cocci = coccilib.Location()
> print >>sys.stderr, cocci
>
> But that just gave me:
>
> Traceback (most recent call last):
>   File "<string>", line 44, in <module>
> AttributeError: 'module' object has no attribute 'Location'
> Error in Python script, line 130, file "/home/ttabi/nv_printf.cocci":
> Python failure
>
> The "import" statement didn't fail, so I presume that coccilib is a
> real library, but I think I'm calling it wrong.  My Python isn't good
> enough to read a library implementation and know how to use it.

It could be cocci.XXX and there is no need to import it.  But files
doesn't seem to exist.  I have asked for it to be added.  In the meantime,
perhas you can just record the file names earlier in the semantic patch,
before there is any transformation.

julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-01-23  6:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-18 21:36 [Cocci] Positional parameter p1[0].file contains temporarily munged filename, not original Timur Tabi
2018-12-18 22:07 ` Julia Lawall
2018-12-19  0:39   ` Timur Tabi
2018-12-19  6:21     ` Julia Lawall
2018-12-19 13:32       ` Timur Tabi
2019-01-22 18:36       ` Timur Tabi
2019-01-22 18:43         ` Julia Lawall
2019-01-23  0:05           ` Timur Tabi
2019-01-23  6:29             ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).