[pypy-svn] r53709 - in pypy/branch/io-improvements/pypy: rlib rlib/test rpython/lltypesystem rpython/lltypesystem/test
docgok at codespeak.net
docgok at codespeak.net
Sat Apr 12 00:27:35 CEST 2008
Author: docgok
Date: Sat Apr 12 00:27:33 2008
New Revision: 53709
Modified:
pypy/branch/io-improvements/pypy/rlib/rsocket.py
pypy/branch/io-improvements/pypy/rlib/rzlib.py
pypy/branch/io-improvements/pypy/rlib/test/test_rsocket.py
pypy/branch/io-improvements/pypy/rpython/lltypesystem/rffi.py
pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_rffi.py
Log:
New non-moving buffer API usage in new exciting places.
Modified: pypy/branch/io-improvements/pypy/rlib/rsocket.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rlib/rsocket.py (original)
+++ pypy/branch/io-improvements/pypy/rlib/rsocket.py Sat Apr 12 00:27:33 2008
@@ -869,18 +869,18 @@
"""Send a data string to the socket. For the optional flags
argument, see the Unix manual. Return the number of bytes
sent; this may be less than len(data) if the network is busy."""
- dataptr = rffi.str2charp(data)
+ dataptr = rffi.get_nonmovingbuffer(data)
try:
return self.send_raw(dataptr, len(data), flags)
finally:
- rffi.free_charp(dataptr)
+ rffi.free_nonmovingbuffer(data, dataptr)
def sendall(self, data, flags=0):
"""Send a data string to the socket. For the optional flags
argument, see the Unix manual. This calls send() repeatedly
until all data is sent. If an error occurs, it's impossible
to tell how much data has been sent."""
- dataptr = rffi.str2charp(data)
+ dataptr = rffi.get_nonmovingbuffer(data)
try:
remaining = len(data)
p = dataptr
@@ -889,7 +889,7 @@
p = rffi.ptradd(p, res)
remaining -= res
finally:
- rffi.free_charp(dataptr)
+ rffi.free_nonmovingbuffer(data, dataptr)
def sendto(self, data, flags, address):
"""Like send(data, flags) but allows specifying the destination
@@ -1265,7 +1265,7 @@
raise RSocketError("unknown address family")
if len(packed) != srcsize:
raise ValueError("packed IP wrong length for inet_ntop")
- srcbuf = rffi.str2charp(packed)
+ srcbuf = rffi.get_nonmovingbuffer(packed)
try:
dstbuf = mallocbuf(dstsize)
try:
@@ -1276,7 +1276,7 @@
finally:
lltype.free(dstbuf, flavor='raw')
finally:
- lltype.free(srcbuf, flavor='raw')
+ lltype.free_nonmovingbuffer(packed, srcbuf)
def setdefaulttimeout(timeout):
if timeout < 0.0:
Modified: pypy/branch/io-improvements/pypy/rlib/rzlib.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rlib/rzlib.py (original)
+++ pypy/branch/io-improvements/pypy/rlib/rzlib.py Sat Apr 12 00:27:33 2008
@@ -154,9 +154,11 @@
Compute the CRC32 checksum of the string, possibly with the given
start value, and return it as a unsigned 32 bit integer.
"""
- bytes = rffi.str2charp(string)
- checksum = _crc32(start, rffi.cast(Bytefp, bytes), len(string))
- rffi.free_charp(bytes)
+ try:
+ bytes = rffi.get_nonmovingbuffer(string)
+ checksum = _crc32(start, rffi.cast(Bytefp, bytes), len(string))
+ finally:
+ rffi.free_nonmovingbuffer(string, bytes)
return checksum
@@ -167,9 +169,11 @@
Compute the Adler-32 checksum of the string, possibly with the given
start value, and return it as a unsigned 32 bit integer.
"""
- bytes = rffi.str2charp(string)
- checksum = _adler32(start, rffi.cast(Bytefp, bytes), len(string))
- rffi.free_charp(bytes)
+ try:
+ bytes = rffi.get_nonmovingbuffer(string)
+ checksum = _adler32(start, rffi.cast(Bytefp, bytes), len(string))
+ finally:
+ rffi.free_nonmovingbuffer(string, bytes)
return checksum
# ____________________________________________________________
Modified: pypy/branch/io-improvements/pypy/rlib/test/test_rsocket.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rlib/test/test_rsocket.py (original)
+++ pypy/branch/io-improvements/pypy/rlib/test/test_rsocket.py Sat Apr 12 00:27:33 2008
@@ -1,6 +1,7 @@
import py, errno, sys
from pypy.rlib import rsocket
from pypy.rlib.rsocket import *
+from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
import socket as cpy_socket
# cannot test error codes in Win32 because ll2ctypes doesn't save
@@ -257,23 +258,23 @@
py.test.raises(GAIError, getaddrinfo, 'www.very-invalidaddress.com', None)
def test_getaddrinfo_snake():
- lst = getaddrinfo('snake.cs.uni-duesseldorf.de', None)
+ lst = getaddrinfo('codespeak.net', None)
assert isinstance(lst, list)
found = False
for family, socktype, protocol, canonname, addr in lst:
- if addr.get_host() == '134.99.112.214':
+ if addr.get_host() == '213.239.226.252':
found = True
assert found, lst
def test_getaddrinfo_no_reverse_lookup():
# It seems that getaddrinfo never runs a reverse lookup on Linux.
# Python2.3 on Windows returns the hostname.
- lst = getaddrinfo('134.99.112.214', None, flags=AI_NUMERICHOST)
+ lst = getaddrinfo('213.239.226.252', None, flags=AI_NUMERICHOST)
assert isinstance(lst, list)
found = False
for family, socktype, protocol, canonname, addr in lst:
- assert canonname != 'snake.cs.uni-duesseldorf.de'
- if addr.get_host() == '134.99.112.214':
+ assert canonname != 'codespeak.net'
+ if addr.get_host() == '213.239.226.252':
found = True
assert found, lst
@@ -369,7 +370,30 @@
clientsock.close()
s.close()
+
+class BaseSendRecvTest(BaseRtypingTest):
+ def test_socketpair(self):
+ if sys.platform == "win32":
+ py.test.skip('No socketpair on Windows')
+
+ def f():
+ s1, s2 = socketpair()
+ s1.sendall('?')
+ buf = s2.recv(100)
+ assert buf == '?'
+ count = s2.send('x'*99)
+ assert 1 <= count <= 99
+ buf = s1.recv(100)
+ assert buf == 'x'*count
+ s1.close()
+ s2.close()
+ self.interpret(f,[])
+
+class TestSendRecvMovingGc(BaseSendRecvTest, LLRtypeMixin):
+ MOVING_GC = True
+class TestSendRecvNonMovingGc(BaseSendRecvTest, LLRtypeMixin):
+ MOVING_GC = False
class TestTCP:
PORT = 50007
Modified: pypy/branch/io-improvements/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/lltypesystem/rffi.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/lltypesystem/rffi.py Sat Apr 12 00:27:33 2008
@@ -489,7 +489,7 @@
else:
data_start = cast_ptr_to_adr(llstr(data)) + \
offsetof(rstr.STR, 'chars') + itemoffsetof(rstr.STR.chars, 0)
- return cast(VOIDP, data_start)
+ return cast(CCHARP, data_start)
# (str, char*) -> None
def free_nonmovingbuffer(data, buf):
Modified: pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_rffi.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_rffi.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_rffi.py Sat Apr 12 00:27:33 2008
@@ -648,10 +648,10 @@
free_nonmovingbuffer(d, buf)
self.interpret(f, [])
-class TestNonmovingBuffer(BaseInterpretedTestRffi, LLRtypeMixin):
- pass
+class TestNonmovingBufferMovingGc(BaseInterpretedTestRffi, LLRtypeMixin):
+ MOVING_GC = True
-class TestLLtypeNonMovingGc(BaseInterpretedTestRffi, LLRtypeMixin):
+class TestNonmovingBufferNonMovingGc(BaseInterpretedTestRffi, LLRtypeMixin):
MOVING_GC = False
class TestCRffi(BaseTestRffi):
More information about the Pypy-commit
mailing list