diff options
author | Adam Jackson <ajax@redhat.com> | 2016-03-24 13:57:58 -0400 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2016-05-17 15:04:56 -0400 |
commit | 88cfc9ddaab5577260293fcbd4f7413fbd4aba21 (patch) | |
tree | 309116774159d5880221de33d4f7b54de4dac0f4 /src/mapi/glapi | |
parent | 7bc5c7f58685e67985b3da1722391432fdd9ba31 (diff) | |
download | external_mesa3d-88cfc9ddaab5577260293fcbd4f7413fbd4aba21.zip external_mesa3d-88cfc9ddaab5577260293fcbd4f7413fbd4aba21.tar.gz external_mesa3d-88cfc9ddaab5577260293fcbd4f7413fbd4aba21.tar.bz2 |
glapi: Add the safe_{add,mul,pad} functions from xserver
We're about to update the generator scripts to use these, easier not to
vary between client and server.
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Adam Jackson <ajax@redhat.com>
Diffstat (limited to 'src/mapi/glapi')
-rw-r--r-- | src/mapi/glapi/gen/glX_proto_send.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index 2b33030..8b3d8d7 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -174,6 +174,7 @@ class PrintGlxProtoStubs(glX_proto_common.glx_print_proto): print '#include <X11/Xlib-xcb.h>' print '#include <xcb/xcb.h>' print '#include <xcb/glx.h>' + print '#include <limits.h>' print '' print '#define __GLX_PAD(n) (((n) + 3) & ~3)' @@ -181,6 +182,29 @@ class PrintGlxProtoStubs(glX_proto_common.glx_print_proto): self.printFastcall() self.printNoinline() print '' + + print 'static _X_INLINE int safe_add(int a, int b)' + print '{' + print ' if (a < 0 || b < 0) return -1;' + print ' if (INT_MAX - a < b) return -1;' + print ' return a + b;' + print '}' + print 'static _X_INLINE int safe_mul(int a, int b)' + print '{' + print ' if (a < 0 || b < 0) return -1;' + print ' if (a == 0 || b == 0) return 0;' + print ' if (a > INT_MAX / b) return -1;' + print ' return a * b;' + print '}' + print 'static _X_INLINE int safe_pad(int a)' + print '{' + print ' int ret;' + print ' if (a < 0) return -1;' + print ' if ((ret = safe_add(a, 3)) < 0) return -1;' + print ' return ret & (GLuint)~3;' + print '}' + print '' + print '#ifndef __GNUC__' print '# define __builtin_expect(x, y) x' print '#endif' |