🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggested changes
  • Loading branch information
pkese committed Jun 9, 2021
commit d084b2e0d53293d26bb2a72d7e078306fa9cdaf2
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ One must now either use enum members (e.g. `MyEnum.Option`), or use enum constru
- Exception stacktraces on `PythonException.StackTrace` are now properly formatted
- Providing an invalid type parameter to a generic type or method produces a helpful Python error
- Empty parameter names (as can be generated from F#) do not cause crashes
- Unicode strings with surrogates get truncated when converting from Python
- Unicode strings with surrogates were truncated when converting from Python

### Removed

Expand Down
6 changes: 3 additions & 3 deletions src/runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,12 +1619,12 @@ internal static string GetManagedString(IntPtr op)
if (type == PyUnicodeType)
{
using var p = PyUnicode_AsUTF16String(new BorrowedReference(op));
var bytesPtr = p.DangerousGetAddress();
int bytesLength = (int)Runtime.PyBytes_Size(bytesPtr);
var bytesPtr = p.DangerousMoveToPointerOrNull();
nint bytesLength = (nint)Runtime.PyBytes_Size(bytesPtr);
char* codePoints = (char*)PyBytes_AsString(bytesPtr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: better add overload for PyBytes_AsString that takes BorrowedReference. This would remove unnecessary call to DangerousGetAddress above.

return new string(codePoints,
startIndex: 1, // skip BOM
length: bytesLength/2-1); // utf16 - BOM
length: (int) (bytesLength/2-1)); // utf16 - BOM
}

return null;
Expand Down