[pypy-svn] r55133 - in pypy/dist/pypy: config lib lib/_ctypes module/_rawffi module/_rawffi/test module/signal module/thread rlib rlib/test rpython/module/test rpython/tool rpython/tool/test translator/c translator/c/src translator/c/test translator/goal translator/goal/test2
afa at codespeak.net
afa at codespeak.net
Thu May 22 19:04:20 CEST 2008
Author: afa
Date: Thu May 22 19:04:13 2008
New Revision: 55133
Added:
pypy/dist/pypy/lib/_subprocess.py
- copied unchanged from r55132, pypy/branch/win32port/pypy/lib/_subprocess.py
pypy/dist/pypy/lib/msvcrt.py
- copied unchanged from r55132, pypy/branch/win32port/pypy/lib/msvcrt.py
pypy/dist/pypy/rpython/module/test/test_ll_os_environ.py
- copied unchanged from r55132, pypy/branch/win32port/pypy/rpython/module/test/test_ll_os_environ.py
Modified:
pypy/dist/pypy/config/pypyoption.py
pypy/dist/pypy/lib/_ctypes/builtin.py
pypy/dist/pypy/module/_rawffi/__init__.py
pypy/dist/pypy/module/_rawffi/interp_rawffi.py
pypy/dist/pypy/module/_rawffi/test/test__rawffi.py
pypy/dist/pypy/module/signal/interp_signal.py
pypy/dist/pypy/module/thread/ll_thread.py
pypy/dist/pypy/rlib/getnameinfo.py
pypy/dist/pypy/rlib/libffi.py
pypy/dist/pypy/rlib/rmmap.py
pypy/dist/pypy/rlib/rpoll.py
pypy/dist/pypy/rlib/rsocket.py
pypy/dist/pypy/rlib/rwin32.py
pypy/dist/pypy/rlib/test/test_libffi.py
pypy/dist/pypy/rlib/test/test_rmmap.py
pypy/dist/pypy/rlib/test/test_rpoll.py
pypy/dist/pypy/rpython/tool/rffi_platform.py
pypy/dist/pypy/rpython/tool/test/test_c.py
pypy/dist/pypy/translator/c/genc.py
pypy/dist/pypy/translator/c/src/instrument.h
pypy/dist/pypy/translator/c/src/thread.h
pypy/dist/pypy/translator/c/src/thread_nt.h
pypy/dist/pypy/translator/c/test/test_extfunc.py
pypy/dist/pypy/translator/c/test/test_newgc.py
pypy/dist/pypy/translator/c/test/test_standalone.py
pypy/dist/pypy/translator/goal/nanos.py
pypy/dist/pypy/translator/goal/test2/test_nanos.py
Log:
Merge of the win32port branch:
Port various modules to the win32 platform.
_rawffi, ctypes, socket, select, signal now translate and (seem to) work on windows.
They are now included in the --allworkingmodules.
Outside the win32-specific changes, some modifications may have an impact on
other platforms. It's perfectly possible that I broke something there.
At least the pypy-c translation completes on Linux.
These changes are:
- r55127: cleanup sys.modules after importing nanos, to prevent inclusion of all os.pyc as
a frozen module inside pypy-c.
- r55055: added _rawffi.get_libc() which loads the same msvcrt as the one used by pypy-c.
- r54947: remove Python.h dependency from pypy's src/thread.h.
- r54946: CConfig.configure() adds the separate module files when compiling the sample program
- r54928: Allow compilation of files residing outside the target directory.
They are copied into our working dir, and compiled there.
Modified: pypy/dist/pypy/config/pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/pypyoption.py (original)
+++ pypy/dist/pypy/config/pypyoption.py Thu May 22 19:04:13 2008
@@ -37,12 +37,6 @@
del working_modules["_minimal_curses"]
# modules currently missing explicit windows support
del working_modules["signal"]
- del working_modules["_rawffi"]
- # modules with broken windows support
- del working_modules["mmap"] # MLS - Added 5/11/08 - broken
- del working_modules["_socket"] # MLS - Added 5/11/08 - broken
- del working_modules["select"] # MLS - Added 5/11/08 - broken
-
module_dependencies = {}
Modified: pypy/dist/pypy/lib/_ctypes/builtin.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/builtin.py (original)
+++ pypy/dist/pypy/lib/_ctypes/builtin.py Thu May 22 19:04:13 2008
@@ -5,8 +5,8 @@
encoding = 'ascii'
errors = 'strict'
-_memmove_addr = ('memmove', _rawffi.libc_name)
-_memset_addr = ('memset', _rawffi.libc_name)
+_memmove_addr = _rawffi.get_libc().getaddressindll('memmove')
+_memset_addr = _rawffi.get_libc().getaddressindll('memset')
def _string_at_addr(addr, lgt):
# address here can be almost anything
Modified: pypy/dist/pypy/module/_rawffi/__init__.py
==============================================================================
--- pypy/dist/pypy/module/_rawffi/__init__.py (original)
+++ pypy/dist/pypy/module/_rawffi/__init__.py Thu May 22 19:04:13 2008
@@ -25,6 +25,7 @@
'charp2rawstring' : 'interp_rawffi.charp2rawstring',
'CallbackPtr' : 'callback.W_CallbackPtr',
'_num_of_allocated_objects' : 'tracker.num_of_allocated_objects',
+ 'get_libc' : 'interp_rawffi.get_libc',
}
appleveldefs = {
@@ -44,10 +45,6 @@
]:
if hasattr(libffi, name):
Module.interpleveldefs[name] = "space.wrap(%r)" % getattr(libffi, name)
-
- # Name of C runtime library
- from pypy.rpython.lltypesystem.ll2ctypes import get_libc_name
- Module.interpleveldefs['libc_name'] = "space.wrap(%r)" % get_libc_name()
super(Module, cls).buildloaders()
buildloaders = classmethod(buildloaders)
Modified: pypy/dist/pypy/module/_rawffi/interp_rawffi.py
==============================================================================
--- pypy/dist/pypy/module/_rawffi/interp_rawffi.py (original)
+++ pypy/dist/pypy/module/_rawffi/interp_rawffi.py Thu May 22 19:04:13 2008
@@ -468,3 +468,9 @@
raise OperationError(space.w_WindowsError, space.wrap(hresult))
return space.wrap(hresult)
check_HRESULT.unwrap_spec = [ObjSpace, int]
+
+def get_libc(space):
+ try:
+ return space.wrap(W_CDLL(space, get_libc_name()))
+ except OSError, e:
+ raise wrap_oserror(space, e)
Modified: pypy/dist/pypy/module/_rawffi/test/test__rawffi.py
==============================================================================
--- pypy/dist/pypy/module/_rawffi/test/test__rawffi.py (original)
+++ pypy/dist/pypy/module/_rawffi/test/test__rawffi.py Thu May 22 19:04:13 2008
@@ -180,9 +180,13 @@
import _rawffi
_rawffi.CDLL(self.libc_name)
+ def test_libc_load(self):
+ import _rawffi
+ _rawffi.get_libc()
+
def test_getattr(self):
import _rawffi
- libc = _rawffi.CDLL(self.libc_name)
+ libc = _rawffi.get_libc()
func = libc.ptr('rand', [], 'i')
assert libc.ptr('rand', [], 'i') is func # caching
assert libc.ptr('rand', [], 'l') is not func
@@ -292,7 +296,7 @@
def test_time(self):
import _rawffi
- libc = _rawffi.CDLL(self.libc_name)
+ libc = _rawffi.get_libc()
time = libc.ptr('time', ['z'], 'l') # 'z' instead of 'P' just for test
arg = _rawffi.Array('P')(1)
arg[0] = 0
@@ -306,7 +310,7 @@
import _rawffi
struct_type = _rawffi.Structure([('tv_sec', 'l'), ('tv_usec', 'l')])
structure = struct_type()
- libc = _rawffi.CDLL(self.libc_name)
+ libc = _rawffi.get_libc()
gettimeofday = libc.ptr('gettimeofday', ['P', 'P'], 'i')
arg1 = structure.byptr()
@@ -341,7 +345,7 @@
("tm_wday", 'i'),
("tm_yday", 'i'),
("tm_isdst", 'i')])
- libc = _rawffi.CDLL(self.libc_name)
+ libc = _rawffi.get_libc()
gmtime = libc.ptr('gmtime', ['P'], 'P')
arg = x.byptr()
@@ -452,7 +456,7 @@
skip("FIXME: compare actually receives a pair of int**")
import _rawffi
import struct
- libc = _rawffi.CDLL(self.libc_name)
+ libc = _rawffi.get_libc()
ll_to_sort = _rawffi.Array('i')(4)
for i in range(4):
ll_to_sort[i] = 4-i
Modified: pypy/dist/pypy/module/signal/interp_signal.py
==============================================================================
--- pypy/dist/pypy/module/signal/interp_signal.py (original)
+++ pypy/dist/pypy/module/signal/interp_signal.py Thu May 22 19:04:13 2008
@@ -21,7 +21,8 @@
eci = ExternalCompilationInfo(
includes = ['stdlib.h', 'src/signals.h'],
separate_module_sources = ['#include <src/signals.h>'],
- include_dirs = [str(py.path.local(autopath.pypydir).join('translator', 'c'))]
+ include_dirs = [str(py.path.local(autopath.pypydir).join('translator', 'c'))],
+ export_symbols = ['pypysig_poll'],
)
def external(name, args, result, **kwds):
Modified: pypy/dist/pypy/module/thread/ll_thread.py
==============================================================================
--- pypy/dist/pypy/module/thread/ll_thread.py (original)
+++ pypy/dist/pypy/module/thread/ll_thread.py Thu May 22 19:04:13 2008
@@ -6,7 +6,7 @@
from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from pypy.rpython.lltypesystem import llmemory
-import thread, py
+import thread, py, os
from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.annotation import model as annmodel
from pypy.rpython.lltypesystem.lltype import typeOf
@@ -18,14 +18,13 @@
error = thread.error
eci = ExternalCompilationInfo(
- includes = ['unistd.h', 'src/thread.h'],
- separate_module_sources=['''
- #include <Python.h>
- #include <src/exception.h>
- #include <src/thread.h>
- '''],
+ includes = ['src/thread.h'],
+ separate_module_sources = [''],
include_dirs = [str(py.path.local(autopath.pypydir).join('translator', 'c')),
- python_inc]
+ python_inc],
+ export_symbols = ['RPyThreadGetIdent', 'RPyThreadLockInit',
+ 'RPyThreadAcquireLock', 'RPyThreadReleaseLock',
+ 'RPyThreadFusedReleaseAcquireLock',]
)
def llexternal(name, args, result, **kwds):
Modified: pypy/dist/pypy/rlib/getnameinfo.py
==============================================================================
--- pypy/dist/pypy/rlib/getnameinfo.py (original)
+++ pypy/dist/pypy/rlib/getnameinfo.py Thu May 22 19:04:13 2008
@@ -24,7 +24,7 @@
if sp:
serv = rffi.charp2str(sp.c_s_name)
else:
- serv = "%d" % _c.ntohs(sin_port)
+ serv = "%d" % r_uint(_c.ntohs(sin_port))
return serv
Modified: pypy/dist/pypy/rlib/libffi.py
==============================================================================
--- pypy/dist/pypy/rlib/libffi.py (original)
+++ pypy/dist/pypy/rlib/libffi.py Thu May 22 19:04:13 2008
@@ -37,15 +37,31 @@
else:
libffidir = py.path.local(pypydir).join('translator', 'c', 'src', 'libffi_msvc')
eci = ExternalCompilationInfo(
+ pre_include_lines = ['#define _WIN32_WINNT 0x501'],
includes = ['ffi.h', 'windows.h'],
libraries = ['kernel32'],
include_dirs = [libffidir],
+ separate_module_sources = ['''
+ #include <stdio.h>
+
+ /* Get the module where the "fopen" function resides in */
+ HANDLE get_libc_handle() {
+ MEMORY_BASIC_INFORMATION mi;
+ memset(&mi, 0, sizeof(mi));
+
+ if( !VirtualQueryEx(GetCurrentProcess(), &fopen, &mi, sizeof(mi)) )
+ return 0;
+
+ return (HMODULE)mi.AllocationBase;
+ }
+ '''],
separate_module_files = [libffidir.join('ffi.c'),
libffidir.join('prep_cif.c'),
libffidir.join('win32.c'),
libffidir.join('pypy_ffi.c'),
],
- export_symbols = ['ffi_call', 'ffi_prep_cif', 'ffi_prep_closure'],
+ export_symbols = ['ffi_call', 'ffi_prep_cif', 'ffi_prep_closure',
+ 'get_libc_handle'],
)
FFI_TYPE_P = lltype.Ptr(lltype.ForwardReference())
@@ -193,6 +209,9 @@
# XXX rffi.cast here...
return res
+ def get_libc_name():
+ return 'libc.so.6'
+
if _MS_WINDOWS:
def dlopen(name):
res = rwin32.LoadLibrary(name)
@@ -218,6 +237,12 @@
FormatError = rwin32.FormatError
LoadLibrary = rwin32.LoadLibrary
+ get_libc_handle = external('get_libc_handle', [], rwin32.HANDLE)
+
+ def get_libc_name():
+ return rwin32.GetModuleFileName(get_libc_handle())
+
+
FFI_OK = cConfig.FFI_OK
FFI_BAD_TYPEDEF = cConfig.FFI_BAD_TYPEDEF
FFI_DEFAULT_ABI = rffi.cast(rffi.USHORT, cConfig.FFI_DEFAULT_ABI)
@@ -518,3 +543,4 @@
def getaddressindll(self, name):
return dlsym(self.lib, name)
+
Modified: pypy/dist/pypy/rlib/rmmap.py
==============================================================================
--- pypy/dist/pypy/rlib/rmmap.py (original)
+++ pypy/dist/pypy/rlib/rmmap.py Thu May 22 19:04:13 2008
@@ -38,21 +38,7 @@
size_t = rffi_platform.SimpleType("size_t", rffi.LONG)
off_t = rffi_platform.SimpleType("off_t", rffi.LONG)
if _MS_WINDOWS:
- DWORD_PTR = rffi_platform.SimpleType("DWORD_PTR", rffi.LONG)
- WORD = rffi_platform.SimpleType("WORD", rffi.UINT)
- DWORD = rffi_platform.SimpleType("DWORD", rffi.ULONG)
- BOOL = rffi_platform.SimpleType("BOOL", rffi.LONG)
- INT = rffi_platform.SimpleType("INT", rffi.INT)
- LONG = rffi_platform.SimpleType("LONG", rffi.LONG)
- PLONG = rffi_platform.SimpleType("PLONG", rffi.LONGP)
- LPVOID = rffi_platform.SimpleType("LPVOID", rffi.INTP)
- LPCVOID = rffi_platform.SimpleType("LPCVOID", rffi.VOIDP)
- HANDLE = rffi_platform.SimpleType("HANDLE", rffi.VOIDP)
- LPHANDLE = rffi_platform.SimpleType("LPHANDLE", rffi.CCHARPP)
- LPCTSTR = rffi_platform.SimpleType("LPCTSTR", rffi.CCHARP)
- LPDWORD = rffi_platform.SimpleType("LPDWORD", rffi.INTP)
LPSECURITY_ATTRIBUTES = rffi_platform.SimpleType("LPSECURITY_ATTRIBUTES", rffi.CCHARP)
- SIZE_T = rffi_platform.SimpleType("SIZE_T", rffi.SIZE_T)
constants = {}
if _POSIX:
@@ -82,6 +68,11 @@
for name in constant_names:
setattr(CConfig, name, rffi_platform.ConstantInteger(name))
+ from pypy.rlib.rwin32 import HANDLE, LPHANDLE
+ from pypy.rlib.rwin32 import DWORD, WORD, DWORD_PTR, LPDWORD
+ from pypy.rlib.rwin32 import BOOL, LPVOID, LPCVOID, LPCTSTR, SIZE_T
+ from pypy.rlib.rwin32 import INT, LONG, PLONG
+
# export the constants inside and outside. see __init__.py
cConfig = rffi_platform.configure(CConfig)
constants.update(cConfig)
Modified: pypy/dist/pypy/rlib/rpoll.py
==============================================================================
--- pypy/dist/pypy/rlib/rpoll.py (original)
+++ pypy/dist/pypy/rlib/rpoll.py Thu May 22 19:04:13 2008
@@ -8,6 +8,7 @@
import os
from pypy.rlib import _rsocket_rffi as _c
from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.rlib.rarithmetic import intmask, r_uint
# ____________________________________________________________
# events
@@ -121,7 +122,7 @@
if ret == _c.WSA_WAIT_TIMEOUT:
return []
- if ret == _c.WSA_WAIT_FAILED:
+ if ret == r_uint(_c.WSA_WAIT_FAILED):
raise PollError(_c.geterrno())
retval = []
Modified: pypy/dist/pypy/rlib/rsocket.py
==============================================================================
--- pypy/dist/pypy/rlib/rsocket.py (original)
+++ pypy/dist/pypy/rlib/rsocket.py Thu May 22 19:04:13 2008
@@ -153,8 +153,7 @@
flags=AI_PASSIVE,
address_to_fill=result)
if len(info) > 1:
- raise RSocketError("wildcard resolved to "
- "multiple addresses")
+ raise RSocketError("wildcard resolved to multiple addresses")
return info[0][4]
# IPv4 also supports the special name "<broadcast>".
Modified: pypy/dist/pypy/rlib/rwin32.py
==============================================================================
--- pypy/dist/pypy/rlib/rwin32.py (original)
+++ pypy/dist/pypy/rlib/rwin32.py Thu May 22 19:04:13 2008
@@ -23,11 +23,20 @@
_compilation_info_ = eci
if WIN32:
+ DWORD_PTR = rffi_platform.SimpleType("DWORD_PTR", rffi.LONG)
+ WORD = rffi_platform.SimpleType("WORD", rffi.UINT)
DWORD = rffi_platform.SimpleType("DWORD", rffi.UINT)
BOOL = rffi_platform.SimpleType("BOOL", rffi.LONG)
- HRESULT = rffi_platform.SimpleType("HRESULT", rffi.LONG)
+ INT = rffi_platform.SimpleType("INT", rffi.INT)
+ LONG = rffi_platform.SimpleType("LONG", rffi.LONG)
+ PLONG = rffi_platform.SimpleType("PLONG", rffi.LONGP)
+ LPVOID = rffi_platform.SimpleType("LPVOID", rffi.INTP)
+ LPCVOID = rffi_platform.SimpleType("LPCVOID", rffi.VOIDP)
+ LPCTSTR = rffi_platform.SimpleType("LPCTSTR", rffi.CCHARP)
+ LPDWORD = rffi_platform.SimpleType("LPDWORD", rffi.INTP)
+ SIZE_T = rffi_platform.SimpleType("SIZE_T", rffi.SIZE_T)
- HANDLE = rffi_platform.SimpleType("HANDLE", rffi.VOIDP)
+ HRESULT = rffi_platform.SimpleType("HRESULT", rffi.LONG)
HLOCAL = rffi_platform.SimpleType("HLOCAL", rffi.VOIDP)
DEFAULT_LANGUAGE = rffi_platform.ConstantInteger(
@@ -45,6 +54,10 @@
return rffi.llexternal(name, args, result, compilation_info=eci, calling_conv='win')
if WIN32:
+ HANDLE = rffi.ULONG
+ LPHANDLE = rffi.CArrayPtr(HANDLE)
+ HMODULE = HANDLE
+
GetLastError = winexternal('GetLastError', [], DWORD)
LoadLibrary = winexternal('LoadLibraryA', [rffi.CCHARP], rffi.VOIDP)
@@ -83,4 +96,16 @@
def FAILED(hr):
return rffi.cast(HRESULT, hr) < 0
-
+
+ _GetModuleFileName = winexternal('GetModuleFileNameA',
+ [HMODULE, rffi.CCHARP, DWORD],
+ DWORD)
+
+ def GetModuleFileName(module):
+ size = 255 # MAX_PATH
+ buf = lltype.malloc(rffi.CCHARP.TO, size, flavor='raw')
+ res = _GetModuleFileName(module, buf, size)
+ if not res:
+ return ''
+ else:
+ return ''.join([buf[i] for i in range(res)])
Modified: pypy/dist/pypy/rlib/test/test_libffi.py
==============================================================================
--- pypy/dist/pypy/rlib/test/test_libffi.py (original)
+++ pypy/dist/pypy/rlib/test/test_libffi.py Thu May 22 19:04:13 2008
@@ -360,3 +360,11 @@
del lib
assert not ALLOCATED
+
+class TestWin32Handles:
+ def test_get_libc_handle(self):
+ handle = get_libc_handle()
+ print get_libc_name()
+ print hex(handle)
+ assert handle != 0
+ assert handle % 0x1000 == 0
Modified: pypy/dist/pypy/rlib/test/test_rmmap.py
==============================================================================
--- pypy/dist/pypy/rlib/test/test_rmmap.py (original)
+++ pypy/dist/pypy/rlib/test/test_rmmap.py Thu May 22 19:04:13 2008
@@ -371,3 +371,14 @@
interpret(func, [f.fileno()])
f.close()
+
+ def test_translated(self):
+ from pypy.translator.c.test.test_genc import compile
+
+ def func(no):
+ m = mmap.mmap(no, 1)
+ r = m.read_byte()
+ m.close()
+ return r
+
+ compile(func, [int])
Modified: pypy/dist/pypy/rlib/test/test_rpoll.py
==============================================================================
--- pypy/dist/pypy/rlib/test/test_rpoll.py (original)
+++ pypy/dist/pypy/rlib/test/test_rpoll.py Thu May 22 19:04:13 2008
@@ -47,3 +47,11 @@
cli.close()
servconn.close()
serv.close()
+
+def test_translate():
+ from pypy.translator.c.test.test_genc import compile
+
+ def func():
+ poll({})
+
+ compile(func, [])
Modified: pypy/dist/pypy/rpython/tool/rffi_platform.py
==============================================================================
--- pypy/dist/pypy/rpython/tool/rffi_platform.py (original)
+++ pypy/dist/pypy/rpython/tool/rffi_platform.py Thu May 22 19:04:13 2008
@@ -537,7 +537,9 @@
"""
def run_example_code(filepath, eci):
- output = build_executable_cache([filepath], eci)
+ eci = eci.convert_sources_to_files(being_main=True)
+ files = [filepath] + [py.path.local(f) for f in eci.separate_module_files]
+ output = build_executable_cache(files, eci)
section = None
for line in output.splitlines():
line = line.strip()
Modified: pypy/dist/pypy/rpython/tool/test/test_c.py
==============================================================================
--- pypy/dist/pypy/rpython/tool/test/test_c.py (original)
+++ pypy/dist/pypy/rpython/tool/test/test_c.py Thu May 22 19:04:13 2008
@@ -22,10 +22,25 @@
compiler = ccompiler.new_compiler()
c_file = udir.join('rffilib.c')
c_file.write(c_source)
- compiler.compile([str(c_file)], output_dir='/')
- compiler.link_shared_lib([str(udir.join('rffilib.o'))],
- 'rffi', output_dir=str(udir))
- cls.lib = ctypes.CDLL(str(udir.join('librffi.so')))
+
+ if sys.platform == 'win32':
+ ccflags = []
+ o_file = 'rffilib.obj'
+ so_file = 'rffi.dll'
+ else:
+ ccflags = ['-fPIC']
+ o_file = 'rffilib.o'
+ so_file = 'librffi.so'
+
+ rootdir = os.path.splitdrive(str(udir))[0] + '/'
+ compiler.compile([str(c_file)], output_dir=rootdir,
+ extra_preargs=ccflags)
+
+ compiler.link_shared_lib([str(udir.join(o_file))],
+ 'rffi', output_dir=str(udir),
+ export_symbols = ['int_int_to_struct_p',
+ 'int_to_void_p'])
+ cls.lib = ctypes.CDLL(str(udir.join(so_file)))
def test_basic(self):
assert self.lib
Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py (original)
+++ pypy/dist/pypy/translator/c/genc.py Thu May 22 19:04:13 2008
@@ -304,8 +304,18 @@
if profopt is not None and not self.config.translation.noprofopt:
profbased = (ProfOpt, profopt)
+ # Copy extrafiles to target directory, if needed
+ extrafiles = []
+ for fn in self.extrafiles:
+ fn = py.path.local(fn)
+ if not fn.relto(udir):
+ newname = self.targetdir.join(fn.basename)
+ fn.copy(newname)
+ fn = newname
+ extrafiles.append(fn)
+
return CCompiler(
- [self.c_source_filename] + self.extrafiles,
+ [self.c_source_filename] + extrafiles,
self.eci, compiler_exe = cc, profbased = profbased)
def compile(self):
@@ -366,6 +376,8 @@
else:
assert fn.dirpath().dirpath() == udir
name = '../' + fn.relto(udir)
+
+ name = name.replace("\\", "/")
cfiles.append(name)
if self.config.translation.gcrootfinder == "asmgcc":
ofiles.append(name[:-2] + '.s')
Modified: pypy/dist/pypy/translator/c/src/instrument.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/instrument.h (original)
+++ pypy/dist/pypy/translator/c/src/instrument.h Thu May 22 19:04:13 2008
@@ -9,10 +9,14 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#ifndef WIN32
#include <sys/mman.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#else
+#include <windows.h>
+#endif
typedef unsigned long instrument_count_t;
@@ -22,18 +26,33 @@
char *fname = getenv("_INSTRUMENT_COUNTERS");
if (fname) {
int fd;
+#ifdef WIN32
+ HANDLE map_handle;
+ HANDLE file_handle;
+#endif
void *buf;
size_t sz = sizeof(instrument_count_t)*INSTRUMENT_NCOUNTER;
fd = open(fname, O_CREAT|O_TRUNC|O_RDWR, 0744);
if (sz > 0) {
lseek(fd, sz-1, SEEK_SET);
write(fd, "", 1);
+#ifndef WIN32
buf = mmap(NULL, sz, PROT_WRITE|PROT_READ, MAP_SHARED,
fd, 0);
if (buf == MAP_FAILED) {
fprintf(stderr, "mapping instrument counters file failed\n");
abort();
}
+#else
+ file_handle = (HANDLE)_get_osfhandle(fd);
+ map_handle = CreateFileMapping(file_handle, NULL, PAGE_READWRITE,
+ 0, sz, "");
+ buf = MapViewOfFile(map_handle, FILE_MAP_WRITE, 0, 0, 0);
+ if (buf == 0) {
+ fprintf(stderr, "mapping instrument counters file failed\n");
+ abort();
+ }
+#endif
_instrument_counters = (instrument_count_t *)buf;
}
}
Modified: pypy/dist/pypy/translator/c/src/thread.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/thread.h (original)
+++ pypy/dist/pypy/translator/c/src/thread.h Thu May 22 19:04:13 2008
@@ -3,7 +3,13 @@
#ifndef __PYPY_THREAD_H
#define __PYPY_THREAD_H
-#include "Python.h"
+#include <assert.h>
+
+#ifdef _WIN32
+#include "thread_nt.h"
+#else
+
+#include <unistd.h>
#ifndef _POSIX_THREADS
/* This means pthreads are not implemented in libc headers, hence the macro
@@ -18,9 +24,7 @@
#include "thread_pthread.h"
#endif
-#ifdef NT_THREADS
-#include "thread_nt.h"
-#endif
+#endif /* !_WIN32 */
#ifdef USE___THREAD
Modified: pypy/dist/pypy/translator/c/src/thread_nt.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/thread_nt.h (original)
+++ pypy/dist/pypy/translator/c/src/thread_nt.h Thu May 22 19:04:13 2008
@@ -19,11 +19,6 @@
* Thread support.
*/
-/*
- * Return the thread Id instead of an handle. The Id is said to uniquely
- identify the thread in the system
- */
-#define RPyThreadGetIdent GetCurrentThreadId
#define RPyOpaque_INITEXPR_ThreadLock { 0, 0, NULL }
typedef struct {
@@ -54,6 +49,15 @@
#ifndef PYPY_NOT_MAIN_FILE
+/*
+ * Return the thread Id instead of an handle. The Id is said to uniquely
+ identify the thread in the system
+ */
+int RPyThreadGetIdent()
+{
+ return GetCurrentThreadId();
+}
+
static int
bootstrap(void *call)
{
@@ -201,7 +205,10 @@
/************************************************************/
-#define RPyThreadLockInit(lock) InitializeNonRecursiveMutex(lock)
+int RPyThreadLockInit(struct RPyOpaque_ThreadLock * lock)
+{
+ return InitializeNonRecursiveMutex(lock);
+}
void RPyOpaqueDealloc_ThreadLock(struct RPyOpaque_ThreadLock *lock)
{
Modified: pypy/dist/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_extfunc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_extfunc.py Thu May 22 19:04:13 2008
@@ -657,9 +657,8 @@
elif hasattr(os, 'waitpid'):
# windows has no fork but some waitpid to be emulated
def test_waitpid():
+ prog = str(sys.executable)
def does_stuff():
- prog = sys.executable
- prog = str(prog)
args = [prog]
# args = [prog, '-c', '"import os;os._exit(4)"']
# note that the above variant creates a bad array
Modified: pypy/dist/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_newgc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_newgc.py Thu May 22 19:04:13 2008
@@ -19,13 +19,14 @@
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=True)
config.translation.gc = gcpolicy
+ config.translation.countmallocs = True
if t is None:
t = TranslationContext(config=config)
if inputtypes is not None:
t.buildannotator().build_types(fn, inputtypes)
t.buildrtyper().specialize()
builder = genc.CExtModuleBuilder(t, fn, config=config)
- builder.generate_source(defines={'COUNT_OP_MALLOCS': 1})
+ builder.generate_source()
builder.compile()
if conftest.option.view:
t.view()
@@ -838,11 +839,13 @@
def test_callback_with_collect(self):
from pypy.rlib.libffi import ffi_type_pointer, cast_type_to_ffitype,\
CDLL, ffi_type_void, CallbackFuncPtr, ffi_type_sint
- from pypy.rpython.lltypesystem import rffi
+ from pypy.rpython.lltypesystem import rffi, ll2ctypes
from pypy.rlib import rgc
import gc
slong = cast_type_to_ffitype(rffi.LONG)
+ libc_name = ll2ctypes.get_libc_name()
+
def callback(ll_args, ll_res, stuff):
gc.collect()
p_a1 = rffi.cast(rffi.VOIDPP, ll_args[0])[0]
@@ -856,7 +859,7 @@
res[0] = -1
def f():
- libc = CDLL('libc.so.6')
+ libc = CDLL(libc_name)
qsort = libc.getpointer('qsort', [ffi_type_pointer, slong,
slong, ffi_type_pointer],
ffi_type_void)
Modified: pypy/dist/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_standalone.py (original)
+++ pypy/dist/pypy/translator/c/test/test_standalone.py Thu May 22 19:04:13 2008
@@ -4,9 +4,10 @@
from pypy.rlib.rarithmetic import r_longlong
from pypy.translator.translator import TranslationContext
from pypy.translator.backendopt import all
-from pypy.translator.c.genc import CStandaloneBuilder
+from pypy.translator.c.genc import CStandaloneBuilder, ExternalCompilationInfo
from pypy.annotation.listdef import s_list_of_strings
from pypy.tool.udir import udir
+from pypy.tool.autopath import pypydir
def test_hello_world():
@@ -54,8 +55,6 @@
# gives the strings unquoted in the list
def test_counters():
- if sys.platform == 'win32':
- py.test.skip("instrument counters support is unix only for now")
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.lltypesystem.lloperation import llop
def entry_point(argv):
@@ -138,8 +137,6 @@
assert map(float, data.split()) == [0.0, 0.0]
def test_profopt():
- if sys.platform == 'win32':
- py.test.skip("instrumentation support is unix only for now")
def add(a,b):
return a + b - b + b - b + b - b + b - b + b - b + b - b + b
def entry_point(argv):
@@ -190,3 +187,42 @@
cbuilder.compile()
data = cbuilder.cmdexec('hi there')
assert data.strip() == "OK"
+
+def test_separate_files():
+ # One file in translator/c/src
+ fname = py.path.local(pypydir).join(
+ 'translator', 'c', 'src', 'll_strtod.h')
+
+ # One file in (another) subdir of the temp directory
+ dirname = udir.join("test_dir").ensure(dir=1)
+ fname2 = dirname.join("test_genc.c")
+ fname2.write("""
+ void f() {
+ LL_strtod_formatd("%5f", 12.3);
+ }""")
+
+ files = [fname, fname2]
+
+ def entry_point(argv):
+ return 0
+
+ t = TranslationContext()
+ t.buildannotator().build_types(entry_point, [s_list_of_strings])
+ t.buildrtyper().specialize()
+
+ cbuilder = CStandaloneBuilder(t, entry_point, t.config)
+ cbuilder.eci = cbuilder.eci.merge(
+ ExternalCompilationInfo(separate_module_files=files))
+ cbuilder.generate_source()
+
+ makefile = udir.join(cbuilder.modulename, 'Makefile').read()
+
+ # generated files are compiled in the same directory
+ assert " ../test_dir/test_genc.c" in makefile
+ assert " ../test_dir/test_genc.o" in makefile
+
+ # but files from pypy source dir must be copied
+ assert "translator/c/src" not in makefile
+ assert " ll_strtod.h" in makefile
+ assert " ll_strtod.o" in makefile
+
Modified: pypy/dist/pypy/translator/goal/nanos.py
==============================================================================
--- pypy/dist/pypy/translator/goal/nanos.py (original)
+++ pypy/dist/pypy/translator/goal/nanos.py Thu May 22 19:04:13 2008
@@ -29,17 +29,25 @@
import os
app_os_path = applevel(r'''
- # NOT_RPYTHON
from os.path import dirname, join, abspath, isfile, islink
''', filename=__file__)
app_os = applevel(r'''
# NOT_RPYTHON
+ import sys
+ sysmodules = sys.modules.keys()
+
from os import sep, pathsep, getenv, name, fdopen
try:
from os import readlink
except ImportError:
pass
+
+ # restore the previous list of loaded modules
+ for name in sys.modules.keys():
+ if name not in sysmodules:
+ del sys.modules[name]
+ del sys
''', filename=__file__)
def getenv(space, w_name):
Modified: pypy/dist/pypy/translator/goal/test2/test_nanos.py
==============================================================================
--- pypy/dist/pypy/translator/goal/test2/test_nanos.py (original)
+++ pypy/dist/pypy/translator/goal/test2/test_nanos.py Thu May 22 19:04:13 2008
@@ -17,4 +17,10 @@
w_dict = space.newdict()
space.exec_(open(filename).read(), w_dict, w_dict)
entry_point = create_entry_point(space, w_dict)
+
+ # check that 'os' is not in sys.modules
+ assert not space.is_true(
+ space.call_method(space.sys.get('modules'),
+ '__contains__', space.wrap('os')))
+
entry_point(['', '-c', 'print 42'])
More information about the Pypy-commit
mailing list