blob: b394bbbeaf12816016bd3215499dd2532e77723a [file] [log] [blame]
Siddharth Shukla8e64d902017-03-12 19:50:18 +01001#!/usr/bin/env python
Craig Tillerbd6c1c02016-12-06 17:35:57 -08002
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003# Copyright 2016 gRPC authors.
Craig Tillerbd6c1c02016-12-06 17:35:57 -08004#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
Craig Tillerbd6c1c02016-12-06 17:35:57 -08008#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009# http://www.apache.org/licenses/LICENSE-2.0
Craig Tillerbd6c1c02016-12-06 17:35:57 -080010#
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Craig Tillera59c16c2016-10-31 07:25:01 -070016
Siddharth Shuklad194f592017-03-11 19:12:43 +010017from __future__ import print_function
18
Craig Tillera59c16c2016-10-31 07:25:01 -070019import os
20import sys
21
22os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '../../..'))
23
24# map of banned function signature to whitelist
25BANNED_EXCEPT = {
Craig Tiller3cf79222016-11-14 08:02:45 -080026 'grpc_resource_quota_ref(': ['src/core/lib/iomgr/resource_quota.c'],
27 'grpc_resource_quota_unref(': ['src/core/lib/iomgr/resource_quota.c'],
28 'grpc_slice_buffer_destroy(': ['src/core/lib/slice/slice_buffer.c'],
29 'grpc_slice_buffer_reset_and_unref(': ['src/core/lib/slice/slice_buffer.c'],
30 'grpc_slice_ref(': ['src/core/lib/slice/slice.c'],
31 'grpc_slice_unref(': ['src/core/lib/slice/slice.c'],
ncteisen1a882cf2017-03-08 15:42:59 -080032 'grpc_error_create(': ['src/core/lib/iomgr/error.c'],
33 'grpc_error_ref(': ['src/core/lib/iomgr/error.c'],
34 'grpc_error_unref(': ['src/core/lib/iomgr/error.c'],
35 'grpc_os_error(': ['src/core/lib/iomgr/error.c'],
36 'grpc_wsa_error(': ['src/core/lib/iomgr/error.c'],
37 'grpc_log_if_error(': ['src/core/lib/iomgr/error.c'],
Craig Tillera3583b22017-04-13 06:42:47 -070038 'grpc_slice_malloc(': ['src/core/lib/slice/slice.c'],
ncteisenea44ba52017-06-08 15:29:46 -070039 'grpc_closure_create(' : ['src/core/lib/iomgr/closure.c'],
40 'grpc_closure_init(' : ['src/core/lib/iomgr/closure.c'],
41 'grpc_closure_sched(' : ['src/core/lib/iomgr/closure.c'],
42 'grpc_closure_run(' : ['src/core/lib/iomgr/closure.c'],
43 'grpc_closure_list_sched(' : ['src/core/lib/iomgr/closure.c'],
Craig Tillera59c16c2016-10-31 07:25:01 -070044}
45
46errors = 0
47for root, dirs, files in os.walk('src/core'):
48 for filename in files:
49 path = os.path.join(root, filename)
50 if os.path.splitext(path)[1] != '.c': continue
51 with open(path) as f:
52 text = f.read()
53 for banned, exceptions in BANNED_EXCEPT.items():
54 if path in exceptions: continue
55 if banned in text:
Siddharth Shuklad194f592017-03-11 19:12:43 +010056 print('Illegal use of "%s" in %s' % (banned, path))
Craig Tillera59c16c2016-10-31 07:25:01 -070057 errors += 1
58
59assert errors == 0