Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Index: _pylibmcmodule.c
===================================================================
--- _pylibmcmodule.c	(revision 7071)
+++ _pylibmcmodule.c	(working copy)
@@ -33,6 +33,7 @@

 #include "_pylibmcmodule.h"

+
 /* {{{ _pylibmc.client implementation */
 /* {{{ Type methods */
 static PylibMC_Client *PylibMC_ClientType_new(PyTypeObject *type,
@@ -131,12 +132,18 @@
         case PYLIBMC_FLAG_PICKLE:
             retval = _PylibMC_Unpickle(value, size);
             break;
+        case PYLIBMC_FLAG_BOOL_TRUE:
+            retval = Py_True;
+            break;
+        case PYLIBMC_FLAG_BOOL_FALSE:
+            retval = Py_False;
+            break;
         case PYLIBMC_FLAG_INTEGER:
         case PYLIBMC_FLAG_LONG:
             retval = PyInt_FromString(value, NULL, 10);
             break;
         case PYLIBMC_FLAG_NONE:
-            retval = PyString_FromStringAndSize(value, (Py_ssize_t)size);
+            retval = PyString_FromStringAndSize(value, (size_t)size);
             break;
         default:
             PyErr_Format(PylibMCExc_MemcachedError,
@@ -199,6 +206,12 @@
         } else if (PyString_Check(val)) {
             store_val = val;
             Py_INCREF(store_val);
+        } else if (val == Py_True) {
+            store_flags |= PYLIBMC_FLAG_BOOL_TRUE;
+            store_val = PyObject_Str(val);
+        } else if (val == Py_False) {
+            store_flags |= PYLIBMC_FLAG_BOOL_FALSE;
+            store_val = PyObject_Str(val);
         } else if (PyInt_Check(val)) {
             store_flags |= PYLIBMC_FLAG_INTEGER;
             store_val = PyObject_Str(val);
@@ -345,7 +358,7 @@
     char **keys, *prefix = NULL;
     unsigned int prefix_len = 0;
     size_t *key_lens;
-    Py_ssize_t nkeys;
+    size_t nkeys;
     memcached_return rc;

     char curr_key[MEMCACHED_MAX_KEY];
@@ -712,6 +725,9 @@
     if (error == MEMCACHED_ERRNO) {
         PyErr_Format(PylibMCExc_MemcachedError,
                 "system error %d from %s: %s", errno, what, strerror(errno));
+    /* The key exists, but it has no value */
+    } else if(error == 0) {
+        return PyString_FromStringAndSize("", 0);
     } else { 
         PyErr_Format(PylibMCExc_MemcachedError, "error %d from %s: %s",
                 error, what, memcached_strerror(self->mc, error));
Index: pylibmc.py
===================================================================
--- pylibmc.py	(revision 7071)
+++ pylibmc.py	(working copy)
@@ -64,6 +64,10 @@
             addr_tups.append((stype, addr, port))
         super(Client, self).__init__(addr_tups)

+        #Perfomance is generally a lot better with tcp_nodelay
+        #so set that as a default
+        self.set_behaviors({'tcp_nodelay': 1})
+
     def get_behaviors(self):
         behaviors = super(Client, self).get_behaviors()
         behaviors["hash"] = hashers_rvs[behaviors["hash"]]
Index: setup.py
===================================================================
--- setup.py	(revision 7071)
+++ setup.py	(working copy)
@@ -60,9 +60,26 @@
 to it, as well as implemented behaviors.
 """

+import os
 from distutils.core import setup, Extension

+BASE_CFLAGS = ['-O3'] #Apply highest optimization
+BASE_LDFLAGS = []
+
+mac_snow_leopard = os.path.exists('/Developer/SDKs/MacOSX10.6.sdk/') and\
+                   int(os.uname()[2].split('.')[0]) >= 8
+
+if mac_snow_leopard:
+    #Only compile the 64bit version on Snow Leopard
+    #libmemcached should also be compiled with make
+    #   CFLAGS="-arch x86_64"
+    #else one will expereince seg. faults
+    BASE_LDFLAGS.extend(['-arch', 'x86_64'])
+    BASE_CFLAGS.extend(['-arch', 'x86_64'])
+
 pylibmc_ext = Extension("_pylibmc", ["_pylibmcmodule.c"],
+                        extra_compile_args=BASE_CFLAGS,
+                        extra_link_args=BASE_LDFLAGS,
                         libraries=["memcached"])

 setup(name="pylibmc", version="0.6.1",
Index: _pylibmcmodule.h
===================================================================
--- _pylibmcmodule.h	(revision 7071)
+++ _pylibmcmodule.h	(working copy)
@@ -47,6 +47,8 @@
 #define PYLIBMC_FLAG_PICKLE  (1 << 0)
 #define PYLIBMC_FLAG_INTEGER (1 << 1)
 #define PYLIBMC_FLAG_LONG    (1 << 2)
+#define PYLIBMC_FLAG_BOOL_TRUE    (1 << 3)
+#define PYLIBMC_FLAG_BOOL_FALSE    (1 << 4)

 #define PYLIBMC_INC  (1 << 0)
 #define PYLIBMC_DEC  (1 << 1)