The second parameter of evhttp_connection_get_peer in libevent already has type as const char **
The compilation of bitcoind with the fresh libevent occurs errors
rpc: Pass const char* to evhttp_connection_get_peer for new libevent #23607
pull Perlover wants to merge 2 commits into bitcoin:master from Perlover:patch-1 changing 2 files +31 −0-
Perlover commented at 4:28 pm on November 26, 2021: contributor
-
MarcoFalke added the label DrahtBot Guix build requested on Nov 26, 2021
-
MarcoFalke added the label Refactoring on Nov 26, 2021
-
MarcoFalke removed the label DrahtBot Guix build requested on Nov 26, 2021
-
Perlover commented at 5:59 pm on November 26, 2021: contributorI tested my compilation with last commit - everything was compiled! So I think this patch is OK If you need I can remake this patch to one single commit (in Monday)
-
hebasto commented at 6:15 pm on November 26, 2021: member
The second parameter of evhttp_connection_get_peer in libevent already has type as
const char **
The compilation of bitcoind with the fresh libevent occurs errorsThere were no upstream releases for now since the commit https://github.com/libevent/libevent/commit/a18301a2bb160ff7c3ffaf5b7653c39ffe27b385 has been merged, right?
-
Perlover commented at 11:48 pm on November 26, 2021: contributor@hebasto I used the master branch of libevent so this commit definitely merged. I am not sure about new releases of libevent with this commit. The old versions have
char **
type for the second parameter. So I patched through preprocessor of C++. I see that all tests are passed. I compiled the bitcoind too with these patches. -
Perlover force-pushed on Nov 29, 2021
-
Perlover commented at 10:09 am on November 29, 2021: contributorI rebased these patches to the one patch and rebased on current master branch
-
Perlover force-pushed on Nov 29, 2021
-
Perlover force-pushed on Nov 29, 2021
-
in src/httpserver.cpp:605 in 7e6efdc576 outdated
600@@ -597,7 +601,12 @@ CService HTTPRequest::GetPeer() const 601 // evhttp retains ownership over returned address string 602 const char* address = ""; 603 uint16_t port = 0; 604- evhttp_connection_get_peer(con, (char**)&address, &port); 605+ 606+ #if HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR
laanwj commented at 4:05 pm on November 29, 2021:Please align#
’s to the left.in src/httpserver.cpp:606 in 7e6efdc576 outdated
600@@ -597,7 +601,12 @@ CService HTTPRequest::GetPeer() const 601 // evhttp retains ownership over returned address string 602 const char* address = ""; 603 uint16_t port = 0; 604- evhttp_connection_get_peer(con, (char**)&address, &port); 605+ 606+ #if HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR 607+ evhttp_connection_get_peer(con, (const char **)&address, &port);
laanwj commented at 4:07 pm on November 29, 2021:Is any cast still needed in this case?&address
isconst char**
, right?laanwj commented at 4:09 pm on November 29, 2021: memberPlease update the PR title to be clearer. “evhttp_connection_get_peer of libevent” is not a good summary of the change.Perlover force-pushed on Nov 30, 2021Perlover renamed this:
evhttp_connection_get_peer of libevent
Improved evhttp_connection_get_peer function call
on Nov 30, 2021Perlover commented at 2:44 pm on November 30, 2021: contributorPlease update the PR title to be clearer. “evhttp_connection_get_peer of libevent” is not a good summary of the change.
My English is not native, I tried to give a more precise definition for this PR. I also applied the changes recommended by you and made a rebase relative to the current master branch.
in configure.ac:1515 in 40f4aa8a61 outdated
1509@@ -1510,6 +1510,13 @@ if test x$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench 1510 fi 1511 fi 1512 1513+AC_MSG_CHECKING([for evhttp_connection_get_peer]) 1514+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <event2/http.h>]], 1515+ [[ evhttp_connection_get_peer((evhttp_connection*) nullptr,(const char**) nullptr,(uint16_t *) nullptr); ]])],
luke-jr commented at 10:59 pm on November 30, 2021:Please specify valid arguments in case libevent eventually addsnonnull
attributes or something
Perlover commented at 11:14 am on December 1, 2021:If I understand correctly, the macro
AC_COMPILE_IF ELSE
only checks the possibility of compiling, not running the program. Therefore, I do not understand why to change the parameters as nullptr to any fictitious ones (as in your final example). By and large, I created the code using examples from the same configuration file as this one, for example:0... 1AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]], 2 [[ gmtime_r((const time_t *) nullptr, (struct tm *) nullptr); ]])], 3...
luke-jr commented at 7:52 pm on December 1, 2021:If libevent some day marks the arguments asnonnull
, the compiler may error ifnullptr
is passedin configure.ac:1513 in 40f4aa8a61 outdated
1509@@ -1510,6 +1510,13 @@ if test x$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench 1510 fi 1511 fi 1512 1513+AC_MSG_CHECKING([for evhttp_connection_get_peer])
luke-jr commented at 11:00 pm on November 30, 2021:0AC_MSG_CHECKING([if evhttp_connection_get_peer expects const char *])
luke-jr changes_requestedluke-jr commented at 0:26 am on December 1, 2021: memberAlso, please prepend your commit message with a shortish summary (~80 chars max, not a hard limit) and a blank line :)luke-jr commented at 1:22 am on December 1, 2021: memberFurther issues:
- In this scope, libevent may not even be installed. (Put the check inside the above
if
block that checks for libevent) - libevent may require certain CFLAGS to be used. (
CXXFLAGS="$CXXFLAGS $EVENT_CFLAGS"
; don’t forgetTEMP_CXXFLAGS
stuff) uint16_t
needs<cstdint>
included
Suggested fix for these and prior issues: https://gist.github.com/luke-jr/f8df9d7173a3f673b82b4f0c26854807
Perlover commented at 11:25 am on December 1, 2021: contributorFurther issues:
1. In this scope, libevent may not even be installed. (Put the check inside the above `if` block that checks for libevent)
There is such a code just above my code. Doesn’t it guarantee that configure will stop before my code is executed? It seems to me that it is redundant to check the installation of libevent, if it is already checked above.
0if test x$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench != xnonononono; then 1 PKG_CHECK_MODULES([EVENT], [libevent >= 2.0.21], [use_libevent=yes], [AC_MSG_ERROR([libevent version 2.0.21 or greater not found.])]) 2 if test x$TARGET_OS != xwindows; then 3 PKG_CHECK_MODULES([EVENT_PTHREADS], [libevent_pthreads >= 2.0.21],, [AC_MSG_ERROR([libevent_pthreads version 2.0.21 or greater not found.])]) 4 fi 5 6 if test x$suppress_external_warnings != xno; then 7 EVENT_CFLAGS=SUPPRESS_WARNINGS($EVENT_CFLAGS) 8 fi 9fi
2. libevent may require certain CFLAGS to be used. (`CXXFLAGS="$CXXFLAGS $EVENT_CFLAGS"`; don't forget `TEMP_CXXFLAGS` stuff)
Is it really that important to use this complex construction with CXXFLAGS here? All 15 checks performed on github pass.
3. `uint16_t` needs `<cstdint>` included
It’s probably better for me to just replace the arguments with those used in libevent: uint16_t -> ev_uint16_t
Suggested fix for these and prior issues: https://gist.github.com/luke-jr/f8df9d7173a3f673b82b4f0c26854807
Perlover commented at 11:48 am on December 1, 2021: contributorSuggested fix for these and prior issues: https://gist.github.com/luke-jr/f8df9d7173a3f673b82b4f0c26854807
0[ AC_MSG_RESULT([no])]
If I understand your code correctly, then there will be no constants defined here and I will have to add additional
#ifdef
or#if defined(...)
checks to my code.The evhttp_connection_get_peer function from libevent changes the type of the second parameter. Fixing the problem. 091ccc38c2Perlover force-pushed on Dec 1, 2021Perlover commented at 12:15 pm on December 1, 2021: contributor@luke-jr, I applied several of your suggestions - description lines inconfigure.ac
, short name commit, addedinclude <cstdio>
. I also corrected the style of pointers in accordance with the widely used style inside the bitcoin code. At the same time, I have not yet checked for installing libevent (it seems to me that the check is already being performed above and it is superfluous), and I also did not add theCXXFLAGS
options - to be honest, it seems to me superfluous for a small test function that checks the type of parameters. I am not in favor of complicating things that can not be complicated. In addition, the code passed all automatic checks. I did not replace the parameters withnullptr
with others, since the macro only checks the possibility of compilation. I don’t see the point in that. I used thenullptr
in a similar way, since this usage is already widely used inconfigure.ac
. And I did rebase on current master branch of bitcoin code.luke-jr commented at 1:33 pm on December 1, 2021: memberRight now, your PR will still break on systems:
- without libevent
- where libevent is installed outside the compiler’s default include path
- when/if the compiler is some day strict about disallowing nullptr where it is invalid
(Also note you should ideally not rebase unless there are conflicts)
luke-jr commented at 7:55 pm on December 1, 2021: memberThere is such a code just above my code. Doesn’t it guarantee that configure will stop before my code is executed?
The check above only runs with that
if test x$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench != xnonononono; then
conditional. Your code currently runs even if this libevent check is skipped. I am suggesting moving it up inside theif
block so it only runs when libevent is used.Is it really that important to use this complex construction with CXXFLAGS here? All 15 checks performed on github pass.
If libevent is installed outside the default compiler include path,
EVENT_CFLAGS
will contain necessary-I...
parameters for the compiler.luke-jr commented at 7:57 pm on December 1, 2021: memberIf I understand your code correctly, then there will be no constants defined here and I will have to add additional #ifdef or #if defined(…) checks to my code.
This is how other similar checks are currently done.
DrahtBot commented at 3:44 am on December 5, 2021: memberThe following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #23810 (refactor: destroy all C-style casts; use modern C++ casts, enforce via
-Wold-style-cast
by PastaPastaPasta)
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Necessary improvements to make configure work without libevent installed c62d763fc3luke-jr approvedluke-jr commented at 8:39 pm on December 9, 2021: membertACK c62d763fc313585d79ad833c9d729f6acf2652aaMarcoFalke added the label DrahtBot Guix build requested on Dec 10, 2021DrahtBot commented at 3:21 am on December 12, 2021: memberGuix builds
DrahtBot removed the label DrahtBot Guix build requested on Dec 12, 2021luke-jr referenced this in commit d3e534f4a5 on Dec 14, 2021luke-jr referenced this in commit ff831bbd9a on Dec 14, 2021laanwj commented at 3:36 pm on January 13, 2022: memberCode review ACK c62d763fc313585d79ad833c9d729f6acf2652aalaanwj renamed this:
Improved evhttp_connection_get_peer function call
net: Pass const char* to evhttp_connection_get_peer for new libevent
on Jan 13, 2022laanwj renamed this:
net: Pass const char* to evhttp_connection_get_peer for new libevent
rpc: Pass const char* to evhttp_connection_get_peer for new libevent
on Jan 13, 2022laanwj added the label RPC/REST/ZMQ on Jan 13, 2022laanwj removed the label Refactoring on Jan 13, 2022laanwj merged this on Jan 13, 2022laanwj closed this on Jan 13, 2022
sidhujag referenced this in commit b8dfbdb946 on Jan 14, 2022DrahtBot locked this on Jan 13, 2023
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-01-02 12:12 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me