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
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@alandonovan
Copy link
Contributor

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
Contributor

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 The path to resolution is known, but the work has not been done. label Nov 8, 2016
@quentinmit quentinmit added this to the Unreleased milestone Nov 8, 2016
@gopherbot
Copy link
Contributor

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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants