4494 Commits

Author SHA1 Message Date
Enji Cooper
cfcc093606 Call super to call methods from the parent class
Not only does it make it clearer to the reader what the intent is behind
the code, it fixes MRO evaluation of classes if the parent-child
relationship is nonlinear.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 16:27:56 -07:00
Enji Cooper
83175940d4 Address no-self-use issues reported by pylint
Sprinkle around `@staticmethod` where need be and raise
`NotImplementedError` from `Entry.GetInitializer` instead of doing
similar with `assert`. `NotImplementedError` will provide a hint to
static analyzers that there are abstract methods which need to be
implemented, if they aren't, in subclasses.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 16:20:24 -07:00
Enji Cooper
6da0cc6108 Run the code through the black formatter
This resolves a number of flake8 issues as well as pylint issues. Not
all of the changes mesh between flake8/pylint though, so there are some
false positives, but it's better than before.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 16:04:37 -07:00
Enji Cooper
10a0403685 Reformat strings to template
This change converts the existing code to use triple-quotes extensively,
in the end-goal of making the code to reformat with black more readable
before and after the change (black messes around with the formatting in
a less than desirable way).

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 15:58:02 -07:00
Enji Cooper
4cde51b678 Add argparse support
This change converts raw parsing with `sys.argv` to its equivalent logic
with `argparse`.

It doesn't fully convert over all of the TODO items listed in the
comments, but it does provide some top-level structure which can be used
to drive down further improvements and structure.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
23874cfcd5 Precompile regular expressions
This change boost performance at scale by pre-compiling regular
expressions in the global space, then reusing them many times within
functions.

This (while not the desired intent of the author) will boost
performance when parsing input.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
1b545a46cd Use bools instead of ints values where possible
This is being done to clarify logic and isn't being done for performance
reasons whatsoever, as bools are derived from ints.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
9157b0d2fa Rename all global variables to match the PEP8 spec
Global variables should be in all caps, as opposed to lowercase.

While here, use named groups for `STRUCT_REF_RE` instead of numbered
groups to make the results and their indented tokens to parse more
intuitive to the end reader.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
dc57672900 Handle file pointers with context suite patterns
This removes the need for manually calling the file pointer's `.close`
methods directly.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
7f115c17c0 Iterate over tokens with a for instead of while
This simplifies the logic and avoids unnecessary copying/slicing of
array elements in `tokens`.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
5408b9636f Fix indentation for RpcGenError
Indentation for the exception was double what it should have been. This
change normalizes the indentation to a consistent standard with the rest
of the file.

Fix minor flake8 issues while here corresponding to the minimum number
of needed blank lines around the class and its methods.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
30229dcf95 Don't override file built-in
Use `filep` instead of `file` to clarify the fact that `file` is a file
pointer object.

This mutes warnings on python 2.7 with `pylint`.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
2c38d6b115 Resolve variable name issues per PEP8
Move all logic under `if __name__ == "__main__"` to a `main(..)`
function.

The purpose of this is to not only address flake8/pylint reported issues
with variable names, but also to enable testing of the function in
isolation to ensure the logic acts as desired.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
f30cc2b04b Sort imports per PEP8
Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-27 10:35:46 -07:00
Enji Cooper
d4e392b54b Mute clang 8 compilation error with gcc pragma
Move the pragma ignoring outside the function to fix the build with gcc.
While here, add equivalent clang pragmas to mute the warning, as well.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2020-03-26 18:31:13 -07:00
Azat Khuzhin
0d2f170048 Merge #976 -- symbols check build fixes
* upstream/pr/976:
  github workflows: ignore previous cache
  github workflows: test for mingw via cmake
  cmake: replace CheckFunctionExists with CheckSymbolExists
2020-03-22 19:36:45 +03:00
yuangongji
6dea151494 github workflows: ignore previous cache
modify the cache key to ignore previous cache
for the changes of configure.ac/CMakeLists.txt
to take effect.
2020-03-22 22:34:41 +08:00
yuangongji
93eb1b70e7 github workflows: test for mingw via cmake 2020-03-22 22:23:19 +08:00
yuangongji
41d1d75a84 cmake: replace CheckFunctionExists with CheckSymbolExists
Checking functions with `CheckFunctionExists` may
get wrong results, we should replace it with
`CheckSymbolExists`, which is recommended by the cmake
official documentation.
Before using `CheckSymbolExists`, we use
`CheckIncludeFiles` to check header files and save the
available header files in a variable that guarantees
`CheckSymbolExists` and `CheckTypeSize` to work correctly.
This approach is modeled after the cmake scripts of `curl`.

The following functions or files were not found before
modification, they can now be found:
- msys2 + mingw-8.1.0 on Windows10 or mingw-7.3.0 on Ubuntu-18.04
timerclear
timercmp
timerisset

- windows10
getaddrinfo
getnameinfo
getprotobynumber
getservbyname
putenv
strtoll
timerclear
timercmp
timerisset

- ubuntu-18.04
sys/sysctl.h
timeradd
timerclear
timercmp
timerisset

- MacOS 10.13
sys/random.h
timeradd
timerclear
timercmp
timerisset
2020-03-22 22:22:51 +08:00
Mario Emmenlauer
1675a55620 LibeventConfig.cmake: restore CMAKE_FIND_LIBRARY_SUFFIXES and LIBEVENT_STATIC_LINK default
The current cmake/LibeventConfig.cmake.in has a few problems and I'm not
sure how cleanly developed it is. It seems rater complex for the little
things I would assume it needs to do.

I found two problems that are fixed in this PR:

- If the downstream user does not explicitly set LIBEVENT_STATIC_LINK
  before calling find_package(libevent) then they will not be able to
  detect the static library, even if its the only one that exists. Since
  this may be rather strict, I've changed the behavior so that
  LIBEVENT_STATIC_LINK can be set to ON or OFF, but if unset, it defaults
  to whatever configuration libevent was built as.

- The other problem is a bug. The package configuration needs to unset
  CMAKE_FIND_LIBRARY_SUFFIXES after use, otherwise all packages that are
  detected after libevent will be "infected" by this setting. This was a
  significant problem for us, and is very hard to detect in downstream
  project, because the order of dependencies will lead to different search
  results.
2020-03-17 21:49:53 +03:00
Azat Khuzhin
5c4ea4afb2 Merge branch 'build-fixes' (#969)
* build-fixes:
  github workflow: fix configure error on mingw-w64
  cmake: fix getaddrinfo checking error
  cmake: remove CheckFunctionExistsEx
  autoconf: fix getaddrinfo checking errors on mingw
2020-03-17 21:45:04 +03:00
yuangongji
a3cb3119c7 github workflow: fix configure error on mingw-w64 2020-03-17 21:43:39 +03:00
yuangongji
503ba1d365 cmake: fix getaddrinfo checking error
Using `CheckFunctionExists` on Windows to check `getaddrinfo`
will get `not found`, but it actually exists. Using `CheckSymbolExists`
with headers will get correct results. Other functions such as
`getnameinfo`,`inet_ntop`,etc. have the same issue.
2020-03-17 21:43:39 +03:00
yuangongji
61c5c19bfd cmake: remove CheckFunctionExistsEx
`CheckFunctionExistsEx` is copied from the cmake modules before
3.1.2, which is the minimum required version of libevent.
The internal module `CheckFunctionExists`of cmake can completely
replace it.
2020-03-17 21:43:39 +03:00
yuangongji
6d54be2cc0 autoconf: fix getaddrinfo checking errors on mingw
`AC_CHECK_FUNCS` can not properly check `getaddrinfo` because this
function requires some special headers on mingw.
Using `AC_CHECK_DECL` can effectively solve this issue.

Same for
- getnameinfo
- getprotobynumber
- getservbyname
- inet_ntop
- inet_pton
2020-03-17 21:43:05 +03:00
Azat Khuzhin
9a9b92ed06 Add EVENT_BASE_FLAG_EPOLL_DISALLOW_TIMERFD flag (fixes: #958)
By default we are using CLOCK_MONOTONIC_COARSE, but if
EVENT_BASE_FLAG_PRECISE_TIMER isset, then CLOCK_MONOTONIC will be used,
however this will also enable timerfd, while this is not always what
someone wants, hence add a flag to control this (by default the old
behavior is preserved, set new flag to change it).
2020-03-01 18:03:46 +03:00
Azat Khuzhin
4e5a41ca0f test-time: do not use deprecated API
- event_init() -> event_base_new()
- event_set() -> event_new()
- check return value of event_base_dispatch()
- use EXIT_SUCCESS/EXIT_FAILURE
2020-03-01 16:42:16 +03:00
Azat Khuzhin
a11edbfa36 test-time: enable debug mode if EVENT_DEBUG_LOGGING_ALL env set 2020-03-01 14:54:36 +03:00
Azat Khuzhin
5a5fe67ee8 Fix typo in thread.h (s/event/evthread) 2020-03-01 13:52:32 +03:00
yuangongji
114b383675 increase segment refcnt only if evbuffer_add_file_segment() succeeds 2020-02-29 17:47:47 +08:00
ayuseleznev
4da9f87ccb evdns: fix a crash when evdns_base with waiting requests is freed
Fix undefined behaviour and application crash that might take
place in some rare cases after calling evdns_base_free when
there are requests in the waiting queue.

Current cleanup procedure in evdns_base_free_and_unlock
function includes 2 steps:
1. Finish all inflight requests.
2. Finish all waiting requests.
During the first step we iterate over each list in req_heads
structure and finish all requests in these lists. With current
logic finishing an inflight request (function request_finished)
removes it from the inflight requests container and forces
a wating connection to be sent (by calling
evdns_requests_pump_waiting_queue). When these new requests are
sent it is possible that they will be inserted to the list in
req_heads that we've already cleaned.
So in some cases container of the inflight requests is not empty
after this procedure and some requests are not finished and
deleted. When timeouts for these requests expire
evdns_request_timeout_callback is called but corresponding
evdns_base has been already deleted which causes undefined
behaviour and possible applicaton crash.

It is interesting to note that in old versions of libevent such
situation was not possible. This bug was introduced by the commit
14f84bbdc77d90b1d936076661443cdbf516c593. Before this commit
nameservers were deleted before finishing the requests. Therefore
it was not possible that requests from the waiting queue be sent
while we finish the inflight requests.
2020-02-28 15:06:24 +03:00
chenguolong
968bbd5c91 event_base_once: fix potential null pointer threat
supposing if base is null, EVBASE_ACQUIRE_LOCK and EVBASE_RELEASE_LOCK
would get a coredump, so we add a guard for protection.

Signed-off-by: chenguolong <cgl.chenguolong@huawei.com>
2020-02-16 02:54:15 +03:00
yuangongji
5fbe6313ae test-ratelim: add missing free 2020-02-12 22:10:31 +08:00
yangyongsheng
08e7d5136d misspelling of output in bufferevent_struct.h 2020-01-28 14:31:39 +08:00
Azat Khuzhin
0b6f29aca6 Merge branch 'github-actions-v2' (#951)
* github-actions-v2:
  travis: disable doxygen and coveralls, in favor of github actions
  github actions: test and coverage
  github actions: doxygen
  Ignore truthy in yamllint (for github-actions)
  test: mark common_timeout as retriable
  cmake: set rpath for libraries on linux
  test-export: compatible with all versions of visual studio
  coverage: 'lcov --remove' need full path
2020-01-27 01:56:58 +03:00
Azat Khuzhin
19a55164f0 travis: disable doxygen and coveralls, in favor of github actions 2020-01-27 01:53:27 +03:00
yuangongji
84bb2c18e4 github actions: test and coverage 2020-01-27 01:50:13 +03:00
yuangongji
d151968fe7 github actions: doxygen 2020-01-27 01:50:13 +03:00
Azat Khuzhin
cf379ecc49 Ignore truthy in yamllint (for github-actions) 2020-01-26 21:37:11 +03:00
Azat Khuzhin
f6d7992b05 test: mark common_timeout as retriable
Refs: https://github.com/libevent/libevent/pull/951#issuecomment-576711224
2020-01-24 07:52:06 +03:00
yuangongji
ce8be2385b cmake: set rpath for libraries on linux 2020-01-24 07:52:06 +03:00
yuangongji
9adc9f1496 test-export: compatible with all versions of visual studio 2020-01-24 07:52:06 +03:00
yuangongji
1a99f9b25c coverage: 'lcov --remove' need full path 2020-01-24 07:52:06 +03:00
Azat Khuzhin
2c473056ab Do not use shared global structures on CYGWIN
Fixes: #950
2020-01-24 07:51:19 +03:00
JackBoosY
ec775a960b Add vcpkg installation instructions 2020-01-21 22:03:37 -08:00
Azat Khuzhin
ca2b72c546 test: move thread into realtime class even on EVENT__DISABLE_THREAD_SUPPORT 2020-01-14 21:58:16 +03:00
Azat Khuzhin
d0adbc0565 test: fix compilation without thread support (EVENT__DISABLE_THREAD_SUPPORT=ON) 2020-01-14 10:20:27 +03:00
Azat Khuzhin
8dcccf35c2 travis-ci: do not allow failures under osx 2020-01-14 02:36:54 +03:00
Azat Khuzhin
30fe125041 test: fix bufferevent/bufferevent_connect_fail_eventcb* under osx/freebsd
For OSX the socket should be closed, otherwise the "connection refused"
will not be triggered.

And freebsd can return error from the connect().
2020-01-14 02:36:39 +03:00
Azat Khuzhin
10504fcab9 test: fix dst thread in move_pthread_to_realtime_scheduling_class (osx)
Fixes the following tests on osx:
- del_wait
- no_events

Refs: #940
2020-01-14 02:07:22 +03:00