whisper : avoid designated initializers

This commit is contained in:
Georgi Gerganov 2023-04-29 10:36:50 +03:00
parent 94aa56f19e
commit b5bd2f43c5
No known key found for this signature in database
GPG Key ID: 449E073F9DC10735

View File

@ -2607,27 +2607,22 @@ struct whisper_context * whisper_init_from_file_no_state(const char * path_model
return nullptr; return nullptr;
} }
whisper_model_loader loader = { whisper_model_loader loader = {};
.context = &fin,
.read = loader.read = [](void * ctx, void * output, size_t read_size) {
[](void *ctx, void *output, size_t read_size) { std::ifstream * fin = (std::ifstream*)ctx;
std::ifstream *fin = (std::ifstream *)ctx; fin->read((char *)output, read_size);
fin->read((char *)output, read_size); return read_size;
return read_size; };
},
.eof = loader.eof = [](void * ctx) {
[](void *ctx) { std::ifstream * fin = (std::ifstream*)ctx;
std::ifstream *fin = (std::ifstream *)ctx; return fin->eof();
return fin->eof(); };
},
.close = loader.close = [](void * ctx) {
[](void *ctx) { std::ifstream * fin = (std::ifstream*)ctx;
std::ifstream *fin = (std::ifstream *)ctx; fin->close();
fin->close();
}
}; };
auto ctx = whisper_init_no_state(&loader); auto ctx = whisper_init_no_state(&loader);
@ -2650,31 +2645,30 @@ struct whisper_context * whisper_init_from_buffer_no_state(void * buffer, size_t
fprintf(stderr, "%s: loading model from buffer\n", __func__); fprintf(stderr, "%s: loading model from buffer\n", __func__);
whisper_model_loader loader = { whisper_model_loader loader = {};
.context = &ctx,
.read = fprintf(stderr, "%s: loading model from buffer\n", __func__);
[](void *ctx, void *output, size_t read_size) {
buf_context *buf = reinterpret_cast<buf_context *>(ctx);
size_t size_to_copy = buf->current_offset + read_size < buf->size loader.context = &ctx;
? read_size
: buf->size - buf->current_offset;
memcpy(output, buf->buffer + buf->current_offset, size_to_copy); loader.read = [](void * ctx, void * output, size_t read_size) {
buf->current_offset += size_to_copy; buf_context * buf = reinterpret_cast<buf_context *>(ctx);
return size_to_copy; size_t size_to_copy = buf->current_offset + read_size < buf->size ? read_size : buf->size - buf->current_offset;
},
.eof = memcpy(output, buf->buffer + buf->current_offset, size_to_copy);
[](void *ctx) { buf->current_offset += size_to_copy;
buf_context *buf = reinterpret_cast<buf_context *>(ctx);
return buf->current_offset >= buf->size; return size_to_copy;
}, };
.close = [](void * /*ctx*/) {}}; loader.eof = [](void * ctx) {
buf_context * buf = reinterpret_cast<buf_context *>(ctx);
return buf->current_offset >= buf->size;
};
loader.close = [](void * /*ctx*/) { };
return whisper_init_no_state(&loader); return whisper_init_no_state(&loader);
} }