forked from ImortisInglorian/fbrtLib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharray_tempdesc.bas
99 lines (75 loc) · 2.4 KB
/
array_tempdesc.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/' !!!REMOVEME!!! '/
/' temp descriptor core, for array fields passed by descriptor '/
#include "fb.bi"
#include "crt/stddef.bi"
/' *********
* temp array descriptors
**********'/
dim shared as FB_LIST tmpdsList = Type( 0, 0, 0, 0 )
dim shared as FB_ARRAY_TMPDESC fb_tmpdsTB(0 to FB_ARRAY_TMPDESCRIPTORS - 1)
extern "C"
/':::::'/
function fb_hArrayAllocTmpDesc cdecl( ) as FBARRAY ptr
dim as FB_ARRAY_TMPDESC ptr dsc
if ( (tmpdsList.fhead = NULL) and (tmpdsList.head = NULL) ) then
fb_hListInit( @tmpdsList, cast(any ptr, @fb_tmpdsTB(0)), sizeof(FB_ARRAY_TMPDESC), FB_ARRAY_TMPDESCRIPTORS )
end if
dsc = cast(FB_ARRAY_TMPDESC ptr, fb_hListAllocElem( @tmpdsList ))
if ( dsc = NULL ) then
return NULL
end if
return cast(FBARRAY ptr, @dsc->array)
end function
/':::::'/
sub fb_hArrayFreeTmpDesc cdecl ( src as FBARRAY ptr )
dim as FB_ARRAY_TMPDESC ptr dsc
dsc = cast(FB_ARRAY_TMPDESC ptr, (cast(ubyte ptr, src)- offsetof(FB_ARRAY_TMPDESC, array)))
fb_hListFreeElem( @tmpdsList, cast(FB_LISTELEM ptr, dsc) )
end sub
function fb_ArrayAllocTempDesc cdecl ( pdesc as FBARRAY ptr ptr, arraydata as any ptr, element_len as size_t, dimensions as size_t, ... ) as FBARRAY ptr
dim as va_list ap
dim as size_t i, elements
dim as ssize_t diff
dim as FBARRAY ptr array
dim as FBARRAYDIM ptr _dim
dim as ssize_t lbTB(0 to FB_MAXDIMENSIONS - 1)
dim as ssize_t ubTB(0 to FB_MAXDIMENSIONS - 1)
FB_LOCK()
array = fb_hArrayAllocTmpDesc( )
FB_UNLOCK()
*pdesc = array
if ( array = NULL ) then
return NULL
end if
if ( dimensions = 0) then
/' special case for GET temp arrays '/
array->size = 0
return array
end if
'va_start( ap, dimensions )
ap = va_first()
_dim = @array->dimTB(0)
for i = 0 to dimensions
lbTB(i) = cast(ssize_t, va_next( ap, ssize_t ))
ubTB(i) = cast(ssize_t, va_next( ap, ssize_t ))
_dim->elements = (ubTB(i) - lbTB(i)) + 1
_dim->lbound = lbTB(i)
_dim->ubound = ubTB(i)
_dim += 1
next
'va_end( ap )
elements = fb_hArrayCalcElements( dimensions, @lbTB(0), @ubTB(0) )
diff = fb_hArrayCalcDiff( dimensions, @lbTB(0), @ubTB(0) ) * element_len
array->data = (cast(ubyte ptr, arraydata)) + diff
array->_ptr = arraydata
array->size = elements * element_len
array->element_len = element_len
array->dimensions = dimensions
return array
end function
sub fb_ArrayFreeTempDesc FBCALL( pdesc as FBARRAY ptr )
FB_LOCK()
fb_hArrayFreeTmpDesc( pdesc )
FB_UNLOCK()
end sub
end extern