Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14-dev']
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14', '3.15-dev']
steps:
- uses: actions/checkout@v5
- name: Get history and tags for SCM versioning to work
Expand Down
29 changes: 24 additions & 5 deletions atom/src/methodwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
#include <cppy/cppy.h>

#if PY_VERSION_HEX < 0x030D0000
// Can be removed when Python < 3.13 is no longer supported
static inline int PyWeakref_GetRef(PyObject *ref, PyObject **pobj) {
PyObject *obj = PyWeakref_GET_OBJECT(ref);
*pobj = obj;
Py_XINCREF(*pobj);
return 1;
}
#endif

#include "methodwrapper.h"
#include "catom.h"
#include "catompointer.h"
#include "packagenaming.h"


namespace atom
{

Expand All @@ -38,10 +48,12 @@ MethodWrapper_dealloc( MethodWrapper* self )
PyObject*
MethodWrapper__call__( MethodWrapper* self, PyObject* args, PyObject* kwargs )
{
PyObject* im_self = PyWeakref_GET_OBJECT( self->im_selfref );
PyObject* raw_im_self = nullptr;
PyWeakref_GetRef( self->im_selfref, &raw_im_self );
cppy::ptr im_self( raw_im_self );
if( im_self != Py_None )
{
cppy::ptr method( PyMethod_New( self->im_func, im_self ) );
cppy::ptr method( PyMethod_New( self->im_func, im_self.get() ) );
if( !method )
return 0;
return PyObject_Call( method.get(), args, kwargs );
Expand All @@ -57,8 +69,12 @@ MethodWrapper_richcompare( MethodWrapper* self, PyObject* other, int op )
{
if( PyMethod_Check( other ) && PyMethod_GET_SELF( other ) )
{
PyObject* raw_im_self = nullptr;
PyWeakref_GetRef( self->im_selfref, &raw_im_self );
cppy::ptr im_self( raw_im_self ); // Automatically handles DECREF when exiting scope

if( ( self->im_func == PyMethod_GET_FUNCTION( other ) ) &&
( PyWeakref_GET_OBJECT( self->im_selfref ) == PyMethod_GET_SELF( other ) ) )
( im_self.get() == PyMethod_GET_SELF( other ) ) )
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
Expand All @@ -80,7 +96,10 @@ MethodWrapper_richcompare( MethodWrapper* self, PyObject* other, int op )
int
MethodWrapper__bool__( MethodWrapper* self )
{
if( PyWeakref_GET_OBJECT( self->im_selfref ) != Py_None )
PyObject* raw_im_self = nullptr;
PyWeakref_GetRef( self->im_selfref, &raw_im_self );
cppy::ptr im_self( raw_im_self );
if( im_self.get() != Py_None )
return 1;
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: 3.15",
"Programming Language :: Python :: Implementation :: CPython",
]
dependencies = ["typing_extensions;python_version<'3.11'"]
Expand Down
Loading