Beispiel #1
0
void en_socket_datagram_connect (EIF_INTEGER fd, EIF_INTEGER fd1, EIF_POINTER sockaddr) {

	SOCKETADDRESS* him;
	int family;
	EIF_INTEGER fdc = -1;
	int ipv6_supported;
	int connect_res;

	EIF_NET_INITIALIZE;

	ipv6_supported = en_ipv6_available();

	him = (SOCKETADDRESS*) sockaddr;
	family = him->him.sa_family; 

	if (family == AF_INET6 && !ipv6_supported) {
		eraise ("Protocol family not supported", EN_PROG);
		return;
	}
    	
	fdc = (family == AF_INET? fd: fd1);
	connect_res = connect(fdc, (struct sockaddr *)him, SOCKETADDRESS_LEN(him));
	if ( connect_res == -1) {
    		eraise("Unable to establish connection", EN_PROG);
	}
}
Beispiel #2
0
rt_private void parsing_store_write(size_t size)
{
	RT_GET_CONTEXT
	char* cmps_out_ptr = cmps_general_buffer;
	lzo_uint cmps_out_size = (lzo_uint) cmp_buffer_size;
	int signed_cmps_out_size;
	
	REQUIRE("cmp_buffer_size not too big", cmp_buffer_size <= 0x7FFFFFFF);
	REQUIRE("size not too big", size <= 0x7FFFFFFF);

	lzo1x_1_compress (
					(unsigned char *) general_buffer,		/* Current buffer location */
					(lzo_uint) size,	/* Current buffer size */
					(unsigned char *) cmps_out_ptr,		/* Output buffer for compressed data */
					&cmps_out_size,		/* Size of output buffer and then size of compressed data */
					wrkmem);			/* Memory allocator */

	signed_cmps_out_size = (int) cmps_out_size;

		/* Write size of compressed data */
	if (parsing_char_write ((char *) &signed_cmps_out_size, sizeof(int)) <= 0)
		eraise ("Unable to write compressed data size", EN_IO);

		/* Write compressed data */
	if (parsing_char_write (cmps_out_ptr, signed_cmps_out_size) <= 0)
		eraise ("Unable to write on specified device", EN_IO);
}
Beispiel #3
0
EIF_INTEGER en_socket_datagram_rcv_from (EIF_INTEGER fd, EIF_INTEGER fd1, EIF_INTEGER *a_last_fd, EIF_POINTER buf, EIF_INTEGER len, EIF_INTEGER flags, EIF_INTEGER timeout, SOCKETADDRESS *him) {

	int nsockets = 0;
	int fduse = 0;
	int result;
	int lenn = sizeof(SOCKETADDRESS);
	int ipv6_supported = en_ipv6_available();

	if (fd > 0) {
		nsockets++;
	}
	if (fd1 > 0) {
		nsockets++;
	}
    	if (nsockets == 2) { /* need to choose one of them */
		int ret, t = (timeout == 0) ? -1: timeout;
		ret = net_timeout2 (fd, fd1, t, &fduse);
		if (ret == 2) {
			fduse = check_last_fd (a_last_fd, fd, fd1);
		} else if (ret == 0) {
			if (ret == 0) {
				eraise("Receive timed out", EN_PROG);
			} else {
				eraise("Receive error", EN_PROG);
			}
			return -1;
		}

	} else if (!ipv6_supported) {
		fduse = fd;
	} else if (fd >= 0) {
		/* ipv6 supported: and this socket bound to an IPV6 only address */
		fduse = fd1;
	} else {
		/* ipv6 supported: and this socket bound to an IPV4 only address */
		fduse = fd;
	}

	if (timeout && nsockets == 1) {
		int ret;
		ret = net_timeout(fduse, timeout);
		if (ret <= 0) {
			if (ret == 0) {
				eraise("Receive timed out", EN_PROG);
			} else {
				eraise("Receive error", EN_PROG);
			}
			return -1;
		}
	}

	result = recvfrom ((SOCKET) fduse, (char *) buf, (int) len, (int) flags, (struct sockaddr *) him, &lenn);
	eif_net_check (result);
	
	return (EIF_INTEGER) result;
}
Beispiel #4
0
/*
 * Current position within file.
 */
EIF_INTEGER eif_file_tell(FILE *f) {
	long res;

	if (f == (FILE *) 0) {
		eraise("invalid file pointer", EN_EXT);
	}

	res = ftell(f);
	if (res == -1) {
		eraise("error occurred", EN_EXT);
	}
	return (EIF_INTEGER) res;
}
Beispiel #5
0
/*
 * Return the associated file descriptor.
 */
EIF_INTEGER eif_file_fd(FILE *f) {
	int res;
	if (!f) {
		res = 0;
		eraise("invalid file pointer", EN_EXT);
	} else {
		res = fileno(f);
		if (res == -1) {
			eraise("error occurred", EN_EXT);
		}
	}
	return (EIF_INTEGER) res;
}
Beispiel #6
0
rt_private void parsing_store_append(struct rt_store_context *a_context, EIF_REFERENCE object, fnptr mid, fnptr nid)
{
	RT_GET_CONTEXT
	struct rt_traversal_context traversal_context;
	int gc_stopped;

	make_index = mid;
	need_index = nid;
	gc_stopped = !eif_gc_ison();
	eif_gc_stop();		/* Procedure `make_index' may call the GC
				 * while creating objects. */

		/* Need to hold mutex here since we are using traversal. */
	EIF_EO_STORE_LOCK;

#ifdef DEBUG
	(void) nomark(object);
#endif
	/* Do the traversal: mark and count the objects to store */
	memset(&traversal_context, 0, sizeof(struct rt_traversal_context));
	traversal_context.is_for_persistence = 1;
	traversal(&traversal_context, object);

	current_position = 0;
	end_of_buffer = 0;

	/* Write in file `file_descriptor' the count of stored objects */
	buffer_write((char *) (&traversal_context.obj_nb), sizeof(uint32));

#ifndef DEBUG
	(void) pst_store(a_context, object,0L);		/* Recursive store process */
#else
	{
		uint32 nb_stored = pst_store(a_context, object,0L);

		if (traversal_context.obj_nb != nb_stored) {
			printf("obj_nb = %d nb_stored = %d\n", traversal_context.obj_nb, nb_stored);
			eraise ("Eiffel partial store", EN_IO);
		}
	}
	if (traversal_context.obj_nb != nomark(object))
		eraise ("Partial store inconsistency", EN_IO);
#endif

	a_context->flush_buffer_function();				/* Flush the buffer */

	EIF_EO_STORE_UNLOCK;	/* Unlock our mutex. */
	if (!gc_stopped)
		eif_gc_run();					/* Restart GC */

}
Beispiel #7
0
rt_public long store_append(EIF_INTEGER f_desc, char *object, fnptr mid, fnptr nid, EIF_REFERENCE s)
{
	/* Append `object' in file `f', and applies routine `mid'
	 * on server `s'. Return position in the file where the object is
	 * stored. */

	/* Initialization */
	server = s;

	if ((file_position = lseek ((int) f_desc, 0, SEEK_END)) == -1)
		eraise ("Unable to seek on internal data files", EN_SYS);

		/* Initialize store context used to store objects for appending. */
	rt_setup_store (&parsing_context, BASIC_STORE);

	parsing_store_append(&parsing_context, object, mid, nid);

		/* Write `parsing_buffer' onto `f_desc'. If we cannot write `parsing_position' bytes
		 * we have a failure. */
	if (write (f_desc, parsing_buffer, parsing_position) != parsing_position) {
		eio();
	}

	parsing_position = 0;

	return file_position;
}
 void set_matrix(SquareBinaryMatrix &m) {
   if((uint_t)m.get_size() != key_len)
     eraise(InvalidMatrix) << "Size of matrix '" << m.get_size() 
                          << "' not equal to key length '" << key_len << "'";
   hash_matrix = m;
   hash_inverse_matrix = m.inverse();
 }
 bloom_filter(size_t m, unsigned long k, const HashPair& fns = HashPair()) :
   mem_block_t(super::nb_bytes__(m)),
   super(m, k, (unsigned char*)mem_block_t::get_ptr(), fns)
 {
   if(!mem_block_t::get_ptr())
     eraise(std::runtime_error) << "Failed to allocate " << super::nb_bytes__(m) << " bytes of memory for bloom_filter";
 }
Beispiel #10
0
rt_private void parsing_compiler_write(size_t size)
{
	RT_GET_CONTEXT
	char* cmps_out_ptr = cmps_general_buffer;
	lzo_uint cmps_out_size = (lzo_uint) cmp_buffer_size;
	int signed_cmps_out_size;
	int number_written;

	REQUIRE("cmp_buffer_size not too big", cmp_buffer_size <= 0x7FFFFFFF);
	REQUIRE("size not too big", size <= 0x7FFFFFFF);
	
	lzo1x_1_compress (
					(unsigned char *) general_buffer,		/* Current buffer location */
					(lzo_uint) size,	/* Current buffer size */
					(unsigned char *) cmps_out_ptr,		/* Output buffer for compressed data */
					&cmps_out_size,		/* Size of output buffer and then size of compressed data */
					wrkmem);			/* Memory allocator */

	signed_cmps_out_size = (int) cmps_out_size;

		/* Write size of compressed data */
	if (write (file_descriptor, (char *) &signed_cmps_out_size, sizeof(int)) <= 0)
		eraise ("Unable to write compressed data size", EN_IO);

		/* Write compressed data */
	while (signed_cmps_out_size > 0) {
		number_written = write (file_descriptor, cmps_out_ptr, signed_cmps_out_size);
		if (number_written <= 0)
			eio();
		signed_cmps_out_size -= number_written;
		cmps_out_ptr += number_written;
	}
}
Beispiel #11
0
void
priv_queue::log_call(processor *client, call_data *call)
{
  bool will_sync = call_data_sync_pid (call) != NULL_PROCESSOR_ID;

  push (pq_message (pq_message::e_normal, client, call));

  if (will_sync)
    {
      processor *client = registry[call_data_sync_pid (call)];

      call_stack_msg = client->result_notify.wait();

      for (;
	   call_stack_msg.type == notify_message::e_callback;
	   call_stack_msg = client->result_notify.wait())
	{
	  (*client)(call_stack_msg.client, call_stack_msg.call);
	  call_stack_msg.call = NULL;
	}

      if (call_stack_msg.type == notify_message::e_dirty)
	{
	  char *msg = "EVE/Qs dirty processor exception";
	  eraise (msg, 32);
	}
    }

  synced = will_sync;
}
Beispiel #12
0
rt_private EIF_INTEGER private_object_id(EIF_REFERENCE object, struct stack *st, EIF_INTEGER *max_value_ptr)
{
	register unsigned int stack_number = 0;
	register struct stchunk *end;
	register EIF_INTEGER Result;
	char *address;

	if (-1 == epush(st, object)) {	/* Cannot record object */
		eraise("object id", EN_MEM);			/* No more memory */
		return (EIF_INTEGER) 0;					/* They ignored it */
		}
	address = (char *) (st->st_top - 1);	/* Was allocated here */
	eif_access(address) = object;		/* Record object's physical address */

		/* Get the stack number */
	for(end = st->st_hd;
		end != st->st_cur;
		stack_number++)
		end = end->sk_next;

	Result = (EIF_INTEGER) (stack_number*STACK_SIZE+1-(st->st_cur->sk_arena-(char **)address));

	if (Result>*max_value_ptr)
		*max_value_ptr = Result;

#ifdef DEBUG
	dprintf (2) ("eif_object_id %d %lx %lx\n", Result, address, object);
#endif
	return Result;
}
 bloom_filter(double fp, size_t n, const HashPair& fns = HashPair()) :
   mem_block_t(super::nb_bytes__(super::opt_m(fp, n))),
   super(super::opt_m(fp, n), super::opt_k(fp), (unsigned char*)mem_block_t::get_ptr(), fns)
 {
   if(!mem_block_t::get_ptr())
     eraise(std::runtime_error) << "Failed to allocate " << super::nb_bytes__(super::opt_m(fp, n))
                                << " bytes of memory for bloom_filter";
 }
Beispiel #14
0
/*
doc:	<routine name="ht_force" export="shared">
doc:		<summary>Put value `val' associated with key `key' in table `ht'. If `ht' is full, we will resize `ht' and try again. If `resizing' failed or if we cannot find a suitable position, an exception is thrown. In other words, it is the same as `ht_safe_force' modulo an exception instead of an error code.</summary>
doc:		<param name="ht" type="struct htable *">Table to initialize.</param>
doc:		<param name="key" type="rt_uint_ptr">Key to insert in `ht'.</param>
doc:		<param name="val" type="void *">Value to insert in `ht'.</param>
doc:		<thread_safety>Not Safe</thread_safety>
doc:		<synchronization>None</synchronization>
doc:	</routine>
*/
rt_shared void ht_force(struct htable *ht, rt_uint_ptr key, void * val)
{
	int l_error;

	REQUIRE("ht not null", ht);
	REQUIRE("key not null", key);

	l_error = ht_safe_force (ht, key, val);
	if (l_error != 0) {
		if (l_error == -1) {
			eraise ("Hash table resizing failure", EN_FATAL);
		} else {
			CHECK("valid error code", l_error == -2);
			eraise ("Hash table insertion failure", EN_FATAL);
		}
	}
}
Beispiel #15
0
  void map(const char *filename) {
    int fd = open(filename, O_RDONLY);
    struct stat stat;
    
    if(fd < 0)
      eraise(ErrorMMap) << "Can't open file '" << filename << "'" << err::no;
    
    if(fstat(fd, &stat) < 0)
      eraise(ErrorMMap) << "Can't stat file '" << filename << "'" << err::no;

    _length = stat.st_size;
    _base = (char *)mmap(NULL, _length, PROT_READ, MAP_SHARED, fd, 0);
    if(_base == MAP_FAILED)
      eraise(ErrorMMap) << "Can't mmap file '" << filename << "'" << err::no;
    close(fd);
    _end = _base + _length;
  }
 void resize() {
   _capacity *= 2;
   void * ndata = realloc(_data, sizeof(T) * _capacity);
   if(ndata == 0) {
     free(ndata);
     _data = 0;
     _capacity = _capacity / 2;
     eraise(SimpleGrowingArrayError) << "Out of memory" << err::no;
   }
   _data = (T*)ndata;
 }
  double_fifo_input<T>::double_fifo_input(unsigned long _nb_buckets) :
    rq(_nb_buckets), wq(_nb_buckets), nb_buckets(_nb_buckets), state(WORKING),
    input_id(0)
  {
    buckets = new T[nb_buckets];

    for(unsigned long i = 0; i < nb_buckets; ++i)
      wq.enqueue(&buckets[i]);

    if(pthread_create(&input_id, 0, static_input_routine, (void *)this) != 0)
      eraise(Error) << "Failed creating input thread" << err::no;
  }
Beispiel #18
0
void host_address_from_name (EIF_POINTER addr, EIF_POINTER name)
	/*x 32-bits netid/hostid set in addr from hostname name */
{
	struct hostent *hp;
#ifdef VXWORKS
	int h_errno = 0;
#endif

	EIF_NET_INITIALIZE;

#ifdef VXWORKS
	hp = NULL;
#else
	hp = gethostbyname((char *) name);
#endif

	if (hp == (struct hostent *) 0) {
#ifdef EIF_WINDOWS
		eif_net_check(EIFNET_ERROR_HAPPENED);
#else
			/* On Unix, `gethostbyname' does not set errno, but h_errno. This is why
			 * we cannot use `eif_net_check'. */
		errno = h_errno;
		if (h_errno == HOST_NOT_FOUND) {
			eraise ("The specified host is unknown.", EN_ISE_IO);
		} else if (h_errno == NO_ADDRESS || h_errno == NO_DATA) {
			eraise ("The requested name is valid but does not have an IP address.", EN_ISE_IO);
		} else if (h_errno == NO_RECOVERY) {
			eraise ("A non-recoverable name server error occurred.", EN_ISE_IO);
		} else if (h_errno == TRY_AGAIN) {
			eraise ("A temporary error occurred on an authoritative name server. Try again later.", EN_ISE_IO);
		} else {
			eio();
		}
#endif
	}

	((struct in_addr *) addr)->s_addr = ((struct in_addr *) (hp->h_addr))->s_addr;
}
Beispiel #19
0
rt_public void eif_extend_object_id_stack (EIF_INTEGER nb_chunks)
	/* extends of `nb_chunks the size of `object_id_stack' */
{
#ifdef ISE_GC
	RT_GET_CONTEXT
	struct stack *st = &object_id_stack;
	char **top;
	struct stchunk * current;
	char **end;

	EIF_OBJECT_ID_LOCK;
	if (st->st_top == (char **) 0) {
		top = st_alloc(st, eif_stack_chunk);	/* Create stack */
		if (top == (char **) 0) {
			EIF_OBJECT_ID_UNLOCK;
			eraise ("Couldn't allocate object id stack", EN_MEM);
		}
				/* No memory */
		st->st_top = top; /* Update new top */
	} 
	current = st->st_cur;	/* save previous current stchunk */
	top = st->st_top;		/* save previous top of stack */
	end = st->st_end;		/*save previous st_end of stack */ 
	SIGBLOCK;		/* Critical section */
	while (--nb_chunks) {
		if (-1 == st_extend(st, eif_stack_chunk)) {
			EIF_OBJECT_ID_UNLOCK;
			eraise ("Couldn't allocate object id stack", EN_MEM);
		}
	}	
	st->st_cur = current;	/* keep previous Current */
	st->st_top = top;		/* keep previous top */
	st->st_end = end;
	
	SIGRESUME;		/* End of critical section */

	EIF_OBJECT_ID_UNLOCK;
#endif
}
Beispiel #20
0
static SOCKET check_socket_bounds (SOCKET l_socket) {
#ifdef EIF_64_BITS
		/* On 64-bit system `SOCKET' is actually a pointer. For the moment, we check that
		 * it is not coded on the whole 64-bit. */
	if (l_socket != INVALID_SOCKET) {
		if ((l_socket & RTU64C(0x00000000FFFFFFFF)) != l_socket) {
				/* We are in trouble. Raise an exception for the moment. */
			eraise ("Descriptor too big to be represented as INTEGER_32", EN_PROG);
		}
	}
#endif
	return l_socket;
}
 generator_manager(const char* cmds, int nb_pipes, const char* shell = 0) :
   cmds_(cmds),
   pipes_(nb_pipes),
   manager_pid_(-1),
   shell_(shell),
   kill_signal_(0)
 {
   if(!cmds_.good())
     eraise(std::runtime_error) << "Failed to open cmds file '" << cmds << "'";
   if(!shell_)
     shell_ = getenv("SHELL");
   if(!shell_)
     shell_ = "/bin/sh";
 }
Beispiel #22
0
rt_public void run_idr_init (size_t idrf_size, int type)
{
	RT_GET_CONTEXT
	idrf_buffer_size = idrf_size;

	run_idr_read_func = run_idr_read;

		/* Because we might mark the first `n' bytes of the buffer (see above
		 * instruction), we need to make sure that we have enough allocated memory
		 * to read or store `idrf_buffer_size' bytes.
		 */
	if (-1 == idrf_create (&idrf, idrf_size + sizeof(int32)))
		eraise ("cannot allocate idrf", EN_MEM);

		/* Reset amount_read */
	amount_read = 0;

		/* When writting a storable we mark some space at the front of the buffer
		 * to store upon writting the size of block, so that only one write operation
		 * is performed */
	if (type) {
		idr_setpos (&idrf.i_encode, sizeof(int32));
	}

#ifdef EIF_64_BITS
	idr_ref_table_counter = 0;
	idr_ref_table = (struct htable*) eif_rt_xmalloc (sizeof (struct htable), C_T, GC_OFF);
	if (idr_ref_table == NULL) {
		eraise ("Cannot allocate 64-32 mapping table", EN_MEM);
		xraise (EN_MEM);
	} else {
		if (ht_create (idr_ref_table, 10000, sizeof(rt_uint_ptr)) == -1) {
			eraise ("Cannot create 64-32 mapping table", EN_MEM);
		}
	}
#endif
}
Beispiel #23
0
/* {STRING_SEARCHER}.make */
void F131_1906 (EIF_REFERENCE Current)
{
	GTCX
	char *l_feature_name = "make";
	RTEX;
	EIF_TYPED_VALUE ui4_1x = {{0}, SK_INT32};
#define ui4_1 ui4_1x.it_i4
	EIF_REFERENCE tr1 = NULL;
	EIF_INTEGER_32 ti4_1;
	RTCDT;
	RTSN;
	RTDA;
	RTLD;
	
	RTLI(2);
	RTLR(0,Current);
	RTLR(1,tr1);
	RTLU (SK_VOID, NULL);
	RTLU (SK_REF, &Current);
	
	RTEAA(l_feature_name, 130, Current, 0, 0, 1851);
	RTSA(dtype);
	RTSC;
	RTME(dtype, 0);
	RTGC;
	RTDBGEAA(130, Current, 1851);
	RTIV(Current, RTAL);
	RTHOOK(1);
	RTDBGAA(Current, dtype, 1748, 0xF800020D, 0); /* deltas */
	
	ti4_1 = (((FUNCTION_CAST(EIF_TYPED_VALUE, (EIF_REFERENCE)) RTWF(1743, dtype))(Current)).it_i4);
	ui4_1 = (EIF_INTEGER_32) (ti4_1 + ((EIF_INTEGER_32) 1L));
	if (ui4_1< 0) {
		eraise ("non_negative_argument", EN_RT_CHECK);
	}
	tr1 = RTLNSP2(eif_non_attached_type(RTWCT(1748, dtype, Dftype(Current))),0,ui4_1,sizeof(EIF_INTEGER_32), EIF_TRUE);
	RT_SPECIAL_COUNT(tr1) = 0;
	RTAR(Current, tr1);
	*(EIF_REFERENCE *)(Current + RTWA(1748, dtype)) = (EIF_REFERENCE) tr1;
	RTVI(Current, RTAL);
	RTRS;
	RTHOOK(2);
	RTDBGLE;
	RTMD(0);
	RTLE;
	RTLO(2);
	RTEE;
#undef ui4_1
}
Beispiel #24
0
  /// Open the next file with given prefix. If one_file is false,
  /// append _0, _1, etc. to the prefix for actual file name. If
  /// one_file is true, the prefix is the file name. The first time
  /// the file is open in trunc mode, the subsequent times in append
  /// mode.
  void open_next_file(const char *prefix, std::ofstream &out) {
    std::ostringstream name;
    name << prefix;
    std::ios::openmode mode = std::ios::out;
    if(one_file_) {
      mode |= (index_++ ? std::ios::ate : std::ios::trunc);
    } else {
      name << index_++;
      mode |= std::ios::trunc;
    }
    file_names_.push_back(name.str());

    out.open(name.str().c_str());
    if(out.fail())
      eraise(ErrorWriting) << "'" << name.str() << "': "
                           << "Can't open file for writing" << err::no;
  }
Beispiel #25
0
int net_char_read(char *pointer, int size)
{
	GTCX
	int i;
#ifdef EIF_VMS
        int rcvbuf = get_socket_maxrecv (socket_fides);
        int chunksize = size;
        if (size > rcvbuf) chunksize = rcvbuf;
#endif

retry:
#ifdef EIF_WINDOWS
	i = recv(socket_fides, pointer, size, 0);
#elif defined EIF_VMS
        i = recv(socket_fides, pointer, chunksize, 0);
#else
	i = read(socket_fides, pointer, size);
#endif
	if (i == SOCKET_ERROR && GET_SOCKET_ERROR == EWOULDBLOCK)
	{
		if (!net_socket_ready(1))
		{
			/* The desired socket is not ready. Raise an
			   exception. */
			eraise(SOCKET_UNAVAILABLE_FOR_READING, EN_RETR);
		} else {	
			/* Should not issue a recursive call here as this may
			   potentially lead to an unbounded number of recursive
			   calls, thus causing stack overflow should the
			   socket issue this error many times in succession. */
			goto retry;
		}
	}
	else if (i > 0 && i < size)
	{
		int prev = i;

		/* A recursive call here is bounded because the remaining
		   number of bytes is guaranteed to decrease each call. */
		i = net_char_read(pointer + i, size - i);
		if (i > 0)
			i += prev;
	}
	return i;
}
Beispiel #26
0
/* Return a buffer large enough to hold the specified minimum size.
 */
rt_private char* net_buffer (int min_size)
{
	static char* buffer = NULL;
	static int buffer_size = 0;

	if (buffer_size < min_size)
	{
		if (buffer == NULL)
			buffer = (char*) malloc (min_size);
		else
			buffer = (char*) realloc (buffer, min_size);

		if (buffer == NULL)
			eraise ("Out of memory in buffered_write", EN_RETR);
		else
			buffer_size = min_size;
	}
	return buffer;
}
 array(size_t _size, uint_t _key_len, uint_t _val_len,
       uint_t _reprobe_limit, size_t *_reprobes) :
   lsize(ceilLog2(_size)), size(((size_t)1) << lsize),
   size_mask(size - 1),
   reprobe_limit(_reprobe_limit, _reprobes, size), key_len(_key_len),
   key_mask(key_len <= lsize ? 0 : (((word)1) << (key_len - lsize)) - 1),
   key_off(key_len <= lsize ? 0 : key_len - lsize),
   offsets(key_off + bitsize(reprobe_limit.val() + 1), _val_len,
           reprobe_limit.val() + 1),
   mem_block(div_ceil(size, (size_t)offsets.get_block_len()) * offsets.get_block_word_len() * sizeof(word)),
   data((word *)mem_block.get_ptr()), reprobes(_reprobes),
   hash_matrix(key_len), 
   hash_inverse_matrix(hash_matrix.init_random_inverse())
 {
   if(!data)
     eraise(ErrorAllocation) << "Failed to allocate " 
                            << (div_ceil(size, (size_t)offsets.get_block_len()) * offsets.get_block_word_len() * sizeof(word))
                            << " bytes of memory";
 }
Beispiel #28
0
rt_shared void do_init(void)
{
	WORD wVersionRequested;
	WSADATA wsaData;
	int err;
	static BOOL done = FALSE;

	if (!done) {
		wVersionRequested = MAKEWORD(2, 0);
		err = WSAStartup(wVersionRequested, &wsaData);
		if (err != 0) {
			fprintf (stderr, "Communications error %d", err);
			eraise ("Unable to start WINSOCK", EN_PROG);
		}
#ifndef EIF_IL_DLL
		eif_register_cleanup(eif_winsock_cleanup);
#endif
		done = TRUE;
	}
}
 // key_len passed in bits
 binary_query_base(const char* data, unsigned int key_len, unsigned int val_len, const RectangularBinaryMatrix& m, size_t mask,
                   size_t size) :
     data_(data),
     val_len_(val_len),
     key_len_(key_len / 8 + (key_len % 8 != 0)),
     m_(m),
     mask_(mask),
     record_len_(val_len + key_len_),
     last_id_(size / record_len_),
     first_key_(key_len / 2),
     last_key_(key_len / 2),
     mid_key_(key_len / 2)
 {
     if(size % record_len_ != 0)
         eraise(std::length_error) << "Size of database (" << size << ") must be a multiple of the length of a record ("
                                   << record_len_ << ")";
     key_at(0, first_key_);
     first_pos_ = key_pos(first_key_);
     key_at(last_id_ - 1, last_key_);
     last_pos_  = key_pos(last_key_);
 }
Beispiel #30
0
/* {TO_SPECIAL}.make_empty_area */
void F202_1852 (EIF_REFERENCE Current, EIF_TYPED_VALUE arg1x)
{
	GTCX
	char *l_feature_name = "make_empty_area";
	RTEX;
#define arg1 arg1x.it_i4
	EIF_TYPED_VALUE up1x = {{0}, SK_POINTER};
#define up1 up1x.it_p
	EIF_TYPED_VALUE ui4_1x = {{0}, SK_INT32};
#define ui4_1 ui4_1x.it_i4
	EIF_REFERENCE tr1 = NULL;
	EIF_INTEGER_32 ti4_1;
	RTCDT;
	RTSN;
	RTDA;
	RTLD;
	
	if ((arg1x.type & SK_HEAD) == SK_REF) arg1x.it_i4 = * (EIF_INTEGER_32 *) arg1x.it_r;
	
	RTLI(2);
	RTLR(0,Current);
	RTLR(1,tr1);
	RTLU (SK_VOID, NULL);
	RTLU(SK_INT32,&arg1);
	RTLU (SK_REF, &Current);
	
	RTEAA(l_feature_name, 201, Current, 0, 1, 2360);
	RTSA(dtype);
	RTSC;
	RTME(dtype, 0);
	RTGC;
	RTDBGEAA(201, Current, 2360);
	RTIV(Current, RTAL);
	if ((RTAL & CK_REQUIRE) || RTAC) {
		RTHOOK(1);
		RTCT("non_negative_argument", EX_PRE);
		RTTE((EIF_BOOLEAN) (arg1 >= ((EIF_INTEGER_32) 0L)), label_1);
		RTCK;
		RTJB;
label_1:
		RTCF;
	}
body:;
	RTHOOK(2);
	RTDBGAA(Current, dtype, 1556, 0xF80000B1, 0); /* area */
	
	ui4_1 = arg1;
	if (ui4_1< 0) {
		eraise ("non_negative_argument", EN_RT_CHECK);
	}
	tr1 = RTLNSP2(eif_non_attached_type(RTWCT(1556, dtype, Dftype(Current))),EO_REF,ui4_1,sizeof(EIF_REFERENCE), EIF_FALSE);
	RT_SPECIAL_COUNT(tr1) = 0;
	RTAR(Current, tr1);
	*(EIF_REFERENCE *)(Current + RTWA(1556, dtype)) = (EIF_REFERENCE) tr1;
	if (RTAL & CK_ENSURE) {
		RTHOOK(3);
		RTCT("area_allocated", EX_POST);
		tr1 = ((up1x = (FUNCTION_CAST(EIF_TYPED_VALUE, (EIF_REFERENCE)) RTWF(1556, dtype))(Current)), (((up1x.type & SK_HEAD) == SK_REF)? (EIF_REFERENCE) 0: (up1x.it_r = RTBU(up1x))), (up1x.type = SK_POINTER), up1x.it_r);
		if ((EIF_BOOLEAN)(tr1 != NULL)) {
			RTCK;
		} else {
			RTCF;
		}
		RTHOOK(4);
		RTCT("capacity_set", EX_POST);
		tr1 = ((up1x = (FUNCTION_CAST(EIF_TYPED_VALUE, (EIF_REFERENCE)) RTWF(1556, dtype))(Current)), (((up1x.type & SK_HEAD) == SK_REF)? (EIF_REFERENCE) 0: (up1x.it_r = RTBU(up1x))), (up1x.type = SK_POINTER), up1x.it_r);
		RTNHOOK(4,1);
		ti4_1 = (((FUNCTION_CAST(EIF_TYPED_VALUE, (EIF_REFERENCE)) RTVF(1624, "capacity", tr1))(tr1)).it_i4);
		if ((EIF_BOOLEAN)(ti4_1 == arg1)) {
			RTCK;
		} else {
			RTCF;
		}
		RTHOOK(5);
		RTCT("count_set", EX_POST);
		tr1 = ((up1x = (FUNCTION_CAST(EIF_TYPED_VALUE, (EIF_REFERENCE)) RTWF(1556, dtype))(Current)), (((up1x.type & SK_HEAD) == SK_REF)? (EIF_REFERENCE) 0: (up1x.it_r = RTBU(up1x))), (up1x.type = SK_POINTER), up1x.it_r);
		RTNHOOK(5,1);
		ti4_1 = (((FUNCTION_CAST(EIF_TYPED_VALUE, (EIF_REFERENCE)) RTVF(1623, "count", tr1))(tr1)).it_i4);
		if ((EIF_BOOLEAN)(ti4_1 == ((EIF_INTEGER_32) 0L))) {
			RTCK;
		} else {
			RTCF;
		}
	}
	RTVI(Current, RTAL);
	RTRS;
	RTHOOK(6);
	RTDBGLE;
	RTMD(0);
	RTLE;
	RTLO(3);
	RTEE;
#undef up1
#undef ui4_1
#undef arg1
}