{-0xfffffffL, 28, -1}};
int i;
- for (i = 0; i < sizeof(testcases) / sizeof(struct triple); ++i) {
+ for (i = 0; i < Py_ARRAY_LENGTH(testcases); ++i) {
PyObject *plong = PyLong_FromLong(testcases[i].input);
size_t nbits = _PyLong_NumBits(plong);
int sign = _PyLong_Sign(plong);
{SIGSEGV, 0, "Segmentation fault", }
};
static const unsigned char faulthandler_nsignals = \
- sizeof(faulthandler_handlers) / sizeof(faulthandler_handlers[0]);
+ Py_ARRAY_LENGTH(faulthandler_handlers);
#ifdef HAVE_SIGALTSTACK
static stack_t stack;
}
/* use lookup table if x is small */
- if (x < (long)(sizeof(SmallFactorials)/sizeof(SmallFactorials[0])))
+ if (x < (long)Py_ARRAY_LENGTH(SmallFactorials))
return PyLong_FromUnsignedLong(SmallFactorials[x]);
/* else express in the form odd_part * 2**two_valuation, and compute as
return self;
}
-static PyObject *
+static PyObject *
oss_exit(PyObject *self, PyObject *unused)
{
PyObject *ret = PyObject_CallMethod(self, "close", NULL);
int num_controls;
int i;
- num_controls = sizeof(control_labels) / sizeof(control_labels[0]);
- assert(num_controls == sizeof(control_names) / sizeof(control_names[0]));
+ num_controls = Py_ARRAY_LENGTH(control_labels);
+ assert(num_controls == Py_ARRAY_LENGTH(control_names));
labels = PyList_New(num_controls);
names = PyList_New(num_controls);
DWORD result;
PyObject *v;
result = GetFullPathNameW(wpath,
- sizeof(woutbuf)/sizeof(woutbuf[0]),
+ Py_ARRAY_LENGTH(woutbuf),
woutbuf, &wtemp);
- if (result > sizeof(woutbuf)/sizeof(woutbuf[0])) {
+ if (result > Py_ARRAY_LENGTH(woutbuf)) {
woutbufp = malloc(result * sizeof(Py_UNICODE));
if (!woutbufp)
return PyErr_NoMemory();
PyUnicode_FSConverter, &opath))
return NULL;
path = PyBytes_AsString(opath);
- if (!GetFullPathName(path, sizeof(outbuf)/sizeof(outbuf[0]),
+ if (!GetFullPathName(path, Py_ARRAY_LENGTH(outbuf),
outbuf, &temp)) {
win32_error("GetFullPathName", path);
Py_DECREF(opath);
cpu_set_repr(Py_cpu_set *set)
{
return PyUnicode_FromFormat("<cpu_set with %li entries>", set->ncpus);
-}
+}
static Py_ssize_t
cpu_set_len(Py_cpu_set *set)
PyObject *result = NULL;
#ifdef MS_WINDOWS
wchar_t user_name[UNLEN + 1];
- DWORD num_chars = sizeof(user_name)/sizeof(user_name[0]);
+ DWORD num_chars = Py_ARRAY_LENGTH(user_name);
if (GetUserNameW(user_name, &num_chars)) {
/* num_chars is the number of unicode chars plus null terminator */
version of the hostname, whereas we need a Unicode string.
Otherwise, gethostname apparently also returns the DNS name. */
wchar_t buf[MAX_COMPUTERNAME_LENGTH + 1];
- DWORD size = sizeof(buf) / sizeof(wchar_t);
+ DWORD size = Py_ARRAY_LENGTH(buf);
PyObject *result;
if (!GetComputerNameExW(ComputerNamePhysicalDnsHostname, buf, &size)) {
if (GetLastError() == ERROR_MORE_DATA) {
DWORD codes[] = {SIO_RCVALL, SIO_KEEPALIVE_VALS};
const char *names[] = {"SIO_RCVALL", "SIO_KEEPALIVE_VALS"};
int i;
- for(i = 0; i<sizeof(codes)/sizeof(*codes); ++i) {
+ for(i = 0; i<Py_ARRAY_LENGTH(codes); ++i) {
PyObject *tmp;
tmp = PyLong_FromUnsignedLong(codes[i]);
if (tmp == NULL)
from Tools/unicode/makeunicodedata.py, it should not be possible
to overflow decomp_prefix. */
prefix_index = decomp_data[index] & 255;
- assert(prefix_index < (sizeof(decomp_prefix)/sizeof(*decomp_prefix)));
+ assert(prefix_index < Py_ARRAY_LENGTH(decomp_prefix));
/* copy prefix */
i = strlen(decomp_prefix[prefix_index]);
break;
}
}
- assert(1 <= x_size &&
- x_size <= (Py_ssize_t)(sizeof(x_digits)/sizeof(digit)));
+ assert(1 <= x_size && x_size <= (Py_ssize_t)Py_ARRAY_LENGTH(x_digits));
/* Round, and convert to double. */
x_digits[0] += half_even_correction[x_digits[0] & 7];
res->ht_type.tp_flags = spec->flags | Py_TPFLAGS_HEAPTYPE;
for (slot = spec->slots; slot->slot; slot++) {
- if (slot->slot >= sizeof(slotoffsets)/sizeof(slotoffsets[0])) {
+ if (slot->slot >= Py_ARRAY_LENGTH(slotoffsets)) {
PyErr_SetString(PyExc_RuntimeError, "invalid slot offset");
goto fail;
}
return PyDict_New();
}
-/*
+/*
Merge the __dict__ of aclass into dict, and recursively also all
the __dict__s of aclass's base classes. The order of merging isn't
defined, as it's expected that only the final set of dict keys is
/* initialize the linebreak bloom filter */
bloom_linebreak = make_bloom_mask(
PyUnicode_2BYTE_KIND, linebreak,
- sizeof(linebreak) / sizeof(linebreak[0]));
+ Py_ARRAY_LENGTH(linebreak));
PyType_Ready(&EncodingMapType);
}
{
// Must go backwards
char **modName;
- for (modName = possibleModules+(sizeof(possibleModules) / sizeof(char *))-2;
+ for (modName = possibleModules+Py_ARRAY_LENGTH(possibleModules)-2;
modName >= possibleModules;
*modName--) {
/* printf("Terminating '%s'\n", *modName);*/
{
// Must go backwards
char **modName;
- for (modName = possibleModules+(sizeof(possibleModules) / sizeof(char *))-2;
+ for (modName = possibleModules+Py_ARRAY_LENGTH(possibleModules)-2;
modName >= possibleModules;
*modName--)
CallModuleDllMain(*modName, DLL_PROCESS_DETACH);
if (keyBuf==NULL) goto done;
memcpy(keyBufPtr, keyPrefix, sizeof(keyPrefix)-sizeof(WCHAR));
- keyBufPtr += sizeof(keyPrefix)/sizeof(WCHAR) - 1;
+ keyBufPtr += Py_ARRAY_LENGTH(keyPrefix) - 1;
mbstowcs(keyBufPtr, PyWin_DLLVersionString, versionLen);
keyBufPtr += versionLen;
/* NULL comes with this one! */
return progpath;
}
-/* Load python3.dll before loading any extension module that might refer
- to it. That way, we can be sure that always the python3.dll corresponding
+/* Load python3.dll before loading any extension module that might refer
+ to it. That way, we can be sure that always the python3.dll corresponding
to this python DLL is loaded, not a python3.dll that might be on the path
by chance.
Return whether the DLL was found.
interp->codec_error_registry = PyDict_New();
if (interp->codec_error_registry) {
- for (i = 0; i < sizeof(methods)/sizeof(methods[0]); ++i) {
+ for (i = 0; i < Py_ARRAY_LENGTH(methods); ++i) {
PyObject *func = PyCFunction_New(&methods[i].def, NULL);
int res;
if (!func)
{L_ERROR_ERRNO, NULL}
};
-#define LOAD_ERRTAB_LEN (sizeof(load_errtab)/sizeof(load_errtab[0]))
#define ERRBUF_APPEND(s) strncat(errbuf, s, sizeof(errbuf)-strlen(errbuf)-1)
PyOS_snprintf(errbuf, sizeof(errbuf), "from module %.200s ", pathname);
}
for(i = 0; message[i] && *message[i]; i++) {
int nerr = atoi(message[i]);
- for (j=0; j<LOAD_ERRTAB_LEN ; j++) {
+ for (j=0; j < Py_ARRAY_LENGTH(load_errtab); j++) {
if (nerr == load_errtab[j].errNo && load_errtab[j].errstr)
ERRBUF_APPEND(load_errtab[j].errstr);
}
the argument must be the full path anyway. */
wchar_t *ptemp;
if (GetFullPathNameW(argv0,
- sizeof(fullpath)/sizeof(fullpath[0]),
+ Py_ARRAY_LENGTH(fullpath),
fullpath,
&ptemp)) {
argv0 = fullpath;