mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #18203: Add _PyMem_RawStrdup() and _PyMem_Strdup()
Replace strdup() with _PyMem_RawStrdup() or _PyMem_Strdup(), depending if the GIL is held or not.
This commit is contained in:
parent
6f8eeee7b9
commit
49fc8ece81
8 changed files with 64 additions and 29 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue