Просмотр исходного кода

Restoring authorship annotation for <ijon@yandex-team.ru>. Commit 2 of 2.

ijon 3 лет назад
Родитель
Сommit
fcd93d3533

+ 1 - 1
library/cpp/cgiparam/cgiparam_ut.cpp

@@ -239,4 +239,4 @@ Y_UNIT_TEST_SUITE(TCgiParametersTest) {
         UNIT_ASSERT_VALUES_EQUAL(c.Print(), "=value/of/empty&key/for/empty=");
         UNIT_ASSERT_VALUES_EQUAL(c.QuotedPrint(""), "=value%2Fof%2Fempty&key%2Ffor%2Fempty=");
     }
-} 
+}

+ 2 - 2
library/cpp/lfalloc/lf_allocX64.h

@@ -43,7 +43,7 @@ static inline long AtomicSub(TAtomic& a, long b) {
 
 #pragma comment(lib, "synchronization.lib")
 
-#ifndef NDEBUG 
+#ifndef NDEBUG
 #define Y_ASSERT_NOBT(x)           \
     {                              \
         if (IsDebuggerPresent()) { \
@@ -119,7 +119,7 @@ static inline long AtomicSub(TAtomic& a, long b) {
 #define Y_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 #endif
 
-#ifndef NDEBUG 
+#ifndef NDEBUG
 #define DBG_FILL_MEMORY
 static bool FillMemoryOnAllocation = true;
 #endif

+ 22 - 22
library/cpp/sighandler/async_signals_handler.cpp

@@ -1,16 +1,16 @@
-#include "async_signals_handler.h" 
+#include "async_signals_handler.h"
 
 #include <util/system/platform.h>
- 
+
 #if !defined(_win_)
- 
+
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <string.h>
 
 #include <unistd.h>
- 
+
 #if defined(_linux_)
 #include <dlfcn.h>
 #endif
@@ -57,13 +57,13 @@ namespace {
         typedef TAutoPtr<TEventHandler> TEventHandlerPtr;
         THashMap<int, TEventHandlerPtr> Handlers;
         TRWMutex HandlersLock;
- 
+
         TAtomic ShouldDie;
         TSystemEvent DieEvent;
 
         static void* ThreadFunc(void* data) {
             reinterpret_cast<TAsyncSignalsHandler*>(data)->RealThreadFunc();
- 
+
             return nullptr;
         }
 
@@ -71,7 +71,7 @@ namespace {
             for (;;) {
                 ui8 signum;
                 const ssize_t bytesRead = read(SignalPipeReadFd, &signum, 1);
- 
+
                 Y_VERIFY(bytesRead >= 0 || (bytesRead == -1 && errno == EINTR), "read failed: %s (errno = %d)", strerror(errno), errno);
 
                 if (AtomicAdd(ShouldDie, 0) != 0) {
@@ -79,7 +79,7 @@ namespace {
 
                     break;
                 }
- 
+
                 if (bytesRead == 0) {
                     break;
                 } else if (bytesRead == -1) {
@@ -94,8 +94,8 @@ namespace {
                     handler->Get()->Handle(signum);
                 }
             }
-        } 
- 
+        }
+
     public:
         TAsyncSignalsHandler()
             : Thread(TThread::TParams(ThreadFunc, this).SetName("sighandler"))
@@ -103,7 +103,7 @@ namespace {
             , ShouldDie(0)
         {
             int filedes[2] = {-1};
- 
+
 #ifdef _linux_
             int result;
 
@@ -145,20 +145,20 @@ namespace {
             Thread.Start();
             Thread.Detach();
         }
- 
+
         ~TAsyncSignalsHandler() {
             AtomicSwap(&ShouldDie, TAtomic(1));
             ui8 fakeSignal = 0;
             WriteAllOrDie(SIGNAL_PIPE_WRITE_FD, &fakeSignal, 1);
- 
+
             DieEvent.WaitT(TDuration::Seconds(15));
- 
+
             /* may cause VERIFY failure in signal handler, propably we should leave it to process clean procedure
         close(SIGNAL_PIPE_WRITE_FD);
         close(SignalPipeReadFd);
 */
         }
- 
+
         bool DoInstall(int signum, TAutoPtr<TEventHandler> handler) {
             TWriteGuard dnd(HandlersLock);
             TEventHandlerPtr& ev = Handlers[signum];
@@ -181,7 +181,7 @@ namespace {
             }
         }
     };
- 
+
     // This pointer is never deleted - yeah, it's intended memory leak.
     // It is necessary to prevent problems when user's signal handler calls exit function
     // which destroys all global variables including this one.
@@ -204,16 +204,16 @@ void SetAsyncSignalHandler(int signum, TAutoPtr<TEventHandler> handler) {
     }
 
     SIGNALS_HANDLER->Install(signum, handler);
-} 
- 
+}
+
 #else //_win_
- 
+
 void SetAsyncSignalHandler(int, TAutoPtr<TEventHandler>) {
     // TODO: it's really easy to port using _pipe, _read and _write, but it must be tested properly.
 }
- 
-#endif 
- 
+
+#endif
+
 namespace {
     template <typename TFunc>
     class TFunctionEventHandler: public TEventHandler {

+ 6 - 6
library/cpp/sighandler/async_signals_handler.h

@@ -1,14 +1,14 @@
-#pragma once 
- 
+#pragma once
+
 #include <util/generic/ptr.h>
 #include <functional>
 
-struct TEventHandler { 
+struct TEventHandler {
     virtual ~TEventHandler() {
     }
-    virtual int Handle(int signum) = 0; 
-}; 
- 
+    virtual int Handle(int signum) = 0;
+};
+
 void SetAsyncSignalHandler(int signum, TAutoPtr<TEventHandler> handler);
 void SetAsyncSignalHandler(int signum, void (*handler)(int));
 void SetAsyncSignalFunction(int signum, std::function<void(int)> func);

+ 27 - 27
library/cpp/string_utils/quote/quote.cpp

@@ -106,7 +106,7 @@ static const bool chars_to_url_escape[256] = {
 template <class It1, class It2, class It3>
 static inline It1 Escape(It1 to, It2 from, It3 end, const bool* escape_map = chars_to_url_escape) {
     while (from != end) {
-        if (escape_map[(unsigned char)*from]) { 
+        if (escape_map[(unsigned char)*from]) {
             *to++ = '%';
             *to++ = d2x((unsigned char)*from >> 4);
             *to++ = d2x((unsigned char)*from & 0xF);
@@ -144,13 +144,13 @@ static inline It1 Unescape(It1 to, It2 from, It3 end, FromHex fromHex) {
     return to;
 }
 
-// CGIEscape returns pointer to the end of the result string 
-// so as it could be possible to populate single long buffer 
-// with several calls to CGIEscape in a row. 
+// CGIEscape returns pointer to the end of the result string
+// so as it could be possible to populate single long buffer
+// with several calls to CGIEscape in a row.
 char* CGIEscape(char* to, const char* from) {
     return Escape(to, FixZero(from), TCStringEndIterator());
-} 
- 
+}
+
 char* CGIEscape(char* to, const char* from, size_t len) {
     return Escape(to, from, from + len);
 }
@@ -176,29 +176,29 @@ TString& AppendCgiEscaped(const TStringBuf value, TString& to) {
     return to;
 }
 
-// More general version of CGIEscape. The optional safe parameter specifies 
-// additional characters that should not be quoted — its default value is '/'. 
+// More general version of CGIEscape. The optional safe parameter specifies
+// additional characters that should not be quoted — its default value is '/'.
 
-// Also returns pointer to the end of result string. 
+// Also returns pointer to the end of result string.
 
 template <class It1, class It2, class It3>
 static inline It1 Quote(It1 to, It2 from, It3 end, const char* safe) {
-    bool escape_map[256]; 
-    memcpy(escape_map, chars_to_url_escape, 256); 
-    // RFC 3986 Uniform Resource Identifiers (URI): Generic Syntax 
-    // lists following reserved characters: 
-    const char* reserved = ":/?#[]@!$&\'()*+,;="; 
-    for (const char* p = reserved; *p; ++p) { 
-        escape_map[(unsigned char)*p] = 1; 
-    } 
-    // characters we think are safe at the moment 
-    for (const char* p = safe; *p; ++p) { 
-        escape_map[(unsigned char)*p] = 0; 
-    } 
- 
+    bool escape_map[256];
+    memcpy(escape_map, chars_to_url_escape, 256);
+    // RFC 3986 Uniform Resource Identifiers (URI): Generic Syntax
+    // lists following reserved characters:
+    const char* reserved = ":/?#[]@!$&\'()*+,;=";
+    for (const char* p = reserved; *p; ++p) {
+        escape_map[(unsigned char)*p] = 1;
+    }
+    // characters we think are safe at the moment
+    for (const char* p = safe; *p; ++p) {
+        escape_map[(unsigned char)*p] = 0;
+    }
+
     return Escape(to, from, end, escape_map);
-} 
- 
+}
+
 char* Quote(char* to, const char* from, const char* safe) {
     return Quote(to, FixZero(from), TCStringEndIterator(), safe);
 }
@@ -209,11 +209,11 @@ char* Quote(char* to, const TStringBuf s, const char* safe) {
 
 void Quote(TString& url, const char* safe) {
     TTempBuf tempBuf(CgiEscapeBufLen(url.size()));
-    char* to = tempBuf.Data(); 
+    char* to = tempBuf.Data();
 
     url.AssignNoAlias(to, Quote(to, url, safe));
-} 
- 
+}
+
 char* CGIUnescape(char* to, const char* from) {
     return Unescape(to, FixZero(from), TCStringEndIterator(), TFromHexZeroTerm());
 }

+ 27 - 27
library/cpp/string_utils/quote/quote_ut.cpp

@@ -4,11 +4,11 @@
 
 Y_UNIT_TEST_SUITE(TCGIEscapeTest) {
     Y_UNIT_TEST(ReturnsEndOfTo) {
-        char r[10]; 
-        const char* returned = CGIEscape(r, "123"); 
-        UNIT_ASSERT_VALUES_EQUAL(r + strlen("123"), returned); 
-        UNIT_ASSERT_VALUES_EQUAL('\0', *returned); 
-    } 
+        char r[10];
+        const char* returned = CGIEscape(r, "123");
+        UNIT_ASSERT_VALUES_EQUAL(r + strlen("123"), returned);
+        UNIT_ASSERT_VALUES_EQUAL('\0', *returned);
+    }
 
     Y_UNIT_TEST(NotZeroTerminated) {
         char r[] = {'1', '2', '3', '4'};
@@ -45,8 +45,8 @@ Y_UNIT_TEST_SUITE(TCGIEscapeTest) {
             TString("&param=!@%23$%25^%26*%28%29%7B%7D%5B%5D%22+&param_param=!@%23$%25^%26*%28%29%7B%7D%5B%5D%22+"));
     }
 
-} 
- 
+}
+
 Y_UNIT_TEST_SUITE(TCGIUnescapeTest) {
     Y_UNIT_TEST(StringBuf) {
         char tmp[100];
@@ -287,33 +287,33 @@ Y_UNIT_TEST_SUITE(TUrlUnescapeTest) {
 
 Y_UNIT_TEST_SUITE(TQuoteTest) {
     Y_UNIT_TEST(ReturnsEndOfTo) {
-        char r[10]; 
-        const char* returned = Quote(r, "123"); 
-        UNIT_ASSERT_VALUES_EQUAL(r + strlen("123"), returned); 
-        UNIT_ASSERT_VALUES_EQUAL('\0', *returned); 
-    } 
- 
+        char r[10];
+        const char* returned = Quote(r, "123");
+        UNIT_ASSERT_VALUES_EQUAL(r + strlen("123"), returned);
+        UNIT_ASSERT_VALUES_EQUAL('\0', *returned);
+    }
+
     Y_UNIT_TEST(SlashIsSafeByDefault) {
-        char r[100]; 
-        Quote(r, "/path;tail/path,tail/"); 
-        UNIT_ASSERT_VALUES_EQUAL("/path%3Btail/path%2Ctail/", r); 
+        char r[100];
+        Quote(r, "/path;tail/path,tail/");
+        UNIT_ASSERT_VALUES_EQUAL("/path%3Btail/path%2Ctail/", r);
         TString s("/path;tail/path,tail/");
-        Quote(s); 
-        UNIT_ASSERT_VALUES_EQUAL("/path%3Btail/path%2Ctail/", s.c_str()); 
-    } 
- 
+        Quote(s);
+        UNIT_ASSERT_VALUES_EQUAL("/path%3Btail/path%2Ctail/", s.c_str());
+    }
+
     Y_UNIT_TEST(SafeColons) {
-        char r[100]; 
-        Quote(r, "/path;tail/path,tail/", ";,"); 
-        UNIT_ASSERT_VALUES_EQUAL("%2Fpath;tail%2Fpath,tail%2F", r); 
+        char r[100];
+        Quote(r, "/path;tail/path,tail/", ";,");
+        UNIT_ASSERT_VALUES_EQUAL("%2Fpath;tail%2Fpath,tail%2F", r);
         TString s("/path;tail/path,tail/");
-        Quote(s, ";,"); 
-        UNIT_ASSERT_VALUES_EQUAL("%2Fpath;tail%2Fpath,tail%2F", s.c_str()); 
-    } 
+        Quote(s, ";,");
+        UNIT_ASSERT_VALUES_EQUAL("%2Fpath;tail%2Fpath,tail%2F", s.c_str());
+    }
 
     Y_UNIT_TEST(StringBuf) {
         char r[100];
         char* end = Quote(r, "abc\0/path", "");
         UNIT_ASSERT_VALUES_EQUAL("abc\0%2Fpath", TStringBuf(r, end));
     }
-} 
+}