Exemple #1
0
int _init_xml_sax(void)
{
  start_new_program();
  ADD_STORAGE(sax_storage);

  set_init_callback(init_sax);
  set_exit_callback(exit_sax);

  ADD_FUNCTION("create", f_create,
               tFunc(tOr(tString, tObj) tObj tOr(tMapping, tVoid) tOr(tMixed, tVoid) tOr(tInt, tVoid), tVoid), 0);
  ADD_FUNCTION("parse", f_parse_xml, tFunc(tVoid, tInt), 0);
  ADD_FUNCTION("getLineNumber", f_getLineNumber, tFunc(tVoid, tInt), 0);
  ADD_FUNCTION("getColumnNumber", f_getColumnNumber, tFunc(tVoid, tInt), 0);
  
  xml_program = end_program();
  add_program_constant("SAX", xml_program, 0);

  start_new_program();
  ADD_STORAGE(sax_storage);
  
  set_init_callback(init_sax);
  set_exit_callback(exit_sax);

  ADD_FUNCTION("create", f_create,
               tFunc(tOr(tString, tObj) tObj tOr(tMapping, tVoid) tOr(tMixed, tVoid) tOr(tInt, tVoid), tVoid), 0);
  ADD_FUNCTION("parse", f_parse_html, tFunc(tOr(tString,tVoid), tInt), 0);
  ADD_FUNCTION("getLineNumber", f_getLineNumber, tFunc(tVoid, tInt), 0);
  ADD_FUNCTION("getColumnNumber", f_getColumnNumber, tFunc(tVoid, tInt), 0);
  
  html_program = end_program();
  add_program_constant("HTML", html_program, 0);
  
  return 1;
}
Exemple #2
0
void cairo_mod_init_path(void)
{
  /*! @decl constant CAIRO_PATH_MOVE_TO
   *! @decl constant CAIRO_PATH_LINE_TO
   *! @decl constant CAIRO_PATH_CURVE_TO
   *! @decl constant CAIRO_PATH_CLOSE_PATH
   *!
   *! The various types of path elements in an Cairo path
   */
  ADD_INT_CONSTANT("CAIRO_PATH_MOVE_TO", CAIRO_PATH_MOVE_TO, 0);
  ADD_INT_CONSTANT("CAIRO_PATH_LINE_TO", CAIRO_PATH_LINE_TO, 0);
  ADD_INT_CONSTANT("CAIRO_PATH_CURVE_TO", CAIRO_PATH_CURVE_TO, 0);
  ADD_INT_CONSTANT("CAIRO_PATH_CLOSE_PATH", CAIRO_PATH_CLOSE_PATH, 0);

  /* Cairo.Path */
  start_new_program();
  {
    ADD_STORAGE(struct cairo_mod_path);
    ADD_FUNCTION("_get_iterator", f_path_get_iterator, tFunc(tVoid,tObj), ID_PUBLIC);
    set_init_callback(init_cairo_mod_path);
    set_exit_callback(exit_cairo_mod_path);
  }
  add_program_constant("Path",
                       cairo_mod_path_program = end_program(),
                       0);

  /* Cairo.PathElement */
  start_new_program();
  {
    ADD_STORAGE(struct cairo_mod_path_element);
    ADD_FUNCTION("get_type", f_path_element_get_type, tFunc(tNone,tInt), ID_PUBLIC);
    ADD_FUNCTION("get_point", f_path_element_get_point, tFunc(tInt, tMapping), ID_PUBLIC);
    ADD_FUNCTION("_sprintf", f_path_element_sprintf, tFunc(tInt tMapping, tStr), ID_STATIC);
    set_init_callback(init_cairo_mod_path_element);
    set_exit_callback(exit_cairo_mod_path_element);
  }
  add_program_constant("PathElement",
                       cairo_mod_path_element_program = end_program(),
                       0);

  /* Cairo.PathIterator */
  start_new_program();
  {
    ADD_STORAGE(struct cairo_mod_path_iterator);
    ADD_FUNCTION("`!", f_path_iterator_not_operator, tFunc(tVoid,tInt), ID_PUBLIC);
    ADD_FUNCTION("`+=", f_path_iterator_add_self, tFunc(tInt,tObj), ID_PUBLIC);
    ADD_FUNCTION("index", f_path_iterator_index, tFunc(tNone,tObj), ID_PUBLIC);
    ADD_FUNCTION("value", f_path_iterator_value, tFunc(tNone,tObj), ID_PUBLIC);
    ADD_FUNCTION("first", f_path_iterator_first, tFunc(tNone,tInt), ID_PUBLIC);
    ADD_FUNCTION("next", f_path_iterator_next, tFunc(tNone,tObj), ID_PUBLIC);
    set_init_callback(init_cairo_mod_path_iterator);
    set_exit_callback(exit_cairo_mod_path_iterator);
  }
  add_program_constant("PathIterator",
                       cairo_mod_path_iterator_program = end_program(),
                       0);
}
Exemple #3
0
void pike_module_init( void )
{
  STRS(data)     = make_shared_string("data");
  STRS(file)     = make_shared_string("file");
  STRS(method)   = make_shared_string("method");
  STRS(protocol) = make_shared_string("protocol");
  STRS(query)    = make_shared_string("query");
  STRS(raw_url)  = make_shared_string("raw_url");

  SVAL(data)->type     = T_STRING;
  SVAL(file)->type     = T_STRING;
  SVAL(method)->type   = T_STRING;
  SVAL(protocol)->type = T_STRING;
  SVAL(query)->type    = T_STRING;
  SVAL(raw_url)->type  = T_STRING;
  
  add_function_constant( "parse_headers", f_parse_headers,
			 "function(string:mapping)", 0);
  add_function_constant( "parse_query_string", f_parse_query_string,
			 "function(string,mapping:void)",
			 OPT_SIDE_EFFECT);
  add_function_constant( "get_address", f_get_address,
                         "function(string:string)", 0);

  start_new_program();
  ADD_STORAGE( buffer  );
  add_function( "append", f_buf_append,
		"function(string:int)", OPT_SIDE_EFFECT );
  add_function( "create", f_buf_create, "function(mapping,mapping:void)", 0 );
  set_exit_callback(free_buf_struct);
  set_init_callback(alloc_buf_struct);
  parsehttp_program = end_program();
  add_program_constant("ParseHTTP", parsehttp_program, 0);
}
Exemple #4
0
static void cleanup_compilation(void *ignored)
{
  struct program *p = end_program();
  if (p) {
    free_program(p);
  }
}
Exemple #5
0
void source_pikestream_init( )
{
  start_new_program();
  ADD_STORAGE( struct callback_prog );
  ADD_FUNCTION("`()", f_got_data, tFunc(tInt tStr,tVoid),0);
  callback_program = end_program();
}
Exemple #6
0
void
_ol_ldap_program_init(void)
{
    start_new_program();
    ADD_STORAGE(OLSTORAGE);

    set_init_callback(init_ldap);
    set_exit_callback(exit_ldap);
    
    ADD_FUNCTION("create", f_create,
                 tFunc(tString, tVoid), 0);
    ADD_FUNCTION("bind", f_ldap_bind,
                 tFunc(tOr(tString, tVoid) tOr(tString, tVoid) tOr(tInt, tVoid),
                       tInt), 0);
    ADD_FUNCTION("unbind", f_ldap_unbind,
                 tFunc(tVoid, tInt), 0);

    ADD_FUNCTION("enable_cache", f_ldap_enable_cache,
                 tFunc(tOr(tInt, tVoid) tOr(tInt, tVoid), tInt), 0);
    ADD_FUNCTION("disable_cache", f_ldap_disable_cache,
                 tFunc(tVoid, tVoid), 0);
    ADD_FUNCTION("destroy_cache", f_ldap_destroy_cache,
                 tFunc(tVoid, tVoid), 0);
    ADD_FUNCTION("flush_cache", f_ldap_flush_cache,
                 tFunc(tVoid, tVoid), 0);
    ADD_FUNCTION("uncache_entry", f_ldap_uncache_entry,
                 tFunc(tString, tVoid), 0);
    ADD_FUNCTION("set_cache_options", f_ldap_set_cache_options,
                 tFunc(tInt, tVoid), 0);
    ADD_FUNCTION("err2string", f_ldap_err2string,
                 tFunc(tInt, tVoid), 0);
    ADD_FUNCTION("set_base_dn", f_set_base_dn,
                 tFunc(tString, tString), 0);
    ADD_FUNCTION("set_basedn", f_set_base_dn,
                 tFunc(tString, tString), 0);
    ADD_FUNCTION("set_scope", f_set_scope,
                 tFunc(tInt, tVoid), 0);
    ADD_FUNCTION("dn2ufn", f_ldap_dn2ufn,
                 tFunc(tString, tString), 0);
    ADD_FUNCTION("explode_dn", f_ldap_explode_dn,
                 tFunc(tString tOr(tInt, tVoid), tArr(tString)), 0);
    ADD_FUNCTION("search", f_ldap_search,
                 tFunc(tOr(tMapping,
                           tString tOr(tArray, tVoid) tOr(tInt, tVoid) tOr(tInt, tVoid)),
                       tOr(tObj, tInt)), 0);
    ADD_FUNCTION("modify", f_ldap_modify,
                 tFunc(tString tArr(tMap(tString, tMixed)), tVoid), 0);
    ADD_FUNCTION("add", f_ldap_add,
                 tFunc(tString tArr(tMap(tString, tMixed)), tVoid), 0);
    ADD_FUNCTION("delete", f_ldap_delete,
                 tFunc(tString, tVoid), 0);
    
    _ol_result_program_init();
    
    ldap_program = end_program();
    add_program_constant("Client", ldap_program, 0);
    add_program_constant("client", ldap_program, 0);
}
Exemple #7
0
int transition_current_machine_with_token(int machine_token_type) {

    if(machine_token_type == MTTYPE_END_OF_FILE || machine_token_type == -1) {
        if (current_machine_is_in_final_state()) {
            if (!spa_stack_is_empty(spa_stack)) {
                return_machine();
                return transition_current_machine_with_token(machine_token_type);
            } else {
                end_program();
                did_finish = 1;
                return 1;
            }
        }
    } else {
        int next_state = current_machine.state_transition_table[current_machine.current_state][machine_token_type];

        /* transition is valid */
        if (next_state != MACHINE_INVALID_STATE) {
            transition_to_next_state(next_state);
            return 1;
        }

        /* transition was not valid -> check if can call another machine */
        int next_machine = machine_call_for_current_machine(machine_token_type);
        /* can call another machine */
        if (next_machine != MTYPE_INVALID) {
            call_machine(next_machine);
            return transition_current_machine_with_token(machine_token_type);
        }
        /* cannot call another machine -> check if can pop a machine */
        if (current_machine_is_in_final_state()) {
            if (!spa_stack_is_empty(spa_stack)) {
                return_machine();
                return transition_current_machine_with_token(machine_token_type);
            } else {
                end_program();
                did_finish = 1;
                return 1;
            }
        }
    }
    throw_semantic_exception(ERR_SINTATIC, "source code could not be correctly parsed");
    did_finish = 1;
    return 0;
}
Exemple #8
0
//Reads and writes one character at a time to the respective file descriptors
//taking care of whether the command is from the socket or to the socket, while
//allowing for encryption and corresponding decryption of data
void read_write(int read_fd, int write_fd, int from_sock)
{
	int w_flag = 0, byte_offset = 0;
	char buffer[BUFF_LIMIT]; 
	ssize_t num_bytes = read(read_fd, buffer, 1);
	if(num_bytes == 0) { end_program(from_sock); }
	while(num_bytes)
	{
		if(crypt_flag && from_sock) { decrypt(buffer, BUFF_LIMIT); } 

		if(*(buffer + byte_offset) == 4)
		{ 
			end_program(from_sock);
		}

		w_flag = 0;
		//Runs all the time with buffer of size one, but allows for flexibility
		//of increasing the buffer size
		if(num_bytes + byte_offset >= BUFF_LIMIT)
		{
			while(byte_offset < BUFF_LIMIT)
			{
				if(crypt_flag && !from_sock) { encrypt(buffer, BUFF_LIMIT); }
				write(write_fd, buffer + byte_offset, 1);
				byte_offset++;
				w_flag = 1;
			}
			if(!w_flag) 
			{
				if(crypt_flag && !from_sock) { encrypt(buffer, BUFF_LIMIT); }
				write(write_fd, buffer+byte_offset,1); 
			}
			num_bytes = read(read_fd, buffer,1);
			if(num_bytes == 0) { end_program(from_sock); }
			byte_offset = 0;
			continue;
		}
		//Runs if buffer size > 1
		if(crypt_flag && !from_sock) { encrypt(buffer, BUFF_LIMIT); }
		write(write_fd,buffer+byte_offset,1);
		byte_offset++;
		num_bytes = read(read_fd, buffer + byte_offset,1);
		if(num_bytes == 0) { end_program(from_sock); }
	}
}
Exemple #9
0
void init_stdio_port(void)
{
  ptrdiff_t offset;
  START_NEW_PROGRAM_ID (STDIO_PORT);
  offset = ADD_STORAGE(struct port);
  PIKE_MAP_VARIABLE("_accept_callback",
                    offset + OFFSETOF(port, accept_callback),
                    tMix, PIKE_T_MIXED, 0);
  PIKE_MAP_VARIABLE("_id",
                    offset + OFFSETOF(port, id), tMix, PIKE_T_MIXED, 0);
  /* function(int|string,void|mixed,void|string:int) */
  ADD_FUNCTION("bind", port_bind,
	       tFunc(tOr(tInt,tStr) tOr(tVoid,tMix) tOr(tVoid,tStr) tOr(tVoid,tInt),tInt), 0);
#ifdef HAVE_SYS_UN_H
  /* function(int|string,void|mixed,void|string:int) */
  ADD_FUNCTION("bind_unix", bind_unix,
               tFunc(tStr tOr(tVoid,tMix),tInt), ID_OPTIONAL);
#endif /* HAVE_SYS_UN_H */
  ADD_FUNCTION("close",port_close,tFunc(tNone,tVoid),0);
  /* function(int,void|mixed:int) */
  ADD_FUNCTION("listen_fd",port_listen_fd,tFunc(tInt tOr(tVoid,tMix),tInt),0);
  /* function(mixed:mixed) */
  ADD_FUNCTION("set_id",port_set_id,tFunc(tMix,tMix),0);
  /* function(:mixed) */
  ADD_FUNCTION("query_id",port_query_id,tFunc(tNone,tMix),0);
  /* function(:string) */
  ADD_FUNCTION("query_address",socket_query_address,tFunc(tNone,tStr),0);
  /* function(:int) */
  ADD_FUNCTION("errno",port_errno,tFunc(tNone,tInt),0);
  /* function(:object) */
  port_fd_factory_fun_num =
    ADD_FUNCTION("fd_factory", port_fd_factory, tFunc(tNone,tObjIs_STDIO_FD),
                 ID_PROTECTED);
  ADD_FUNCTION("accept",port_accept,tFunc(tNone,tObjIs_STDIO_FD),0);
  /* function(void|string|int,void|mixed,void|string:void) */
  ADD_FUNCTION("create", port_create,
	       tFunc(tOr3(tVoid,tStr,tInt) tOr(tVoid,tMix) tOr(tVoid,tStr),
		     tVoid), 0);
  ADD_FUNCTION ("set_backend", port_set_backend, tFunc(tObj,tVoid), 0);
  ADD_FUNCTION ("query_backend", port_query_backend, tFunc(tVoid,tObj), 0);
  ADD_FUNCTION ("query_fd", port_query_fd, tFunc(tVoid,tInt), 0);

#ifdef SO_REUSEPORT
  ADD_INT_CONSTANT( "SO_REUSEPORT_SUPPORT", SO_REUSEPORT, ID_OPTIONAL );
#endif
#ifdef TCP_FASTOPEN
  ADD_INT_CONSTANT( "TCP_FASTOPEN_SUPPORT", TCP_FASTOPEN, ID_OPTIONAL );
#endif
  set_init_callback(init_port_struct);
  set_exit_callback(exit_port_struct);

  port_program = end_program();
  add_program_constant( "_port", port_program, 0 );

}
Exemple #10
0
void init_pike_searching(void)
{
  start_new_program();
  pike_search_struct_offset=ADD_STORAGE(struct pike_mem_searcher);
  MAP_VARIABLE("__s", tStr, 0,
	       pike_search_struct_offset + OFFSETOF(pike_mem_searcher,s),
	       PIKE_T_STRING);
  pike_search_program=end_program();
  add_program_constant("Search",pike_search_program,ID_STATIC);

  memsearch_cache=allocate_mapping(10);
  memsearch_cache->data->flags |= MAPPING_FLAG_WEAK;
}
Exemple #11
0
void pike_module_init(void)
{
  #ifdef PEXTS_VERSION
  pexts_init();
#endif

    /* Compression program */
    start_new_program();
    ADD_STORAGE(bz_stream);
    
    set_init_callback(init_deflate);
    set_exit_callback(exit_deflate);

    ADD_FUNCTION("create", f_deflate_create, 
                 tFunc( tOr(tVoid, tInt), tVoid), 0);
    ADD_FUNCTION("deflate", f_deflate_deflate,
		 tFunc(tString tOr(tInt, tVoid), tString), 0);
    ADD_FUNCTION("compress_file", f_deflate_file,
		 tFunc(tString tOr(tString, tVoid), tVoid), 0);

    deflate_program = end_program();
    add_program_constant("deflate", deflate_program, 0);
    
    /* Decompression program */
    start_new_program();
    ADD_STORAGE(bz_stream);

    ADD_FUNCTION("create", f_inflate_create, 
                 tFunc(tOr(tInt, tVoid), tVoid), 0);
    ADD_FUNCTION("inflate", f_inflate_inflate,
		 tFunc(tString, tString), 0);
		 
    set_init_callback(init_inflate);
    set_exit_callback(exit_inflate);
    
    inflate_program = end_program();
    add_program_constant("inflate", inflate_program, 0);
}
Exemple #12
0
main()
{
int nprocs = 4;

//tempo

struct timeval iniciotmp, finaltmp;

int tempogasto;


int pidf,id_wait;
void dt_shareG();

   mc_var_inic ();

   def_task (0, "inicializa_matriz", sizeof (__inicializa_matriz__));
   def_task (1, "multiplica_matriz", sizeof (__multiplica_matriz__));
   id_wait=sem_wait_inic(2);


   alloc_proc(nprocs);
      
   pidf = exec_task (0, nprocs);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      inicializa_matriz();
      end_task();            /* --- rs31() - create --- */
   }

    wait_all();
    gettimeofday(&iniciotmp, NULL);
      
   pidf = exec_task (1, nprocs);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      multiplica_matriz();
      end_task();            /* --- rs31() - create --- */
   }

    wait_all();
    gettimeofday(&finaltmp, NULL);
    tempogasto = (int) (1000 * (finaltmp.tv_sec - iniciotmp.tv_sec) + (finaltmp.tv_usec - iniciotmp.tv_usec) / 1000);
    printf("Tempo decorrido: %d\n", tempogasto);
       wait_all();      /* --- rs307()  */
   end_program();
   remove_semaforo(id_wait);
return 0;
}
Exemple #13
0
void task_end() {
	debug("Main waiting for pthreads to arrive here");
	int i;
	end_program();
	debug("End in pthread %d", (int) pthread_self());

	for (i = 0; i < schedulers_nr; ++i) {
		debug("Waiting for thread %d", i);
		//pthread_cond_broadcast(&wake_up_threads);
		pthread_join(schedulers[i].thread, NULL);	
	}

	for (i = 0; i < schedulers_nr; ++i) {		
		pthread_mutex_destroy(&schedulers[i].ready.lock);
		pthread_mutex_destroy(&schedulers[i].lock);
	}
	
	SAFE_FREE(schedulers);
	debug("End reached");
}
Exemple #14
0
board *dup_board(board *src, board *dest)
{
	int x, y;

	board *dest;
	
	dest = malloc(sizeof(*dest));

	if (!dest) {
		end_program();
	}

	for (y = 0; y < brd_h; y++) {
		for (x = 0; x < brd_w; x++) {
			(*dest)[y][x] = (*src)[y][x];
		}
	}

	return dest;
}
Exemple #15
0
int main()
{
	int key;

	init_display();

	play_again:
	reset_game();
	display_board(&grid);
	play_game();

	movecur(15, 9 + brd_h * 2);
	textcolour(12);
	strout("Game Over! Press ESCAPE to exit or ENTER to play again.");

	do {
		key = os_wait_for_key();
	} while (key != ESC_KEY && key != ENTER_KEY);

	if (key == ENTER_KEY) goto play_again;
	end_program();
}
Exemple #16
0
void init_avs_search_program(void)
{
  // start building the AVS.Search program
  start_new_program();

  // request space for the per-object private data
  ADD_STORAGE(struct private_search_data);


  // add the program methods
  add_function("create", f_create, 
	"function(object:void)", ID_PUBLIC);
  add_function("destroy", f_destroy, 
	"function(void:void)", ID_PUBLIC);
  add_function("docsfound", f_docsfound, 
	"function(void:int)", ID_PUBLIC);
  add_function("docsreturned", f_docsreturned, 
	"function(void:int)", ID_PUBLIC);
  add_function("termcount", f_termcount, 
	"function(void:int)", ID_PUBLIC);
  add_function("get_result", f_get_result, 
	"function(int:void)", ID_PUBLIC);
  add_function("get_term", f_get_term,
	"function(int:array)", ID_PUBLIC);
  add_function("get_version", f_get_version,
	"function(void:string)", ID_PUBLIC);
  add_function("get_date", f_get_date,
	"function(void:array)", ID_PUBLIC);
  add_function("get_data", f_get_data,
	"function(void:string)", ID_PUBLIC);
  add_function("get_docid", f_get_docid,
	"function(void:string)", ID_PUBLIC);
  add_function("get_relevance", f_get_relevance,
	"function(void:float)", ID_PUBLIC);

  // finish and add the AVS.Search program
  search_program = end_program();
  add_program_constant("Search", search_program, 0);
}
Exemple #17
0
/* Initialized the sender */
void init_nbio(void) {
  start_new_program();
  ADD_STORAGE( nbio_storage );
  set_init_callback(alloc_nb_struct);
  set_exit_callback(free_nb_struct);
  ADD_FUNCTION("start", f_nbio_start, tFunc(tVoid, tVoid), 0);
  ADD_FUNCTION("nbio_status", f_nbio_status, tFunc(tVoid, tArray), 0);
  ADD_FUNCTION("input",  f_input, tFunc(tObj tOr(tInt, tVoid), tVoid), 0);
  ADD_FUNCTION("write",  f_write, tFunc(tStr, tVoid), 0);
  ADD_FUNCTION("output", f_output, tFunc(tObj, tVoid), 0);
  ADD_FUNCTION("_output_write_cb", f__output_write_cb, tFunc(tInt, tVoid), 0);
  ADD_FUNCTION("_input_read_cb", f__input_read_cb, tFunc(tInt tStr, tVoid), 0);
  ADD_FUNCTION("_input_close_cb", f__input_close_cb, tFunc(tInt, tVoid), 0);
  ADD_FUNCTION("set_done_callback", f_set_done_callback, tFunc(tOr(tVoid,tFunc(tMix, tMix)) tOr(tVoid,tMix),tVoid),0);
  ADD_FUNCTION("bytes_sent", f_bytes_sent, tFunc(tNone,tInt), 0);
  nbio_program = end_program();
  add_program_constant("nbio", nbio_program, 0);
  
  output_write_cb_off = find_identifier("_output_write_cb", nbio_program);
  input_read_cb_off   = find_identifier("_input_read_cb", nbio_program);
  input_close_cb_off  = find_identifier("_input_close_cb", nbio_program);
}
Exemple #18
0
void init_avs_count_program(void)
{
  // start building the AVS.Search program
  start_new_program();

  // request space for the per-object private data
  ADD_STORAGE(struct private_count_data);

  // add the program methods
  add_function("create", f_create, 
	"function(object:void)", ID_PUBLIC);
  add_function("destroy", f_destroy, 
	"function(void:void)", ID_PUBLIC);
  add_function("get_count", f_get_count, 
	"function(void:int)", ID_PUBLIC);
  add_function("next", f_next, 
	"function(void:void)", ID_PUBLIC);
  add_function("get_word", f_get_word, 
	"function(void:string)", ID_PUBLIC);

  // finish and add the AVS.Search program
  count_program = end_program();
  add_program_constant("Count", count_program, 0);
}
Exemple #19
0
/*! @decl program load_module(string module_name)
 *!
 *! Load a binary module.
 *!
 *! This function loads a module written in C or some other language
 *! into Pike. The module is initialized and any programs or constants
 *! defined will immediately be available.
 *!
 *! When a module is loaded the C function @tt{pike_module_init()@} will
 *! be called to initialize it. When Pike exits @tt{pike_module_exit()@}
 *! will be called. These two functions @b{must@} be available in the module.
 *!
 *! @note
 *!   The current working directory is normally not searched for
 *!   dynamic modules. Please use @expr{"./name.so"@} instead of just
 *!   @expr{"name.so"@} to load modules from the current directory.
 */
void f_load_module(INT32 args)
{
  extern int global_callable_flags;

  void *module;
  modfun init, exit;
  struct module_list *new_module;
  struct pike_string *module_name;

  ONERROR err;

  module_name = Pike_sp[-args].u.string;

  if((Pike_sp[-args].type != T_STRING) ||
     (module_name->size_shift) ||
     string_has_null(module_name)) {
    Pike_error("Bad argument 1 to load_module()\n");
  }

  {
    struct module_list *mp;
    for (mp = dynamic_module_list; mp; mp = mp->next)
      if (mp->name == module_name && mp->module_prog) {
	pop_n_elems(args);
	ref_push_program(mp->module_prog);
	return;
      }
  }

  /* Removing RTLD_GLOBAL breaks some PiGTK themes - Hubbe */
  /* Using RTLD_LAZY is faster, but makes it impossible to 
   * detect linking problems at runtime..
   */
  module=dlopen(module_name->str, 
                RTLD_NOW /*|RTLD_GLOBAL*/  );

  if(!module)
  {
    struct object *err_obj = low_clone (module_load_error_program);
#define LOADERR_STRUCT(OBJ) \
    ((struct module_load_error_struct *) (err_obj->storage + module_load_error_offset))

    const char *err = dlerror();
    if (err) {
      if (err[strlen (err) - 1] == '\n')
	push_string (make_shared_binary_string (err, strlen (err) - 1));
      else
	push_text (err);
    }
    else
      push_constant_text ("Unknown reason");

    add_ref (LOADERR_STRUCT (err_obj)->path = Pike_sp[-args - 1].u.string);
    add_ref (LOADERR_STRUCT (err_obj)->reason = Pike_sp[-1].u.string);

    if (Pike_sp[-args].u.string->len < 1024) {
      throw_error_object (err_obj, "load_module", Pike_sp - args - 1, args,
			  "load_module(\"%s\") failed: %s\n",
			  module_name->str, Pike_sp[-1].u.string->str);
    } else {
      throw_error_object (err_obj, "load_module", Pike_sp - args - 1, args,
			  "load_module() failed: %s\n",
			  Pike_sp[-1].u.string->str);
    }
  }

#ifdef PIKE_DEBUG
  {
    struct module_list *mp;
    for (mp = dynamic_module_list; mp; mp = mp->next)
      if (mp->module == module && mp->module_prog) {
	fprintf(stderr, "load_module(): Module loaded twice:\n"
		"Old name: %s\n"
		"New name: %s\n",
		mp->name->str, module_name->str);
	pop_n_elems(args);
	ref_push_program(mp->module_prog);
	return;
      }
  }
#endif /* PIKE_DEBUG */

  init = CAST_TO_FUN(dlsym(module, "pike_module_init"));
  if (!init) {
    init = CAST_TO_FUN(dlsym(module, "_pike_module_init"));
    if (!init) {
      dlclose(module);
      Pike_error("pike_module_init missing in dynamic module \"%S\".\n",
		 module_name);
    }
  }

  exit = CAST_TO_FUN(dlsym(module, "pike_module_exit"));
  if (!exit) {
    exit = CAST_TO_FUN(dlsym(module, "_pike_module_exit"));
    if (!exit) {
      dlclose(module);
      Pike_error("pike_module_exit missing in dynamic module \"%S\".\n",
		 module_name);
    }
  }

#if defined(__NT__) && defined(_M_IA64)
  {
    fprintf(stderr, "pike_module_init: 0x%p\n"
	    "  func: 0x%p\n"
	    "  gp:   0x%p\n",
	    init, ((void **)init)[0], ((void **)init)[1]);
    fprintf(stderr, "pike_module_exit: 0x%p\n"
	    "  func: 0x%p\n"
	    "  gp:   0x%p\n",
	    exit, ((void **)exit)[0], ((void **)exit)[1]);
  }
#endif /* __NT__ && _M_IA64 */

  new_module=ALLOC_STRUCT(module_list);
  new_module->next=dynamic_module_list;
  dynamic_module_list=new_module;
  new_module->module=module;
  copy_shared_string(new_module->name, Pike_sp[-args].u.string);
  new_module->module_prog = NULL;
  new_module->init=init;
  new_module->exit=exit;

  enter_compiler(new_module->name, 1);

  start_new_program();

  global_callable_flags|=CALLABLE_DYNAMIC;

#ifdef PIKE_DEBUG
  { struct svalue *save_sp=Pike_sp;
#endif
  SET_ONERROR(err, cleanup_compilation, NULL);
#if defined(__NT__) && defined(_M_IA64)
  fprintf(stderr, "Calling pike_module_init()...\n");
#endif /* __NT__ && _M_IA64 */
  (*(modfun)init)();
#if defined(__NT__) && defined(_M_IA64)
  fprintf(stderr, "pike_module_init() done.\n");
#endif /* __NT__ && _M_IA64 */
  UNSET_ONERROR(err);
#ifdef PIKE_DEBUG
  if(Pike_sp != save_sp)
    Pike_fatal("load_module(%s) left %ld droppings on stack!\n",
	       module_name->str,
	       PTRDIFF_T_TO_LONG(Pike_sp - save_sp));
  }
#endif

  pop_n_elems(args);
  {
    struct program *p = end_program();
    exit_compiler();
    if (p) {
      if (
#if 0
	  p->num_identifier_references
#else /* !0 */
	  1
#endif /* 0 */
	  ) {
	push_program(p);
	add_ref(new_module->module_prog = Pike_sp[-1].u.program);
      } else {
	/* No identifier references -- Disabled module. */
	free_program(p);
	push_undefined();
      }
    } else {
      /* Initialization failed. */
      new_module->exit();
      dlclose(module);
      dynamic_module_list = new_module->next;
      free_string(new_module->name);
      free(new_module);
      Pike_error("Failed to initialize dynamic module \"%S\".\n",
		 module_name);
    }
  }
}
Exemple #20
0
int main()
{
int i, j;


int pidf,id_wait;
void dt_shareG();

   mc_var_inic ();

   def_task (0, "multiplicarAB", sizeof (__multiplicarAB__));
   def_task (1, "multiplicarCD", sizeof (__multiplicarCD__));
   def_task (2, "sumar", sizeof (__sumar__));
   def_task (3, "print", sizeof (__print__));
   id_wait=sem_wait_inic(4);


   for (i=0; i<100; i++){
        for (j = 0; j < 100; j++)
        {
            /*A[i][j] = i + j;
            B[i][j] = i + 2*j;
            C[i][j] = i*2 + j*3;
            D[i][j] = i*2 + j;*/
            sharedG->A[i][j] = 1;
            sharedG->B[i][j] = 1;
            sharedG->C[i][j] = 1;
            sharedG->D[i][j] = 1;
        }
    }

    alloc_proc(4);

      
   pidf = exec_task (0, 1);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      multiplicarAB();
      end_task();            /* --- rs31() - create --- */
   }

      
   pidf = exec_task (1, 1);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      multiplicarCD();
      end_task();            /* --- rs31() - create --- */
   }


    wait_all();

      
   pidf = exec_task (2, 1);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      sumar();
      end_task();            /* --- rs31() - create --- */
   }

    
    
   wait_proc (2);    /* --- wait_proc() --- */


      
   pidf = exec_task (3, 1);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      print();
      end_task();            /* --- rs31() - create --- */
   }


       wait_all();      /* --- rs307()  */
   end_program();
   remove_semaforo(id_wait);
return 0;
}
void CPhantomContextView::EndProgram()
{
    end_program();
}