Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
3ebd2551
Commit
3ebd2551
authored
May 25, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #547 from undingen/pyexpat
Add pyexpat support
parents
ca90416c
b78965d0
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
813 additions
and
16 deletions
+813
-16
Makefile
Makefile
+8
-2
from_cpython/CMakeLists.txt
from_cpython/CMakeLists.txt
+7
-1
from_cpython/Include/pyexpat.h
from_cpython/Include/pyexpat.h
+50
-0
from_cpython/Modules/pyexpat.c
from_cpython/Modules/pyexpat.c
+37
-7
from_cpython/setup.py
from_cpython/setup.py
+34
-6
src/capi/modsupport.cpp
src/capi/modsupport.cpp
+9
-0
test/cpython/test_pyexpat.py
test/cpython/test_pyexpat.py
+668
-0
No files found.
Makefile
View file @
3ebd2551
...
...
@@ -1197,11 +1197,17 @@ TEST_EXT_MODULE_NAMES := basic_test descr_test slots_test
TEST_EXT_MODULE_SRCS
:=
$
(
TEST_EXT_MODULE_NAMES:%
=
test
/test_extension/%.c
)
TEST_EXT_MODULE_OBJS
:=
$
(
TEST_EXT_MODULE_NAMES:%
=
test
/test_extension/%.pyston.so
)
SHAREDMODS_NAMES
:=
_multiprocessing
SHAREDMODS_NAMES
:=
_multiprocessing
pyexpat
SHAREDMODS_SRCS
:=
\
_multiprocessing/multiprocessing.c
\
_multiprocessing/semaphore.c
\
_multiprocessing/socket_connection.c
_multiprocessing/socket_connection.c
\
expat/xmlparse.c
\
expat/xmlrole.c
\
expat/xmltok.c
\
expat/xmltok_impl.c
\
expat/xmltok_ns.c
\
pyexpat.c
SHAREDMODS_SRCS
:=
$
(
SHAREDMODS_SRCS:%
=
from_cpython/Modules/%
)
SHAREDMODS_OBJS
:=
$
(
SHAREDMODS_NAMES:%
=
lib_pyston/%.pyston.so
)
...
...
from_cpython/CMakeLists.txt
View file @
3ebd2551
...
...
@@ -110,7 +110,7 @@ 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"
)
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
add_custom_command
(
OUTPUT
${
CMAKE_BINARY_DIR
}
/lib_pyston/_multiprocessing.pyston.so
${
CMAKE_BINARY_DIR
}
/lib_pyston/pyexpat.pyston.so
COMMAND
${
CMAKE_BINARY_DIR
}
/pyston setup.py build --build-lib
${
CMAKE_BINARY_DIR
}
/lib_pyston
DEPENDS
pyston
...
...
@@ -119,5 +119,11 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/lib_pyston/_multiprocessing.pyston
Modules/_multiprocessing/multiprocessing.c
Modules/_multiprocessing/semaphore.c
Modules/_multiprocessing/socket_connection.c
Modules/expat/xmlparse.c
Modules/expat/xmlrole.c
Modules/expat/xmltok.c
Modules/expat/xmltok_impl.c
Modules/expat/xmltok_ns.c
Modules/pyexpat.c
WORKING_DIRECTORY
${
CMAKE_CURRENT_SOURCE_DIR
}
)
add_custom_target
(
sharedmods DEPENDS
${
CMAKE_BINARY_DIR
}
/lib_pyston/_multiprocessing.pyston.so
)
from_cpython/Include/pyexpat.h
0 → 100644
View file @
3ebd2551
// This file is originally from CPython 2.7, with modifications for Pyston
/* Stuff to export relevant 'expat' entry points from pyexpat to other
* parser modules, such as cElementTree. */
/* note: you must import expat.h before importing this module! */
#define PyExpat_CAPI_MAGIC "pyexpat.expat_CAPI 1.0"
#define PyExpat_CAPSULE_NAME "pyexpat.expat_CAPI"
struct
PyExpat_CAPI
{
char
*
magic
;
/* set to PyExpat_CAPI_MAGIC */
int
size
;
/* set to sizeof(struct PyExpat_CAPI) */
int
MAJOR_VERSION
;
int
MINOR_VERSION
;
int
MICRO_VERSION
;
/* pointers to selected expat functions. add new functions at
the end, if needed */
const
XML_LChar
*
(
*
ErrorString
)(
enum
XML_Error
code
);
enum
XML_Error
(
*
GetErrorCode
)(
XML_Parser
parser
);
XML_Size
(
*
GetErrorColumnNumber
)(
XML_Parser
parser
);
XML_Size
(
*
GetErrorLineNumber
)(
XML_Parser
parser
);
enum
XML_Status
(
*
Parse
)(
XML_Parser
parser
,
const
char
*
s
,
int
len
,
int
isFinal
);
XML_Parser
(
*
ParserCreate_MM
)(
const
XML_Char
*
encoding
,
const
XML_Memory_Handling_Suite
*
memsuite
,
const
XML_Char
*
namespaceSeparator
);
void
(
*
ParserFree
)(
XML_Parser
parser
);
void
(
*
SetCharacterDataHandler
)(
XML_Parser
parser
,
XML_CharacterDataHandler
handler
);
void
(
*
SetCommentHandler
)(
XML_Parser
parser
,
XML_CommentHandler
handler
);
void
(
*
SetDefaultHandlerExpand
)(
XML_Parser
parser
,
XML_DefaultHandler
handler
);
void
(
*
SetElementHandler
)(
XML_Parser
parser
,
XML_StartElementHandler
start
,
XML_EndElementHandler
end
);
void
(
*
SetNamespaceDeclHandler
)(
XML_Parser
parser
,
XML_StartNamespaceDeclHandler
start
,
XML_EndNamespaceDeclHandler
end
);
void
(
*
SetProcessingInstructionHandler
)(
XML_Parser
parser
,
XML_ProcessingInstructionHandler
handler
);
void
(
*
SetUnknownEncodingHandler
)(
XML_Parser
parser
,
XML_UnknownEncodingHandler
handler
,
void
*
encodingHandlerData
);
void
(
*
SetUserData
)(
XML_Parser
parser
,
void
*
userData
);
/* always add new stuff to the end! */
};
from_cpython/Modules/pyexpat.c
View file @
3ebd2551
#include "Python.h"
#include <ctype.h>
#include "frameobject.h"
// Pyston change:
//#include "frameobject.h"
#include "code.h" // CPython includes this from compile.h which gets included by Python.h
#include "expat.h"
#include "pyexpat.h"
...
...
@@ -29,6 +32,9 @@
#define FIX_TRACE
#endif
// Pyston change: Disable tracing for now until we support it
#undef FIX_TRACE
enum
HandlerTypes
{
StartElement
,
EndElement
,
...
...
@@ -153,7 +159,7 @@ get_handler_name(struct HandlerInfo *hinfo)
{
PyObject
*
name
=
hinfo
->
nameobj
;
if
(
name
==
NULL
)
{
name
=
Py
String_FromString
(
hinfo
->
name
);
name
=
Py
GC_AddRoot
(
PyString_FromString
(
hinfo
->
name
)
);
hinfo
->
nameobj
=
name
;
}
Py_XINCREF
(
name
);
...
...
@@ -261,11 +267,16 @@ flag_error(xmlparseobject *self)
static
PyCodeObject
*
getcode
(
enum
HandlerTypes
slot
,
char
*
func_name
,
int
lineno
)
{
// Pyston change: Disable this until we support custom code objects
#if 0
if (handler_info[slot].tb_code == NULL) {
handler_info[slot].tb_code =
PyCode_NewEmpty(__FILE__, func_name, lineno);
}
return handler_info[slot].tb_code;
#else
return
NULL
;
#endif
}
#ifdef FIX_TRACE
...
...
@@ -336,6 +347,8 @@ static PyObject*
call_with_frame
(
PyCodeObject
*
c
,
PyObject
*
func
,
PyObject
*
args
,
xmlparseobject
*
self
)
{
// Pyston change: Disable this until we support custom tracebacks
#if 0
PyThreadState *tstate = PyThreadState_GET();
PyFrameObject *f;
PyObject *res;
...
...
@@ -374,6 +387,14 @@ call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args,
tstate
->
frame
=
f
->
f_back
;
Py_DECREF
(
f
);
return
res
;
#else
PyObject
*
res
;
res
=
PyEval_CallObject
(
func
,
args
);
if
(
res
==
NULL
)
{
XML_StopParser
(
self
->
itself
,
XML_FALSE
);
}
return
res
;
#endif
}
#ifndef Py_USING_UNICODE
...
...
@@ -1122,7 +1143,9 @@ xmlparse_ExternalEntityParserCreate(xmlparseobject *self, PyObject *args)
for
(
i
=
0
;
handler_info
[
i
].
name
!=
NULL
;
i
++
)
/* do nothing */
;
new_parser
->
handlers
=
malloc
(
sizeof
(
PyObject
*
)
*
i
);
// Pyston change: use GC alloc routine because those contain Python objects
// new_parser->handlers = malloc(sizeof(PyObject *) * i);
new_parser
->
handlers
=
PyMem_Malloc
(
sizeof
(
PyObject
*
)
*
i
);
if
(
!
new_parser
->
handlers
)
{
Py_DECREF
(
new_parser
);
return
PyErr_NoMemory
();
...
...
@@ -1341,7 +1364,9 @@ newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
for
(
i
=
0
;
handler_info
[
i
].
name
!=
NULL
;
i
++
)
/* do nothing */
;
self
->
handlers
=
malloc
(
sizeof
(
PyObject
*
)
*
i
);
// Pyston change: use GC alloc routine because those contain Python objects
// self->handlers = malloc(sizeof(PyObject *) * i);
self
->
handlers
=
PyMem_Malloc
(
sizeof
(
PyObject
*
)
*
i
);
if
(
!
self
->
handlers
)
{
Py_DECREF
(
self
);
return
PyErr_NoMemory
();
...
...
@@ -1372,7 +1397,8 @@ xmlparse_dealloc(xmlparseobject *self)
self
->
handlers
[
i
]
=
NULL
;
Py_XDECREF
(
temp
);
}
free
(
self
->
handlers
);
// Pyston change: object are allocated using the GC not malloc
// free(self->handlers);
self
->
handlers
=
NULL
;
}
if
(
self
->
buffer
!=
NULL
)
{
...
...
@@ -1853,6 +1879,10 @@ MODULE_INITFUNC(void)
Py_TYPE
(
&
Xmlparsetype
)
=
&
PyType_Type
;
// Pyston change:
if
(
PyType_Ready
(
&
Xmlparsetype
)
<
0
)
return
;
/* Create the module and add the functions */
m
=
Py_InitModule3
(
MODULE_NAME
,
pyexpat_methods
,
pyexpat_module_documentation
);
...
...
@@ -1861,8 +1891,8 @@ MODULE_INITFUNC(void)
/* Add some symbolic constants to the module */
if
(
ErrorObject
==
NULL
)
{
ErrorObject
=
PyErr_NewException
(
"xml.parsers.expat.ExpatError"
,
NULL
,
NULL
);
ErrorObject
=
Py
GC_AddRoot
(
Py
Err_NewException
(
"xml.parsers.expat.ExpatError"
,
NULL
,
NULL
)
)
;
if
(
ErrorObject
==
NULL
)
return
;
}
...
...
from_cpython/setup.py
View file @
3ebd2551
...
...
@@ -7,13 +7,41 @@ def relpath(fn):
r
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
fn
)
return
r
def
multiprocessing_ext
():
return
Extension
(
"_multiprocessing"
,
sources
=
map
(
relpath
,
[
"Modules/_multiprocessing/multiprocessing.c"
,
"Modules/_multiprocessing/socket_connection.c"
,
"Modules/_multiprocessing/semaphore.c"
,
]))
def
pyexpat_ext
():
define_macros
=
[(
'HAVE_EXPAT_CONFIG_H'
,
'1'
),]
expat_sources
=
map
(
relpath
,
[
'Modules/expat/xmlparse.c'
,
'Modules/expat/xmlrole.c'
,
'Modules/expat/xmltok.c'
,
'Modules/pyexpat.c'
])
expat_depends
=
map
(
relpath
,
[
'Modules/expat/ascii.h'
,
'Modules/expat/asciitab.h'
,
'Modules/expat/expat.h'
,
'Modules/expat/expat_config.h'
,
'Modules/expat/expat_external.h'
,
'Modules/expat/internal.h'
,
'Modules/expat/latin1tab.h'
,
'Modules/expat/utf8tab.h'
,
'Modules/expat/xmlrole.h'
,
'Modules/expat/xmltok.h'
,
'Modules/expat/xmltok_impl.h'
])
return
Extension
(
'pyexpat'
,
define_macros
=
define_macros
,
include_dirs
=
[
relpath
(
'Modules/expat'
)],
sources
=
expat_sources
,
depends
=
expat_depends
,
)
setup
(
name
=
"Pyston"
,
version
=
"1.0"
,
description
=
"Pyston shared modules"
,
ext_modules
=
[
Extension
(
"_multiprocessing"
,
sources
=
map
(
relpath
,
[
"Modules/_multiprocessing/multiprocessing.c"
,
"Modules/_multiprocessing/socket_connection.c"
,
"Modules/_multiprocessing/semaphore.c"
,
]),
)],
ext_modules
=
[
multiprocessing_ext
(),
pyexpat_ext
()]
)
src/capi/modsupport.cpp
View file @
3ebd2551
...
...
@@ -463,6 +463,15 @@ extern "C" int PyModule_AddIntConstant(PyObject* _m, const char* name, long valu
return
PyModule_AddObject
(
_m
,
name
,
boxInt
(
value
));
}
extern
"C"
PyObject
*
PyModule_New
(
const
char
*
name
)
noexcept
{
BoxedModule
*
module
=
new
BoxedModule
();
module
->
giveAttr
(
"__name__"
,
boxStrConstant
(
name
));
module
->
giveAttr
(
"__doc__"
,
None
);
module
->
giveAttr
(
"__package__"
,
None
);
return
module
;
}
extern
"C"
PyObject
*
PyEval_CallMethod
(
PyObject
*
obj
,
const
char
*
methodname
,
const
char
*
format
,
...)
noexcept
{
va_list
vargs
;
PyObject
*
meth
;
...
...
test/cpython/test_pyexpat.py
0 → 100644
View file @
3ebd2551
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment