Ticket #207 (closed enhancement: fixed)

Opened 6 years ago

Last modified 6 years ago

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

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

Change History

Changed 6 years ago by dalcinl

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.

Changed 6 years ago by scoder

  • owner changed from somebody to dalcinl

Changed 6 years ago by scoder

  • status changed from new to closed
  • resolution set to fixed

Changed 6 years ago by scoder

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