Commit 598da395 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #581 from undingen/deco_whitespace

Add the _elementtree and update libpypa
parents abd3c8e1 ca9d59b7
...@@ -1208,7 +1208,8 @@ SHAREDMODS_SRCS := \ ...@@ -1208,7 +1208,8 @@ SHAREDMODS_SRCS := \
expat/xmltok.c \ expat/xmltok.c \
expat/xmltok_impl.c \ expat/xmltok_impl.c \
expat/xmltok_ns.c \ expat/xmltok_ns.c \
pyexpat.c pyexpat.c \
_elementtree.c
SHAREDMODS_SRCS := $(SHAREDMODS_SRCS:%=from_cpython/Modules/%) SHAREDMODS_SRCS := $(SHAREDMODS_SRCS:%=from_cpython/Modules/%)
SHAREDMODS_OBJS := $(SHAREDMODS_NAMES:%=lib_pyston/%.pyston.so) SHAREDMODS_OBJS := $(SHAREDMODS_NAMES:%=lib_pyston/%.pyston.so)
......
...@@ -112,7 +112,10 @@ file(GLOB_RECURSE STDPARSER_SRCS Parser ...@@ -112,7 +112,10 @@ file(GLOB_RECURSE STDPARSER_SRCS Parser
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers -Wno-tautological-compare -Wno-type-limits -Wno-unused-result -Wno-strict-aliasing") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers -Wno-tautological-compare -Wno-type-limits -Wno-unused-result -Wno-strict-aliasing")
add_library(FROM_CPYTHON OBJECT ${STDMODULE_SRCS} ${STDOBJECT_SRCS} ${STDPYTHON_SRCS} ${STDPARSER_SRCS}) add_library(FROM_CPYTHON OBJECT ${STDMODULE_SRCS} ${STDOBJECT_SRCS} ${STDPYTHON_SRCS} ${STDPARSER_SRCS})
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/lib_pyston/_multiprocessing.pyston.so ${CMAKE_BINARY_DIR}/lib_pyston/pyexpat.pyston.so add_custom_command(OUTPUT
${CMAKE_BINARY_DIR}/lib_pyston/_multiprocessing.pyston.so
${CMAKE_BINARY_DIR}/lib_pyston/pyexpat.pyston.so
${CMAKE_BINARY_DIR}/lib_pyston/_elementtree.pyston.so
COMMAND ${CMAKE_BINARY_DIR}/pyston setup.py build --build-lib ${CMAKE_BINARY_DIR}/lib_pyston COMMAND ${CMAKE_BINARY_DIR}/pyston setup.py build --build-lib ${CMAKE_BINARY_DIR}/lib_pyston
DEPENDS DEPENDS
pyston pyston
...@@ -127,5 +130,6 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/lib_pyston/_multiprocessing.pyston ...@@ -127,5 +130,6 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/lib_pyston/_multiprocessing.pyston
Modules/expat/xmltok_impl.c Modules/expat/xmltok_impl.c
Modules/expat/xmltok_ns.c Modules/expat/xmltok_ns.c
Modules/pyexpat.c Modules/pyexpat.c
Modules/_elementtree.c
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(sharedmods DEPENDS ${CMAKE_BINARY_DIR}/lib_pyston/_multiprocessing.pyston.so) add_custom_target(sharedmods DEPENDS ${CMAKE_BINARY_DIR}/lib_pyston/_multiprocessing.pyston.so)
...@@ -1791,8 +1791,9 @@ treebuilder_handle_data(TreeBuilderObject* self, PyObject* data) ...@@ -1791,8 +1791,9 @@ treebuilder_handle_data(TreeBuilderObject* self, PyObject* data)
Py_INCREF(data); self->data = data; Py_INCREF(data); self->data = data;
} else { } else {
/* more than one item; use a list to collect items */ /* more than one item; use a list to collect items */
if (PyString_CheckExact(self->data) && Py_REFCNT(self->data) == 1 && // Pyston change: Py_REFCNT(self->data) -> 2
PyString_CheckExact(data) && PyString_GET_SIZE(data) == 1) { if (PyString_CheckExact(self->data) && /*Py_REFCNT(self->data)*/2 == 1 &&
PyString_CheckExact(data) && PyString_GET_SIZE(data) == 1) {
/* expat often generates single character data sections; handle /* expat often generates single character data sections; handle
the most common case by resizing the existing string... */ the most common case by resizing the existing string... */
Py_ssize_t size = PyString_GET_SIZE(self->data); Py_ssize_t size = PyString_GET_SIZE(self->data);
...@@ -2878,6 +2879,16 @@ init_elementtree(void) ...@@ -2878,6 +2879,16 @@ init_elementtree(void)
Py_TYPE(&XMLParser_Type) = &PyType_Type; Py_TYPE(&XMLParser_Type) = &PyType_Type;
#endif #endif
// Pyston change: register types
if (PyType_Ready(&Element_Type) < 0)
return;
if (PyType_Ready(&TreeBuilder_Type) < 0)
return;
#if defined(USE_EXPAT)
if (PyType_Ready(&XMLParser_Type) < 0)
return;
#endif
m = Py_InitModule("_elementtree", _functions); m = Py_InitModule("_elementtree", _functions);
if (!m) if (!m)
return; return;
......
...@@ -40,8 +40,21 @@ def pyexpat_ext(): ...@@ -40,8 +40,21 @@ def pyexpat_ext():
depends = expat_depends, depends = expat_depends,
) )
def elementtree_ext():
# elementtree depends on expat
pyexpat = pyexpat_ext()
define_macros = pyexpat.define_macros + [('USE_PYEXPAT_CAPI', None),]
return Extension('_elementtree',
define_macros = define_macros,
include_dirs = pyexpat.include_dirs,
libraries = pyexpat.libraries,
sources = [relpath('Modules/_elementtree.c')],
depends = pyexpat.depends,
)
setup(name="Pyston", setup(name="Pyston",
version="1.0", version="1.0",
description="Pyston shared modules", description="Pyston shared modules",
ext_modules=[multiprocessing_ext(), pyexpat_ext()] ext_modules=[multiprocessing_ext(), pyexpat_ext(), elementtree_ext()]
) )
Subproject commit 7f14a66674f6d65c717199512e7ca705110c8da1 Subproject commit 89f615a75fbc86d0dda71b407cb704077749c2cc
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
namespace pyston { namespace pyston {
namespace gc { namespace gc {
extern "C" inline void* gc_alloc(size_t bytes, GCKind kind_id) __attribute__((visibility("default"))); extern "C" void* gc_alloc(size_t bytes, GCKind kind_id) __attribute__((visibility("default")));
extern "C" inline void* gc_realloc(void* ptr, size_t bytes) __attribute__((visibility("default"))); extern "C" void* gc_realloc(void* ptr, size_t bytes) __attribute__((visibility("default")));
extern "C" inline void gc_free(void* ptr) __attribute__((visibility("default"))); extern "C" void gc_free(void* ptr) __attribute__((visibility("default")));
} }
template <class T> class StlCompatAllocator { template <class T> class StlCompatAllocator {
......
...@@ -1241,6 +1241,10 @@ Box* longHash(BoxedLong* self) { ...@@ -1241,6 +1241,10 @@ Box* longHash(BoxedLong* self) {
raiseExcHelper(TypeError, "descriptor '__pow__' requires a 'long' object but received a '%s'", raiseExcHelper(TypeError, "descriptor '__pow__' requires a 'long' object but received a '%s'",
getTypeName(self)); getTypeName(self));
// If the long fits into an int we have to return the same hash in order that we can find the value in a dict.
if (mpz_fits_slong_p(self->n))
return boxInt(mpz_get_si(self->n));
// Not sure if this is a good hash function or not; // Not sure if this is a good hash function or not;
// simple, but only includes top bits: // simple, but only includes top bits:
union { union {
......
# fail-if: '-x' not in EXTRA_JIT_ARGS
def dec(f): def dec(f):
return f return f
......
d = {2:2} d = {2:2}
d[1] = 1 d[1] = 1
print d print d
print d[1] print d[1], d[1L], d[1.0], d[True]
d = {} d = {}
for i in xrange(10): for i in xrange(10):
......
# test is based on the cpython ElementTree doc
def test(ET):
xml_str = """<?xml version="1.0"?>
<data>
<country name="Liechtenstein">
<rank>1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapore">
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
</country>
<country name="Panama">
<rank>68</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
</data>
"""
root = ET.fromstring(xml_str)
for child in root:
print child.tag, child.attrib
print root[0][1].text
for neighbor in root.iter('neighbor'):
print sorted(neighbor.attrib.items())
for country in root.findall('country'):
rank = country.find('rank').text
name = country.get('name')
print name, rank
import xml.etree.ElementTree as Python_ET
import xml.etree.cElementTree as CAPI_ET
test(Python_ET)
test(CAPI_ET)
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