Skip to content

Conversation

@da-woods
Copy link
Contributor

#3925

This is a corner-case mostly to silence C warnings. It can happen
with strings created manually (i.e. not by Cython) using the deprecated
C-API on Python 3.9+

I haven't added a test since it seems quite hard to construct a
string that fails it

cython#3925

This is a corner-case mostly to silence C warnings. It can happen
with strings created manually (i.e. not by Cython) using the deprecated
C-API on Python 3.9+

I haven't added a test since it seems quite hard to construct a
string that fails it
@da-woods
Copy link
Contributor Author

The alternative would be to fall back to PyUnicode_FindChar or PyUnicode_Contains on the understanding that this would be a rarely used slow path. Both of these would require Python error handling (in a function that isn't supposed to return exceptions)

Comment on lines +179 to +180
/* This should only happen if the user has manually created a non-PEP393 string
* (i.e. it's very unlikely)
Copy link
Contributor

@scoder scoder Apr 24, 2021

Choose a reason for hiding this comment

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

wchar strings are actually a common thing on Windows, where that's kind-of the native system Unicode string type. Windows file names fall into that category, for example. "\\" in file_path could possibly get you here.

@scoder
Copy link
Contributor

scoder commented Apr 24, 2021

The right fallback is probably what already follows just below for the pre-3.9 case, except that we'd have to use wchar_t instead of Py_UNICODE.

@da-woods
Copy link
Contributor Author

The right fallback is probably what already follows just below for the pre-3.9 case, except that we'd have to use wchar_t instead of Py_UNICODE.

That still requires PyUnicode_AS_UNICODE - there doesn't seem to be a way to access the data as wchar_t instead of Py_UNICODE.

That suggests to me that the right thing to do is revert 3363638 but wrap the whole thing in

#pragma GCC diagnostic push  // works for clang too
#prgama GCC diagnostic ignored "-Wdeprecated"

// code...

#pragma GCC diagnostic pop

(just to make the warnings go away.) Possibly with something similar for MSVC too.

@scoder
Copy link
Contributor

scoder commented Apr 24, 2021

Actually, WCHAR_KIND is already scheduled for removal in Py3.12 and PyUnicode_IS_READY() as well. I'll see if I can come up with something reasonable here.

@scoder
Copy link
Contributor

scoder commented Apr 24, 2021

See #4135 for an attempt to make this more future proof.

@scoder
Copy link
Contributor

scoder commented Apr 25, 2021

Superseded by #4135.

@scoder scoder closed this Apr 25, 2021
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.

2 participants