size_t n;
char *p;
n = 100;
- if ((p = (char *)PyObject_MALLOC(n)) == NULL)
+ if ((p = (char *)PyMem_MALLOC(n)) == NULL)
return NULL;
fflush(sys_stdout);
#ifndef RISCOS
case 0: /* Normal case */
break;
case 1: /* Interrupt */
- PyObject_FREE(p);
+ PyMem_FREE(p);
return NULL;
case -1: /* EOF */
case -2: /* Error */
n = strlen(p);
while (n > 0 && p[n-1] != '\n') {
size_t incr = n+2;
- p = (char *)PyObject_REALLOC(p, n + incr);
+ p = (char *)PyMem_REALLOC(p, n + incr);
if (p == NULL)
return NULL;
if (incr > INT_MAX) {
break;
n += strlen(p+n);
}
- return (char *)PyObject_REALLOC(p, n+1);
+ return (char *)PyMem_REALLOC(p, n+1);
}
/* By initializing this function pointer, systems embedding Python can
override the readline function.
- Note: Python expects in return a buffer allocated with PyObject_Malloc. */
+ Note: Python expects in return a buffer allocated with PyMem_Malloc. */
char *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);
{
tok->decoding_erred = 1;
if (tok->fp != NULL && tok->buf != NULL) /* see PyTokenizer_Free */
- PyObject_FREE(tok->buf);
+ PyMem_FREE(tok->buf);
tok->buf = NULL;
return NULL; /* as if it were EOF */
}
static char *
new_string(const char *s, Py_ssize_t len)
{
- char* result = (char *)PyObject_MALLOC(len + 1);
+ char* result = (char *)PyMem_MALLOC(len + 1);
if (result != NULL) {
memcpy(result, s, len);
result[len] = '\0';
char* r = new_string(begin, t - begin);
char* q = get_normal_name(r);
if (r != q) {
- PyObject_FREE(r);
+ PyMem_FREE(r);
r = new_string(q, strlen(q));
}
return r;
tok->decoding_state = -1;
}
else
- PyObject_FREE(cs);
+ PyMem_FREE(cs);
#else
/* Without Unicode support, we cannot
process the coding spec. Since there
won't be any Unicode literals, that
won't matter. */
- PyObject_FREE(cs);
+ PyMem_FREE(cs);
#endif
}
} else { /* then, compare cs with BOM */
r = (strcmp(tok->encoding, cs) == 0);
- PyObject_FREE(cs);
+ PyMem_FREE(cs);
}
}
if (!r) {
return 1;
}
if (tok->encoding != NULL)
- PyObject_FREE(tok->encoding);
+ PyMem_FREE(tok->encoding);
tok->encoding = new_string("utf-8", 5); /* resulting is in utf-8 */
return 1;
NON_BOM:
struct tok_state *tok = tok_new();
if (tok == NULL)
return NULL;
- if ((tok->buf = (char *)PyObject_MALLOC(BUFSIZ)) == NULL) {
+ if ((tok->buf = (char *)PyMem_MALLOC(BUFSIZ)) == NULL) {
PyTokenizer_Free(tok);
return NULL;
}
PyTokenizer_Free(struct tok_state *tok)
{
if (tok->encoding != NULL)
- PyObject_FREE(tok->encoding);
+ PyMem_FREE(tok->encoding);
#ifndef PGEN
Py_XDECREF(tok->decoding_readline);
Py_XDECREF(tok->decoding_buffer);
#endif
if (tok->fp != NULL && tok->buf != NULL)
- PyObject_FREE(tok->buf);
+ PyMem_FREE(tok->buf);
PyMem_FREE(tok);
}
if (converted == NULL)
goto error_nomem;
- PyObject_FREE(*inp);
+ PyMem_FREE(*inp);
*inp = converted;
if (tok->encoding != NULL)
- PyObject_FREE(tok->encoding);
+ PyMem_FREE(tok->encoding);
tok->encoding = new_string(encoding, strlen(encoding));
if (tok->encoding == NULL)
goto error_nomem;
if (newtok == NULL)
tok->done = E_INTR;
else if (*newtok == '\0') {
- PyObject_FREE(newtok);
+ PyMem_FREE(newtok);
tok->done = E_EOF;
}
#if !defined(PGEN) && defined(Py_USING_UNICODE)
else if (tok_stdin_decode(tok, &newtok) != 0)
- PyObject_FREE(newtok);
+ PyMem_FREE(newtok);
#endif
else if (tok->start != NULL) {
size_t start = tok->start - tok->buf;
size_t oldlen = tok->cur - tok->buf;
size_t newlen = oldlen + strlen(newtok);
char *buf = tok->buf;
- buf = (char *)PyObject_REALLOC(buf, newlen+1);
+ buf = (char *)PyMem_REALLOC(buf, newlen+1);
tok->lineno++;
if (buf == NULL) {
- PyObject_FREE(tok->buf);
+ PyMem_FREE(tok->buf);
tok->buf = NULL;
- PyObject_FREE(newtok);
+ PyMem_FREE(newtok);
tok->done = E_NOMEM;
return EOF;
}
tok->cur = tok->buf + oldlen;
tok->line_start = tok->cur;
strcpy(tok->buf + oldlen, newtok);
- PyObject_FREE(newtok);
+ PyMem_FREE(newtok);
tok->inp = tok->buf + newlen;
tok->end = tok->inp + 1;
tok->start = tok->buf + start;
else {
tok->lineno++;
if (tok->buf != NULL)
- PyObject_FREE(tok->buf);
+ PyMem_FREE(tok->buf);
tok->buf = newtok;
tok->line_start = tok->buf;
tok->cur = tok->buf;
if (tok->start == NULL) {
if (tok->buf == NULL) {
tok->buf = (char *)
- PyObject_MALLOC(BUFSIZ);
+ PyMem_MALLOC(BUFSIZ);
if (tok->buf == NULL) {
tok->done = E_NOMEM;
return EOF;
Py_ssize_t curvalid = tok->inp - tok->buf;
Py_ssize_t newsize = curvalid + BUFSIZ;
char *newbuf = tok->buf;
- newbuf = (char *)PyObject_REALLOC(newbuf,
- newsize);
+ newbuf = (char *)PyMem_REALLOC(newbuf,
+ newsize);
if (newbuf == NULL) {
tok->done = E_NOMEM;
tok->cur = tok->inp;