Skip to content

Commit 0ea83ce

Browse files
authored
net.http,ci,db.sqlite: rewrite .github/workflows/windows-install-sqlite.bat in .vsh, fix vschannel on windows downloading content > 32KB (#25792)
1 parent 8a1efb3 commit 0ea83ce

8 files changed

Lines changed: 75 additions & 28 deletions

File tree

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
@echo off
1+
REM This file should be run from the top folder of the V compiler itself.
22

3-
curl -L https://sqlite.org/2025/sqlite-amalgamation-3510000.zip -o sqlite-amalgamation-3510000.zip
4-
5-
unzip sqlite-amalgamation-3510000.zip -d thirdparty\
6-
7-
del thirdparty\sqlite-amalgamation-3510000\shell.c
8-
9-
move /y thirdparty\sqlite-amalgamation-3510000 thirdparty\sqlite
10-
11-
dir thirdparty\sqlite
3+
v vlib/db/sqlite/install_thirdparty_sqlite.vsh

‎thirdparty/vschannel/vschannel.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void vschannel_init(TlsContext *tls_ctx) {
8787
tls_ctx->creds_initialized = TRUE;
8888
}
8989

90-
INT request(TlsContext *tls_ctx, INT iport, LPWSTR host, CHAR *req, DWORD req_len, CHAR **out)
90+
INT request(TlsContext *tls_ctx, INT iport, LPWSTR host, CHAR *req, DWORD req_len, CHAR **out, vschannel_allocator afn)
9191
{
9292
SecBuffer ExtraData;
9393
SECURITY_STATUS Status;
@@ -149,7 +149,7 @@ INT request(TlsContext *tls_ctx, INT iport, LPWSTR host, CHAR *req, DWORD req_le
149149
tls_ctx->p_pemote_cert_context = NULL;
150150

151151
// Request from server
152-
if(https_make_request(tls_ctx, req, req_len, out, &resp_length)) {
152+
if(https_make_request(tls_ctx, req, req_len, out, &resp_length, afn)) {
153153
vschannel_cleanup(tls_ctx);
154154
return resp_length;
155155
}
@@ -711,7 +711,7 @@ static SECURITY_STATUS client_handshake_loop(TlsContext *tls_ctx, BOOL fDoInitia
711711
}
712712

713713

714-
static SECURITY_STATUS https_make_request(TlsContext *tls_ctx, CHAR *req, DWORD req_len, CHAR **out, int *length) {
714+
static SECURITY_STATUS https_make_request(TlsContext *tls_ctx, CHAR *req, DWORD req_len, CHAR **out, int *length, vschannel_allocator afn) {
715715
SecPkgContext_StreamSizes Sizes;
716716
SECURITY_STATUS scRet;
717717
SecBufferDesc Message;
@@ -875,7 +875,7 @@ static SECURITY_STATUS https_make_request(TlsContext *tls_ctx, CHAR *req, DWORD
875875
// increase buffer size if we need
876876
int required_length = *length+(int)pDataBuffer->cbBuffer;
877877
if( required_length > buff_size ) {
878-
CHAR *a = VSCHANNEL_REALLOC(*out, required_length);
878+
CHAR *a = afn(*out, required_length);
879879
if( a == NULL ) {
880880
scRet = SEC_E_INTERNAL_ERROR;
881881
return scRet;

‎thirdparty/vschannel/vschannel.h‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
// Define here to be sure
2121
#define SP_PROT_TLS1_2_CLIENT 0x00000800
2222

23-
#if !defined(VSCHANNEL_REALLOC)
24-
#define VSCHANNEL_REALLOC realloc
25-
#endif
23+
typedef void* (*vschannel_allocator)(void*, INT64);
2624

2725
typedef struct TlsContext TlsContext;
2826

@@ -32,9 +30,9 @@ static void vschannel_init(TlsContext *tls_ctx);
3230

3331
static void vschannel_cleanup(TlsContext *tls_ctx);
3432

35-
static INT request(TlsContext *tls_ctx, INT iport, LPWSTR host, CHAR *req, DWORD req_len, CHAR **out);
33+
static INT request(TlsContext *tls_ctx, INT iport, LPWSTR host, CHAR *req, DWORD req_len, CHAR **out, vschannel_allocator afn);
3634

37-
static SECURITY_STATUS https_make_request(TlsContext *tls_ctx, CHAR *req, DWORD req_len, CHAR **out, int *length);
35+
static SECURITY_STATUS https_make_request(TlsContext *tls_ctx, CHAR *req, DWORD req_len, CHAR **out, int *length, vschannel_allocator afn);
3836

3937
static INT connect_to_server(TlsContext *tls_ctx, LPWSTR host, INT port_number);
4038

‎vlib/builtin/backtraces_windows.c.v‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn print_backtrace_skipping_top_frames_msvc(skipframes int) bool {
117117
if C.SymGetLineFromAddr64(handle, frame_addr, &offset, &sline64) == 1 {
118118
file_name := unsafe { tos3(sline64.f_file_name) }
119119
lnumber := sline64.f_line_number
120-
lineinfo = file_name + i64(lnumber).str()
120+
lineinfo = file_name + ':' + i64(lnumber).str()
121121
} else {
122122
// addr:
123123
lineinfo = '?? : address = 0x' + ptr_str(frame_addr)
@@ -129,7 +129,7 @@ fn print_backtrace_skipping_top_frames_msvc(skipframes int) bool {
129129
eprint(sfunc)
130130
eprint_space_padding(sfunc, 25)
131131
eprint(' ')
132-
eprint(lineinfo)
132+
eprintln(lineinfo)
133133
} else {
134134
// https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes
135135
cerr := int(C.GetLastError())

‎vlib/builtin/cfns.c.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ fn C.closesocket(int) int
408408

409409
fn C.vschannel_init(&C.TlsContext)
410410

411-
fn C.request(&C.TlsContext, int, &u16, &u8, u32, &&u8) int
411+
fn C.request(&C.TlsContext, int, &u16, &u8, u32, &&u8, fn (voidptr, isize) voidptr) int
412412

413413
fn C.vschannel_cleanup(&C.TlsContext)
414414

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env -S v run
2+
3+
import os
4+
import net.http
5+
import compress.szip
6+
import crypto.sha3
7+
8+
fn should_be_ok(http_status_code int, msg string) {
9+
assert http_status_code == 200, '${msg}. Check your internet connection and try again later.'
10+
}
11+
12+
fn main() {
13+
unbuffer_stdout()
14+
os.chdir(@VROOT)!
15+
16+
download_page_url := 'https://sqlite.org/download.html'
17+
println('> Getting ${download_page_url} ...')
18+
download_page := http.get(download_page_url)!
19+
should_be_ok(download_page.status_code, 'The download page of SQLite is not available now.')
20+
21+
dlines := download_page.body.split_into_lines()
22+
amalgamation_csv := dlines.filter(|line| line.starts_with('PRODUCT,')
23+
&& line.contains('amalgamation'))[0].split(',')
24+
assert amalgamation_csv.len >= 4
25+
26+
version := amalgamation_csv[1]
27+
zip_name := os.file_name(amalgamation_csv[2])
28+
zip_url := 'https://sqlite.org/${amalgamation_csv[2]}'
29+
url_size := amalgamation_csv[3].int()
30+
url_sha3 := amalgamation_csv[4]
31+
println('> Getting SQLite amalgamation version: ${version}')
32+
println('> from url: ${zip_url}')
33+
println('> expected size: ${url_size}')
34+
println('> expected SHA3: ${url_sha3} ...')
35+
amalgamation_name := zip_name.to_lower().replace('.zip', '')
36+
37+
println('> Downloading from ${zip_url} ...')
38+
zip_content := http.get(zip_url)!
39+
should_be_ok(zip_content.status_code, 'The .zip file URL of SQLite is not available now.')
40+
41+
assert zip_content.body.len == url_size
42+
println('> download size: ${zip_content.body.len} matches expected size: ${url_size} .')
43+
zip_shasum := sha3.sum256(zip_content.body.bytes()).hex()
44+
assert zip_shasum == url_sha3
45+
println('> download sha3: ${zip_shasum} matches too.')
46+
47+
os.write_file(zip_name, zip_content.body)!
48+
assert os.is_file(zip_name)
49+
assert szip.extract_zip_to_dir(zip_name, 'thirdparty')!
50+
os.rmdir_all('thirdparty/sqlite') or {}
51+
os.mv('thirdparty/${amalgamation_name}', 'thirdparty/sqlite')!
52+
os.rm('thirdparty/sqlite/shell.c')!
53+
files := os.walk_ext('thirdparty/sqlite', '')
54+
for f in files {
55+
println('> extracted file: ${f:-40s} | size: ${os.file_size(f):8}')
56+
}
57+
58+
println('> removing ${zip_name} ...')
59+
os.rm(zip_name)!
60+
println('> done')
61+
}

‎vlib/db/sqlite/sqlite.c.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $if windows {
88
#flag windows -I@VEXEROOT/thirdparty/sqlite
99
#flag windows -L@VEXEROOT/thirdparty/sqlite
1010
#flag windows @VEXEROOT/thirdparty/sqlite/sqlite3.o
11-
#include "sqlite3.h" # The SQLite header file is missing. Please run .github/workflows/windows-install-sqlite.bat to download an SQLite amalgamation.
11+
#include "sqlite3.h" # The SQLite header file is missing. Please run vlib/db/sqlite/install_thirdparty_sqlite.vsh to download an SQLite amalgamation.
1212
} $else {
1313
#flag -lsqlite3
1414
#include "sqlite3.h" # The SQLite header file is missing. Please install its development package first.

‎vlib/net/http/backend_vschannel_windows.c.v‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
// that can be found in the LICENSE file.
44
module http
55

6-
$if gcboehm ? {
7-
#define VSCHANNEL_REALLOC GC_REALLOC
8-
}
9-
106
#flag windows -I @VEXEROOT/thirdparty/vschannel
117
#flag -l ws2_32 -l crypt32 -l secur32 -l user32
128
#include "vschannel.c"
@@ -24,7 +20,7 @@ fn vschannel_ssl_do(req &Request, port int, method Method, host_name string, pat
2420
$if trace_http_request ? {
2521
eprintln('> ${sdata}')
2622
}
27-
length := C.request(&ctx, port, addr.to_wide(), sdata.str, sdata.len, &buff)
23+
length := C.request(&ctx, port, addr.to_wide(), sdata.str, sdata.len, &buff, v_realloc)
2824
C.vschannel_cleanup(&ctx)
2925
response_text := unsafe { buff.vstring_with_len(length) }
3026
if req.on_progress != unsafe { nil } {

0 commit comments

Comments
 (0)