Skip to content

Commit 9d875cf

Browse files
committed
refactor: Use shorthand for allocating/freeing
1 parent 203f81e commit 9d875cf

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/odb_backend.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ impl<B: OdbBackend> Backend<B> {
10881088
inner: stream,
10891089
};
10901090

1091-
*stream_out = unsafe { allocate(stream).cast() };
1091+
*stream_out = unsafe { box_allocate(stream).cast() };
10921092

10931093
raw::GIT_OK
10941094
}
@@ -1134,7 +1134,7 @@ impl<B: OdbBackend> Backend<B> {
11341134
inner: stream,
11351135
};
11361136

1137-
*stream_out = unsafe { allocate(stream).cast() };
1137+
*stream_out = unsafe { box_allocate(stream).cast() };
11381138

11391139
raw::GIT_OK
11401140
}
@@ -1217,10 +1217,9 @@ impl<B: OdbBackend> Backend<B> {
12171217
},
12181218
inner: writepack,
12191219
};
1220-
let writepack = Box::into_raw(Box::new(writepack));
12211220

12221221
let out_writepack = unsafe { out_writepack_ptr.as_mut().unwrap() };
1223-
*out_writepack = writepack.cast();
1222+
*out_writepack = unsafe { box_allocate(writepack).cast() };
12241223

12251224
raw::GIT_OK
12261225
}
@@ -1249,8 +1248,7 @@ impl<B: OdbBackend> Backend<B> {
12491248
}
12501249

12511250
extern "C" fn free(backend: *mut raw::git_odb_backend) {
1252-
let inner = unsafe { Box::from_raw(backend.cast::<Self>()) };
1253-
drop(inner);
1251+
unsafe { box_free(backend.cast::<Self>()) }
12541252
}
12551253
}
12561254

@@ -1306,8 +1304,7 @@ where
13061304
raw::GIT_OK
13071305
}
13081306
extern "C" fn free(writepack_ptr: *mut raw::git_odb_writepack) {
1309-
let inner = unsafe { Box::from_raw(writepack_ptr.cast::<Self>()) };
1310-
drop(inner);
1307+
unsafe { box_free(writepack_ptr.cast::<Self>()) }
13111308
}
13121309
}
13131310

@@ -1379,15 +1376,15 @@ impl<B, T> Stream<B, T> {
13791376
}
13801377

13811378
extern "C" fn free(stream_ptr: *mut raw::git_odb_stream) {
1382-
unsafe { free(stream_ptr.cast::<Self>()) }
1379+
unsafe { box_free(stream_ptr.cast::<Self>()) }
13831380
}
13841381
}
13851382
type WriteStream<B> = Stream<B, <B as OdbBackend>::WriteStream>;
13861383
type ReadStream<B> = Stream<B, <B as OdbBackend>::ReadStream>;
13871384

1388-
unsafe fn allocate<T>(value: T) -> *mut T {
1385+
unsafe fn box_allocate<T>(value: T) -> *mut T {
13891386
Box::into_raw(Box::new(value))
13901387
}
1391-
unsafe fn free<T>(ptr: *mut T) {
1388+
unsafe fn box_free<T>(ptr: *mut T) {
13921389
drop(Box::from_raw(ptr))
13931390
}

0 commit comments

Comments
 (0)