Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#207 closed enhancement (fixed)

make Cython understand 'size_t' as a native C type

Reported by: dalcinl Owned by: dalcinl
Priority: major Milestone: 0.11
Component: Code Generation Keywords:
Cc:

Attachments (1)

SIZE_T.diff (8.1 KB) - added by dalcinl 6 years ago.

Download all attachments as: .zip

Change History (5)

Changed 6 years ago by dalcinl

comment:1 Changed 6 years ago by scoder

Copying this here from the mailing list:

	static INLINE size_t __pyx_PyInt_AsSize_t(PyObject* b) {
 		 unsigned PY_LONG_LONG val =
				 __pyx_PyInt_AsUnsignedLongLong(b);
 		 if (unlikely(val == (unsigned PY_LONG_LONG)-1 &&
				 PyErr_Occurred())) {
 		       return (size_t)-1;

The (size_t)-1 definitely looks funny. I noticed that (unsigned PY_LONG_LONG)-1 is also used in __pyx_PyInt_AsUnsignedLongLong(), so I just hope it does the right thing.

 		  } else if (unlikely((unsigned PY_LONG_LONG)(size_t)val
							 != val)) {
 		       PyErr_SetString(PyExc_OverflowError, "value too
					 large to convert to size_t");

This should return an error value, so it lacks a return (size_t)-1.

 		  }
 		  return val;
	}

It would be great if we had tests for the error cases. It's not obvious
that they work as expected. The same applies to the "unsigned long long"
conversion, IMHO.

comment:2 Changed 6 years ago by scoder

  • Owner changed from somebody to dalcinl

comment:3 Changed 6 years ago by scoder

  • Resolution set to fixed
  • Status changed from new to closed

comment:4 Changed 6 years ago by scoder

  • Milestone changed from wishlist to 0.11
Note: See TracTickets for help on using tickets.