Cumulative season's silent-bug hunting (~62 fixes) across the FiveSql2 SQL engine, the Five compiler/runtime, and the hbrdd RDD layer. Saved as a single checkpoint before refactoring the parser to delegate xBase command translation to the preprocessor. Highlights: FiveSql2 engine (_FiveSql2/src/) - prefix-glob index attach -> explicit convention (<table>_pk.ntx, <table>_uq.ntx, <table>.cdx) — fixes silent multi-row INSERT row-drop - DROP/CREATE TABLE FErase chain extended (.cdx, .fsc, .fsv, .dbt, .fpt) - COUNT(DISTINCT col) parsed + aggregated via hSeen hash - UNION column-count mismatch returns SQL_ERR_GRAMMAR (was silent) - DISTINCT + ORDER BY hidden-col leak fixed (trim before DISTINCT) - Derived table FROM (SELECT...) + JOIN right-side derived - Self-FK CASCADE depth 2+ via SqlGetSingleColPK pre-collect - LAG/LEAD default arg uses SqlEvalRowExpr (handles -N const exprs) - DATE literal round-trip validation (Feb 29 non-leap rejected) - CREATE OR REPLACE VIEW; CREATE VIEW errors on already-exists - AlterTable type dispatcher comma-wrapped (1-char type "A" no longer matches CHARACTER) Compiler / runtime - gengo: HB_ -> FV_ prefix on emitted Go function names (Five identity) - gengo split: emit_block.go, emit_stmt.go, folding.go extracted - parser/stmtreg.go nudges - hbrt: debug TUI/CLI restructure (debugcmd, debugkey, termios_*), windows debug stubs collapsed - thread/vm/value/class/pcinterp tightening from panic traces RDD layer (hbrdd/) - dbf: null bitmap support (null.go + null_test.go), mmap split (mmap_posix.go / mmap_windows.go), byte-level numeric parse - ntx/cdx: windows mmap parity - workarea + mem RDD: cross-area state-bleed fixes RTL (hbrtl/) - errorlog rewrite with platform-specific FD (errorlog_fd_unix / errorlog_fd_other) - sqlscan, sqlhelpers, indexrtl, datetime extensions Gates green at checkpoint: - go test ./... : PASS - FiveSql2 SQL:1999 : 43/43 - Harbour compat : 56/56 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
83 lines
2.0 KiB
Go
83 lines
2.0 KiB
Go
//go:build windows
|
|
|
|
// Windows mmap — see hbrdd/ntx/mmap_windows.go for the commentary; this
|
|
// is the same implementation for the CDX index package. Keeping
|
|
// separate copies (instead of a shared helper) because the registry
|
|
// map is private to each package, avoiding cross-package coupling for
|
|
// what is otherwise 50 lines of stdlib-only code.
|
|
|
|
package cdx
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"sync"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
const (
|
|
pageReadonly = 0x02
|
|
fileMapRead = 0x0004
|
|
)
|
|
|
|
var (
|
|
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
procCreateFileMappingW = kernel32.NewProc("CreateFileMappingW")
|
|
procMapViewOfFile = kernel32.NewProc("MapViewOfFile")
|
|
procUnmapViewOfFile = kernel32.NewProc("UnmapViewOfFile")
|
|
procCloseHandle = kernel32.NewProc("CloseHandle")
|
|
|
|
mappingMu sync.Mutex
|
|
mappings = map[uintptr]syscall.Handle{}
|
|
)
|
|
|
|
func mmapFile(f *os.File, size int) ([]byte, error) {
|
|
if size <= 0 {
|
|
return nil, fmt.Errorf("mmap: non-positive size %d", size)
|
|
}
|
|
hFile := syscall.Handle(f.Fd())
|
|
sizeHigh := uint32(uint64(size) >> 32)
|
|
sizeLow := uint32(uint64(size) & 0xFFFFFFFF)
|
|
hMap, _, err := procCreateFileMappingW.Call(
|
|
uintptr(hFile), 0, pageReadonly,
|
|
uintptr(sizeHigh), uintptr(sizeLow), 0,
|
|
)
|
|
if hMap == 0 {
|
|
return nil, fmt.Errorf("CreateFileMapping: %v", err)
|
|
}
|
|
addr, _, err := procMapViewOfFile.Call(
|
|
hMap, fileMapRead, 0, 0, uintptr(size),
|
|
)
|
|
if addr == 0 {
|
|
procCloseHandle.Call(hMap)
|
|
return nil, fmt.Errorf("MapViewOfFile: %v", err)
|
|
}
|
|
data := unsafe.Slice((*byte)(unsafe.Pointer(addr)), size)
|
|
|
|
mappingMu.Lock()
|
|
mappings[addr] = syscall.Handle(hMap)
|
|
mappingMu.Unlock()
|
|
return data, nil
|
|
}
|
|
|
|
func munmapFile(data []byte) error {
|
|
if len(data) == 0 {
|
|
return nil
|
|
}
|
|
addr := uintptr(unsafe.Pointer(&data[0]))
|
|
mappingMu.Lock()
|
|
hMap, ok := mappings[addr]
|
|
delete(mappings, addr)
|
|
mappingMu.Unlock()
|
|
|
|
r, _, err := procUnmapViewOfFile.Call(addr)
|
|
if r == 0 {
|
|
return fmt.Errorf("UnmapViewOfFile: %v", err)
|
|
}
|
|
if ok {
|
|
procCloseHandle.Call(uintptr(hMap))
|
|
}
|
|
return nil
|
|
}
|