mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Fix bugs and make improvements
- Get clone() working on FreeBSD - Increase some Python build quotas - Add more atomic builtins to chibicc - Fix ASAN poisoning of alloca() memory - Make MODE= mandatory link path tinier - Improve the examples folder a little bit - Start working on some more resource limits - Make the linenoise auto-complete UI as good as GNU readline - Update compile.com, avoiding AVX codegen on non-AVX systems - Make sure empty path to syscalls like opendir raises ENOENT - Correctly polyfill ENOENT vs. ENOTDIR on the New Technology - Port bestline's paredit features to //third_party/linenoise - Remove workarounds for RHEL 5.0 bugs that were fixed in 5.1
This commit is contained in:
parent
c3fb624647
commit
ae638c0850
181 changed files with 2994 additions and 1367 deletions
54
third_party/python/Modules/_pickle.c
vendored
54
third_party/python/Modules/_pickle.c
vendored
|
@ -653,7 +653,7 @@ typedef struct PicklerObject {
|
|||
is an unbound method, NULL otherwise */
|
||||
PyObject *dispatch_table; /* private dispatch_table, can be NULL */
|
||||
|
||||
PyObject *write; /* write() method of the output stream. */
|
||||
PyObject *write_; /* write() method of the output stream. */
|
||||
PyObject *output_buffer; /* Write into a local bytearray buffer before
|
||||
flushing to the stream. */
|
||||
Py_ssize_t output_len; /* Length of output_buffer. */
|
||||
|
@ -699,7 +699,7 @@ typedef struct UnpicklerObject {
|
|||
Py_ssize_t next_read_idx;
|
||||
Py_ssize_t prefetched_idx; /* index of first prefetched byte */
|
||||
|
||||
PyObject *read; /* read() method of the input stream. */
|
||||
PyObject *read_; /* read() method of the input stream. */
|
||||
PyObject *readline; /* readline() method of the input stream. */
|
||||
PyObject *peek; /* peek() method of the input stream, or NULL */
|
||||
|
||||
|
@ -1045,14 +1045,14 @@ _Pickler_FlushToFile(PicklerObject *self)
|
|||
{
|
||||
PyObject *output, *result;
|
||||
|
||||
assert(self->write != NULL);
|
||||
assert(self->write_ != NULL);
|
||||
|
||||
/* This will commit the frame first */
|
||||
output = _Pickler_GetString(self);
|
||||
if (output == NULL)
|
||||
return -1;
|
||||
|
||||
result = _Pickle_FastCall(self->write, output);
|
||||
result = _Pickle_FastCall(self->write_, output);
|
||||
Py_XDECREF(result);
|
||||
return (result == NULL) ? -1 : 0;
|
||||
}
|
||||
|
@ -1118,7 +1118,7 @@ _Pickler_New(void)
|
|||
|
||||
self->pers_func = NULL;
|
||||
self->dispatch_table = NULL;
|
||||
self->write = NULL;
|
||||
self->write_ = NULL;
|
||||
self->proto = 0;
|
||||
self->bin = 0;
|
||||
self->framing = 0;
|
||||
|
@ -1175,8 +1175,8 @@ _Pickler_SetOutputStream(PicklerObject *self, PyObject *file)
|
|||
{
|
||||
_Py_IDENTIFIER(write);
|
||||
assert(file != NULL);
|
||||
self->write = _PyObject_GetAttrId(file, &PyId_write);
|
||||
if (self->write == NULL) {
|
||||
self->write_ = _PyObject_GetAttrId(file, &PyId_write);
|
||||
if (self->write_ == NULL) {
|
||||
if (PyErr_ExceptionMatches(PyExc_AttributeError))
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"file must have a 'write' attribute");
|
||||
|
@ -1222,7 +1222,7 @@ _Unpickler_SkipConsumed(UnpicklerObject *self)
|
|||
|
||||
assert(self->peek); /* otherwise we did something wrong */
|
||||
/* This makes a useless copy... */
|
||||
r = PyObject_CallFunction(self->read, "n", consumed);
|
||||
r = PyObject_CallFunction(self->read_, "n", consumed);
|
||||
if (r == NULL)
|
||||
return -1;
|
||||
Py_DECREF(r);
|
||||
|
@ -1253,7 +1253,7 @@ _Unpickler_ReadFromFile(UnpicklerObject *self, Py_ssize_t n)
|
|||
PyObject *data;
|
||||
Py_ssize_t read_size;
|
||||
|
||||
assert(self->read != NULL);
|
||||
assert(self->read_ != NULL);
|
||||
|
||||
if (_Unpickler_SkipConsumed(self) < 0)
|
||||
return -1;
|
||||
|
@ -1287,7 +1287,7 @@ _Unpickler_ReadFromFile(UnpicklerObject *self, Py_ssize_t n)
|
|||
len = PyLong_FromSsize_t(n);
|
||||
if (len == NULL)
|
||||
return -1;
|
||||
data = _Pickle_FastCall(self->read, len);
|
||||
data = _Pickle_FastCall(self->read_, len);
|
||||
}
|
||||
if (data == NULL)
|
||||
return -1;
|
||||
|
@ -1314,7 +1314,7 @@ _Unpickler_ReadImpl(UnpicklerObject *self, char **s, Py_ssize_t n)
|
|||
/* This case is handled by the _Unpickler_Read() macro for efficiency */
|
||||
assert(self->next_read_idx + n > self->input_len);
|
||||
|
||||
if (!self->read)
|
||||
if (!self->read_)
|
||||
return bad_readline();
|
||||
|
||||
num_read = _Unpickler_ReadFromFile(self, n);
|
||||
|
@ -1381,7 +1381,7 @@ _Unpickler_Readline(UnpicklerObject *self, char **result)
|
|||
return _Unpickler_CopyLine(self, line_start, num_read, result);
|
||||
}
|
||||
}
|
||||
if (!self->read)
|
||||
if (!self->read_)
|
||||
return bad_readline();
|
||||
|
||||
num_read = _Unpickler_ReadFromFile(self, READ_WHOLE_LINE);
|
||||
|
@ -1493,7 +1493,7 @@ _Unpickler_New(void)
|
|||
self->input_len = 0;
|
||||
self->next_read_idx = 0;
|
||||
self->prefetched_idx = 0;
|
||||
self->read = NULL;
|
||||
self->read_ = NULL;
|
||||
self->readline = NULL;
|
||||
self->peek = NULL;
|
||||
self->encoding = NULL;
|
||||
|
@ -1533,13 +1533,13 @@ _Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file)
|
|||
else
|
||||
return -1;
|
||||
}
|
||||
self->read = _PyObject_GetAttrId(file, &PyId_read);
|
||||
self->read_ = _PyObject_GetAttrId(file, &PyId_read);
|
||||
self->readline = _PyObject_GetAttrId(file, &PyId_readline);
|
||||
if (self->readline == NULL || self->read == NULL) {
|
||||
if (self->readline == NULL || self->read_ == NULL) {
|
||||
if (PyErr_ExceptionMatches(PyExc_AttributeError))
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"file must have 'read' and 'readline' attributes");
|
||||
Py_CLEAR(self->read);
|
||||
Py_CLEAR(self->read_);
|
||||
Py_CLEAR(self->readline);
|
||||
Py_CLEAR(self->peek);
|
||||
return -1;
|
||||
|
@ -4158,7 +4158,7 @@ _pickle_Pickler_dump(PicklerObject *self, PyObject *obj)
|
|||
/* Check whether the Pickler was initialized correctly (issue3664).
|
||||
Developers often forget to call __init__() in their subclasses, which
|
||||
would trigger a segfault without this check. */
|
||||
if (self->write == NULL) {
|
||||
if (self->write_ == NULL) {
|
||||
PickleState *st = _Pickle_GetGlobalState();
|
||||
PyErr_Format(st->PicklingError,
|
||||
"Pickler.__init__() was not called by %s.__init__()",
|
||||
|
@ -4218,7 +4218,7 @@ Pickler_dealloc(PicklerObject *self)
|
|||
PyObject_GC_UnTrack(self);
|
||||
|
||||
Py_XDECREF(self->output_buffer);
|
||||
Py_XDECREF(self->write);
|
||||
Py_XDECREF(self->write_);
|
||||
Py_XDECREF(self->pers_func);
|
||||
Py_XDECREF(self->dispatch_table);
|
||||
Py_XDECREF(self->fast_memo);
|
||||
|
@ -4231,7 +4231,7 @@ Pickler_dealloc(PicklerObject *self)
|
|||
static int
|
||||
Pickler_traverse(PicklerObject *self, visitproc visit, void *arg)
|
||||
{
|
||||
Py_VISIT(self->write);
|
||||
Py_VISIT(self->write_);
|
||||
Py_VISIT(self->pers_func);
|
||||
Py_VISIT(self->dispatch_table);
|
||||
Py_VISIT(self->fast_memo);
|
||||
|
@ -4242,7 +4242,7 @@ static int
|
|||
Pickler_clear(PicklerObject *self)
|
||||
{
|
||||
Py_CLEAR(self->output_buffer);
|
||||
Py_CLEAR(self->write);
|
||||
Py_CLEAR(self->write_);
|
||||
Py_CLEAR(self->pers_func);
|
||||
Py_CLEAR(self->dispatch_table);
|
||||
Py_CLEAR(self->fast_memo);
|
||||
|
@ -4293,7 +4293,7 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file,
|
|||
_Py_IDENTIFIER(dispatch_table);
|
||||
|
||||
/* In case of multiple __init__() calls, clear previous content. */
|
||||
if (self->write != NULL)
|
||||
if (self->write_ != NULL)
|
||||
(void)Pickler_clear(self);
|
||||
|
||||
if (_Pickler_SetProtocol(self, protocol, fix_imports) < 0)
|
||||
|
@ -6514,9 +6514,9 @@ _pickle_Unpickler_load_impl(UnpicklerObject *self)
|
|||
|
||||
/* Check whether the Unpickler was initialized correctly. This prevents
|
||||
segfaulting if a subclass overridden __init__ with a function that does
|
||||
not call Unpickler.__init__(). Here, we simply ensure that self->read
|
||||
not call Unpickler.__init__(). Here, we simply ensure that self->read_
|
||||
is not NULL. */
|
||||
if (unpickler->read == NULL) {
|
||||
if (unpickler->read_ == NULL) {
|
||||
PickleState *st = _Pickle_GetGlobalState();
|
||||
PyErr_Format(st->UnpicklingError,
|
||||
"Unpickler.__init__() was not called by %s.__init__()",
|
||||
|
@ -6676,7 +6676,7 @@ Unpickler_dealloc(UnpicklerObject *self)
|
|||
{
|
||||
PyObject_GC_UnTrack((PyObject *)self);
|
||||
Py_XDECREF(self->readline);
|
||||
Py_XDECREF(self->read);
|
||||
Py_XDECREF(self->read_);
|
||||
Py_XDECREF(self->peek);
|
||||
Py_XDECREF(self->stack);
|
||||
Py_XDECREF(self->pers_func);
|
||||
|
@ -6698,7 +6698,7 @@ static int
|
|||
Unpickler_traverse(UnpicklerObject *self, visitproc visit, void *arg)
|
||||
{
|
||||
Py_VISIT(self->readline);
|
||||
Py_VISIT(self->read);
|
||||
Py_VISIT(self->read_);
|
||||
Py_VISIT(self->peek);
|
||||
Py_VISIT(self->stack);
|
||||
Py_VISIT(self->pers_func);
|
||||
|
@ -6709,7 +6709,7 @@ static int
|
|||
Unpickler_clear(UnpicklerObject *self)
|
||||
{
|
||||
Py_CLEAR(self->readline);
|
||||
Py_CLEAR(self->read);
|
||||
Py_CLEAR(self->read_);
|
||||
Py_CLEAR(self->peek);
|
||||
Py_CLEAR(self->stack);
|
||||
Py_CLEAR(self->pers_func);
|
||||
|
@ -6772,7 +6772,7 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file,
|
|||
_Py_IDENTIFIER(persistent_load);
|
||||
|
||||
/* In case of multiple __init__() calls, clear previous content. */
|
||||
if (self->read != NULL)
|
||||
if (self->read_ != NULL)
|
||||
(void)Unpickler_clear(self);
|
||||
|
||||
if (_Unpickler_SetInputStream(self, file) < 0)
|
||||
|
|
48
third_party/python/Modules/expat/xmlparse.c
vendored
48
third_party/python/Modules/expat/xmlparse.c
vendored
|
@ -219,7 +219,7 @@ typedef struct {
|
|||
const XML_Char *base;
|
||||
const XML_Char *publicId;
|
||||
const XML_Char *notation;
|
||||
XML_Bool open;
|
||||
XML_Bool open_;
|
||||
XML_Bool is_param;
|
||||
XML_Bool is_internal; /* true if declared in internal subset outside PE */
|
||||
} ENTITY;
|
||||
|
@ -2276,7 +2276,7 @@ static enum XML_Error doContent(XML_Parser parser, int startTagLevel,
|
|||
reportDefault(parser, enc, s, next);
|
||||
break;
|
||||
}
|
||||
if (entity->open) return XML_ERROR_RECURSIVE_ENTITY_REF;
|
||||
if (entity->open_) return XML_ERROR_RECURSIVE_ENTITY_REF;
|
||||
if (entity->notation) return XML_ERROR_BINARY_ENTITY_REF;
|
||||
if (entity->textPtr) {
|
||||
enum XML_Error result;
|
||||
|
@ -2292,9 +2292,9 @@ static enum XML_Error doContent(XML_Parser parser, int startTagLevel,
|
|||
if (result != XML_ERROR_NONE) return result;
|
||||
} else if (parser->m_externalEntityRefHandler) {
|
||||
const XML_Char *context;
|
||||
entity->open = XML_TRUE;
|
||||
entity->open_ = XML_TRUE;
|
||||
context = getContext(parser);
|
||||
entity->open = XML_FALSE;
|
||||
entity->open_ = XML_FALSE;
|
||||
if (!context) return XML_ERROR_NO_MEMORY;
|
||||
if (!parser->m_externalEntityRefHandler(
|
||||
parser->m_externalEntityRefHandlerArg, context, entity->base,
|
||||
|
@ -4417,7 +4417,7 @@ static enum XML_Error doProlog(XML_Parser parser, const ENCODING *enc,
|
|||
}
|
||||
break;
|
||||
}
|
||||
if (entity->open) return XML_ERROR_RECURSIVE_ENTITY_REF;
|
||||
if (entity->open_) return XML_ERROR_RECURSIVE_ENTITY_REF;
|
||||
if (entity->textPtr) {
|
||||
enum XML_Error result;
|
||||
XML_Bool betweenDecl =
|
||||
|
@ -4429,14 +4429,14 @@ static enum XML_Error doProlog(XML_Parser parser, const ENCODING *enc,
|
|||
}
|
||||
if (parser->m_externalEntityRefHandler) {
|
||||
dtd->paramEntityRead = XML_FALSE;
|
||||
entity->open = XML_TRUE;
|
||||
entity->open_ = XML_TRUE;
|
||||
if (!parser->m_externalEntityRefHandler(
|
||||
parser->m_externalEntityRefHandlerArg, 0, entity->base,
|
||||
entity->systemId, entity->publicId)) {
|
||||
entity->open = XML_FALSE;
|
||||
entity->open_ = XML_FALSE;
|
||||
return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
|
||||
}
|
||||
entity->open = XML_FALSE;
|
||||
entity->open_ = XML_FALSE;
|
||||
handleDefault = XML_FALSE;
|
||||
if (!dtd->paramEntityRead) {
|
||||
dtd->keepProcessing = dtd->standalone;
|
||||
|
@ -4692,7 +4692,7 @@ static enum XML_Error processInternalEntity(XML_Parser parser, ENTITY *entity,
|
|||
(OPEN_INTERNAL_ENTITY *)MALLOC(parser, sizeof(OPEN_INTERNAL_ENTITY));
|
||||
if (!openEntity) return XML_ERROR_NO_MEMORY;
|
||||
}
|
||||
entity->open = XML_TRUE;
|
||||
entity->open_ = XML_TRUE;
|
||||
entity->processed = 0;
|
||||
openEntity->next = parser->m_openInternalEntities;
|
||||
parser->m_openInternalEntities = openEntity;
|
||||
|
@ -4722,7 +4722,7 @@ static enum XML_Error processInternalEntity(XML_Parser parser, ENTITY *entity,
|
|||
entity->processed = (int)(next - textStart);
|
||||
parser->m_processor = internalEntityProcessor;
|
||||
} else {
|
||||
entity->open = XML_FALSE;
|
||||
entity->open_ = XML_FALSE;
|
||||
parser->m_openInternalEntities = openEntity->next;
|
||||
/* put openEntity back in list of free instances */
|
||||
openEntity->next = parser->m_freeInternalEntities;
|
||||
|
@ -4768,7 +4768,7 @@ static enum XML_Error internalEntityProcessor(XML_Parser parser,
|
|||
entity->processed = (int)(next - (char *)entity->textPtr);
|
||||
return result;
|
||||
} else {
|
||||
entity->open = XML_FALSE;
|
||||
entity->open_ = XML_FALSE;
|
||||
parser->m_openInternalEntities = openEntity->next;
|
||||
/* put openEntity back in list of free instances */
|
||||
openEntity->next = parser->m_freeInternalEntities;
|
||||
|
@ -4915,11 +4915,11 @@ static enum XML_Error appendAttributeValue(XML_Parser parser,
|
|||
*/
|
||||
break;
|
||||
}
|
||||
if (entity->open) {
|
||||
if (entity->open_) {
|
||||
if (enc == parser->m_encoding) {
|
||||
/* It does not appear that this line can be executed.
|
||||
*
|
||||
* The "if (entity->open)" check catches recursive entity
|
||||
* The "if (entity->open_)" check catches recursive entity
|
||||
* definitions. In order to be called with an open
|
||||
* entity, it must have gone through this code before and
|
||||
* been through the recursive call to
|
||||
|
@ -4928,7 +4928,7 @@ static enum XML_Error appendAttributeValue(XML_Parser parser,
|
|||
* internal encoding (internal_utf8 or internal_utf16),
|
||||
* which can never be the same as the principle encoding.
|
||||
* It doesn't appear there is another code path that gets
|
||||
* here with entity->open being TRUE.
|
||||
* here with entity->open_ being TRUE.
|
||||
*
|
||||
* Since it is not certain that this logic is watertight,
|
||||
* we keep the line and merely exclude it from coverage
|
||||
|
@ -4948,11 +4948,11 @@ static enum XML_Error appendAttributeValue(XML_Parser parser,
|
|||
} else {
|
||||
enum XML_Error result;
|
||||
const XML_Char *textEnd = entity->textPtr + entity->textLen;
|
||||
entity->open = XML_TRUE;
|
||||
entity->open_ = XML_TRUE;
|
||||
result = appendAttributeValue(parser, parser->m_internalEncoding,
|
||||
isCdata, (char *)entity->textPtr,
|
||||
(char *)textEnd, pool);
|
||||
entity->open = XML_FALSE;
|
||||
entity->open_ = XML_FALSE;
|
||||
if (result) return result;
|
||||
}
|
||||
} break;
|
||||
|
@ -5022,7 +5022,7 @@ static enum XML_Error storeEntityValue(XML_Parser parser, const ENCODING *enc,
|
|||
dtd->keepProcessing = dtd->standalone;
|
||||
goto endEntityValue;
|
||||
}
|
||||
if (entity->open) {
|
||||
if (entity->open_) {
|
||||
if (enc == parser->m_encoding) parser->m_eventPtr = entityTextPtr;
|
||||
result = XML_ERROR_RECURSIVE_ENTITY_REF;
|
||||
goto endEntityValue;
|
||||
|
@ -5030,24 +5030,24 @@ static enum XML_Error storeEntityValue(XML_Parser parser, const ENCODING *enc,
|
|||
if (entity->systemId) {
|
||||
if (parser->m_externalEntityRefHandler) {
|
||||
dtd->paramEntityRead = XML_FALSE;
|
||||
entity->open = XML_TRUE;
|
||||
entity->open_ = XML_TRUE;
|
||||
if (!parser->m_externalEntityRefHandler(
|
||||
parser->m_externalEntityRefHandlerArg, 0, entity->base,
|
||||
entity->systemId, entity->publicId)) {
|
||||
entity->open = XML_FALSE;
|
||||
entity->open_ = XML_FALSE;
|
||||
result = XML_ERROR_EXTERNAL_ENTITY_HANDLING;
|
||||
goto endEntityValue;
|
||||
}
|
||||
entity->open = XML_FALSE;
|
||||
entity->open_ = XML_FALSE;
|
||||
if (!dtd->paramEntityRead) dtd->keepProcessing = dtd->standalone;
|
||||
} else
|
||||
dtd->keepProcessing = dtd->standalone;
|
||||
} else {
|
||||
entity->open = XML_TRUE;
|
||||
entity->open_ = XML_TRUE;
|
||||
result = storeEntityValue(
|
||||
parser, parser->m_internalEncoding, (char *)entity->textPtr,
|
||||
(char *)(entity->textPtr + entity->textLen));
|
||||
entity->open = XML_FALSE;
|
||||
entity->open_ = XML_FALSE;
|
||||
if (result) goto endEntityValue;
|
||||
}
|
||||
break;
|
||||
|
@ -5431,7 +5431,7 @@ static const XML_Char *getContext(XML_Parser parser) {
|
|||
const XML_Char *s;
|
||||
ENTITY *e = (ENTITY *)hashTableIterNext(&iter);
|
||||
if (!e) break;
|
||||
if (!e->open) continue;
|
||||
if (!e->open_) continue;
|
||||
if (needSep && !poolAppendChar(&parser->m_tempPool, CONTEXT_SEP))
|
||||
return NULL;
|
||||
for (s = e->name; *s; s++)
|
||||
|
@ -5453,7 +5453,7 @@ static XML_Bool setContext(XML_Parser parser, const XML_Char *context) {
|
|||
if (!poolAppendChar(&parser->m_tempPool, XML_T('\0'))) return XML_FALSE;
|
||||
e = (ENTITY *)lookup(parser, &dtd->generalEntities,
|
||||
poolStart(&parser->m_tempPool), 0);
|
||||
if (e) e->open = XML_TRUE;
|
||||
if (e) e->open_ = XML_TRUE;
|
||||
if (*s != XML_T('\0')) s++;
|
||||
context = s;
|
||||
poolDiscard(&parser->m_tempPool);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue