1#!/usr/bin/env bash
2
3unbound_functions=0
4skipped=()
5
6# false positives
7skipped+=(uv_thread_create uv_thread_create_ex)
8
9# intentionally not bound
10skipped+=(uv_replace_allocator uv_library_shutdown)
11
12# threading/synchronization
13skipped+=(
14	uv_mutex_init uv_mutex_init_recursive uv_mutex_destroy uv_mutex_lock uv_mutex_trylock
15	uv_mutex_unlock uv_rwlock_init uv_rwlock_destroy uv_rwlock_rdlock uv_rwlock_tryrdlock
16	uv_rwlock_rdunlock uv_rwlock_wrlock uv_rwlock_trywrlock uv_rwlock_wrunlock uv_sem_init
17	uv_sem_destroy uv_sem_post uv_sem_wait uv_sem_trywait uv_cond_init uv_cond_destroy
18	uv_cond_signal uv_cond_broadcast uv_barrier_init uv_barrier_destroy uv_barrier_wait
19	uv_cond_wait uv_cond_timedwait uv_once uv_key_create uv_key_delete uv_key_get uv_key_set
20)
21
22# yet to be implemented / ruled out
23# https://github.com/luvit/luv/issues/410
24skipped+=(
25	uv_loop_configure uv_setup_args uv_default_loop uv_loop_new uv_loop_delete
26	uv_loop_size uv_loop_fork uv_loop_get_data uv_loop_set_data uv_strerror uv_strerror_r uv_err_name
27	uv_err_name_r uv_handle_size uv_handle_get_type uv_handle_type_name uv_handle_get_data
28	uv_handle_get_loop uv_handle_set_data uv_req_size uv_req_get_data uv_req_set_data uv_req_get_type
29	uv_req_type_name uv_pipe_chmod uv_process_get_pid uv_get_osfhandle
30	uv_open_osfhandle uv_fs_get_type uv_fs_get_result uv_fs_get_ptr uv_fs_get_path uv_fs_get_statbuf
31	uv_ip4_addr uv_ip6_addr uv_ip4_name uv_ip6_name uv_inet_ntop uv_inet_pton uv_dlopen uv_dlclose
32	uv_dlsym uv_dlerror uv_udp_using_recvmmsg uv_fs_get_system_error
33)
34
35# get all public uv_ functions from uv.h
36for fn in `grep -oP "UV_EXTERN [^\(]+ uv_[^\(]+\(" deps/libuv/include/uv.h | sed 's/($//' | grep -oP "[^ ]+$"`; do
37	# skip everything in the skipped array and any initialization/cleanup fns
38	if [[ " ${skipped[@]} " =~ " ${fn} " || $fn == *_init* || $fn == *_free* || $fn == *_cleanup ]] ; then
39		continue
40	fi
41	# count all uses
42	count=`grep -o "\b$fn\b" src/*.c | wc -l`
43	# check if a luv_ version exists
44	grep -q "\bl$fn\b" src/*.c
45	bound=$?
46	# not bound
47	if [ ! $bound -eq 0 ] ; then
48		# not used
49		if [ $count -eq 0 ] ; then
50			echo $fn
51		else
52			echo "$fn (used internally but not bound externally)"
53		fi
54		unbound_functions=$((unbound_functions+1))
55	fi
56done
57
58exit $unbound_functions
59