1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ci: add more byteptr/&byte compatibility shims to smooth the transition to &byte

This commit is contained in:
Delyan Angelov 2021-04-04 22:43:13 +03:00
parent 519c7194d7
commit 43d83717e7
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 49 additions and 43 deletions

View File

@ -11,22 +11,25 @@ module picohttpparser
struct C.phr_header { struct C.phr_header {
pub: pub:
name charptr name &char
name_len int name_len int
value charptr value &char
value_len int value_len int
} }
type PPchar = &&char
struct C.phr_header_t {} struct C.phr_header_t {}
fn C.phr_parse_request(buf charptr, len size_t, method &charptr, method_len &size_t, path &charptr, path_len &size_t, minor_version &int, headers &C.phr_header, num_headers &size_t, last_len size_t) int fn C.phr_parse_request(buf &char, len size_t, method PPchar, method_len &size_t, path PPchar, path_len &size_t, minor_version &int, headers &C.phr_header, num_headers &size_t, last_len size_t) int
fn C.phr_parse_response(buf charptr, len size_t, minor_version &int, status &int, msg &charptr, msg_len &size_t, headers &C.phr_header, num_headers &size_t, last_len size_t) int fn C.phr_parse_response(buf &char, len size_t, minor_version &int, status &int, msg PPchar, msg_len &size_t, headers &C.phr_header, num_headers &size_t, last_len size_t) int
fn C.phr_parse_headers(buf charptr, len size_t, headers &C.phr_header, num_headers &size_t, last_len size_t) int fn C.phr_parse_headers(buf &char, len size_t, headers &C.phr_header, num_headers &size_t, last_len size_t) int
fn C.phr_parse_request_path(buf_start &char, len size_t, method PPchar, method_len &size_t, path PPchar, path_len &size_t) int
fn C.phr_parse_request_path_pipeline(buf_start &char, len size_t, method PPchar, method_len &size_t, path PPchar, path_len &size_t) int
fn C.get_date() &byte
fn C.phr_parse_request_path(buf_start charptr, len size_t, method &charptr, method_len &size_t, path &charptr, path_len &size_t) int
fn C.phr_parse_request_path_pipeline(buf_start charptr, len size_t, method &charptr, method_len &size_t, path &charptr, path_len &size_t) int
fn C.get_date() byteptr
// char * u64toa(uint64_t value, char *buffer) // char * u64toa(uint64_t value, char *buffer)
fn C.u64toa(value u64, buffer charptr) charptr fn C.u64toa(buffer &char, value u64) &char

View File

@ -2,16 +2,13 @@ module picohttpparser
pub struct Request { pub struct Request {
pub mut: pub mut:
method string method string
path string path string
headers[100] C.phr_header headers [100]C.phr_header
num_headers u64 num_headers u64
body string body string
} }
[inline] [inline]
pub fn (mut r Request) parse_request(s string, max_headers int) int { pub fn (mut r Request) parse_request(s string, max_headers int) int {
method_len := u64(0) method_len := u64(0)
@ -19,14 +16,8 @@ pub fn (mut r Request) parse_request(s string, max_headers int) int {
minor_version := 0 minor_version := 0
num_headers := u64(max_headers) num_headers := u64(max_headers)
pret := C.phr_parse_request( pret := C.phr_parse_request(s.str, s.len, PPchar(&r.method.str), &method_len, PPchar(&r.path.str),
s.str, s.len, &path_len, &minor_version, &r.headers[0], &num_headers, 0)
&r.method.str, &method_len,
&r.path.str, &path_len,
&minor_version,
&r.headers[0], &num_headers,
0
)
if pret > 0 { if pret > 0 {
unsafe { unsafe {
r.method = tos(r.method.str, int(method_len)) r.method = tos(r.method.str, int(method_len))
@ -42,11 +33,8 @@ pub fn (mut r Request) parse_request_path(s string) int {
method_len := u64(0) method_len := u64(0)
path_len := u64(0) path_len := u64(0)
pret := C.phr_parse_request_path( pret := C.phr_parse_request_path(s.str, s.len, PPchar(&r.method.str), &method_len,
s.str, s.len, PPchar(&r.path.str), &path_len)
&r.method.str, &method_len,
&r.path.str, &path_len
)
if pret > 0 { if pret > 0 {
unsafe { unsafe {
r.method = tos(r.method.str, int(method_len)) r.method = tos(r.method.str, int(method_len))
@ -61,11 +49,8 @@ pub fn (mut r Request) parse_request_path_pipeline(s string) int {
method_len := u64(0) method_len := u64(0)
path_len := u64(0) path_len := u64(0)
pret := C.phr_parse_request_path_pipeline( pret := C.phr_parse_request_path_pipeline(s.str, s.len, PPchar(&r.method.str), &method_len,
s.str, s.len, PPchar(&r.path.str), &path_len)
&r.method.str, &method_len,
&r.path.str, &path_len
)
if pret > 0 { if pret > 0 {
unsafe { unsafe {
r.method = tos(r.method.str, int(method_len)) r.method = tos(r.method.str, int(method_len))

View File

@ -50,17 +50,35 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
if c.check_types(got, expected) { if c.check_types(got, expected) {
return return
} }
igot := int(got) idx_got := got.idx()
iexpected := int(expected) idx_expected := expected.idx()
if (igot == ast.byteptr_type_idx && iexpected == 65545) if idx_got in [ ast.byteptr_type_idx, ast.charptr_type_idx] || idx_expected in [ast.byteptr_type_idx, ast.charptr_type_idx] {
|| (iexpected == ast.byteptr_type_idx && igot == 65545) { igot := int(got)
iexpected := int(expected)
// TODO: remove; transitional compatibility for byteptr === &byte // TODO: remove; transitional compatibility for byteptr === &byte
return if (igot == ast.byteptr_type_idx && iexpected == 65545)
} || (iexpected == ast.byteptr_type_idx && igot == 65545) {
if (igot == ast.charptr_type_idx && iexpected == 65551) return
|| (iexpected == ast.charptr_type_idx && igot == 65545) { }
// TODO: remove; transitional compatibility for charptr === &char // TODO: remove; transitional compatibility for charptr === &char
return if (igot == ast.charptr_type_idx && iexpected == 65551)
|| (iexpected == ast.charptr_type_idx && igot == 65551) {
return
}
muls_got := got.nr_muls()
muls_expected := expected.nr_muls()
if idx_got == ast.byteptr_type_idx && idx_expected == ast.byte_type_idx && muls_got + 1 == muls_expected {
return
}
if idx_expected == ast.byteptr_type_idx && idx_got == ast.byte_type_idx && muls_expected + 1 == muls_got {
return
}
if idx_got == ast.charptr_type_idx && idx_expected == ast.char_type_idx && muls_got + 1 == muls_expected {
return
}
if idx_expected == ast.charptr_type_idx && idx_got == ast.char_type_idx && muls_expected + 1 == muls_got {
return
}
} }
return error('cannot use `${c.table.type_to_str(got.clear_flag(.variadic))}` as `${c.table.type_to_str(expected.clear_flag(.variadic))}`') return error('cannot use `${c.table.type_to_str(got.clear_flag(.variadic))}` as `${c.table.type_to_str(expected.clear_flag(.variadic))}`')
} }