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

fix:(j2t/native) panic when fieldmap is empty #76

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CFLAGS_avx := -msse -mno-sse4 -mavx -mpclmul -mno-avx2 -mstack-alignment=0 -DUS
CFLAGS_avx2 := -msse -mno-sse4 -mavx -mpclmul -mavx2 -mstack-alignment=0 -DUSE_AVX=1 -DUSE_AVX2=1
CFLAGS_sse := -msse -mno-sse4 -mno-avx -mno-avx2 -mpclmul

CC_amd64 := clang
CC_amd64 := /opt/homebrew/Cellar/llvm\@14/14.0.6/bin/clang
ASM2ASM_amd64 := tools/asm2asm/asm2asm.py

CFLAGS := -mno-red-zone
Expand Down
16 changes: 16 additions & 0 deletions conv/j2t/conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,3 +1552,19 @@ func TestSimpleArgs(t *testing.T) {
require.Equal(t, exp, out)
})
}

func TestEmptyStruct(t *testing.T) {
desc, err := thrift.NewDescritorFromContent(context.Background(), "a/b/main.thrift", `
struct Req {}

service Svc {
void Method(1: Req req)
}
`, nil, true)
require.NoError(t, err)
reqDesc := desc.Functions()["Method"].Request().Struct().FieldById(1).Type()
cv := NewBinaryConv(conv.Options{})
out, err := cv.Do(context.Background(), reqDesc, []byte(`{"UNKNOWN":1}`))
require.NoError(t, err)
fmt.Printf("%+v", out)
}
8 changes: 4 additions & 4 deletions conv/j2t/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func isJsonString(val string) bool {
if len(val) < 2 {
return false
}
c := json.SkipBlank(val, 0)

c := json.SkipBlank(val, 0)
if c < 0 {
return false
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func (self *BinaryConv) writeStringValue(ctx context.Context, buf *[]byte, f *th
if err := self.doNative(ctx, rt.Str2Mem(val), f.Type(), &p.Buf, req, false); err != nil {
return newError(meta.ErrConvert, fmt.Sprintf("failed to convert value of field '%s'", f.Name()), err)
}
// try text encoding, see thrift.EncodeText
// try text encoding, see thrift.EncodeText
} else {
return newError(meta.ErrConvert, fmt.Sprintf("unsupported http-mapping encoding %v for '%s'", enc, f.Name()), nil)
}
Expand All @@ -181,7 +181,7 @@ BACK:
return nil
}

func (self *BinaryConv)writeRequestBaseToThrift(ctx context.Context, buf *[]byte, field *thrift.FieldDescriptor) error {
func (self *BinaryConv) writeRequestBaseToThrift(ctx context.Context, buf *[]byte, field *thrift.FieldDescriptor) error {
var b *base.Base
if bobj := ctx.Value(conv.CtxKeyThriftReqBase); bobj != nil {
if v, ok := bobj.(*base.Base); ok && v != nil {
Expand Down
Loading
Loading