Ticket #399 (closed enhancement: fixed)

Opened 5 years ago

Last modified 4 years ago

Let ssize_t be a native type.

Reported by: robertwb Owned by: dalcinl
Priority: major Milestone: 0.13
Component: Parsing Keywords:
Cc: haoyu

Description

We support size_t, we should support ssize_t as well.

Attachments

add_ssize_t.patch Download (5.2 KB) - added by haoyu 4 years ago.
Patch to add ssize_t, includes a test case

Change History

Changed 4 years ago by scoder

  • type changed from defect to enhancement

Changed 4 years ago by robertwb

  • milestone changed from 0.12 to 0.12.1

Changed 4 years ago by robertwb

  • milestone changed from 0.12.1 to 0.13

Changed 4 years ago by haoyu

Patch to add ssize_t, includes a test case

Changed 4 years ago by haoyu

  • cc haoyu added

Changed 4 years ago by scoder

I didn't test the patch, but it looks good at a quick glance.

Changed 4 years ago by robertwb

It may be worth creating the PyObject? module name at module load time (do we do that already), and simply re-using that, rather than re-creating it for every function.

Changed 4 years ago by robertwb

Oops, I was talking about #422

Changed 4 years ago by dagss

I'm worried about the 1 << 31 etc. in the testcases -- will the testcases only work on 32 bit machines?

You can check "sizeof(ssize_t)" and generate the docstring conditionally on that.

Changed 4 years ago by dalcinl

  • owner changed from somebody to dalcinl

Pushed:  http://hg.cython.org/cython-devel/rev/1a9bfb4ff18a Tested: Linux32/64 and Windows32 (MSVC and MinGW)

Comments: 'ssize_t' is not a C99 standard type. If available, core Python(>2.4) defines Py_ssize_t to ssize_t. If ssize_t is not available, then any Cython code using ssize_t will fail at C compile time. I do not think we should #define or typedef ssize_t if it is missing, but raise your voice if you do not agree. For Py>=2.5, detecting a missing ssize_t is trivial (macro available pyconfig.h) and then we could conditionally "#define ssize_t Py_ssize_t" (or ptrdiff_t).

For older Python(<2.5), the to_py/from_py conversions will end-up being performed with the PyInt?_{As|From}Long() functions, so things will be fine for Linux{32|64}, Windows32, and not sure what happens on OS X 32/64.

PS: From the list of mayor platforms, Win64 is the only one where things are broken for Py<2.5 . Provided that full 64bits support was introduced in Py2.5, I do not actually care too much. If anyone complains about this, I'll politely ask her to donate a Win64 license ;-) in order to support Cython development.

Changed 4 years ago by dalcinl

  • status changed from new to closed
  • resolution set to fixed
  • summary changed from [easy] Let ssize_t be a native type. to Let ssize_t be a native type.

In Cython-Dev was agreed that 'ssize_t' in Cython should mean 'Py_ssize_t' in C.

 http://hg.cython.org/cython-devel/rev/bc1e09f2fef7

Note: See TracTickets for help on using tickets.