Siddharth Shukla | 8e64d90 | 2017-03-12 19:50:18 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
Craig Tiller | bd6c1c0 | 2016-12-06 17:35:57 -0800 | [diff] [blame] | 2 | |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | # Copyright 2016 gRPC authors. |
Craig Tiller | bd6c1c0 | 2016-12-06 17:35:57 -0800 | [diff] [blame] | 4 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | # 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 Tiller | bd6c1c0 | 2016-12-06 17:35:57 -0800 | [diff] [blame] | 8 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
Craig Tiller | bd6c1c0 | 2016-12-06 17:35:57 -0800 | [diff] [blame] | 10 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | # 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 Tiller | a59c16c | 2016-10-31 07:25:01 -0700 | [diff] [blame] | 16 | |
Siddharth Shukla | d194f59 | 2017-03-11 19:12:43 +0100 | [diff] [blame] | 17 | from __future__ import print_function |
| 18 | |
Craig Tiller | a59c16c | 2016-10-31 07:25:01 -0700 | [diff] [blame] | 19 | import os |
| 20 | import sys |
| 21 | |
| 22 | os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '../../..')) |
| 23 | |
| 24 | # map of banned function signature to whitelist |
| 25 | BANNED_EXCEPT = { |
Craig Tiller | 3cf7922 | 2016-11-14 08:02:45 -0800 | [diff] [blame] | 26 | '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'], |
ncteisen | 1a882cf | 2017-03-08 15:42:59 -0800 | [diff] [blame] | 32 | '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 Tiller | a3583b2 | 2017-04-13 06:42:47 -0700 | [diff] [blame] | 38 | 'grpc_slice_malloc(': ['src/core/lib/slice/slice.c'], |
ncteisen | ea44ba5 | 2017-06-08 15:29:46 -0700 | [diff] [blame] | 39 | '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 Tiller | a59c16c | 2016-10-31 07:25:01 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | errors = 0 |
| 47 | for 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 Shukla | d194f59 | 2017-03-11 19:12:43 +0100 | [diff] [blame] | 56 | print('Illegal use of "%s" in %s' % (banned, path)) |
Craig Tiller | a59c16c | 2016-10-31 07:25:01 -0700 | [diff] [blame] | 57 | errors += 1 |
| 58 | |
| 59 | assert errors == 0 |