refactor(cli): expose filename and buffer leaves from Rust
Move the pure filename-collision, input/output-buffer construction, and compressed-destination-name helpers to direct Rust-owned caller symbols. Leave C responsible for diagnostics, filesystem resources, suffix-list policy, and the surrounding file-processing orchestration. Test Plan: Pending capped full verification after this atomic ABI cleanup.
This commit is contained in:
+8
-38
@@ -320,7 +320,7 @@ int FIO_rust_multiFilesConcatAction(int nbFilesTotal,
|
||||
/* These policy and filesystem leaves are implemented by the Rust CLI archive.
|
||||
* The declarations in fileio.h remain the C ABI shims while file-I/O
|
||||
* orchestration and diagnostics stay here. */
|
||||
int FIO_rust_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);
|
||||
int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);
|
||||
/* FIO_highbit64() is a Rust-owned scalar policy leaf. */
|
||||
unsigned FIO_highbit64(unsigned long long v);
|
||||
unsigned long long FIO_getLargestFileSize(const char** inFileNames, unsigned nbFiles);
|
||||
@@ -332,9 +332,9 @@ int FIO_rust_adjustParamsForPatchFromMode(FIO_prefs_t* prefs,
|
||||
unsigned* fileWindowLog,
|
||||
int* autoLdm,
|
||||
int* optimalParser);
|
||||
void FIO_rust_setInBuffer(ZSTD_inBuffer* output, const void* buf, size_t s, size_t pos);
|
||||
void FIO_rust_setOutBuffer(ZSTD_outBuffer* output, void* buf, size_t s, size_t pos);
|
||||
const char* FIO_rust_determineCompressedName(const char* srcFileName, const char* outDirName, const char* suffix);
|
||||
void FIO_setInBuffer(ZSTD_inBuffer* output, const void* buf, size_t s, size_t pos);
|
||||
void FIO_setOutBuffer(ZSTD_outBuffer* output, void* buf, size_t s, size_t pos);
|
||||
const char* FIO_determineCompressedName(const char* srcFileName, const char* outDirName, const char* suffix);
|
||||
const char* FIO_rust_determineDstName(const char* srcFileName, const char* outDirName,
|
||||
const char* const* suffixList, const char* suffixListStr);
|
||||
int FIO_rust_adjustMemLimitForPatchFromMode(FIO_prefs_t* prefs,
|
||||
@@ -961,13 +961,6 @@ static void FIO_initDict(FIO_Dict_t* dict, const char* fileName, FIO_prefs_t* co
|
||||
}
|
||||
|
||||
|
||||
/* FIO_checkFilenameCollisions() :
|
||||
* Checks for and warns if there are any files that would have the same output path
|
||||
*/
|
||||
int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles) {
|
||||
return FIO_rust_checkFilenameCollisions(filenameTable, nbFiles);
|
||||
}
|
||||
|
||||
static void FIO_adjustMemLimitForPatchFromMode(FIO_prefs_t* const prefs,
|
||||
unsigned long long const dictSize,
|
||||
unsigned long long const maxSrcFileSize)
|
||||
@@ -1058,20 +1051,6 @@ static int FIO_multiFilesConcatWarning(const FIO_ctx_t* fCtx, FIO_prefs_t* prefs
|
||||
return UTIL_requireUserConfirmation("Proceed? (y/n): ", "Aborting...", "yY", fCtx->hasStdinInput);
|
||||
}
|
||||
|
||||
static ZSTD_inBuffer setInBuffer(const void* buf, size_t s, size_t pos)
|
||||
{
|
||||
ZSTD_inBuffer i;
|
||||
FIO_rust_setInBuffer(&i, buf, s, pos);
|
||||
return i;
|
||||
}
|
||||
|
||||
static ZSTD_outBuffer setOutBuffer(void* buf, size_t s, size_t pos)
|
||||
{
|
||||
ZSTD_outBuffer o;
|
||||
FIO_rust_setOutBuffer(&o, buf, s, pos);
|
||||
return o;
|
||||
}
|
||||
|
||||
#ifndef ZSTD_NOCOMPRESS
|
||||
|
||||
/* **********************************************************************
|
||||
@@ -2555,8 +2534,10 @@ static int FIO_rust_zstd_compressStream(
|
||||
{
|
||||
FIO_rust_zstd_projection_context_t* const context =
|
||||
(FIO_rust_zstd_projection_context_t*)opaque;
|
||||
ZSTD_inBuffer inBuff = setInBuffer(input, inputSize, inputPos);
|
||||
ZSTD_outBuffer outBuff = setOutBuffer(output, outputSize, 0);
|
||||
ZSTD_inBuffer inBuff;
|
||||
ZSTD_outBuffer outBuff;
|
||||
FIO_setInBuffer(&inBuff, input, inputSize, inputPos);
|
||||
FIO_setOutBuffer(&outBuff, output, outputSize, 0);
|
||||
size_t const toFlush = ZSTD_toFlushNow(context->cctx);
|
||||
size_t const result = ZSTD_compressStream2(
|
||||
context->cctx, &outBuff, &inBuff, (ZSTD_EndDirective)directive);
|
||||
@@ -3470,17 +3451,6 @@ int FIO_compressFilename(FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs, const
|
||||
return result;
|
||||
}
|
||||
|
||||
/* FIO_determineCompressedName() :
|
||||
* create a destination filename for compressed srcFileName.
|
||||
* @return a pointer to it.
|
||||
* This function never returns an error (it may abort() in case of pb)
|
||||
*/
|
||||
static const char*
|
||||
FIO_determineCompressedName(const char* srcFileName, const char* outDirName, const char* suffix)
|
||||
{
|
||||
return FIO_rust_determineCompressedName(srcFileName, outDirName, suffix);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
FIO_ctx_t* fCtx;
|
||||
FIO_prefs_t* prefs;
|
||||
|
||||
+12
-12
@@ -1844,7 +1844,7 @@ pub unsafe extern "C" fn FIO_getLargestFileSize(
|
||||
/// The pointer form avoids relying on a cross-language struct return ABI while
|
||||
/// retaining the public `ZSTD_inBuffer` field order and values.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn FIO_rust_setInBuffer(
|
||||
pub unsafe extern "C" fn FIO_setInBuffer(
|
||||
output: *mut FIO_inBuffer,
|
||||
buf: *const c_void,
|
||||
size: usize,
|
||||
@@ -1861,7 +1861,7 @@ pub unsafe extern "C" fn FIO_rust_setInBuffer(
|
||||
|
||||
/// Fill a C-compatible output buffer through an output pointer.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn FIO_rust_setOutBuffer(
|
||||
pub unsafe extern "C" fn FIO_setOutBuffer(
|
||||
output: *mut FIO_outBuffer,
|
||||
buf: *mut c_void,
|
||||
size: usize,
|
||||
@@ -2023,7 +2023,7 @@ pub extern "C" fn FIO_LZ4_GetBlockSize_FromBlockId(id: c_int) -> c_int {
|
||||
/// not thread-safe. The output-directory basename construction is shared
|
||||
/// with `UTIL_createFilenameFromOutDir`, while suffix assembly remains here.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn FIO_rust_determineCompressedName(
|
||||
pub unsafe extern "C" fn FIO_determineCompressedName(
|
||||
src_file_name: *const c_char,
|
||||
out_dir_name: *const c_char,
|
||||
suffix: *const c_char,
|
||||
@@ -2256,7 +2256,7 @@ fn display_filename_collision_warning(filename: *const c_char) {
|
||||
/// Rust implementation of the filename collision checker used by
|
||||
/// `FIO_checkFilenameCollisions` in `programs/fileio.c`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn FIO_rust_checkFilenameCollisions(
|
||||
pub unsafe extern "C" fn FIO_checkFilenameCollisions(
|
||||
filename_table: *const *const c_char,
|
||||
nb_files: c_uint,
|
||||
) -> c_int {
|
||||
@@ -3242,13 +3242,13 @@ mod tests {
|
||||
};
|
||||
|
||||
unsafe {
|
||||
FIO_rust_setInBuffer(
|
||||
FIO_setInBuffer(
|
||||
&mut input,
|
||||
source.as_ptr().cast::<c_void>(),
|
||||
source.len(),
|
||||
1,
|
||||
);
|
||||
FIO_rust_setOutBuffer(
|
||||
FIO_setOutBuffer(
|
||||
&mut output,
|
||||
destination.as_mut_ptr().cast::<c_void>(),
|
||||
destination.len(),
|
||||
@@ -3693,10 +3693,10 @@ mod tests {
|
||||
|
||||
unsafe {
|
||||
let name =
|
||||
FIO_rust_determineCompressedName(source.as_ptr(), ptr::null(), suffix.as_ptr());
|
||||
FIO_determineCompressedName(source.as_ptr(), ptr::null(), suffix.as_ptr());
|
||||
assert_eq!(CStr::from_ptr(name).to_bytes(), b"input/nested/file.zst");
|
||||
|
||||
let name = FIO_rust_determineCompressedName(
|
||||
let name = FIO_determineCompressedName(
|
||||
source.as_ptr(),
|
||||
output_dir.as_ptr(),
|
||||
suffix.as_ptr(),
|
||||
@@ -3705,7 +3705,7 @@ mod tests {
|
||||
|
||||
let stdin = CString::new("/*stdin*\\").unwrap();
|
||||
let name =
|
||||
FIO_rust_determineCompressedName(stdin.as_ptr(), ptr::null(), suffix.as_ptr());
|
||||
FIO_determineCompressedName(stdin.as_ptr(), ptr::null(), suffix.as_ptr());
|
||||
assert_eq!(CStr::from_ptr(name).to_bytes(), b"/*stdout*\\");
|
||||
}
|
||||
}
|
||||
@@ -3825,8 +3825,8 @@ mod tests {
|
||||
let names = [ptr::null(), empty.as_ptr()];
|
||||
|
||||
unsafe {
|
||||
assert_eq!(FIO_rust_checkFilenameCollisions(ptr::null(), 0), 0);
|
||||
assert_eq!(FIO_rust_checkFilenameCollisions(names.as_ptr(), 2), 0);
|
||||
assert_eq!(FIO_checkFilenameCollisions(ptr::null(), 0), 0);
|
||||
assert_eq!(FIO_checkFilenameCollisions(names.as_ptr(), 2), 0);
|
||||
assert!(same_filename_collision_key(ptr::null(), empty.as_ptr()));
|
||||
}
|
||||
}
|
||||
@@ -3848,7 +3848,7 @@ mod tests {
|
||||
first.as_ptr(),
|
||||
different.as_ptr()
|
||||
));
|
||||
assert_eq!(FIO_rust_checkFilenameCollisions(names.as_ptr(), 2), 0);
|
||||
assert_eq!(FIO_checkFilenameCollisions(names.as_ptr(), 2), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user