Tor  0.4.3.0-alpha-dev
Macros | Functions
smartlist_core.c File Reference

Implements the core functionality of a smartlist (a resizeable dynamic array). For more functionality and helper functions, see the container library. More...

#include "lib/err/torerr.h"
#include "lib/malloc/malloc.h"
#include "lib/smartlist_core/smartlist_core.h"
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Macros

#define SMARTLIST_DEFAULT_CAPACITY   16
 
#define MAX_CAPACITY   (int)((SIZE_MAX / (sizeof(void*))))
 

Functions

smartlist_tsmartlist_new (void)
 
void smartlist_free_ (smartlist_t *sl)
 
void smartlist_clear (smartlist_t *sl)
 
static void smartlist_ensure_capacity (smartlist_t *sl, size_t size)
 
void smartlist_grow (smartlist_t *sl, size_t new_size)
 
void smartlist_add (smartlist_t *sl, void *element)
 
void smartlist_add_all (smartlist_t *s1, const smartlist_t *s2)
 
void smartlist_add_strdup (struct smartlist_t *sl, const char *string)
 
void smartlist_remove (smartlist_t *sl, const void *element)
 
void smartlist_remove_keeporder (smartlist_t *sl, const void *element)
 
void * smartlist_pop_last (smartlist_t *sl)
 
int smartlist_contains (const smartlist_t *sl, const void *element)
 
void smartlist_del (smartlist_t *sl, int idx)
 
void smartlist_del_keeporder (smartlist_t *sl, int idx)
 
void smartlist_insert (smartlist_t *sl, int idx, void *val)
 

Detailed Description

Implements the core functionality of a smartlist (a resizeable dynamic array). For more functionality and helper functions, see the container library.

Definition in file smartlist_core.c.

Macro Definition Documentation

◆ SMARTLIST_DEFAULT_CAPACITY

#define SMARTLIST_DEFAULT_CAPACITY   16

All newly allocated smartlists have this capacity.

Definition at line 21 of file smartlist_core.c.

Function Documentation

◆ smartlist_add()

void smartlist_add ( smartlist_t sl,
void *  element 
)

Append element to the end of the list.

Definition at line 117 of file smartlist_core.c.

Referenced by add_connection_to_closeable_list(), authdir_type_to_string(), authority_cert_get_all(), build_vanguard_middle_exclude_list(), circuit_add_to_origin_circuit_list(), circuit_describe_status_for_controller(), circuit_get_all_pending_on_channel(), circuit_unlink_all_from_channel(), config_mgr_list_deprecated_vars(), config_mgr_list_vars(), connection_start_reading_from_linked_conn(), consensus_cache_find_all(), consensus_split_lines(), decode_hashed_passwords(), dir_server_add(), dircollator_collate_by_ed25519(), dirserv_get_routerdescs(), entry_guards_update_confirmed(), extrainfo_dump_to_string_stats_helper(), get_detached_signatures_from_pending_consensuses(), get_eligible_guards(), get_frequent_members(), get_ns_str_from_sr_values(), getinfo_helper_entry_guards(), handle_control_getconf(), handle_control_getinfo(), handle_control_hspost(), handle_get_keys(), hs_circuitmap_get_all_intro_circ_relay_side(), hs_set_conn_addr_port(), init_circuit_base(), list_server_status_v1(), nodelist_add_node_and_family(), nodelist_find_nodes_with_microdesc(), parse_protocol_list(), policy_expand_private(), policy_expand_unspec(), process_append_argument(), pubsub_adjmap_add(), rend_data_dup(), rend_service_add_filenames_to_list(), retry_all_listeners(), retry_listener_ports(), service_add_fnames_to_list(), setup_intro_point_exclude_list(), smartlist_add_linecpy(), smartlist_add_vasprintf(), smartlist_pqueue_add(), storage_dir_save_bytes_to_file(), storage_dir_save_labeled_to_file(), tor_mainloop_connect_pubsub_events(), and transport_add().

◆ smartlist_add_all()

void smartlist_add_all ( smartlist_t s1,
const smartlist_t s2 
)

◆ smartlist_add_strdup()

void smartlist_add_strdup ( struct smartlist_t sl,
const char *  string 
)

◆ smartlist_clear()

void smartlist_clear ( smartlist_t sl)

◆ smartlist_contains()

int smartlist_contains ( const smartlist_t sl,
const void *  element 
)

◆ smartlist_del()

void smartlist_del ( smartlist_t sl,
int  idx 
)

Remove the idxth element of sl; if idx is not the last element, swap the last element of sl into the idxth space.

Definition at line 214 of file smartlist_core.c.

Referenced by circuit_close_all_marked(), and routerlist_insert().

◆ smartlist_del_keeporder()

void smartlist_del_keeporder ( smartlist_t sl,
int  idx 
)

Remove the idxth element of sl; if idx is not the last element, moving all subsequent elements back one space. Return the old value of the idxth element.

Definition at line 228 of file smartlist_core.c.

Referenced by smartlist_uniq().

◆ smartlist_ensure_capacity()

static void smartlist_ensure_capacity ( smartlist_t sl,
size_t  size 
)
inlinestatic

Make sure that sl can hold at least size entries.

Definition at line 62 of file smartlist_core.c.

Referenced by smartlist_add(), and smartlist_grow().

◆ smartlist_free_()

void smartlist_free_ ( smartlist_t sl)

Deallocate a smartlist. Does not release storage associated with the list's elements.

Definition at line 39 of file smartlist_core.c.

◆ smartlist_grow()

void smartlist_grow ( smartlist_t sl,
size_t  new_size 
)

Expand sl so that its length is at least new_size, filling in previously unused entries with NULL>

Do nothing if sl already had at least new_size elements.

Definition at line 97 of file smartlist_core.c.

Referenced by dcfg_add_recv(), and dcfg_msg_set_chan().

◆ smartlist_insert()

void smartlist_insert ( smartlist_t sl,
int  idx,
void *  val 
)

Insert the value val as the new idxth element of sl, moving all items previously at idx or later forward one space.

Definition at line 244 of file smartlist_core.c.

◆ smartlist_new()

smartlist_t* smartlist_new ( void  )

Allocate and return an empty smartlist.

Definition at line 26 of file smartlist_core.c.

Referenced by accept_encoding_header(), add_onion_helper_clientauth(), add_onion_helper_keyarg(), add_wildcarded_test_address(), append_cell_stats_by_command(), authdir_type_to_string(), bridge_list_get(), build_middle_exclude_list(), build_service_desc_encrypted(), build_vanguard_middle_exclude_list(), circuit_count_pending_on_channel(), circuit_describe_status_for_controller(), circuit_get_global_list(), circuit_get_global_origin_circuit_list(), circuit_list_path_impl(), circuit_log_ancient_one_hop_circuits(), circuit_unlink_all_from_channel(), cleanup_intro_points(), clear_bridge_list(), clear_transport_list(), client_check_address_changed(), client_likes_consensus(), compute_consensus_method(), compute_consensus_versions_list(), compute_frac_paths_available(), compute_nth_protocol_set(), config_mgr_list_deprecated_vars(), config_mgr_list_vars(), config_register_addressmaps(), connection_dir_bridge_routerdesc_failed(), connection_or_report_broken_states(), consdiffmgr_cleanup(), consdiffmgr_consensus_load(), consdiffmgr_diffs_load(), consdiffmgr_ensure_space_for_files(), consdiffmgr_rescan_flavor_(), consdiffmgr_set_cache_flags(), consdiffmgr_validate(), consensus_cache_find_first(), consensus_cache_rescan(), control_event_descriptors_changed(), control_ports_write_to_file(), create_initial_guard_context(), create_managed_proxy_environment(), decode_auth_type(), decode_create2_list(), decode_hashed_passwords(), decode_intro_points(), decode_introduction_point(), desc_encode_v3(), dir_server_add(), dir_split_resource_into_fingerprint_pairs(), dir_split_resource_into_spoolable(), dircollator_collate(), directory_get_consensus_url(), directory_post_to_hs_dir(), directory_remove_invalid(), directory_send_command(), dirserv_get_routerdescs(), dirvote_add_vote(), dirvote_clear_votes(), dirvote_compute_consensuses(), dirvote_fetch_missing_votes(), disk_state_parse_srv(), dump_desc_fifo_add_and_clean(), encode_intro_point(), encode_protocol_list(), entry_guard_chan_failed(), entry_guard_encode_for_state(), entry_guard_parse_from_state(), entry_guards_load_guards_from_state(), entry_guards_update_primary(), expand_protocol_list(), extrainfo_dump_to_string(), find_all_exitpolicy(), format_cell_stats(), format_networkstatus_vote(), format_recommended_version_list(), gen_ed_diff(), geoip_get_request_history(), geoip_get_transport_history(), geoip_parse_entry(), get_all_auth_client_lines(), get_bindaddr_for_server_proxy(), get_bindaddr_from_transport_listen_line(), get_configured_ports(), get_connection_array(), get_current_process_environment_variables(), get_detached_signatures_from_pending_consensuses(), get_eligible_guards(), get_inner_encrypted_layer_plaintext(), get_majority_srv_from_votes(), get_my_declared_family(), get_ns_str_from_sr_values(), get_options_from_transport_options_line(), get_outer_encrypted_layer_plaintext(), get_possible_sybil_list(), get_transport_in_state_by_name(), get_transport_options_for_server_proxy(), get_transport_proxy_ports(), getinfo_helper_config(), getinfo_helper_entry_guards(), handle_control_add_onion(), handle_control_extendcircuit(), handle_control_getconf(), handle_control_getinfo(), handle_control_hspost(), handle_control_mapaddress(), handle_get_keys(), handle_get_microdesc(), handle_get_status_vote(), hs_circ_handle_introduce2(), hs_circuitmap_get_all_intro_circ_relay_side(), hs_config_service_all(), hs_get_responsible_hsdirs(), hs_pick_hsdir(), hs_service_stage_services(), hs_set_conn_addr_port(), init_geoip_countries(), init_logging(), lint_message_consistency(), list_authority_ids_with_downloads(), list_bridge_identities(), list_getinfo_options(), list_pending_downloads(), list_pending_fpsk_downloads(), list_server_status_v1(), list_sk_digests_for_authority_id(), list_v3_auth_ids(), make_consensus_method_list(), mark_bridge_list(), mark_transport_list(), microdesc_list_missing_digest256(), microdesc_parse_fields(), microdescs_add_to_cache(), microdescs_parse_from_string(), networkstatus_check_consensus_signature(), networkstatus_parse_detached_signatures(), networkstatus_parse_vote_from_string(), node_get_all_orports(), nodefamily_canonicalize(), nodelist_find_nodes_with_microdesc(), normalize_nickname_list(), options_act_reversible(), options_init_logs(), parse_addr_policy(), parse_authorized_client(), parse_dir_fallback_line(), parse_ports(), parse_protocol_list(), periodic_events_register(), pick_hsdir_v3(), pick_needed_intro_points(), pick_restricted_middle_node(), policies_parse_exit_policy_from_options(), policy_dump_to_string(), policy_expand_private(), policy_expand_unspec(), port_parse_ports_relay(), predicted_ports_alloc(), process_init(), pt_configure_remaining_proxies(), pt_get_extra_info_descriptor_string(), pubsub_adjmap_add(), rend_client_get_random_intro_impl(), rend_data_dup(), rend_parse_client_keys(), rend_parse_service_authorization(), rend_service_parse_port_config(), rep_hist_get_predicted_ports(), rep_hist_log_link_protocol_counts(), rep_hist_reset_buffer_stats(), resolved_cell_parse(), retry_all_listeners(), retry_listener_ports(), router_add_exit_policy(), router_get_descriptor_digests_in_consensus(), router_get_trusted_dir_servers_mutable(), router_load_extrainfo_from_string(), router_load_routers_from_string(), router_parse_entry_from_string(), routerlist_reset_warnings(), routerset_parse(), service_authorized_client_config_equal(), service_desc_hsdirs_changed(), set_expiry(), set_service_default_config(), sr_get_string_for_vote(), state_transport_line_is_valid(), storage_dir_save_bytes_to_file(), storage_dir_save_labeled_to_file(), string_is_valid_nonrfc_hostname(), sweep_bridge_list(), sweep_transport_list(), tor_init_connection_lists(), tor_mainloop_connect_pubsub_events(), transport_add(), trusted_dirs_flush_certs_to_disk(), update_consensus_router_descriptor_downloads(), update_extrainfo_downloads(), upload_descriptor_to_all(), and write_short_policy().

◆ smartlist_pop_last()

void* smartlist_pop_last ( smartlist_t sl)

If sl is nonempty, remove and return the final element. Otherwise, return NULL.

Definition at line 187 of file smartlist_core.c.

◆ smartlist_remove()

void smartlist_remove ( smartlist_t sl,
const void *  element 
)

Remove all elements E from sl such that E==element. Preserve the order of any elements before E, but elements after E can be rearranged.

Definition at line 151 of file smartlist_core.c.

Referenced by circuit_about_to_free(), connection_stop_reading_from_linked_conn(), connection_unlink(), and smartlist_subtract().

◆ smartlist_remove_keeporder()

void smartlist_remove_keeporder ( smartlist_t sl,
const void *  element 
)

As smartlist_remove, but do not change the order of any elements not removed

Definition at line 167 of file smartlist_core.c.

Referenced by remove_guard_from_confirmed_and_primary_lists().