Commit 39b32381 authored by Rudi Chen's avatar Rudi Chen

Get the _ctypes module to compile.

parent bb31b6ee
...@@ -118,6 +118,7 @@ add_custom_command(OUTPUT ...@@ -118,6 +118,7 @@ add_custom_command(OUTPUT
${CMAKE_BINARY_DIR}/lib_pyston/pyexpat.pyston.so ${CMAKE_BINARY_DIR}/lib_pyston/pyexpat.pyston.so
${CMAKE_BINARY_DIR}/lib_pyston/_elementtree.pyston.so ${CMAKE_BINARY_DIR}/lib_pyston/_elementtree.pyston.so
${CMAKE_BINARY_DIR}/lib_pyston/bz2.pyston.so ${CMAKE_BINARY_DIR}/lib_pyston/bz2.pyston.so
${CMAKE_BINARY_DIR}/lib_pyston/_ctypes.pyston.so
${CMAKE_BINARY_DIR}/lib_pyston/grp.pyston.so ${CMAKE_BINARY_DIR}/lib_pyston/grp.pyston.so
${CMAKE_BINARY_DIR}/lib_pyston/termios.pyston.so ${CMAKE_BINARY_DIR}/lib_pyston/termios.pyston.so
${CMAKE_BINARY_DIR}/lib_pyston/_curses.pyston.so ${CMAKE_BINARY_DIR}/lib_pyston/_curses.pyston.so
...@@ -129,6 +130,11 @@ add_custom_command(OUTPUT ...@@ -129,6 +130,11 @@ add_custom_command(OUTPUT
Modules/_multiprocessing/multiprocessing.c Modules/_multiprocessing/multiprocessing.c
Modules/_multiprocessing/semaphore.c Modules/_multiprocessing/semaphore.c
Modules/_multiprocessing/socket_connection.c Modules/_multiprocessing/socket_connection.c
Modules/_ctypes/_ctypes.c
Modules/_ctypes/callbacks.c
Modules/_ctypes/callproc.c
Modules/_ctypes/stgdict.c
Modules/_ctypes/cfield.c
Modules/expat/xmlparse.c Modules/expat/xmlparse.c
Modules/expat/xmlrole.c Modules/expat/xmlrole.c
Modules/expat/xmltok.c Modules/expat/xmltok.c
......
#ifndef Py_COMPILE_H
#define Py_COMPILE_H
#include "code.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Public interface */
struct _node; /* Declare the existence of this type */
PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);
/* Future feature support */
typedef struct {
int ff_features; /* flags set by future statements */
int ff_lineno; /* line number of last future statement */
} PyFutureFeatures;
#define FUTURE_NESTED_SCOPES "nested_scopes"
#define FUTURE_GENERATORS "generators"
#define FUTURE_DIVISION "division"
#define FUTURE_ABSOLUTE_IMPORT "absolute_import"
#define FUTURE_WITH_STATEMENT "with_statement"
#define FUTURE_PRINT_FUNCTION "print_function"
#define FUTURE_UNICODE_LITERALS "unicode_literals"
struct _mod; /* Declare the existence of this type */
PyAPI_FUNC(PyCodeObject *) PyAST_Compile(struct _mod *, const char *,
PyCompilerFlags *, PyArena *);
PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(struct _mod *, const char *);
#ifdef __cplusplus
}
#endif
#endif /* !Py_COMPILE_H */
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
#include "Python.h" #include "Python.h"
#include "compile.h" /* required only for 2.3, as it seems */ #include "compile.h" /* required only for 2.3, as it seems */
#include "frameobject.h"
// Pyston change: We don't have this file and commented out the function that needs it, but
// we may want to support that function in the future.
//#include "frameobject.h"
#include <ffi.h> #include <ffi.h>
#ifdef MS_WIN32 #ifdef MS_WIN32
...@@ -149,6 +152,9 @@ failed: ...@@ -149,6 +152,9 @@ failed:
/* after code that pyrex generates */ /* after code that pyrex generates */
void _ctypes_add_traceback(char *funcname, char *filename, int lineno) void _ctypes_add_traceback(char *funcname, char *filename, int lineno)
{ {
// TODO: Pyston change:
// Supporting this will require frameobject.h
#if 0
PyObject *py_globals = 0; PyObject *py_globals = 0;
PyCodeObject *py_code = 0; PyCodeObject *py_code = 0;
PyFrameObject *py_frame = 0; PyFrameObject *py_frame = 0;
...@@ -170,6 +176,9 @@ void _ctypes_add_traceback(char *funcname, char *filename, int lineno) ...@@ -170,6 +176,9 @@ void _ctypes_add_traceback(char *funcname, char *filename, int lineno)
Py_XDECREF(py_globals); Py_XDECREF(py_globals);
Py_XDECREF(py_code); Py_XDECREF(py_code);
Py_XDECREF(py_frame); Py_XDECREF(py_frame);
#else
assert(false);
#endif
} }
#ifdef MS_WIN32 #ifdef MS_WIN32
......
...@@ -1291,7 +1291,9 @@ s_get(void *ptr, Py_ssize_t size) ...@@ -1291,7 +1291,9 @@ s_get(void *ptr, Py_ssize_t size)
*/ */
slen = strlen(PyString_AS_STRING(result)); slen = strlen(PyString_AS_STRING(result));
size = min(size, (Py_ssize_t)slen); size = min(size, (Py_ssize_t)slen);
if (result->ob_refcnt == 1) {
// Pyston change: no ob_refcnt
if (false /*result->ob_refcnt == 1*/) {
/* shorten the result */ /* shorten the result */
_PyString_Resize(&result, size); _PyString_Resize(&result, size);
return result; return result;
......
...@@ -2,11 +2,22 @@ ...@@ -2,11 +2,22 @@
from distutils.core import setup, Extension from distutils.core import setup, Extension
import os import os
import sysconfig
def relpath(fn): def relpath(fn):
r = os.path.join(os.path.dirname(__file__), fn) r = os.path.join(os.path.dirname(__file__), fn)
return r return r
def unique(f):
# Use an array otherwise Python 2 gets confused about scoping.
cache = []
def wrapper(*args):
if len(cache) == 0:
cache.append(f(*args))
return cache[0]
return wrapper
@unique
def multiprocessing_ext(): def multiprocessing_ext():
return Extension("_multiprocessing", sources = map(relpath, [ return Extension("_multiprocessing", sources = map(relpath, [
"Modules/_multiprocessing/multiprocessing.c", "Modules/_multiprocessing/multiprocessing.c",
...@@ -14,26 +25,58 @@ def multiprocessing_ext(): ...@@ -14,26 +25,58 @@ def multiprocessing_ext():
"Modules/_multiprocessing/semaphore.c", "Modules/_multiprocessing/semaphore.c",
])) ]))
@unique
def bz2_ext(): def bz2_ext():
return Extension("bz2", sources = map(relpath, [ return Extension("bz2", sources = map(relpath, [
"Modules/bz2module.c", "Modules/bz2module.c",
]), libraries = ['bz2']) ]), libraries = ['bz2'])
@unique
def ctypes_ext():
ext = Extension("_ctypes", sources = map(relpath, [
"Modules/_ctypes/_ctypes.c",
"Modules/_ctypes/callbacks.c",
"Modules/_ctypes/callproc.c",
"Modules/_ctypes/stgdict.c",
"Modules/_ctypes/cfield.c"
]))
# Hack: Just copy the values of ffi_inc and ffi_lib from CPython's setup.py
# May want something more robust later.
ffi_inc = ['/usr/include/x86_64-linux-gnu']
ffi_lib = "ffi_pic"
ext.include_dirs.extend(ffi_inc)
ext.libraries.append(ffi_lib)
return ext
@unique
def ctypes_test_ext():
# TODO: I'm not sure how to use the ctypes tests, I just copied it over
# from CPython's setup.py. For now we're only importing ctypes, not passing
# all its tests.
return Extension('_ctypes_test',
sources= map(relpath, ['Modules/_ctypes/_ctypes_test.c']))
@unique
def grp_ext(): def grp_ext():
return Extension("grp", sources = map(relpath, [ return Extension("grp", sources = map(relpath, [
"Modules/grpmodule.c", "Modules/grpmodule.c",
])) ]))
@unique
def curses_ext(): def curses_ext():
return Extension("_curses", sources = map(relpath, [ return Extension("_curses", sources = map(relpath, [
"Modules/_cursesmodule.c", "Modules/_cursesmodule.c",
]), libraries = ['curses']) ]), libraries = ['curses'])
@unique
def termios_ext(): def termios_ext():
return Extension("termios", sources = map(relpath, [ return Extension("termios", sources = map(relpath, [
"Modules/termios.c", "Modules/termios.c",
])) ]))
@unique
def pyexpat_ext(): def pyexpat_ext():
define_macros = [('HAVE_EXPAT_CONFIG_H', '1'),] define_macros = [('HAVE_EXPAT_CONFIG_H', '1'),]
expat_sources = map(relpath, ['Modules/expat/xmlparse.c', expat_sources = map(relpath, ['Modules/expat/xmlparse.c',
...@@ -60,6 +103,7 @@ def pyexpat_ext(): ...@@ -60,6 +103,7 @@ def pyexpat_ext():
depends = expat_depends, depends = expat_depends,
) )
@unique
def elementtree_ext(): def elementtree_ext():
# elementtree depends on expat # elementtree depends on expat
pyexpat = pyexpat_ext() pyexpat = pyexpat_ext()
...@@ -71,10 +115,15 @@ def elementtree_ext(): ...@@ -71,10 +115,15 @@ def elementtree_ext():
sources = [relpath('Modules/_elementtree.c')], sources = [relpath('Modules/_elementtree.c')],
depends = pyexpat.depends, depends = pyexpat.depends,
) )
ext_modules = [multiprocessing_ext(),
pyexpat_ext(),
elementtree_ext(),
bz2_ext(),
ctypes_ext(),
ctypes_test_ext(),
grp_ext(),
curses_ext(),
termios_ext()]
setup(name="Pyston", setup(name="Pyston", version="1.0", description="Pyston shared modules", ext_modules=ext_modules)
version="1.0",
description="Pyston shared modules",
ext_modules=[multiprocessing_ext(), pyexpat_ext(), elementtree_ext(), bz2_ext(), grp_ext(), curses_ext(), termios_ext()]
)
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