Created
November 5, 2013 07:21
-
-
Save elazarl/7315150 to your computer and use it in GitHub Desktop.
No backtrace for Go calls across SOs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func Panic() { panic("oooh, no stacktrace") } | |
func make_bt_longer() { | |
Panic() | |
} | |
func main() { | |
Completer = func (text string, start, end int) (replacement string, options []string) { | |
make_bt_longer() | |
return | |
} | |
Readline("press tab and see no bt> ") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
#cgo darwin CFLAGS: -I/opt/local/include | |
#cgo darwin LDFLAGS: -L/opt/local/lib | |
#cgo LDFLAGS: -lreadline | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include "readline/readline.h" | |
#include "readline/history.h" | |
extern void setup_readline_completion(); | |
*/ | |
import "C" | |
import "unsafe" | |
func init() { | |
C.setup_readline_completion() | |
} | |
type CompleteFunc func (text string, start, end int) (replacement string, options []string) | |
var Completer CompleteFunc | |
//export completer | |
func completer(line *C.char, start, end int) **C.char { | |
if Completer == nil { | |
return nil | |
} | |
replacement, options := Completer(C.GoString(C.rl_line_buffer), start, end) | |
raw := C.calloc((C.size_t)(unsafe.Sizeof((*C.char)(nil))), (C.size_t)(len(options) + 2)) | |
rv := (*[1<<31](*C.char))(raw) | |
rv[0] = C.CString(replacement) | |
for i, w := range options { | |
rv[i+1] = C.CString(w) | |
} | |
return (**C.char)(raw) | |
} | |
func Readline(prompt string) (string, bool) { | |
line := C.readline(C.CString(prompt)) | |
if line == nil { | |
return "", false | |
} | |
return C.GoString(line), true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "readline/readline.h" | |
// exported in readline.go | |
extern char** completer(char*, int, int); | |
void setup_readline_completion() { | |
rl_attempted_completion_function = (rl_completion_func_t*)completer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment