dsvtnz6350 2017-09-16 14:09
浏览 84
已采纳

修改Golang内部文件?

I had the idea of adding a sync.WaitGroup Limit(max int) function to resrict the number of the WaitGroup counter.

So I opened the waitgroup.go file in go/src/sync and made the changes, saved the file and tried testing it in a main.go file on my desktop. When I ran the file, it says:

$ go run main.go
wg.Limit undefined (type sync.WaitGroup has no field or method Limit)

To fix this error message, I copied the folder from go/src/sync into the folder on my desktop containing my main.go file and changed the import from sync to ./sync.

After running go run main.go this time, I got the following output:

$ go run main.go
sync\mutex.go:14:2: use of internal package not allowed
sync\pool.go:8:2: use of internal package not allowed
syncwmutex.go:8:2: use of internal package not allowed
sync\waitgroup.go:8:2: use of internal package not allowed

To fix these messages, I copied go/src/internal into the folder on my desktop containing my main.go file and I modified all the files in ./sync that reference internal/.. to ./internal/..

I run it again and I get the following output:

$ go run main.go
# _/C_/.../sync
sync\mutex.go:20: missing function body for "throw"
sync\pool.go:66: missing function body for "fastrand"
sync\pool.go:249: missing function body for "runtime_registerPoolCleanup"
sync\pool.go:250: missing function body for "runtime_procPin"
sync\pool.go:251: missing function body for "runtime_procUnpin"
syncuntime.go:14: missing function body for "runtime_Semacquire"
syncuntime.go:17: missing function body for "runtime_SemacquireMutex"
syncuntime.go:23: missing function body for "runtime_Semrelease"
syncuntime.go:36: missing function body for "runtime_notifyListAdd"
syncuntime.go:39: missing function body for "runtime_notifyListWait"
syncuntime.go:39: too many errors

How can I implement my simple idea by modifying the source files of go/src without receiving these errors?

  • 写回答

2条回答 默认 最新

  • douhulao7642 2017-09-16 14:37
    关注

    In your installation of Go, navigate to the src folder and run the file called run.bat which will recompile all the packages removing the first error you described.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况