Test > Test

Change valist with an array of args

(1/2) > >>

frankie:
This is the modified code that still holds the former one, commented out, for reference purpose.

jcfuller:
frankie,
  I found a piece of code that fails using your CreateArr code.
It is really non-real world code in my opinion as there is no data to preserve,
but it does compile and run as a 32bit app with PellesC, VS 2015, TDM-GCC-32, Tiny C 9.2.6
It fails with all of them when compiled as a 64bit app except Tiny C 9.2.6 64bit.
If we remove the "preserve" and use just: redim buffer$[arr_size] it is fine.
Thank you for your help,

James

"c" with preserve

--- Code: ---buffer = (char**)CreateArr (buffer, sizeof(char), 1, 2, dimensions);

--- End code ---
"c" without preserve

--- Code: ---buffer = (char**)CreateArr (buffer, sizeof(char), 0, 2, dimensions);

--- End code ---

This is the basic code that produces the attached "c".

--- Code: ---    dim dynamic buffer$[10]
    dim num_lines as integer
    dim arr_size as integer
    arr_size = 10
    num_lines = 0
    for num_lines = 1 to 100
        if num_lines >= arr_size then
            print "*** growing from: " & STR$(arr_size) & " to: " & STR$(arr_size + 10);
            arr_size += 10
            redim preserve buffer$[arr_size]
            print " *** grown"
        end if
    next
    Pause   

--- End code ---

frankie:
Ok got it.
This should be the main reason for bad working.
The code adds two dummy elements at the end of the array and set them to 0 to be used as an end of array mark. The original code used this line to set them to 0:

--- Code: ---*(((int *)vp)) = 0;

--- End code ---
In this way only 4 bytes of an 8 bytes 64bits pointer are set to 0, the remaining keeps the trash that they contained. Anyway it works on machines having int of same size of pointers. But on 64bits machine this is not the case...  8)
I replaced it with this code:

--- Code: ---*(((void **)vp)) = NULL;

--- End code ---
That correctly set a full size pointer.
You may try this fix also on the original code using variadic functions, and I think it will come back to life!  ;D
Let me know.

EDIT the patch can be also:

--- Code: ---*vp = NULL;

--- End code ---
Because vp is already defined as void **vp;.

jcfuller:
frankie,
  THANK YOU, THANK YOU
We did need your change away from the variadic function along with this one.
So far all is well.

James

frankie:
You're welcome.

Navigation

[0] Message Index

[#] Next page

Go to full version