Staging
v0.5.1
https://github.com/python/cpython
Revision a40c793d06ee2b42a5013015352616b4ca6b288b authored by Tim Peters on 05 September 2001, 22:36:56 UTC, committed by Tim Peters on 05 September 2001, 22:36:56 UTC
requires that errno ever get set, and it looks like glibc is already
playing that game.  New rules:

+ Never use HUGE_VAL.  Use the new Py_HUGE_VAL instead.

+ Never believe errno.  If overflow is the only thing you're interested in,
  use the new Py_OVERFLOWED(x) macro.  If you're interested in any libm
  errors, use the new Py_SET_ERANGE_IF_OVERFLOW(x) macro, which attempts
  to set errno the way C89 said it worked.

Unfortunately, none of these are reliable, but they work on Windows and I
*expect* under glibc too.
1 parent 75ed167
Raw File
Tip revision: a40c793d06ee2b42a5013015352616b4ca6b288b authored by Tim Peters on 05 September 2001, 22:36:56 UTC
Rework the way we try to check for libm overflow, given that C99 no longer
Tip revision: a40c793
bitset.c

/* Bitset primitives used by the parser generator */

#include "pgenheaders.h"
#include "bitset.h"

bitset
newbitset(int nbits)
{
	int nbytes = NBYTES(nbits);
	bitset ss = PyMem_NEW(BYTE, nbytes);
	
	if (ss == NULL)
		Py_FatalError("no mem for bitset");
	
	ss += nbytes;
	while (--nbytes >= 0)
		*--ss = 0;
	return ss;
}

void
delbitset(bitset ss)
{
	PyMem_DEL(ss);
}

int
addbit(bitset ss, int ibit)
{
	int ibyte = BIT2BYTE(ibit);
	BYTE mask = BIT2MASK(ibit);
	
	if (ss[ibyte] & mask)
		return 0; /* Bit already set */
	ss[ibyte] |= mask;
	return 1;
}

#if 0 /* Now a macro */
int
testbit(bitset ss, int ibit)
{
	return (ss[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0;
}
#endif

int
samebitset(bitset ss1, bitset ss2, int nbits)
{
	int i;
	
	for (i = NBYTES(nbits); --i >= 0; )
		if (*ss1++ != *ss2++)
			return 0;
	return 1;
}

void
mergebitset(bitset ss1, bitset ss2, int nbits)
{
	int i;
	
	for (i = NBYTES(nbits); --i >= 0; )
		*ss1++ |= *ss2++;
}
back to top