Skip to content

Commit

Permalink
windows: fix buffer allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
koehlma committed Dec 12, 2015
1 parent f64b7c8 commit bdf128f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cffi_declarations.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,5 @@ int cross_uv_udp_open(uv_udp_t*, int);
void cross_set_process_uid_gid(uv_process_options_t*, int, int);

int cross_uv_fs_close(uv_loop_t*, uv_fs_t*, int, uv_fs_cb);

void cross_uv_buf_set(uv_buf_t*, char*, unsigned int);
5 changes: 5 additions & 0 deletions cffi_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ void cross_set_process_uid_gid(uv_process_options_t* options, int uid, int gid)

int cross_uv_fs_close(uv_loop_t* loop, uv_fs_t* request, int fd, uv_fs_cb callback) {
return uv_fs_close(loop, request, (uv_file) fd, callback);
}

void cross_uv_buf_set(uv_buf_t* buffer, char* base, unsigned int length) {
buffer->base = base;
buffer->len = length;
}
13 changes: 11 additions & 2 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function, unicode_literals, division

import os
import unittest

import uv
Expand All @@ -34,8 +37,8 @@ def reraise(exc_type, exc_value, exc_traceback):


if uv.is_win32:
TEST_PIPE1 = r'\\?\pipe\python-uv-test1'
TEST_PIPE2 = r'\\?\pipe\python-uv-test2'
TEST_PIPE1 = '\\\\?\\pipe\\python-uv-test1'
TEST_PIPE2 = '\\\\?\\pipe\\python-uv-test2'
else:
TEST_PIPE1 = '/tmp/python-uv-test1'
TEST_PIPE2 = '/tmp/python-uv-test2'
Expand All @@ -48,6 +51,12 @@ def reraise(exc_type, exc_value, exc_traceback):
TEST_PORT1 = 12345
TEST_PORT2 = 12346

try: os.remove(TEST_PIPE1)
except: pass

try: os.remove(TEST_PIPE2)
except: pass


class TestLoop(uv.Loop):
def __init__(self):
Expand Down
4 changes: 4 additions & 0 deletions uv/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ def mutable_c_string(string):

def str_c2py(c_string):
return ffi.string(c_string).decode()


def uv_buffer_set(uv_buffer, c_base, length):
lib.cross_uv_buf_set(uv_buffer, c_base, length)
8 changes: 3 additions & 5 deletions uv/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import threading
import traceback

from .library import ffi, lib, attach
from .library import ffi, lib, attach, uv_buffer_set

from .common import Enumeration, with_metaclass
from .error import UVError, LoopClosedError
Expand Down Expand Up @@ -67,11 +67,9 @@ def __init__(self, buffer_size=2**16):

def _allocate(self, uv_handle, suggested_size, uv_buf):
if self.buffer_in_use:
uv_buf.base = ffi.NULL
uv_buf.len = 0
uv_buffer_set(uv_buf, ffi.NULL, 0)
else:
uv_buf.base = self.c_buffer
uv_buf.len = self.buffer_size
uv_buffer_set(uv_buf, self.c_buffer, self.buffer_size)
self.buffer_in_use = True

def finalize(self, uv_handle, length, uv_buf):
Expand Down

0 comments on commit bdf128f

Please sign in to comment.