Skip to content

Commit

Permalink
inc: winapi: Use clng() etc. instead of __LONG32 casts
Browse files Browse the repository at this point in the history
Using clng() directly is probably cleaner; and as far as the fbfrog-based
translation goes, expanding the __LONG32 macro allows fbfrog to parse
the #defines easier. That in turn allowed the auto-translation of the 3
changed #defines in winerror.bi; the additional culng()'s are then
added automatically around 32bit uint math operations (see also d26035a).
  • Loading branch information
dkl committed Apr 10, 2015
1 parent 47056bf commit dec5df4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion inc/win/basetsd.bi
Expand Up @@ -169,7 +169,7 @@ type PDWORD32 as ulong ptr
#define PtrToShort(p) cshort(cast(LONG_PTR, (p)))
#define IntToPtr(i) cptr(VOID ptr, cast(INT_PTR, clng(i)))
#define UIntToPtr(ui) cptr(VOID ptr, cast(UINT_PTR, culng(ui)))
#define LongToPtr(l) cptr(VOID ptr, cast(LONG_PTR, cast(__LONG32, l)))
#define LongToPtr(l) cptr(VOID ptr, cast(LONG_PTR, clng(l)))
#define ULongToPtr(ul) cptr(VOID ptr, cast(ULONG_PTR, culng(ul)))

private function PtrToPtr64(byval p as const any ptr) as any ptr
Expand Down
2 changes: 1 addition & 1 deletion inc/win/vfw.bi
Expand Up @@ -1041,7 +1041,7 @@ const MCIWNDF_NOOPEN = &h8000
#define MCIWndGetStart(hwnd) cast(LONG, MCIWndSM(hwnd, MCIWNDM_GETSTART, cast(WPARAM, 0), cast(LPARAM, 0)))
#define MCIWndGetLength(hwnd) cast(LONG, MCIWndSM(hwnd, MCIWNDM_GETLENGTH, cast(WPARAM, 0), cast(LPARAM, 0)))
#define MCIWndGetEnd(hwnd) cast(LONG, MCIWndSM(hwnd, MCIWNDM_GETEND, cast(WPARAM, 0), cast(LPARAM, 0)))
#define MCIWndStep(hwnd, n) cast(LONG, MCIWndSM(hwnd, MCI_STEP, cast(WPARAM, 0), cast(LPARAM, cast(__LONG32, (n)))))
#define MCIWndStep(hwnd, n) cast(LONG, MCIWndSM(hwnd, MCI_STEP, cast(WPARAM, 0), cast(LPARAM, clng((n)))))
#define MCIWndDestroy(hwnd) MCIWndSM(hwnd, WM_CLOSE, cast(WPARAM, 0), cast(LPARAM, 0))
#define MCIWndSetZoom(hwnd, iZoom) MCIWndSM(hwnd, MCIWNDM_SETZOOM, cast(WPARAM, 0), cast(LPARAM, cast(UINT, (iZoom))))
#define MCIWndGetZoom(hwnd) cast(UINT, MCIWndSM(hwnd, MCIWNDM_GETZOOM, cast(WPARAM, 0), cast(LPARAM, 0)))
Expand Down
6 changes: 3 additions & 3 deletions inc/win/winerror.bi
Expand Up @@ -1891,15 +1891,15 @@ const SEVERITY_SUCCESS = 0
const SEVERITY_ERROR = 1
#define SUCCEEDED(hr) (cast(HRESULT, (hr)) >= 0)
#define FAILED(hr) (cast(HRESULT, (hr)) < 0)
#define IS_ERROR(Status) ((culng(Status) shr 31) = SEVERITY_ERROR)
#define IS_ERROR(Status) (culng(culng((Status)) shr 31) = SEVERITY_ERROR)
#define HRESULT_CODE(hr) ((hr) and &hFFFF)
#define SCODE_CODE(sc) ((sc) and &hFFFF)
#define HRESULT_FACILITY(hr) (((hr) shr 16) and &h1fff)
#define SCODE_FACILITY(sc) (((sc) shr 16) and &h1fff)
#define HRESULT_SEVERITY(hr) (((hr) shr 31) and &h1)
#define SCODE_SEVERITY(sc) (((sc) shr 31) and &h1)
#define MAKE_HRESULT(sev, fac, code) cast(HRESULT, (culng(sev) shl 31) or (culng(fac) shl 16) or culng(code))
#define MAKE_SCODE(sev, fac, code) cast(SCODE , (culng(sev) shl 31) or (culng(fac) shl 16) or culng(code))
#define MAKE_HRESULT(sev, fac, code) cast(HRESULT, culng(culng(culng(culng((sev)) shl 31) or culng(culng((fac)) shl 16)) or culng((code))))
#define MAKE_SCODE(sev, fac, code) cast(SCODE, culng(culng(culng(culng((sev)) shl 31) or culng(culng((fac)) shl 16)) or culng((code))))
const FACILITY_NT_BIT = &h10000000
#define __HRESULT_FROM_WIN32(x) iif(cast(HRESULT, (x)) <= 0, cast(HRESULT, (x)), cast(HRESULT, (((x) and &h0000FFFF) or (FACILITY_WIN32 shl 16)) or &h80000000))
#define HRESULT_FROM_WIN32(x) __HRESULT_FROM_WIN32(x)
Expand Down
10 changes: 5 additions & 5 deletions inc/win/winsock.bi
Expand Up @@ -184,8 +184,8 @@ const IOC_OUT = &h40000000
const IOC_IN = &h80000000
#define IOC_INOUT (IOC_IN or IOC_OUT)
#define _IO(x, y) ((IOC_VOID or ((x) shl 8)) or (y))
#define _IOR(x, y, t) (((IOC_OUT or ((cast(__LONG32, sizeof((t))) and IOCPARM_MASK) shl 16)) or ((x) shl 8)) or (y))
#define _IOW(x, y, t) (((IOC_IN or ((cast(__LONG32, sizeof((t))) and IOCPARM_MASK) shl 16)) or ((x) shl 8)) or (y))
#define _IOR(x, y, t) (((IOC_OUT or ((clng(sizeof((t))) and IOCPARM_MASK) shl 16)) or ((x) shl 8)) or (y))
#define _IOW(x, y, t) (((IOC_IN or ((clng(sizeof((t))) and IOCPARM_MASK) shl 16)) or ((x) shl 8)) or (y))
#define FIONREAD _IOR(asc("f"), 127, u_long)
#define FIONBIO _IOW(asc("f"), 126, u_long)
#define FIOASYNC _IOW(asc("f"), 125, u_long)
Expand Down Expand Up @@ -233,17 +233,17 @@ const IPPORT_RESERVED = 1024
const IMPLINK_IP = 155
const IMPLINK_LOWEXPER = 156
const IMPLINK_HIGHEXPER = 158
#define IN_CLASSA(i) ((cast(__LONG32, (i)) and &h80000000) = 0)
#define IN_CLASSA(i) ((clng((i)) and &h80000000) = 0)
const IN_CLASSA_NET = &hff000000
const IN_CLASSA_NSHIFT = 24
const IN_CLASSA_HOST = &h00ffffff
const IN_CLASSA_MAX = 128
#define IN_CLASSB(i) ((cast(__LONG32, (i)) and &hc0000000) = &h80000000)
#define IN_CLASSB(i) ((clng((i)) and &hc0000000) = &h80000000)
const IN_CLASSB_NET = &hffff0000
const IN_CLASSB_NSHIFT = 16
const IN_CLASSB_HOST = &h0000ffff
const IN_CLASSB_MAX = 65536
#define IN_CLASSC(i) ((cast(__LONG32, (i)) and &he0000000) = &hc0000000)
#define IN_CLASSC(i) ((clng((i)) and &he0000000) = &hc0000000)
const IN_CLASSC_NET = &hffffff00
const IN_CLASSC_NSHIFT = 8
const IN_CLASSC_HOST = &h000000ff
Expand Down
12 changes: 6 additions & 6 deletions inc/win/winsock2.bi
Expand Up @@ -181,8 +181,8 @@ const IOC_OUT = &h40000000
const IOC_IN = &h80000000
#define IOC_INOUT (IOC_IN or IOC_OUT)
#define _IO(x, y) ((IOC_VOID or ((x) shl 8)) or (y))
#define _IOR(x, y, t) (((IOC_OUT or ((cast(__LONG32, sizeof((t))) and IOCPARM_MASK) shl 16)) or ((x) shl 8)) or (y))
#define _IOW(x, y, t) (((IOC_IN or ((cast(__LONG32, sizeof((t))) and IOCPARM_MASK) shl 16)) or ((x) shl 8)) or (y))
#define _IOR(x, y, t) (((IOC_OUT or ((clng(sizeof((t))) and IOCPARM_MASK) shl 16)) or ((x) shl 8)) or (y))
#define _IOW(x, y, t) (((IOC_IN or ((clng(sizeof((t))) and IOCPARM_MASK) shl 16)) or ((x) shl 8)) or (y))
#define FIONREAD _IOR(asc("f"), 127, u_long)
#define FIONBIO _IOW(asc("f"), 126, u_long)
#define FIOASYNC _IOW(asc("f"), 125, u_long)
Expand Down Expand Up @@ -241,21 +241,21 @@ const IPPORT_RESERVED = 1024
const IMPLINK_IP = 155
const IMPLINK_LOWEXPER = 156
const IMPLINK_HIGHEXPER = 158
#define IN_CLASSA(i) ((cast(__LONG32, (i)) and &h80000000) = 0)
#define IN_CLASSA(i) ((clng((i)) and &h80000000) = 0)
const IN_CLASSA_NET = &hff000000
const IN_CLASSA_NSHIFT = 24
const IN_CLASSA_HOST = &h00ffffff
const IN_CLASSA_MAX = 128
#define IN_CLASSB(i) ((cast(__LONG32, (i)) and &hc0000000) = &h80000000)
#define IN_CLASSB(i) ((clng((i)) and &hc0000000) = &h80000000)
const IN_CLASSB_NET = &hffff0000
const IN_CLASSB_NSHIFT = 16
const IN_CLASSB_HOST = &h0000ffff
const IN_CLASSB_MAX = 65536
#define IN_CLASSC(i) ((cast(__LONG32, (i)) and &he0000000) = &hc0000000)
#define IN_CLASSC(i) ((clng((i)) and &he0000000) = &hc0000000)
const IN_CLASSC_NET = &hffffff00
const IN_CLASSC_NSHIFT = 8
const IN_CLASSC_HOST = &h000000ff
#define IN_CLASSD(i) ((cast(__LONG32, (i)) and &hf0000000) = &he0000000)
#define IN_CLASSD(i) ((clng((i)) and &hf0000000) = &he0000000)
const IN_CLASSD_NET = &hf0000000
const IN_CLASSD_NSHIFT = 28
const IN_CLASSD_HOST = &h0fffffff
Expand Down

0 comments on commit dec5df4

Please sign in to comment.