Skip to content

Commit eefaa98

Browse files
committed
backported pypy fixes from 2.1
1 parent ceda8a4 commit eefaa98

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

plugins/pypy/pypy_setup.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def read(self, size=0):
393393
rlen = ffi.new('ssize_t*')
394394
chunk = lib.uwsgi_request_body_read(self.wsgi_req, size, rlen)
395395
if chunk != ffi.NULL:
396-
return ffi.string(chunk, rlen[0])
396+
return ffi.buffer(chunk, rlen[0])[:]
397397
if rlen[0] < 0:
398398
raise IOError("error reading wsgi.input")
399399
raise IOError("error waiting for wsgi.input")
@@ -402,7 +402,7 @@ def getline(self, hint=0):
402402
rlen = ffi.new('ssize_t*')
403403
chunk = lib.uwsgi_request_body_readline(self.wsgi_req, hint, rlen)
404404
if chunk != ffi.NULL:
405-
return ffi.string(chunk, rlen[0])
405+
return ffi.buffer(chunk, rlen[0])[:]
406406
if rlen[0] < 0:
407407
raise IOError("error reading line from wsgi.input")
408408
raise IOError("error waiting for line on wsgi.input")
@@ -521,7 +521,7 @@ def __init__(self, func):
521521
def __call__(self, argc, argv, argvs, buf):
522522
pargs = []
523523
for i in range(0, argc):
524-
pargs.append(ffi.string(argv[i], argvs[i]))
524+
pargs.append(ffi.buffer(argv[i], argvs[i])[:])
525525
response = self.func(*pargs)
526526
if len(response) > 0:
527527
buf[0] = lib.uwsgi_malloc(len(response))
@@ -560,7 +560,7 @@ def uwsgi_pypy_rpc(node, func, *args):
560560

561561
response = lib.uwsgi_do_rpc(c_node, ffi.new("char[]",func), argc, argv, argvs, rsize)
562562
if response:
563-
ret = ffi.string(response, rsize[0])
563+
ret = ffi.buffer(response, rsize[0])[:]
564564
lib.free(response)
565565
return ret
566566
return None
@@ -587,7 +587,7 @@ def uwsgi_pypy_uwsgi_cache_get(key, cache=ffi.NULL):
587587
value = lib.uwsgi_cache_magic_get(key, len(key), vallen, ffi.NULL, cache)
588588
if value == ffi.NULL:
589589
return None
590-
ret = ffi.string(value, vallen[0])
590+
ret = ffi.buffer(value, vallen[0])[:]
591591
libc.free(value)
592592
return ret
593593
uwsgi.cache_get = uwsgi_pypy_uwsgi_cache_get
@@ -617,8 +617,9 @@ def uwsgi_pypy_uwsgi_cache_keys(cache=ffi.NULL):
617617
uci = ffi.new('struct uwsgi_cache_item **')
618618
while True:
619619
uci[0] = lib.uwsgi_cache_keys(uc, pos, uci)
620-
if uci[0] == ffi.NULL: break
621-
l.append(ffi.string(lib.uwsgi_cache_item_key(uci[0]), uci[0].keysize))
620+
if uci[0] == ffi.NULL:
621+
break
622+
l.append(ffi.buffer(lib.uwsgi_cache_item_key(uci[0]), uci[0].keysize)[:])
622623
lib.uwsgi_cache_rwunlock(uc)
623624
return l
624625
uwsgi.cache_keys = uwsgi_pypy_uwsgi_cache_keys
@@ -849,7 +850,7 @@ def uwsgi_pypy_websocket_recv():
849850
ub = lib.uwsgi_websocket_recv(wsgi_req);
850851
if ub == ffi.NULL:
851852
raise IOError("unable to receive websocket message")
852-
ret = ffi.string(ub.buf, ub.pos)
853+
ret = ffi.buffer(ub.buf, ub.pos)[:]
853854
lib.uwsgi_buffer_destroy(ub)
854855
return ret
855856
uwsgi.websocket_recv = uwsgi_pypy_websocket_recv
@@ -862,7 +863,7 @@ def uwsgi_pypy_websocket_recv_nb():
862863
ub = lib.uwsgi_websocket_recv_nb(wsgi_req);
863864
if ub == ffi.NULL:
864865
raise IOError("unable to receive websocket message")
865-
ret = ffi.string(ub.buf, ub.pos)
866+
ret = ffi.buffer(ub.buf, ub.pos)[:]
866867
lib.uwsgi_buffer_destroy(ub)
867868
return ret
868869
uwsgi.websocket_recv_nb = uwsgi_pypy_websocket_recv_nb
@@ -897,7 +898,7 @@ def uwsgi_pypy_chunked_read(timeout=0):
897898
chunk = lib.uwsgi_chunked_read(wsgi_req, rlen, timeout, 0)
898899
if chunk == ffi.NULL:
899900
raise IOError("unable to receive chunked part")
900-
return ffi.string(chunk, rlen[0])
901+
return ffi.buffer(chunk, rlen[0])[:]
901902
uwsgi.chunked_read = uwsgi_pypy_chunked_read
902903

903904
"""
@@ -911,8 +912,7 @@ def uwsgi_pypy_chunked_read_nb():
911912
if lib.uwsgi_is_again() > 0:
912913
return None
913914
raise IOError("unable to receive chunked part")
914-
915-
return ffi.string(chunk, rlen[0])
915+
return ffi.buffer(chunk, rlen[0])[:]
916916
uwsgi.chunked_read_nb = uwsgi_pypy_chunked_read_nb
917917

918918
"""

0 commit comments

Comments
 (0)