Index: _pylibmcmodule.c ===================================================================
33 | 33 | |
---|---|---|
34 | 34 | #include "_pylibmcmodule.h" |
35 | 35 | |
36 | ||
36 | 37 | /* {{{ _pylibmc.client implementation */ |
37 | 38 | /* {{{ Type methods */ |
38 | 39 | static PylibMC_Client *PylibMC_ClientType_new(PyTypeObject *type, |
… | ||
131 | 132 | case PYLIBMC_FLAG_PICKLE: |
132 | 133 | retval = _PylibMC_Unpickle(value, size); |
133 | 134 | break; |
135 | case PYLIBMC_FLAG_BOOL_TRUE: | |
136 | retval = Py_True; | |
137 | break; | |
138 | case PYLIBMC_FLAG_BOOL_FALSE: | |
139 | retval = Py_False; | |
140 | break; | |
134 | 141 | case PYLIBMC_FLAG_INTEGER: |
135 | 142 | case PYLIBMC_FLAG_LONG: |
136 | 143 | retval = PyInt_FromString(value, NULL, 10); |
137 | 144 | break; |
138 | 145 | case PYLIBMC_FLAG_NONE: |
139 | retval = PyString_FromStringAndSize(value, ( |
|
146 | retval = PyString_FromStringAndSize(value, (size_t)size); | |
140 | 147 | break; |
141 | 148 | default: |
142 | 149 | PyErr_Format(PylibMCExc_MemcachedError, |
… | ||
199 | 206 | } else if (PyString_Check(val)) { |
200 | 207 | store_val = val; |
201 | 208 | Py_INCREF(store_val); |
209 | } else if (val == Py_True) { | |
210 | store_flags |= PYLIBMC_FLAG_BOOL_TRUE; | |
211 | store_val = PyObject_Str(val); | |
212 | } else if (val == Py_False) { | |
213 | store_flags |= PYLIBMC_FLAG_BOOL_FALSE; | |
214 | store_val = PyObject_Str(val); | |
202 | 215 | } else if (PyInt_Check(val)) { |
203 | 216 | store_flags |= PYLIBMC_FLAG_INTEGER; |
204 | 217 | store_val = PyObject_Str(val); |
… | ||
345 | 358 | char **keys, *prefix = NULL; |
346 | 359 | unsigned int prefix_len = 0; |
347 | 360 | size_t *key_lens; |
348 | |
|
361 | size_t nkeys; | |
349 | 362 | memcached_return rc; |
350 | 363 | |
351 | 364 | char curr_key[MEMCACHED_MAX_KEY]; |
… | ||
712 | 725 | if (error == MEMCACHED_ERRNO) { |
713 | 726 | PyErr_Format(PylibMCExc_MemcachedError, |
714 | 727 | "system error %d from %s: %s", errno, what, strerror(errno)); |
728 | /* The key exists, but it has no value */ | |
729 | } else if(error == 0) { | |
730 | return PyString_FromStringAndSize("", 0); | |
715 | 731 | } else { |
716 | 732 | PyErr_Format(PylibMCExc_MemcachedError, "error %d from %s: %s", |
717 | 733 | error, what, memcached_strerror(self->mc, error)); |
Index: pylibmc.py ===================================================================
64 | 64 | addr_tups.append((stype, addr, port)) |
---|---|---|
65 | 65 | super(Client, self).__init__(addr_tups) |
66 | 66 | |
67 | #Perfomance is generally a lot better with tcp_nodelay | |
68 | #so set that as a default | |
69 | self.set_behaviors({'tcp_nodelay': 1}) | |
70 | ||
67 | 71 | def get_behaviors(self): |
68 | 72 | behaviors = super(Client, self).get_behaviors() |
69 | 73 | behaviors["hash"] = hashers_rvs[behaviors["hash"]] |
Index: setup.py ===================================================================
60 | 60 | to it, as well as implemented behaviors. |
---|---|---|
61 | 61 | """ |
62 | 62 | |
63 | import os | |
63 | 64 | from distutils.core import setup, Extension |
64 | 65 | |
66 | BASE_CFLAGS = ['-O3'] #Apply highest optimization | |
67 | BASE_LDFLAGS = [] | |
68 | ||
69 | mac_snow_leopard = os.path.exists('/Developer/SDKs/MacOSX10.6.sdk/') and\ | |
70 | int(os.uname()[2].split('.')[0]) >= 8 | |
71 | ||
72 | if mac_snow_leopard: | |
73 | #Only compile the 64bit version on Snow Leopard | |
74 | #libmemcached should also be compiled with make | |
75 | # CFLAGS="-arch x86_64" | |
76 | #else one will expereince seg. faults | |
77 | BASE_LDFLAGS.extend(['-arch', 'x86_64']) | |
78 | BASE_CFLAGS.extend(['-arch', 'x86_64']) | |
79 | ||
65 | 80 | pylibmc_ext = Extension("_pylibmc", ["_pylibmcmodule.c"], |
81 | extra_compile_args=BASE_CFLAGS, | |
82 | extra_link_args=BASE_LDFLAGS, | |
66 | 83 | libraries=["memcached"]) |
67 | 84 | |
68 | 85 | setup(name="pylibmc", version="0.6.1", |
Index: _pylibmcmodule.h ===================================================================
47 | 47 | #define PYLIBMC_FLAG_PICKLE (1 << 0) |
---|---|---|
48 | 48 | #define PYLIBMC_FLAG_INTEGER (1 << 1) |
49 | 49 | #define PYLIBMC_FLAG_LONG (1 << 2) |
50 | #define PYLIBMC_FLAG_BOOL_TRUE (1 << 3) | |
51 | #define PYLIBMC_FLAG_BOOL_FALSE (1 << 4) | |
50 | 52 | |
51 | 53 | #define PYLIBMC_INC (1 << 0) |
52 | 54 | #define PYLIBMC_DEC (1 << 1) |
Direct link: https://paste.plurk.com/show/17567