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

gh-106320: Remove private _PyDict function #108449

Merged
merged 2 commits into from Aug 24, 2023
Merged

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Aug 24, 2023

Move private _PyDict functions to the internal C API (pycore_dict.h):

  • _PyDictView_Intersect()
  • _PyDictView_New()
  • _PyDict_ContainsId()
  • _PyDict_DelItemId()
  • _PyDict_DelItem_KnownHash()
  • _PyDict_GetItemIdWithError()
  • _PyDict_GetItem_KnownHash()
  • _PyDict_HasSplitTable()
  • _PyDict_NewPresized()
  • _PyDict_Next()
  • _PyDict_Pop()
  • _PyDict_SetItemId()
  • _PyDict_SetItem_KnownHash()
  • _PyDict_SizeOf()

No longer export most of these functions.

Move also the _PyDictViewObject to the internal C API.

Move dict_getitem_knownhash() function from _testcapi to the _testinternalcapi extension. Update test_capi.test_dict for this move.

Move private _PyDict functions to the internal C API (pycore_dict.h):

* _PyDictView_Intersect()
* _PyDictView_New()
* _PyDict_ContainsId()
* _PyDict_DelItemId()
* _PyDict_DelItem_KnownHash()
* _PyDict_GetItemIdWithError()
* _PyDict_GetItem_KnownHash()
* _PyDict_HasSplitTable()
* _PyDict_NewPresized()
* _PyDict_Next()
* _PyDict_Pop()
* _PyDict_SetItemId()
* _PyDict_SetItem_KnownHash()
* _PyDict_SizeOf()

No longer export most of these functions.

Move also the _PyDictViewObject to the internal C API.

Move dict_getitem_knownhash() function from _testcapi to the
_testinternalcapi extension. Update test_capi.test_dict for this
move.
@vstinner vstinner enabled auto-merge (squash) August 24, 2023 19:38
@vstinner vstinner merged commit 2689301 into python:main Aug 24, 2023
20 checks passed
@vstinner vstinner deleted the pycore_dict2 branch August 24, 2023 23:23
@eendebakpt
Copy link
Contributor

@vstinner In this PR the method _PyDict_NewPresized was moved to the internal API. According to https://devguide.python.org/developer-workflow/c-api/#with-the-extern-keyword the method should still be available for stdlib extensions.

I am using the method in an extension module #91610, but the build is failing since this PR was merged with error message Error: _copy failed to import: /home/runner/work/cpython/cpython-builddir/build/lib.linux-x86_64-3.13-pydebug/_copy.cpython-313d-x86_64-linux-gnu.so: undefined symbol: _PyDict_NewPresized (but the build is successful for Windows platforms).

I added the correct header file #include "pycore_dict.h" and macros Py_BUILD_CORE_MODULE and Py_BUILD_CORE_BUILTIN. What else needs to be done to make use of _PyDict_NewPresized?

@vstinner
Copy link
Member Author

I am using the method in an extension module #91610, but the build is failing since this PR was merged with error message Error: _copy failed to import: /home/runner/work/cpython/cpython-builddir/build/lib.linux-x86_64-3.13-pydebug/_copy.cpython-313d-x86_64-linux-gnu.so: undefined symbol: _PyDict_NewPresized (but the build is successful for Windows platforms).

If you want to use this function in a stdlib extension, you should replace extern with PyAPI_FUNC(). It's required to be able to use the function in extensions built as shared libraries.

scoder added a commit to scoder/cpython that referenced this pull request Oct 24, 2023
scoder added a commit to scoder/cpython that referenced this pull request Oct 24, 2023
scoder added a commit to scoder/cpython that referenced this pull request Oct 24, 2023
scoder added a commit to scoder/cpython that referenced this pull request Oct 24, 2023
scoder added a commit to scoder/cpython that referenced this pull request Oct 24, 2023
scoder added a commit to scoder/cpython that referenced this pull request Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants