summaryrefslogtreecommitdiffstats
path: root/Objects/obmalloc.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-07 21:30:24 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-07-07 21:30:24 (GMT)
commit49fc8ece8172162510890f42127d2aa4e13f878b (patch)
tree798c7555b232e40e607ec1b01cec87687515cf57 /Objects/obmalloc.c
parent6f8eeee7b9cae7e3f899c89baefe9acc575f2fb5 (diff)
downloadcpython-49fc8ece8172162510890f42127d2aa4e13f878b.zip
cpython-49fc8ece8172162510890f42127d2aa4e13f878b.tar.gz
cpython-49fc8ece8172162510890f42127d2aa4e13f878b.tar.bz2
Issue #18203: Add _PyMem_RawStrdup() and _PyMem_Strdup()
Replace strdup() with _PyMem_RawStrdup() or _PyMem_Strdup(), depending if the GIL is held or not.
Diffstat (limited to 'Objects/obmalloc.c')
-rw-r--r--Objects/obmalloc.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index 97a137d..8e25229 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -294,6 +294,34 @@ PyMem_Free(void *ptr)
_PyMem.free(_PyMem.ctx, ptr);
}
+char *
+_PyMem_RawStrdup(const char *str)
+{
+ size_t size;
+ char *copy;
+
+ size = strlen(str) + 1;
+ copy = PyMem_RawMalloc(size);
+ if (copy == NULL)
+ return NULL;
+ memcpy(copy, str, size);
+ return copy;
+}
+
+char *
+_PyMem_Strdup(const char *str)
+{
+ size_t size;
+ char *copy;
+
+ size = strlen(str) + 1;
+ copy = PyMem_Malloc(size);
+ if (copy == NULL)
+ return NULL;
+ memcpy(copy, str, size);
+ return copy;
+}
+
void *
PyObject_Malloc(size_t size)
{