Skip to content

Instantly share code, notes, and snippets.

@yaymukund
Created November 18, 2011 21:15
Show Gist options
  • Save yaymukund/1377779 to your computer and use it in GitHub Desktop.
Save yaymukund/1377779 to your computer and use it in GitHub Desktop.
Patch for installing pylibmc
--- _pylibmcmodule.c.old»···2011-11-18 13:10:03.000000000 -0800
+++ _pylibmcmodule.c»···2011-11-18 02:51:05.000000000 -0800
@@ -45,6 +45,26 @@
#define PyModule_ADD_REF(mod, nam, obj) \
{ Py_INCREF(obj); \
PyModule_AddObject(mod, nam, obj); }
+size_t
+strnlen(const char *s, size_t maxlen)
+{
+ const char * eospos;
+ eospos = memchr(s, (int)'\0', maxlen);
+ return (eospos == NULL ? maxlen : (size_t)(eospos-s));
+}
+
+char *
+strndup (char const *s, size_t n)
+{
+ size_t len = strnlen (s, n);
+ char *new = malloc (len + 1);
+
+ if (new == NULL)
+ return NULL;
+
+ new[len] = '\0';
+ return memcpy (new, s, len);
+}
·
/* {{{ Type methods */
static PylibMC_Client *PylibMC_ClientType_new(PyTypeObject *type,
--- _pylibmcmodule.c.old»···2011-11-18 13:10:03.000000000 -0800
+++ _pylibmcmodule.c»···2011-11-18 02:51:05.000000000 -0800
@@ -45,6 +45,26 @@
#define PyModule_ADD_REF(mod, nam, obj) \
{ Py_INCREF(obj); \
PyModule_AddObject(mod, nam, obj); }
+size_t
+strnlen(const char *s, size_t maxlen)
+{
+ const char * eospos;
+ eospos = memchr(s, (int)'\0', maxlen);
+ return (eospos == NULL ? maxlen : (size_t)(eospos-s));
+}
+
+char *
+strndup (char const *s, size_t n)
+{
+ size_t len = strnlen (s, n);
+ char *new = malloc (len + 1);
+
+ if (new == NULL)
+ return NULL;
+
+ new[len] = '\0';
+ return memcpy (new, s, len);
+}
·
/* {{{ Type methods */
static PylibMC_Client *PylibMC_ClientType_new(PyTypeObject *type,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment