diff --git a/_demo/setjmp/setjmp.go b/_demo/setjmp/setjmp.go new file mode 100644 index 00000000..b8508de5 --- /dev/null +++ b/_demo/setjmp/setjmp.go @@ -0,0 +1,16 @@ +package main + +import ( + "github.com/goplus/llgo/c/setjmp" +) + +func main() { + var jb setjmp.SigjmpBuf + switch ret := setjmp.Sigsetjmp(&jb, 0); ret { + case 0: + println("Hello, setjmp!") + setjmp.Siglongjmp(&jb, 1) + default: + println("exception:", ret) + } +} diff --git a/c/setjmp/setjmp.go b/c/setjmp/setjmp.go new file mode 100644 index 00000000..89c6745a --- /dev/null +++ b/c/setjmp/setjmp.go @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package setjmp + +// #include +import "C" + +import ( + _ "unsafe" + + "github.com/goplus/llgo/c" +) + +const ( + LLGoPackage = "decl" +) + +type ( + JmpBuf = C.jmp_buf + SigjmpBuf = C.sigjmp_buf +) + +// ----------------------------------------------------------------------------- + +//go:linkname Setjmp C.setjmp +func Setjmp(env *JmpBuf) c.Int + +//go:linkname Longjmp C.longjmp +func Longjmp(env *JmpBuf, val c.Int) + +// ----------------------------------------------------------------------------- + +//go:linkname Sigsetjmp C.sigsetjmp +func Sigsetjmp(env *SigjmpBuf, savemask c.Int) c.Int + +//go:linkname Siglongjmp C.siglongjmp +func Siglongjmp(env *SigjmpBuf, val c.Int) + +// ----------------------------------------------------------------------------- diff --git a/cl/blocks/block.go b/cl/blocks/block.go index 21960751..4f220339 100644 --- a/cl/blocks/block.go +++ b/cl/blocks/block.go @@ -74,7 +74,7 @@ func findLoop(states []*blockState, path []int, from, iblk int) []int { } return path } - if ret := findLoop(states, path, from, succ); ret != nil { + if ret := findLoop(states, path, from, succ); len(ret) > 0 { return ret } }