Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/cmd/gorename: renaming clobbers files that import "C" #17839

Closed
alandonovan opened this issue Nov 7, 2016 · 2 comments
Closed

x/tools/cmd/gorename: renaming clobbers files that import "C" #17839

alandonovan opened this issue Nov 7, 2016 · 2 comments
Assignees
Milestone

Comments

@alandonovan
Copy link
Contributor

@alandonovan alandonovan commented Nov 7, 2016

If a renaming edits a file that imports "C", that file gets completely overwritten by the result of cgo preprocessing (and renaming) applied to that file, potentially destroying source code:

$ cat test.go 
package test

/* #include <stdio.h> */
import "C"

func f() { C.puts(nil) }
$ cat test2.go 
package test

func _() { f() }
$ gorename -from test::f -to g
Renamed 2 occurrences in 2 files in 1 package.
$ cat test.go 
// Created by cgo - DO NOT EDIT

//line /usr/local/google/home/adonovan/go/src/test/test.go:1
package test

//line /usr/local/google/home/adonovan/go/src/test/test.go:7

//line /usr/local/google/home/adonovan/go/src/test/test.go:6
func g() { _Cfunc_puts(nil) }
$ cat test2.go 
package test

func _() { g() }
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Nov 7, 2016

FYI, my test case was to rename p to q here:

package main

/*
#include <stdio.h>
void put(int* x) {
  printf("%p\n", x);
}
*/
import "C"

var p *C.int

func main() {
    C.put(p)
}
@quentinmit quentinmit changed the title cmd/gorename: renaming clobbers files that import "C" x/tools/cmd/gorename: renaming clobbers files that import "C" Nov 8, 2016
@quentinmit quentinmit added the NeedsFix label Nov 8, 2016
@quentinmit quentinmit added this to the Unreleased milestone Nov 8, 2016
@gopherbot
Copy link

@gopherbot gopherbot commented Jun 15, 2017

CL https://golang.org/cl/45930 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.