tor  0.4.0.0-alpha-dev
Macros
smartlist_foreach.h File Reference

Go to the source code of this file.

Macros

#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
 
#define SMARTLIST_FOREACH_REVERSE_BEGIN(sl, type, var)
 
#define SMARTLIST_FOREACH_END(var)
 
#define SMARTLIST_FOREACH(sl, type, var, cmd)
 
#define SMARTLIST_DEL_CURRENT(sl, var)
 
#define SMARTLIST_DEL_CURRENT_KEEPORDER(sl, var)
 
#define SMARTLIST_REPLACE_CURRENT(sl, var, val)
 

Detailed Description

Macros for iterating over the elements of a smartlist_t.

Definition in file smartlist_foreach.h.

Macro Definition Documentation

◆ SMARTLIST_DEL_CURRENT

#define SMARTLIST_DEL_CURRENT (   sl,
  var 
)
Value:
smartlist_del(sl, var ## _sl_idx); \
--var ## _sl_idx; \
--var ## _sl_len; \
STMT_END
void smartlist_del(smartlist_t *sl, int idx)

Helper: While in a SMARTLIST_FOREACH loop over the list sl indexed with the variable var, remove the current element in a way that won't confuse the loop.

Definition at line 120 of file smartlist_foreach.h.

Referenced by circuit_free_all(), entry_guards_load_guards_from_state(), hs_pick_hsdir(), microdescs_add_to_cache(), pt_prepare_proxy_list_for_config_read(), remove_invalid_intro_points(), routerset_subtract_nodes(), set_environment_variable_in_smartlist(), sweep_bridge_list(), sweep_proxy_list(), and sweep_transport_list().

◆ SMARTLIST_DEL_CURRENT_KEEPORDER

#define SMARTLIST_DEL_CURRENT_KEEPORDER (   sl,
  var 
)
Value:
smartlist_del_keeporder(sl, var ## _sl_idx); \
--var ## _sl_idx; \
--var ## _sl_len; \
STMT_END
void smartlist_del_keeporder(smartlist_t *sl, int idx)

Helper: While in a SMARTLIST_FOREACH loop over the list sl indexed with the variable var, remove the current element in a way that won't confuse the loop.

Definition at line 130 of file smartlist_foreach.h.

Referenced by MOCK_IMPL().

◆ SMARTLIST_FOREACH

#define SMARTLIST_FOREACH (   sl,
  type,
  var,
  cmd 
)
Value:
SMARTLIST_FOREACH_BEGIN(sl,type,var) { \
cmd; \
} SMARTLIST_FOREACH_END(var)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)

An alias for SMARTLIST_FOREACH_BEGIN and SMARTLIST_FOREACH_END, using cmd as the loop body. This wrapper is here for convenience with very short loops.

By convention, we do not use this for loops which nest, or for loops over 10 lines or so. Use SMARTLIST_FOREACH_{BEGIN,END} for those.

Definition at line 112 of file smartlist_foreach.h.

Referenced by addr_policy_list_free_(), already_have_cert(), assert_unconfigured_count_ok(), authority_cert_get_all(), authority_cert_get_by_digests(), authority_cert_get_by_sk_digest(), authority_cert_get_newest_by_id(), bridge_free_(), bridge_line_free_(), cert_list_free_(), circpad_machines_free(), circuit_clear_testing_cell_stats(), clear_bridge_list(), clear_dir_servers(), clear_geoip_db(), clear_transport_list(), config_clear(), connection_free_all(), connection_or_clear_identity_map(), connection_or_update_token_buckets(), consensus_join_lines(), control_event_conn_bandwidth_used(), control_event_descriptors_changed(), control_update_global_event_mask(), count_established_intro_points(), crypto_digest_smartlist_prefix(), dir_conn_clear_spool(), dirserv_get_routerdescs(), dirvote_clear_votes(), dump_routerlist_mem_usage(), find_all_by_keyword(), find_all_exitpolicy(), find_bridge_by_digest(), find_expiring_intro_point(), find_opt_by_keyword(), format_cell_stats(), geoip_load_file(), get_configured_bridge_by_routerinfo(), get_transport_proxy_ports(), getinfo_helper_downloads(), guard_selection_free_(), interface_address6_list_free_(), kvline_encode(), list_getinfo_options(), list_v3_auth_ids(), make_consensus_method_list(), managed_proxy_destroy(), mark_bridge_list(), mark_transport_list(), microdesc_check_counts(), microdesc_free_all(), microdesc_reset_outdated_dirservers_list(), microdescs_add_to_cache(), MOCK_IMPL(), networkstatus_get_detached_signatures(), networkstatus_get_voter_by_id(), networkstatus_get_voter_sig_by_alg(), networkstatus_reset_warnings(), networkstatus_vote_free_(), node_in_nickname_smartlist(), nodelist_refresh_countries(), nodes_in_same_family(), or_options_free_(), parse_protocol_list(), process_free_(), process_free_all(), process_reset_environment(), proto_entry_free_(), protocol_list_supports_protocol(), protover_contains_long_protocol_names(), protover_free_all(), pt_prepare_proxy_list_for_config_read(), rend_client_get_random_intro_impl(), rend_data_free_(), rend_parse_client_keys(), rend_parse_service_authorization(), rend_service_free_(), rend_service_free_all(), rend_service_get_by_pk_digest(), rend_service_get_by_service_id(), rep_hist_remove_predicted_ports(), rep_hist_reset_buffer_stats(), rep_hist_update_bwhist_state_section(), retry_listener_ports(), router_find_exact_exit_enclave(), router_get_fallback_dirserver_by_digest(), router_get_trusteddirserver_by_digest(), router_reset_warnings(), router_set_status(), routerlist_find_elt_(), routerlist_find_my_routerinfo(), routerlist_reset_warnings(), routerset_free_(), routerset_get_all_nodes(), routerset_subtract_nodes(), schedule_active_linked_connections_cb(), signed_descs_update_status_from_consensus_networkstatus(), storage_dir_free_(), storage_dir_rescan(), storage_dir_save_chunks_to_file(), trusted_dirs_flush_certs_to_disk(), and write_short_policy().

◆ SMARTLIST_FOREACH_BEGIN

#define SMARTLIST_FOREACH_BEGIN (   sl,
  type,
  var 
)
Value:
STMT_BEGIN \
int var ## _sl_idx, var ## _sl_len=(sl)->num_used; \
type var; \
for (var ## _sl_idx = 0; var ## _sl_idx < var ## _sl_len; \
++var ## _sl_idx) { \
var = (sl)->list[var ## _sl_idx];

Iterate over the items in a smartlist sl, in order. For each item, assign it to a new local variable of type type named var, and execute the statements inside the loop body. Inside the loop, the loop index can be accessed as var_sl_idx and the length of the list can be accessed as var_sl_len.

NOTE: Do not change the length of the list while the loop is in progress, unless you adjust the _sl_len variable correspondingly. See second example below.

Example use:

  smartlist_t *list = smartlist_split("A:B:C", ":", 0, 0);
  SMARTLIST_FOREACH_BEGIN(list, char *, cp) {
    printf("%d: %s\n", cp_sl_idx, cp);
    tor_free(cp);
  } SMARTLIST_FOREACH_END(cp);
  smartlist_free(list);

Example use (advanced):

  SMARTLIST_FOREACH_BEGIN(list, char *, cp) {
    if (!strcmp(cp, "junk")) {
      tor_free(cp);
      SMARTLIST_DEL_CURRENT(list, cp);
    }
  } SMARTLIST_FOREACH_END(cp);

Definition at line 78 of file smartlist_foreach.h.

Referenced by addr_policy_append_reject_addr_list(), addr_policy_append_reject_addr_list_filter(), addressmap_address_should_automap(), bridge_resolve_conflicts(), channel_free_list(), channel_listener_free_list(), check_server_ports(), choose_guard_selection(), circpad_handle_padding_negotiate(), circuit_any_opened_circuits(), circuit_close_all_marked(), circuit_discard_optional_exit_enclaves(), circuit_dump_by_conn(), circuit_enough_testing_circs(), circuit_expire_old_circuits_clientside(), circuit_expire_old_circuits_serverside(), circuit_expire_waiting_for_better_guard(), circuit_free_all(), circuit_get_all_pending_on_channel(), circuit_get_best(), circuit_get_by_global_id(), circuit_get_ready_rend_circ_by_rend_data(), circuit_log_ancient_one_hop_circuits(), circuit_mark_all_dirty_circs_as_unusable(), circuit_mark_all_unused_circs(), circuit_predict_and_launch_new(), circuit_stream_is_being_handled(), circuit_unlink_all_from_channel(), clear_circ_bw_fields(), compare_known_tor_addr_to_addr_policy(), compare_known_tor_addr_to_addr_policy_noport(), compare_unknown_tor_addr_to_addr_policy(), compute_consensus_versions_list(), compute_routerstatus_consensus(), connection_ap_expire_beginning(), connection_ap_fail_onehop(), connection_control_closed(), connection_expire_held_open(), connection_mark_all_noncontrol_connections(), connection_mark_all_noncontrol_listeners(), connection_or_group_set_badness_(), control_event_circ_bandwidth_used(), control_ports_write_to_file(), count_intro_point_circuits(), count_pending_general_client_circuits(), count_real_listeners(), dircollator_add_vote(), directory_get_from_all_authorities(), directory_remove_invalid(), dirserv_count_measured_bws(), dirserv_get_routerdesc_spool(), dirserv_test_reachability(), dirvote_fetch_missing_votes(), dirvote_get_intermediate_param_value(), dump_cell_pool_usage(), dump_desc_fifo_cleanup(), dumpstats(), encode_protocol_list(), entry_guard_chan_failed(), entry_guards_all_primary_guards_are_down(), entry_guards_free_all(), entry_guards_load_guards_from_state(), entry_guards_update_confirmed(), entry_guards_update_filtered_sets(), entry_guards_update_guards_in_state(), entry_guards_update_primary(), exit_policy_is_general_exit_helper(), expand_protocol_list(), fetch_bridge_descriptors(), fetch_v2_desc_by_descid(), find_single_ipv6_orport(), find_transport_name_by_bridge_addrport(), flush_log_messages_from_startup(), geoip_get_request_history(), get_bindaddr_for_server_proxy(), get_configured_bridge_by_addr_port_digest(), get_configured_bridge_by_exact_addr_port_digest(), get_configured_bridge_by_orports_digest(), get_eligible_guards(), get_first_advertised_addr_by_type_af(), get_first_advertised_port_by_type_af(), get_first_listener_addrport_string(), get_frequent_members(), get_managed_proxy_by_argv_and_type(), get_possible_sybil_list(), get_sampled_guard_with_id(), get_transport_by_bridge_addrport(), get_transport_options_for_server_proxy(), get_transport_proxy_ports(), getinfo_helper_entry_guards(), hostname_in_track_host_exits(), hs_pick_hsdir(), list_pending_fpsk_downloads(), list_server_status_v1(), mark_all_dirservers_up(), mark_primary_guards_maybe_reachable(), microdescs_add_to_cache(), MOCK_IMPL(), networkstatus_check_consensus_signature(), nodelist_add_node_and_family(), nodelist_assert_ok(), nodelist_find_nodes_with_microdesc(), num_reachable_filtered_guards(), ocirc_event_publish(), orconn_event_publish(), pathbias_count_circs_in_states(), policies_log_first_redundant_entry(), policies_parse_exit_policy_reject_private(), policy_dump_to_string(), policy_expand_private(), policy_expand_unspec(), policy_is_reject_star(), port_exists_by_type_addr_port(), proto_entry_encode_into(), protocol_list_supports_protocol_or_later(), proxy_mode(), proxy_prepare_for_restart(), pt_get_extra_info_descriptor_string(), pt_prepare_proxy_list_for_config_read(), reenable_blocked_connections_cb(), register_client_proxy(), register_server_proxy(), remove_invalid_intro_points(), rend_client_cancel_descriptor_fetches(), rend_client_close_other_intros(), rend_client_desc_trynow(), rend_services_add_filenames_to_lists(), rep_hist_get_predicted_ports(), rep_hist_note_used_port(), rep_hist_remove_predicted_ports(), retry_all_listeners(), retry_listener_ports(), router_exit_policy_all_nodes_reject(), router_get_active_listener_port_by_type_af(), routerlist_assert_ok(), routerlist_descriptors_added(), routers_make_ed_keys_unique(), sample_reachable_filtered_entry_guards(), sampled_guards_prune_obsolete_entries(), sampled_guards_update_consensus_presence(), scale_active_circuits(), select_scheduler(), set_environment_variable_in_smartlist(), storage_dir_clean_tmpfiles(), storage_dir_get_usage(), sum_up_cell_stats_by_command(), sweep_bridge_list(), sweep_proxy_list(), sweep_transport_list(), warn_nonlocal_client_ports(), warn_nonlocal_controller_ports(), and warn_nonlocal_ext_orports().

◆ SMARTLIST_FOREACH_END

#define SMARTLIST_FOREACH_END (   var)
Value:
var = NULL; \
(void) var ## _sl_idx; \
} STMT_END

Definition at line 99 of file smartlist_foreach.h.

◆ SMARTLIST_FOREACH_REVERSE_BEGIN

#define SMARTLIST_FOREACH_REVERSE_BEGIN (   sl,
  type,
  var 
)
Value:
STMT_BEGIN \
int var ## _sl_idx, var ## _sl_len=(sl)->num_used; \
type var; \
for (var ## _sl_idx = var ## _sl_len-1; var ## _sl_idx >= 0; \
--var ## _sl_idx) { \
var = (sl)->list[var ## _sl_idx];

Iterates over the items in smartlist sl in reverse order, similar to SMARTLIST_FOREACH_BEGIN

NOTE: This macro is incompatible with SMARTLIST_DEL_CURRENT.

Definition at line 91 of file smartlist_foreach.h.

Referenced by circpad_add_matching_machines().

◆ SMARTLIST_REPLACE_CURRENT

#define SMARTLIST_REPLACE_CURRENT (   sl,
  var,
  val 
)
Value:
STMT_BEGIN \
smartlist_set(sl, var ## _sl_idx, val); \
STMT_END

Helper: While in a SMARTLIST_FOREACH loop over the list sl indexed with the variable var, replace the current element with val. Does not deallocate the current value of var.

Definition at line 141 of file smartlist_foreach.h.