great include cleanup
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#include "likely.h"
|
||||
#include <libowfat/compiler.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include "safemult.h"
|
||||
#include "array.h"
|
||||
#include "byte.h"
|
||||
#include <libowfat/safemult.h>
|
||||
#include <libowfat/array.h>
|
||||
#include <libowfat/byte.h>
|
||||
|
||||
#if 0
|
||||
static array x;
|
||||
@@ -46,26 +46,26 @@
|
||||
|
||||
void* array_allocate(array* x,uint64 membersize,int64 pos) {
|
||||
uint64 wanted;
|
||||
if (__unlikely(x->allocated<0)) return 0; /* array is failed */
|
||||
if (__unlikely(pos+1<1)) return 0;
|
||||
if (unlikely(x->allocated<0)) return 0; /* array is failed */
|
||||
if (unlikely(pos+1<1)) return 0;
|
||||
/* second case of overflow: pos*membersize too large */
|
||||
if (__unlikely(!umult64(membersize,pos+1,&wanted))) return 0;
|
||||
if (unlikely(!umult64(membersize,pos+1,&wanted))) return 0;
|
||||
|
||||
if (wanted > (uint64)x->initialized) {
|
||||
if (__unlikely(wanted >= (uint64)x->allocated)) {
|
||||
if (unlikely(wanted >= (uint64)x->allocated)) {
|
||||
/* round up a little */
|
||||
if (membersize<8)
|
||||
wanted=(wanted+127)&(-128ll); /* round up to multiple of 128 */
|
||||
else
|
||||
wanted=(wanted+4095)&(-4096ll); /* round up to 4k pages */
|
||||
|
||||
if (__unlikely(wanted<128)) return 0; /* overflow during rounding */
|
||||
if (unlikely(wanted<128)) return 0; /* overflow during rounding */
|
||||
|
||||
if (sizeof(size_t) != sizeof(int64) && __unlikely((size_t)(wanted) != wanted))
|
||||
if (sizeof(size_t) != sizeof(int64) && unlikely((size_t)(wanted) != wanted))
|
||||
return 0;
|
||||
{
|
||||
char* tmp=realloc(x->p,wanted);
|
||||
if (__unlikely(!tmp)) return 0;
|
||||
if (unlikely(!tmp)) return 0;
|
||||
x->p=tmp;
|
||||
}
|
||||
x->allocated=wanted;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "array.h"
|
||||
#include <libowfat/array.h>
|
||||
|
||||
int64 array_bytes(const array* const x) {
|
||||
if (x->allocated<0) return -1;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "array.h"
|
||||
#include "byte.h"
|
||||
#include <libowfat/array.h>
|
||||
#include <libowfat/byte.h>
|
||||
|
||||
void array_cat(array* to,const array* const from) {
|
||||
if (from->allocated<0) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "array.h"
|
||||
#include <libowfat/array.h>
|
||||
|
||||
void array_cat0(array* to) {
|
||||
static char zero;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "array.h"
|
||||
#include "byte.h"
|
||||
#include <libowfat/array.h>
|
||||
#include <libowfat/byte.h>
|
||||
|
||||
void array_catb(array* to,const char* from,uint64 len) {
|
||||
long l;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "array.h"
|
||||
#include <libowfat/array.h>
|
||||
|
||||
void array_cate(array* to,const array* const from,int64 pos,int64 stop) {
|
||||
if (pos<0 || stop<pos) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "array.h"
|
||||
#include "str.h"
|
||||
#include <libowfat/array.h>
|
||||
#include <libowfat/str.h>
|
||||
|
||||
void array_cats(array* to,const char* from) {
|
||||
array_catb(to,from,str_len(from));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "array.h"
|
||||
#include "str.h"
|
||||
#include <libowfat/array.h>
|
||||
#include <libowfat/str.h>
|
||||
|
||||
void array_cats0(array* to,const char* from) {
|
||||
array_catb(to,from,str_len(from)+1);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "byte.h"
|
||||
#include "array.h"
|
||||
#include <libowfat/array.h>
|
||||
#include <libowfat/byte.h>
|
||||
|
||||
int array_equal(const array* const x,const array* const y) {
|
||||
if (x->initialized!=y->initialized) return 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include "array.h"
|
||||
#include <libowfat/array.h>
|
||||
|
||||
void array_fail(array* x) {
|
||||
if (x->p) free(x->p);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "likely.h"
|
||||
#include "safemult.h"
|
||||
#include "array.h"
|
||||
#include <libowfat/compiler.h>
|
||||
#include <libowfat/safemult.h>
|
||||
#include <libowfat/array.h>
|
||||
|
||||
#if 0
|
||||
static array x;
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
void* array_get(const array* const x,uint64 membersize,int64 pos) {
|
||||
uint64 wanted;
|
||||
if (__unlikely(pos+1<1)) return 0;
|
||||
if (__unlikely(!umult64(membersize,pos,&wanted))) return 0;
|
||||
if (unlikely(pos+1<1)) return 0;
|
||||
if (unlikely(!umult64(membersize,pos,&wanted))) return 0;
|
||||
|
||||
if (__unlikely((int64)wanted >= x->allocated || wanted>=x->initialized)) return 0;
|
||||
if (unlikely((int64)wanted >= x->allocated || wanted>=x->initialized)) return 0;
|
||||
return (void*)(x->p+pos*membersize);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "array.h"
|
||||
#include <libowfat/array.h>
|
||||
|
||||
int64 array_length(const array* const x,uint64 membersize) {
|
||||
if (x->allocated<0) return -1;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include "array.h"
|
||||
#include <libowfat/array.h>
|
||||
|
||||
void array_reset(array* x) {
|
||||
if (x->p) free(x->p);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "array.h"
|
||||
#include <libowfat/array.h>
|
||||
|
||||
void* array_start(const array* const x) {
|
||||
return x->p;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "array.h"
|
||||
#include <libowfat/array.h>
|
||||
|
||||
void array_trunc(array* x) {
|
||||
x->initialized=0;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "likely.h"
|
||||
#include "safemult.h"
|
||||
#include "array.h"
|
||||
#include <libowfat/compiler.h>
|
||||
#include <libowfat/safemult.h>
|
||||
#include <libowfat/array.h>
|
||||
|
||||
/* I'm not sure I understand what this function is good for */
|
||||
void array_truncate(array* x,uint64 membersize,int64 len) {
|
||||
uint64 wanted;
|
||||
if (__unlikely(len<0)) return;
|
||||
if (__unlikely(!umult64(membersize,len,&wanted))) return;
|
||||
if (__unlikely(wanted > x->initialized)) return;
|
||||
if (unlikely(len<0)) return;
|
||||
if (unlikely(!umult64(membersize,len,&wanted))) return;
|
||||
if (unlikely(wanted > x->initialized)) return;
|
||||
x->initialized=wanted;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#include "likely.h"
|
||||
#include <stdlib.h>
|
||||
#ifndef _WIN32
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "iarray.h"
|
||||
#include <libowfat/iarray.h>
|
||||
#ifdef __dietlibc__
|
||||
#include <sys/atomic.h>
|
||||
#else
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "iarray.h"
|
||||
#include <libowfat/iarray.h>
|
||||
|
||||
static void freechain(iarray_page* p,size_t pagesize) {
|
||||
while (p) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "iarray.h"
|
||||
#include <libowfat/iarray.h>
|
||||
|
||||
void* iarray_get(iarray* ia,size_t pos) {
|
||||
size_t index;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "iarray.h"
|
||||
#include <libowfat/iarray.h>
|
||||
|
||||
void iarray_init(iarray* ia,size_t elemsize) {
|
||||
size_t i;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "iarray.h"
|
||||
#include <libowfat/iarray.h>
|
||||
|
||||
size_t iarray_length(iarray* ia) {
|
||||
return ia->len;
|
||||
|
||||
Reference in New Issue
Block a user