{"thread":{"id":"51648","subject":"[PATCH] http: use xmalloc with cURL","startedAt":"2019-08-15T15:35:09Z","lastAt":"2019-08-15T22:18:37Z","messageCount":6,"participants":["Carlo Marcelo Arenas Belón","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"380475","messageId":"20190815153504.23199-1-carenas@gmail.com","threadId":"51648","inReplyTo":null,"subject":"[PATCH] http: use xmalloc with cURL","fromName":"Carlo Marcelo Arenas Belón","fromEmail":"carenas@gmail.com","sentAt":"2019-08-15T15:35:04Z","receivedAt":"2019-08-15T15:35:09Z","isPatch":true,"sender":{"key":"carenas@gmail.com","avatar":"https://avatars.githubusercontent.com/u/76036?v=4"},"body":"f0ed8226c9 (Add custom memory allocator to MinGW and MacOS builds, 2009-05-31)\nnever told cURL about it.\n\nCorrect that by using the cURL initializer available since version 7.12 to\npoint to xmalloc and friends for consistency which then will pass the\nallocation requests along when USE_NED_ALLOCATOR=YesPlease is used (most\nlikely in Windows)\n\nSigned-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>\n---\nThis doesn't conflict with anything and was originally based on maint (so it\napplies cleanly also to master and next), but is now rebased on top of\njk/drop-release-pack-memory so the final product wouldn't have any chance to\nintroduce problems (thanks Peff)\n\nit has been built and tested in Windows through Azure Pipelines (thanks Dscho)\nand shouldn't introduce any build problems even with ancient versions or cURL\n(thanks Daniel) and while not strictly needed is a nice thing to have for\nconsistency (thanks Junio)\n\n http.h | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/http.h b/http.h\nindex b429f1cf04..e5f075dcbf 100644\n--- a/http.h\n+++ b/http.h\n@@ -22,9 +22,15 @@\n #define DEFAULT_MAX_REQUESTS 5\n #endif\n \n+#if LIBCURL_VERSION_NUM >= 0x070c00\n+#define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \\\n+\t\t\t\t\t\txrealloc, xstrdup, xcalloc)\n+#endif\n+\n #if LIBCURL_VERSION_NUM < 0x070704\n #define curl_global_cleanup() do { /* nothing */ } while (0)\n #endif\n+\n #if LIBCURL_VERSION_NUM < 0x070800\n #define curl_global_init(a) do { /* nothing */ } while (0)\n #endif\n\nbase-commit: 9827d4c185e4da728f51cd77c54a38c9de62495f\n-- \n2.23.0.rc2\n\n"},{"id":"380485","messageId":"xmqq5zmy4ami.fsf@gitster-ct.c.googlers.com","threadId":"51648","inReplyTo":"20190815153504.23199-1-carenas@gmail.com","subject":"Re: [PATCH] http: use xmalloc with cURL","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-08-15T17:11:17Z","receivedAt":"2019-08-15T17:11:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Carlo Marcelo Arenas Belón  <carenas@gmail.com> writes:\n\n> f0ed8226c9 (Add custom memory allocator to MinGW and MacOS builds, 2009-05-31)\n> never told cURL about it.\n>\n> Correct that by using the cURL initializer available since version 7.12 to\n> point to xmalloc and friends for consistency which then will pass the\n> allocation requests along when USE_NED_ALLOCATOR=YesPlease is used (most\n> likely in Windows)\n>\n> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>\n> ---\n> This doesn't conflict with anything and was originally based on maint (so it\n> applies cleanly also to master and next), but is now rebased on top of\n> jk/drop-release-pack-memory so the final product wouldn't have any chance to\n> introduce problems (thanks Peff)\n>\n> it has been built and tested in Windows through Azure Pipelines (thanks Dscho)\n> and shouldn't introduce any build problems even with ancient versions or cURL\n> (thanks Daniel) and while not strictly needed is a nice thing to have for\n> consistency (thanks Junio)\n\nThanks, all.  I do not think I did anything that deserves a\n\"thanks\", but anyway.\n>  http.h | 6 ++++++\n>  1 file changed, 6 insertions(+)\n>\n> diff --git a/http.h b/http.h\n> index b429f1cf04..e5f075dcbf 100644\n> --- a/http.h\n> +++ b/http.h\n> @@ -22,9 +22,15 @@\n>  #define DEFAULT_MAX_REQUESTS 5\n>  #endif\n>  \n> +#if LIBCURL_VERSION_NUM >= 0x070c00\n> +#define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \\\n> +\t\t\t\t\t\txrealloc, xstrdup, xcalloc)\n> +#endif\n> +\n>  #if LIBCURL_VERSION_NUM < 0x070704\n>  #define curl_global_cleanup() do { /* nothing */ } while (0)\n>  #endif\n> +\n>  #if LIBCURL_VERSION_NUM < 0x070800\n>  #define curl_global_init(a) do { /* nothing */ } while (0)\n>  #endif\n\nThe earlier version had definitions pertaining to curl_global_init()\nat a single place, but the above version allows arbitrary amount of\nunrelated stuff to be placed in between two definitions in future\nupdates.  Is that a good idea?  I sort of expected \"we always call\nglobal_init(), but if curl is old enough to lack it, define it as\nempty, and if curl is new enough to have curl_global_init_mem(),\nthen call it instead\" #if/#else/#if/#endif/#endif cascade.\n\n>\n> base-commit: 9827d4c185e4da728f51cd77c54a38c9de62495f\n"},{"id":"380488","messageId":"20190815191314.27440-1-carenas@gmail.com","threadId":"51648","inReplyTo":"20190815153504.23199-1-carenas@gmail.com","subject":"[PATCH v2] http: use xmalloc with cURL","fromName":"Carlo Marcelo Arenas Belón","fromEmail":"carenas@gmail.com","sentAt":"2019-08-15T19:13:14Z","receivedAt":"2019-08-15T19:13:23Z","isPatch":true,"sender":{"key":"carenas@gmail.com","avatar":"https://avatars.githubusercontent.com/u/76036?v=4"},"body":"f0ed8226c9 (Add custom memory allocator to MinGW and MacOS builds, 2009-05-31)\nnever told cURL about it.\n\nCorrect that by using the cURL initializer available since version 7.12 to\npoint to xmalloc and friends for consistency which then will pass the\nallocation requests along when USE_NED_ALLOCATOR=YesPlease is used (most\nlikely in Windows)\n\nSigned-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>\n---\n\nNotes:\n    v2: keep all global_init ifdefs together (as suggested by Junio)\n\n http.h | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/http.h b/http.h\nindex b429f1cf04..20a2030c94 100644\n--- a/http.h\n+++ b/http.h\n@@ -25,8 +25,12 @@\n #if LIBCURL_VERSION_NUM < 0x070704\n #define curl_global_cleanup() do { /* nothing */ } while (0)\n #endif\n+\n #if LIBCURL_VERSION_NUM < 0x070800\n #define curl_global_init(a) do { /* nothing */ } while (0)\n+#elseif LIBCURL_VERSION_NUM >= 0x070c00\n+#define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \\\n+\t\t\t\t\t\txrealloc, xstrdup, xcalloc)\n #endif\n \n #if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)\n\nbase-commit: 9827d4c185e4da728f51cd77c54a38c9de62495f\n-- \n2.23.0.rc2\n\n"},{"id":"380489","messageId":"xmqqo90q2pfw.fsf@gitster-ct.c.googlers.com","threadId":"51648","inReplyTo":"20190815191314.27440-1-carenas@gmail.com","subject":"Re: [PATCH v2] http: use xmalloc with cURL","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-08-15T19:34:11Z","receivedAt":"2019-08-15T19:34:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Carlo Marcelo Arenas Belón  <carenas@gmail.com> writes:\n\n> +#elseif LIBCURL_VERSION_NUM >= 0x070c00\n\n#elif\n\n> +#define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \\\n> +\t\t\t\t\t\txrealloc, xstrdup, xcalloc)\n>  #endif\n>  \n>  #if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)\n>\n> base-commit: 9827d4c185e4da728f51cd77c54a38c9de62495f\n"},{"id":"380519","messageId":"20190815214429.28048-1-carenas@gmail.com","threadId":"51648","inReplyTo":"xmqqo90q2pfw.fsf@gitster-ct.c.googlers.com","subject":"[PATCH v3] http: use xmalloc with cURL","fromName":"Carlo Marcelo Arenas Belón","fromEmail":"carenas@gmail.com","sentAt":"2019-08-15T21:44:29Z","receivedAt":"2019-08-15T21:44:38Z","isPatch":true,"sender":{"key":"carenas@gmail.com","avatar":"https://avatars.githubusercontent.com/u/76036?v=4"},"body":"f0ed8226c9 (Add custom memory allocator to MinGW and MacOS builds,\n2009-05-31) never told cURL about it.\n\nCorrect that by using the cURL initializer available since version 7.12 to\npoint to xmalloc and friends for consistency which then will pass the\nallocation requests along when USE_NED_ALLOCATOR=YesPlease is used (most\nlikely in Windows)\n\nSigned-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>\n---\nv3: proper use of #elif (Thanks Junio)\nv2: keep all curl_global_init ifdefs together (as suggested by Junio)\n\n http.h | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/http.h b/http.h\nindex b429f1cf04..20a2030c94 100644\n--- a/http.h\n+++ b/http.h\n@@ -25,8 +25,12 @@\n #if LIBCURL_VERSION_NUM < 0x070704\n #define curl_global_cleanup() do { /* nothing */ } while (0)\n #endif\n+\n #if LIBCURL_VERSION_NUM < 0x070800\n #define curl_global_init(a) do { /* nothing */ } while (0)\n+#elif LIBCURL_VERSION_NUM >= 0x070c00\n+#define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \\\n+\t\t\t\t\t\txrealloc, xstrdup, xcalloc)\n #endif\n \n #if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)\n\nbase-commit: 9827d4c185e4da728f51cd77c54a38c9de62495f\n-- \n2.23.0.rc2\n"},{"id":"380524","messageId":"xmqqblwq2hu2.fsf@gitster-ct.c.googlers.com","threadId":"51648","inReplyTo":"20190815214429.28048-1-carenas@gmail.com","subject":"Re: [PATCH v3] http: use xmalloc with cURL","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-08-15T22:18:29Z","receivedAt":"2019-08-15T22:18:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Carlo Marcelo Arenas Belón  <carenas@gmail.com> writes:\n\n>  #if LIBCURL_VERSION_NUM < 0x070800\n>  #define curl_global_init(a) do { /* nothing */ } while (0)\n> +#elif LIBCURL_VERSION_NUM >= 0x070c00\n> +#define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \\\n> +\t\t\t\t\t\txrealloc, xstrdup, xcalloc)\n>  #endif\n\nYup.  That looks better.\n\nIf your curl version is recent enough (which presumably is true for\nmost people these days), the entire #if/#endif block is skipped\nwhile scanning for #else or #elif and #elseif willq be silently\nignored; it is unfortunate that #elseif won't be flagged by CPP as a\npotential error X-<.\n"}]}