Exemple #1
0
void PVUnionArray::deserialize(ByteBuffer *pbuffer,
        DeserializableControl *pcontrol) {
    svector data(reuse());

    size_t size = this->getArray()->getArraySizeType() == Array::fixed ?
                this->getArray()->getMaximumCapacity() :
                SerializeHelper::readSize(pbuffer, pcontrol);

    data.resize(size);

    UnionConstPtr punion = unionArray->getUnion();

    PVDataCreatePtr pvDataCreate = getPVDataCreate();

    for(size_t i = 0; i<size; i++) {
        pcontrol->ensureData(1);
        size_t temp = pbuffer->getByte();
        if(temp==0) {
            data[i].reset();
        }
        else {
            if(data[i].get()==NULL || !data[i].unique()) {
                data[i] = pvDataCreate->createPVUnion(punion);
            }
            data[i]->deserialize(pbuffer, pcontrol);
        }
    }
    replace(freeze(data)); // calls postPut()
}
Exemple #2
0
void PVUnionArray::compress() {
    if (getArray()->getArraySizeType() == Array::fixed)
            return;

    svector vec(reuse()); // TODO: check for first NULL before realloc

    size_t length = vec.size();
    size_t newLength = 0;

    for(size_t i=0; i<length; i++) {
        if(vec[i].get()!=NULL) {
            newLength++;
            continue;
        }
        // find first non 0
        size_t notNull = 0;
        for(size_t j=i+1;j<length;j++) {
            if(vec[j].get()!=NULL) {
                notNull = j;
                break;
            }
        }
        if(notNull!=0) {
            vec[i] = vec[notNull];
            vec[notNull].reset();
            newLength++;
            continue;
         }
         break;
    }

    vec.resize(newLength);
    const_svector cdata(freeze(vec));
    swap(cdata);
}
Exemple #3
0
void	MemSplit::alloc(int maxarray, int maxstrlen, simpleAlloc &mem)
{
	maxArray = maxarray;
	maxLen = maxstrlen;
	Array = (char**)mem.alloc(maxArray * sizeof(char*) );
	Length = (int *)mem.alloc(maxArray * sizeof(int) );
	memory = (char *)mem.alloc(maxArray * (maxLen+1) );
	reuse();
}
Exemple #4
0
void	MemSplit::alloc(int maxarray, int maxstrlen)
{
	maxArray = maxarray;
	maxLen = maxstrlen;
	Array = new char*[maxArray];
	Length = new int [maxArray];
	memory = new char [maxArray * (maxLen+1) ];
	reuse();
}
Exemple #5
0
bool
Socket::init() {
  /* Create the socket. */
  handle = socket (PF_INET, SOCK_STREAM, 0);
  if (handle== -1) JGACHINE_SERROR("create");

  if (!server) return connect();

  reuse();
  if (!bind()) JGACHINE_SERROR("bind");
  if (!listen()) JGACHINE_SERROR("listen");
  return true;
}
Exemple #6
0
bool objlist_insert_first(ObjList **objlist, Obj *obj)
{
    ObjList *node=reuse(objlist);
    
    if(node==NULL)
        node=mknode(obj);
    
    if(node==NULL)
        return FALSE;
    
    LINK_ITEM_FIRST(*objlist, node, next, prev);
    
    return TRUE;
}
Exemple #7
0
static void dumpcover(Node p, int nt, int in) {
	int rulenum, i;
	short *nts;
	Node kids[10];

	p = reuse(p, nt);
	rulenum = getrule(p, nt);
	nts = IR->x._nts[rulenum];
	fprint(stderr, "dumpcover(%x) = ", p);
	for (i = 0; i < in; i++)
		fprint(stderr, " ");
	dumprule(rulenum);
	(*IR->x._kids)(p, rulenum, kids);
	for (i = 0; nts[i]; i++)
		dumpcover(kids[i], nts[i], in+1);
}
        br_status reduce_ac_app(func_decl * f, unsigned num_args, expr * const * args, expr_ref & result) {
            set & s = f2set(f);

            if (num_args == 2) {
                if (!m_util.is_numeral(args[0]) && !m_util.is_numeral(args[1]))
                    s.insert(expr_pair(args[0], args[1]));
                return BR_FAILED;
            }

            ptr_buffer<expr, 128> _args;
            bool first = false;
            expr * num = 0;
            for (unsigned i = 0; i < num_args; i++) {
                expr * arg = args[i];
                if (num == 0 && m_util.is_numeral(arg)) {
                    if (i == 0) first = true;
                    num = arg;
                }
                else {
                    _args.push_back(arg);
                }
            }
            num_args = _args.size();


            // std::sort(_args.begin(), _args.end(), ref_count_lt());
            // std::sort(_args.begin(), _args.end(), ast_to_lt());
            
        try_to_reuse:
            if (num_args > 1 && num_args < m_max_args) {
                for (unsigned i = 0; i < num_args - 1; i++) {
                    for (unsigned j = i + 1; j < num_args; j++) {
                        expr * r = reuse(s, f, _args[i], _args[j]);
                        if (r != 0) {
                            TRACE("bv_sharing_detail", tout << "reusing args: " << i << " " << j << "\n";);
                            _args[i] = r;
                            SASSERT(num_args > 1);
                            for (unsigned w = j; w < num_args - 1; w++) {
                                _args[w] = _args[w+1];
                            }
                            num_args--;
                            goto try_to_reuse;
                        }
                    }
                }
Exemple #9
0
	void socket_handle_t::dis_connect(int shut, bool bReuseSocket/* = true*/)
	{
		if( !is_open() )
			throw service::network_exception("Socket not open");

		int ret = ::shutdown(socket_, shut);
		assert(ret != SOCKET_ERROR);

		if( bReuseSocket )
		{
			reuse_addr reuse(true);
			set_option(reuse);
		}
		else
		{
			close();
		}
	}
Exemple #10
0
size_t PVUnionArray::append(size_t number)
{
    checkLength(value.size()+number);

    svector data(reuse());
    data.resize(data.size()+number);

    UnionConstPtr punion = unionArray->getUnion();

    PVDataCreatePtr pvDataCreate = getPVDataCreate();
    for(svector::reverse_iterator it = data.rbegin(); number; ++it, --number)
        *it = pvDataCreate->createPVUnion(punion);

    size_t newLength = data.size();

    const_svector cdata(freeze(data));
    swap(cdata);

    return newLength;
}
Exemple #11
0
static void reduce(Node p, int nt) {
	int rulenum, i;
	short *nts;
	Node kids[10];

	p = reuse(p, nt);
	rulenum = getrule(p, nt);
	nts = IR->x._nts[rulenum];
	(*IR->x._kids)(p, rulenum, kids);
	for (i = 0; nts[i]; i++)
		reduce(kids[i], nts[i]);
	if (IR->x._isinstruction[rulenum]) {
		assert(p->x.inst == 0 || p->x.inst == nt);
		p->x.inst = nt;
		if (p->syms[RX] && p->syms[RX]->temporary) {
			debug(fprint(stderr, "(using %s)\n", p->syms[RX]->name));
			p->syms[RX]->x.usecount++;
		}
	}
}
 static bucket_ptr expand_or_create_buckets
    ( bucket_ptr old_buckets, const size_type old_num
    , allocator_type &alloc,  const size_type new_num)
 {
    size_type received_size = new_num;
    bucket_ptr reuse(old_buckets);
    bucket_ptr ret = alloc.allocation_command
          (boost::interprocess::expand_fwd | boost::interprocess::allocate_new, new_num, received_size, reuse);
    if(ret == old_buckets){
       bucket_ptr buckets_init = old_buckets + old_num;
       for(size_type i = 0; i < (new_num - old_num); ++i){
          ::new(to_raw_pointer(buckets_init++), boost_container_new_t())bucket_type();
       }
    }
    else{
       bucket_ptr buckets_init = ret;
       for(size_type i = 0; i < new_num; ++i){
          ::new(to_raw_pointer(buckets_init++), boost_container_new_t())bucket_type();
       }
    }
    return ret;
 }
	void WebSocket::start( Processable* p )
	{
		_processable = p;
		
		_server_sock = accept_ptr( new tcp::acceptor( _io_service ) );
		tcp::endpoint ep( tcp::v4( ), _port );
		
		// open the socket, set it to non blocking and bind the socket
		_server_sock->open( ep.protocol( ) );
		
		// set to reuse address
		tcp::acceptor::reuse_address reuse( true );
		_server_sock->set_option( reuse );
		
		_server_sock->bind( ep );
		_server_sock->listen( );
		
		sock_ptr s( new tcp::socket( _io_service ) );
		_server_sock->async_accept( *s, boost::bind( &WebSocket::_async_accept, this, s, boost::asio::placeholders::error ) );
		
		_io_service.run( );
	}
Exemple #14
0
int nepim_socket_opt(FILE *err, int sd, int pmtu_mode, int ttl, int tos, int ra)
{
  if (unlinger(sd))
    return NEPIM_SOCK_ERR_UNLINGER;

  if (reuse(sd))
    return NEPIM_SOCK_ERR_REUSE;

  if (nepim_socket_pmtu(sd, pmtu_mode))
    return NEPIM_SOCK_ERR_PMTU;

  if (nepim_socket_ttl(sd, ttl))
    return NEPIM_SOCK_ERR_TTL;

  if (nepim_socket_tos(err, sd, tos))
    return NEPIM_SOCK_ERR_TOS;

  if (ra)
    if (socket_set_ra(err, sd))
      return NEPIM_SOCK_ERR_RA;

  return NEPIM_SOCK_ERR_NONE;
}
Exemple #15
0
bool PVUnionArray::remove(size_t offset,size_t number)
{
    if (number==0)
        return true;
    else if (offset+number>getLength())
        return false;
    else if (getArray()->getArraySizeType() == Array::fixed)
        return false;

    svector vec(reuse());

    size_t length = vec.size();

    for(size_t i = offset; i+number < length; i++) {
         vec[i].swap(vec[i + number]);
    }

    vec.resize(length - number);
    const_svector cdata(freeze(vec));
    swap(cdata);

    return true;
}
Exemple #16
0
static unsigned emitasm(Node p, int nt) {
	int rulenum;
	short *nts;
	char *fmt;
	Node kids[10];

	p = reuse(p, nt);
	rulenum = getrule(p, nt);
	nts = IR->x._nts[rulenum];
	fmt = IR->x._templates[rulenum];
	assert(fmt);
	if (IR->x._isinstruction[rulenum] && p->x.emitted)
		print("%s", p->syms[RX]->x.name);
	else if (*fmt == '#')
		(*IR->x.emit2)(p);
	else {
		if (*fmt == '?') {
			fmt++;
			assert(p->kids[0]);
			if (p->syms[RX] == p->x.kids[0]->syms[RX])
				while (*fmt++ != '\n')
					;
		}
		for ((*IR->x._kids)(p, rulenum, kids); *fmt; fmt++)
			if (*fmt != '%')
				(void)putchar(*fmt);
			else if (*++fmt == 'F')
				print("%d", framesize);
			else if (*fmt >= '0' && *fmt <= '9')
				emitasm(kids[*fmt - '0'], nts[*fmt - '0']);
			else if (*fmt >= 'a' && *fmt < 'a' + NELEMS(p->syms))
				fputs(p->syms[*fmt - 'a']->x.name, stdout);
			else
				(void)putchar(*fmt);
	}
	return 0;
}
    void* alloc(size_t size)
    {
        void* result;

        // Freed allocations of the common size are not stored back into the main
        // m_freeList, but are instead stored in a separate vector.  If the request
        // is for a common sized allocation, check this list.
        if ((size == m_commonSize) && m_commonSizedAllocations.size()) {
            result = m_commonSizedAllocations.last();
            m_commonSizedAllocations.removeLast();
        } else {
            // Serach m_freeList for a suitable sized chunk to allocate memory from.
            FreeListEntry* entry = m_freeList.search(size, m_freeList.GREATER_EQUAL);

            // This would be bad news.
            if (!entry) {
                // Errk!  Lets take a last-ditch desparation attempt at defragmentation...
                coalesceFreeSpace();
                // Did that free up a large enough chunk?
                entry = m_freeList.search(size, m_freeList.GREATER_EQUAL);
                // No?...  *BOOM!*
                if (!entry)
                    CRASH();
            }
            ASSERT(entry->size != m_commonSize);

            // Remove the entry from m_freeList.  But! -
            // Each entry in the tree may represent a chain of multiple chunks of the
            // same size, and we only want to remove one on them.  So, if this entry
            // does have a chain, just remove the first-but-one item from the chain.
            if (FreeListEntry* next = entry->nextEntry) {
                // We're going to leave 'entry' in the tree; remove 'next' from its chain.
                entry->nextEntry = next->nextEntry;
                next->nextEntry = 0;
                entry = next;
            } else
                m_freeList.remove(entry->size);

            // Whoo!, we have a result!
            ASSERT(entry->size >= size);
            result = entry->pointer;

            // If the allocation exactly fits the chunk we found in the,
            // m_freeList then the FreeListEntry node is no longer needed.
            if (entry->size == size)
                delete entry;
            else {
                // There is memory left over, and it is not of the common size.
                // We can reuse the existing FreeListEntry node to add this back
                // into m_freeList.
                entry->pointer = (void*)((intptr_t)entry->pointer + size);
                entry->size -= size;
                addToFreeList(entry);
            }
        }

        // Call reuse to report to the operating system that this memory is in use.
        ASSERT(isWithinVMPool(result, size));
        reuse(result, size);
        return result;
    }
Exemple #18
0
	void reuse() const {
		_ESQ_SERVICE_TCPIP reuse(socket_);
	}
Exemple #19
0
/*
 * new_password - validate old password and replace with new (both old and
 * new in global "char crypt_passwd[128]")
 */
static int new_password (const struct passwd *pw)
{
	char *clear;		/* Pointer to clear text */
	char *cipher;		/* Pointer to cipher text */
	char *cp;		/* Pointer to getpass() response */
	char orig[200];		/* Original password */
	char pass[200];		/* New password */
	int i;			/* Counter for retries */
	int warned;
	int pass_max_len = -1;
	char *method;

#ifdef HAVE_LIBCRACK_HIST
	int HistUpdate (const char *, const char *);
#endif				/* HAVE_LIBCRACK_HIST */

	/*
	 * Authenticate the user. The user will be prompted for their own
	 * password.
	 */

	if (!amroot && crypt_passwd[0]) {
		clear = getpass (_("Old password: "******"incorrect password for %s",
				 pw->pw_name));
			sleep (1);
			fprintf (stderr,
				 _("Incorrect password for %s.\n"),
				 pw->pw_name);
			return -1;
		}
		STRFCPY (orig, clear);
		strzero (clear);
		strzero (cipher);
	} else {
		orig[0] = '\0';
	}

	/*
	 * Get the new password. The user is prompted for the new password
	 * and has five tries to get it right. The password will be tested
	 * for strength, unless it is the root user. This provides an escape
	 * for initial login passwords.
	 */
	if ((method = getdef_str ("ENCRYPT_METHOD")) == NULL) {
		if (!getdef_bool ("MD5_CRYPT_ENAB")) {
			pass_max_len = getdef_num ("PASS_MAX_LEN", 8);
		}
	} else {
		if (   (strcmp (method, "MD5")    == 0)
#ifdef USE_SHA_CRYPT
		    || (strcmp (method, "SHA256") == 0)
		    || (strcmp (method, "SHA512") == 0)
#endif				/* USE_SHA_CRYPT */
		    ) {
			pass_max_len = -1;
		} else {
			pass_max_len = getdef_num ("PASS_MAX_LEN", 8);
		}
	}
	if (!qflg) {
		if (pass_max_len == -1) {
			printf (_(
"Enter the new password (minimum of %d characters)\n"
"Please use a combination of upper and lower case letters and numbers.\n"),
				getdef_num ("PASS_MIN_LEN", 5));
		} else {
			printf (_(
"Enter the new password (minimum of %d, maximum of %d characters)\n"
"Please use a combination of upper and lower case letters and numbers.\n"),
				getdef_num ("PASS_MIN_LEN", 5), pass_max_len);
		}
	}

	warned = 0;
	for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i--) {
		cp = getpass (_("New password: "******"Try again."));
			continue;
		}

		/*
		 * If enabled, warn about weak passwords even if you are
		 * root (enter this password again to use it anyway). 
		 * --marekm
		 */
		if (amroot && !warned && getdef_bool ("PASS_ALWAYS_WARN")
		    && (!obscure (orig, pass, pw) || reuse (pass, pw))) {
			puts (_("\nWarning: weak password (enter it again to use it anyway)."));
			warned++;
			continue;
		}
		cp = getpass (_("Re-enter new password: "******"They don't match; try again.\n"), stderr);
		} else {
			strzero (cp);
			break;
		}
	}
	memzero (orig, sizeof orig);

	if (i == 0) {
		memzero (pass, sizeof pass);
		return -1;
	}

	/*
	 * Encrypt the password, then wipe the cleartext password.
	 */
	cp = pw_encrypt (pass, crypt_make_salt (NULL, NULL));
	memzero (pass, sizeof pass);

#ifdef HAVE_LIBCRACK_HIST
	HistUpdate (pw->pw_name, crypt_passwd);
#endif				/* HAVE_LIBCRACK_HIST */
	STRFCPY (crypt_passwd, cp);
	return 0;
}
 void
 MemoryManager::alloc_refill(SharedMemory* sm, size_t sz) {
   // Try to reuse the not used memory
   reuse(start,lsz);
   alloc_fill(sm,sz,false);
 }
Exemple #21
0
command * handle_key(int key, command *stack_ptr, DIR_SAVE *verz_buff, coords *c){
	int verb = 0;
	switch (key) {
		case KEY_DOWN:
			if (verb==1) printw("KEY_DOWN: %d\n",key);
			if (stack_ptr->previous != NULL) {
				stack_ptr = stack_ptr->previous; 
					
				//Zeile loeschen
				getyx(stdscr, c->y, c->x);
				move(c->y, 0);
				clrtoeol();
					
				//Prompt und Kommando neu schreiben.
				PROMPT
				getyx(stdscr, c->y0, c->x0);
				printw("%s",stack_ptr->cmd);
				//Positionszaehler auf momentane Position setzen.
				c->i=strlen(stack_ptr->cmd);
			}
			else break;
			break;
				
		case KEY_UP:
			if (verb==1) printw("KEY_UP: %d\n",key);
			if (stack_ptr->next != NULL) {
				stack_ptr = stack_ptr->next;
					
				//momentane Position in der Shell ermitteln.
				getyx(stdscr, c->y, c->x);
				move(c->y, 0);
				clrtoeol(); // Zeile loeschen.
					
				//Prompt und Kommando neu schreiben.
				PROMPT
				getyx(stdscr, c->y0, c->x0);
				printw("%s",stack_ptr->cmd);
				//Positionszaehler auf momentane Position setzen.
				c->i=strlen(stack_ptr->cmd);
			}
			else break;
			break;
			
		case KEY_LEFT:
			if (verb==1) printw("KEY_LEFT: %d\n",key);
			getyx(stdscr, c->y, c->x);
			move(c->y, c->x-1);
			break;

		case KEY_RIGHT:
			if (verb==1) printw("KEY_RIGHT: %d\n",key);
			getyx(stdscr, c->y, c->x);
			move(c->y, c->x+1);
			break;
			
		case KEY_BACKSPACE_LINUX:
			if (verb==1) printw ("KEY_BACKSPACE: %d\n",key);

			getyx(stdscr, c->y, c->x);
			//printw("i:%i\n",c->i);
			if ( (c->i) > 0) {

				//Inhalt der Zeile ein Zeichen abzwacken
				//(c->i)--;
				//stack_ptr->cmd[(c->i)]='\0';

				//Zeile umschreiben/momentane pos auslassen.

				int len = c->i;
				int ii = 0;

				char cmd_tmp[MAX_CHARS_PER_LINE];
				//printw("c->i: %i\n",c->i);
				int j;
				for(j=0; j<=len; j++) {
					//printw("%c",stack_ptr->cmd[ii]);
					// Die derzeitige Position beim Umschreiben ueberspringen
					// (Vom Promptende aus gesehen im Kommando)
					if(j==abs(c->x0 - (c->x-1))){
						j++;
						c->i--;
					}
					cmd_tmp[ii] = stack_ptr->cmd[j];
					ii++;
				}
				strcpy(stack_ptr->cmd,cmd_tmp);

				//Zeile loeschen
				move(c->y, 0);
				clrtoeol();
				//Prompt neu aufbauen
				PROMPT
				printw("%s",stack_ptr->cmd);
				move(c->y,c->x-1);
			}
			else break;
			break;
				
		case KEY_ENTER_CUSTOM:
			if (verb==1) printw("KEY_ENTER_CUSTOM: %d\n",key);
			//Fall: next Zeiger am Stapel nicht Null: Wir sind im Inneren des Stapels.
			//es handelt sich... um eine Wiederverwendung eines Befehles durch den User!
			if (stack_ptr->next != NULL){
				if(verb==1) printw("reusing cmd...\n");

				//Kommando in den Speicher des obersten (leeren) Stackelements kopieren.
				stack_ptr = reuse(stack_ptr);
				if(verb==1) printw("executing cmd...\n");

				evaluate_expression(stack_ptr,verz_buff);
				//jetzt erst Push ausfuehren
				stack_ptr = push(stack_ptr);
			}
			else {
				if(verb==1) printw("Executing cmd on top of stack\n");
				//Fall: alles normal, sind oben am Stapel -
				//push-back durchfuehren....

				//Ausdruck auswerten
				if(verb==1) printw("Evaluating...\n");
				evaluate_expression(stack_ptr,verz_buff);

				//Ausdruck auf den Kommando Stack "ablegen" indem neues Kommando auf Spitze des Stack angelegt wird.
				//stack_ptr zeigt danach auf das neue (noch leere Kommando)
				stack_ptr = push(stack_ptr);
			}

			//Prompt leer wieder aufbauen.
			PROMPT
			//Position des Prompts sichern
			getyx(stdscr, c->y0, c->x0);
			//Positionszaehler auf leer zuruecksetzen.
			c->i=0;
			break;
				
		default:
			//Zeichen zu Kommandopuffer hinzufuegen (wenn keine Sondertaste)
			if (verb==1) printw ("Tastaturcode %d\n", key);
			//stack_ptr->cmd[(c->i)] = key;
			//stack_ptr->cmd[(c->i)+1] = '\0';
			getyx(stdscr, c->y, c->x);
			stack_ptr->cmd[(abs(c->x0 - c->x))] = key;
			//printw("\npos: %i, key: %c\n",(abs(c->x0 - c->x)), key);
			if((abs(c->x - c->x0) >= c->i )) {
				(c->i)++;
				stack_ptr->cmd[(c->i+1)] = '\0';
			}
			(c->x)++;
			move(c->y,c->x);


			//Bisher eingegebenes Kommando wieder aufbauen (nachdem der gedrueckte Key behandelt wurde.)
			//getyx(stdscr, c->y, c->x);
			move(c->y, 0);
			clrtoeol();
			if (verb==1) printw("\nBisher eingegebenes Kdo. wieder aufgebaut\n");
			PROMPT
			getyx(stdscr, c->y0, c->x0);
			printw("%s",stack_ptr->cmd);
			move(c->y,c->x);
	}

return stack_ptr;
}