Last active
August 29, 2015 14:09
-
-
Save vladimir-smirnov-sociomantic/2f040b5300c600f4692b to your computer and use it in GitHub Desktop.
Test case for bug in PyPy or CFFI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env pypy | |
from cffi import FFI | |
ffi = FFI() | |
ffi.cdef(r'typedef union _cairo_path_data_t cairo_path_data_t; union _cairo_path_data_t {struct {int type;int length;} header;struct {double x, y;} point;};typedef struct cairo_path {int status; union _cairo_path_data_t *data; int num_data;} cairo_path_t;') | |
def encode_path_ok(): | |
length = 4 | |
data = ffi.new('cairo_path_data_t[]', length) | |
# path = ffi.new('cairo_path_t *', (0, data, length)) | |
path = ffi.new('cairo_path_t *', {'status': 0, 'data': data, 'num_data': length}) | |
return path, data | |
def encode_path(): | |
length = 4 | |
data = ffi.new('cairo_path_data_t[]', length) | |
path = ffi.new('cairo_path_t *', (0, data, length)) | |
# path = ffi.new('cairo_path_t *', {'status': 0, 'data': data, 'num_data': length}) | |
return path, data | |
from pprint import pprint | |
print("Working example") | |
for i in range(0, 100000): | |
path_new, data = encode_path_ok() | |
if path_new.data != data: | |
raise Exception("Failed on iteration %i" % i) | |
print("Will fail") | |
for i in range(0, 100000): | |
path_new, data = encode_path() | |
if path_new.data != data: | |
raise Exception("Failed on iteration %i" % i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment