From: Brian Aker Date: Mon, 28 Nov 2011 05:39:23 +0000 (-0800) Subject: Merge in trunk X-Git-Tag: 1.0.3~4^2~3 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=3481bbb3f9e4f98c7b984b0f77ebeb468a7d486b;hp=5456b8df880eb3d611f4a607a152c338f7b0f0c7;p=m6w6%2Flibmemcached Merge in trunk --- diff --git a/ChangeLog b/ChangeLog index e61d7280..c4bc32de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,4 @@ 1.0.3 -* Change default distribution to be consistent 1.0.2 Mon Oct 24 08:00:48 PDT 2011 * Dropped libmemcached/memcached_util.h (undocumented header file) diff --git a/Makefile.am b/Makefile.am index d19991ec..b9e758b0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,8 +26,6 @@ EXTRA_DIST= \ config/pandora-plugin \ config/uncrustify.cfg -libmemcached_libmemcached_la_LDFLAGS= - include libtest/include.am include libhashkit-1.0/include.am diff --git a/clients/memcapable.cc b/clients/memcapable.cc index b325413d..8bce153a 100644 --- a/clients/memcapable.cc +++ b/clients/memcapable.cc @@ -33,7 +33,8 @@ #include #include -#include +#include +#include #include #include #include @@ -132,7 +133,7 @@ static memcached_socket_t set_noblock(void) if (flags == -1) { perror("Failed to get socket flags"); - closesocket(sock); + memcached_close_socket(sock); return INVALID_SOCKET; } @@ -141,7 +142,7 @@ static memcached_socket_t set_noblock(void) if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) { perror("Failed to set socket to nonblocking mode"); - closesocket(sock); + memcached_close_socket(sock); return INVALID_SOCKET; } } diff --git a/example/memcached_light.c b/example/memcached_light.c index ed892861..18274378 100644 --- a/example/memcached_light.c +++ b/example/memcached_light.c @@ -35,9 +35,10 @@ #include #include +#include #include -#include "storage.h" -#include "memcached_light.h" +#include "example/storage.h" +#include "example/memcached_light.h" extern memcached_binary_protocol_callback_st interface_v0_impl; extern memcached_binary_protocol_callback_st interface_v1_impl; diff --git a/example/storage.h b/example/storage.h index 12955846..bd1b8780 100644 --- a/example/storage.h +++ b/example/storage.h @@ -1,6 +1,5 @@ /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#ifndef STORAGE_H -#define STORAGE_H +#pragma once struct item { uint64_t cas; @@ -23,5 +22,3 @@ struct item* create_item(const void* key, size_t nkey, const void *data, bool delete_item(const void* key, size_t nkey); void flush(uint32_t when); void release_item(struct item* item); - -#endif diff --git a/libmemcached-1.0/return.h b/libmemcached-1.0/return.h index fa36243f..e5788c50 100644 --- a/libmemcached-1.0/return.h +++ b/libmemcached-1.0/return.h @@ -85,6 +85,7 @@ enum memcached_return_t { MEMCACHED_DEPRECATED, MEMCACHED_IN_PROGRESS, MEMCACHED_SERVER_TEMPORARILY_DISABLED, + MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE, MEMCACHED_MAXIMUM_RETURN /* Always add new error code before */ }; diff --git a/libmemcached/behavior.cc b/libmemcached/behavior.cc index 64456a4b..bb17f2bd 100644 --- a/libmemcached/behavior.cc +++ b/libmemcached/behavior.cc @@ -384,7 +384,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr, if (getsockopt(instance->fd, SOL_SOCKET, SO_SNDBUF, &sock_size, &sock_length) < 0) { - memcached_set_errno(*ptr, errno, MEMCACHED_AT); + memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT); return 0; /* Zero means error */ } } @@ -420,10 +420,9 @@ uint64_t memcached_behavior_get(memcached_st *ptr, if (getsockopt(instance->fd, SOL_SOCKET, SO_RCVBUF, &sock_size, &sock_length) < 0) { - memcached_set_errno(*ptr, errno, MEMCACHED_AT); + memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT); return 0; /* Zero means error */ } - } return (uint64_t) sock_size; diff --git a/libmemcached/callback.cc b/libmemcached/callback.cc index 83d8ce8f..36f4b309 100644 --- a/libmemcached/callback.cc +++ b/libmemcached/callback.cc @@ -90,7 +90,6 @@ void *memcached_callback_get(memcached_st *ptr, memcached_return_t *error) { memcached_return_t local_error; - if (error == NULL) { error = &local_error; diff --git a/libmemcached/close_socket.hpp b/libmemcached/close_socket.hpp new file mode 100644 index 00000000..0d18857a --- /dev/null +++ b/libmemcached/close_socket.hpp @@ -0,0 +1,79 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + + +/* To hide the platform differences between MS Windows and Unix, I am + * going to use the Microsoft way and #define the Microsoft-specific + * functions to the unix way. Microsoft use a separate subsystem for sockets, + * but Unix normally just use a filedescriptor on the same functions. It is + * a lot easier to map back to the unix way with macros than going the other + * way without side effect ;-) + */ +#ifdef WIN32 +#include "win32/wrappers.h" +#define get_socket_errno() WSAGetLastError() +#else +#define INVALID_SOCKET -1 +#define SOCKET_ERROR -1 +#define closesocket(a) close(a) +#define get_socket_errno() errno +#endif + +#ifdef __cplusplus +static inline void memcached_close_socket(int& socket_fd) +{ + closesocket(socket_fd); + socket_fd= INVALID_SOCKET; +} +#endif + +#ifndef HAVE_MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif + +#ifndef HAVE_MSG_DONTWAIT +#define MSG_DONTWAIT 0 +#endif + +#ifndef HAVE_MSG_MORE +#define MSG_MORE 0 +#endif + + diff --git a/libmemcached/common.h b/libmemcached/common.h index 47735195..ba0b4063 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -106,6 +106,7 @@ memcached_return_t memcached_server_execute(memcached_st *ptr, #include #include #include +#include #endif #include #include diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 3cc8e245..6cad60d5 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -64,12 +64,14 @@ static memcached_return_t connect_poll(memcached_server_st *server) { int err; socklen_t len= sizeof (err); - (void)getsockopt(server->fd, SOL_SOCKET, SO_ERROR, &err, &len); - - // We check the value to see what happened wth the socket. - if (err == 0) + if (getsockopt(server->fd, SOL_SOCKET, SO_ERROR, &err, &len) == 0) { - return MEMCACHED_SUCCESS; + // We check the value to see what happened wth the socket. + if (err == 0) + { + return MEMCACHED_SUCCESS; + } + errno= err; } return memcached_set_errno(*server, err, MEMCACHED_AT); @@ -99,21 +101,26 @@ static memcached_return_t connect_poll(memcached_server_st *server) if (fds[0].revents & POLLERR) { int err; - socklen_t len= sizeof (err); - (void)getsockopt(server->fd, SOL_SOCKET, SO_ERROR, &err, &len); - memcached_set_errno(*server, (err == 0) ? get_socket_errno() : err, MEMCACHED_AT); - } - else - { - memcached_set_errno(*server, get_socket_errno(), MEMCACHED_AT); + socklen_t len= sizeof(err); + if (getsockopt(server->fd, SOL_SOCKET, SO_ERROR, &err, &len) == 0) + { + if (err == 0) + { + // This should never happen, if it does? Punt. + continue; + } + errno= err; + } } + int local_errno= get_socket_errno(); // We cache in case closesocket() modifies errno + assert_msg(server->fd != INVALID_SOCKET, "poll() was passed an invalid file descriptor"); (void)closesocket(server->fd); server->fd= INVALID_SOCKET; server->state= MEMCACHED_SERVER_STATE_NEW; - return memcached_set_errno(*server, get_socket_errno(), MEMCACHED_AT); + return memcached_set_errno(*server, local_errno, MEMCACHED_AT); } } } diff --git a/libmemcached/csl/context.cc b/libmemcached/csl/context.cc index 1a60fede..1e6e18ae 100644 --- a/libmemcached/csl/context.cc +++ b/libmemcached/csl/context.cc @@ -42,15 +42,20 @@ void Context::abort(const char *error_arg, yytokentype last_token, const char *l { rc= MEMCACHED_PARSE_ERROR; (void)last_token; - (void)last_token_str; if (error_arg) { - memcached_set_parser_error(*memc, MEMCACHED_AT, "Error occured while parsing: %s", error_arg); + memcached_set_parser_error(*memc, MEMCACHED_AT, "%s", error_arg); return; } - memcached_set_parser_error(*memc, MEMCACHED_AT, "Error occured while parsing: %s", memcached_strerror(NULL, MEMCACHED_PARSE_ERROR)); + if (last_token_str) + { + memcached_set_parser_error(*memc, MEMCACHED_AT, "%s", last_token_str); + return; + } + + memcached_set_parser_error(*memc, MEMCACHED_AT, "unknown parsing error"); } void Context::error(const char *error_arg, yytokentype last_token, const char *last_token_str) @@ -101,3 +106,17 @@ const char *Context::set_hostname(const char *str, size_t size) return _hostname; } +bool Context::set_hash(memcached_hash_t hash) +{ + if (_has_hash) + { + return false; + } + + if ((memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, hash)) != MEMCACHED_SUCCESS) + { + return false; + } + + return _has_hash= true; +} diff --git a/libmemcached/csl/context.h b/libmemcached/csl/context.h index 94f68134..77fac219 100644 --- a/libmemcached/csl/context.h +++ b/libmemcached/csl/context.h @@ -52,7 +52,8 @@ public: memc(NULL), rc(rc_arg), _is_server(false), - _end(false) + _end(false), + _has_hash(false) { _hostname[0]= 0; buf= option_string; @@ -75,6 +76,8 @@ public: _end= true; } + bool set_hash(memcached_hash_t hash); + void set_server() { _is_server= true; @@ -85,14 +88,14 @@ public: _is_server= false; } - bool is_server() + bool is_server() const { return _is_server; } const char *set_hostname(const char *str, size_t size); - const char *hostname() + const char *hostname() const { return _hostname; } @@ -122,4 +125,5 @@ private: bool _is_server; bool _end; char _hostname[NI_MAXHOST]; + bool _has_hash; }; diff --git a/libmemcached/csl/parser.cc b/libmemcached/csl/parser.cc index 63d92e8e..a9fb743a 100644 --- a/libmemcached/csl/parser.cc +++ b/libmemcached/csl/parser.cc @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.5. */ -/* Skeleton implementation for Bison's Yacc-like parsers in C +/* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.3" +#define YYBISON_VERSION "2.5" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -74,7 +73,7 @@ /* Copy the first part of user declarations. */ -/* Line 189 of yacc.c */ +/* Line 268 of yacc.c */ #line 36 "libmemcached/csl/parser.yy" @@ -115,8 +114,8 @@ inline void __config_error(Context *context, yyscan_t *scanner, const char *erro -/* Line 189 of yacc.c */ -#line 120 "libmemcached/csl/parser.cc" +/* Line 268 of yacc.c */ +#line 119 "libmemcached/csl/parser.cc" /* Enabling traces. */ #ifndef YYDEBUG @@ -227,8 +226,8 @@ inline void __config_error(Context *context, yyscan_t *scanner, const char *erro /* Copy the second part of user declarations. */ -/* Line 264 of yacc.c */ -#line 232 "libmemcached/csl/parser.cc" +/* Line 343 of yacc.c */ +#line 231 "libmemcached/csl/parser.cc" #ifdef short # undef short @@ -331,11 +330,11 @@ YYID (yyi) # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # endif @@ -358,24 +357,24 @@ YYID (yyi) # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# if (defined __cplusplus && ! defined _STDLIB_H \ +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif @@ -404,23 +403,7 @@ union yyalloc ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif +# define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of @@ -440,6 +423,26 @@ union yyalloc #endif +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + /* YYFINAL -- State number of the termination state. */ #define YYFINAL 71 /* YYLAST -- Last index in YYTABLE. */ @@ -538,12 +541,12 @@ static const yytype_int8 yyrhs[] = static const yytype_uint16 yyrline[] = { 0, 172, 172, 173, 177, 179, 181, 183, 188, 193, - 197, 201, 212, 220, 228, 235, 239, 243, 247, 251, - 258, 265, 276, 283, 290, 297, 303, 307, 311, 315, - 319, 323, 327, 331, 335, 339, 343, 347, 354, 358, - 362, 366, 370, 374, 378, 382, 386, 390, 394, 398, - 405, 406, 411, 412, 417, 421, 425, 429, 433, 437, - 441, 445, 449, 456, 460, 467, 471, 475 + 197, 201, 212, 222, 232, 241, 245, 249, 253, 257, + 269, 282, 295, 302, 309, 318, 324, 328, 332, 336, + 340, 344, 348, 352, 356, 360, 364, 368, 375, 379, + 383, 387, 391, 395, 399, 403, 407, 411, 415, 419, + 426, 427, 432, 433, 438, 442, 446, 450, 454, 458, + 462, 466, 470, 477, 481, 488, 492, 496 }; #endif @@ -613,8 +616,8 @@ static const yytype_uint8 yyr2[] = 1, 1, 1, 1, 1, 1, 1, 1 }; -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero +/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const yytype_uint8 yydefact[] = { @@ -661,8 +664,7 @@ static const yytype_int8 yypgoto[] = /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ + number is the opposite. If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { @@ -676,6 +678,12 @@ static const yytype_uint8 yytable[] = 66, 84, 0, 0, 72 }; +#define yypact_value_is_default(yystate) \ + ((yystate) == (-61)) + +#define yytable_value_is_error(yytable_value) \ + YYID (0) + static const yytype_int8 yycheck[] = { 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, @@ -736,7 +744,6 @@ do \ { \ yychar = (Token); \ yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ YYPOPSTACK (1); \ goto yybackup; \ } \ @@ -778,19 +785,10 @@ while (YYID (0)) #endif -/* YY_LOCATION_PRINT -- Print the location on the stream. - This macro was not mandated originally: define only if we know - we won't break user code: when these are the locations we know. */ +/* This macro is provided for backward compatibility. */ #ifndef YY_LOCATION_PRINT -# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) -# else -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -# endif +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) #endif @@ -990,7 +988,6 @@ int yydebug; # define YYMAXDEPTH 10000 #endif - #if YYERROR_VERBOSE @@ -1093,115 +1090,142 @@ yytnamerr (char *yyres, const char *yystr) } # endif -/* Copy into YYRESULT an error message about the unexpected token - YYCHAR while in state YYSTATE. Return the number of bytes copied, - including the terminating null byte. If YYRESULT is null, do not - copy anything; just return the number of bytes that would be - copied. As a special case, return 0 if an ordinary "syntax error" - message will do. Return YYSIZE_MAXIMUM if overflow occurs during - size calculation. */ -static YYSIZE_T -yysyntax_error (char *yyresult, int yystate, int yychar) -{ - int yyn = yypact[yystate]; +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. - if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) - return 0; - else - { - int yytype = YYTRANSLATE (yychar); - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - int yysize_overflow = 0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; - -# if 0 - /* This is so xgettext sees the translatable formats that are - constructed on the fly. */ - YY_("syntax error, unexpected %s"); - YY_("syntax error, unexpected %s, expecting %s"); - YY_("syntax error, unexpected %s, expecting %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); -# endif - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - - yyarg[0] = yytname[yytype]; - yyfmt = yystpcpy (yyformat, yyunexpected); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; - } + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) +{ + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = 0; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; + + /* There are many possibilities here to consider: + - Assume YYFAIL is not used. It's too flawed to consider. See + + for details. YYERROR is fine as it does not invoke this + function. + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) + { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } + } - yyf = YY_(yyformat); - yysize1 = yysize + yystrlen (yyf); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } - if (yysize_overflow) - return YYSIZE_MAXIMUM; + yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; - if (yyresult) - { - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - char *yyp = yyresult; - int yyi = 0; - while ((*yyp = *yyf) != '\0') - { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; - } - else - { - yyp++; - yyf++; - } - } - } - return yysize; + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; } #endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | @@ -1238,6 +1262,7 @@ yydestruct (yymsg, yytype, yyvaluep, context, scanner) } } + /* Prevent warnings from -Wmissing-prototypes. */ #ifdef YYPARSE_PARAM #if defined __STDC__ || defined __cplusplus @@ -1254,12 +1279,9 @@ int yyparse (); #endif /* ! YYPARSE_PARAM */ - - - -/*-------------------------. -| yyparse or yypush_parse. | -`-------------------------*/ +/*----------. +| yyparse. | +`----------*/ #ifdef YYPARSE_PARAM #if (defined __STDC__ || defined __C99__FUNC__ \ @@ -1447,7 +1469,7 @@ yybackup: /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yyn == YYPACT_NINF) + if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ @@ -1478,8 +1500,8 @@ yybackup: yyn = yytable[yyn]; if (yyn <= 0) { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; + if (yytable_value_is_error (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } @@ -1534,600 +1556,632 @@ yyreduce: { case 4: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 178 "libmemcached/csl/parser.yy" - { ;} + { } break; case 5: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 180 "libmemcached/csl/parser.yy" - { ;} + { } break; case 6: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 182 "libmemcached/csl/parser.yy" - { ;} + { } break; case 7: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 184 "libmemcached/csl/parser.yy" { context->set_end(); YYACCEPT; - ;} + } break; case 8: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 189 "libmemcached/csl/parser.yy" { context->rc= MEMCACHED_PARSE_USER_ERROR; - parser_abort(context, NULL); - ;} + parser_abort(context, "ERROR called directly"); + } break; case 9: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 194 "libmemcached/csl/parser.yy" { memcached_reset(context->memc); - ;} + } break; case 10: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 198 "libmemcached/csl/parser.yy" { yydebug= 1; - ;} + } break; case 11: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 202 "libmemcached/csl/parser.yy" { if ((context->rc= memcached_parse_configure_file(*context->memc, (yyvsp[(3) - (3)].string).c_str, (yyvsp[(3) - (3)].string).size)) != MEMCACHED_SUCCESS) { - parser_abort(context, NULL); + parser_abort(context, "Failed to parse configuration file"); } - ;} + } break; case 12: -/* Line 1464 of yacc.c */ +/* Line 1806 of yacc.c */ #line 213 "libmemcached/csl/parser.yy" { if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, (yyvsp[(2) - (4)].server).c_str, (yyvsp[(3) - (4)].number), (yyvsp[(4) - (4)].number)))) { - parser_abort(context, NULL); + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", (yyvsp[(2) - (4)].server).c_str, uint32_t((yyvsp[(3) - (4)].number))); + parser_abort(context, buffer); } context->unset_server(); - ;} + } break; case 13: -/* Line 1464 of yacc.c */ -#line 221 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 223 "libmemcached/csl/parser.yy" { if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, (yyvsp[(2) - (4)].server).c_str, (yyvsp[(3) - (4)].number), (yyvsp[(4) - (4)].number)))) { - parser_abort(context, NULL); + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", (yyvsp[(2) - (4)].server).c_str, uint32_t((yyvsp[(3) - (4)].number))); + parser_abort(context, buffer); } context->unset_server(); - ;} + } break; case 14: -/* Line 1464 of yacc.c */ -#line 229 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 233 "libmemcached/csl/parser.yy" { if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, (yyvsp[(2) - (3)].string).c_str, (yyvsp[(3) - (3)].number)))) { - parser_abort(context, NULL); + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "Failed to add server: %s", (yyvsp[(2) - (3)].string).c_str); + parser_abort(context, buffer); } - ;} + } break; case 15: -/* Line 1464 of yacc.c */ -#line 236 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 242 "libmemcached/csl/parser.yy" { memcached_set_configuration_file(context->memc, (yyvsp[(2) - (2)].string).c_str, (yyvsp[(2) - (2)].string).size); - ;} + } break; case 16: -/* Line 1464 of yacc.c */ -#line 240 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 246 "libmemcached/csl/parser.yy" { context->memc->configure.initial_pool_size= (yyvsp[(2) - (2)].number); - ;} + } break; case 17: -/* Line 1464 of yacc.c */ -#line 244 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 250 "libmemcached/csl/parser.yy" { context->memc->configure.max_pool_size= (yyvsp[(2) - (2)].number); - ;} + } break; case 19: -/* Line 1464 of yacc.c */ -#line 252 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 258 "libmemcached/csl/parser.yy" { + if (memcached_callback_get(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL)) + { + parser_abort(context, "--NAMESPACE can only be called once"); + } + if ((context->rc= memcached_set_namespace(context->memc, (yyvsp[(2) - (2)].string).c_str, (yyvsp[(2) - (2)].string).size)) != MEMCACHED_SUCCESS) { - parser_abort(context, NULL);; + parser_abort(context, memcached_last_error_message(context->memc)); } - ;} + } break; case 20: -/* Line 1464 of yacc.c */ -#line 259 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 270 "libmemcached/csl/parser.yy" { + // Check to see if DISTRIBUTION has already been set + if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, (yyvsp[(2) - (2)].distribution))) != MEMCACHED_SUCCESS) + { + parser_abort(context, "--DISTRIBUTION can only be called once"); + } + if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, (yyvsp[(2) - (2)].distribution))) != MEMCACHED_SUCCESS) { - parser_abort(context, NULL);; + parser_abort(context, memcached_last_error_message(context->memc));; } - ;} + } break; case 21: -/* Line 1464 of yacc.c */ -#line 266 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 283 "libmemcached/csl/parser.yy" { + // Check to see if DISTRIBUTION has already been set if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, (yyvsp[(2) - (4)].distribution))) != MEMCACHED_SUCCESS) { - parser_abort(context, NULL);; + parser_abort(context, "--DISTRIBUTION can only be called once"); } + if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, (yyvsp[(4) - (4)].hash))) != MEMCACHED_SUCCESS) { - parser_abort(context, NULL);; + parser_abort(context, "Unable to set the hash for the DISTRIBUTION requested"); } - ;} + } break; case 22: -/* Line 1464 of yacc.c */ -#line 277 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 296 "libmemcached/csl/parser.yy" { - if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, (yyvsp[(2) - (2)].hash))) != MEMCACHED_SUCCESS) + if (context->set_hash((yyvsp[(2) - (2)].hash)) == false) { - parser_abort(context, NULL);; + parser_abort(context, "--HASH can only be set once"); } - ;} + } break; case 23: -/* Line 1464 of yacc.c */ -#line 284 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 303 "libmemcached/csl/parser.yy" { if ((context->rc= memcached_behavior_set(context->memc, (yyvsp[(1) - (2)].behavior), (yyvsp[(2) - (2)].number))) != MEMCACHED_SUCCESS) { - parser_abort(context, NULL);; + parser_abort(context, "Unable to set behavior"); } - ;} + } break; case 24: -/* Line 1464 of yacc.c */ -#line 291 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 310 "libmemcached/csl/parser.yy" { if ((context->rc= memcached_behavior_set(context->memc, (yyvsp[(1) - (1)].behavior), true)) != MEMCACHED_SUCCESS) { - parser_abort(context, NULL);; + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "Could not set: %s", libmemcached_string_behavior((yyvsp[(1) - (1)].behavior))); + parser_abort(context, buffer); } - ;} + } break; case 25: -/* Line 1464 of yacc.c */ -#line 298 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 319 "libmemcached/csl/parser.yy" { - ;} + } break; case 26: -/* Line 1464 of yacc.c */ -#line 304 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 325 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS; - ;} + } break; case 27: -/* Line 1464 of yacc.c */ -#line 308 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 329 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT; - ;} + } break; case 28: -/* Line 1464 of yacc.c */ -#line 312 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 333 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK; - ;} + } break; case 29: -/* Line 1464 of yacc.c */ -#line 316 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 337 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK; - ;} + } break; case 30: -/* Line 1464 of yacc.c */ -#line 320 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 341 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH; - ;} + } break; case 31: -/* Line 1464 of yacc.c */ -#line 324 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 345 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS; - ;} + } break; case 32: -/* Line 1464 of yacc.c */ -#line 328 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 349 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_POLL_TIMEOUT; - ;} + } break; case 33: -/* Line 1464 of yacc.c */ -#line 332 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 353 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_RCV_TIMEOUT; - ;} + } break; case 34: -/* Line 1464 of yacc.c */ -#line 336 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 357 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT; - ;} + } break; case 35: -/* Line 1464 of yacc.c */ -#line 340 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 361 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_SND_TIMEOUT; - ;} + } break; case 36: -/* Line 1464 of yacc.c */ -#line 344 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 365 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE; - ;} + } break; case 37: -/* Line 1464 of yacc.c */ -#line 348 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 369 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE; - ;} + } break; case 38: -/* Line 1464 of yacc.c */ -#line 355 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 376 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL; - ;} + } break; case 39: -/* Line 1464 of yacc.c */ -#line 359 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 380 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS; - ;} + } break; case 40: -/* Line 1464 of yacc.c */ -#line 363 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 384 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY; - ;} + } break; case 41: -/* Line 1464 of yacc.c */ -#line 367 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 388 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_NOREPLY; - ;} + } break; case 42: -/* Line 1464 of yacc.c */ -#line 371 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 392 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ; - ;} + } break; case 43: -/* Line 1464 of yacc.c */ -#line 375 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 396 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_SORT_HOSTS; - ;} + } break; case 44: -/* Line 1464 of yacc.c */ -#line 379 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 400 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_SUPPORT_CAS; - ;} + } break; case 45: -/* Line 1464 of yacc.c */ -#line 383 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 404 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_TCP_NODELAY; - ;} + } break; case 46: -/* Line 1464 of yacc.c */ -#line 387 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 408 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE; - ;} + } break; case 47: -/* Line 1464 of yacc.c */ -#line 391 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 412 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE; - ;} + } break; case 48: -/* Line 1464 of yacc.c */ -#line 395 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 416 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_USE_UDP; - ;} + } break; case 49: -/* Line 1464 of yacc.c */ -#line 399 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 420 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_VERIFY_KEY; - ;} + } break; case 50: -/* Line 1464 of yacc.c */ -#line 405 "libmemcached/csl/parser.yy" - { (yyval.number)= MEMCACHED_DEFAULT_PORT;;} +/* Line 1806 of yacc.c */ +#line 426 "libmemcached/csl/parser.yy" + { (yyval.number)= MEMCACHED_DEFAULT_PORT;} break; case 51: -/* Line 1464 of yacc.c */ -#line 407 "libmemcached/csl/parser.yy" - { ;} +/* Line 1806 of yacc.c */ +#line 428 "libmemcached/csl/parser.yy" + { } break; case 52: -/* Line 1464 of yacc.c */ -#line 411 "libmemcached/csl/parser.yy" - { (yyval.number)= 1; ;} +/* Line 1806 of yacc.c */ +#line 432 "libmemcached/csl/parser.yy" + { (yyval.number)= 1; } break; case 53: -/* Line 1464 of yacc.c */ -#line 413 "libmemcached/csl/parser.yy" - { ;} +/* Line 1806 of yacc.c */ +#line 434 "libmemcached/csl/parser.yy" + { } break; case 54: -/* Line 1464 of yacc.c */ -#line 418 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 439 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_MD5; - ;} + } break; case 55: -/* Line 1464 of yacc.c */ -#line 422 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 443 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_CRC; - ;} + } break; case 56: -/* Line 1464 of yacc.c */ -#line 426 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 447 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_FNV1_64; - ;} + } break; case 57: -/* Line 1464 of yacc.c */ -#line 430 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 451 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_FNV1A_64; - ;} + } break; case 58: -/* Line 1464 of yacc.c */ -#line 434 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 455 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_FNV1_32; - ;} + } break; case 59: -/* Line 1464 of yacc.c */ -#line 438 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 459 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_FNV1A_32; - ;} + } break; case 60: -/* Line 1464 of yacc.c */ -#line 442 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 463 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_HSIEH; - ;} + } break; case 61: -/* Line 1464 of yacc.c */ -#line 446 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 467 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_MURMUR; - ;} + } break; case 62: -/* Line 1464 of yacc.c */ -#line 450 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 471 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_JENKINS; - ;} + } break; case 63: -/* Line 1464 of yacc.c */ -#line 457 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 478 "libmemcached/csl/parser.yy" { (yyval.string)= (yyvsp[(1) - (1)].string); - ;} + } break; case 64: -/* Line 1464 of yacc.c */ -#line 461 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 482 "libmemcached/csl/parser.yy" { (yyval.string)= (yyvsp[(1) - (1)].string); - ;} + } break; case 65: -/* Line 1464 of yacc.c */ -#line 468 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 489 "libmemcached/csl/parser.yy" { (yyval.distribution)= MEMCACHED_DISTRIBUTION_CONSISTENT; - ;} + } break; case 66: -/* Line 1464 of yacc.c */ -#line 472 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 493 "libmemcached/csl/parser.yy" { (yyval.distribution)= MEMCACHED_DISTRIBUTION_MODULA; - ;} + } break; case 67: -/* Line 1464 of yacc.c */ -#line 476 "libmemcached/csl/parser.yy" +/* Line 1806 of yacc.c */ +#line 497 "libmemcached/csl/parser.yy" { (yyval.distribution)= MEMCACHED_DISTRIBUTION_RANDOM; - ;} + } break; -/* Line 1464 of yacc.c */ -#line 2129 "libmemcached/csl/parser.cc" +/* Line 1806 of yacc.c */ +#line 2172 "libmemcached/csl/parser.cc" default: break; } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); @@ -2155,6 +2209,10 @@ yyreduce: | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { @@ -2162,37 +2220,36 @@ yyerrlab: #if ! YYERROR_VERBOSE yyerror (context, scanner, YY_("syntax error")); #else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) { - YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); - if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) - { - YYSIZE_T yyalloc = 2 * yysize; - if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) - yyalloc = YYSTACK_ALLOC_MAXIMUM; - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yyalloc); - if (yymsg) - yymsg_alloc = yyalloc; - else - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - } - } - - if (0 < yysize && yysize <= yymsg_alloc) - { - (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (context, scanner, yymsg); - } - else - { - yyerror (context, scanner, YY_("syntax error")); - if (yysize != 0) - goto yyexhaustedlab; - } + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (context, scanner, yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } +# undef YYSYNTAX_ERROR #endif } @@ -2251,7 +2308,7 @@ yyerrlab1: for (;;) { yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) + if (!yypact_value_is_default (yyn)) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) @@ -2310,8 +2367,13 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, context, scanner); + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, context, scanner); + } /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -2336,8 +2398,8 @@ yyreturn: -/* Line 1684 of yacc.c */ -#line 481 "libmemcached/csl/parser.yy" +/* Line 2067 of yacc.c */ +#line 502 "libmemcached/csl/parser.yy" void Context::start() diff --git a/libmemcached/csl/parser.h b/libmemcached/csl/parser.h index 16657d24..4112d748 100644 --- a/libmemcached/csl/parser.h +++ b/libmemcached/csl/parser.h @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.5. */ -/* Skeleton interface for Bison's Yacc-like parsers in C +/* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/libmemcached/include.am b/libmemcached/include.am index e3f5fa3f..0da3de33 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -22,6 +22,7 @@ noinst_HEADERS+= \ libmemcached/byteorder.h \ libmemcached/common.h \ libmemcached/continuum.hpp \ + libmemcached/close_socket.hpp \ libmemcached/do.hpp \ libmemcached/error.hpp \ libmemcached/initialize_query.h \ @@ -97,6 +98,7 @@ libmemcached/options.cc: libmemcached/csl/parser.h libmemcached_libmemcached_la_DEPENDENCIES= libmemcached_libmemcached_la_LIBADD= +libmemcached_libmemcached_la_LDFLAGS= if TARGET_LINUX libmemcached_libmemcached_la_LIBADD+= -lm endif diff --git a/libmemcached/io.cc b/libmemcached/io.cc index 8642c187..85e5ed42 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -268,16 +268,23 @@ static memcached_return_t io_wait(memcached_server_write_instance_st ptr, { int err; socklen_t len= sizeof (err); - (void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len); - memcached_set_errno(*ptr, (err == 0) ? get_socket_errno() : err, MEMCACHED_AT); + if (getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len) == 0) + { + if (err == 0) + { + continue; + } + errno= err; + } } else { memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT); } + int local_errno= get_socket_errno(); // We cache in case memcached_quit_server() modifies errno memcached_quit_server(ptr, true); - return memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT); + return memcached_set_errno(*ptr, local_errno, MEMCACHED_AT); } } } diff --git a/libmemcached/memcached.cc b/libmemcached/memcached.cc index 3201c99c..8c1e3acb 100644 --- a/libmemcached/memcached.cc +++ b/libmemcached/memcached.cc @@ -87,7 +87,7 @@ static inline bool _memcached_init(memcached_st *self) self->virtual_bucket= NULL; - self->distribution= MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY; + self->distribution= MEMCACHED_DISTRIBUTION_MODULA; if (hashkit_create(&self->hashkit) == NULL) { diff --git a/libmemcached/storage.cc b/libmemcached/storage.cc index f3616251..89bc8e87 100644 --- a/libmemcached/storage.cc +++ b/libmemcached/storage.cc @@ -276,7 +276,7 @@ static memcached_return_t memcached_send_ascii(memcached_st *ptr, WATCHPOINT_ASSERT(write_length < MEMCACHED_DEFAULT_COMMAND_SIZE); } - if (ptr->flags.use_udp and ptr->flags.buffer_requests) + if (ptr->flags.use_udp) { size_t cmd_size= write_length + value_length +2; if (cmd_size > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH) diff --git a/libmemcached/strerror.cc b/libmemcached/strerror.cc index ebb90056..b70a60b9 100644 --- a/libmemcached/strerror.cc +++ b/libmemcached/strerror.cc @@ -185,6 +185,9 @@ const char *memcached_strerror(memcached_st *, memcached_return_t rc) case MEMCACHED_SERVER_TEMPORARILY_DISABLED: return "SERVER HAS FAILED AND IS DISABLED UNTIL TIMED RETRY"; + case MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE: + return "SERVER FAILED TO ALLOCATE OBJECT"; + default: case MEMCACHED_MAXIMUM_RETURN: return "INVALID memcached_return_t"; diff --git a/libmemcachedprotocol/common.h b/libmemcachedprotocol/common.h index 398e7ee2..2e3e7c6d 100644 --- a/libmemcachedprotocol/common.h +++ b/libmemcachedprotocol/common.h @@ -45,6 +45,7 @@ #include #include #include +#include /* * I don't really need the following two functions as function pointers diff --git a/libmemcachedutil/ping.cc b/libmemcachedutil/ping.cc index 82d891a9..28d11081 100644 --- a/libmemcachedutil/ping.cc +++ b/libmemcachedutil/ping.cc @@ -42,11 +42,13 @@ bool libmemcached_util_ping(const char *hostname, in_port_t port, memcached_return_t *ret) { memcached_return_t unused; - if (not ret) + if (ret == NULL) + { ret= &unused; + } memcached_st *memc_ptr= memcached_create(NULL); - if (not memc_ptr) + if (memc_ptr == NULL) { *ret= MEMCACHED_MEMORY_ALLOCATION_FAILURE; return false; diff --git a/libtest/include.am b/libtest/include.am index a52c573a..a668d690 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -35,6 +35,9 @@ export GDB_COMMAND valgrind: @echo make check TESTS_ENVIRONMENT="\"$(VALGRIND_COMMAND)\"" +gdb: + @echo make check TESTS_ENVIRONMENT="\"$(GDB_COMMAND)\"" + helgrind: @echo make check TESTS_ENVIRONMENT="\"$(HELGRIND_COMMAND)\"" diff --git a/libtest/string.hpp b/libtest/string.hpp index 8c3d50c1..c79fef26 100644 --- a/libtest/string.hpp +++ b/libtest/string.hpp @@ -25,6 +25,7 @@ #include "util/string.hpp" #define test_literal_param util_literal_param +#define test_literal_compare_param util_literal_compare_param #define test_literal_param_size util_literal_param_size #define test_string_make_from_cstr util_string_make_from_cstr #define test_array_length util_array_length diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 7936a524..ad55d17c 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -48,7 +48,6 @@ static void *world_create(server_startup_st& servers, test_return_t& error) return NULL; } - in_port_t max_port= TEST_PORT_BASE; for (uint32_t x= 0; x < servers.count(); x++) { @@ -249,7 +248,17 @@ static test_return_t _runner_default(libmemcached_test_callback_fn func, libmemc { test_true(container); test_true(container->memc); - return func(container->memc); + test_return_t ret; + try { + ret= func(container->memc); + } + catch (std::exception& e) + { + Error << e.what(); + return TEST_FAILURE; + } + + return ret; } return TEST_SUCCESS; diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index 03dc591d..c2fbdc32 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -485,7 +485,7 @@ static test_return_t memcached_return_t_TEST(memcached_st *memc) 4159057246U, 3425930182U, 2593724503U, 1868899624U, 1769812374U, 2302537950U, 1110330676U, 3365377466U, 1336171666U, 3021258493U, 2334992265U, 3861994737U, - 3365377466U }; + 3582734124, 3365377466U }; // You have updated the memcache_error messages but not updated docs/tests. for (int rc= int(MEMCACHED_SUCCESS); rc < int(MEMCACHED_MAXIMUM_RETURN); ++rc) @@ -501,7 +501,7 @@ static test_return_t memcached_return_t_TEST(memcached_st *memc) } test_compare(values[rc], hash_val); } - test_compare(48, int(MEMCACHED_MAXIMUM_RETURN)); + test_compare(49, int(MEMCACHED_MAXIMUM_RETURN)); return TEST_SUCCESS; } @@ -941,8 +941,11 @@ static test_return_t bad_key_test(memcached_st *memc) memcached_callback_set(memc_clone, MEMCACHED_CALLBACK_NAMESPACE, NULL)); std::vector longkey; - longkey.reserve(MEMCACHED_MAX_KEY); - longkey.insert(longkey.end(), MEMCACHED_MAX_KEY, 'a'); + { + std::vector::iterator it= longkey.begin(); + longkey.insert(it, MEMCACHED_MAX_KEY, 'a'); + } + test_compare(longkey.size(), size_t(MEMCACHED_MAX_KEY)); { size_t string_length; @@ -1854,11 +1857,10 @@ static test_return_t block_add_regression(memcached_st *memc) /* First add all of the items.. */ for (size_t x= 0; x < REGRESSION_BINARY_VS_BLOCK_COUNT; ++x) { - memcached_return_t rc; char blob[1024] = {0}; - rc= memcached_add_by_key(memc, "bob", 3, global_pairs[x].key, global_pairs[x].key_length, blob, sizeof(blob), 0, 0); - test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + memcached_return_t rc= memcached_add_by_key(memc, "bob", 3, global_pairs[x].key, global_pairs[x].key_length, blob, sizeof(blob), 0, 0); + test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE, memcached_strerror(NULL, rc)); } return TEST_SUCCESS; @@ -1866,9 +1868,9 @@ static test_return_t block_add_regression(memcached_st *memc) static test_return_t binary_add_regression(memcached_st *memc) { - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1); + test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, true)); test_return_t rc= block_add_regression(memc); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 0); + return rc; } @@ -2240,32 +2242,32 @@ static test_return_t user_supplied_bug3(memcached_st *memc) getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE); #endif - size_t key_lengths[HALDENBRAND_KEY_COUNT]; - char **keys= static_cast(calloc(HALDENBRAND_KEY_COUNT, sizeof(char *))); - test_true(keys); - for (uint32_t x= 0; x < HALDENBRAND_KEY_COUNT; x++) + std::vector key_lengths; + key_lengths.resize(HALDENBRAND_KEY_COUNT); + std::vector keys; + keys.resize(key_lengths.size()); + for (uint32_t x= 0; x < key_lengths.size(); x++) { char key[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1]; int key_length= snprintf(key, sizeof(key), "%u", x); - test_true(key_length); + test_true(key_length > 0 and key_length < MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1); keys[x]= strdup(key); - test_true(keys[x]); key_lengths[x]= key_length; - test_compare(size_t(key_length), strlen(keys[x])); } test_compare(MEMCACHED_SUCCESS, - memcached_mget(memc, (const char **)keys, key_lengths, HALDENBRAND_KEY_COUNT)); + memcached_mget(memc, &keys[0], &key_lengths[0], key_lengths.size())); unsigned int keys_returned; test_compare(TEST_SUCCESS, fetch_all_results(memc, keys_returned, MEMCACHED_SUCCESS)); test_compare(HALDENBRAND_KEY_COUNT, keys_returned); - for (uint32_t x= 0; x < HALDENBRAND_KEY_COUNT; x++) + for (std::vector::iterator iter= keys.begin(); + iter != keys.end(); + iter++) { - free(keys[x]); + free(*iter); } - free(keys); return TEST_SUCCESS; } @@ -2498,11 +2500,11 @@ static test_return_t user_supplied_bug7(memcached_st *memc) memcached_flush(memc, 0); flags= 245; - memcached_return_t rc= memcached_set(memc, keys, key_length, - insert_data, VALUE_SIZE_BUG5, - (time_t)0, flags); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys, key_length, + insert_data, VALUE_SIZE_BUG5, + (time_t)0, flags)); + memcached_return_t rc; flags= 0; value= memcached_get(memc, keys, key_length, &value_length, &flags, &rc); @@ -2651,12 +2653,12 @@ static test_return_t user_supplied_bug12(memcached_st *memc) value= memcached_get(memc, "autoincrement", strlen("autoincrement"), &value_length, &flags, &rc); - test_true(value == NULL); + test_null(value); test_compare(MEMCACHED_NOTFOUND, rc); rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"), 1, &number_value); - test_true(value == NULL); + test_null(value); /* The binary protocol will set the key if it doesn't exist */ if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1) { @@ -2667,18 +2669,16 @@ static test_return_t user_supplied_bug12(memcached_st *memc) test_compare(MEMCACHED_NOTFOUND, rc); } - rc= memcached_set(memc, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0)); - value= memcached_get(memc, "autoincrement", strlen("autoincrement"), - &value_length, &flags, &rc); + value= memcached_get(memc, "autoincrement", strlen("autoincrement"), &value_length, &flags, &rc); test_true(value); - test_compare(MEMCACHED_SUCCESS, rc); free(value); - rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"), - 1, &number_value); - test_true(number_value == 2); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_increment(memc, "autoincrement", strlen("autoincrement"), 1, &number_value)); + test_compare(2UL, number_value); return TEST_SUCCESS; } @@ -2923,25 +2923,24 @@ static test_return_t _user_supplied_bug21(memcached_st* memc, size_t key_count) /* empty the cache to ensure misses (hence non-responses) */ test_compare(MEMCACHED_SUCCESS, memcached_flush(memc_clone, 0)); - size_t* key_lengths= new (std::nothrow) size_t[key_count]; - test_true(key_lengths); - char **keys= static_cast(calloc(key_count, sizeof(char *))); - test_true(keys); - for (unsigned int x= 0; x < key_count; x++) + std::vector key_lengths; + key_lengths.resize(key_count); + std::vector keys; + keys.resize(key_lengths.size()); + for (unsigned int x= 0; x < key_lengths.size(); x++) { - char buffer[30]; - - snprintf(buffer, 30, "%u", x); - keys[x]= strdup(buffer); - test_true(keys[x]); - key_lengths[x]= strlen(keys[x]); + char key[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1]; + int key_length= snprintf(key, sizeof(key), "%u", x); + test_true(key_length > 0 and key_length < MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1); + keys[x]= strdup(key); + key_lengths[x]= key_length; } oldalarm= signal(SIGALRM, fail); alarm(5); test_compare_got(MEMCACHED_SUCCESS, - memcached_mget(memc_clone, (const char **)keys, key_lengths, key_count), memcached_last_error_message(memc_clone)); + memcached_mget(memc_clone, &keys[0], &key_lengths[0], key_count), memcached_last_error_message(memc_clone)); alarm(0); signal(SIGALRM, oldalarm); @@ -2963,12 +2962,12 @@ static test_return_t _user_supplied_bug21(memcached_st* memc, size_t key_count) test_false(return_key[0]); test_false(return_value); - for (unsigned int x= 0; x < key_count; x++) + for (std::vector::iterator iter= keys.begin(); + iter != keys.end(); + iter++) { - free(keys[x]); + free(*iter); } - free(keys); - delete [] key_lengths; memcached_free(memc_clone); @@ -3123,17 +3122,16 @@ static test_return_t generate_data(memcached_st *memc) static test_return_t generate_data_with_stats(memcached_st *memc) { - uint32_t host_index= 0; unsigned int check_execute= execute_set(memc, global_pairs, global_count); - test_true(check_execute == global_count); + test_compare(check_execute, global_count); // @todo hosts used size stats memcached_return_t rc; memcached_stat_st *stat_p= memcached_stat(memc, NULL, &rc); test_true(stat_p); - for (host_index= 0; host_index < SERVERS_TO_CREATE; host_index++) + for (uint32_t host_index= 0; host_index < SERVERS_TO_CREATE; host_index++) { /* This test was changes so that "make test" would work properlly */ if (DEBUG) @@ -3467,7 +3465,7 @@ static test_return_t pre_jenkins(memcached_st *memc) { memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_JENKINS); - return TEST_SUCCESS; + return TEST_SKIPPED; } @@ -5642,7 +5640,9 @@ test_st tests[] ={ {"analyzer", true, (test_callback_fn*)analyzer_test}, {"memcached_pool_st", true, (test_callback_fn*)connection_pool_test }, {"memcached_pool_st #2", true, (test_callback_fn*)connection_pool2_test }, +#if 0 {"memcached_pool_st #3", true, (test_callback_fn*)connection_pool3_test }, +#endif {"memcached_pool_test", true, (test_callback_fn*)memcached_pool_test }, {"test_get_last_disconnect", true, (test_callback_fn*)test_get_last_disconnect}, {"verbosity", true, (test_callback_fn*)test_verbosity}, diff --git a/tests/mem_udp.cc b/tests/mem_udp.cc index e33610da..16fc1c73 100644 --- a/tests/mem_udp.cc +++ b/tests/mem_udp.cc @@ -173,17 +173,20 @@ static test_return_t udp_set_test(memcached_st *memc) { unsigned int num_iters= 1025; //request id rolls over at 1024 + test_true(memc); + for (size_t x= 0; x < num_iters;x++) { Expected expected_ids; get_udp_request_ids(memc, expected_ids); unsigned int server_key= memcached_generate_hash(memc, test_literal_param("foo")); + test_true(server_key < memcached_server_count(memc)); memcached_server_instance_st instance= memcached_server_instance_by_position(memc, server_key); size_t init_offset= instance->write_buffer_offset; memcached_return_t rc= memcached_set(memc, test_literal_param("foo"), test_literal_param("when we sanitize"), - (time_t)0, (uint32_t)0); + time_t(0), uint32_t(0)); test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); /** NB, the check below assumes that if new write_ptr is less than * the original write_ptr that we have flushed. For large payloads, this @@ -212,12 +215,14 @@ static test_return_t udp_set_test(memcached_st *memc) static test_return_t udp_buffered_set_test(memcached_st *memc) { + test_true(memc); test_compare(MEMCACHED_INVALID_ARGUMENTS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, true)); return TEST_SUCCESS; } static test_return_t udp_set_too_big_test(memcached_st *memc) { + test_true(memc); char value[MAX_UDP_DATAGRAM_LENGTH]; Expected expected_ids; get_udp_request_ids(memc, expected_ids); @@ -232,6 +237,8 @@ static test_return_t udp_set_too_big_test(memcached_st *memc) static test_return_t udp_delete_test(memcached_st *memc) { + test_true(memc); + //request id rolls over at 1024 for (size_t x= 0; x < 1025; x++) { @@ -447,7 +454,7 @@ collection_st collection[] ={ }; #define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT +10 -#include "libmemcached_world.h" +#include "tests/libmemcached_world.h" void get_world(Framework *world) { diff --git a/tests/parser.cc b/tests/parser.cc index bfcb0816..32b0d9d8 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -41,7 +41,6 @@ using namespace libtest; #include -#include #include #include #include @@ -224,7 +223,9 @@ scanner_variable_t hash_strings[]= { { ARRAY, make_scanner_string("--HASH=CRC"), scanner_string_null, NULL }, { ARRAY, make_scanner_string("--HASH=FNV1A_32"), scanner_string_null, NULL }, { ARRAY, make_scanner_string("--HASH=FNV1_32"), scanner_string_null, NULL }, +#if 0 { ARRAY, make_scanner_string("--HASH=JENKINS"), scanner_string_null, NULL }, +#endif { ARRAY, make_scanner_string("--HASH=MD5"), scanner_string_null, NULL }, { NIL, scanner_string_null, scanner_string_null, NULL} }; @@ -235,10 +236,10 @@ static test_return_t _test_option(scanner_variable_t *scanner, bool test_true_op for (scanner_variable_t *ptr= scanner; ptr->type != NIL; ptr++) { memcached_st *memc= memcached(ptr->option.c_str, ptr->option.size); - - // The case that it should have parsed, but it didn't. We will inspect - // for an error with libmemcached_check_configuration() - if (not memc and test_true_opt) + + // The case that it should have parsed, but it didn't. We will inspect for + // an error with libmemcached_check_configuration() + if (memc == NULL and test_true_opt) { char buffer[2048]; bool success= libmemcached_check_configuration(ptr->option.c_str, ptr->option.size, buffer, sizeof(buffer)); @@ -247,6 +248,7 @@ static test_return_t _test_option(scanner_variable_t *scanner, bool test_true_op temp+= " with option string:"; temp+= ptr->option.c_str; test_true_got(success, temp.c_str()); + Error << "Failed for " << temp; return TEST_FAILURE; // The line above should fail since memc should be null } @@ -334,11 +336,9 @@ test_return_t test_namespace_keyword(memcached_st*) test_return_t memcached_create_with_options_with_filename(memcached_st*) { - if (access(SUPPORT_EXAMPLE_CNF, R_OK)) - return TEST_SKIPPED; + test_skip(0, access(SUPPORT_EXAMPLE_CNF, R_OK)); - memcached_st *memc_ptr; - memc_ptr= memcached(test_literal_param("--CONFIGURE-FILE=\"support/example.cnf\"")); + memcached_st *memc_ptr= memcached(test_literal_param("--CONFIGURE-FILE=\"support/example.cnf\"")); test_true_got(memc_ptr, "memcached() failed"); memcached_free(memc_ptr); @@ -347,56 +347,58 @@ test_return_t memcached_create_with_options_with_filename(memcached_st*) test_return_t libmemcached_check_configuration_with_filename_test(memcached_st*) { - if (access(SUPPORT_EXAMPLE_CNF, R_OK)) - return TEST_SKIPPED; + test_skip(0, access(SUPPORT_EXAMPLE_CNF, R_OK)); - memcached_return_t rc; char buffer[BUFSIZ]; - rc= libmemcached_check_configuration(test_literal_param("--CONFIGURE-FILE=\"support/example.cnf\""), buffer, sizeof(buffer)); - test_true_got(rc == MEMCACHED_SUCCESS, (rc == MEMCACHED_ERRNO) ? strerror(errno) : memcached_strerror(NULL, rc)); + test_compare_hint(MEMCACHED_SUCCESS, + libmemcached_check_configuration(test_literal_param("--CONFIGURE-FILE=\"support/example.cnf\""), buffer, sizeof(buffer)), + buffer); - rc= libmemcached_check_configuration(test_literal_param("--CONFIGURE-FILE=support/example.cnf"), buffer, sizeof(buffer)); - test_false_with(rc == MEMCACHED_SUCCESS, memcached_strerror(NULL, rc)); + test_compare_hint(MEMCACHED_SUCCESS, + libmemcached_check_configuration(test_literal_param("--CONFIGURE-FILE=support/example.cnf"), buffer, sizeof(buffer)), + buffer); - rc= libmemcached_check_configuration(test_literal_param("--CONFIGURE-FILE=\"bad-path/example.cnf\""), buffer, sizeof(buffer)); - test_true_got(rc == MEMCACHED_ERRNO, memcached_strerror(NULL, rc)); + test_compare_hint(MEMCACHED_ERRNO, + libmemcached_check_configuration(test_literal_param("--CONFIGURE-FILE=\"bad-path/example.cnf\""), buffer, sizeof(buffer)), + buffer) ; return TEST_SUCCESS; } test_return_t libmemcached_check_configuration_test(memcached_st*) { - memcached_return_t rc; char buffer[BUFSIZ]; - test_compare(MEMCACHED_SUCCESS, libmemcached_check_configuration(test_literal_param("--server=localhost"), buffer, sizeof(buffer))); - rc= libmemcached_check_configuration(test_literal_param("--dude=localhost"), buffer, sizeof(buffer)); - test_false_with(rc == MEMCACHED_SUCCESS, buffer); - test_true(rc == MEMCACHED_PARSE_ERROR); + test_compare_hint(MEMCACHED_PARSE_ERROR, + libmemcached_check_configuration(test_literal_param("--dude=localhost"), buffer, sizeof(buffer)), + buffer); return TEST_SUCCESS; } test_return_t memcached_create_with_options_test(memcached_st*) { - memcached_st *memc_ptr; - memc_ptr= memcached(test_literal_param("--server=localhost")); - test_true_got(memc_ptr, memcached_last_error_message(memc_ptr)); - memcached_free(memc_ptr); + { + memcached_st *memc_ptr; + memc_ptr= memcached(test_literal_param("--server=localhost")); + test_true_got(memc_ptr, memcached_last_error_message(memc_ptr)); + memcached_free(memc_ptr); + } - memc_ptr= memcached(test_literal_param("--dude=localhost")); - test_false_with(memc_ptr, memcached_last_error_message(memc_ptr)); + { + memcached_st *memc_ptr= memcached(test_literal_param("--dude=localhost")); + test_false_with(memc_ptr, memcached_last_error_message(memc_ptr)); + } return TEST_SUCCESS; } test_return_t test_include_keyword(memcached_st*) { - if (access(SUPPORT_EXAMPLE_CNF, R_OK)) - return TEST_SKIPPED; + test_skip(0, access(SUPPORT_EXAMPLE_CNF, R_OK)); char buffer[BUFSIZ]; test_compare(MEMCACHED_SUCCESS, @@ -433,7 +435,7 @@ test_return_t test_error_keyword(memcached_st*) return TEST_SUCCESS; } -#define RANDOM_STRINGS 100 +#define RANDOM_STRINGS 1000 test_return_t random_statement_build_test(memcached_st*) { std::vector option_list; @@ -456,6 +458,30 @@ test_return_t random_statement_build_test(memcached_st*) for (scanner_variable_t *ptr= hash_strings; ptr->type != NIL; ptr++) option_list.push_back(&ptr->option); + std::vector used_list; + used_list.resize(option_list.size()); + + struct used_options_st { + bool has_hash; + bool has_namespace; + bool has_distribution; + bool has_buffer_requests; + bool has_udp; + bool has_binary; + bool has_verify_key; + + used_options_st() : + has_hash(false), + has_namespace(false), + has_distribution(false), + has_buffer_requests(false), + has_udp(false), + has_binary(false), + has_verify_key(false) + { + } + } used_options; + for (uint32_t x= 0; x < RANDOM_STRINGS; x++) { std::string random_options; @@ -463,38 +489,127 @@ test_return_t random_statement_build_test(memcached_st*) uint32_t number_of= random() % option_list.size(); for (uint32_t options= 0; options < number_of; options++) { - random_options+= option_list[random() % option_list.size()]->c_str; - random_options+= " "; - } + size_t option_list_position= random() % option_list.size(); - memcached_st *memc_ptr= memcached(random_options.c_str(), random_options.size() -1); - if (not memc_ptr) - { - switch (errno) + if (used_list[option_list_position]) { - case EINVAL: -#if 0 // Testing framework is not smart enough for this just yet. + continue; + } + used_list[option_list_position]= true; + + std::string random_string= option_list[option_list_position]->c_str; + + if (random_string.compare(0, test_literal_compare_param("--HASH")) == 0) + { + if (used_options.has_hash) { - // We will try to find the specific error - char buffer[2048]; - memcached_return_t rc= libmemcached_check_configuration(random_options.c_str(), random_options.size(), buffer, sizeof(buffer)); - test_true_got(rc != MEMCACHED_SUCCESS, "memcached_create_with_options() failed whiled libmemcached_check_configuration() was successful"); - std::cerr << "Error occured on " << random_options.c_str() << " : " << buffer << std::endl; - return TEST_FAILURE; + continue; + } + + if (used_options.has_distribution) + { + continue; + } + used_options.has_hash= true; + } + + if (random_string.compare(0, test_literal_compare_param("--NAMESPACE")) == 0) + { + if (used_options.has_namespace) + { + continue; + } + used_options.has_namespace= true; + } + + if (random_string.compare(0, test_literal_compare_param("--USE-UDP")) == 0) + { + if (used_options.has_udp) + { + continue; + } + used_options.has_udp= true; + + if (used_options.has_buffer_requests) + { + continue; } -#endif - break; - case ENOMEM: - std::cerr << "Failed to allocate memory for memcached_create_with_options()" << std::endl; - memcached_free(memc_ptr); - return TEST_FAILURE; - default: - std::cerr << "Unknown error from memcached_create_with_options?!!" << std::endl; - memcached_free(memc_ptr); - return TEST_FAILURE; } + + if (random_string.compare(0, test_literal_compare_param("--BUFFER-REQUESTS")) == 0) + { + if (used_options.has_buffer_requests) + { + continue; + } + used_options.has_buffer_requests= true; + + if (used_options.has_udp) + { + continue; + } + } + + if (random_string.compare(0, test_literal_compare_param("--BINARY-PROTOCOL")) == 0) + { + if (used_options.has_binary) + { + continue; + } + used_options.has_binary= true; + + if (used_options.has_verify_key) + { + continue; + } + } + + if (random_string.compare(0, test_literal_compare_param("--VERIFY-KEY")) == 0) + { + if (used_options.has_verify_key) + { + continue; + } + used_options.has_verify_key= true; + + if (used_options.has_binary) + { + continue; + } + } + + if (random_string.compare(0, test_literal_compare_param("--DISTRIBUTION")) == 0) + { + if (used_options.has_distribution) + { + continue; + } + + if (used_options.has_hash) + { + continue; + } + used_options.has_distribution= true; + } + + random_options+= random_string; + random_options+= " "; + } + + if (random_options.size() <= 1) + { + continue; + } + + random_options.resize(random_options.size() -1); + + char buffer[BUFSIZ]; + memcached_return_t rc= libmemcached_check_configuration(random_options.c_str(), random_options.size(), buffer, sizeof(buffer)); + if (memcached_failed(rc)) + { + Error << "libmemcached_check_configuration(" << random_options << ") : " << buffer; + return TEST_FAILURE; } - memcached_free(memc_ptr); } return TEST_SUCCESS; @@ -558,7 +673,7 @@ static memcached_return_t dump_socket_information(const memcached_st *, if (strcmp(memcached_server_name(instance), check->socket)) { - std::cerr << std::endl << __FILE__ << ":" << __LINE__ << " " << memcached_server_name(instance) << " != " << check->socket << std::endl; + Error << memcached_server_name(instance) << " != " << check->socket; return MEMCACHED_FAILURE; } diff --git a/tests/plus.cpp b/tests/plus.cpp index 7de8164f..5078f1f5 100644 --- a/tests/plus.cpp +++ b/tests/plus.cpp @@ -282,7 +282,7 @@ collection_st collection[] ={ #define SERVERS_TO_CREATE 5 #define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT +10 -#include "libmemcached_world.h" +#include "tests/libmemcached_world.h" void get_world(Framework *world) { diff --git a/util/string.hpp b/util/string.hpp index 58d0ce27..873551e5 100644 --- a/util/string.hpp +++ b/util/string.hpp @@ -47,6 +47,8 @@ #define util_literal_param(X) (X), (static_cast((sizeof(X) - 1))) #define util_literal_param_size(X) static_cast(sizeof(X) - 1) +#define util_literal_compare_param(X) (static_cast((sizeof(X) - 1))), (X) + #define util_string_make_from_cstr(X) (X), ((X) ? strlen(X) : 0) #define util_array_length(__array) sizeof(__array)/sizeof(&__array)