Skip to content

Commit 14b7a61

Browse files
authored
Merge pull request #251 from rpavlik/disable-extension-prototypes
Disable extension prototypes
2 parents 227a10a + 44e4a4c commit 14b7a61

File tree

4 files changed

+109
-52
lines changed

4 files changed

+109
-52
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- issue.174.gh.OpenXR-SDK-Source
3+
- issue.1554.gl
4+
- issue.1338.gl
5+
---
6+
Hide prototypes for extension functions unless explicitly requested by defining `XR_EXTENSION_PROTOTYPES`. These functions are not exported from the loader, so having their prototypes available is confusing and leads to link errors, etc.

specification/scripts/cgenerator.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def __init__(self,
2727
protectFeature=True,
2828
protectProto=None,
2929
protectProtoStr=None,
30+
protectExtensionProto=None,
31+
protectExtensionProtoStr=None,
3032
apicall='',
3133
apientry='',
3234
apientryp='',
@@ -56,6 +58,13 @@ def __init__(self,
5658
set to None.
5759
- protectProtoStr - #ifdef/#ifndef symbol to use around prototype
5860
declarations, if protectProto is set
61+
- protectExtensionProto - If conditional protection should be generated
62+
around extension prototype declarations, set to either '#ifdef'
63+
to require opt-in (#ifdef protectExtensionProtoStr) or '#ifndef'
64+
to require opt-out (#ifndef protectExtensionProtoStr). Otherwise
65+
set to None.
66+
- protectExtensionProtoStr - #ifdef/#ifndef symbol to use around
67+
extension prototype declarations, if protectExtensionProto is set
5968
- apicall - string to use for the function declaration prefix,
6069
such as APICALL on Windows.
6170
- apientry - string to use for the calling convention macro,
@@ -93,6 +102,12 @@ def __init__(self,
93102
self.protectProtoStr = protectProtoStr
94103
"""#ifdef/#ifndef symbol to use around prototype declarations, if protectProto is set"""
95104

105+
self.protectExtensionProto = protectExtensionProto
106+
"""If conditional protection should be generated around extension prototype declarations, set to either '#ifdef' to require opt-in (#ifdef protectExtensionProtoStr) or '#ifndef' to require opt-out (#ifndef protectExtensionProtoStr). Otherwise set to None."""
107+
108+
self.protectExtensionProtoStr = protectExtensionProtoStr
109+
"""#ifdef/#ifndef symbol to use around extension prototype declarations, if protectExtensionProto is set"""
110+
96111
self.apicall = apicall
97112
"""string to use for the function declaration prefix, such as APICALL on Windows."""
98113

@@ -186,11 +201,20 @@ def beginFeature(self, interface, emit):
186201
self.sections = {section: [] for section in self.ALL_SECTIONS}
187202
self.feature_not_empty = False
188203

204+
def _endProtectComment(self, protect_str, protect_directive="#ifdef"):
205+
if protect_directive is None or protect_str is None:
206+
raise RuntimeError("Shouldn't call in here without something to protect")
207+
if "ifdef" in protect_directive:
208+
return '/* ' + protect_str + ' */'
209+
else:
210+
return '/* !' + protect_str + ' */'
211+
189212
def endFeature(self):
190213
"Actually write the interface to the output file."
191214
# C-specific
192215
if self.emit:
193216
if self.feature_not_empty:
217+
is_core = self.featureName.startswith(self.conventions.api_prefix + "VERSION_")
194218
if self.genOpts.conventions.writeFeature(self.featureExtraProtect, self.genOpts.filename):
195219
self.newline()
196220
if self.genOpts.protectFeature:
@@ -213,15 +237,30 @@ def endFeature(self):
213237
if self.genOpts.protectProto:
214238
write(self.genOpts.protectProto,
215239
self.genOpts.protectProtoStr, file=self.outFile)
240+
if self.genOpts.protectExtensionProto and not is_core:
241+
write(self.genOpts.protectExtensionProto,
242+
self.genOpts.protectExtensionProtoStr, file=self.outFile)
216243
write('\n'.join(self.sections['command']), end='', file=self.outFile)
244+
if self.genOpts.protectExtensionProto and not is_core:
245+
write('#endif',
246+
self._endProtectComment(protect_directive=self.genOpts.protectExtensionProto,
247+
protect_str=self.genOpts.protectExtensionProtoStr),
248+
file=self.outFile)
217249
if self.genOpts.protectProto:
218-
write('#endif', file=self.outFile)
250+
write('#endif',
251+
self._endProtectComment(protect_directive=self.genOpts.protectProto,
252+
protect_str=self.genOpts.protectProtoStr),
253+
file=self.outFile)
219254
else:
220255
self.newline()
221256
if self.featureExtraProtect is not None:
222-
write('#endif /*', self.featureExtraProtect, '*/', file=self.outFile)
257+
write('#endif',
258+
self._endProtectComment(protect_str=self.featureExtraProtect),
259+
file=self.outFile)
223260
if self.genOpts.protectFeature:
224-
write('#endif /*', self.featureName, '*/', file=self.outFile)
261+
write('#endif',
262+
self._endProtectComment(protect_str=self.featureName),
263+
file=self.outFile)
225264
# Finish processing in superclass
226265
OutputGenerator.endFeature(self)
227266

specification/scripts/genxr.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def makeGenOpts(args):
148148
protectFeature = False,
149149
protectProto = '#ifndef',
150150
protectProtoStr = 'XR_NO_PROTOTYPES',
151+
protectExtensionProto = '#ifdef',
152+
protectExtensionProtoStr = 'XR_EXTENSION_PROTOTYPES',
151153
apicall = 'XRAPI_ATTR ',
152154
apientry = 'XRAPI_CALL ',
153155
apientryp = 'XRAPI_PTR *',
@@ -177,6 +179,8 @@ def makeGenOpts(args):
177179
protectFeature = False,
178180
protectProto = '#ifndef',
179181
protectProtoStr = 'XR_NO_PROTOTYPES',
182+
protectExtensionProto = '#ifdef',
183+
protectExtensionProtoStr = 'XR_EXTENSION_PROTOTYPES',
180184
apicall = 'XRAPI_ATTR ',
181185
apientry = 'XRAPI_CALL ',
182186
apientryp = 'XRAPI_PTR *',

0 commit comments

Comments
 (0)