Skip to content

use getptr a lot less #618

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 12 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ on:

jobs:
julia:
name: Test (${{ matrix.os }}, julia ${{ matrix.jlversion }})
name: Test Julia (${{ matrix.jlversion }} on ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
fail-fast: false
matrix:
arch: [x64] # x86 unsupported by MicroMamba
os: [ubuntu-latest, windows-latest, macos-latest]
Expand Down Expand Up @@ -50,13 +50,13 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

python:
name: Test (${{ matrix.os }}, python ${{ matrix.pyversion }})
name: Test Python (${{ matrix.pyversion }} on ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
pyversion: [">=3.8", "3.8"]
pyversion: ["3", "3.13.2", "3.13.1", "3.13.0", "3.12", "3.8"]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -93,8 +93,15 @@ jobs:
uv run pytest -s --nbval --cov=pysrc ./pytest/
env:
PYTHON_JULIACALL_THREADS: '2'
PYTHON_JULIACALL_HANDLE_SIGNALS: 'yes'

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Setup tmate session on failure
uses: mxschmitt/action-tmate@v3
if: ${{ failure() }}
with:
limit-access-to-actor: true
4 changes: 2 additions & 2 deletions pytest/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def test_issue_433():
def test_julia_gc():
from juliacall import Main as jl

if jl.seval('v"1.11.0-" <= VERSION < v"1.11.3"'):
# Seems to be a Julia bug - hopefully fixed in 1.11.3
if jl.seval('v"1.11.0-" <= VERSION < v"1.11.6"'):
# Seems to be a Julia bug - hopefully fixed in 1.11.6
pytest.skip("Test not yet supported on Julia 1.11+")

# We make a bunch of python objects with no reference to them,
Expand Down
3 changes: 3 additions & 0 deletions src/JlWrap/C.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function _pyjl_callmethod(o::C.PyPtr, args::C.PyPtr)
end

const PYJLBUFCACHE = Dict{Ptr{Cvoid},Any}()
const PYJLBUFCACHE_DEBUG = []

@kwdef struct PyBufferInfo{N}
# data
Expand Down Expand Up @@ -177,7 +178,9 @@ function _pyjl_get_buffer_impl(

# internal
cptr = Base.pointer_from_objref(c)
@assert !haskey(PYJLBUFCACHE, cptr)
PYJLBUFCACHE[cptr] = c
push!(PYJLBUFCACHE_DEBUG, c)
b.internal[] = cptr

# obj
Expand Down
18 changes: 0 additions & 18 deletions src/Utils/Utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,6 @@ function explode_union(T)
end
end

"""
pointer_from_obj(x)

Returns `(p, c)` where `Base.pointer_from_objref(p) === x`.

The pointer remains valid provided the object `c` is not garbage collected.
"""
function pointer_from_obj(o::T) where {T}
if T.mutable
c = o
p = Base.pointer_from_objref(o)
else
c = Ref{Any}(o)
p = unsafe_load(Ptr{Ptr{Cvoid}}(Base.pointer_from_objref(c)))
end
p, c
end

"""
ExtraNewline(x)

Expand Down
Loading