[pypy-commit] pypy numpy-fixes: merge default into branch

2015-05-16 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: numpy-fixes
Changeset: r77347:d42df199eb45
Date: 2015-05-16 19:58 +0300
http://bitbucket.org/pypy/pypy/changeset/d42df199eb45/

Log:merge default into branch

diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py
--- a/lib_pypy/datetime.py
+++ b/lib_pypy/datetime.py
@@ -1507,8 +1507,13 @@
 
 converter = _time.localtime if tz is None else _time.gmtime
 
-t, frac = divmod(t, 1.0)
-us = _round(frac * 1e6)
+if isinstance(t, int):
+us = 0
+else:
+t_full = t
+t = int(_math.floor(t))
+frac = t_full - t
+us = _round(frac * 1e6)
 
 # If timestamp is less than one microsecond smaller than a
 # full second, us can be rounded up to 100.  In this case,
@@ -1527,8 +1532,13 @@
 @classmethod
 def utcfromtimestamp(cls, t):
 Construct a UTC datetime from a POSIX timestamp (like time.time()).
-t, frac = divmod(t, 1.0)
-us = _round(frac * 1e6)
+if isinstance(t, int):
+us = 0
+else:
+t_full = t
+t = int(_math.floor(t))
+frac = t_full - t
+us = _round(frac * 1e6)
 
 # If timestamp is less than one microsecond smaller than a
 # full second, us can be rounded up to 100.  In this case,
diff --git a/pypy/doc/cpython_differences.rst b/pypy/doc/cpython_differences.rst
--- a/pypy/doc/cpython_differences.rst
+++ b/pypy/doc/cpython_differences.rst
@@ -320,6 +320,13 @@
   http://bugs.python.org/issue14621, some of us believe it has no
   purpose in CPython either.
 
+* You can't store non-string keys in type objects.  For example::
+
+class A(object):
+locals()[42] = 3
+
+  won't work.
+
 * ``sys.setrecursionlimit(n)`` sets the limit only approximately,
   by setting the usable stack space to ``n * 768`` bytes.  On Linux,
   depending on the compiler settings, the default of 768KB is enough
@@ -361,8 +368,13 @@
   opposed to a dict proxy like in CPython. Mutating the dict will change the
   type and vice versa. For builtin types, a dictionary will be returned that
   cannot be changed (but still looks and behaves like a normal dictionary).
+  
+* some functions and attributes of the ``gc`` module behave in a
+  slightly different way: for example, ``gc.enable`` and
+  ``gc.disable`` are supported, but instead of enabling and disabling
+  the GC, they just enable and disable the execution of finalizers.
 
 * PyPy prints a random line from past #pypy IRC topics at startup in
-  interactive mode. In a released version, this behaviour is supressed, but
+  interactive mode. In a released version, this behaviour is suppressed, but
   setting the environment variable PYPY_IRC_TOPIC will bring it back. Note that
   downstream package providers have been known to totally disable this feature.
diff --git a/pypy/doc/embedding.rst b/pypy/doc/embedding.rst
--- a/pypy/doc/embedding.rst
+++ b/pypy/doc/embedding.rst
@@ -51,6 +51,9 @@
otherwise return 0.  You should really do your own error handling in the
source. It'll acquire the GIL.
 
+   Note: this is meant to be called *only once* or a few times at most.  See
+   the `more complete example`_ below.
+
 .. function:: int pypy_execute_source_ptr(char* source, void* ptr);
 
.. note:: Not available in PyPy = 2.2.1
@@ -65,8 +68,9 @@
Note that this function is not thread-safe itself, so you need to guard it
with a mutex.
 
-Simple example
---
+
+Minimal example
+---
 
 Note that this API is a lot more minimal than say CPython C API, so at first
 it's obvious to think that you can't do much. However, the trick is to do
@@ -78,10 +82,10 @@
 
 .. code-block:: c
 
-#include include/PyPy.h
+#include PyPy.h
 #include stdio.h
 
-const char source[] = print 'hello from pypy';
+static char source[] = print 'hello from pypy';
 
 int main(void)
 {
@@ -103,154 +107,115 @@
 
 If we save it as ``x.c`` now, compile it and run it (on linux) with::
 
-fijal@hermann:/opt/pypy$ gcc -o x x.c -lpypy-c -L.
-fijal@hermann:/opt/pypy$ LD_LIBRARY_PATH=. ./x
+$ gcc -g -o x x.c -lpypy-c -L/opt/pypy/bin -I/opt/pypy/include
+$ LD_LIBRARY_PATH=/opt/pypy/bin ./x
 hello from pypy
 
-on OSX it is necessary to set the rpath of the binary if one wants to link to 
it::
+.. note:: If the compilation fails because of missing PyPy.h header file,
+  you are running PyPy = 2.2.1.  Get it here__.
+
+.. __: 
https://bitbucket.org/pypy/pypy/raw/c4cd6eca9358066571500ac82aaacfdaa3889e8c/include/PyPy.h
+
+On OSX it is necessary to set the rpath of the binary if one wants to link to 
it,
+with a command like::
 
 gcc -o x x.c -lpypy-c -L. -Wl,-rpath -Wl,@executable_path
 ./x
 hello from pypy
 
-Worked!
 
-.. note:: If the compilation fails because of missing PyPy.h header file,
-  you are running PyPy = 2.2.1, please see the 

[pypy-commit] pypy numpy-fixes: merge default into branch

2015-05-12 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: numpy-fixes
Changeset: r77303:0a9ce2fd743a
Date: 2015-05-13 07:45 +0300
http://bitbucket.org/pypy/pypy/changeset/0a9ce2fd743a/

Log:merge default into branch

diff --git a/lib-python/2.7/socket.py b/lib-python/2.7/socket.py
--- a/lib-python/2.7/socket.py
+++ b/lib-python/2.7/socket.py
@@ -145,6 +145,34 @@
 name = hostname
 return name
 
+class RefCountingWarning(UserWarning):
+pass
+
+def _do_reuse_or_drop(socket, methname):
+try:
+method = getattr(socket, methname)
+except (AttributeError, TypeError):
+warnings.warn('%s' object has no _reuse/_drop methods
+{{
+You make use (or a library you are using makes use) of the internal
+classes '_socketobject' and '_fileobject' in socket.py, initializing
+them with custom objects.  On PyPy, these custom objects need two
+extra methods, _reuse() and _drop(), that maintain an explicit
+reference counter.  When _drop() has been called as many times as
+_reuse(), then the object should be freed.
+
+Without these methods, you get the warning here.  This is to
+prevent the following situation: if your (or the library's) code
+relies on reference counting for prompt closing, then on PyPy, the
+__del__ method will be called later than on CPython.  You can
+easily end up in a situation where you open and close a lot of
+(high-level) '_socketobject' or '_fileobject', but the (low-level)
+custom objects will accumulate before their __del__ are called.
+You quickly risk running out of file descriptors, for example.
+}} % (socket.__class__.__name__,), RefCountingWarning, stacklevel=3)
+else:
+method()
+
 
 _socketmethods = (
 'bind', 'connect', 'connect_ex', 'fileno', 'listen',
@@ -182,19 +210,7 @@
 if _sock is None:
 _sock = _realsocket(family, type, proto)
 else:
-# PyPy note about refcounting: implemented with _reuse()/_drop()
-# on the class '_socket.socket'.  Python 3 did it differently
-# with a reference counter on this class 'socket._socketobject'
-# instead, but it is a less compatible change.
-
-# Note that a few libraries (like eventlet) poke at the
-# private implementation of socket.py, passing custom
-# objects to _socketobject().  These libraries need the
-# following fix for use on PyPy: the custom objects need
-# methods _reuse() and _drop() that maintains an explicit
-# reference counter, starting at 0.  When it drops back to
-# zero, close() must be called.
-_sock._reuse()
+_do_reuse_or_drop(_sock, '_reuse')
 
 self._sock = _sock
 
@@ -228,13 +244,13 @@
 def close(self):
 s = self._sock
 self._sock = _closedsocket()
-s._drop()
+_do_reuse_or_drop(s, '_drop')
 close.__doc__ = _realsocket.close.__doc__
 
 def accept(self):
 sock, addr = self._sock.accept()
 sockobj = _socketobject(_sock=sock)
-sock._drop()# already a copy in the _socketobject()
+_do_reuse_or_drop(sock, '_drop') # already a copy in the 
_socketobject()
 return sockobj, addr
 accept.__doc__ = _realsocket.accept.__doc__
 
@@ -290,14 +306,7 @@
  _close]
 
 def __init__(self, sock, mode='rb', bufsize=-1, close=False):
-# Note that a few libraries (like eventlet) poke at the
-# private implementation of socket.py, passing custom
-# objects to _fileobject().  These libraries need the
-# following fix for use on PyPy: the custom objects need
-# methods _reuse() and _drop() that maintains an explicit
-# reference counter, starting at 0.  When it drops back to
-# zero, close() must be called.
-sock._reuse()
+_do_reuse_or_drop(sock, '_reuse')
 self._sock = sock
 self.mode = mode # Not actually used in this version
 if bufsize  0:
@@ -338,7 +347,7 @@
 if self._close:
 s.close()
 else:
-s._drop()
+_do_reuse_or_drop(s, '_drop')
 
 def __del__(self):
 try:
diff --git a/pypy/module/micronumpy/concrete.py 
b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -533,6 +533,9 @@
 return self.__class__(self.start, new_strides, new_backstrides, 
new_shape,
   self, orig_array)
 
+def sort(self, space, w_axis, w_order):
+from .selection import sort_array
+return sort_array(self, space, w_axis, w_order)
 
 class NonWritableSliceArray(SliceArray):
 def descr_setitem(self, space, orig_array, w_index, w_value):
diff --git a/pypy/module/micronumpy/selection.py 
b/pypy/module/micronumpy/selection.py
--- 

[pypy-commit] pypy numpy-fixes: merge default into branch

2015-05-09 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: numpy-fixes
Changeset: r77265:bd891c231bf7
Date: 2015-05-09 23:26 +0300
http://bitbucket.org/pypy/pypy/changeset/bd891c231bf7/

Log:merge default into branch

diff too long, truncating to 2000 out of 2015 lines

diff --git a/lib_pypy/_functools.py b/lib_pypy/_functools.py
--- a/lib_pypy/_functools.py
+++ b/lib_pypy/_functools.py
@@ -8,16 +8,16 @@
 partial(func, *args, **keywords) - new function with partial application
 of the given arguments and keywords.
 
-
-def __init__(self, *args, **keywords):
-if not args:
-raise TypeError('__init__() takes at least 2 arguments (1 given)')
-func, args = args[0], args[1:]
+def __init__(*args, **keywords):
+if len(args)  2:
+raise TypeError('__init__() takes at least 2 arguments (%d given)'
+% len(args))
+self, func, args = args[0], args[1], args[2:]
 if not callable(func):
 raise TypeError(the first argument must be callable)
 self._func = func
 self._args = args
-self._keywords = keywords or None
+self._keywords = keywords
 
 def __delattr__(self, key):
 if key == '__dict__':
@@ -37,19 +37,22 @@
 return self._keywords
 
 def __call__(self, *fargs, **fkeywords):
-if self.keywords is not None:
-fkeywords = dict(self.keywords, **fkeywords)
-return self.func(*(self.args + fargs), **fkeywords)
+if self._keywords:
+fkeywords = dict(self._keywords, **fkeywords)
+return self._func(*(self._args + fargs), **fkeywords)
 
 def __reduce__(self):
 d = dict((k, v) for k, v in self.__dict__.iteritems() if k not in
 ('_func', '_args', '_keywords'))
 if len(d) == 0:
 d = None
-return (type(self), (self.func,),
-(self.func, self.args, self.keywords, d))
+return (type(self), (self._func,),
+(self._func, self._args, self._keywords, d))
 
 def __setstate__(self, state):
-self._func, self._args, self._keywords, d = state
+func, args, keywords, d = state
 if d is not None:
 self.__dict__.update(d)
+self._func = func
+self._args = args
+self._keywords = keywords
diff --git a/lib_pypy/gdbm.py b/lib_pypy/gdbm.py
--- a/lib_pypy/gdbm.py
+++ b/lib_pypy/gdbm.py
@@ -1,4 +1,6 @@
 import cffi, os, sys
+import thread
+_lock = thread.allocate_lock()
 
 ffi = cffi.FFI()
 ffi.cdef('''
@@ -40,6 +42,7 @@
 
 try:
 verify_code = '''
+#include stdlib.h
 #include gdbm.h
 
 static datum pygdbm_fetch(GDBM_FILE gdbm_file, char *dptr, int dsize) {
@@ -86,101 +89,121 @@
 return {'dptr': ffi.new(char[], key), 'dsize': len(key)}
 
 class gdbm(object):
-ll_dbm = None
+__ll_dbm = None
+
+# All public methods need to acquire the lock; all private methods
+# assume the lock is already held.  Thus public methods cannot call
+# other public methods.
 
 def __init__(self, filename, iflags, mode):
-res = lib.gdbm_open(filename, 0, iflags, mode, ffi.NULL)
-self.size = -1
-if not res:
-self._raise_from_errno()
-self.ll_dbm = res
+with _lock:
+res = lib.gdbm_open(filename, 0, iflags, mode, ffi.NULL)
+self.__size = -1
+if not res:
+self.__raise_from_errno()
+self.__ll_dbm = res
 
 def close(self):
-if self.ll_dbm:
-lib.gdbm_close(self.ll_dbm)
-self.ll_dbm = None
+with _lock:
+if self.__ll_dbm:
+lib.gdbm_close(self.__ll_dbm)
+self.__ll_dbm = None
 
-def _raise_from_errno(self):
+def __raise_from_errno(self):
 if ffi.errno:
 raise error(ffi.errno, os.strerror(ffi.errno))
 raise error(lib.gdbm_errno, lib.gdbm_strerror(lib.gdbm_errno))
 
 def __len__(self):
-if self.size  0:
-self.size = len(self.keys())
-return self.size
+with _lock:
+if self.__size  0:
+self.__size = len(self.__keys())
+return self.__size
 
 def __setitem__(self, key, value):
-self._check_closed()
-self._size = -1
-r = lib.gdbm_store(self.ll_dbm, _fromstr(key), _fromstr(value),
-   lib.GDBM_REPLACE)
-if r  0:
-self._raise_from_errno()
+with _lock:
+self.__check_closed()
+self.__size = -1
+r = lib.gdbm_store(self.__ll_dbm, _fromstr(key), _fromstr(value),
+   lib.GDBM_REPLACE)
+if r  0:
+self.__raise_from_errno()
 
 def __delitem__(self, key):
-self._check_closed()
-res = lib.gdbm_delete(self.ll_dbm, _fromstr(key))
-if res  0:
-raise KeyError(key)
+with 

[pypy-commit] pypy numpy-fixes: merge default into branch

2015-05-06 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: numpy-fixes
Changeset: r77156:be47257b1b03
Date: 2015-05-06 17:06 +0300
http://bitbucket.org/pypy/pypy/changeset/be47257b1b03/

Log:merge default into branch

diff too long, truncating to 2000 out of 5994 lines

diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -420,3 +420,10 @@
 the terms of the GPL license version 2 or any later version.  Thus the
 gdbm module, provided in the file lib_pypy/gdbm.py, is redistributed
 under the terms of the GPL license as well.
+
+License for 'pypy/module/_vmprof/src'
+--
+
+The code is based on gperftools. You may see a copy of the License for it at
+
+https://code.google.com/p/gperftools/source/browse/COPYING
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -276,7 +276,11 @@
 if argtypes:
 args = 
[argtype._CData_retval(argtype.from_address(arg)._buffer)
 for argtype, arg in zip(argtypes, args)]
-return to_call(*args)
+try:
+return to_call(*args)
+except SystemExit, e:
+handle_system_exit(e)
+raise
 return f
 
 def __call__(self, *args, **kwargs):
@@ -305,7 +309,11 @@
 except (UnicodeError, TypeError, ValueError), e:
 raise ArgumentError(str(e))
 try:
-res = self.callable(*newargs)
+try:
+res = self.callable(*newargs)
+except SystemExit, e:
+handle_system_exit(e)
+raise
 except:
 exc_info = sys.exc_info()
 traceback.print_tb(exc_info[2], file=sys.stderr)
@@ -715,3 +723,22 @@
 make_fastpath_subclass.memo[CFuncPtr] = CFuncPtrFast
 return CFuncPtrFast
 make_fastpath_subclass.memo = {}
+
+
+def handle_system_exit(e):
+# issue #1194: if we get SystemExit here, then exit the interpreter.
+# Highly obscure imho but some people seem to depend on it.
+if sys.flags.inspect:
+return   # Don't exit if -i flag was given.
+else:
+code = e.code
+if isinstance(code, int):
+exitcode = code
+else:
+f = getattr(sys, 'stderr', None)
+if f is None:
+f = sys.__stderr__
+print  f, code
+exitcode = 1
+
+_rawffi.exit(exitcode)
diff --git a/lib_pypy/greenlet.egg-info b/lib_pypy/greenlet.egg-info
--- a/lib_pypy/greenlet.egg-info
+++ b/lib_pypy/greenlet.egg-info
@@ -1,6 +1,6 @@
 Metadata-Version: 1.0
 Name: greenlet
-Version: 0.4.5
+Version: 0.4.6
 Summary: Lightweight in-process concurrent programming
 Home-page: https://github.com/python-greenlet/greenlet
 Author: Ralf Schmitt (for CPython), PyPy team
diff --git a/lib_pypy/greenlet.py b/lib_pypy/greenlet.py
--- a/lib_pypy/greenlet.py
+++ b/lib_pypy/greenlet.py
@@ -1,7 +1,7 @@
 import sys
 import _continuation
 
-__version__ = 0.4.5
+__version__ = 0.4.6
 
 # 
 # Exceptions
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -38,6 +38,10 @@
 _csv, cppyy, _pypyjson
 ])
 
+if sys.platform.startswith('linux') and sys.maxint  2147483647:
+  if 0: # XXX disabled until we fix the absurd .so mess
+working_modules.add('_vmprof')
+
 translation_modules = default_modules.copy()
 translation_modules.update([
 fcntl, time, select, signal, _rawffi, zlib, struct, _md5,
@@ -99,6 +103,7 @@
 _hashlib  : [pypy.module._ssl.interp_ssl],
 _minimal_curses: [pypy.module._minimal_curses.fficurses],
 _continuation: [rpython.rlib.rstacklet],
+_vmprof : [pypy.module._vmprof.interp_vmprof],
 }
 
 def get_module_validator(modname):
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
@@ -67,3 +67,10 @@
 
 .. branch: object-dtype2
 Extend numpy dtypes to allow using objects with associated garbage collection 
hook
+
+.. branch: vmprof2
+Add backend support for vmprof - a lightweight statistical profiler -
+to linux64, see client at https://vmprof.readthedocs.org
+
+.. branch: jit_hint_docs
+Add more detail to @jit.elidable and @jit.promote in rpython/rlib/jit.py
diff --git a/pypy/goal/pypy.ico b/pypy/goal/pypy.ico
new file mode 100644
index 
..09d07dcc5a783200f440c68c0987926a80d6b667
GIT binary patch

[cut]

diff --git a/pypy/goal/targetpypystandalone.py 
b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -238,6 +238,7 @@
 
 config.translation.suggest(check_str_without_nul=True)
 config.translation.suggest(shared=True)
+