Skip to content
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

Consider always returning python strings instead of c_char_p #7

Open
falkTX opened this issue Mar 24, 2022 · 2 comments
Open

Consider always returning python strings instead of c_char_p #7

falkTX opened this issue Mar 24, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@falkTX
Copy link
Member

falkTX commented Mar 24, 2022

Otherwise makes things a bit confusing to use.
port buffers are void* and need to be casted to their proper type, but strings could in theory just be always converted to/from python types

Opinions welcome

@SpotlightKid
Copy link
Collaborator

I'm not sure what you mean. If a C function has been declared with restype = c_char_p for ctypes, it will already return a bytes string, not a c_char_p instance.

I suppose we could return a str instead, but then we would have to add an encoding parameter to Python functions calling a C function, which returns c_char_p. For example:

def get_version_string(encoding=ENCODING):
    if jlib.jack_get_version_string:
        return _d(jlib.jack_get_version_string(), ENCODING)

    return None

The default value could be either the module global ENCODING (value "utf-8"), as shown here, or None, in which case the functions would still return bytes by default and str only if you pass an encoding name.

Since the encoding keyword parameter would be the last parameter and have a default value, you could still call the function in the same way as before. But changing the default return type to str would of course break backwards compatibility.

@falkTX
Copy link
Member Author

falkTX commented Mar 27, 2022

I meant converting to strings instead of bytes yes.

Is there any valid usecase for returning something other than utf8?
Every single string in jack (and most linux tools) can be assumed to be utf8 unless stated otherwise.
For common calls that return something from jack without user input (like get the version string) the encoding should be set to utf8 without a chance to pick any other, doesnt make sense to me to allow other encodings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants