Skip to content

Fixed UTF-8 encoding for whats_left.py and type mismatching in stdlib/src/ssl.rs #4440

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

Merged
merged 4 commits into from
Feb 18, 2023

Conversation

PandH4cker
Copy link
Contributor

@PandH4cker PandH4cker commented Jan 11, 2023

This Pull Request is fixing the charmap error when running Python over the script whats_left.py as shown below:

λ python.exe -I whats_left.py
test_sqlite3: testing with version '2.6.0', sqlite_version '3.39.4'
Traceback (most recent call last):
  File "[REDACTED]\IdeaProjects\RustPython\whats_left.py", line 445, in <module>
    f.write(output + "\n")
  File "[REDACTED]\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\u03c0' in position 76582: character maps to <undefined>

The line responsible of this behaviour is:

with open(GENERATED_FILE, "w") as f:

Hence, we just need to add the parameter encoding to the value UTF-8 to resolve this error.

The second fix resides in the ssl.rs file. Indeed, there are some type mismatching that cause errors while building with whats_left.py, where are listed below:

const OP_ALL: libc::c_ulong = sys::SSL_OP_ALL & !sys::SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;
[...]
fn set_options(&self, opts: libc::c_ulong) {
            self.builder()
                .set_options(SslOptions::from_bits_truncate(opts));
}

closes #4255

@@ -119,7 +119,7 @@ mod _ssl {
#[pyattr]
const PROTO_MAXIMUM_SUPPORTED: i32 = ProtoVersion::MaxSupported as i32;
#[pyattr]
const OP_ALL: libc::c_ulong = sys::SSL_OP_ALL & !sys::SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;
const OP_ALL: libc::c_ulong = (sys::SSL_OP_ALL & !sys::SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) as u32;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const OP_ALL: libc::c_ulong = (sys::SSL_OP_ALL & !sys::SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) as u32;
const OP_ALL: libc::c_ulong = (sys::SSL_OP_ALL & !sys::SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) as libc::c_ulong;

@fanninpm
Copy link
Contributor

What happens after a cargo clean?

@youknowone youknowone force-pushed the whats_left_utf8 branch 2 times, most recently from ba2c8d5 to 3b7e942 Compare February 17, 2023 21:55
@youknowone
Copy link
Member

also closes #4255

@youknowone youknowone merged commit a5091c5 into RustPython:main Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants