Skip to content

Commit c8fd18b

Browse files
authored
fix: go panic (#2201)
This was an interesting one! TODO: add more findings why it works on Mac and not on Linux <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Fixes Go panic by adjusting memory allocation in `InvokeRuntimeCli` and updates Dockerfile for Linux compatibility. > > - **Go Panic Fix**: > - In `exports.go`, `InvokeRuntimeCli` function now allocates an extra slot in `arg_c_strings` array to prevent out-of-bounds access. > - Adjusts `defer` block to correctly free only initialized C strings. > - **Dockerfile Update**: > - In `test-package.Dockerfile`, adds `--platform=linux/amd64` to `FROM` directive to ensure compatibility with Linux. > - Installs Go 1.22 and protobuf Go plugin for building Go applications. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for 6cbb8de. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent a9208b6 commit c8fd18b

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

engine/language_client_go/baml_go/exports.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ func BamlVersion() string {
4242
}
4343

4444
func InvokeRuntimeCli(args []string) (int, error) {
45-
arg_c_strings := make([]*C.char, len(args))
45+
arg_c_strings := make([]*C.char, len(args)+1)
4646
for i, arg := range args {
4747
arg_c_strings[i] = C.CString(arg)
4848
}
49+
4950
defer func() {
50-
for _, arg_c_string := range arg_c_strings {
51-
C.free(unsafe.Pointer(arg_c_string))
51+
for i := 0; i < len(args); i++ {
52+
C.free(unsafe.Pointer(arg_c_strings[i]))
5253
}
5354
}()
5455

integ-tests/python/docker-tests/test-package.Dockerfile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.12
1+
FROM --platform=linux/amd64 python:3.12
22

33
WORKDIR /app
44

@@ -31,6 +31,19 @@ SHELL ["/bin/bash", "-c"]
3131
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
3232
ENV PATH="/root/.cargo/bin:${PATH}"
3333

34+
# Install Go 1.22
35+
RUN curl -L https://go.dev/dl/go1.22.10.linux-amd64.tar.gz -o go1.22.10.linux-amd64.tar.gz && \
36+
rm -rf /usr/local/go && \
37+
tar -C /usr/local -xzf go1.22.10.linux-amd64.tar.gz && \
38+
rm go1.22.10.linux-amd64.tar.gz
39+
40+
ENV PATH="/usr/local/go/bin:${PATH}"
41+
ENV GOPATH="/root/go"
42+
ENV PATH="${GOPATH}/bin:${PATH}"
43+
44+
# Install protobuf Go plugin
45+
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
46+
3447
# Install uv properly
3548
ADD https://astral.sh/uv/install.sh /uv-installer.sh
3649

0 commit comments

Comments
 (0)