-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ops): fallback when FastApiOneByteString is not utf8 #18518
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
fix(ops): fallback when FastApiOneByteString is not utf8
- Loading branch information
commit 096bef77fb6ba0ee3d4bc78de862c1d648df028a
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,13 +200,33 @@ impl Transform { | |
*ty = parse_quote! { *const #core::v8::fast_api::FastApiOneByteString }; | ||
match str_ty { | ||
StringType::Ref => q!(Vars { var: &ident }, { | ||
let var = unsafe { &*var }.as_str(); | ||
let var = match ::std::str::from_utf8(unsafe { &*var }.as_bytes()) { | ||
Ok(v) => v, | ||
Err(_) => { | ||
unsafe { &mut *fast_api_callback_options }.fallback = true; | ||
return Default::default(); | ||
} | ||
}; | ||
}), | ||
StringType::Cow => q!(Vars { var: &ident }, { | ||
let var = ::std::borrow::Cow::Borrowed(unsafe { &*var }.as_str()); | ||
let var = ::std::borrow::Cow::Borrowed( | ||
match ::std::str::from_utf8(unsafe { &*var }.as_bytes()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to avoid doing the V8 fallback, and instead just create a String copy conditionally from the bytes? |
||
Ok(v) => v, | ||
Err(_) => { | ||
unsafe { &mut *fast_api_callback_options }.fallback = true; | ||
return Default::default(); | ||
} | ||
}, | ||
); | ||
}), | ||
StringType::Owned => q!(Vars { var: &ident }, { | ||
let var = unsafe { &*var }.as_str().to_owned(); | ||
let var = match ::std::str::from_utf8(unsafe { &*var }.as_bytes()) { | ||
Ok(v) => v.to_owned(), | ||
Err(_) => { | ||
unsafe { &mut *fast_api_callback_options }.fallback = true; | ||
return Default::default(); | ||
} | ||
}; | ||
}), | ||
} | ||
} | ||
|
@@ -718,6 +738,7 @@ impl Optimizer { | |
let segment = single_segment(segments)?; | ||
match segment { | ||
PathSegment { ident, .. } if ident == "str" => { | ||
self.needs_fast_callback_option = true; | ||
self.fast_parameters.push(FastValue::SeqOneByteString); | ||
assert!(self | ||
.transforms | ||
|
@@ -742,6 +763,7 @@ impl Optimizer { | |
if let Some(val) = get_fast_scalar(ident.to_string().as_str()) { | ||
self.fast_parameters.push(val); | ||
} else if ident == "String" { | ||
self.needs_fast_callback_option = true; | ||
// Is `T` an owned String? | ||
self.fast_parameters.push(FastValue::SeqOneByteString); | ||
assert!(self | ||
|
@@ -775,6 +797,7 @@ impl Optimizer { | |
} | ||
// Is `T` a str? | ||
PathSegment { ident, .. } if ident == "str" => { | ||
self.needs_fast_callback_option = true; | ||
self.fast_parameters.push(FastValue::SeqOneByteString); | ||
assert!(self | ||
.transforms | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If memory serves, I had to do a separate
default
return value for pointer returning since there's no Default impl for a void pointer.