Skip to content

gap: use GAP_IN from kernel API#35861

Merged
vbraun merged 10 commits intosagemath:developfrom
fingolfin:mh/GAP_IN
Jan 14, 2026
Merged

gap: use GAP_IN from kernel API#35861
vbraun merged 10 commits intosagemath:developfrom
fingolfin:mh/GAP_IN

Conversation

@fingolfin
Copy link
Copy Markdown
Contributor

@fingolfin fingolfin commented Jun 30, 2023

... to implement __contains__.

I am basing this on the code for _compare_equal which wraps GAP_EQ. Its use of sig_on etc. differs considerably from e.g. _mul_ which wraps GAP_PROD. I don't know if this has any significance, and which.

Contains PR #35761, once that is merged I'll rebase here. DONE

@fingolfin fingolfin force-pushed the mh/GAP_IN branch 3 times, most recently from 47dfe0b to a538a16 Compare July 3, 2023 06:54
@fchapoton
Copy link
Copy Markdown
Contributor

I am not sure if the finally is ever visited. Better assign the result to some variable and return this afterwards ?

@fingolfin
Copy link
Copy Markdown
Contributor Author

I am not sure if the finally is ever visited.

Isn't that a core part of the Python semantics? Or are you suggesting cython might violate the usual Python semantics there?

@fingolfin
Copy link
Copy Markdown
Contributor Author

Also note that other places in the code use finally just like that, including gap_eval

Comment thread src/sage/libs/gap/element.pyx Outdated
@fingolfin
Copy link
Copy Markdown
Contributor Author

File "src/sage/libs/gap/element.pyx", line 619, in sage.libs.gap.element.GapElement.__contains__
Failed example:
    1 in libgap.eval('Integers')
Exception raised:
    Traceback (most recent call last):
      File "/sage/src/sage/doctest/forker.py", line 696, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/sage/src/sage/doctest/forker.py", line 1106, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.libs.gap.element.GapElement.__contains__[1]>", line 1, in <module>
        Integer(1) in libgap.eval('Integers')
      File "sage/libs/gap/element.pyx", line 635, in sage.libs.gap.element.GapElement.__contains__
        sig_on()
    cysignals.signals.SignalError: Segmentation fault
**********************************************************************
File "src/sage/libs/gap/element.pyx", line 622, in sage.libs.gap.element.GapElement.__contains__
Failed example:
    3 in libgap([1,5,3,2])
Expected:
    True
Got:
    False

So there is a segfault, seemingly on the sig_on added in this PR... I just don't get it.

@fingolfin
Copy link
Copy Markdown
Contributor Author

Oh no, wait, of course facepalm the sig_on shows the error that it caught from the underlying code... and there I am passing in blindly the value other.value, but other might not be a GapElement at all -- indeed in the example it is a Python integer. So I guess I must inspect the other argument and possibly convert it? Hmm, but then again the other functions which call things like GAP_SUM or GAP_LT don't do that either...?!?

@fchapoton
Copy link
Copy Markdown
Contributor

I am not sure if the finally is ever visited.

Isn't that a core part of the Python semantics? Or are you suggesting cython might violate the usual Python semantics there?

your are right:

https://docs.python.org/fr/3/reference/compound_stmts.html#finally-clause

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 10, 2023

Documentation preview for this PR (built with commit 0096442; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

... to implement `__contains__`.

I am basing this on the code for `_compare_equal` which wraps `GAP_EQ`.
Its use of `sig_on` etc. differs considerably from e.g. `_mul_` which
wraps `GAP_PROD`. I don't know if this has any significance, and which.
@fchapoton fchapoton self-assigned this Jan 3, 2026
@fchapoton
Copy link
Copy Markdown
Contributor

fchapoton commented Jan 7, 2026

@fingolfin : I have fixed things and it now works. Do you think it looks good ?

@fingolfin
Copy link
Copy Markdown
Contributor Author

I couldn't say, I don't know enough about the Sage side. The bits I understand seems fine. If it works, it works...

@fchapoton
Copy link
Copy Markdown
Contributor

ok, thanks. So let's run the CI once again and then I will set to positive

vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 8, 2026
sagemathgh-35861: gap: use GAP_IN from kernel API
    
... to implement `__contains__`.

I am basing this on the code for `_compare_equal` which wraps `GAP_EQ`.
Its use of `sig_on` etc. differs considerably from e.g. `_mul_` which
wraps `GAP_PROD`. I don't know if this has any significance, and which.

<s>Contains PR sagemath#35761, once that is merged I'll rebase here.</s> DONE
    
URL: sagemath#35861
Reported by: Max Horn
Reviewer(s): Max Horn
vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 13, 2026
sagemathgh-35861: gap: use GAP_IN from kernel API
    
... to implement `__contains__`.

I am basing this on the code for `_compare_equal` which wraps `GAP_EQ`.
Its use of `sig_on` etc. differs considerably from e.g. `_mul_` which
wraps `GAP_PROD`. I don't know if this has any significance, and which.

<s>Contains PR sagemath#35761, once that is merged I'll rebase here.</s> DONE
    
URL: sagemath#35861
Reported by: Max Horn
Reviewer(s): Max Horn
@vbraun vbraun merged commit 4f1f86f into sagemath:develop Jan 14, 2026
22 of 24 checks passed
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.

3 participants