Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

use plain malloc/free in freezing code

  • Loading branch information...
commit b6b440e611cb72a20956c5e66cee3e5126b43c4b 1 parent a841345
Robert Bradshaw robertwb authored

Showing 2 changed files with 18 additions and 18 deletions. Show diff stats Hide diff stats

  1. +9 9 Cython/Compiler/ModuleNode.py
  2. +9 9 bin/cython_freeze
18 Cython/Compiler/ModuleNode.py
@@ -2579,7 +2579,7 @@ def generate_typeptr_assignment_code(self, entry, code):
2579 2579 mbstate_t mbs;
2580 2580 #endif
2581 2581 if (argsize != (size_t)-1) {
2582   - res = (wchar_t *)PyMem_Malloc((argsize+1)*sizeof(wchar_t));
  2582 + res = (wchar_t *)malloc((argsize+1)*sizeof(wchar_t));
2583 2583 if (!res)
2584 2584 goto oom;
2585 2585 count = mbstowcs(res, arg, argsize+1);
@@ -2593,7 +2593,7 @@ def generate_typeptr_assignment_code(self, entry, code):
2593 2593 if (*tmp == 0)
2594 2594 return res;
2595 2595 }
2596   - PyMem_Free(res);
  2596 + free(res);
2597 2597 }
2598 2598 /* Conversion failed. Fall back to escaping with surrogateescape. */
2599 2599 #ifdef HAVE_MBRTOWC
@@ -2602,7 +2602,7 @@ def generate_typeptr_assignment_code(self, entry, code):
2602 2602 /* Overallocate; as multi-byte characters are in the argument, the
2603 2603 actual output could use less memory. */
2604 2604 argsize = strlen(arg) + 1;
2605   - res = PyMem_Malloc(argsize*sizeof(wchar_t));
  2605 + res = malloc(argsize*sizeof(wchar_t));
2606 2606 if (!res) goto oom;
2607 2607 in = (unsigned char*)arg;
2608 2608 out = res;
@@ -2645,7 +2645,7 @@ def generate_typeptr_assignment_code(self, entry, code):
2645 2645 /* Cannot use C locale for escaping; manually escape as if charset
2646 2646 is ASCII (i.e. escape all bytes > 128. This will still roundtrip
2647 2647 correctly in the locale's charset, which must be an ASCII superset. */
2648   - res = PyMem_Malloc((strlen(arg)+1)*sizeof(wchar_t));
  2648 + res = malloc((strlen(arg)+1)*sizeof(wchar_t));
2649 2649 if (!res) goto oom;
2650 2650 in = (unsigned char*)arg;
2651 2651 out = res;
@@ -2665,9 +2665,9 @@ def generate_typeptr_assignment_code(self, entry, code):
2665 2665 int
2666 2666 main(int argc, char **argv)
2667 2667 {
2668   - wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
  2668 + wchar_t **argv_copy = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
2669 2669 /* We need a second copies, as Python might modify the first one. */
2670   - wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
  2670 + wchar_t **argv_copy2 = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
2671 2671 int i, res;
2672 2672 char *oldloc;
2673 2673 if (!argv_copy || !argv_copy2) {
@@ -2685,10 +2685,10 @@ def generate_typeptr_assignment_code(self, entry, code):
2685 2685 free(oldloc);
2686 2686 res = __Pyx_main(argc, argv_copy);
2687 2687 for (i = 0; i < argc; i++) {
2688   - PyMem_Free(argv_copy2[i]);
  2688 + free(argv_copy2[i]);
2689 2689 }
2690   - PyMem_Free(argv_copy);
2691   - PyMem_Free(argv_copy2);
  2690 + free(argv_copy);
  2691 + free(argv_copy2);
2692 2692 return res;
2693 2693 }
2694 2694 #endif
18 bin/cython_freeze
@@ -148,7 +148,7 @@ char2wchar(char* arg)
148 148 mbstate_t mbs;
149 149 #endif
150 150 if (argsize != (size_t)-1) {
151   - res = (wchar_t *)PyMem_Malloc((argsize+1)*sizeof(wchar_t));
  151 + res = (wchar_t *)malloc((argsize+1)*sizeof(wchar_t));
152 152 if (!res)
153 153 goto oom;
154 154 count = mbstowcs(res, arg, argsize+1);
@@ -162,7 +162,7 @@ char2wchar(char* arg)
162 162 if (*tmp == 0)
163 163 return res;
164 164 }
165   - PyMem_Free(res);
  165 + free(res);
166 166 }
167 167 /* Conversion failed. Fall back to escaping with surrogateescape. */
168 168 #ifdef HAVE_MBRTOWC
@@ -171,7 +171,7 @@ char2wchar(char* arg)
171 171 /* Overallocate; as multi-byte characters are in the argument, the
172 172 actual output could use less memory. */
173 173 argsize = strlen(arg) + 1;
174   - res = PyMem_Malloc(argsize*sizeof(wchar_t));
  174 + res = malloc(argsize*sizeof(wchar_t));
175 175 if (!res) goto oom;
176 176 in = (unsigned char*)arg;
177 177 out = res;
@@ -214,7 +214,7 @@ char2wchar(char* arg)
214 214 /* Cannot use C locale for escaping; manually escape as if charset
215 215 is ASCII (i.e. escape all bytes > 128. This will still roundtrip
216 216 correctly in the locale's charset, which must be an ASCII superset. */
217   - res = PyMem_Malloc((strlen(arg)+1)*sizeof(wchar_t));
  217 + res = malloc((strlen(arg)+1)*sizeof(wchar_t));
218 218 if (!res) goto oom;
219 219 in = (unsigned char*)arg;
220 220 out = res;
@@ -234,9 +234,9 @@ oom:
234 234 int
235 235 main(int argc, char **argv)
236 236 {
237   - wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
  237 + wchar_t **argv_copy = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
238 238 /* We need a second copies, as Python might modify the first one. */
239   - wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc);
  239 + wchar_t **argv_copy2 = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
240 240 int i, res;
241 241 char *oldloc;
242 242 if (!argv_copy || !argv_copy2) {
@@ -254,10 +254,10 @@ main(int argc, char **argv)
254 254 free(oldloc);
255 255 res = python_main(argc, argv_copy);
256 256 for (i = 0; i < argc; i++) {
257   - PyMem_Free(argv_copy2[i]);
  257 + free(argv_copy2[i]);
258 258 }
259   - PyMem_Free(argv_copy);
260   - PyMem_Free(argv_copy2);
  259 + free(argv_copy);
  260 + free(argv_copy2);
261 261 return res;
262 262 }
263 263 #endif"""

0 comments on commit b6b440e

Please sign in to comment.
Something went wrong with that request. Please try again.