Commit 5e858cec authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge commit '0ae46' into refcounting

parents 0dc46274 0ae46342
...@@ -178,6 +178,8 @@ add_custom_command(OUTPUT ${STDMODULES} ...@@ -178,6 +178,8 @@ add_custom_command(OUTPUT ${STDMODULES}
Modules/termios.c Modules/termios.c
Modules/_cursesmodule.c Modules/_cursesmodule.c
Modules/mmapmodule.c Modules/mmapmodule.c
Modules/_localemodule.c
Modules/cPickle.c
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(sharedmods ALL DEPENDS ${CMAKE_BINARY_DIR}/from_cpython/Lib/_multiprocessing.pyston.so) add_custom_target(sharedmods ALL DEPENDS ${CMAKE_BINARY_DIR}/from_cpython/Lib/_multiprocessing.pyston.so)
......
...@@ -58,6 +58,10 @@ PyAPI_DATA(PyTypeObject*) instancemethod_cls; ...@@ -58,6 +58,10 @@ PyAPI_DATA(PyTypeObject*) instancemethod_cls;
#define PyMethod_Check(op) (Py_TYPE(op) == &PyMethod_Type) #define PyMethod_Check(op) (Py_TYPE(op) == &PyMethod_Type)
PyAPI_FUNC(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *) PYSTON_NOEXCEPT; PyAPI_FUNC(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *) PYSTON_NOEXCEPT;
// Pyston change: pyston addition returns PyClassObject->cl_name
PyAPI_FUNC(PyObject *) PyClass_Name(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyInstance_New(PyObject *, PyObject *, PyAPI_FUNC(PyObject *) PyInstance_New(PyObject *, PyObject *,
PyObject *) PYSTON_NOEXCEPT; PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *) PYSTON_NOEXCEPT; PyAPI_FUNC(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *) PYSTON_NOEXCEPT;
......
...@@ -110,6 +110,8 @@ PyAPI_DATA(PyTypeObject) PyDictValues_Type; ...@@ -110,6 +110,8 @@ PyAPI_DATA(PyTypeObject) PyDictValues_Type;
PyAPI_DATA(PyTypeObject*) dict_cls; PyAPI_DATA(PyTypeObject*) dict_cls;
#define PyDict_Type (*dict_cls) #define PyDict_Type (*dict_cls)
PyAPI_DATA(PyTypeObject*) attrwrapper_cls;
#define PyAttrWrapper_Type (*attrwrapper_cls)
PyAPI_DATA(PyTypeObject*) dictiterkey_cls; PyAPI_DATA(PyTypeObject*) dictiterkey_cls;
#define PyDictIterKey_Type (*dictiterkey_cls) #define PyDictIterKey_Type (*dictiterkey_cls)
PyAPI_DATA(PyTypeObject*) dictitervalue_cls; PyAPI_DATA(PyTypeObject*) dictitervalue_cls;
......
...@@ -19,6 +19,10 @@ PyAPI_DATA(PyTypeObject*) capifunc_cls; ...@@ -19,6 +19,10 @@ PyAPI_DATA(PyTypeObject*) capifunc_cls;
#define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type) #define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type)
// Pyston change: expose our builtin_function_or_method type
PyAPI_DATA(PyTypeObject*) builtin_function_or_method_cls;
#define PyBuiltinFunction_Type (*builtin_function_or_method_cls)
typedef PyObject *(*PyCFunction)(PyObject *, PyObject *); typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *, typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
PyObject *); PyObject *);
......
...@@ -1123,6 +1123,8 @@ class AbstractPickleModuleTests(unittest.TestCase): ...@@ -1123,6 +1123,8 @@ class AbstractPickleModuleTests(unittest.TestCase):
s = StringIO.StringIO("X''.") s = StringIO.StringIO("X''.")
self.assertRaises(EOFError, self.module.load, s) self.assertRaises(EOFError, self.module.load, s)
# Pyston change:
@unittest.skip("pyston does not support this currently")
def test_restricted(self): def test_restricted(self):
# issue7128: cPickle failed in restricted mode # issue7128: cPickle failed in restricted mode
builtins = {self.module.__name__: self.module, builtins = {self.module.__name__: self.module,
......
# expected: fail
from test.test_support import run_unittest from test.test_support import run_unittest
from _locale import (setlocale, LC_NUMERIC, localeconv, Error) from _locale import (setlocale, LC_NUMERIC, localeconv, Error)
try: try:
......
# expected: fail
# Simple test suite for Cookie.py # Simple test suite for Cookie.py
from test.test_support import run_unittest, run_doctest, check_warnings from test.test_support import run_unittest, run_doctest, check_warnings
......
# expected: fail
import cPickle import cPickle
import cStringIO import cStringIO
import io import io
......
# expected: fail
from test.test_support import run_unittest, verbose from test.test_support import run_unittest, verbose
import unittest import unittest
import locale import locale
......
# expected: fail
import pickle import pickle
from cStringIO import StringIO from cStringIO import StringIO
......
# expected: fail
import pickle import pickle
import pickletools import pickletools
from test import test_support from test import test_support
......
# expected: fail
# regression test for SAX 2.0 -*- coding: utf-8 -*- # regression test for SAX 2.0 -*- coding: utf-8 -*-
# $Id$ # $Id$
......
<?xml version="1.0" encoding="iso-8859-1"?>
<HTML xmlns:pp="http://www.isogen.com/paul/post-processor">
<TITLE>Introduction to XSL</TITLE>
<H1>Introduction to XSL</H1>
<HR></HR>
<H2>Overview
</H2>
<UL>
<LI>1.Intro</LI>
<LI>2.History</LI>
<LI>3.XSL Basics</LI>
<LI>Lunch</LI>
<LI>4.An XML Data Model</LI>
<LI>5.XSL Patterns</LI>
<LI>6.XSL Templates</LI>
<LI>7.XSL Formatting Model
</LI>
</UL>
<HR></HR>
<H2>Intro</H2>
<UL>
<LI>Who am I?</LI>
<LI>Who are you?</LI>
<LI>Why are we here?
</LI>
</UL>
<HR></HR>
<H2>History: XML and SGML</H2>
<UL>
<LI>XML is a subset of SGML.</LI>
<LI>SGML allows the separation of abstract content from formatting.</LI>
<LI>Also one of XML's primary virtues (in the doc publishing domain).
</LI>
</UL>
<HR></HR>
<H2>History: What are stylesheets?</H2>
<UL>
<LI>Stylesheets specify the formatting of SGML/XML documents.</LI>
<LI>Stylesheets put the "style" back into documents.</LI>
<LI>New York Times content+NYT Stylesheet = NYT paper
</LI>
</UL>
<HR></HR>
<H2>History: FOSI</H2>
<UL>
<LI>FOSI: "Formatted Output Specification Instance"
<UL>
<LI>MIL-STD-28001
</LI>
<LI>FOSI's are SGML documents
</LI>
<LI>A stylesheet for another document
</LI>
</UL></LI>
<LI>Obsolete but implemented...
</LI>
</UL>
</HTML>
\ No newline at end of file
...@@ -144,6 +144,8 @@ typedef struct { ...@@ -144,6 +144,8 @@ typedef struct {
PyObject **data; PyObject **data;
} Pdata; } Pdata;
// Pyston change: use GC allocs instead of malloc
#if 0
static void static void
Pdata_dealloc(Pdata *self) Pdata_dealloc(Pdata *self)
{ {
...@@ -157,10 +159,13 @@ Pdata_dealloc(Pdata *self) ...@@ -157,10 +159,13 @@ Pdata_dealloc(Pdata *self)
free(self->data); free(self->data);
PyObject_Del(self); PyObject_Del(self);
} }
#endif
static PyTypeObject PdataType = { static PyTypeObject PdataType = {
PyVarObject_HEAD_INIT(NULL, 0) "cPickle.Pdata", sizeof(Pdata), 0, PyVarObject_HEAD_INIT(NULL, 0) "cPickle.Pdata", sizeof(Pdata), 0,
(destructor)Pdata_dealloc, // Pyston change: use GC allocs instead of malloc
// (destructor)Pdata_dealloc,
(destructor)0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0L,0L,0L,0L, "" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0L,0L,0L,0L, ""
}; };
...@@ -175,7 +180,11 @@ Pdata_New(void) ...@@ -175,7 +180,11 @@ Pdata_New(void)
return NULL; return NULL;
self->size = 8; self->size = 8;
self->length = 0; self->length = 0;
self->data = malloc(self->size * sizeof(PyObject*));
// Pyston change: use GC allocs instead of malloc
// self->data = malloc(self->size * sizeof(PyObject*));
self->data = PyMem_Malloc(self->size * sizeof(PyObject*));
if (self->data) if (self->data)
return (PyObject*)self; return (PyObject*)self;
Py_DECREF(self); Py_DECREF(self);
...@@ -225,7 +234,11 @@ Pdata_grow(Pdata *self) ...@@ -225,7 +234,11 @@ Pdata_grow(Pdata *self)
if (bigger > (PY_SSIZE_T_MAX / sizeof(PyObject *))) if (bigger > (PY_SSIZE_T_MAX / sizeof(PyObject *)))
goto nomemory; goto nomemory;
nbytes = bigger * sizeof(PyObject *); nbytes = bigger * sizeof(PyObject *);
tmp = realloc(self->data, nbytes);
// Pyston change: use GC allocs instead of malloc
// tmp = realloc(self->data, nbytes);
tmp = PyMem_Realloc(self->data, nbytes);
if (tmp == NULL) if (tmp == NULL)
goto nomemory; goto nomemory;
self->data = tmp; self->data = tmp;
...@@ -322,11 +335,17 @@ Pdata_popList(Pdata *self, Py_ssize_t start) ...@@ -322,11 +335,17 @@ Pdata_popList(Pdata *self, Py_ssize_t start)
} \ } \
} }
// Pyston change:
/*
#define FREE_ARG_TUP(self) { \ #define FREE_ARG_TUP(self) { \
if (Py_REFCNT(self->arg) > 1) { \ if (Py_REFCNT(self->arg) > 1) { \
Py_CLEAR(self->arg); \ Py_CLEAR(self->arg); \
} \ } \
} }
*/
#define FREE_ARG_TUP(self) { \
Py_CLEAR(self->arg); \
}
typedef struct Picklerobject { typedef struct Picklerobject {
PyObject_HEAD PyObject_HEAD
...@@ -531,7 +550,9 @@ read_file(Unpicklerobject *self, char **s, Py_ssize_t n) ...@@ -531,7 +550,9 @@ read_file(Unpicklerobject *self, char **s, Py_ssize_t n)
Py_ssize_t size; Py_ssize_t size;
size = ((n < 32) ? 32 : n); size = ((n < 32) ? 32 : n);
if (!( self->buf = (char *)malloc(size))) { // Pyston change: use GC allocs instead of malloc
// if (!( self->buf = (char *)malloc(size))) {
if (!( self->buf = (char *)PyMem_Malloc(size))) {
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
} }
...@@ -539,7 +560,9 @@ read_file(Unpicklerobject *self, char **s, Py_ssize_t n) ...@@ -539,7 +560,9 @@ read_file(Unpicklerobject *self, char **s, Py_ssize_t n)
self->buf_size = size; self->buf_size = size;
} }
else if (n > self->buf_size) { else if (n > self->buf_size) {
char *newbuf = (char *)realloc(self->buf, n); // Pyston change: use GC allocs instead of malloc
// char *newbuf = (char *)realloc(self->buf, n);
char *newbuf = (char *)PyMem_Realloc(self->buf, n);
if (!newbuf) { if (!newbuf) {
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
...@@ -575,7 +598,9 @@ readline_file(Unpicklerobject *self, char **s) ...@@ -575,7 +598,9 @@ readline_file(Unpicklerobject *self, char **s)
Py_ssize_t i; Py_ssize_t i;
if (self->buf_size == 0) { if (self->buf_size == 0) {
if (!( self->buf = (char *)malloc(40))) { // Pyston change: use GC allocs instead of malloc
// if (!( self->buf = (char *)malloc(40))) {
if (!( self->buf = (char *)PyMem_Malloc(40))) {
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
} }
...@@ -599,7 +624,9 @@ readline_file(Unpicklerobject *self, char **s) ...@@ -599,7 +624,9 @@ readline_file(Unpicklerobject *self, char **s)
return -1; return -1;
} }
bigger = self->buf_size << 1; bigger = self->buf_size << 1;
newbuf = (char *)realloc(self->buf, bigger); // Pyston change: use GC allocs instead of malloc
// newbuf = (char *)realloc(self->buf, bigger);
newbuf = (char *)PyMem_Realloc(self->buf, bigger);
if (newbuf == NULL) { if (newbuf == NULL) {
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
...@@ -800,7 +827,9 @@ get(Picklerobject *self, PyObject *id) ...@@ -800,7 +827,9 @@ get(Picklerobject *self, PyObject *id)
static int static int
put(Picklerobject *self, PyObject *ob) put(Picklerobject *self, PyObject *ob)
{ {
if (Py_REFCNT(ob) < 2 || self->fast) // Pyston change:
// if (Py_REFCNT(ob) < 2 || self->fast)
if (/*Py_REFCNT(ob) < 2 ||*/ self->fast)
return 0; return 0;
return put2(self, ob); return put2(self, ob);
...@@ -2087,7 +2116,9 @@ save_inst(Picklerobject *self, PyObject *args) ...@@ -2087,7 +2116,9 @@ save_inst(Picklerobject *self, PyObject *args)
} }
if (!self->bin) { if (!self->bin) {
if (!( name = ((PyClassObject *)class)->cl_name )) { // Pyston change:
// if (!( name = ((PyClassObject *)class)->cl_name )) {
if (!( name = PyClass_Name(class))) {
PyErr_SetString(PicklingError, "class has no name"); PyErr_SetString(PicklingError, "class has no name");
goto finally; goto finally;
} }
...@@ -2634,7 +2665,9 @@ save(Picklerobject *self, PyObject *args, int pers_save) ...@@ -2634,7 +2665,9 @@ save(Picklerobject *self, PyObject *args, int pers_save)
#endif #endif
} }
if (Py_REFCNT(args) > 1) { // Pyston change:
// if (Py_REFCNT(args) > 1) {
if (/*Py_REFCNT(args) >*/ 1) {
if (!( py_ob_id = PyLong_FromVoidPtr(args))) if (!( py_ob_id = PyLong_FromVoidPtr(args)))
goto finally; goto finally;
...@@ -2689,6 +2722,14 @@ save(Picklerobject *self, PyObject *args, int pers_save) ...@@ -2689,6 +2722,14 @@ save(Picklerobject *self, PyObject *args, int pers_save)
} }
break; break;
// Pyston change: add support for attrwrapper
case 'a':
if (type == &PyAttrWrapper_Type) {
res = save_dict(self, args);
goto finally;
}
break;
case 'i': case 'i':
if (type == &PyInstance_Type) { if (type == &PyInstance_Type) {
res = save_inst(self, args); res = save_inst(self, args);
...@@ -2701,6 +2742,12 @@ save(Picklerobject *self, PyObject *args, int pers_save) ...@@ -2701,6 +2742,12 @@ save(Picklerobject *self, PyObject *args, int pers_save)
res = save_global(self, args, NULL); res = save_global(self, args, NULL);
goto finally; goto finally;
} }
// Pyston change: moved because we call this type 'capifunc'
if (type == &PyCFunction_Type) {
res = save_global(self, args, NULL);
goto finally;
}
break; break;
case 'f': case 'f':
...@@ -2716,10 +2763,18 @@ save(Picklerobject *self, PyObject *args, int pers_save) ...@@ -2716,10 +2763,18 @@ save(Picklerobject *self, PyObject *args, int pers_save)
break; break;
case 'b': case 'b':
// Pyston change: moved because we call this type 'capifunc'
/*
if (type == &PyCFunction_Type) { if (type == &PyCFunction_Type) {
res = save_global(self, args, NULL); res = save_global(self, args, NULL);
goto finally; goto finally;
} }
*/
// Pyston change: added handler for 'builtin_function_or_method'
if (type == &PyBuiltinFunction_Type) {
res = save_global(self, args, NULL);
goto finally;
}
} }
if (!pers_save && self->inst_pers_func) { if (!pers_save && self->inst_pers_func) {
...@@ -3144,7 +3199,8 @@ get_Pickler(PyObject *self, PyObject *args, PyObject *kwds) ...@@ -3144,7 +3199,8 @@ get_Pickler(PyObject *self, PyObject *args, PyObject *kwds)
return (PyObject *)newPicklerobject(file, proto); return (PyObject *)newPicklerobject(file, proto);
} }
// Pyston change: use GC allocs instead of malloc
#if 0
static void static void
Pickler_dealloc(Picklerobject *self) Pickler_dealloc(Picklerobject *self)
{ {
...@@ -3160,6 +3216,7 @@ Pickler_dealloc(Picklerobject *self) ...@@ -3160,6 +3216,7 @@ Pickler_dealloc(Picklerobject *self)
PyMem_Free(self->write_buf); PyMem_Free(self->write_buf);
Py_TYPE(self)->tp_free((PyObject *)self); Py_TYPE(self)->tp_free((PyObject *)self);
} }
#endif
static int static int
Pickler_traverse(Picklerobject *self, visitproc visit, void *arg) Pickler_traverse(Picklerobject *self, visitproc visit, void *arg)
...@@ -3286,7 +3343,9 @@ static PyTypeObject Picklertype = { ...@@ -3286,7 +3343,9 @@ static PyTypeObject Picklertype = {
"cPickle.Pickler", /*tp_name*/ "cPickle.Pickler", /*tp_name*/
sizeof(Picklerobject), /*tp_basicsize*/ sizeof(Picklerobject), /*tp_basicsize*/
0, 0,
(destructor)Pickler_dealloc, /* tp_dealloc */ // Pyston change: use GC allocs instead of malloc
// (destructor)Pickler_dealloc, /* tp_dealloc */
0, /* tp_dealloc */
0, /* tp_print */ 0, /* tp_print */
0, /* tp_getattr */ 0, /* tp_getattr */
0, /* tp_setattr */ 0, /* tp_setattr */
...@@ -4643,10 +4702,16 @@ load_mark(Unpicklerobject *self) ...@@ -4643,10 +4702,16 @@ load_mark(Unpicklerobject *self)
s=self->marks_size+20; s=self->marks_size+20;
if (s <= self->num_marks) s=self->num_marks + 1; if (s <= self->num_marks) s=self->num_marks + 1;
if (self->marks == NULL) if (self->marks == NULL)
marks=(Py_ssize_t *)malloc(s * sizeof(Py_ssize_t)); // Pyston change: use GC allocs instead of malloc
// marks=(Py_ssize_t *)malloc(s * sizeof(Py_ssize_t));
marks=(Py_ssize_t *)PyMem_Malloc(s * sizeof(Py_ssize_t));
else else
marks=(Py_ssize_t *)realloc(self->marks, // Pyston change: use GC allocs instead of malloc
// marks=(Py_ssize_t *)realloc(self->marks,
// s * sizeof(Py_ssize_t));
marks=(Py_ssize_t *)PyMem_Realloc(self->marks,
s * sizeof(Py_ssize_t)); s * sizeof(Py_ssize_t));
if (!marks) { if (!marks) {
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
...@@ -5529,7 +5594,8 @@ get_Unpickler(PyObject *self, PyObject *file) ...@@ -5529,7 +5594,8 @@ get_Unpickler(PyObject *self, PyObject *file)
return (PyObject *)newUnpicklerobject(file); return (PyObject *)newUnpicklerobject(file);
} }
// Pyston change: use GC allocs instead of malloc
#if 0
static void static void
Unpickler_dealloc(Unpicklerobject *self) Unpickler_dealloc(Unpicklerobject *self)
{ {
...@@ -5554,6 +5620,7 @@ Unpickler_dealloc(Unpicklerobject *self) ...@@ -5554,6 +5620,7 @@ Unpickler_dealloc(Unpicklerobject *self)
Py_TYPE(self)->tp_free((PyObject *)self); Py_TYPE(self)->tp_free((PyObject *)self);
} }
#endif
static int static int
Unpickler_traverse(Unpicklerobject *self, visitproc visit, void *arg) Unpickler_traverse(Unpicklerobject *self, visitproc visit, void *arg)
...@@ -5785,7 +5852,9 @@ static PyTypeObject Unpicklertype = { ...@@ -5785,7 +5852,9 @@ static PyTypeObject Unpicklertype = {
"cPickle.Unpickler", /*tp_name*/ "cPickle.Unpickler", /*tp_name*/
sizeof(Unpicklerobject), /*tp_basicsize*/ sizeof(Unpicklerobject), /*tp_basicsize*/
0, 0,
(destructor)Unpickler_dealloc, /* tp_dealloc */ // Pyston change: use GC allocs instead of malloc
// (destructor)Unpickler_dealloc, /* tp_dealloc */
(destructor)0, /* tp_dealloc */
0, /* tp_print */ 0, /* tp_print */
(getattrfunc)Unpickler_getattr, /* tp_getattr */ (getattrfunc)Unpickler_getattr, /* tp_getattr */
(setattrfunc)Unpickler_setattr, /* tp_setattr */ (setattrfunc)Unpickler_setattr, /* tp_setattr */
...@@ -5870,6 +5939,10 @@ init_stuff(PyObject *module_dict) ...@@ -5870,6 +5939,10 @@ init_stuff(PyObject *module_dict)
if (PyType_Ready(&Picklertype) < 0) if (PyType_Ready(&Picklertype) < 0)
return -1; return -1;
// Pyston change:
if (PyType_Ready(&PdataType) < 0)
return -1;
INIT_STR(__class__); INIT_STR(__class__);
INIT_STR(__getinitargs__); INIT_STR(__getinitargs__);
INIT_STR(__dict__); INIT_STR(__dict__);
......
...@@ -146,6 +146,19 @@ def elementtree_ext(): ...@@ -146,6 +146,19 @@ def elementtree_ext():
sources = [relpath('Modules/_elementtree.c')], sources = [relpath('Modules/_elementtree.c')],
depends = pyexpat.depends, depends = pyexpat.depends,
) )
@unique
def locale_ext():
return Extension("_locale", sources = map(relpath, [
"Modules/_localemodule.c",
]))
@unique
def cPickle_ext():
return Extension("cPickle", sources = map(relpath, [
"Modules/cPickle.c",
]))
ext_modules = [future_builtins_ext(), ext_modules = [future_builtins_ext(),
multiprocessing_ext(), multiprocessing_ext(),
pyexpat_ext(), pyexpat_ext(),
...@@ -159,8 +172,11 @@ ext_modules = [future_builtins_ext(), ...@@ -159,8 +172,11 @@ ext_modules = [future_builtins_ext(),
readline_ext(), readline_ext(),
termios_ext(), termios_ext(),
mmap_ext(), mmap_ext(),
locale_ext(),
cPickle_ext()
] ]
builtin_headers = map(relpath, glob.glob("Include/*.h")) builtin_headers = map(relpath, glob.glob("Include/*.h"))
for m in ext_modules: for m in ext_modules:
......
...@@ -2052,7 +2052,7 @@ static void add_tp_new_wrapper(BoxedClass* type) noexcept { ...@@ -2052,7 +2052,7 @@ static void add_tp_new_wrapper(BoxedClass* type) noexcept {
if (type->getattr(new_str)) if (type->getattr(new_str))
return; return;
type->giveAttr(incref(new_str), new BoxedCApiFunction(tp_new_methoddef, type)); type->giveAttr(incref(new_str), new BoxedCApiFunction(tp_new_methoddef, type, NULL /* module name */));
} }
void add_operators(BoxedClass* cls) noexcept { void add_operators(BoxedClass* cls) noexcept {
......
...@@ -30,8 +30,9 @@ public: ...@@ -30,8 +30,9 @@ public:
Box* module; Box* module;
public: public:
BoxedCApiFunction(PyMethodDef* method_def, Box* passthrough, Box* module = NULL) BoxedCApiFunction(PyMethodDef* method_def, Box* passthrough, Box* module_name)
: method_def(method_def), passthrough(passthrough), module(module) { : method_def(method_def), passthrough(passthrough), module(module_name) {
assert(!module || PyString_Check(module_name));
Py_XINCREF(passthrough); Py_XINCREF(passthrough);
Py_XINCREF(module); Py_XINCREF(module);
} }
......
...@@ -2182,7 +2182,7 @@ void setupBuiltins() { ...@@ -2182,7 +2182,7 @@ void setupBuiltins() {
{ "print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc }, { "print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc },
}; };
for (auto& md : builtin_methods) { for (auto& md : builtin_methods) {
builtins_module->giveAttr(md.ml_name, new BoxedCApiFunction(&md, builtins_module)); builtins_module->giveAttr(md.ml_name, new BoxedCApiFunction(&md, builtins_module, boxString("__builtin__")));
} }
} }
} }
...@@ -745,7 +745,7 @@ void setupSys() { ...@@ -745,7 +745,7 @@ void setupSys() {
sys_flags_cls->freeze(); sys_flags_cls->freeze();
for (auto& md : sys_methods) { for (auto& md : sys_methods) {
sys_module->giveAttr(md.ml_name, new BoxedCApiFunction(&md, sys_module)); sys_module->giveAttr(md.ml_name, new BoxedCApiFunction(&md, sys_module, boxString("sys")));
} }
sys_module->giveAttrBorrowed("__displayhook__", sys_module->getattr(autoDecref(internStringMortal("displayhook")))); sys_module->giveAttrBorrowed("__displayhook__", sys_module->getattr(autoDecref(internStringMortal("displayhook"))));
......
...@@ -1609,6 +1609,12 @@ extern "C" PyObject* PyClass_New(PyObject* bases, PyObject* dict, PyObject* name ...@@ -1609,6 +1609,12 @@ extern "C" PyObject* PyClass_New(PyObject* bases, PyObject* dict, PyObject* name
} }
} }
extern "C" PyObject* PyClass_Name(PyObject* _classobj) noexcept {
RELEASE_ASSERT(PyClass_Check(_classobj), "");
BoxedClassobj* classobj = (BoxedClassobj*)_classobj;
return classobj->name;
}
extern "C" PyObject* PyMethod_New(PyObject* func, PyObject* self, PyObject* klass) noexcept { extern "C" PyObject* PyMethod_New(PyObject* func, PyObject* self, PyObject* klass) noexcept {
try { try {
return new BoxedInstanceMethod(self, func, klass); return new BoxedInstanceMethod(self, func, klass);
......
...@@ -158,6 +158,9 @@ Box* dictLen(BoxedDict* self) { ...@@ -158,6 +158,9 @@ Box* dictLen(BoxedDict* self) {
} }
extern "C" Py_ssize_t PyDict_Size(PyObject* op) noexcept { extern "C" Py_ssize_t PyDict_Size(PyObject* op) noexcept {
if (op->cls == attrwrapper_cls)
return PyObject_Size(op);
RELEASE_ASSERT(PyDict_Check(op), ""); RELEASE_ASSERT(PyDict_Check(op), "");
return static_cast<BoxedDict*>(op)->d.size(); return static_cast<BoxedDict*>(op)->d.size();
} }
......
...@@ -1285,13 +1285,8 @@ extern "C" int PyList_SetSlice(PyObject* a, Py_ssize_t ilow, Py_ssize_t ihigh, P ...@@ -1285,13 +1285,8 @@ extern "C" int PyList_SetSlice(PyObject* a, Py_ssize_t ilow, Py_ssize_t ihigh, P
// TODO should just call list_ass_slice // TODO should just call list_ass_slice
try { try {
BoxedSlice* slice = (BoxedSlice*)createSlice(autoDecref(boxInt(ilow)), autoDecref(boxInt(ihigh)), None); adjustNegativeIndicesOnObject(l, &ilow, &ihigh);
if (v) listSetitemSliceInt64(l, ilow, ihigh, 1, v);
autoDecref(listSetitemSlice(l, slice, v));
else
autoDecref(listDelitemSlice(l, slice));
Py_DECREF(slice);
return 0; return 0;
} catch (ExcInfo e) { } catch (ExcInfo e) {
setCAPIException(e); setCAPIException(e);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <mpfr.h> #include <mpfr.h>
#include <sstream> #include <sstream>
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "capi/typeobject.h" #include "capi/typeobject.h"
...@@ -204,18 +205,19 @@ extern "C" PyObject* PyLong_FromString(const char* str, char** pend, int base) n ...@@ -204,18 +205,19 @@ extern "C" PyObject* PyLong_FromString(const char* str, char** pend, int base) n
|| (base == 2 && (str[1] == 'b' || str[1] == 'B')))) || (base == 2 && (str[1] == 'b' || str[1] == 'B'))))
str += 2; str += 2;
llvm::StringRef str_ref = str;
llvm::StringRef str_ref_trimmed = str_ref.rtrim(base < 22 ? "Ll \t\n\v\f\r" : " \t\n\v\f\r");
BoxedLong* rtn = new BoxedLong(); BoxedLong* rtn = new BoxedLong();
int r = 0; int r = 0;
if ((str[strlen(str) - 1] == 'L' || str[strlen(str) - 1] == 'l') && base < 22) { if (str_ref_trimmed != str_ref)
std::string without_l(str, strlen(str) - 1); r = mpz_init_set_str(rtn->n, str_ref_trimmed.str().c_str(), base);
r = mpz_init_set_str(rtn->n, without_l.c_str(), base); else
} else {
// if base great than 22, 'l' or 'L' should count as a digit.
r = mpz_init_set_str(rtn->n, str, base); r = mpz_init_set_str(rtn->n, str, base);
}
if (pend) if (pend) {
*pend = const_cast<char*>(str) + strlen(str); *pend = const_cast<char*>(str) + str_ref.size();
}
if (r != 0) { if (r != 0) {
PyErr_Format(PyExc_ValueError, "invalid literal for long() with base %d: '%s'", base, str); PyErr_Format(PyExc_ValueError, "invalid literal for long() with base %d: '%s'", base, str);
return NULL; return NULL;
...@@ -529,6 +531,12 @@ extern "C" void* PyLong_AsVoidPtr(PyObject* vv) noexcept { ...@@ -529,6 +531,12 @@ extern "C" void* PyLong_AsVoidPtr(PyObject* vv) noexcept {
return (void*)x; return (void*)x;
} }
extern "C" size_t _PyLong_NumBits(PyObject* vv) noexcept {
RELEASE_ASSERT(PyLong_Check(vv), "");
return mpz_sizeinbase(((BoxedLong*)vv)->n, 2);
}
extern "C" int _PyLong_AsByteArray(PyLongObject* v, unsigned char* bytes, size_t n, int little_endian, extern "C" int _PyLong_AsByteArray(PyLongObject* v, unsigned char* bytes, size_t n, int little_endian,
int is_signed) noexcept { int is_signed) noexcept {
const mpz_t* op = &((BoxedLong*)v)->n; const mpz_t* op = &((BoxedLong*)v)->n;
......
...@@ -63,9 +63,7 @@ test_collections assertion failed when doing vars(collections.namedtuple( ...@@ -63,9 +63,7 @@ test_collections assertion failed when doing vars(collections.namedtuple(
test_compileall [unknown] test_compileall [unknown]
test_compiler [unknown] test_compiler [unknown]
test_compile [unknown] test_compile [unknown]
test_cookie [unknown]
test_copy Please debug this test in VM. test_copy Please debug this test in VM.
test_cpickle [unknown]
test_cprofile [unknown] test_cprofile [unknown]
test_crypt [unknown] test_crypt [unknown]
test_csv [unknown] test_csv [unknown]
...@@ -91,8 +89,6 @@ test_email [unknown] ...@@ -91,8 +89,6 @@ test_email [unknown]
test_enumerate assert instead of exception in BoxedEnumerate test_enumerate assert instead of exception in BoxedEnumerate
test_exceptions we are missing recursion-depth checking test_exceptions we are missing recursion-depth checking
test_extcall f(**kw) crashes if kw isn't a dict test_extcall f(**kw) crashes if kw isn't a dict
test_file2k we abort when you try to open() a directory
test_file_eintr not sure
test_fileio [unknown] test_fileio [unknown]
test_fork1 [unknown] test_fork1 [unknown]
test_frozen [unknown] test_frozen [unknown]
...@@ -130,8 +126,6 @@ test_kqueue Not really a failure, but it tries to skip itself and we ...@@ -130,8 +126,6 @@ test_kqueue Not really a failure, but it tries to skip itself and we
test_lib2to3 [unknown] test_lib2to3 [unknown]
test_linuxaudiodev [unknown] test_linuxaudiodev [unknown]
test_list longs as slice indices test_list longs as slice indices
test__locale No module named _locale
test_locale [unknown]
test_long_future [unknown] test_long_future [unknown]
test_macos Not really a failure, but it tries to skip itself and we don't support that test_macos Not really a failure, but it tries to skip itself and we don't support that
test_macostools Not really a failure, but it tries to skip itself and we don't support that test_macostools Not really a failure, but it tries to skip itself and we don't support that
...@@ -152,8 +146,6 @@ test_parser [unknown] ...@@ -152,8 +146,6 @@ test_parser [unknown]
test_pdb [unknown] test_pdb [unknown]
test_peepholer [unknown] test_peepholer [unknown]
test_pep352 various unique bugs test_pep352 various unique bugs
test_pickletools [unknown]
test_pickle unknown
test_pkg unknown bug test_pkg unknown bug
test_poplib SSLError (but only on CI) test_poplib SSLError (but only on CI)
test_pprint [unknown] test_pprint [unknown]
...@@ -168,7 +160,6 @@ test_resource [unknown] ...@@ -168,7 +160,6 @@ test_resource [unknown]
test_richcmp PyObject_Not test_richcmp PyObject_Not
test_rlcompleter [unknown] test_rlcompleter [unknown]
test_runpy [unknown] test_runpy [unknown]
test_sax [unknown]
test_scope eval of code object from existing function (not currently supported) test_scope eval of code object from existing function (not currently supported)
test_scriptpackages [unknown] test_scriptpackages [unknown]
test_shelve [unknown] test_shelve [unknown]
......
...@@ -4,11 +4,11 @@ Date: Tue, 28 Apr 2015 11:49:32 +0200 ...@@ -4,11 +4,11 @@ Date: Tue, 28 Apr 2015 11:49:32 +0200
Subject: [PATCH] fastmath: Add support for Pyston Subject: [PATCH] fastmath: Add support for Pyston
--- ---
src/_fastmath.c | 21 +++++++++++++++++++++ src/_fastmath.c | 30 ++++++++++++++++++++++++++++--
1 file changed, 21 insertions(+) 1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/src/_fastmath.c b/src/_fastmath.c diff --git a/src/_fastmath.c b/src/_fastmath.c
index e369f5a..c4cf2aa 100644 index e369f5a..854a984 100644
--- a/src/_fastmath.c --- a/src/_fastmath.c
+++ b/src/_fastmath.c +++ b/src/_fastmath.c
@@ -29,7 +29,14 @@ @@ -29,7 +29,14 @@
...@@ -54,6 +54,21 @@ index e369f5a..c4cf2aa 100644 ...@@ -54,6 +54,21 @@ index e369f5a..c4cf2aa 100644
typedef struct typedef struct
{ {
@@ -1427,8 +1448,13 @@ getStrongPrime (PyObject *self, PyObject *args, PyObject *kwargs)
Py_BLOCK_THREADS;
res = 1;
res &= getRandomRange (X, lower_bound, upper_bound, randfunc);
- res &= getRandomNBitInteger (y[0], 101, randfunc);
- res &= getRandomNBitInteger (y[1], 101, randfunc);
+ // Pyston change: abort on the first error encountered
+ // res &= getRandomNBitInteger (y[0], 101, randfunc);
+ // res &= getRandomNBitInteger (y[1], 101, randfunc);
+ if (res)
+ res &= getRandomNBitInteger (y[0], 101, randfunc);
+ if (res)
+ res &= getRandomNBitInteger (y[1], 101, randfunc);
Py_UNBLOCK_THREADS;
if (!res)
{
-- --
2.1.0 1.9.1
import subprocess, sys, os, shutil, StringIO import subprocess, sys, os, shutil, StringIO
sys.path.append(os.path.dirname(__file__) + "/../lib")
import test_helper
PATCHES = ["pycrypto_0001-fastmath-Add-support-for-Pyston.patch"] PATCHES = ["pycrypto_0001-fastmath-Add-support-for-Pyston.patch"]
PATCHES = [os.path.abspath(os.path.join(os.path.dirname(__file__), p)) for p in PATCHES] PATCHES = [os.path.abspath(os.path.join(os.path.dirname(__file__), p)) for p in PATCHES]
...@@ -56,6 +58,9 @@ enc_data = public_key.encrypt(test_string, 32) ...@@ -56,6 +58,9 @@ enc_data = public_key.encrypt(test_string, 32)
assert enc_data != test_string assert enc_data != test_string
assert key.decrypt(enc_data) == test_string assert key.decrypt(enc_data) == test_string
expected = [{'ran': 1891}]
test_helper.run_test([sys.executable, "setup.py", "test"], pycrypto_dir, expected)
print "-- Tests finished" print "-- Tests finished"
print "-- Unpatching pycrypto" print "-- Unpatching pycrypto"
......
import cPickle
l = [[], (123,)]
l.append(l)
s = cPickle.dumps(l)
print repr(s)
l2 = cPickle.loads(s)
l3 = l2.pop()
print l2, l3, l2 is l3
print cPickle.loads(cPickle.dumps("hello world"))
# Sqlalchemy wants this:
import operator
print repr(cPickle.dumps(len))
print repr(cPickle.dumps(operator.and_))
class C(object):
pass
c = C()
c.a = 1
# print repr(cPickle.dumps(c)) # Our output is different to cpythons because we don't do some refcounting opts.
print cPickle.loads(cPickle.dumps(c)).a
for obj in [(1, 2), "hello world", u"hola world", 1.0, 1j, 1L, 2, {1:2}, set([3]), frozenset([4])]:
print
print "Testing pickling subclasses of %s..." % type(obj)
class MySubclass(type(obj)):
pass
o = MySubclass(obj)
print repr(o), type(o)
for protocol in (0, 1, 2):
print "Protocol", protocol
s = cPickle.dumps(o, protocol=protocol)
# print repr(s) # Our output is different to cpythons because we don't do some refcounting opts.
o2 = cPickle.loads(s)
print repr(o2), type(o2)
import cStringIO
StringIO = cPickle.loads(cPickle.dumps(cStringIO.StringIO))
print type(StringIO())
...@@ -42,3 +42,7 @@ for obj in [(1, 2), "hello world", u"hola world", 1.0, 1j, 1L, 2, {1:2}, set([3] ...@@ -42,3 +42,7 @@ for obj in [(1, 2), "hello world", u"hola world", 1.0, 1j, 1L, 2, {1:2}, set([3]
o2 = pickle.loads(s) o2 = pickle.loads(s)
print repr(o2), type(o2) print repr(o2), type(o2)
import cStringIO
StringIO = pickle.loads(pickle.dumps(cStringIO.StringIO))
print type(StringIO())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment