]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commit
llama : return nullptr from llama_grammar_init (#8093)
authorDaniel Bevenius <redacted>
Tue, 25 Jun 2024 19:07:28 +0000 (21:07 +0200)
committerGitHub <redacted>
Tue, 25 Jun 2024 19:07:28 +0000 (15:07 -0400)
commite6bf007744eb06336a231ef39cf08146dd16d2ce
tree556b6bef69769ec9c26995c064c1148d3bed6655
parent84631fe1504de40427dc4b4cdac92fa7ebf65955
llama : return nullptr from llama_grammar_init (#8093)

* llama : return nullptr from llama_grammar_init

This commit updates llama_grammar_init to return nullptr instead of
throwing an exception.

The motivation for this is that this function is declared inside an
extern "C" block and is intended/may be used from C code which will not
be able to handle exceptions thrown, and results in undefined behavior.

On Windows and using MSVC the following warning is currently generated:
```console
C:\llama.cpp\llama.cpp(13998,1): warning C4297: 'llama_grammar_init':
function assumed not to throw an exception but does
C:\llama.cpp\llama.cpp(13998,1): message :
__declspec(nothrow), throw(), noexcept(true), or noexcept was specified
on the function
```

Signed-off-by: Daniel Bevenius <redacted>
* squash! llama : return nullptr from llama_grammar_init

Add checks for nullptr when calling llama_grammar_init.

Signed-off-by: Daniel Bevenius <redacted>
---------

Signed-off-by: Daniel Bevenius <redacted>
Co-authored-by: Clint Herron <redacted>
common/sampling.cpp
examples/gbnf-validator/gbnf-validator.cpp
llama.cpp
llama.h
tests/test-grammar-integration.cpp
tests/test-llama-grammar.cpp