Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r74549:9a1ca4c16f23 Date: 2014-11-17 10:05 -0800 http://bitbucket.org/pypy/pypy/changeset/9a1ca4c16f23/
Log: merge default diff too long, truncating to 2000 out of 7347 lines diff --git a/lib-python/conftest.py b/lib-python/conftest.py --- a/lib-python/conftest.py +++ b/lib-python/conftest.py @@ -60,7 +60,7 @@ skip=None): self.basename = basename self._usemodules = usemodules.split() + [ - '_socket', 'binascii', 'rctime', 'select', 'signal'] + '_socket', 'binascii', 'time', 'select', 'signal'] if not sys.platform == 'win32': self._usemodules.extend(['_posixsubprocess', 'fcntl']) self._compiler = compiler diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py --- a/pypy/config/pypyoption.py +++ b/pypy/config/pypyoption.py @@ -30,7 +30,7 @@ # --allworkingmodules working_modules = default_modules.copy() working_modules.update([ - "_socket", "unicodedata", "mmap", "fcntl", "_locale", "pwd", "rctime" , + "_socket", "unicodedata", "mmap", "fcntl", "_locale", "pwd", "time" , "select", "zipimport", "_lsprof", "crypt", "signal", "_rawffi", "termios", "zlib", "bz2", "struct", "_hashlib", "_md5", "_minimal_curses", "thread", "itertools", "pyexpat", "_ssl", "cpyext", "array", @@ -41,7 +41,7 @@ translation_modules = default_modules.copy() translation_modules.update([ - "fcntl", "rctime", "select", "signal", "_rawffi", "zlib", "struct", + "fcntl", "time", "select", "signal", "_rawffi", "zlib", "struct", "array", "binascii", # the following are needed for pyrepl (and hence for the # interactive prompt/pdb) @@ -66,19 +66,15 @@ default_modules.add("_locale") if sys.platform == "sunos5": - working_modules.remove('mmap') # depend on ctypes, can't get at c-level 'errono' - working_modules.remove('rctime') # depend on ctypes, missing tm_zone/tm_gmtoff - working_modules.remove('signal') # depend on ctypes, can't get at c-level 'errono' working_modules.remove('fcntl') # LOCK_NB not defined working_modules.remove("_minimal_curses") working_modules.remove("termios") - working_modules.remove("_multiprocessing") # depends on rctime if "cppyy" in working_modules: working_modules.remove("cppyy") # depends on ctypes module_dependencies = { - '_multiprocessing': [('objspace.usemodules.rctime', True), + '_multiprocessing': [('objspace.usemodules.time', True), ('objspace.usemodules.thread', True)], 'cpyext': [('objspace.usemodules.array', True)], 'cppyy': [('objspace.usemodules.cpyext', True)], diff --git a/pypy/doc/config/objspace.usemodules.rctime.txt b/pypy/doc/config/objspace.usemodules.rctime.txt deleted file mode 100644 --- a/pypy/doc/config/objspace.usemodules.rctime.txt +++ /dev/null @@ -1,7 +0,0 @@ -Use the 'rctime' module. - -'rctime' is our `rffi`_ based implementation of the builtin 'time' module. -It supersedes the less complete :config:`objspace.usemodules.time`, -at least for C-like targets (the C and LLVM backends). - -.. _`rffi`: ../rffi.html diff --git a/pypy/doc/config/objspace.usemodules.time.txt b/pypy/doc/config/objspace.usemodules.time.txt --- a/pypy/doc/config/objspace.usemodules.time.txt +++ b/pypy/doc/config/objspace.usemodules.time.txt @@ -1,5 +1,1 @@ Use the 'time' module. - -Obsolete; use :config:`objspace.usemodules.rctime` for our up-to-date version -of the application-level 'time' module, at least for C-like targets (the C -and LLVM backends). diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -43,3 +43,11 @@ .. branch nditer-external_loop Implement `external_loop` arguement to numpy's nditer + +.. branch kill-rctime + +Rename pypy/module/rctime to pypy/module/time, since it contains the implementation of the 'time' module. + +.. branch: ssa-flow + +Use SSA form for flow graphs inside build_flow() and part of simplify_graph() diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -500,11 +500,6 @@ if name not in modules: modules.append(name) - # a bit of custom logic: rctime take precedence over time - # XXX this could probably be done as a "requires" in the config - if 'rctime' in modules and 'time' in modules: - modules.remove('time') - self._builtinmodule_list = modules return self._builtinmodule_list diff --git a/pypy/module/_lsprof/test/test_cprofile.py b/pypy/module/_lsprof/test/test_cprofile.py --- a/pypy/module/_lsprof/test/test_cprofile.py +++ b/pypy/module/_lsprof/test/test_cprofile.py @@ -1,6 +1,6 @@ class AppTestCProfile(object): spaceconfig = { - "usemodules": ['_lsprof', 'rctime'], + "usemodules": ['_lsprof', 'time'], } def setup_class(cls): diff --git a/pypy/module/_md5/test/test_md5.py b/pypy/module/_md5/test/test_md5.py --- a/pypy/module/_md5/test/test_md5.py +++ b/pypy/module/_md5/test/test_md5.py @@ -7,7 +7,7 @@ class AppTestMD5(object): spaceconfig = { - 'usemodules': ['_md5', 'binascii', 'rctime', 'struct'], + 'usemodules': ['_md5', 'binascii', 'time', 'struct'], } def setup_class(cls): diff --git a/pypy/module/_multibytecodec/src/cjkcodecs/multibytecodec.h b/pypy/module/_multibytecodec/src/cjkcodecs/multibytecodec.h --- a/pypy/module/_multibytecodec/src/cjkcodecs/multibytecodec.h +++ b/pypy/module/_multibytecodec/src/cjkcodecs/multibytecodec.h @@ -97,24 +97,24 @@ Py_UNICODE *outbuf_start, *outbuf, *outbuf_end; }; -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN struct pypy_cjk_dec_s *pypy_cjk_dec_new(const MultibyteCodec *codec); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_dec_init(struct pypy_cjk_dec_s *d, char *inbuf, Py_ssize_t inlen); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN void pypy_cjk_dec_free(struct pypy_cjk_dec_s *); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_dec_chunk(struct pypy_cjk_dec_s *); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_UNICODE *pypy_cjk_dec_outbuf(struct pypy_cjk_dec_s *); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_dec_outlen(struct pypy_cjk_dec_s *); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_dec_inbuf_remaining(struct pypy_cjk_dec_s *d); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_dec_inbuf_consumed(struct pypy_cjk_dec_s* d); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_dec_replace_on_error(struct pypy_cjk_dec_s* d, Py_UNICODE *, Py_ssize_t, Py_ssize_t); @@ -125,35 +125,35 @@ unsigned char *outbuf_start, *outbuf, *outbuf_end; }; -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN struct pypy_cjk_enc_s *pypy_cjk_enc_new(const MultibyteCodec *codec); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_enc_init(struct pypy_cjk_enc_s *d, Py_UNICODE *inbuf, Py_ssize_t inlen); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN void pypy_cjk_enc_free(struct pypy_cjk_enc_s *); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_enc_chunk(struct pypy_cjk_enc_s *, Py_ssize_t); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_enc_reset(struct pypy_cjk_enc_s *); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN char *pypy_cjk_enc_outbuf(struct pypy_cjk_enc_s *); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_enc_outlen(struct pypy_cjk_enc_s *); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_enc_inbuf_remaining(struct pypy_cjk_enc_s *d); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_enc_inbuf_consumed(struct pypy_cjk_enc_s* d); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN Py_ssize_t pypy_cjk_enc_replace_on_error(struct pypy_cjk_enc_s* d, char *, Py_ssize_t, Py_ssize_t); -RPY_EXPORTED_FOR_TESTS +RPY_EXTERN const MultibyteCodec *pypy_cjk_enc_getcodec(struct pypy_cjk_enc_s *); /* list of codecs defined in the .c files */ #define DEFINE_CODEC(name) \ - RPY_EXPORTED_FOR_TESTS MultibyteCodec *pypy_cjkcodec_##name(void); + RPY_EXTERN MultibyteCodec *pypy_cjkcodec_##name(void); // _codecs_cn DEFINE_CODEC(gb2312) diff --git a/pypy/module/_multiprocessing/interp_semaphore.py b/pypy/module/_multiprocessing/interp_semaphore.py --- a/pypy/module/_multiprocessing/interp_semaphore.py +++ b/pypy/module/_multiprocessing/interp_semaphore.py @@ -254,7 +254,7 @@ start = _GetTickCount() while True: - from pypy.module.rctime.interp_time import State + from pypy.module.time.interp_time import State interrupt_event = space.fromcache(State).get_interrupt_event() handles = [self.handle, interrupt_event] diff --git a/pypy/module/_random/test/test_random.py b/pypy/module/_random/test/test_random.py --- a/pypy/module/_random/test/test_random.py +++ b/pypy/module/_random/test/test_random.py @@ -1,6 +1,6 @@ class AppTestRandom: spaceconfig = { - "usemodules": ['_random', 'rctime'], + "usemodules": ['_random', 'time'], } def test_dict(self): diff --git a/pypy/module/_ssl/thread_lock.py b/pypy/module/_ssl/thread_lock.py --- a/pypy/module/_ssl/thread_lock.py +++ b/pypy/module/_ssl/thread_lock.py @@ -65,7 +65,7 @@ eci = rthread.eci.merge(ExternalCompilationInfo( separate_module_sources=[separate_module_source], post_include_bits=[ - "RPY_EXPORTED_FOR_TESTS int _PyPy_SSL_SetupThreads(void);"], + "RPY_EXTERN int _PyPy_SSL_SetupThreads(void);"], libraries = libraries, )) diff --git a/pypy/module/bz2/test/test_bz2_file.py b/pypy/module/bz2/test/test_bz2_file.py --- a/pypy/module/bz2/test/test_bz2_file.py +++ b/pypy/module/bz2/test/test_bz2_file.py @@ -54,7 +54,7 @@ # XXX: CheckAllocation fails on py3 (seems to false positive on # BZ2File's RLocks) spaceconfig = { - 'usemodules': ['bz2', 'binascii', 'rctime', 'struct', 'thread'] + 'usemodules': ['bz2', 'binascii', 'time', 'struct', 'thread'] } def setup_class(cls): diff --git a/pypy/module/cppyy/include/capi.h b/pypy/module/cppyy/include/capi.h --- a/pypy/module/cppyy/include/capi.h +++ b/pypy/module/cppyy/include/capi.h @@ -2,6 +2,7 @@ #define CPPYY_CAPI #include <stddef.h> +#include "src/precommondefs.h" #ifdef __cplusplus extern "C" { @@ -15,102 +16,167 @@ typedef void* (*cppyy_methptrgetter_t)(cppyy_object_t); /* name to opaque C++ scope representation -------------------------------- */ + RPY_EXTERN int cppyy_num_scopes(cppyy_scope_t parent); + RPY_EXTERN char* cppyy_scope_name(cppyy_scope_t parent, int iscope); + RPY_EXTERN char* cppyy_resolve_name(const char* cppitem_name); + RPY_EXTERN cppyy_scope_t cppyy_get_scope(const char* scope_name); + RPY_EXTERN cppyy_type_t cppyy_get_template(const char* template_name); + RPY_EXTERN cppyy_type_t cppyy_actual_class(cppyy_type_t klass, cppyy_object_t obj); /* memory management ------------------------------------------------------ */ + RPY_EXTERN cppyy_object_t cppyy_allocate(cppyy_type_t type); + RPY_EXTERN void cppyy_deallocate(cppyy_type_t type, cppyy_object_t self); + RPY_EXTERN void cppyy_destruct(cppyy_type_t type, cppyy_object_t self); /* method/function dispatching -------------------------------------------- */ + RPY_EXTERN void cppyy_call_v(cppyy_method_t method, cppyy_object_t self, int nargs, void* args); + RPY_EXTERN unsigned char cppyy_call_b(cppyy_method_t method, cppyy_object_t self, int nargs, void* args); + RPY_EXTERN char cppyy_call_c(cppyy_method_t method, cppyy_object_t self, int nargs, void* args); + RPY_EXTERN short cppyy_call_h(cppyy_method_t method, cppyy_object_t self, int nargs, void* args); + RPY_EXTERN int cppyy_call_i(cppyy_method_t method, cppyy_object_t self, int nargs, void* args); + RPY_EXTERN long cppyy_call_l(cppyy_method_t method, cppyy_object_t self, int nargs, void* args); + RPY_EXTERN long long cppyy_call_ll(cppyy_method_t method, cppyy_object_t self, int nargs, void* args); + RPY_EXTERN float cppyy_call_f(cppyy_method_t method, cppyy_object_t self, int nargs, void* args); + RPY_EXTERN double cppyy_call_d(cppyy_method_t method, cppyy_object_t self, int nargs, void* args); + RPY_EXTERN void* cppyy_call_r(cppyy_method_t method, cppyy_object_t self, int nargs, void* args); + RPY_EXTERN char* cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs, void* args); + RPY_EXTERN cppyy_object_t cppyy_constructor(cppyy_method_t method, cppyy_type_t klass, int nargs, void* args); + RPY_EXTERN cppyy_object_t cppyy_call_o(cppyy_method_t method, cppyy_object_t self, int nargs, void* args, cppyy_type_t result_type); + RPY_EXTERN cppyy_methptrgetter_t cppyy_get_methptr_getter(cppyy_scope_t scope, cppyy_index_t idx); /* handling of function argument buffer ----------------------------------- */ + RPY_EXTERN void* cppyy_allocate_function_args(int nargs); + RPY_EXTERN void cppyy_deallocate_function_args(void* args); + RPY_EXTERN size_t cppyy_function_arg_sizeof(); + RPY_EXTERN size_t cppyy_function_arg_typeoffset(); /* scope reflection information ------------------------------------------- */ + RPY_EXTERN int cppyy_is_namespace(cppyy_scope_t scope); + RPY_EXTERN int cppyy_is_enum(const char* type_name); /* class reflection information ------------------------------------------- */ + RPY_EXTERN char* cppyy_final_name(cppyy_type_t type); + RPY_EXTERN char* cppyy_scoped_final_name(cppyy_type_t type); + RPY_EXTERN int cppyy_has_complex_hierarchy(cppyy_type_t type); + RPY_EXTERN int cppyy_num_bases(cppyy_type_t type); + RPY_EXTERN char* cppyy_base_name(cppyy_type_t type, int base_index); + RPY_EXTERN int cppyy_is_subtype(cppyy_type_t derived, cppyy_type_t base); /* calculate offsets between declared and actual type, up-cast: direction > 0; down-cast: direction < 0 */ + RPY_EXTERN ptrdiff_t cppyy_base_offset(cppyy_type_t derived, cppyy_type_t base, cppyy_object_t address, int direction); /* method/function reflection information --------------------------------- */ + RPY_EXTERN int cppyy_num_methods(cppyy_scope_t scope); + RPY_EXTERN cppyy_index_t cppyy_method_index_at(cppyy_scope_t scope, int imeth); + RPY_EXTERN cppyy_index_t* cppyy_method_indices_from_name(cppyy_scope_t scope, const char* name); + RPY_EXTERN char* cppyy_method_name(cppyy_scope_t scope, cppyy_index_t idx); + RPY_EXTERN char* cppyy_method_result_type(cppyy_scope_t scope, cppyy_index_t idx); + RPY_EXTERN int cppyy_method_num_args(cppyy_scope_t scope, cppyy_index_t idx); + RPY_EXTERN int cppyy_method_req_args(cppyy_scope_t scope, cppyy_index_t idx); + RPY_EXTERN char* cppyy_method_arg_type(cppyy_scope_t scope, cppyy_index_t idx, int arg_index); + RPY_EXTERN char* cppyy_method_arg_default(cppyy_scope_t scope, cppyy_index_t idx, int arg_index); + RPY_EXTERN char* cppyy_method_signature(cppyy_scope_t scope, cppyy_index_t idx); + RPY_EXTERN int cppyy_method_is_template(cppyy_scope_t scope, cppyy_index_t idx); + RPY_EXTERN int cppyy_method_num_template_args(cppyy_scope_t scope, cppyy_index_t idx); + RPY_EXTERN char* cppyy_method_template_arg_name(cppyy_scope_t scope, cppyy_index_t idx, cppyy_index_t iarg); + RPY_EXTERN cppyy_method_t cppyy_get_method(cppyy_scope_t scope, cppyy_index_t idx); + RPY_EXTERN cppyy_index_t cppyy_get_global_operator( cppyy_scope_t scope, cppyy_scope_t lc, cppyy_scope_t rc, const char* op); /* method properties ------------------------------------------------------ */ + RPY_EXTERN int cppyy_is_constructor(cppyy_type_t type, cppyy_index_t idx); + RPY_EXTERN int cppyy_is_staticmethod(cppyy_type_t type, cppyy_index_t idx); /* data member reflection information ------------------------------------- */ + RPY_EXTERN int cppyy_num_datamembers(cppyy_scope_t scope); + RPY_EXTERN char* cppyy_datamember_name(cppyy_scope_t scope, int datamember_index); + RPY_EXTERN char* cppyy_datamember_type(cppyy_scope_t scope, int datamember_index); + RPY_EXTERN ptrdiff_t cppyy_datamember_offset(cppyy_scope_t scope, int datamember_index); + RPY_EXTERN int cppyy_datamember_index(cppyy_scope_t scope, const char* name); /* data member properties ------------------------------------------------- */ + RPY_EXTERN int cppyy_is_publicdata(cppyy_type_t type, int datamember_index); + RPY_EXTERN int cppyy_is_staticdata(cppyy_type_t type, int datamember_index); /* misc helpers ----------------------------------------------------------- */ + RPY_EXTERN long long cppyy_strtoll(const char* str); + RPY_EXTERN unsigned long long cppyy_strtoull(const char* str); + RPY_EXTERN void cppyy_free(void* ptr); + RPY_EXTERN cppyy_object_t cppyy_charp2stdstring(const char* str); + RPY_EXTERN cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr); #ifdef __cplusplus diff --git a/pypy/module/cppyy/src/dummy_backend.cxx b/pypy/module/cppyy/src/dummy_backend.cxx --- a/pypy/module/cppyy/src/dummy_backend.cxx +++ b/pypy/module/cppyy/src/dummy_backend.cxx @@ -1,4 +1,3 @@ -#include "src/precommondefs.h" #include "cppyy.h" #include "capi.h" @@ -349,29 +348,24 @@ /* name to opaque C++ scope representation -------------------------------- */ -RPY_EXPORTED_FOR_TESTS int cppyy_num_scopes(cppyy_scope_t handle) { return 0; } -RPY_EXPORTED_FOR_TESTS char* cppyy_resolve_name(const char* cppitem_name) { return cppstring_to_cstring(cppitem_name); } -RPY_EXPORTED_FOR_TESTS cppyy_scope_t cppyy_get_scope(const char* scope_name) { return s_handles[scope_name]; // lookup failure will return 0 (== error) } -RPY_EXPORTED_FOR_TESTS cppyy_type_t cppyy_actual_class(cppyy_type_t klass, cppyy_object_t /* obj */) { return klass; } /* memory management ------------------------------------------------------ */ -RPY_EXPORTED_FOR_TESTS void cppyy_destruct(cppyy_type_t handle, cppyy_object_t self) { if (handle == s_handles["example01"]) delete (dummy::example01*)self; @@ -379,7 +373,6 @@ /* method/function dispatching -------------------------------------------- */ -RPY_EXPORTED_FOR_TESTS void cppyy_call_v(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { long idx = (long)method; if (idx == s_methods["static_example01::staticSetPayload_payload*_double"]) { @@ -469,7 +462,6 @@ } } -RPY_EXPORTED_FOR_TESTS unsigned char cppyy_call_b(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { unsigned char result = 0; const long idx = (long)method; @@ -482,7 +474,6 @@ return result; } -RPY_EXPORTED_FOR_TESTS char cppyy_call_c(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { char result = 0; const long idx = (long)method; @@ -498,7 +489,6 @@ return result; } -RPY_EXPORTED_FOR_TESTS short cppyy_call_h(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { short result = 0; const long idx = (long)method; @@ -514,7 +504,6 @@ return result; } -RPY_EXPORTED_FOR_TESTS int cppyy_call_i(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { int result = 0; const long idx = (long)method; @@ -547,7 +536,6 @@ return result; } -RPY_EXPORTED_FOR_TESTS long cppyy_call_l(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { long result = 0; const long idx = (long)method; @@ -689,7 +677,6 @@ return result; } -RPY_EXPORTED_FOR_TESTS long long cppyy_call_ll(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { long long result = 0; const long idx = (long)method; @@ -705,7 +692,6 @@ return result; } -RPY_EXPORTED_FOR_TESTS float cppyy_call_f(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { float result = 0; const long idx = (long)method; @@ -718,7 +704,6 @@ return result; } -RPY_EXPORTED_FOR_TESTS double cppyy_call_d(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { double result = 0.; const long idx = (long)method; @@ -740,7 +725,6 @@ return result; } -RPY_EXPORTED_FOR_TESTS char* cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) { char* result = 0; const long idx = (long)method; @@ -753,7 +737,6 @@ return result; } -RPY_EXPORTED_FOR_TESTS cppyy_object_t cppyy_constructor(cppyy_method_t method, cppyy_type_t handle, int nargs, void* args) { void* result = 0; const long idx = (long)method; @@ -776,14 +759,12 @@ return (cppyy_object_t)result; } -RPY_EXPORTED_FOR_TESTS cppyy_methptrgetter_t cppyy_get_methptr_getter(cppyy_type_t /* handle */, cppyy_index_t /* method_index */) { return (cppyy_methptrgetter_t)0; } /* handling of function argument buffer ----------------------------------- */ -RPY_EXPORTED_FOR_TESTS void* cppyy_allocate_function_args(int nargs) { CPPYY_G__value* args = (CPPYY_G__value*)malloc(nargs*sizeof(CPPYY_G__value)); for (int i = 0; i < nargs; ++i) @@ -793,36 +774,30 @@ /* handling of function argument buffer ----------------------------------- */ -RPY_EXPORTED_FOR_TESTS void cppyy_deallocate_function_args(void* args) { free(args); } -RPY_EXPORTED_FOR_TESTS size_t cppyy_function_arg_sizeof() { return sizeof(CPPYY_G__value); } -RPY_EXPORTED_FOR_TESTS size_t cppyy_function_arg_typeoffset() { return offsetof(CPPYY_G__value, type); } /* scope reflection information ------------------------------------------- */ -RPY_EXPORTED_FOR_TESTS int cppyy_is_namespace(cppyy_scope_t /* handle */) { return 0; } -RPY_EXPORTED_FOR_TESTS int cppyy_is_enum(const char* /* type_name */) { return 0; } /* class reflection information ------------------------------------------- */ -RPY_EXPORTED_FOR_TESTS char* cppyy_final_name(cppyy_type_t handle) { for (Handles_t::iterator isp = s_handles.begin(); isp != s_handles.end(); ++isp) { if (isp->second == handle) @@ -831,75 +806,61 @@ return cppstring_to_cstring("<unknown>"); } -RPY_EXPORTED_FOR_TESTS char* cppyy_scoped_final_name(cppyy_type_t handle) { return cppyy_final_name(handle); } -RPY_EXPORTED_FOR_TESTS int cppyy_has_complex_hierarchy(cppyy_type_t /* handle */) { return 0; } -RPY_EXPORTED_FOR_TESTS int cppyy_num_bases(cppyy_type_t /*handle*/) { return 0; } /* method/function reflection information --------------------------------- */ -RPY_EXPORTED_FOR_TESTS int cppyy_num_methods(cppyy_scope_t handle) { return s_scopes[handle].m_methods.size(); } -RPY_EXPORTED_FOR_TESTS cppyy_index_t cppyy_method_index_at(cppyy_scope_t /* scope */, int imeth) { return (cppyy_index_t)imeth; } -RPY_EXPORTED_FOR_TESTS char* cppyy_method_name(cppyy_scope_t handle, cppyy_index_t method_index) { return cppstring_to_cstring(s_scopes[handle].m_methods[(int)method_index].m_name); } -RPY_EXPORTED_FOR_TESTS char* cppyy_method_result_type(cppyy_scope_t handle, cppyy_index_t method_index) { return cppstring_to_cstring(s_scopes[handle].m_methods[method_index].m_returntype); } -RPY_EXPORTED_FOR_TESTS int cppyy_method_num_args(cppyy_scope_t handle, cppyy_index_t method_index) { return s_scopes[handle].m_methods[method_index].m_argtypes.size(); } -RPY_EXPORTED_FOR_TESTS int cppyy_method_req_args(cppyy_scope_t handle, cppyy_index_t method_index) { return cppyy_method_num_args(handle, method_index); } -RPY_EXPORTED_FOR_TESTS char* cppyy_method_arg_type(cppyy_scope_t handle, cppyy_index_t method_index, int arg_index) { return cppstring_to_cstring(s_scopes[handle].m_methods[method_index].m_argtypes[arg_index]); } -RPY_EXPORTED_FOR_TESTS char* cppyy_method_arg_default( cppyy_scope_t /* handle */, cppyy_index_t /* method_index */, int /* arg_index */) { return cppstring_to_cstring(""); } -RPY_EXPORTED_FOR_TESTS char* cppyy_method_signature(cppyy_scope_t /* handle */, cppyy_index_t /* method_index */) { return cppstring_to_cstring(""); } -RPY_EXPORTED_FOR_TESTS int cppyy_method_is_template(cppyy_scope_t /* handle */, cppyy_index_t /* method_index */) { return 0; } -RPY_EXPORTED_FOR_TESTS cppyy_method_t cppyy_get_method(cppyy_scope_t handle, cppyy_index_t method_index) { if (s_scopes.find(handle) != s_scopes.end()) { long id = s_scopes[handle].m_method_offset + (long)method_index; @@ -911,7 +872,6 @@ /* method properties ----------------------------------------------------- */ -RPY_EXPORTED_FOR_TESTS int cppyy_is_constructor(cppyy_type_t handle, cppyy_index_t method_index) { if (s_scopes.find(handle) != s_scopes.end()) return s_scopes[handle].m_methods[method_index].m_type == kConstructor; @@ -919,7 +879,6 @@ return 0; } -RPY_EXPORTED_FOR_TESTS int cppyy_is_staticmethod(cppyy_type_t handle, cppyy_index_t method_index) { if (s_scopes.find(handle) != s_scopes.end()) return s_scopes[handle].m_methods[method_index].m_type == kStatic; @@ -929,34 +888,28 @@ /* data member reflection information ------------------------------------- */ -RPY_EXPORTED_FOR_TESTS int cppyy_num_datamembers(cppyy_scope_t handle) { return s_scopes[handle].m_datambrs.size(); } -RPY_EXPORTED_FOR_TESTS char* cppyy_datamember_name(cppyy_scope_t handle, int idatambr) { return cppstring_to_cstring(s_scopes[handle].m_datambrs[idatambr].m_name); } -RPY_EXPORTED_FOR_TESTS char* cppyy_datamember_type(cppyy_scope_t handle, int idatambr) { return cppstring_to_cstring(s_scopes[handle].m_datambrs[idatambr].m_type); } -RPY_EXPORTED_FOR_TESTS ptrdiff_t cppyy_datamember_offset(cppyy_scope_t handle, int idatambr) { return s_scopes[handle].m_datambrs[idatambr].m_offset; } /* data member properties ------------------------------------------------ */ -RPY_EXPORTED_FOR_TESTS int cppyy_is_publicdata(cppyy_scope_t handle, int idatambr) { return 1; } -RPY_EXPORTED_FOR_TESTS int cppyy_is_staticdata(cppyy_scope_t handle, int idatambr) { return s_scopes[handle].m_datambrs[idatambr].m_isstatic; } @@ -964,44 +917,37 @@ /* misc helpers ----------------------------------------------------------- */ #if defined(_MSC_VER) -RPY_EXPORTED_FOR_TESTS long long cppyy_strtoll(const char* str) { return _strtoi64(str, NULL, 0); } extern "C" { -RPY_EXPORTED_FOR_TESTS unsigned long long cppyy_strtoull(const char* str) { return _strtoui64(str, NULL, 0); } } #else -RPY_EXPORTED_FOR_TESTS long long cppyy_strtoll(const char* str) { return strtoll(str, NULL, 0); } extern "C" { -RPY_EXPORTED_FOR_TESTS unsigned long long cppyy_strtoull(const char* str) { return strtoull(str, NULL, 0); } } #endif -RPY_EXPORTED_FOR_TESTS void cppyy_free(void* ptr) { free(ptr); } -RPY_EXPORTED_FOR_TESTS cppyy_object_t cppyy_charp2stdstring(const char* str) { void* arena = new char[sizeof(std::string)]; new (arena) std::string(str); return (cppyy_object_t)arena; } -RPY_EXPORTED_FOR_TESTS cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr) { void* arena = new char[sizeof(std::string)]; new (arena) std::string(*(std::string*)ptr); diff --git a/pypy/module/cppyy/test/conftest.py b/pypy/module/cppyy/test/conftest.py --- a/pypy/module/cppyy/test/conftest.py +++ b/pypy/module/cppyy/test/conftest.py @@ -50,7 +50,7 @@ eci = ExternalCompilationInfo( separate_module_files=[srcpath.join('dummy_backend.cxx')], include_dirs=[incpath, tstpath, cdir], - compile_extra=['-DRPY_EXPORTED_FOR_TESTS=RPY_EXPORTED'], + compile_extra=['-DRPY_EXTERN=RPY_EXPORTED'], use_cpp_linker=True, ) diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -775,8 +775,7 @@ struct PyPyAPI { %(members)s } _pypyAPI; - RPY_EXPORTED_FOR_TESTS - struct PyPyAPI* pypyAPI = &_pypyAPI; + RPY_EXTERN struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) functions = generate_decls_and_callbacks(db, export_symbols) @@ -947,7 +946,7 @@ name_no_star = process_va_name(name) header = ('%s pypy_va_get_%s(va_list* vp)' % (name, name_no_star)) - pypy_decls.append('RPY_EXPORTED_FOR_TESTS ' + header + ';') + pypy_decls.append('RPY_EXTERN ' + header + ';') functions.append(header + '\n{return va_arg(*vp, %s);}\n' % name) for name, (typ, expr) in GLOBALS.iteritems(): @@ -1007,7 +1006,7 @@ if sys.platform == 'win32': get_pythonapi_source = ''' #include <windows.h> - RPY_EXPORTED_FOR_TESTS + RPY_EXTERN HANDLE pypy_get_pythonapi_handle() { MEMORY_BASIC_INFORMATION mi; memset(&mi, 0, sizeof(mi)); diff --git a/pypy/module/cpyext/include/modsupport.h b/pypy/module/cpyext/include/modsupport.h --- a/pypy/module/cpyext/include/modsupport.h +++ b/pypy/module/cpyext/include/modsupport.h @@ -82,11 +82,20 @@ /* * This is from pyport.h. Perhaps it belongs elsewhere. */ +#ifdef _WIN32 +/* explicitly export since PyAPI_FUNC is usually dllimport */ +#ifdef __cplusplus +#define PyMODINIT_FUNC extern "C" __declspec(dllexport) void +#else +#define PyMODINIT_FUNC __declspec(dllexport) void +#endif +#else #ifdef __cplusplus #define PyMODINIT_FUNC extern "C" PyAPI_FUNC(PyObject *) #else #define PyMODINIT_FUNC PyAPI_FUNC(PyObject *) #endif +#endif /* WIN32 */ PyAPI_DATA(char *) _Py_PackageContext; diff --git a/pypy/module/cpyext/test/conftest.py b/pypy/module/cpyext/test/conftest.py --- a/pypy/module/cpyext/test/conftest.py +++ b/pypy/module/cpyext/test/conftest.py @@ -7,7 +7,7 @@ # it's necessary to run "import time" at least once before any # other cpyext test, otherwise the same statement will fail in # test_datetime.py. - space = gettestobjspace(usemodules=['rctime']) + space = gettestobjspace(usemodules=['time']) space.getbuiltinmodule("time") def pytest_ignore_collect(path, config): diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py --- a/pypy/module/cpyext/test/test_cpyext.py +++ b/pypy/module/cpyext/test/test_cpyext.py @@ -102,7 +102,7 @@ class LeakCheckingTest(object): """Base class for all cpyext tests.""" spaceconfig = dict(usemodules=['cpyext', 'thread', '_rawffi', 'array', - 'itertools', 'rctime', 'binascii', 'micronumpy']) + 'itertools', 'time', 'binascii', 'micronumpy']) spaceconfig['std.withmethodcache'] = True enable_leak_checking = True diff --git a/pypy/module/fcntl/test/test_fcntl.py b/pypy/module/fcntl/test/test_fcntl.py --- a/pypy/module/fcntl/test/test_fcntl.py +++ b/pypy/module/fcntl/test/test_fcntl.py @@ -12,7 +12,7 @@ class AppTestFcntl: spaceconfig = dict(usemodules=('fcntl', 'array', 'struct', 'termios', - 'select', 'rctime')) + 'select', 'time')) def setup_class(cls): tmpprefix = str(udir.ensure('test_fcntl', dir=1).join('tmp_')) diff --git a/pypy/module/imp/test/test_app.py b/pypy/module/imp/test/test_app.py --- a/pypy/module/imp/test/test_app.py +++ b/pypy/module/imp/test/test_app.py @@ -4,7 +4,7 @@ class AppTestImpModule: spaceconfig = { - 'usemodules': ['binascii', 'imp', 'itertools', 'rctime', 'struct'], + 'usemodules': ['binascii', 'imp', 'itertools', 'time', 'struct'], } def setup_class(cls): diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py --- a/pypy/module/imp/test/test_import.py +++ b/pypy/module/imp/test/test_import.py @@ -194,7 +194,7 @@ class AppTestImport(BaseImportTest): spaceconfig = { - "usemodules": ['rctime'], + "usemodules": ['time'], } def setup_class(cls): @@ -1199,7 +1199,7 @@ class AppTestImportHooks(object): spaceconfig = { - "usemodules": ['struct', 'itertools', 'rctime'], + "usemodules": ['struct', 'itertools', 'time'], } def setup_class(cls): @@ -1446,7 +1446,7 @@ class AppTestMultithreadedImp(object): - spaceconfig = dict(usemodules=['thread', 'rctime']) + spaceconfig = dict(usemodules=['thread', 'time']) def setup_class(cls): #if not conftest.option.runappdirect: diff --git a/pypy/module/math/test/test_math.py b/pypy/module/math/test/test_math.py --- a/pypy/module/math/test/test_math.py +++ b/pypy/module/math/test/test_math.py @@ -7,7 +7,7 @@ class AppTestMath: spaceconfig = { - "usemodules": ['math', 'struct', 'itertools', 'rctime', 'binascii'], + "usemodules": ['math', 'struct', 'itertools', 'time', 'binascii'], } def setup_class(cls): diff --git a/pypy/module/micronumpy/nditer.py b/pypy/module/micronumpy/nditer.py --- a/pypy/module/micronumpy/nditer.py +++ b/pypy/module/micronumpy/nditer.py @@ -89,10 +89,9 @@ for w_item in lst: if not space.isinstance_w(w_item, space.w_str) and not \ space.isinstance_w(w_item, space.w_unicode): - typename = space.type(w_item).getname(space) raise oefmt(space.w_TypeError, - 'expected string or Unicode object, %s found', - typename) + "expected string or Unicode object, %T found", + w_item) item = space.str_w(w_item) if item == 'external_loop': nditer.external_loop = True diff --git a/pypy/module/mmap/interp_mmap.py b/pypy/module/mmap/interp_mmap.py --- a/pypy/module/mmap/interp_mmap.py +++ b/pypy/module/mmap/interp_mmap.py @@ -5,6 +5,7 @@ from rpython.rlib import rmmap, rarithmetic from rpython.rlib.buffer import Buffer from rpython.rlib.rmmap import RValueError, RTypeError, RMMapError +from rpython.rlib.rstring import StringBuilder if rmmap.HAVE_LARGEFILE_SUPPORT: OFF_T = rarithmetic.r_longlong @@ -171,17 +172,18 @@ self.check_valid() space = self.space - start, stop, step = space.decode_index(w_index, self.mmap.size) + start, stop, step, length = space.decode_index4(w_index, self.mmap.size) if step == 0: # index only return space.wrap(ord(self.mmap.getitem(start))) elif step == 1: if stop - start < 0: return space.wrapbytes("") - return space.wrapbytes(self.mmap.getslice(start, stop - start)) + return space.wrapbytes(self.mmap.getslice(start, length)) else: - res = "".join([self.mmap.getitem(i) - for i in range(start, stop, step)]) - return space.wrapbytes(res) + b = StringBuilder(length) + for i in range(start, stop, step): + b.append(self.mmap.getitem(i)) + return space.wrapbytes(b.build()) def descr_setitem(self, w_index, w_value): space = self.space diff --git a/pypy/module/operator/tscmp.h b/pypy/module/operator/tscmp.h --- a/pypy/module/operator/tscmp.h +++ b/pypy/module/operator/tscmp.h @@ -1,1 +1,1 @@ -RPY_EXPORTED_FOR_TESTS int pypy_tscmp(const char *, const char *, long, long); +RPY_EXTERN int pypy_tscmp(const char *, const char *, long, long); diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py --- a/pypy/module/posix/test/test_posix2.py +++ b/pypy/module/posix/test/test_posix2.py @@ -14,7 +14,7 @@ import signal def setup_module(mod): - usemodules = ['binascii', 'posix', 'signal', 'struct', 'rctime'] + usemodules = ['binascii', 'posix', 'signal', 'struct', 'time'] # py3k os.open uses subprocess, requiring the following per platform if os.name != 'nt': usemodules += ['fcntl', 'select'] diff --git a/pypy/module/pyexpat/test/test_parser.py b/pypy/module/pyexpat/test/test_parser.py --- a/pypy/module/pyexpat/test/test_parser.py +++ b/pypy/module/pyexpat/test/test_parser.py @@ -200,7 +200,7 @@ class AppTestPyexpat2: spaceconfig = dict(usemodules=['_rawffi', 'pyexpat', 'itertools', - '_socket', 'rctime', 'struct', 'binascii']) + '_socket', 'time', 'struct', 'binascii']) def test_django_bug(self): xml_str = '<?xml version="1.0" standalone="no"?><!DOCTYPE example SYSTEM "http://example.com/example.dtd"><root/>' diff --git a/pypy/module/pypyjit/test/test_policy.py b/pypy/module/pypyjit/test/test_policy.py --- a/pypy/module/pypyjit/test/test_policy.py +++ b/pypy/module/pypyjit/test/test_policy.py @@ -29,7 +29,7 @@ assert pypypolicy.look_inside_function(get_ident) def test_time(): - from pypy.module.rctime.interp_time import time + from pypy.module.time.interp_time import time assert pypypolicy.look_inside_function(time) def test_io(): diff --git a/pypy/module/rctime/__init__.py b/pypy/module/rctime/__init__.py deleted file mode 100644 --- a/pypy/module/rctime/__init__.py +++ /dev/null @@ -1,42 +0,0 @@ - -from pypy.interpreter.mixedmodule import MixedModule -import os - -_WIN = os.name == "nt" - -class Module(MixedModule): - applevel_name = 'time' - - interpleveldefs = { - 'time': 'interp_time.time', - 'clock': 'interp_time.clock', - 'ctime': 'interp_time.ctime', - 'asctime': 'interp_time.asctime', - 'gmtime': 'interp_time.gmtime', - 'localtime': 'interp_time.localtime', - 'mktime': 'interp_time.mktime', - 'strftime': 'interp_time.strftime', - 'sleep' : 'interp_time.sleep', - } - - if os.name == "posix": - interpleveldefs['tzset'] = 'interp_time.tzset' - - appleveldefs = { - 'struct_time': 'app_time.struct_time', - '__doc__': 'app_time.__doc__', - 'strptime': 'app_time.strptime', - } - - def startup(self, space): - if _WIN: - from pypy.module.rctime.interp_time import State - space.fromcache(State).startup(space) - - # this machinery is needed to expose constants - # that have to be initialized one time only - from pypy.module.rctime import interp_time - - interp_time._init_timezone(space) - interp_time._init_accept2dyear(space) - diff --git a/pypy/module/rctime/interp_time.py b/pypy/module/rctime/interp_time.py deleted file mode 100644 --- a/pypy/module/rctime/interp_time.py +++ /dev/null @@ -1,687 +0,0 @@ -from rpython.rtyper.tool import rffi_platform as platform -from rpython.rtyper.lltypesystem import rffi -from pypy.interpreter.error import OperationError, oefmt -from pypy.interpreter.gateway import unwrap_spec -from rpython.rtyper.lltypesystem import lltype -from rpython.rlib.rarithmetic import intmask -from rpython.rlib import rposix -from rpython.translator.tool.cbuild import ExternalCompilationInfo -import os -import sys -import time as pytime - -_POSIX = os.name == "posix" -_WIN = os.name == "nt" -_CYGWIN = sys.platform == "cygwin" - -_time_zones = [] -if _CYGWIN: - _time_zones = ["GMT-12", "GMT-11", "GMT-10", "GMT-9", "GMT-8", "GMT-7", - "GMT-6", "GMT-5", "GMT-4", "GMT-3", "GMT-2", "GMT-1", - "GMT", "GMT+1", "GMT+2", "GMT+3", "GMT+4", "GMT+5", - "GMT+6", "GMT+7", "GMT+8", "GMT+9", "GMT+10", "GMT+11", - "GMT+12", "GMT+13", "GMT+14"] - -if _WIN: - # Interruptible sleeps on Windows: - # We install a specific Console Ctrl Handler which sets an 'event'. - # time.sleep() will actually call WaitForSingleObject with the desired - # timeout. On Ctrl-C, the signal handler is called, the event is set, - # and the wait function exits. - from rpython.rlib import rwin32 - from pypy.interpreter.error import wrap_windowserror, wrap_oserror - from rpython.rlib import rthread as thread - - eci = ExternalCompilationInfo( - includes = ['windows.h'], - post_include_bits = [ - "RPY_EXPORTED_FOR_TESTS\n" - "BOOL pypy_timemodule_setCtrlHandler(HANDLE event);"], - separate_module_sources=[''' - static HANDLE interrupt_event; - - static BOOL WINAPI CtrlHandlerRoutine( - DWORD dwCtrlType) - { - SetEvent(interrupt_event); - /* allow other default handlers to be called. - * Default Python handler will setup the - * KeyboardInterrupt exception. - */ - return 0; - } - - BOOL pypy_timemodule_setCtrlHandler(HANDLE event) - { - interrupt_event = event; - return SetConsoleCtrlHandler(CtrlHandlerRoutine, TRUE); - } - - '''], - ) - _setCtrlHandlerRoutine = rffi.llexternal( - 'pypy_timemodule_setCtrlHandler', - [rwin32.HANDLE], rwin32.BOOL, - compilation_info=eci) - - class GlobalState: - def __init__(self): - self.init() - - def init(self): - self.interrupt_event = rwin32.NULL_HANDLE - - def startup(self, space): - # Initialize the event handle used to signal Ctrl-C - try: - globalState.interrupt_event = rwin32.CreateEvent( - rffi.NULL, True, False, rffi.NULL) - except WindowsError, e: - raise wrap_windowserror(space, e) - if not _setCtrlHandlerRoutine(globalState.interrupt_event): - raise wrap_windowserror( - space, rwin32.lastWindowsError("SetConsoleCtrlHandler")) - - globalState = GlobalState() - - class State: - def __init__(self, space): - self.main_thread = 0 - - def _cleanup_(self): - self.main_thread = 0 - globalState.init() - - def startup(self, space): - self.main_thread = thread.get_ident() - globalState.startup(space) - - def get_interrupt_event(self): - return globalState.interrupt_event - - -_includes = ["time.h"] -if _POSIX: - _includes.append('sys/time.h') - -class CConfig: - _compilation_info_ = ExternalCompilationInfo( - includes = _includes - ) - CLOCKS_PER_SEC = platform.ConstantInteger("CLOCKS_PER_SEC") - clock_t = platform.SimpleType("clock_t", rffi.ULONG) - has_gettimeofday = platform.Has('gettimeofday') - -if _POSIX: - calling_conv = 'c' - CConfig.timeval = platform.Struct("struct timeval", - [("tv_sec", rffi.INT), - ("tv_usec", rffi.INT)]) - if _CYGWIN: - CConfig.tm = platform.Struct("struct tm", [("tm_sec", rffi.INT), - ("tm_min", rffi.INT), ("tm_hour", rffi.INT), ("tm_mday", rffi.INT), - ("tm_mon", rffi.INT), ("tm_year", rffi.INT), ("tm_wday", rffi.INT), - ("tm_yday", rffi.INT), ("tm_isdst", rffi.INT)]) - else: - CConfig.tm = platform.Struct("struct tm", [("tm_sec", rffi.INT), - ("tm_min", rffi.INT), ("tm_hour", rffi.INT), ("tm_mday", rffi.INT), - ("tm_mon", rffi.INT), ("tm_year", rffi.INT), ("tm_wday", rffi.INT), - ("tm_yday", rffi.INT), ("tm_isdst", rffi.INT), ("tm_gmtoff", rffi.LONG), - ("tm_zone", rffi.CCHARP)]) -elif _WIN: - calling_conv = 'win' - CConfig.tm = platform.Struct("struct tm", [("tm_sec", rffi.INT), - ("tm_min", rffi.INT), ("tm_hour", rffi.INT), ("tm_mday", rffi.INT), - ("tm_mon", rffi.INT), ("tm_year", rffi.INT), ("tm_wday", rffi.INT), - ("tm_yday", rffi.INT), ("tm_isdst", rffi.INT)]) - -class cConfig: - pass - -for k, v in platform.configure(CConfig).items(): - setattr(cConfig, k, v) -cConfig.tm.__name__ = "_tm" - -def external(name, args, result, eci=CConfig._compilation_info_): - if _WIN and rffi.sizeof(rffi.TIME_T) == 8: - # Recent Microsoft compilers use 64bit time_t and - # the corresponding functions are named differently - if (rffi.TIME_T in args or rffi.TIME_TP in args - or result in (rffi.TIME_T, rffi.TIME_TP)): - name = '_' + name + '64' - return rffi.llexternal(name, args, result, - compilation_info=eci, - calling_conv=calling_conv, - releasegil=False) - -if _POSIX: - cConfig.timeval.__name__ = "_timeval" - timeval = cConfig.timeval - -CLOCKS_PER_SEC = cConfig.CLOCKS_PER_SEC -clock_t = cConfig.clock_t -tm = cConfig.tm -glob_buf = lltype.malloc(tm, flavor='raw', zero=True, immortal=True) - -if cConfig.has_gettimeofday: - c_gettimeofday = external('gettimeofday', [rffi.VOIDP, rffi.VOIDP], rffi.INT) -TM_P = lltype.Ptr(tm) -c_clock = external('clock', [rffi.TIME_TP], clock_t) -c_time = external('time', [rffi.TIME_TP], rffi.TIME_T) -c_gmtime = external('gmtime', [rffi.TIME_TP], TM_P) -c_mktime = external('mktime', [TM_P], rffi.TIME_T) -c_localtime = external('localtime', [rffi.TIME_TP], TM_P) -if _POSIX: - c_tzset = external('tzset', [], lltype.Void) -if _WIN: - win_eci = ExternalCompilationInfo( - includes = ["time.h"], - post_include_bits = ["RPY_EXPORTED_FOR_TESTS\n" - "long pypy_get_timezone();\n" - "RPY_EXPORTED_FOR_TESTS\n" - "int pypy_get_daylight();\n" - "RPY_EXPORTED_FOR_TESTS\n" - "char** pypy_get_tzname();\n" - "RPY_EXPORTED_FOR_TESTS\n" - "void* pypy__tzset();"], - separate_module_sources = [""" - long pypy_get_timezone() { return timezone; } - int pypy_get_daylight() { return daylight; } - char** pypy_get_tzname() { return tzname; } - void pypy__tzset() { return _tzset(); } - """]) - # Ensure sure that we use _tzset() and timezone from the same C Runtime. - c_tzset = external('pypy__tzset', [], lltype.Void, win_eci) - c_get_timezone = external('pypy_get_timezone', [], rffi.LONG, win_eci) - c_get_daylight = external('pypy_get_daylight', [], rffi.INT, win_eci) - c_get_tzname = external('pypy_get_tzname', [], rffi.CCHARPP, win_eci) - -c_strftime = external('strftime', [rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, TM_P], - rffi.SIZE_T) - -def _init_accept2dyear(space): - if os.environ.get("PYTHONY2K"): - accept2dyear = 0 - else: - accept2dyear = 1 - _set_module_object(space, "accept2dyear", space.wrap(accept2dyear)) - -def _init_timezone(space): - timezone = daylight = altzone = 0 - tzname = ["", ""] - - if _WIN: - c_tzset() - timezone = c_get_timezone() - altzone = timezone - 3600 - daylight = c_get_daylight() - tzname_ptr = c_get_tzname() - tzname = rffi.charp2str(tzname_ptr[0]), rffi.charp2str(tzname_ptr[1]) - - if _POSIX: - if _CYGWIN: - YEAR = (365 * 24 + 6) * 3600 - - # about January 11th - t = (((c_time(lltype.nullptr(rffi.TIME_TP.TO))) / YEAR) * YEAR + 10 * 24 * 3600) - # we cannot have reference to stack variable, put it on the heap - t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw') - t_ref[0] = rffi.cast(rffi.TIME_T, t) - p = c_localtime(t_ref) - q = c_gmtime(t_ref) - janzone = (p.c_tm_hour + 24 * p.c_tm_mday) - (q.c_tm_hour + 24 * q.c_tm_mday) - if janzone < -12: - janname = " " - elif janzone > 14: - janname = " " - else: - janname = _time_zones[janzone - 12] - janzone = janzone * 3600 - # about July 11th - tt = t + YEAR / 2 - t_ref[0] = rffi.cast(rffi.TIME_T, tt) - p = c_localtime(t_ref) - q = c_gmtime(t_ref) - julyzone = (p.c_tm_hour + 24 * p.c_tm_mday) - (q.c_tm_hour + 24 * q.c_tm_mday) - if julyzone < -12: - julyname = " " - elif julyzone > 14: - julyname = " " - else: - julyname = _time_zones[julyzone - 12] - julyzone = julyzone * 3600 - lltype.free(t_ref, flavor='raw') - - if janzone < julyzone: - # DST is reversed in the southern hemisphere - timezone = julyzone - altzone = janzone - daylight = int(janzone != julyzone) - tzname = [julyname, janname] - else: - timezone = janzone - altzone = julyzone - daylight = int(janzone != julyzone) - tzname = [janname, julyname] - - else: - YEAR = (365 * 24 + 6) * 3600 - - t = (((c_time(lltype.nullptr(rffi.TIME_TP.TO))) / YEAR) * YEAR) - # we cannot have reference to stack variable, put it on the heap - t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw') - t_ref[0] = rffi.cast(rffi.TIME_T, t) - p = c_localtime(t_ref) - janzone = -p.c_tm_gmtoff - tm_zone = rffi.charp2str(p.c_tm_zone) - janname = [" ", tm_zone][bool(tm_zone)] - tt = t + YEAR / 2 - t_ref[0] = rffi.cast(rffi.TIME_T, tt) - p = c_localtime(t_ref) - lltype.free(t_ref, flavor='raw') - tm_zone = rffi.charp2str(p.c_tm_zone) - julyzone = -p.c_tm_gmtoff - julyname = [" ", tm_zone][bool(tm_zone)] - - if janzone < julyzone: - # DST is reversed in the southern hemisphere - timezone = julyzone - altzone = janzone - daylight = int(janzone != julyzone) - tzname = [julyname, janname] - else: - timezone = janzone - altzone = julyzone - daylight = int(janzone != julyzone) - tzname = [janname, julyname] - - _set_module_object(space, "timezone", space.wrap(timezone)) - _set_module_object(space, 'daylight', space.wrap(daylight)) - tzname_w = [space.wrap(tzname[0]), space.wrap(tzname[1])] - _set_module_object(space, 'tzname', space.newtuple(tzname_w)) - _set_module_object(space, 'altzone', space.wrap(altzone)) - -def _get_error_msg(): - errno = rposix.get_errno() - return os.strerror(errno) - -if sys.platform != 'win32': - @unwrap_spec(secs=float) - def sleep(space, secs): - if secs < 0: - raise OperationError(space.w_IOError, - space.wrap("Invalid argument: negative time in sleep")) - pytime.sleep(secs) -else: - from rpython.rlib import rwin32 - from errno import EINTR - def _simple_sleep(space, secs, interruptible): - if secs == 0.0 or not interruptible: - pytime.sleep(secs) - else: - millisecs = int(secs * 1000) - interrupt_event = space.fromcache(State).get_interrupt_event() - rwin32.ResetEvent(interrupt_event) - rc = rwin32.WaitForSingleObject(interrupt_event, millisecs) - if rc == rwin32.WAIT_OBJECT_0: - # Yield to make sure real Python signal handler - # called. - pytime.sleep(0.001) - raise wrap_oserror(space, - OSError(EINTR, "sleep() interrupted")) - @unwrap_spec(secs=float) - def sleep(space, secs): - if secs < 0: - raise OperationError(space.w_IOError, - space.wrap("Invalid argument: negative time in sleep")) - # as decreed by Guido, only the main thread can be - # interrupted. - main_thread = space.fromcache(State).main_thread - interruptible = (main_thread == thread.get_ident()) - MAX = sys.maxint / 1000.0 # > 24 days - while secs > MAX: - _simple_sleep(space, MAX, interruptible) - secs -= MAX - _simple_sleep(space, secs, interruptible) - -def _get_module_object(space, obj_name): - w_module = space.getbuiltinmodule('time') - w_obj = space.getattr(w_module, space.wrap(obj_name)) - return w_obj - -def _set_module_object(space, obj_name, w_obj_value): - w_module = space.getbuiltinmodule('time') - space.setattr(w_module, space.wrap(obj_name), w_obj_value) - -def _get_inttime(space, w_seconds): - # w_seconds can be a wrapped None (it will be automatically wrapped - # in the callers, so we never get a real None here). - if space.is_none(w_seconds): - seconds = pytime.time() - else: - seconds = space.float_w(w_seconds) - # - t = rffi.cast(rffi.TIME_T, seconds) - # - # Logic from CPython: How much info did we lose? We assume that - # time_t is an integral type. If we lost a second or more, the - # input doesn't fit in a time_t; call it an error. - diff = seconds - rffi.cast(lltype.Float, t) - if diff <= -1.0 or diff >= 1.0: - raise OperationError(space.w_ValueError, - space.wrap("timestamp out of range for platform time_t")) - return t - -def _tm_to_tuple(space, t): - time_tuple = [ - space.wrap(rffi.getintfield(t, 'c_tm_year') + 1900), - space.wrap(rffi.getintfield(t, 'c_tm_mon') + 1), # want january == 1 - space.wrap(rffi.getintfield(t, 'c_tm_mday')), - space.wrap(rffi.getintfield(t, 'c_tm_hour')), - space.wrap(rffi.getintfield(t, 'c_tm_min')), - space.wrap(rffi.getintfield(t, 'c_tm_sec')), - space.wrap((rffi.getintfield(t, 'c_tm_wday') + 6) % 7), # want monday == 0 - space.wrap(rffi.getintfield(t, 'c_tm_yday') + 1), # want january, 1 == 1 - space.wrap(rffi.getintfield(t, 'c_tm_isdst'))] - - w_struct_time = _get_module_object(space, 'struct_time') - w_time_tuple = space.newtuple(time_tuple) - return space.call_function(w_struct_time, w_time_tuple) - -def _gettmarg(space, w_tup, allowNone=True): - if space.is_none(w_tup): - if not allowNone: - raise OperationError(space.w_TypeError, - space.wrap("tuple expected")) - # default to the current local time - tt = rffi.r_time_t(int(pytime.time())) - t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw') - t_ref[0] = tt - pbuf = c_localtime(t_ref) - lltype.free(t_ref, flavor='raw') - if not pbuf: - raise OperationError(space.w_ValueError, - space.wrap(_get_error_msg())) - return pbuf - - tup_w = space.fixedview(w_tup) - if len(tup_w) != 9: - raise oefmt(space.w_TypeError, - "argument must be sequence of length 9, not %d", - len(tup_w)) - - y = space.c_int_w(tup_w[0]) - tm_mon = space.c_int_w(tup_w[1]) - if tm_mon == 0: - tm_mon = 1 - tm_mday = space.c_int_w(tup_w[2]) - if tm_mday == 0: - tm_mday = 1 - tm_yday = space.c_int_w(tup_w[7]) - if tm_yday == 0: - tm_yday = 1 - rffi.setintfield(glob_buf, 'c_tm_mon', tm_mon) - rffi.setintfield(glob_buf, 'c_tm_mday', tm_mday) - rffi.setintfield(glob_buf, 'c_tm_hour', space.c_int_w(tup_w[3])) - rffi.setintfield(glob_buf, 'c_tm_min', space.c_int_w(tup_w[4])) - rffi.setintfield(glob_buf, 'c_tm_sec', space.c_int_w(tup_w[5])) - rffi.setintfield(glob_buf, 'c_tm_wday', space.c_int_w(tup_w[6])) - rffi.setintfield(glob_buf, 'c_tm_yday', tm_yday) - rffi.setintfield(glob_buf, 'c_tm_isdst', space.c_int_w(tup_w[8])) - if _POSIX: - if _CYGWIN: - pass - else: - # actually never happens, but makes annotator happy - glob_buf.c_tm_zone = lltype.nullptr(rffi.CCHARP.TO) - rffi.setintfield(glob_buf, 'c_tm_gmtoff', 0) - - if y < 1000: - w_accept2dyear = _get_module_object(space, "accept2dyear") - accept2dyear = space.is_true(w_accept2dyear) - - if accept2dyear: - if 69 <= y <= 99: - y += 1900 - elif 0 <= y <= 68: - y += 2000 - else: - raise OperationError(space.w_ValueError, - space.wrap("year out of range")) - space.warn(space.wrap("Century info guessed for a 2-digit year."), - space.w_DeprecationWarning) - - # tm_wday does not need checking of its upper-bound since taking "% - # 7" in _gettmarg() automatically restricts the range. - if rffi.getintfield(glob_buf, 'c_tm_wday') < -1: - raise OperationError(space.w_ValueError, - space.wrap("day of week out of range")) - - rffi.setintfield(glob_buf, 'c_tm_year', y - 1900) - rffi.setintfield(glob_buf, 'c_tm_mon', - rffi.getintfield(glob_buf, 'c_tm_mon') - 1) - rffi.setintfield(glob_buf, 'c_tm_wday', - (rffi.getintfield(glob_buf, 'c_tm_wday') + 1) % 7) - rffi.setintfield(glob_buf, 'c_tm_yday', - rffi.getintfield(glob_buf, 'c_tm_yday') - 1) - - return glob_buf - -def _checktm(space, t_ref): - """Checks added to make sure strftime() and asctime() do not crash - Python by indexing blindly into some array for a textual - representation by some bad index (fixes bug #897625). No check for - year or wday since handled in _gettmarg().""" - if not 0 <= rffi.getintfield(t_ref, 'c_tm_mon') <= 11: - raise OperationError(space.w_ValueError, - space.wrap("month out of range")) - if not 1 <= rffi.getintfield(t_ref, 'c_tm_mday') <= 31: - raise OperationError(space.w_ValueError, - space.wrap("day of month out of range")) - if not 0 <= rffi.getintfield(t_ref, 'c_tm_hour') <= 23: - raise OperationError(space.w_ValueError, - space.wrap("hour out of range")) - if not 0 <= rffi.getintfield(t_ref, 'c_tm_min') <= 59: - raise OperationError(space.w_ValueError, - space.wrap("minute out of range")) - if not 0 <= rffi.getintfield(t_ref, 'c_tm_sec') <= 61: - raise OperationError(space.w_ValueError, - space.wrap("seconds out of range")) - # tm_wday does not need checking: "% 7" in _gettmarg() automatically - # restricts the range - if not 0 <= rffi.getintfield(t_ref, 'c_tm_yday') <= 365: - raise OperationError(space.w_ValueError, - space.wrap("day of year out of range")) - -def time(space): - """time() -> floating point number - - Return the current time in seconds since the Epoch. - Fractions of a second may be present if the system clock provides them.""" - - secs = pytime.time() - return space.wrap(secs) - -if _WIN: - class PCCache: - pass - pccache = PCCache() - pccache.divisor = 0.0 - pccache.ctrStart = 0 - -def clock(space): - """clock() -> floating point number - - Return the CPU time or real time since the start of the process or since - the first call to clock(). This has as much precision as the system - records.""" - - return space.wrap(pytime.clock()) - -def ctime(space, w_seconds=None): - """ctime([seconds]) -> string - - Convert a time in seconds since the Epoch to a string in local time. - This is equivalent to asctime(localtime(seconds)). When the time tuple is - not present, current time as returned by localtime() is used.""" - - seconds = _get_inttime(space, w_seconds) - with lltype.scoped_alloc(rffi.TIME_TP.TO, 1) as t_ref: - t_ref[0] = seconds - p = c_localtime(t_ref) - if not p: - raise OperationError(space.w_ValueError, - space.wrap("unconvertible time")) - return _asctime(space, p) - -# by now w_tup is an optional argument (and not *args) -# because of the ext. compiler bugs in handling such arguments (*args, **kwds) -def asctime(space, w_tup=None): - """asctime([tuple]) -> string - - Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'. - When the time tuple is not present, current time as returned by localtime() - is used.""" - buf_value = _gettmarg(space, w_tup) - _checktm(space, buf_value) - return _asctime(space, buf_value) - -_wday_names = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] -_mon_names = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", - "Oct", "Nov", "Dec"] - -def _asctime(space, t_ref): - # Inspired by Open Group reference implementation available at - # http://pubs.opengroup.org/onlinepubs/009695399/functions/asctime.html - w, getif = space.wrap, rffi.getintfield - args = [w(_wday_names[getif(t_ref, 'c_tm_wday')]), - w(_mon_names[getif(t_ref, 'c_tm_mon')]), - w(getif(t_ref, 'c_tm_mday')), - w(getif(t_ref, 'c_tm_hour')), - w(getif(t_ref, 'c_tm_min')), - w(getif(t_ref, 'c_tm_sec')), - w(getif(t_ref, 'c_tm_year') + 1900)] - return space.mod(w("%.3s %.3s%3d %.2d:%.2d:%.2d %d"), - space.newtuple(args)) - -def gmtime(space, w_seconds=None): - """gmtime([seconds]) -> (tm_year, tm_mon, tm_day, tm_hour, tm_min, - tm_sec, tm_wday, tm_yday, tm_isdst) - - Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a. - GMT). When 'seconds' is not passed in, convert the current time instead. - """ - - # rpython does not support that a variable has two incompatible builtins - # as value so we have to duplicate the code. NOT GOOD! see localtime() too - seconds = _get_inttime(space, w_seconds) - t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw') - t_ref[0] = seconds - p = c_gmtime(t_ref) - lltype.free(t_ref, flavor='raw') - - if not p: - raise OperationError(space.w_ValueError, space.wrap(_get_error_msg())) - return _tm_to_tuple(space, p) - -def localtime(space, w_seconds=None): - """localtime([seconds]) -> (tm_year, tm_mon, tm_day, tm_hour, tm_min, - tm_sec, tm_wday, tm_yday, tm_isdst) - - Convert seconds since the Epoch to a time tuple expressing local time. - When 'seconds' is not passed in, convert the current time instead.""" - - seconds = _get_inttime(space, w_seconds) - t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw') - t_ref[0] = seconds - p = c_localtime(t_ref) - lltype.free(t_ref, flavor='raw') - - if not p: - raise OperationError(space.w_ValueError, space.wrap(_get_error_msg())) - return _tm_to_tuple(space, p) - -def mktime(space, w_tup): - """mktime(tuple) -> floating point number - - Convert a time tuple in local time to seconds since the Epoch.""" - - buf = _gettmarg(space, w_tup, allowNone=False) - rffi.setintfield(buf, "c_tm_wday", -1) - tt = c_mktime(buf) - # A return value of -1 does not necessarily mean an error, but tm_wday - # cannot remain set to -1 if mktime succeeds. - if tt == -1 and rffi.getintfield(buf, "c_tm_wday") == -1: - raise OperationError(space.w_OverflowError, - space.wrap("mktime argument out of range")) - - return space.wrap(float(tt)) - -if _POSIX: - def tzset(space): - """tzset() - - Initialize, or reinitialize, the local timezone to the value stored in - os.environ['TZ']. The TZ environment variable should be specified in - standard Unix timezone format as documented in the tzset man page - (eg. 'US/Eastern', 'Europe/Amsterdam'). Unknown timezones will silently - fall back to UTC. If the TZ environment variable is not set, the local - timezone is set to the systems best guess of wallclock time. - Changing the TZ environment variable without calling tzset *may* change - the local timezone used by methods such as localtime, but this behaviour - should not be relied on""" - - c_tzset() - - # reset timezone, altzone, daylight and tzname - _init_timezone(space) - -@unwrap_spec(format=str) -def strftime(space, format, w_tup=None): - """strftime(format[, tuple]) -> string - - Convert a time tuple to a string according to a format specification. - See the library reference manual for formatting codes. When the time tuple - is not present, current time as returned by localtime() is used.""" - buf_value = _gettmarg(space, w_tup) - _checktm(space, buf_value) - - # Normalize tm_isdst just in case someone foolishly implements %Z - # based on the assumption that tm_isdst falls within the range of - # [-1, 1] - if rffi.getintfield(buf_value, 'c_tm_isdst') < -1: - rffi.setintfield(buf_value, 'c_tm_isdst', -1) - elif rffi.getintfield(buf_value, 'c_tm_isdst') > 1: - rffi.setintfield(buf_value, 'c_tm_isdst', 1) - - if _WIN: - # check that the format string contains only valid directives - length = len(format) - i = 0 - while i < length: - if format[i] == '%': - i += 1 - if i < length and format[i] == '#': - # not documented by python - i += 1 - if i >= length or format[i] not in "aAbBcdHIjmMpSUwWxXyYzZ%": - raise OperationError(space.w_ValueError, - space.wrap("invalid format string")) - i += 1 - - i = 1024 - while True: - outbuf = lltype.malloc(rffi.CCHARP.TO, i, flavor='raw') - try: - buflen = c_strftime(outbuf, i, format, buf_value) - if buflen > 0 or i >= 256 * len(format): - # if the buffer is 256 times as long as the format, - # it's probably not failing for lack of room! - # More likely, the format yields an empty result, - # e.g. an empty format, or %Z when the timezone - # is unknown. - result = rffi.charp2strn(outbuf, intmask(buflen)) - return space.wrap(result) - finally: - lltype.free(outbuf, flavor='raw') - i += i diff --git a/pypy/module/rctime/test/test_rctime.py b/pypy/module/rctime/test/test_rctime.py deleted file mode 100644 --- a/pypy/module/rctime/test/test_rctime.py +++ /dev/null @@ -1,368 +0,0 @@ -class AppTestRCTime: - spaceconfig = { - "usemodules": ['rctime', 'struct', 'binascii'], - } - - def test_attributes(self): - import time as rctime - assert isinstance(rctime.accept2dyear, int) - assert isinstance(rctime.altzone, int) - assert isinstance(rctime.daylight, int) - assert isinstance(rctime.timezone, int) - assert isinstance(rctime.tzname, tuple) - assert isinstance(rctime.__doc__, str) - - def test_sleep(self): - import time as rctime - import sys - import os - raises(TypeError, rctime.sleep, "foo") - rctime.sleep(0.12345) - raises(IOError, rctime.sleep, -1.0) - - def test_clock(self): - import time as rctime - rctime.clock() - assert isinstance(rctime.clock(), float) - - def test_time(self): - import time as rctime - t1 = rctime.time() - assert isinstance(rctime.time(), float) - assert rctime.time() != 0.0 # 0.0 means failure - rctime.sleep(0.02) - t2 = rctime.time() - assert t1 != t2 # the resolution should be at least 0.01 secs - - def test_ctime(self): - import time as rctime - raises(TypeError, rctime.ctime, "foo") - rctime.ctime(None) - rctime.ctime() - res = rctime.ctime(0) - assert isinstance(res, str) - rctime.ctime(rctime.time()) - raises(ValueError, rctime.ctime, 1E200) - raises(OverflowError, rctime.ctime, 10**900) - for year in [-100, 100, 1000, 2000, 10000]: - try: - testval = rctime.mktime((year, 1, 10) + (0,)*6) - except (ValueError, OverflowError): - # If mktime fails, ctime will fail too. This may happen - # on some platforms. - pass - else: - assert rctime.ctime(testval)[20:] == str(year) - - def test_gmtime(self): - import time as rctime - raises(TypeError, rctime.gmtime, "foo") - rctime.gmtime() - rctime.gmtime(None) - rctime.gmtime(0) - res = rctime.gmtime(rctime.time()) - assert isinstance(res, rctime.struct_time) - assert res[-1] == 0 # DST is always zero in gmtime() - t0 = rctime.mktime(rctime.gmtime()) - t1 = rctime.mktime(rctime.gmtime(None)) - assert 0 <= (t1 - t0) < 1.2 - t = rctime.time() - assert rctime.gmtime(t) == rctime.gmtime(t) - raises(ValueError, rctime.gmtime, 2**64) - raises(ValueError, rctime.gmtime, -2**64) - - def test_localtime(self): - import time as rctime - import os - raises(TypeError, rctime.localtime, "foo") - rctime.localtime() - rctime.localtime(None) - rctime.localtime(0) - res = rctime.localtime(rctime.time()) - assert isinstance(res, rctime.struct_time) - t0 = rctime.mktime(rctime.localtime()) - t1 = rctime.mktime(rctime.localtime(None)) - assert 0 <= (t1 - t0) < 1.2 - t = rctime.time() - assert rctime.localtime(t) == rctime.localtime(t) - if os.name == 'nt': - raises(ValueError, rctime.localtime, -1) - else: - rctime.localtime(-1) - - def test_mktime(self): - import time as rctime - import os, sys - raises(TypeError, rctime.mktime, "foo") - raises(TypeError, rctime.mktime, None) - raises(TypeError, rctime.mktime, (1, 2)) - raises(TypeError, rctime.mktime, (1, 2, 3, 4, 5, 6, 'f', 8, 9)) - res = rctime.mktime(rctime.localtime()) - assert isinstance(res, float) - - ltime = rctime.localtime() - rctime.accept2dyear == 0 - ltime = list(ltime) - ltime[0] = -1 - raises(ValueError, rctime.mktime, tuple(ltime)) - rctime.accept2dyear == 1 - - ltime = list(ltime) - ltime[0] = 67 - ltime = tuple(ltime) - if os.name != "nt" and sys.maxsize < 1<<32: # time_t may be 64bit - raises(OverflowError, rctime.mktime, ltime) - - ltime = list(ltime) - ltime[0] = 100 - raises(ValueError, rctime.mktime, tuple(ltime)) - - t = rctime.time() - assert int(rctime.mktime(rctime.localtime(t))) == int(t) - assert int(rctime.mktime(rctime.gmtime(t))) - rctime.timezone == int(t) - ltime = rctime.localtime() - assert rctime.mktime(tuple(ltime)) == rctime.mktime(ltime) - if os.name != 'nt': - assert rctime.mktime(rctime.localtime(-1)) == -1 - - res = rctime.mktime((2000, 1, 1, 0, 0, 0, -1, -1, -1)) - if os.name == 'nt': - assert rctime.ctime(res) == 'Sat Jan 01 00:00:00 2000' - else: - assert rctime.ctime(res) == 'Sat Jan 1 00:00:00 2000' - - def test_asctime(self): - import time as rctime - rctime.asctime() - # raises(TypeError, rctime.asctime, None) - raises(TypeError, rctime.asctime, ()) - raises(TypeError, rctime.asctime, (1,)) - raises(TypeError, rctime.asctime, range(8)) - raises(TypeError, rctime.asctime, (1, 2)) - raises(TypeError, rctime.asctime, (1, 2, 3, 4, 5, 6, 'f', 8, 9)) - raises(TypeError, rctime.asctime, "foo") - raises(ValueError, rctime.asctime, (1900, -1, 1, 0, 0, 0, 0, 1, -1)) - res = rctime.asctime() - assert isinstance(res, str) - rctime.asctime(rctime.localtime()) - t = rctime.time() - assert rctime.ctime(t) == rctime.asctime(rctime.localtime(t)) - if rctime.timezone: - assert rctime.ctime(t) != rctime.asctime(rctime.gmtime(t)) - ltime = rctime.localtime() - assert rctime.asctime(tuple(ltime)) == rctime.asctime(ltime) - try: - rctime.asctime((12345,) + (0,) * 8) # assert this doesn't crash - except ValueError: - pass # some OS (ie POSIXes besides Linux) reject year > 9999 - - def test_asctime_large_year(self): - import time as rctime - assert rctime.asctime((12345,) + - (0,) * 8) == 'Mon Jan 1 00:00:00 12345' - assert rctime.asctime((123456789,) + - (0,) * 8) == 'Mon Jan 1 00:00:00 123456789' - sizeof_int = 4 - bigyear = (1 << 8 * sizeof_int - 1) - 1 - asc = rctime.asctime((bigyear, 6, 1) + (0,)*6) - assert asc[-len(str(bigyear)):] == str(bigyear) - raises(OverflowError, rctime.asctime, (bigyear + 1,) + (0,)*8) - - def test_accept2dyear_access(self): - import time as rctime - - accept2dyear = rctime.accept2dyear - del rctime.accept2dyear - try: - # with year >= 1900 this shouldn't need to access accept2dyear - assert rctime.asctime((2000,) + (0,) * 8).split()[-1] == '2000' - finally: - rctime.accept2dyear = accept2dyear - - def test_accept2dyear_bad(self): - import time as rctime - class X: - def __bool__(self): - raise RuntimeError('boo') - orig, rctime.accept2dyear = rctime.accept2dyear, X() - try: - raises(RuntimeError, rctime.asctime, (200,) + (0,) * 8) - finally: - rctime.accept2dyear = orig - - def test_struct_time(self): - import time as rctime - raises(TypeError, rctime.struct_time) - raises(TypeError, rctime.struct_time, "foo") - raises(TypeError, rctime.struct_time, (1, 2, 3)) - tup = (1, 2, 3, 4, 5, 6, 7, 8, 9) - st_time = rctime.struct_time(tup) - assert str(st_time).startswith('time.struct_time(tm_year=1, ') - assert len(st_time) == len(tup) - - def test_tzset(self): - import time as rctime - import os - - if not os.name == "posix": - skip("tzset available only under Unix") - - # epoch time of midnight Dec 25th 2002. Never DST in northern - # hemisphere. - xmas2002 = 1040774400.0 - - # these formats are correct for 2002, and possibly future years - # this format is the 'standard' as documented at: - # http://www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap08.html - # They are also documented in the tzset(3) man page on most Unix _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit