Skip to content

Commit 79eea3a

Browse files
committed
fix missized vec
1 parent 5d46cc6 commit 79eea3a

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

binding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int eval(void *params_ptr, void *state_pr, char *text)
139139
return llama_eval(ctx, tokens.data(), n_prompt_tokens, n_past);
140140
}
141141

142-
int llama_predict(void *params_ptr, void *state_pr, char *result, bool debug)
142+
int llama_predict(void *params_ptr, void *state_pr, char **result, bool debug)
143143
{
144144
gpt_params *params_p = (gpt_params *)params_ptr;
145145
llama_context *ctx = (llama_context *)state_pr;
@@ -547,7 +547,7 @@ int llama_predict(void *params_ptr, void *state_pr, char *result, bool debug)
547547
llama_reset_timings(ctx);
548548
}
549549

550-
strcpy(result, res.c_str());
550+
*result = strdup(res.c_str());
551551
return 0;
552552
}
553553

binding.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ extern "C"
3131

3232
void llama_binding_free_model(void *state);
3333

34-
int llama_predict(void *params_ptr, void *state_pr, char *result, bool debug);
34+
int llama_predict(void *params_ptr, void *state_pr, char **result, bool debug);
3535

3636
#ifdef __cplusplus
3737
}
3838

3939
std::vector<std::string> create_vector(const char **strings, int count);
4040
void delete_vector(std::vector<std::string> *vec);
41-
#endif
41+
#endif

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl LLama {
423423

424424
println!("count {}", reverse_count);
425425

426-
let mut out = Vec::with_capacity(opts.tokens as usize);
426+
let mut out: *mut c_char = std::ptr::null_mut();
427427

428428
let logit_bias_cstr = CString::new(opts.logit_bias.clone()).unwrap();
429429

@@ -476,15 +476,15 @@ impl LLama {
476476
opts.prompt_cache_ro,
477477
);
478478

479-
let ret = llama_predict(params, self.state, out.as_mut_ptr(), opts.debug_mode);
479+
let ret = llama_predict(params, self.state, &mut out as _, opts.debug_mode);
480480

481481
if ret != 0 {
482482
return Err("Failed to predict".into());
483483
}
484484

485485
llama_free_params(params);
486486

487-
let c_str: &CStr = CStr::from_ptr(out.as_mut_ptr());
487+
let c_str: &CStr = CStr::from_ptr(out);
488488
let mut res: String = c_str.to_str().unwrap().to_owned();
489489

490490
res = res.trim_start().to_string();

0 commit comments

Comments
 (0)