Skip to content

Commit

Permalink
Fix detectCIC and detect_cic_raw functions not accepting `bytearr…
Browse files Browse the repository at this point in the history
…ay` objects.
  • Loading branch information
AngheloAlf committed Dec 23, 2023
1 parent 5faa0a2 commit f454baf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Python bindings:
- Fix `detectCIC` and `detect_cic_raw` functions not accepting `bytearray`
objects.

## [1.1.0] - 2023-12-22

### Added
Expand Down
16 changes: 12 additions & 4 deletions src/rs/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,20 @@ pub fn detect_cic(rom_bytes: &[u8]) -> Result<CICKind, Ipl3ChecksumError> {
#[allow(non_snake_case)]
pub(crate) mod python_bindings {
use pyo3::prelude::*;
use std::borrow::Cow;

/**
* We use a `Cow` instead of a plain &[u8] the latter only allows Python's
* `bytes` objects, while Cow allows for both `bytes` and `bytearray`.
* This is important because an argument typed as `bytes` allows to pass a
* `bytearray` object too.
*/

#[pyfunction]
pub(crate) fn detectCICRaw(
raw_bytes: &[u8],
raw_bytes: Cow<[u8]>,
) -> Result<Option<super::CICKind>, super::Ipl3ChecksumError> {
match super::detect_cic_raw(raw_bytes) {
match super::detect_cic_raw(&raw_bytes) {
Ok(cic) => Ok(Some(cic)),
Err(e) => match e {
super::Ipl3ChecksumError::BufferSizeIsWrong {
Expand All @@ -67,9 +75,9 @@ pub(crate) mod python_bindings {

#[pyfunction]
pub(crate) fn detectCIC(
rom_bytes: &[u8],
rom_bytes: Cow<[u8]>,
) -> Result<Option<super::CICKind>, super::Ipl3ChecksumError> {
match super::detect_cic(rom_bytes) {
match super::detect_cic(&rom_bytes) {
Ok(cic) => Ok(Some(cic)),
Err(e) => match e {
super::Ipl3ChecksumError::BufferSizeIsWrong {
Expand Down

0 comments on commit f454baf

Please sign in to comment.