gh-135748: Use Argument Clinic for more socket functions - #155257
Open
serhiy-storchaka wants to merge 6 commits into
Open
gh-135748: Use Argument Clinic for more socket functions#155257serhiy-storchaka wants to merge 6 commits into
serhiy-storchaka wants to merge 6 commits into
Conversation
Convert all convertible functions and methods of the socket module. They now have signatures for introspection, and functions which take several arguments use METH_FASTCALL instead of METH_VARARGS. ioctl(), sendto() and setsockopt() are left as they are. Their behaviour depends on the number of the arguments or on the value of a preceding argument, which Argument Clinic cannot express.
| PyMutex_Unlock(&netdb_lock); | ||
| #endif | ||
| finally: | ||
| PyMem_Free(ip_num); |
Contributor
There was a problem hiding this comment.
The memory still needs to be freed right?
| if (iv.buf != NULL) { | ||
| PyBuffer_Release(&iv); | ||
| } | ||
| if (iv->buf != NULL) { |
| /*[clinic input] | ||
| _socket.socket.setblocking | ||
| self as s: self(type="PySocketSockObject *") | ||
| flag as arg: object |
Contributor
There was a problem hiding this comment.
This could use bool converter directly
Restore freeing the buffer allocated by the "et" format in gethostbyaddr(), remove the empty block left after the Py_buffer converter took over releasing the initialization vector in sendmsg_afalg(), and use the bool converter in setblocking().
Restore the AF_INET default family of socketpair() on platforms which do not define AF_UNIX, and the note about os.close() and os.dup() in the docstrings of close() and dup(). Remove the preprocessor guards around the METHODDEF macros of the functions generated by Argument Clinic: such macro is empty if the function is not compiled.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Convert all convertible functions and methods of the socket module to Argument Clinic. They now have signatures for introspection, and functions which take several arguments use
METH_FASTCALLinstead ofMETH_VARARGS.The number of
_socketcallables for whichinspect.signature()fails drops from 26 to 7. Five of those seven are deliberate:listen()(the default isPy_MIN(SOMAXCONN, 128)),getservbyname()andgetservbyport()(the C default isNULLandNoneis not accepted),sendmsg()andsendmsg_afalg()(arguments which are absent rather than defaulted).ioctl(),sendto()andsetsockopt()are left as they are. Their behaviour depends on the number of the arguments or on the value of a preceding argument, which Argument Clinic cannot express:sendto(data[, flags], address)-- the optional argument is in the middle, while optional groups only support[left] required [right].setsockopt()distinguishes 3 from 4 arguments withPyTuple_Size(), and both resulting error messages are asserted bytest_socket.ioctl()parses its second argument differently depending oncmd.The parameter names are taken from the existing docstrings. Seven of them differ from
Doc/library/socket.rst(for examplerecv(buffersize)versus the documentedbufsize); the documentation is left unchanged here.