コード例 #1
0
ファイル: fork.c プロジェクト: LediKorsar/gawk
static NODE *
do_fork(int nargs)
{
	int ret = -1;
	NODE **aptr;
	NODE *tmp;

	if  (do_lint && get_curfunc_arg_count() > 0)
		lintwarn("fork: called with too many arguments");

	ret = fork();

	if (ret < 0)
		update_ERRNO();
	else if (ret == 0) {
		/* update PROCINFO in the child */

		aptr = assoc_lookup(PROCINFO_node, tmp = make_string("pid", 3), FALSE);
		(*aptr)->numbr = (AWKNUM) getpid();
		unref(tmp);

		aptr = assoc_lookup(PROCINFO_node, tmp = make_string("ppid", 4), FALSE);
		(*aptr)->numbr = (AWKNUM) getppid();
		unref(tmp);
	}

	/* Set the return value */
	return make_number((AWKNUM) ret);
}
コード例 #2
0
ファイル: finclib.c プロジェクト: guolilong2012/study
void finc_run_string(FinC* self, unsigned char* str)
{
    FinCNode* l_node;
    String* l_str;
    FinCParser* parser;

    parser = finc_parser_new();
    finc_parser_set_env(parser, self->env);
    l_str = string_new_str(str);
	
	finc_parser_parser_string(parser, l_str);
    l_node =  addref(FinCNode, parser->tree_root);
    unref(parser);

    if ( g_finc_context->error !=0 )
    {
		printf("\t%d error founded, stopped...\n", g_finc_context->error);
		unref(l_node);
		return;
    }

    if (l_node)
    {
		finc_node_evaluate (l_node);
		unref (l_node);
    }
}
コード例 #3
0
/**
 * Map/Setの要素を全て解放する
 * entryの配列は使いまわす
 */
static int map_clear(Value *vret, Value *v, RefNode *node)
{
    RefMap *r = Value_vp(*v);
    int i;

    if (r->lock_count > 0) {
        throw_error_select(THROW_CANNOT_MODIFY_ON_ITERATION);
        return FALSE;
    }
    for (i = 0; i < r->entry_num; i++) {
        HashValueEntry *p = r->entry[i];
        while (p != NULL) {
            HashValueEntry *prev = p;
            unref(p->key);
            unref(p->val);
            p = p->next;

            free(prev);
        }
        r->entry[i] = NULL;
    }
    r->count = 0;

    return TRUE;
}
コード例 #4
0
ファイル: fincstruct.c プロジェクト: guolilong2012/study
void finc_struct_destroy(Object* self)
{
    unref(((FinCStruct*)self)->name);
    unref(((FinCStruct*)self)->hash_field);

    mem_destroy (self);
}
コード例 #5
0
ファイル: list.c プロジェクト: guolilong2012/study
void list_clear(List* self)
{
	RealList* l_reallist = (RealList*)self;
	ListNode* l_stand = l_reallist->head;
	while ( l_stand )
	{
		if ( l_stand->next )
		{
			l_stand=l_stand->next;

			unref(l_stand->prev->data);
			mem_destroy(l_stand->prev);
		}
		else
		{
			unref(l_stand->data);
			mem_destroy(l_stand);
			break;
		}
	}

	l_reallist->length=0;
	l_reallist->head=NULL;
	l_reallist->tail=NULL;
	l_reallist->current=NULL;
}
コード例 #6
0
/**
 * vからkey要素を取り除いて、valに返す
 */
int refmap_del(Value *val, RefMap *rm, Value key)
{
    HashValueEntry *ep, **epp;
    uint32_t hash;

    if (!map_search_sub(&epp, &hash, rm, key)) {
        return FALSE;
    }
    ep = *epp;
    if (ep != NULL) {
        // 一致(削除)
        unref(ep->key);
        *epp = ep->next;
        if (val != NULL) {
            *val = ep->val;
        } else {
            unref(ep->val);
        }
        free(ep);
        rm->count--;
    } else {
        if (val != NULL) {
            *val = VALUE_NULL;
        }
    }
    return TRUE;
}
コード例 #7
0
ファイル: z-object.c プロジェクト: rawnak/honeycomb
static void  z_object_cleanup_attached_properties(Self *self)
{
{
 ZVector *attached_properties = (ZVector *) selfp->attached_properties;

 if (attached_properties) {
 ZVectorIter *it, *end;

 /* iterate through all attached properties */
 it = z_vector_get_begin(attached_properties);
 end = z_vector_get_end(attached_properties);

 for (; !z_vector_iter_is_equal(it, end); z_vector_iter_increment(it)) {
 /* the vector contains a list of maps that has a pointer to 'self'.
				   our goal is to remove 'self' from the map */
 ZMap *map = (ZMap *) z_vector_get_item(attached_properties, it);

 /* remove the pointer */
 ZMapIter *x = z_map_find(map, self);
 z_map_erase1(map, x);
 unref(Z_OBJECT(x));
 }

 unref(Z_OBJECT(end));
 unref(Z_OBJECT(it));
 unref(Z_OBJECT(attached_properties));

 selfp->attached_properties = NULL;
 }

 }
}
コード例 #8
0
ファイル: uv_wrap.c プロジェクト: steveyen/uv
// params: stream, stringToWrite, afterWriteCallback(status)
//
LUA_API int wrap_uv_write(lua_State *L) {
    uv_stream_t *stream;
    uv_stream_t **stream_p = luaL_checkudata(L, 1, "uv_stream_t_ptr");
    stream = *stream_p;

    size_t slen = 0;
    char *s = (char *) luaL_checklstring(L, 2, &slen);
    if (s == NULL || slen <= 0) {
        lua_pushinteger(L, 0);
        return 1;
    }

    write_req_t *wr = malloc(sizeof(*wr));
    if (wr != NULL) {
        lua_pushvalue(L, 2);
        wr->ref_buf = ref(L);
        wr->ref_cb = ref_function(L, 3);
        if (wr->ref_buf && wr->ref_cb) {
            wr->buf = uv_buf_init(s, slen);

            int res = uv_write(&wr->req, stream, &wr->buf, 1,
                               wrap_uv_on_write);
            lua_pushinteger(L, res);
            return 1;
        }

        unref(wr->ref_buf);
        unref(wr->ref_cb);
        free(wr);
    }

    luaL_error(L, "wrap_uv_write malloc failed");
    return 0;
}
コード例 #9
0
ファイル: z-object.c プロジェクト: rawnak/honeycomb
void  z_object_disconnect(Self *self,char *name,void *key)
{
{
 assert(selfp->signal_map != NULL);

 /* locate signal's closure list by name */
 ZMap *signal_map = (ZMap *) selfp->signal_map;
 ZMapIter *map_iter = z_map_find(signal_map, name);
 assert(map_iter != NULL);
 ZVector *closure_list = z_map_get_value(signal_map, map_iter);
 unref(Z_OBJECT(map_iter));

 /* remove the closure from the list */
 ZVectorIter *it = z_vector_get_begin(closure_list);
 ZVectorIter *end = z_vector_get_end(closure_list);

 while (!z_vector_iter_is_equal(it, end)) {
 void *current_key = z_vector_get_item(closure_list, it);

 if (current_key == key) {
 z_vector_erase1(closure_list, it);
 break;
 } else {
 z_vector_iter_increment(it);
 }
 }

 unref(Z_OBJECT(end));
 unref(Z_OBJECT(it));

 unref(self);
 }
}
コード例 #10
0
	virtual void
	start(Runnable *runnable, bool detached, bool runnableShouldBeFreed) throw(ThreadException) {
		this->runnable = runnable;
		this->detached = detached;
		this->runnableShouldBeFreed = runnableShouldBeFreed;
		if (detached) {
			pthread_attr_t attr;

			if (pthread_attr_init(&attr) != 0) {
				throw ThreadException("Cannot initialize pthread attribute.");
			}
			if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0) {
				throw ThreadException("Cannot set pthread detach state.");
			}
			ref();
			if (pthread_create(&thread, &attr, entry, this) != 0) {
				unref();
				throw ThreadException("Cannot create a thread.");
			}
			pthread_attr_destroy(&attr);
		} else {
			ref();
			if (pthread_create(&thread, NULL, entry, this) != 0) {
				unref();
				throw ThreadException("Cannot create a thread.");
			}
		}
	}
コード例 #11
0
ファイル: transform.c プロジェクト: llou/libheracles
void free_filter(struct filter *f) {
    if (f == NULL)
        return;
    assert(f->ref == 0);
    unref(f->next, filter);
    unref(f->glob, string);
    free(f);
}
コード例 #12
0
ファイル: transform.c プロジェクト: llou/libheracles
void free_transform(struct transform *xform) {
    if (xform == NULL)
        return;
    assert(xform->ref == 0);
    unref(xform->lens, lens);
    unref(xform->filter, filter);
    free(xform);
}
コード例 #13
0
ファイル: finclib.c プロジェクト: guolilong2012/study
void finc_exit(FinC* self)
{
    unref(self->env);
    unref(self->sys_func);
    unref(self->context);

    mem_destroy(self);
}
コード例 #14
0
ファイル: sparr.c プロジェクト: Distrotech/gawk
static void
load_READLINE(NODE *symbol, void *data)
{
	sdata_t *sd = (sdata_t *) data;
	NODE *file, *tmp;
	FILE *fp;
	static char linebuf[BUFSIZ];
	int i;
	bool long_line = false;

	if (! sd->load_file)	/* non-existent SYS["readline"] or already loaded */ 
		return;

	file = sd->filename;
	force_string(file);

	if (file->stlen == 0)
		return;

	assoc_clear(symbol);

	if ((fp = fopen(file->stptr, "r" )) == NULL) {
		warning(_("READLINE (%s): %s"), file->stptr, strerror(errno));
		return;
	}

	for (i = 1; fgets(linebuf, sizeof(linebuf), fp ) != NULL; i++) {
		NODE **lhs;
		size_t sz;

		sz = strlen(linebuf);
		if (sz > 0 && linebuf[sz - 1] == '\n') {
			linebuf[sz - 1] = '\0';
			sz--;
			if (long_line) {
				long_line = false;
				i--;
				continue;
			}
		} else if (long_line) {
			i--;
			continue;
		} else {
			if (do_lint)
				lintwarn(_("file `%s' does not end in newline or line # `%d' is too long"),
					file->stptr, i);
			long_line = true;
		}

		tmp = make_number(i);
		lhs = assoc_lookup(symbol, tmp);
		unref(tmp);
		unref(*lhs);
		*lhs = make_string(linebuf, sz);
	}
	fclose(fp);
	sd->load_file = false;	/* don't load this file again */
}	
コード例 #15
0
ファイル: HttpConnection.cpp プロジェクト: crnt/x0
/**
 * Writes as much as it wouldn't block of the response stream into the underlying socket.
 *
 */
bool HttpConnection::writeSome()
{
	TRACE("writeSome()");
	ref();

	ssize_t rv = output_.sendto(sink_);

	TRACE("writeSome(): sendto().rv=%ld %s", rv, rv < 0 ? strerror(errno) : "");

	if (rv > 0) {
		// output chunk written
		request_->bytesTransmitted_ += rv;
		goto done;
	}

	if (rv == 0) {
		// output fully written
		watchInput();

		if (request_->isFinished()) {
			// finish() got invoked before reply was fully sent out, thus,
			// finalize() was delayed.
			request_->finalize();
		}

		TRACE("writeSome: output fully written. closed:%d, outputPending:%ld, refCount:%d", isClosed(), output_.size(), refCount_);

		if (isClosed() && !isOutputPending() && refCount_ == 0) {
			worker_->release(handle_);
		}
		goto done;
	}

	// sendto() failed
	switch (errno) {
	case EINTR:
		break;
	case EAGAIN:
#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
	case EWOULDBLOCK:
#endif
		// complete write would block, so watch write-ready-event and be called back
		watchOutput();
		break;
	default:
		//log(Severity::error, "Connection write error: %s", strerror(errno));
		goto err;
	}

done:
	unref();
	return true;

err:
	abort();
	unref();
	return false;
}
コード例 #16
0
ファイル: regexp.c プロジェクト: mchf/augeas
void free_regexp(struct regexp *regexp) {
    if (regexp == NULL)
        return;
    assert(regexp->ref == 0);
    unref(regexp->info, info);
    unref(regexp->pattern, string);
    if (regexp->re != NULL) {
        regfree(regexp->re);
        free(regexp->re);
    }
    free(regexp);
}
コード例 #17
0
ファイル: compiler.hpp プロジェクト: tomilov/insituc
 result_type
 operator () (ast::operand const & _lhs, ast::operand const & _rhs) const
 {
     auto const compile_ = [&] (auto const & l, auto const & r) -> result_type
     {
         return compile(l, r);
     };
     if (!multivisit(compile_, *unref(_lhs), *unref(_rhs))) {
         return false;
     }
     return true;
 }
コード例 #18
0
ファイル: ext.c プロジェクト: infoburp/gawk
NODE *
load_old_ext(SRCFILE *s, const char *init_func, const char *fini_func, NODE *obj)
{
	NODE *(*func)(NODE *, void *);
	NODE *tmp;
	void *dl;
	int flags = RTLD_LAZY;
	int *gpl_compat;
	const char *lib_name = s->fullpath;

	if (init_func == NULL || init_func[0] == '\0')
		init_func = OLD_INIT_FUNC;

	if (fini_func == NULL || fini_func[0] == '\0')
		fini_func = OLD_FINI_FUNC;

	if (do_sandbox)
		fatal(_("extensions are not allowed in sandbox mode"));

	if (do_traditional || do_posix)
		fatal(_("`extension' is a gawk extension"));

	if (lib_name == NULL)
		fatal(_("extension: received NULL lib_name"));

	if ((dl = dlopen(lib_name, flags)) == NULL)
		fatal(_("extension: cannot open library `%s' (%s)"), lib_name,
		      dlerror());

	/* Per the GNU Coding standards */
	gpl_compat = (int *) dlsym(dl, "plugin_is_GPL_compatible");
	if (gpl_compat == NULL)
		fatal(_("extension: library `%s': does not define `plugin_is_GPL_compatible' (%s)"),
				lib_name, dlerror());
	func = (NODE *(*)(NODE *, void *)) dlsym(dl, init_func);
	if (func == NULL)
		fatal(_("extension: library `%s': cannot call function `%s' (%s)"),
				lib_name, init_func, dlerror());

	if (obj == NULL) {
		obj = make_string(lib_name, strlen(lib_name));
		tmp = (*func)(obj, dl);
		unref(tmp);
		unref(obj);
		tmp = NULL;
	} else
		tmp = (*func)(obj, dl);

	s->fini_func = (void (*)(void)) dlsym(dl, fini_func);
	return tmp;
}
コード例 #19
0
ファイル: uv_wrap.c プロジェクト: steveyen/uv
static void wrap_uv_on_write(uv_write_t *req, int status) {
    write_req_t *wr = (write_req_t *) req;
    assert(wr && wr->ref_cb && wr->ref_cb->L);
    lua_rawgeti(wr->ref_cb->L, LUA_REGISTRYINDEX, wr->ref_cb->ref);
    lua_pushnumber(wr->ref_cb->L, status);
    if (lua_pcall(wr->ref_cb->L, 1, 0, 0) != 0) {
        printf("wrap_uv_on_write pcall error: %s\n",
               lua_tostring(wr->ref_cb->L, -1));
    }

    unref(wr->ref_buf);
    unref(wr->ref_cb);
    free(wr);
}
コード例 #20
0
ファイル: Component.cpp プロジェクト: doughodson/OpenEaagles
// setSlotComponent() -- Sets a single component
bool Component::setSlotComponent(Component* const single)
{
   // When a only one component ... make it a PairStream
   const auto pairStream = new PairStream();
   const auto pair = new Pair("1", single);
   pairStream->put( pair );
   pair->unref();

   // Process the new components list and swap
   processComponents(pairStream, typeid(Component));
   pairStream->unref();

   return true;
}
コード例 #21
0
ファイル: Matrix.cpp プロジェクト: doughodson/OpenEaagles
// Returns a pre-ref'd pointer to the inverse of this matrix, or zero
// if the matrix can not be inverted
Matrix* Matrix::getInvLU() const
{
   if (!isGoodMatrix() || !isSquare()) return nullptr;

   const unsigned int N = rows;
   const auto pL = new Matrix(N,N);
   const auto pU = new Matrix(N,N);
   getLU(pL, pU);

   const auto pB = new Matrix(N,N);
   pB->makeIdent();

   const auto pY = new Matrix(N,N);
   const auto pX = new Matrix(N,N);

   //-------------------------------------------------------
   // find Y from LY = I using forward substitution
   //-------------------------------------------------------
   for (unsigned int i = 0; i < N; i++) {
      for (unsigned int j = 0; j < N; j++) {
         (*pY)(i,j) = (*pB)(i,j);
         for (unsigned int k = 0; k < i; k++) {
            (*pY)(i,j) -= (*pL)(i,k) * (*pY)(k,j);
         }
      }
   }

   //-------------------------------------------------------
   // find X from UX = Y using back substitution
   //-------------------------------------------------------
   for (int i = (N-1); i >= 0; i--)
   {
      for (unsigned int j = 0; j < N; j++) {
         (*pX)(i,j) = (*pY)(i,j);
         for (int k = (N-1); k > i; k--) {
            (*pX)(i,j) -= (*pU)(i,k) * (*pX)(k,j);
         }
         (*pX)(i,j) /= (*pU)(i,i);
      }
   }

   pL->unref();
   pU->unref();
   pB->unref();
   pY->unref();

   return pX;
}
コード例 #22
0
ファイル: nocodec-ui-gtk.cpp プロジェクト: snorp/moon
void
GtkNoCodecsUI::Close ()
{
	gtk_widget_destroy (dialog);
	unref ();
	running = false;
}
コード例 #23
0
ファイル: coll.cpp プロジェクト: randalboyle/xmms2-devel
	Coll Coll::operator=( const Coll& src )
	{
		unref();
		coll_ = src.coll_;
		ref();
		return *this;
	}
コード例 #24
0
int main(int argc, char**argv)
{  
    int err;
    sqlite3 *conn;
    char *errmsg;
    
    err = sqlite3_open("test.sl3",&conn);

    Table *t = table_new(TableCsv | TableColumns);
    
    err = sqlite3_exec(conn,"select * from test",
        table_add_row,t,&errmsg);
    
    if (err) {
        printf("err '%s'\n",errmsg);
        return 1;
    }

    table_finish_rows(t);
    
    DUMPA(float,(float*)t->cols[1],"%f");
  
    sqlite3_close(conn);
    unref(t);
    
    DI(obj_kount());
    return 0;
}
コード例 #25
0
ファイル: HttpConnection.cpp プロジェクト: crnt/x0
void HttpConnection::io(Socket *, int revents)
{
	TRACE("io(revents=%04x) isHandlingRequest:%d", revents, flags_ & IsHandlingRequest);

	ref();

	if (revents & ev::ERROR) {
		log(Severity::error, "Potential bug in connection I/O watching. Closing.");
		abort();
		goto done;
	}

	if ((revents & Socket::Read) && !readSome())
		goto done;

	if ((revents & Socket::Write) && !writeSome())
		goto done;

	if (!process())
		goto done;

	switch (status()) {
	case ReadingRequest:
		watchInput(worker_->server_.maxReadIdle());
		break;
	case KeepAliveRead:
		watchInput(worker_->server_.maxKeepAlive());
	default:
		break;
	}

done:
	unref();
}
コード例 #26
0
ファイル: testa.c プロジェクト: stevedonovan/llib
int main(int argc,  const char **argv)
{
    ArgState *state = arg_command_line(args,argv);
    if (! interactive) {
        if (array_len(incdirs) > 0) {
            printf("the include paths\n");
            FOR_ARR (str_t,P,incdirs)
                printf("'%s'\n",*P);
        }
        if (array_len(string_args) > 0) {
            printf("the string args\n");
            FOR_ARR (str_t,P,string_args)
                printf("'%s'\n",*P);
        }
        printf("flag a is %d\n",a);
    } else {
        char *line;
            printf("> ");
        while ((line = file_getline(stdin)) != NULL) {
            char **parts = str_split(line," ");
            // args_process assumes args start at second element, hence -1 here
            PValue v = arg_process(state,(const char**)parts-1);
            if (v != NULL) {
                printf("%s\n",value_tostring(v));
                unref(v);
            }
            dispose(parts,line);
            printf("> ");
            arg_reset_used(state);
        }        
    }
    return 0;
}
コード例 #27
0
ファイル: list.c プロジェクト: guolilong2012/study
void list_remove_current(List* self)
{
	RealList* l_reallist = (RealList*)self;
	ListNode* l_stand;

	if ( l_reallist->current == NULL )return ;

	l_stand = l_reallist->current;
	if ( l_stand->prev )
		l_stand->prev->next = l_stand->next;
	else
		l_reallist->head = l_stand->next;

	if ( l_stand->next )
	{
		l_stand->next->prev = l_stand->prev;
		l_reallist->current = l_stand->next;
	}
	else
	{
		l_reallist->tail = l_stand->prev;
		l_reallist->current = l_stand->prev;
	}

	unref(l_stand->data);
	mem_destroy(l_stand);

	l_reallist->length--;
}
コード例 #28
0
ファイル: throw.c プロジェクト: x768/fox-lang
void throw_stopiter()
{
    if (fg->error != VALUE_NULL) {
        unref(fg->error);
    }
    fg->error = vp_Value(ref_new(fs->cls_stopiter));
}
コード例 #29
0
ファイル: m_apm.cpp プロジェクト: xubingyue/xqilla
void MAPM::copyFrom(M_APM Nval) 
{
	 M_APM oldVal=myVal;
	 myVal=Nval;
	 ref(myVal);
	 unref(oldVal);
}
コード例 #30
0
// endpoint builder
Endpoint* builder(const std::string& filename)
{
   // read configuration file
   unsigned int num_errors = 0;
   oe::base::Object* obj = oe::base::edl_parser(filename, factory, &num_errors);
   if (num_errors > 0) {
      std::cerr << "File: " << filename << ", number of errors: " << num_errors << std::endl;
      std::exit(EXIT_FAILURE);
   }

   // test to see if an object was created
   if (obj == nullptr) {
      std::cerr << "Invalid configuration file, no objects defined!" << std::endl;
      std::exit(EXIT_FAILURE);
   }

   // do we have a base::Pair, if so, point to object in Pair, not Pair itself
   const auto pair = dynamic_cast<oe::base::Pair*>(obj);
   if (pair != nullptr) {
      obj = pair->object();
      obj->ref();
      pair->unref();
   }

   // try to cast to proper object, and check
   const auto endpoint = dynamic_cast<Endpoint*>(obj);
   if (endpoint == nullptr) {
      std::cerr << "Invalid configuration file!" << std::endl;
      std::exit(EXIT_FAILURE);
   }
   return endpoint;
}