Skip to content

Commit

Permalink
Turn on auto-formatting, fix a couple nits (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordemort authored Apr 16, 2022
1 parent f9b51dd commit 8895ca5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
25 changes: 14 additions & 11 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@
"build": {
"dockerfile": "Dockerfile",
},
// "workspaceFolder": "/usr/src/pystarlark",
"settings": {
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
},
"python.defaultInterpreterPath": "/opt/python/cp310-cp310/bin/python3",
"go.toolsEnvVars": {
"CGO_CFLAGS": "-I/opt/python/cp310-cp310/include/python3.10",
"CGO_LDFLAGS": "-Wl,--unresolved-symbols=ignore-all"
},
"C_Cpp.default.includePath": ["/opt/python/cp310-cp310/include/python3.10"]
"C_Cpp.default.includePath": [
"/opt/python/cp310-cp310/include/python3.10"
],
"C_Cpp.clang_format_style": "file",
"C_Cpp.clang_format_fallbackStyle": "LLVM",
"C_Cpp.formatting": "clangFormat",
"[c]": {
"editor.defaultFormatter": "ms-vscode.cpptools"
},
"editor.formatOnSave": true
},
"extensions": [
"extensions": [
"bierner.github-markdown-preview",
"eamodio.gitlens",
"golang.go",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-vscode.cpptools",
"oderwat.indent-rainbow",
],
],
}
16 changes: 11 additions & 5 deletions starlark.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ static void HandleStarlarkError(StarlarkReturn *retval) {
}

/* Starlark object */
typedef struct { PyObject_HEAD unsigned long starlark_thread; } StarlarkGo;
typedef struct {
PyObject_HEAD unsigned long starlark_thread;
} StarlarkGo;

/* Starlark object methods */
static PyObject *StarlarkGo_new(PyTypeObject *type, PyObject *args,
Expand Down Expand Up @@ -144,16 +146,20 @@ static PyMethodDef StarlarkGo_methods[] = {
static PyTypeObject StarlarkGoType = {
PyVarObject_HEAD_INIT(NULL, 0) // this confuses clang-format
.tp_name = "pystarlark._lib.StarlarkGo",
.tp_doc = "Starlark interpreter", .tp_basicsize = sizeof(StarlarkGo),
.tp_itemsize = 0, .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = "Starlark interpreter",
.tp_basicsize = sizeof(StarlarkGo),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_new = (newfunc)StarlarkGo_new,
.tp_dealloc = (destructor)StarlarkGo_dealloc,
.tp_methods = StarlarkGo_methods};

/* Module */
static PyModuleDef pystarlark_lib = {
PyModuleDef_HEAD_INIT, .m_name = "pystarlark._lib",
.m_doc = "Interface to starlark-go", .m_size = -1,
PyModuleDef_HEAD_INIT,
.m_name = "pystarlark._lib",
.m_doc = "Interface to starlark-go",
.m_size = -1,
};

/* Helper to fetch exception classes */
Expand Down
7 changes: 3 additions & 4 deletions starlark.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package main
import "C"

import (
"fmt"
"math/rand"
"reflect"
"unsafe"
Expand Down Expand Up @@ -38,15 +37,15 @@ func DestroyThread(threadId C.ulong) {
func makeStarlarkErrorArgs(err error) *C.StarlarkErrorArgs {
args := (*C.StarlarkErrorArgs)(C.malloc(C.sizeof_StarlarkErrorArgs))
args.error = C.CString(err.Error())
args.error_type = C.CString(fmt.Sprintf("%s", reflect.TypeOf(err)))
args.error_type = C.CString(reflect.TypeOf(err).String())

return args
}

func makeSyntaxErrorArgs(err *syntax.Error) *C.SyntaxErrorArgs {
args := (*C.SyntaxErrorArgs)(C.malloc(C.sizeof_SyntaxErrorArgs))
args.error = C.CString(err.Error())
args.error_type = C.CString(fmt.Sprintf("%s", reflect.TypeOf(err)))
args.error_type = C.CString(reflect.TypeOf(err).String())
args.msg = C.CString(err.Msg)
args.filename = C.CString(err.Pos.Filename())
args.line = C.uint(err.Pos.Line)
Expand All @@ -58,7 +57,7 @@ func makeSyntaxErrorArgs(err *syntax.Error) *C.SyntaxErrorArgs {
func makeEvalErrorArgs(err *starlark.EvalError) *C.EvalErrorArgs {
args := (*C.EvalErrorArgs)(C.malloc(C.sizeof_EvalErrorArgs))
args.error = C.CString(err.Error())
args.error_type = C.CString(fmt.Sprintf("%s", reflect.TypeOf(err)))
args.error_type = C.CString(reflect.TypeOf(err).String())
args.backtrace = C.CString(err.Backtrace())

return args
Expand Down

0 comments on commit 8895ca5

Please sign in to comment.