static PyObject* cross_correlate(PyObject* self, PyObject* args) { // Parse the args const char* my_spc_filename; if (!PyArg_ParseTuple(args, "sii", &my_spc_filename, &start_channel, &stop_channel)) { return NULL; } printf("Cross-correlating on %s (START: %d / STOP: %d)\n", my_spc_filename, start_channel, stop_channel); // Reset count rates, etc int i; fifo_gap=0; histogram = malloc(sizeof(int)*histogram_bins); for (i=0; i<histogram_bins; i+=1) { histogram[i]=0; } // Open the file spc_file=fopen(my_spc_filename, "rb"); if (spc_file==0) { return NULL; } // Examine all of the photons in the file. int finished=0; grab_chunk(); while (nrecords>0 && finished!=-1) { finished=split_channels(); process_chunk(0); process_chunk(1); if (finished!=-1) { grab_chunk(); } } // Close the SPC file, prepare the data, free memory and return fclose(spc_file); PyObject* output = build_output_dict(); free(histogram); return output; }
/* get_memory -- grab one or more pages from the operating system */ static void *get_memory(unsigned size) { unsigned alloc_size = round_up(size, GC_PAGESIZE); void *p; /* This happens e.g. if custom translation makes the code size zero */ if (alloc_size == 0) return NULL; p = grab_chunk(alloc_size); if (p == NULL) panic("out of memory"); ASSERT((unsigned) p % GC_PAGESIZE == 0); DEBUG_PRINT('b', ("Allocated chunk at %p\n", p)); return p; }