use custom memory functions for nghttp3 and ngtcp2#18196
Closed
dvdzhuang wants to merge 5 commits intocurl:masterfrom
Closed
use custom memory functions for nghttp3 and ngtcp2#18196dvdzhuang wants to merge 5 commits intocurl:masterfrom
dvdzhuang wants to merge 5 commits intocurl:masterfrom
Conversation
Contributor
Author
|
Sorry, changes broke tests 2500 - 2503. Closing while I investigate |
Contributor
|
Thanks, good idea! As to the nitty, gritty details, I would tweak this a bit like the following. This does not need the diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c
index 643c403fec..575ebb9022 100644
--- a/lib/vquic/curl_ngtcp2.c
+++ b/lib/vquic/curl_ngtcp2.c
@@ -1212,7 +1212,7 @@ static CURLcode init_ngh3_conn(struct Curl_cfilter *cf,
rc = nghttp3_conn_client_new(&ctx->h3conn,
&ngh3_callbacks,
&ctx->h3settings,
- (nghttp3_mem *)Curl_nghttp3_mem(),
+ Curl_nghttp3_mem(),
cf);
if(rc) {
failf(data, "error creating nghttp3 connection instance");
@@ -2475,7 +2475,7 @@ static const struct alpn_spec ALPN_SPEC_H3 = {
&ctx->connected_path,
NGTCP2_PROTO_VER_V1, &ng_callbacks,
&ctx->settings, &ctx->transport_params,
- (ngtcp2_mem *)Curl_ngtcp2_mem(), cf);
+ Curl_ngtcp2_mem(), cf);
if(rc)
return CURLE_QUIC_CONNECT_ERROR;
diff --git a/lib/vquic/vquic.c b/lib/vquic/vquic.c
index 11f337dc3d..7091c58c88 100644
--- a/lib/vquic/vquic.c
+++ b/lib/vquic/vquic.c
@@ -751,25 +751,31 @@ void *Curl_ngtcp2_realloc(void *ptr, size_t size, void *user_data)
}
#ifdef USE_NGTCP2
-static ngtcp2_mem curl_ngtcp2_mem_ = {
+static struct ngtcp2_mem curl_ngtcp2_mem = {
NULL,
Curl_ngtcp2_malloc,
Curl_ngtcp2_free,
Curl_ngtcp2_calloc,
Curl_ngtcp2_realloc
};
-void *Curl_ngtcp2_mem(void) { return (void *)&curl_ngtcp2_mem_; }
+struct ngtcp2_mem *Curl_ngtcp2_mem(void)
+{
+ return (void *)&curl_ngtcp2_mem;
+}
#endif
#ifdef USE_NGHTTP3
-static nghttp3_mem curl_nghttp3_mem_ = {
+static struct nghttp3_mem curl_nghttp3_mem = {
NULL,
Curl_ngtcp2_malloc,
Curl_ngtcp2_free,
Curl_ngtcp2_calloc,
Curl_ngtcp2_realloc
};
-void *Curl_nghttp3_mem(void) { return (void *)&curl_nghttp3_mem_; }
+struct nghttp3_mem *Curl_nghttp3_mem(void)
+{
+ return &curl_nghttp3_mem;
+}
#endif
#endif /* USE_NGTCP2 || USE_NGHTTP3 */
diff --git a/lib/vquic/vquic.h b/lib/vquic/vquic.h
index 2d5f225a64..0f81334f29 100644
--- a/lib/vquic/vquic.h
+++ b/lib/vquic/vquic.h
@@ -49,22 +49,6 @@ CURLcode Curl_cf_quic_create(struct Curl_cfilter **pcf,
extern struct Curl_cftype Curl_cft_http3;
-#if defined(USE_NGTCP2) || defined(USE_NGHTTP3)
-
-void *Curl_ngtcp2_malloc(size_t size, void *user_data);
-void Curl_ngtcp2_free(void *ptr, void *user_data);
-void *Curl_ngtcp2_calloc(size_t nmemb, size_t size, void *user_data);
-void *Curl_ngtcp2_realloc(void *ptr, size_t size, void *user_data);
-
-#ifdef USE_NGTCP2
-void *Curl_ngtcp2_mem(void);
-#endif
-#ifdef USE_NGHTTP3
-void *Curl_nghttp3_mem(void);
-#endif
-
-#endif /* USE_NGTCP2 || USE_NGHTTP3 */
-
#else
#define Curl_vquic_init() 1
#endif /* !CURL_DISABLE_HTTP && USE_HTTP3 */
diff --git a/lib/vquic/vquic_int.h b/lib/vquic/vquic_int.h
index d271368d29..7e26095d1a 100644
--- a/lib/vquic/vquic_int.h
+++ b/lib/vquic/vquic_int.h
@@ -91,4 +91,21 @@ CURLcode vquic_recv_packets(struct Curl_cfilter *cf,
#endif /* !USE_HTTP3 */
+#if defined(USE_NGTCP2) || defined(USE_NGHTTP3)
+void *Curl_ngtcp2_malloc(size_t size, void *user_data);
+void Curl_ngtcp2_free(void *ptr, void *user_data);
+void *Curl_ngtcp2_calloc(size_t nmemb, size_t size, void *user_data);
+void *Curl_ngtcp2_realloc(void *ptr, size_t size, void *user_data);
+
+#ifdef USE_NGTCP2
+struct ngtcp2_mem;
+struct ngtcp2_mem *Curl_ngtcp2_mem(void);
+#endif
+#ifdef USE_NGHTTP3
+struct nghttp3_mem;
+struct nghttp3_mem *Curl_nghttp3_mem(void);
+#endif
+
+#endif /* USE_NGTCP2 || USE_NGHTTP3 */
+
#endif /* HEADER_CURL_VQUIC_QUIC_INT_H */ |
Contributor
|
Just noticed, the |
Contributor
Author
|
Thanks; I've added your suggestions 👍 |
bagder
approved these changes
Aug 18, 2025
Member
|
Thanks! |
vszakats
pushed a commit
that referenced
this pull request
Aug 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pass curl's memory functions to the nghttp3 and ngtcp2 functions that allow them. This allows custom memory functions passed by the curl user to be used in nghttp3 and ngtcp2.
I added these functions in vquic since it's common to both curl_ngtcp2 and curl_osslq, but please let me know if there's a better place to put them. These functions are also the same as those used for nghttp2: 9089ef1