Opened 7 years ago

Closed 7 years ago

#13803 closed enhancement (wontfix)

Python binding to limits.h

Reported by: vdelecroix Owned by: jason
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: misc Keywords: limits, C datatype
Cc: sstarosta Merged in:
Authors: Reviewers: Leif Leonhardy, Vincent Delecroix
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

Prior to #12224 we need to know what C types limits. The patch provides a direct Python access to limits.h.

Attachments (1)

trac_13803-limits.patch (5.5 KB) - added by vdelecroix 7 years ago.

Download all attachments as: .zip

Change History (12)

Changed 7 years ago by vdelecroix

comment:1 Changed 7 years ago by vdelecroix

  • Status changed from new to needs_review

comment:2 Changed 7 years ago by sstarosta

  • Cc sstarosta added

comment:3 Changed 7 years ago by leif

s/Mimimum/Minimum/ (once)

s/a C long long max/a C long long int/

Not sure whether the doctests make sense when they're all tagged # random...

We also have things like sys.maxint, a couple of (size-related) definitions from distutils.sysconfig.get_config_var[s](), and os.sysconf().

The values don't vary much on the platforms supported by Sage; AFAIK there are currently only differences depending on whether we're on a 32- or 64-bit operating system, or, more precisely, whether Sage was built 32-bit or 64-bit (as one could in principle run a 32-bit binary dist on a 64-bit OS, or even build and run a 32-bit version on a 64-bit OS, e.g. Solaris). It would IMHO make sense to get a doctest error in case some results are unexpected.

comment:4 Changed 7 years ago by leif

P.S.: In the docstrings, I'd typeset the C types monospaced, e.g. ``unsigned long int``.

comment:5 Changed 7 years ago by leif

  • Reviewers set to Leif Leonhardy
  • Status changed from needs_review to needs_work

P.P.S.:

LLONG_* and ULLONG_* of course require C99, so you have to add extra_compile_args = ['-std=c99'] to the module_list.py entry. (There are systems on which GCC does not default to -std=gnu99.)

comment:6 Changed 7 years ago by vdelecroix

Thanks very much (I am not at all a specialist but I need to call char_max() in some constructor).

Is the following a safe test ?

sage: from sage.misc.limits import int_min
sage: int_min() # random (architecture and platform dependence)
-2147483648
sage: import sysconfig
sage: s = sysconfig.get_config_var('SIZEOF_INT')
sage: int_min() == - 2**(s*8-1)
True

Best, Vincent

comment:7 Changed 7 years ago by jason

It seems that this would be a valuable upstream Cython contribution as well.

In fact, isn't this it? https://github.com/cython/cython/blob/master/Cython/Includes/libc/limits.pxd

Maybe this patch would be cleaner if you did:

from libc cimport limits

at the top and then used limits.<whatever>? Or maybe not. It's a suggestion.

Last edited 7 years ago by jason (previous) (diff)

comment:8 follow-up: Changed 7 years ago by jdemeyer

It seems that #12224 doesn't require this, nor does it seem needed since it's in Cython as Jason mentioned.

comment:9 in reply to: ↑ 8 Changed 7 years ago by vdelecroix

  • Milestone changed from sage-5.10 to sage-duplicate/invalid/wontfix

Replying to jdemeyer:

It seems that #12224 doesn't require this, nor does it seem needed since it's in Cython as Jason mentioned.

You are right. Not anymore.

comment:10 Changed 7 years ago by jdemeyer

  • Authors Vincent Delecroix deleted
  • Reviewers changed from Leif Leonhardy to Leif Leonhardy, Vincent Delecroix
  • Status changed from needs_work to positive_review

comment:11 Changed 7 years ago by jdemeyer

  • Resolution set to wontfix
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.