Skip to content

Moving _PyMem_RawStrdup to private API causes build failure #127991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
clin1234 opened this issue Dec 16, 2024 · 5 comments
Closed

Moving _PyMem_RawStrdup to private API causes build failure #127991

clin1234 opened this issue Dec 16, 2024 · 5 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) pending The issue will be closed if no feedback is provided topic-C-API

Comments

@clin1234
Copy link

#106320 causes build failure in marcelotduarte/cx_Freeze#2568 (comment)

What is the recommended replacement for the now private function?

@tomasr8
Copy link
Member

tomasr8 commented Dec 16, 2024

Made private here: #107187

I think as a replacement you can do what the function is doing internally, that is, call PyMem_RawMalloc and memcpy:

cpython/Objects/obmalloc.c

Lines 1047 to 1057 in 52d552c

_PyMem_RawStrdup(const char *str)
{
assert(str != NULL);
size_t size = strlen(str) + 1;
char *copy = PyMem_RawMalloc(size);
if (copy == NULL) {
return NULL;
}
memcpy(copy, str, size);
return copy;
}

@ZeroIntensity
Copy link
Member

@vstinner Do you think it's worth adding a public variation of PyMem_Strdup and PyMem_RawStrdup?

@vstinner
Copy link
Member

@ZeroIntensity:

@vstinner Do you think it's worth adding a public variation of PyMem_Strdup and PyMem_RawStrdup?

It's not worth it. Please don't add them.

There is a simple replacement for _PyMem_RawStrdup(): just use strdup() (with free()). If you really need/want to use PyMem_RawMalloc(), you can copy/paste the code that @tomasr8 gave.

@vstinner
Copy link
Member

@clin1234: Would you be ok to close the issue? Or do you think that something else should be done? I'm not sure why you closed your cx_Freeze upstream PR.

@clin1234
Copy link
Author

I made a separate pull request replacing the private function with strdup (marcelotduarte/cx_Freeze#2738)

@ZeroIntensity ZeroIntensity closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) pending The issue will be closed if no feedback is provided topic-C-API
Projects
None yet
Development

No branches or pull requests

5 participants