From 013ba5f610951d6c322a99d780aca6713f314140 Mon Sep 17 00:00:00 2001
From: Radek Senfeld <rush@logic.cz>
Date: Tue, 11 Oct 2011 22:45:49 +0200
Subject: [PATCH] fixed #ifdef issue when libmemcached is compiled with SASL
support disabled
---
_pylibmcmodule.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/_pylibmcmodule.c b/_pylibmcmodule.c
index 093ccbe..644ce49 100644
--- a/_pylibmcmodule.c
+++ b/_pylibmcmodule.c
@@ -65,7 +65,7 @@ static PylibMC_Client *PylibMC_ClientType_new(PyTypeObject *type,
static void PylibMC_ClientType_dealloc(PylibMC_Client *self) {
if (self->mc != NULL) {
-#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
+#if LIBMEMCACHED_WITH_SASL_SUPPORT
if (self->sasl_set) {
memcached_destroy_sasl_auth_data(self->mc);
}
@@ -98,7 +98,7 @@ static int PylibMC_Client_init(PylibMC_Client *self, PyObject *args,
/* setup sasl */
if (user != NULL || pass != NULL) {
-#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
+#if LIBMEMCACHED_WITH_SASL_SUPPORT
if (user == NULL || pass == NULL) {
PyErr_SetString(PyExc_TypeError, "SASL requires both username and password");
goto error;
@@ -2019,7 +2019,7 @@ static int _PylibMC_CheckKeyStringAndSize(char *key, Py_ssize_t size) {
}
static int _init_sasl(void) {
-#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
+#if LIBMEMCACHED_WITH_SASL_SUPPORT
int rc;
/* sasl_client_init needs to be called once before using SASL, and
@@ -2168,7 +2168,7 @@ PyMODINIT_FUNC init_pylibmc(void) {
PyModule_AddStringConstant(module,
"libmemcached_version", LIBMEMCACHED_VERSION_STRING);
-#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
+#if LIBMEMCACHED_WITH_SASL_SUPPORT
PyModule_ADD_REF(module, "support_sasl", Py_True);
#else
PyModule_ADD_REF(module, "support_sasl", Py_False);
--
1.7.10
From c1088cb8c7448c58acdb3194f5a6944b7bdcd823 Mon Sep 17 00:00:00 2001
From: Ludvig Ericson <ludvig@lericson.se>
Date: Sun, 4 Dec 2011 20:07:03 +0100
Subject: [PATCH] Use memcached_last_error_message() where possible
---
_pylibmcmodule.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)
diff --git a/_pylibmcmodule.c b/_pylibmcmodule.c
index 5dd7e21..2371b66 100644
--- a/_pylibmcmodule.c
+++ b/_pylibmcmodule.c
@@ -1871,24 +1871,11 @@ static PyObject *PylibMC_Client_clone(PylibMC_Client *self) {
static char *_get_lead(memcached_st *mc, char *buf, int n, const char *what,
memcached_return error, const char *key, Py_ssize_t len) {
- int sz = snprintf(buf, n, "error %d from %s", error, what);
+ int sz = snprintf(buf, n, "error %d from %.32s", error, what);
- /*
- * Need to protect from libmemcached versions as their
- * memcached_server_instance_st are called (memcached_server_st *).
- */
-#if LIBMEMCACHED_VERSION_HEX >= 0x00038000
- if (key != NULL) {
- memcached_return rc = MEMCACHED_FAILURE;
- memcached_server_instance_st svr = NULL;
-
- svr = memcached_server_by_key(mc, key, len, &rc);
- if (svr && rc == MEMCACHED_SUCCESS) {
- sz += snprintf(buf + sz, n - sz, " on %s:%d",
- svr->hostname, svr->port);
- }
+ if (key != NULL && len) {
+ sz += snprintf(buf+sz, n-sz, "(%.32s)", key);
}
-#endif
return buf;
}
@@ -1910,7 +1897,11 @@ static void _set_error(memcached_st *mc, memcached_return error, char *lead) {
}
}
- PyErr_Format(exc, "%s: %s", lead, memcached_strerror(mc, error));
+#if LIBMEMCACHED_VERSION_HEX >= 0x00049000
+ PyErr_Format(exc, "%s: %.200s", lead, memcached_last_error_message(mc));
+#else
+ PyErr_Format(exc, "%s: %.200s", lead, memcached_strerror(mc, error));
+#endif
}
}
--
1.7.10