Skip to content

Commit

Permalink
use plain malloc/free in freezing code
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwb committed Oct 29, 2009
1 parent a841345 commit b6b440e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions Cython/Compiler/ModuleNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2579,7 +2579,7 @@ def generate_typeptr_assignment_code(self, entry, code):
mbstate_t mbs;
#endif
if (argsize != (size_t)-1) {
res = (wchar_t *)PyMem_Malloc((argsize+1)*sizeof(wchar_t));
res = (wchar_t *)malloc((argsize+1)*sizeof(wchar_t));
if (!res)
goto oom;
count = mbstowcs(res, arg, argsize+1);
Expand All @@ -2593,7 +2593,7 @@ def generate_typeptr_assignment_code(self, entry, code):
if (*tmp == 0)
return res;
}
PyMem_Free(res);
free(res);
}
/* Conversion failed. Fall back to escaping with surrogateescape. */
#ifdef HAVE_MBRTOWC
Expand All @@ -2602,7 +2602,7 @@ def generate_typeptr_assignment_code(self, entry, code):
/* Overallocate; as multi-byte characters are in the argument, the
actual output could use less memory. */
argsize = strlen(arg) + 1;
res = PyMem_Malloc(argsize*sizeof(wchar_t));
res = malloc(argsize*sizeof(wchar_t));
if (!res) goto oom;
in = (unsigned char*)arg;
out = res;
Expand Down Expand Up @@ -2645,7 +2645,7 @@ def generate_typeptr_assignment_code(self, entry, code):
/* Cannot use C locale for escaping; manually escape as if charset
is ASCII (i.e. escape all bytes > 128. This will still roundtrip
correctly in the locale's charset, which must be an ASCII superset. */
res = PyMem_Malloc((strlen(arg)+1)*sizeof(wchar_t));
res = malloc((strlen(arg)+1)*sizeof(wchar_t));
if (!res) goto oom;
in = (unsigned char*)arg;
out = res;
Expand All @@ -2665,9 +2665,9 @@ def generate_typeptr_assignment_code(self, entry, code):
int
main(int argc, char **argv)
{
wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
wchar_t **argv_copy = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
/* We need a second copies, as Python might modify the first one. */
wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
wchar_t **argv_copy2 = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
int i, res;
char *oldloc;
if (!argv_copy || !argv_copy2) {
Expand All @@ -2685,10 +2685,10 @@ def generate_typeptr_assignment_code(self, entry, code):
free(oldloc);
res = __Pyx_main(argc, argv_copy);
for (i = 0; i < argc; i++) {
PyMem_Free(argv_copy2[i]);
free(argv_copy2[i]);
}
PyMem_Free(argv_copy);
PyMem_Free(argv_copy2);
free(argv_copy);
free(argv_copy2);
return res;
}
#endif
Expand Down
18 changes: 9 additions & 9 deletions bin/cython_freeze
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ char2wchar(char* arg)
mbstate_t mbs;
#endif
if (argsize != (size_t)-1) {
res = (wchar_t *)PyMem_Malloc((argsize+1)*sizeof(wchar_t));
res = (wchar_t *)malloc((argsize+1)*sizeof(wchar_t));
if (!res)
goto oom;
count = mbstowcs(res, arg, argsize+1);
Expand All @@ -162,7 +162,7 @@ char2wchar(char* arg)
if (*tmp == 0)
return res;
}
PyMem_Free(res);
free(res);
}
/* Conversion failed. Fall back to escaping with surrogateescape. */
#ifdef HAVE_MBRTOWC
Expand All @@ -171,7 +171,7 @@ char2wchar(char* arg)
/* Overallocate; as multi-byte characters are in the argument, the
actual output could use less memory. */
argsize = strlen(arg) + 1;
res = PyMem_Malloc(argsize*sizeof(wchar_t));
res = malloc(argsize*sizeof(wchar_t));
if (!res) goto oom;
in = (unsigned char*)arg;
out = res;
Expand Down Expand Up @@ -214,7 +214,7 @@ char2wchar(char* arg)
/* Cannot use C locale for escaping; manually escape as if charset
is ASCII (i.e. escape all bytes > 128. This will still roundtrip
correctly in the locale's charset, which must be an ASCII superset. */
res = PyMem_Malloc((strlen(arg)+1)*sizeof(wchar_t));
res = malloc((strlen(arg)+1)*sizeof(wchar_t));
if (!res) goto oom;
in = (unsigned char*)arg;
out = res;
Expand All @@ -234,9 +234,9 @@ oom:
int
main(int argc, char **argv)
{
wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
wchar_t **argv_copy = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
/* We need a second copies, as Python might modify the first one. */
wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
wchar_t **argv_copy2 = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
int i, res;
char *oldloc;
if (!argv_copy || !argv_copy2) {
Expand All @@ -254,10 +254,10 @@ main(int argc, char **argv)
free(oldloc);
res = python_main(argc, argv_copy);
for (i = 0; i < argc; i++) {
PyMem_Free(argv_copy2[i]);
free(argv_copy2[i]);
}
PyMem_Free(argv_copy);
PyMem_Free(argv_copy2);
free(argv_copy);
free(argv_copy2);
return res;
}
#endif"""

0 comments on commit b6b440e

Please sign in to comment.