From 8aa66a6c6c0d8984b7d2668c03bad5a3b29e3a33 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sun, 5 Oct 2025 15:41:23 +0200 Subject: memops wrapper, remove unused includes --- src/ai_providers/DeepSeek.cpp | 17 ++++++----------- src/ai_providers/openAI.cpp | 23 +++++++++-------------- 2 files changed, 15 insertions(+), 25 deletions(-) (limited to 'src/ai_providers') diff --git a/src/ai_providers/DeepSeek.cpp b/src/ai_providers/DeepSeek.cpp index 4dd4e0a..a1857e9 100644 --- a/src/ai_providers/DeepSeek.cpp +++ b/src/ai_providers/DeepSeek.cpp @@ -14,15 +14,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define _CRT_SECURE_NO_WARNINGS - -#include -#include -#include - #define CPPHTTPLIB_OPENSSL_SUPPORT #include "httplib.h" #include "strops.hpp" +#include "memops.hpp" #include "logger.hpp" #include "importer.hpp" @@ -41,7 +36,7 @@ static bool _DeepSeek_query_with_file(char* query, size_t query_length, char* fi //cli.enable_server_certificate_verification(false); //char* query_escaped = strops::prep_str_for_json(query, query_length); - //free(query); // TODO why?? + //memops::unalloc(query); // TODO why?? size_t file_size = strlen(query_buffer); sprintf(query_buffer + file_size, "%s", query); @@ -49,7 +44,7 @@ static bool _DeepSeek_query_with_file(char* query, size_t query_length, char* fi char* query_escaped = strops::prep_str_for_json(query_buffer, strlen(query_buffer)); size_t body_size = file_size + QUERY_BUFFER_SIZE; - char* body = (char*)malloc(body_size); + char* body = (char*)memops::alloc(body_size); strops::format(body, body_size, "{\"model\":\"deepseek-reasoner\", \"messages\": [ { \"role\": \"user\", \"content\": \"%s\" } ] }", query_escaped); @@ -59,7 +54,7 @@ static bool _DeepSeek_query_with_file(char* query, size_t query_length, char* fi headers.insert(std::make_pair("Accept", "application/json")); httplib::Result res = cli.Post("/chat/completions", headers, body, "application/json"); - free(body); + memops::unalloc(body); if (!res || res->status != 200) { logger::error("ERROR Failed to query API."); @@ -68,7 +63,7 @@ static bool _DeepSeek_query_with_file(char* query, size_t query_length, char* fi } char* response_body = (char*)res->body.c_str(); - *response = (char*)malloc(100000); + *response = (char*)memops::alloc(100000); memset(*response, 0, 100000); strncpy(*response, response_body, 100000); @@ -95,7 +90,7 @@ static bool _DeepSeek_upload_file(char* file_path, char* file_id, size_t file_id fseek(orig_file, 0, SEEK_SET); size_t buffer_size = sz + QUERY_BUFFER_SIZE; - char* file_content_buffer = (char*)malloc(buffer_size); + char* file_content_buffer = (char*)memops::alloc(buffer_size); memset(file_content_buffer, 0, buffer_size); query_buffer = file_content_buffer; diff --git a/src/ai_providers/openAI.cpp b/src/ai_providers/openAI.cpp index c4526ef..b55f191 100644 --- a/src/ai_providers/openAI.cpp +++ b/src/ai_providers/openAI.cpp @@ -14,14 +14,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define _CRT_SECURE_NO_WARNINGS - -#include -#include -#include - #define CPPHTTPLIB_OPENSSL_SUPPORT #include "httplib.h" +#include "memops.hpp" #include "strops.hpp" #include "logger.hpp" #include "importer.hpp" @@ -35,10 +30,10 @@ static bool _openAI_query_with_file(char* query, size_t query_length, char* file //cli.enable_server_certificate_verification(false); char* query_escaped = strops::prep_str_for_json(query, query_length); - free(query); + memops::unalloc(query); size_t body_size = query_length + 200; - char* body = (char*)malloc(body_size); + char* body = (char*)memops::alloc(body_size); strops::format(body, body_size, "{\"model\":\"gpt-5-nano\", \"input\": [ { \"role\": \"user\", \"content\": [ { \"type\": \"input_file\", \"file_id\": \"%s\" }, " "{ \"type\": \"input_text\", \"text\": \"%s\" } ] } ] }", file_id, query_escaped); @@ -47,7 +42,7 @@ static bool _openAI_query_with_file(char* query, size_t query_length, char* file headers.insert(std::make_pair("Authorization", std::string("Bearer ") + api_key)); httplib::Result res = cli.Post("/v1/responses", headers, body, "application/json"); - free(body); + memops::unalloc(body); if (!res || res->status != 200) { logger::error("ERROR Failed to query API."); @@ -56,14 +51,14 @@ static bool _openAI_query_with_file(char* query, size_t query_length, char* file } char* response_body = (char*)res->body.c_str(); - *response = (char*)malloc(100000); + *response = (char*)memops::alloc(100000); memset(*response, 0, 100000); strncpy(*response, response_body, 100000); strops::get_json_value(*response, "text", *response, 100000); *response = strops::unprep_str_from_json(*response); #else - *response = (char*)malloc(100000); + *response = (char*)memops::alloc(100000); memset(*response, 0, 100000); strops::copy(*response, " urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0 urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 492043632 2024-09-01 2024-09-01 380 USD Final invoice do:team:67840ecb-44e2-472e-bc45-801bd4e1f1fe DigitalOcean LLC 101 Avenue of the Americas 2nd Floor New York 10013 NY US EU528002224 VAT DigitalOcean LLC My Team Keerderstraat 81 Maastricht 6226 XW LI NL VAT aldrikboy@gmail.com 492043632 3.49 15.60 3.28 VAT 1.00 0.21 VAT 16.60 16.60 20.09 20.09 1 16.60 false Discount Product Usage Charges Internal Tax Rate ID VAT ", 100000); #endif @@ -108,7 +103,7 @@ static bool _openAI_upload_file(char* file_path, char* file_id, size_t file_id_l size_t part_size = 64000000; // 64mb logger::info("Created upload %s with part size %zu.", upload_id, part_size); - char *buffer = (char*)malloc(part_size); + char *buffer = (char*)memops::alloc(part_size); char completion_body[1048]; strops::format(completion_body, sizeof(completion_body), "{\"part_ids\": ["); @@ -135,7 +130,7 @@ static bool _openAI_upload_file(char* file_path, char* file_id, size_t file_id_l if (!part_res || part_res->status != 200) { logger::error("Failed to upload part %d.", part_number); logger::error(part_res->body.c_str()); - free(buffer); + memops::unalloc(buffer); fclose(orig_file); return 0; } @@ -152,7 +147,7 @@ static bool _openAI_upload_file(char* file_path, char* file_id, size_t file_id_l strops::format(completion_body+strlen(completion_body), sizeof(completion_body)-strlen(completion_body), "]}"); - free(buffer); + memops::unalloc(buffer); fclose(orig_file); // ---------- Step 3: Complete upload ---------- -- cgit v1.2.3-70-g09d2