Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for compilation warnings/errors #2

Merged
merged 14 commits into from
May 3, 2013
Merged

Fixes for compilation warnings/errors #2

merged 14 commits into from
May 3, 2013

Conversation

mudhairless
Copy link
Contributor

Ignore the .travis.yml file for now, it is related to travis-ci.org and I'm still working on it.
The other changed files fix two issues:

  1. warning: 'XKeycodeToKeysym' is deprecated on unix hosts
  2. if STRICT_ANSI is defined the _controlfp function is not defined in some versions of mingw-gcc

dkl added a commit that referenced this pull request May 3, 2013
Fixes for compilation warnings/errors
@dkl dkl merged commit 84eb0ff into freebasic:master May 3, 2013
@jklwn jklwn mentioned this pull request Jan 25, 2019
@jklwn jklwn mentioned this pull request Sep 7, 2019
jklwn3 added a commit to jklwn4/fbc that referenced this pull request Sep 18, 2019
SARG-FB added a commit to SARG-FB/fbc that referenced this pull request Oct 25, 2020
mov -xxx[rbp], rax --> mov -xxx[rbp], rax kept
mov rcx, -xxx[rbp] --> freebasic#2 mov rcx, -xxx[rbp] commented
mov rcx, rax new line

movq -xxx[rbp], xmm0 --> movq -xxx[rbp], xmm0 kept
movq xmm1, -xxx[rbp] --> freebasic#3 movq xmm1, -xxx[rbp] commented
movsd xmm1, xmm0 new line
jayrm pushed a commit to jayrm/fbc that referenced this pull request Oct 26, 2020
(cherry picked from commit 67cdf68)

gas64 : fix incomplete test in optimization module
(cherry picked from commit f78ce79)

gas64 : new optimizations

mov -xxx[rbp], rax --> mov -xxx[rbp], rax kept
mov rcx, -xxx[rbp] --> freebasic#2 mov rcx, -xxx[rbp] commented
mov rcx, rax new line

movq -xxx[rbp], xmm0 --> movq -xxx[rbp], xmm0 kept
movq xmm1, -xxx[rbp] --> freebasic#3 movq xmm1, -xxx[rbp] commented
movsd xmm1, xmm0 new line
(cherry picked from commit 170d5db)

gas64 : fix wrong use of test sse41 when converting float to ulongint causing use of roundss/roundsd even with CPU non compatible
(cherry picked from commit 1b8d94a)

gas64 : removal of useless test in optimization (optim 3-1)
(cherry picked from commit 61cacf2)

gas64 : all 4 leading spaces replaced by tab (thanks to Notepad++)
	'By SARG' added (removed by error)
(cherry picked from commit 023cfeb)

gas64 : fix new optimizations....
(cherry picked from commit ff7867b)

Merge pull request freebasic#262 from SARG-FB/gas64_rev

gas64; sse41 checks and optimization fixes

- fix sse41 test, before the asm test instruction was wrongly used.
- fix wrong optimization for xmmN registers.
- new optimizations canceling the above fix.
- some changes in asm_info() lines, typos fixes
(cherry picked from commit ab9fbd3)
czsgaba added a commit to czsgaba/fbc that referenced this pull request Dec 9, 2020
* Fix not drawing if there's only 1 dirty line

* gfxlib: added Direct2D driver (adeyblue)

- preferred driver on newer systems
- DirectX driver is still fallback for older systems

* Fix a leaky realloc

* Another one

* rtlib: update change log

- github # 205, fix rtlib realloc memory leaks in 'redim preserve' and 'fb_hGetLocaleInfo' (adeyblue)

* - rtlib: gitbub # 205, fix realloc memory leak and malloc null ptrs in utf_conv.bi API functions

- CharToUTF, 'WCharToUTF, UTFToChar, UTFToWChar, and related functions
- rtlib utf conversion functions when passed a dst=NULL ptr, are expected to allocate memory (malloc/realloc)
- in the event of out-of-memory error, return NULL

* rtlib: gitbub # 205, fix potential malloc null ptr access in dev file read/write methods

* fbcunit: update to version 0.9

- fbcu.setBriefSummary( true|false ) method to choose brief summary (true), otherwise full summary (false, default)
- fbcu.setHideCases( true|false ) method to prevent cases (failed asserts) from printing (true), otherwise show all (false, default)
- fbcu.getHideCases() as boolean to return current setting for "hide-cases" option
- added missing fbcunit_qb.bas:fbcu_check_internal_state() stub
- added missing fbcunit_qb.bas:fbcu_write_report_xml() stub
- update copyright to 2020

* fbc-tests: add options for --brief-summary and --hide-cases

* fbc: fb_MemMove, fbMemCopy, POKE ANY, dst, src, count

- add fb_MemMove cdecl alias "memmove" ( byref as any, byref as const any, byval as uinteger ) as any ptr
- add fb_MemCopy cdecl alias "memcpy" ( byref as any, byref as const any, byval as uinteger ) as any ptr
- fb_MemCopy used to be part of the compiler, and is actually used in existing examples/xml/expat.bas
- fb_MemCopy was likely removed in the past as it was not needed by either compiler or fb runtime directly
- update prototype warnings for fb_MemCopy and fb_MemMove
- add POKE ANY quirk syntax variant to invoke fb_MemMove
- add 'POKE ANY, dst, src, count' statement, count bytes are moved from src reference to dst reference

* fbc: add inc/fbc-int/memory.bi for low level memory operations

- ./inc/fbc-int/memory.bi - fbc API for low level memory operations allocate, callocate, reallocate, deallocate, clear, memcopy, memmove
- fixed default new, new[] operator (allocate) after #undef allocate caused compiler crash
- fixed default delete, delete[] operator (deallocate) after undef deallocate caused compiler crash

* fbc: add test for array in 'POKE ANY, a(), b(), count'

* fbc: fix 'POKE ANY, string, string, count' test, had bad buffer length

* * fbc-tests: fix 'POKE ANY' string test

- cause was a 'poke any, a, b, n' overwriting string descriptor
- rewrite string tests to sure clear usage

* fbc: print backend name when using 'fbc -v -version' command line options

* Fix screen 8 from rendering half size. Other cleanup

* If gdi_init fails to create the window after going full screen then gdi_quit wouldn't restore the screen since it was dependent on the window being created

* This DRIVER_SHAPED_WINDOW if overrode choices made in the other two ifs, so its been made part of the main if/else if chain

* fbgfx: move DirectDraw driver lower in the list when searching for drivers

- Direct2D driver (see 5e93d69) was added as first choice for driver

* Make WM_PAINT set dirty bits to indicate what needs redrawing. Fix function pointer cast masking incorrect signature.

* bugfix 921 - horizontal line drawing on 8-bit image was using wrong bpp

* fbdoc: wiki snapshot 2020-08-08

* fbdoc: follow at most one redirect to allow for server side URL rewrite

* fbdoc: copyright updates for 2020

* fbdoc: copyright updates for 2020

* fbdoc: update examples in examples/manual

* Update loadgif.bas

Fix compile error when __GIFLIB_VER__ == 4

* fbc: drop POKE ANY syntax

* fbc: sf.net #909: suffixes in '-lang fb' generate warning

- reverted changes due sf.net #893
- invalid suffixes due to '-lang fb' are now pedantic warning only specified with '-w pedantic' or '-w suffix'

* oGLfbgfx: cosmetic changes

* oGLfbgfx: refactor GL_setup_pixel_format

* oGLfbgfx: refactor common code in to GL_common_init()

* oGLfbgfx: win32 fixed opengl driver was leaking thread handle under 'screencontrol fb.SET_GL_2D_MODE, fb.OGL_2D_AUTO_SYNC'

* oGLfbgfx: win32 opengl add locking for OGL_2D_AUTO_SYNC

* oGLfbGFX: prevent opengl mode and scale from changing until next mode is set

* oGLfbgfx: update changelog and source notes for 2d_mode and scale

* fbc-tests: test results of log-tests possibly lost due xargs redirection

- the previous always 'true' statement was intended to prevent signal 13 from xargs when input pipe was empty, however, has the undesirable effect of not capturing the wanted output

* fbc-tests: typo in log-tests.mk TAIL should be tail

* fbc-tests: update tests due to fix in ./tests/log-tests
fbc: update docs and help on warning options

* fbc: sf.net bug-fix # 908 visibility / access rights of overload For/Next/Step operators not taken into account by for...next statement

- check visibility for overloaded operators FOR, NEXT, and STEP

* fbc: revert '-lang fb' suffix handling

- reverted changes due sf.net #893: invalid suffixes due to '-lang fb'
- reverted changes due sf.net #832: Fix bug allowing QB style suffixes on all keywords, regardless of -lang
- suffixes in '-lang fb' reverted to fbc-1.05.0 behaviours

* fbc: internal change: prep for FB_PROCATTRIB

- main purpose for FB_SYMBATTRIB is to efficiently decide based on most common checks using 'attrib' for filtering
- FB_SYMBATTRIB contains several attributes that are for procedures only and are mutually exclusive
- prep for internal changes of FB_PROCATTRIB

* fbc: internal change: FB_PROCATTRIB

- pass proc attrib 'pattrib' parameters to internal functions

* fbc: internal cosmetics on FB_SYMBSTATS

* fbc: rename FB_SYMBATTRIB* constants to FB_PROCATTRIB*

* fbc: internal change: FB_PROCATTRIB* additions

- remove optional params on symbNewSymbol
- pass proc attrib to symbNewSymbol
- fix? a strange case in symbAddNamespace() where symb attrib was previously setting all attrib bits

* fbc: add internal verbose option for symbol debugging in symbDumpStr

* fbc: internal change: FB_PROCATTRIB

- a couple of symbIsRef() should be symbIsReturnByRef()

* fbc: internal change: LEXCHECK_ALLOWSUFFIX is no longer needed after reversion of suffix errors

* fbc: prepare for suffix handling with internal changes

- add new LEXCHECK_POST_* flags
- move hMatch() and hMatchIdOrKw() to lex.bi / lex.bas
- add lexCheckToken()
- add 'Suffix ignored' warning

* fbc: warning for suffixes on all built-in keywords, variables, types, etc

- sf.net #909, #832, #866 reverted error on suffix in lang fb dialect
- sf.net #832: warn on suffixes for all built-in keywords.
- 'Suffix ignored' warning in -lang fb instead of errors
- '-w suffix' or '-w pedantic' command line option enables 'Suffix ignored' warning for built-in in string functions
- track the suffix in FBTOKEN.suffixchar to speed up suffix checks
- add context specific flags for all lexSkipToken(), hMatch(), hMatchIdOrKw() to check suffixes
- lang dialect specific warnings for suffixes
- added lexCheckToken() for suffix checking

* * fbc: warning for suffixes on all built-in keywords, variables, types, etc

- fix-ups to incorrect handled suffix checking
- add warning verification count for suffix tests

* * fbc: warning for suffixes on all built-in keywords, variables, types, etc

- don't include output from #dump or #odump debug stuff, it can change often

* added: __FB_UNIQUEID__ defines
changed: defines and macros can now be invoked without ()'s

* added: __FB_UNIQUEID_PUSH__(), __FB_UNIQUEID__(), __FB_UNIQUEID_POP__(), __FB_ARGSPLIT__() builtin macros
changed: macros and defines can now be invoked without ()'s

* changed:
- using str2tok for better results
- the __FB_ARGSPLIT__ was split in two macros: __FB_ARG_LEFTOF__ and __FB_ARG_RIGHTOF__

* changed:
- using str2tok for better results
- the __FB_ARGSPLIT__ is now split in two macros: __FB_ARG_LEFTOF__ and __FB_ARG_RIGHTOF__

* added: __fb_join__() builtin macro
added: new examples

* fixed: bit() is an intrinsic macro and was used as string without "'s around in a #print

* fixed: it should be bitops to pass the warning tests....

* fixed: symbUniqueId() returns a $ prefix in -gen gcc mode

* fbc-tests: update tests/pp/macro_no_parentheses.bas

* fbc: basic-macro: invert logic to hasParens

* fbc: basic-macro: clean-up memory leaks

* fbc: basic-macro: move changelog messages to head version

* fbc: basic macros - add __FB_ARG_COUNT__() builtin macro

* basic-macro: cosmetic clean-ups

* fbc: basic-macro: __FB_JOIN__ can handle ascii and unicode source

- default to zstring handling for all macro callbacks (and define callbacks)
- add separate callbacks for zstring and wstring source code handling

* fbc: basic-macros: fix logic error in __FB_JOIN__

* fbc: basic-macro: add tests

- add tests for __FB_JOIN__(), fixing a bug in a previous merge
- add tests for __FB_ARG_LEFTOF__() and __FB_ARG_RIGHTOF__()

* fbc: fix sf.net #906: #error on line 2 not reported if immediately following #error on line 1

- pre-processor checks, ppCheck(), can occur most anywhere while parsing
- only one error message is printed per statement (i.e. separate counter from line number).
- only at the beginning of a file in cProgram() the first 2 lines of the file are parsed before the parser.stmt.cnt is incremented, thus producing only one error message.
- incrementing the statement count when #error is parsed, solves the issue

* fbc: fix sf.net #906: partial test

* rtlib: internal fb_MemCopyClear() argument types changed to expect unsigned lengths (UINTEGER => size_t)

* fbc: basic-macro: add missed test file

* fbc: basic-macros add quote & unquote functions

- add __FB_QUOTE__(), __FB_UNQUOTE__() builtin macros
- tests added

* basic-macros: must have parens on builtins

* fbc: basic-macros: '#macro name ? (arg)' syntax

- due to symbol name lookups, optional parentheses were causing some breaks in existing code
- this changes the behaviour by making parentheses required as before by default
- the behaviour of a macro can be changed using '#macro name ? (arg)' syntax

* fbc: suffixes, warn instead of error on suffixes in '-lang fb'

- refactor hCheckSuffix() in to lexCheckToken()
- silently ignore '$' suffix on builtin string functions in '-lang fb'
- warn on string function suffix in '-lang fb' is given '-w suffix' or '-w pedandtic'
- add suffix warning tests for builtin string functions

* fbc: suffixes, warn instead of error on suffixes in '-lang fb'

- also warn if string suffix is expected, but some other suffix was found

* fbc: basic-macros: fix ICE when accessing unique id stacks

- prevent ICE in __FB_UNIQUEID_POP__() due to stack underflow
- prevent ICE in __FB_UNIQUEID__() due to no stack defined

* fbc: basic-macros: prevent side effects when skipping statements

- '#if 0' skipping still expands macros, so prevent side effects in __fb_uniqueid*() macros

* fbc: basic-macros: add tests for __fb_uniqueid*() macros

* fbc: basic-macros: error on __fb_uniqueid_pop__ underflow

- log-test for __fb_uniqueid_pop__ stack underflow with undefined stack
- log-test for __fb_uniqueid_pop__ stack underflow with defined stack

* fbc: basic-macros: make __fb_uniqueid__ returns consistent

- __fb_uniqueid__ for undefined stack returns empty string
- __fb_uniqueid__ for empty stack returns empty string

* rtlib: internal change for isvarlen arguments

- use FALSE/TRUE for 'isvarlen' value instead of literals
- internal change on calls to fb_ArrayClear & fb_ArrayErase

* rtlib: check for static (fixed length) arrays in ERASE

- check for static (fixed length) arrays in fb_ArrayErase
- if the array is static but wasn't known at compile time then the array must be cleared only
- perform a run-time check using array descriptor flags to determine if array is static

* rtlib: add tests for ERASE of string arrays

* rtlib: remove legacy 'isvarlen' argument from array erase functions

- remove isvarlen parameter from fb_ArrayErase(), it's constant in all uses
- remove isvarlen parameter from fb_ArrayClear(), it's constant in all uses

* rtlib: remove unused 'dofill' argument in array functions

- remove dofill parameter from fb_ArrayClearObj(), it's constant in all uses

* rtlib: check for static object arrays in ERASE

- object arrays passed to fb_ArrayErase must clear / re-init the array if it is a static array (fixed length)
- internal change: fb_ArrayErase also needs default ctor, in the event that the a static array is passed

* rtlib: remove legacy array functions

- remove legacy fb_Redim() API function
- remove legacy fb_RedimPresv() API function
- these functions are no longer used and internal array structure has changed anyway

* rtlib: remove legacy array functions for temp array descriptors

- temporary descriptors are no longer used
- remove legacy array_setdesc.c
- remove legacy array_tmpdesc.c

* rtlib: error on invalid REDIM [PRESERVE]

- REDIM [PRESERVE] will generate run time error if attempting to resize static (fixed length) arrays.

* rtlib: update warnings/rtl-prototypes.bas for changed API

- fb_ArrayErase, fb_ArrayEraseObj, fb_ArrayClear, fb_ArrayClearObj

* FB_READ_LARGE / FB_WRITE_LARGE functions.

They differ from fread/fwrite in two main ways:
1. They take only a single parameter for the size, in bytes
2. They read/write in chunks of 1MB, to bypass any multi-gigabyte limits.
1MB chunks should be large enough to avoid significant overhead per chunk,
yet well short of any 32-bit length limits.

Use them in place of fread/fwrite in fbDevFileRead/Write, called eventually
by file GETs/PUTs.

* Rename nmemb to nbytes for clarity.

sed -i s/nmemb/nbytes/g fb_file.h

* Update fb_file.h

FB_FREAD_LARGE / FB_FWRITE_LARGE - don't bother short-circuiting small operations to the native functions.

* internal: updates for for ./inc/fbc-int headers

- updates source comments
- error on lang qb
- always use namespaces for lang fb & fblite

* fbc: basic-macros: add __FB_EVAL__ builtin

* fbc: basic-macros: prevent __FB_EVAL__ from emitting expressions to .pp.bas

* fbc: sf.net #882: error on REDIM udt.field(expr) if default constructor has no access

* Added data destructors for thread local data that makes additional allocations. Data they can leave allocated is now freed at thread exit

* rtlib: TLSfix: fix close_dir_internal( typos )

* rtlib TLS destructors (adeyblue)

* rtlib: update src/rtlib/dos/symb_reg.txt

* Fixes sourceforge bug #918

* rtlib: windows, fix for sf.net # 918, pcopy (console) bug

- copy large console buffer now uses malloc instead of alloca (adeyblue)

* rtlib: fix typo in changelog.txt

- sf.net # 914 should have been # 918

* Turn off the QuickEdit console mode during GetMouse initialisation, as that prevents the mouse messages from being generated

* rtlib: github freebasic#216: function getMouse() seems broken on Win10 when using the Console Mode (screen 0)

- fixed by turn off the QuickEdit console mode during GetMouse (adeyblue)

* fbdoc: add warning level number to mkerrlst.bas warning list generator

* fbc-tests: inhibit number display in tests/numbers/cast_f2ll.bas with fbcu.getHideCases()

* gas64: add FB_BACKEND_GAS64 logic for gas 64 emitter (SARG)

* gas64: default to gas64 backend on all x86_64 targets

* gas64: track labels used for gosubs

* gas64: always create AST_OP_DBG_LINEEND nodes

* gas64: add gas x86_64 emitter

* Revert "gas64: default to gas64 backend on all x86_64 targets"

This reverts commit 430f554.

* gas64: update changelog.txt

* gas64: function return results

- 'sarg' removed
- cpp log-tests fix however induces crashes when self compiling

* gas64: function results for structs

- fix for structures (size 9-16) on linux, new field retinreg and new enum
- some optimizations
- emitloadres reviewed

* gas64: function results for UDTs

- struc_analyse renamed to struct_analyze and moved into symb-struct.bas
- fix adding in struct_analyze for udt containing array
- fix removing of typeaddrof for FB_DATATYPE_STRUCT
- sizeof(integer) replaced by typegetsize(longint)
- removal of useless code in symb-proc.bas
- new procedure for handling storage 2 registers 16 bytes (usually 8 bytes max)
- retinreg only in FBS_STRUCT and used through its udt symbol
- some typos, cleaning

* gas64: whitespace and cosmetic changes

* gas64: move return type for gas64+Linux to hGetReturnTypeGas64Linux()

* gas64: emitstore optimization

    - simplification of emitted code in emitstore
    - class1/class2 renamed in part1/part2

* gas64: add gas64 testing to travis-ci

* update bindings: BASS 2.4.15, sqlite 3.33.0

* hotfix: disable SSE41 test and ASM in ir-gas64.bas

- exclude direct use of ASM in ir-gas64.bas
- disable test for SSE 41

* - rename retinreg to retin2regs (clearer)

* gas64: complete review for sse41
- no more asm code executed in fbc
- sse4_1 feature tested at begin of execution (like ctors) and update a flag
- flag tested when converting float into integer.
- some cosmetic changes

* gfxlib2: add DISABLE_D3D10 for building on / targeting WinXP

* gfxlib2: define ARRAYSIZE for old versions of gcc

* fbc-tests: DOS - functions/argv.bas

- don't link to windows libraries on DOS
- mask the test for DOS.  When building & testing on WinXP test can fail to due long versus short filenames

* build: disable d3d10 on winxp

* release: save FBSHA1 value for multiple use

- save the FBSHA1 value from git and pass it explicitly to make
- disable the D3D10 graphics driver on win32-mingworg

* rtlib: update src/rtlib/dos/symb_reg.txt

* fbc-tests: add mutex in threads/threadcall.bas

- occasional test-suite failures due to unit tests in multiple threads
- fbcunit is not thread-safe on it's own
- wrap the call to 'CU_ASSERT_TRUE' in a mutex in threads/threadcall.bas

* Disable vga16 blitter on ARM because it uses x86 asm
(as opposed to disabling the whole fbdev driver.)

* gfxlib2: enable frame buffer on linux-arm targets, but disable vga16_blitter

* gfxlib2: enable vga16_blitter on linux_arm, but disable the x86 assembler

* gfxlib2: linux-arm framebuffer and vga16_blitter

- enable frame buffer for linux-arm targets
- add vga16_blitter for linux-arm targets to pack 2 pixels per byte and write to linear frame buffer

* Fix DirectX and GDI GFX drivers crashing on some systems with IMEs because they show the window before they've completed initialisation

* changelog: fix messages for github # 256 - frame buffer on ARM

* changelog: update directx and gdi drivers, only show window after intialization is complete [skip travis]

* fbc: sf.net # 925: CSIGN/CUSGN preserve size when converting pointers

- previously on 64-bit CSIGN was converted to LONG and CSGN was converted to ULONG, when size should be preserved
- this also was seen in the STEP value of FOR...NEXT statements where STEP value for pointers was also converted to LONG
- this change preserves the size of the pointer when converted to [u]integer

* changelog: fix typo CSIGN/CUNSG

* travis: disable some tests for faster build testing

* gas64: fix check

* gas64: fix internal check

- returning structure values in registers true only if type is non-pointer struct

* Revert "travis: disable some tests for faster build testing"

This reverts commit 5267093.

* Revert "gas64: fix internal check"

This reverts commit 4d177a8.

Revert "gas64: fix check"

This reverts commit 350fd28.

* gas64: check if structure is returned in 2 registers

- add hIsStructIn2Regs() internal function
- add comments in hGetReturnTypeGas64Linux()

* gas64: invert test for SSE 41 feature flag

* gas64: some changes in comments and removal of some asm_info()

* gas64 : fix incomplete test in optimization module

* gas64 : new optimizations

mov -xxx[rbp], rax --> mov -xxx[rbp], rax kept
mov rcx, -xxx[rbp] --> freebasic#2 mov rcx, -xxx[rbp] commented
mov rcx, rax new line

movq -xxx[rbp], xmm0 --> movq -xxx[rbp], xmm0 kept
movq xmm1, -xxx[rbp] --> freebasic#3 movq xmm1, -xxx[rbp] commented
movsd xmm1, xmm0 new line

* gas64 : fix wrong use of test sse41 when converting float to ulongint causing use of roundss/roundsd even with CPU non compatible

* gas64 : removal of useless test in optimization (optim 3-1)

* gas64 : all 4 leading spaces replaced by tab (thanks to Notepad++)
	'By SARG' added (removed by error)

* gas64 : fix new optimizations....

* - gfxlib2: X11 driver - set the window title for both the frame window and the client window

* gfxlib2: fix linux GFX_NO_FRAME + GFX_OPENGL freezing at exit

- freezing due to dead lock between exit routines
- driver was waiting on window thread to exit, but window thread waiting on client frame to unmap
- resolves github issue # 122

* rtlib: add math lock

* rtlib: add fbc-int/math.bi

- Add fb_Rnd32() for getting 32-bit only part of RNG's
- Add fb_RndGetInternals() for getting internal state information
- Add fbc-int/math.bi and tests for RND, RND32, RANDOMIZE, GETINTERNALS

* rtlib: remove duplicate code in src/rtlib/math_rnd.c

* rtlib: fbc-int/math.bi declaration corrections

* rtlib: fix typo for fb_MathUnlock()

* rtlib: in fb_Rnd(), buffer RND_REAL values

* rtlib: sf.net # 914 thread safe random number generator

- rtlib: RANDOMIZE RND_REAL for real random number generator now fills a buffer (624 ulongs) and RND iterates the buffer
- ./inc/fbc-int/math.bi - fbc API for rnd, rnd32, randomize, expose some random number generator internals
- sf.net #914: threadsafe RND() and RANDOMIZE() by adding a mutex

* gas64 : removal of duplicate code in _emitconvert by creating sub hEmitRoundFloat

* rtlib: Add FB_RND_ALGORITHMS as part of the rtlib API

- add ./inc/fbmath.bi
- move FB_RND_ALGORITHMS to FB namespace
- add enum FB_RND_ALGORITHMS to ./src/rtlib/fb_math.h

* rtlib: rename FB_RNDINTERNALS to FB_RNDSTATE

* rtlib: move all of RND global state into a FB_RNDSTATE type variable

- add static FB_RNDSTATE ctx variable to hold all global RND state
- fb_RndGetState() returns a pointer to the global state

* rtlib: refactor startup code for math_rnd.c

* rtlib: refactor RANDOMIZE start up code

* rtlib: update fbmath.bi

- if fbmath.bi is included, move RANDOMIZE and RND to the FB namespace

* fbmath.bi: add PRNG types

- Add a simple fb.RndFAST32 type with rnd & rnd32 methods
- Add a simple fb.RndMSWS32 type with rnd & rnd32 methods
- Add a simple fb.RndSquares32 type with rnd & rnd32 methods
- Add a simple fb.RndPCG32 type with rnd & rnd32 methods
- Add a simple fb.Rndxoroshiro128 type with rnd & rnd64 methods

* rtlib: fbc-int/math.bi - update internals

- remove the init functions from the exposed API, they are not useful publicly
- rnd & randomize are in the fbc namespace again
- move the QB seeding code back to fb_Randomize

* rtlib: update changelog.txt - randomize, rnd, fbc-int/math.bi, fbmath.bi

* rtlib: typo in fb_math.h declaration of FB_RNDSTATE

* Fixed: in the process of converting double byte characters (such as Chinese characters), the wrong buffer length was obtained.

* rtlib: string and wstring conversions

In previous commit (Skyfish) converting between string and wstring uses multi-byte & wide character
functions wctombs() & mbtowcs() However, on DOS wctombs() & mbtowcs() just map to memcpy, so keep
the previous string length calculation for DOS only.

* rtlib: RND fix typo for DOS

- DOS version of math_rnd.c incorrectly includes hRndCtxInitREAL32 when it should be disabled

* dos: update symb_reg.txt

* fbc: bugfix sf.net 568, asm error assigning 16-bit constant to 32-bit var

- was invalid use of movsx instruction on immediate (short => long)

* fbc: bugfix sf.net 568, optimize constant 0 conversions after hOptNULLOpt()

- hOptNULLOpt() can possibly leave zero value CONST nodes behind that don't get optimized out due a parent CONV node
- this change adds hOptConstCONV() called from hOptNULLOpt() to eliminate the extra operation
- only for 0 value integer to integer conversions

* rtlib: fix for loop in fb_math.h for older gcc

* fbc: internal cThreadCallFunc() was using wrong function to get the procedures return type

* Implemented ThreadSelf and the surprising amount of plumbing it required. Plus tests and bi

* rtlib: added ThreadSelf (adeyblue)

- touch changelog.txt

* fbcunit: update to version 1.0

- fbcu.setShowConsole( true|false ) method to show console logging (true), or not (false, default)
- fbcu.getShowConsole() as boolean to return current setting for "showConsole" option
- fbcu.outputConsoleString( byref s as const string = "" ) output to console depending on showConsole setting

* fbc-tests: add show-console option from fbcunit version 1.0

- console output is disabled by default
- use 'fbc-tests --show-console' to enable console output (messages)
- update threads/racecondition.bas & threads/self.bas to optionally show console output

* fbc: read objinfo for elf format files on arm32 and arm64 (aarch64) to allow automatic options and linking of libraries

* release: add linux-arm and linux-aarch64 targets

- update makefile to build linux-aarch64 and linux-arm targets
- update build.sh to allow linux-aarch64 and linux-arm targets
- choose 1.07.2 for bootstrap source on linux-aarch
- choose 1.07.2 for bootstrap source on linux-arm

* fbc-tests: disable some tests for arm targets

- arm targets returning NAN instead of IND
- threadcall appears broken on arm
- use -d ENABLE_CHECK_BUGS=1 compile time option to enable bug checks

* update changelog.txt for the arm and aarch64 changes

* fbc: name mangling for cva_list name mangling with arm32 and arm64 (aarch64) targets

- va_list on arm and aarch64 is actually in the std namespace requiring "St" to mangle "std::"

* fbc: cva_list name mangling with arm32 and arm64 (aarch64) targets

- add missing notes to symbKeywordTypeInit()

* fbc: sf.net # 924: built-in for RGB() & RGBA() returns ULONG

* gfxlib2: POINT() returns ULONG

* fbc-tests: suite name fixups

* fbcunit: check for return values in SUITE_INIT and SUITE_EXIT routines

* fbc-tests: return success value in SUITE_INIT and SUITE_EXIT routines

* fbdoc: wiki snapshot 2020-12-06

Co-authored-by: adeyblue <adeyblue@example.com>
Co-authored-by: coderJeff <coder@execulink.com>
Co-authored-by: countingpine <matthew.w.fearnley@gmail.com>
Co-authored-by: v1ctor <av1ctor@yahoo.com.br>
Co-authored-by: av1ctor <av1ctortv@gmail.com>
Co-authored-by: SARG <debug@aliceadsl.fr>
Co-authored-by: Stefan Wurzinger <swurzinger@gmx.at>
Co-authored-by: SkyFish <skyfish4tb@gmail.com>
dkl added a commit to dkl/fbc that referenced this pull request Jul 18, 2022
CLEAR takes the "object" to clear by reference, not an address by value.
The extra @ (address-of) lead to clearing a temp var on stack (and
likely overflowing it) instead of clearing the wanted variable,
i.e. undefined behaviour.

Reported at: freebasic#382
gcc AddressSanitizer finds this issue aswell:
==279298==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffb16875e8 at pc 0x7fb7f4a01c23 bp 0x7fffb16874a0 sp 0x7fffb1686c48
WRITE of size 200 at 0x7fffb16875e8 thread T0
    #0 0x7fb7f4a01c22 in __interceptor_memset ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:799
    freebasic#1 0xa3fb11 in TESTS::FBC_TESTS::UDT_WSTRING_::MIDSTMT::ASCII() (/home/daniel/fb/fbc/tests/fbc-tests+0xa3fb11)
    freebasic#2 0xcc536c in FBCU::RUN_TESTS(bool, bool) src/fbcunit.bas:649
    freebasic#3 0xcc134e in main (/home/daniel/fb/fbc/tests/fbc-tests+0xcc134e)
    freebasic#4 0x7fb7f4506d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    freebasic#5 0x7fb7f4506e3f in __libc_start_main_impl ../csu/libc-start.c:392
    freebasic#6 0x413364 in _start (/home/daniel/fb/fbc/tests/fbc-tests+0x413364)

Fixes: 135f364 "udt-wstring: MID statement will accept UDT as Z|WSTRING"
dkl added a commit to dkl/fbc that referenced this pull request Jul 18, 2022
Given
	dim e1 as wstring * BUFFERSIZE
	dim n1 as integer = BUFFERSIZE
then e1[n1] is an out-of-bounds access. I'm not entirely sure if the
change is sane with regards to the intent of the code (maybe e1 is
supposed to be BUFFERSIZE + 1?), but least it's not overflowing anymore.

Found with gcc AddressSanitizer:
[...]
==325124==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffd6b7ecd28 at pc 0x000000b97cfb bp 0x7ffd6b7ec800 sp 0x7ffd6b7ec7f0
WRITE of size 4 at 0x7ffd6b7ecd28 thread T0
    #0 0xb97cfa in TESTS::FBC_TESTS::WSTRING_::MIDSTMT::ASCII() wstring/midstmt.bas:86
    freebasic#1 0xc56259 in FBCU::RUN_TESTS(bool, bool) src/fbcunit.bas:649
    freebasic#2 0xc52533 in main (/home/daniel/fb/fbc/tests/fbc-tests+0xc52533)
    freebasic#3 0x7fe4d3ddad8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    freebasic#4 0x7fe4d3ddae3f in __libc_start_main_impl ../csu/libc-start.c:392
    freebasic#5 0x4082e4 in _start (/home/daniel/fb/fbc/tests/fbc-tests+0x4082e4)

Address 0x7ffd6b7ecd28 is located in stack of thread T0 at offset 1000 in frame
    #0 0xb97420 in TESTS::FBC_TESTS::WSTRING_::MIDSTMT::ASCII() wstring/midstmt.bas:70

  This frame has 8 object(s):
    [32, 100) 'DST$1'
    [144, 212) 'SRC$1'
    [256, 456) 'W1$8'
    [528, 728) 'W2$8'
    [800, 1000) 'E1$8' <== Memory access at offset 1000 overflows this variable
    [1072, 1272) 'W1$10'
    [1344, 1544) 'W2$10'
    [1616, 1816) 'E1$10'
[...]

Fixes: 135f364 "udt-wstring: MID statement will accept UDT as Z|WSTRING"
dkl added a commit to dkl/fbc that referenced this pull request Jul 18, 2022
CLEAR takes the "object" to clear by reference, not an address by value.
The extra @ (address-of) lead to clearing a temp var on stack (and
likely overflowing it) instead of clearing the wanted variable,
i.e. undefined behaviour.

Reported at: freebasic#382
gcc AddressSanitizer finds this issue aswell:
```
==279298==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffb16875e8 at pc 0x7fb7f4a01c23 bp 0x7fffb16874a0 sp 0x7fffb1686c48
WRITE of size 200 at 0x7fffb16875e8 thread T0
    #0 0x7fb7f4a01c22 in __interceptor_memset ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:799
    freebasic#1 0xa3fb11 in TESTS::FBC_TESTS::UDT_WSTRING_::MIDSTMT::ASCII() (/home/daniel/fb/fbc/tests/fbc-tests+0xa3fb11)
    freebasic#2 0xcc536c in FBCU::RUN_TESTS(bool, bool) src/fbcunit.bas:649
    freebasic#3 0xcc134e in main (/home/daniel/fb/fbc/tests/fbc-tests+0xcc134e)
    freebasic#4 0x7fb7f4506d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    freebasic#5 0x7fb7f4506e3f in __libc_start_main_impl ../csu/libc-start.c:392
    freebasic#6 0x413364 in _start (/home/daniel/fb/fbc/tests/fbc-tests+0x413364)
```

Fixes: 135f364 "udt-wstring: MID statement will accept UDT as Z|WSTRING"
dkl added a commit to dkl/fbc that referenced this pull request Jul 18, 2022
Given
	dim e1 as wstring * BUFFERSIZE
	dim n1 as integer = BUFFERSIZE
then e1[n1] is an out-of-bounds access. I'm not entirely sure if the
change is sane with regards to the intent of the code (maybe e1 is
supposed to be BUFFERSIZE + 1?), but least it's not overflowing anymore.

Found with gcc AddressSanitizer:
```
==325124==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffd6b7ecd28 at pc 0x000000b97cfb bp 0x7ffd6b7ec800 sp 0x7ffd6b7ec7f0
WRITE of size 4 at 0x7ffd6b7ecd28 thread T0
    #0 0xb97cfa in TESTS::FBC_TESTS::WSTRING_::MIDSTMT::ASCII() wstring/midstmt.bas:86
    freebasic#1 0xc56259 in FBCU::RUN_TESTS(bool, bool) src/fbcunit.bas:649
    freebasic#2 0xc52533 in main (/home/daniel/fb/fbc/tests/fbc-tests+0xc52533)
    freebasic#3 0x7fe4d3ddad8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    freebasic#4 0x7fe4d3ddae3f in __libc_start_main_impl ../csu/libc-start.c:392
    freebasic#5 0x4082e4 in _start (/home/daniel/fb/fbc/tests/fbc-tests+0x4082e4)

Address 0x7ffd6b7ecd28 is located in stack of thread T0 at offset 1000 in frame
    #0 0xb97420 in TESTS::FBC_TESTS::WSTRING_::MIDSTMT::ASCII() wstring/midstmt.bas:70

  This frame has 8 object(s):
    [32, 100) 'DST$1'
    [144, 212) 'SRC$1'
    [256, 456) 'W1$8'
    [528, 728) 'W2$8'
    [800, 1000) 'E1$8' <== Memory access at offset 1000 overflows this variable
    [1072, 1272) 'W1$10'
    [1344, 1544) 'W2$10'
    [1616, 1816) 'E1$10'
[...]
```

Fixes: 135f364 "udt-wstring: MID statement will accept UDT as Z|WSTRING"
SARG-FB added a commit to SARG-FB/fbc that referenced this pull request Jan 1, 2024
jayrm pushed a commit that referenced this pull request Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants