Fix string returns

This commit is contained in:
John Bintz 2024-03-18 12:34:30 -04:00
parent bfe0f8a09b
commit e5cb65a302
3 changed files with 64 additions and 66 deletions

Binary file not shown.

View File

@ -197,7 +197,16 @@ to contact me.
* Fix crash bug in `Socket Inet Ntoa$` if called with the BSD Socket library
was not open.
#
### 1.1.2 (2024-03-18)
* Fix all functions that return strings so that strings work properly
in AMOS. While you could kind of use the immediate return value of the
string, any future manipulation of that string would fail. This fixes
the following functions:
* `Socket Inet Ntoa$`
* `Dns Get Address By Name$`
* `Socket Recv$`
# Development
### Environment

View File

@ -7,7 +7,7 @@
; extension number 18
ExtNb equ 18-1
Version MACRO
dc.b "1.1.1-20240317"
dc.b "1.1.2-20240318"
ENDM
VerNumber equ $1
@ -1184,12 +1184,12 @@ _SocketSelect_PerformSelect
Lib_Par SocketInetNtoA
; - - - - - - - - - - - - -
PreserveStackFunction
EnsureBSDSocketLibrary _SocketInetNtoa_LibraryOpen
EnsureBSDSocketLibrary _SocketInetNtoA_LibraryOpen
RestoreStackFunction
Ret_Int
_SocketInetNtoa_LibraryOpen:
_SocketInetNtoA_LibraryOpen:
MOVE.L D3,D0
WithDataStorageToA3
LoadBSDSocketBaseFromA3
@ -1204,22 +1204,27 @@ _SocketInetNtoA_StringSizeLoop:
TST.B (A0)+
BNE _SocketInetNtoA_StringSizeLoop
MOVE.L A0,D3
SUB.L A2,D3 ; D3 = length
SUBQ #1,D3 ; get rid of the null terminator
MOVE.L A0,D4
SUB.L A2,D4 ; D4 = length
SUBQ #1,D4 ; get rid of the null terminator
; add 2 and even out the space
MOVE.L D4,D3
AND.W #$FFFE,D3
ADDQ.W #2,D3
Rjsr L_Demande ; string base address is in A0/A1
MOVE.W D3,(A0)+ ; length of string
SUBQ #1,D3
LEA 2(A0,D3.W),A1
MOVE.L A1,HiChaine(A5)
MOVE.L A0,A1
MOVE.W D4,(A0)+ ; length of string
SUBQ #1,D4
_SocketInetNtoA_StringCopyLoop:
MOVE.B (A2,D3),(A0,D3)
DBRA D3,_SocketInetNtoA_StringCopyLoop
; make the address even
EvenOutStringAddress A0,D3
MOVE.L A0,HiChaine(A5) ; Does L_Demande nuke A5 too?
MOVE.B (A2,D4),(A0,D4)
DBRA D4,_SocketInetNtoA_StringCopyLoop
MOVE.L A1,D3 ; string return
@ -1267,14 +1272,12 @@ _SocketRecvString_NotNegative:
_SocketRecvString_NotTooLong:
MOVE.L A3,-(SP) ; preserve A3
MOVE.L D0,-(SP) ; preserve D0
; reserve memory for recv buffer
Rjsr L_RamFast ; D0 now contains memory pointer
BNE _SocketRecvString_BufferAllocated
; reserve failed
MOVE.L (SP)+,D0
MOVE.L (SP)+,A3
MOVE.L ChVide(A5),D3 ; empty string
@ -1284,16 +1287,14 @@ _SocketRecvString_NotTooLong:
_SocketRecvString_BufferAllocated:
MOVE.L D0,A0 ; buffer address
MOVE.L D1,D0 ; socket
MOVE.L (SP)+,D1 ; length
MOVE.L (SP)+,D1 ; reserved ram buffer length
MOVEQ #0,D2 ; flags
MOVEM.L A0-A1/D1,-(SP)
WithDataStorageToA3
LoadBSDSocketBaseFromA3
CALLLIB recv ; D0 has received length or -1
EndDataStorage
MOVEM.L (SP)+,A0-A1/D1
; did we receive data? if we didn't get a single byte, we're done
@ -1304,7 +1305,6 @@ _SocketRecvString_BufferAllocated:
MOVE.L D1,D0
MOVE.L A0,A1
Rjsr L_RamFree
MOVE.L (SP)+,A3
MOVE.L ChVide(A5),D3
@ -1314,37 +1314,37 @@ _SocketRecvString_BufferAllocated:
; TODO received data is wrong somewhere
_SocketRecvString_DataReceived:
; D0 contains receive length
; D0 contains socket receive length
MOVE.L D1,-(SP)
; TODO: handle zero return length
MOVE.L A0,A2 ; A2 contains read buffer
MOVE.L D1,-(SP) ; reserved ram buffer length
; demande/hichaine string setup
MOVEQ #0,D3
MOVE.W D0,D3 ; prep for L_Demande. can we request a zero length string?
MOVE.L A0,A2 ; L_Demande blows away A0 and A1, A2 now contains buffer
MOVE.W D0,D3
AND.W #$FFFE,D3
ADDQ #2,D3
Rjsr L_Demande ; A0/A1 contain string address
MOVE.W D3,(A0)+ ; put in string length
SUBQ #1,D3 ; reduce by one for DBRA
LEA 2(A0,D3.W),A1
MOVE.L A1,HiChaine(A5)
MOVE.L A0,A1
MOVE.W D0,(A1)+ ; put in string length
SUBQ #1,D0 ; reduce by one for DBRA
MOVE.L A2,A3 ; A3 now contains start of buffer
_SocketRecvString_CopyData:
MOVE.B (A2,D3),(A0,D3)
DBRA D3,_SocketRecvString_CopyData
MOVE.B (A2,D0),(A1,D0)
DBRA D0,_SocketRecvString_CopyData
MOVE.L (SP)+,D0 ; reserved ram buffer length
EvenOutStringAddress A0,D2
; add to string manager for garbage collection?
MOVE.L A0,HiChaine(A5)
MOVE.L (SP)+,D0
; free ram
MOVE.L A1,-(SP) ; A1 contains our string addres
;MOVE.L D1,D0
MOVE.L A0,-(SP)
MOVE.L A3,A1
Rjsr L_RamFree
MOVE.L (SP)+,D3 ; string return
MOVE.L (SP)+,D3
MOVE.L (SP)+,A3
RestoreStackFunction
@ -1735,7 +1735,7 @@ _SocketReuseAddr_LibraryOpen:
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; =Dns Get Host Address By Name$(Name String)
; =Dns Get Address By Name$(Name String)
;
; Get the status of a socket
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1789,14 +1789,6 @@ _SocketReuseAddr_LibraryOpen:
TST.L D0
BNE .GetIPAddress
Dlea DebugArea,A0
MOVE.L D3,A1
MOVE.L #1,(A0)+
MOVE.W (A1),(A0)+
MOVE.W (A1),D2
MOVE.B 1(A1,D2),(A0)+
MOVE.B 2(A1,D2),(A0)+
RestoreStackFunction
MOVE.L ChVide(A5),D3
@ -1813,9 +1805,6 @@ _SocketReuseAddr_LibraryOpen:
CALLLIB Inet_NtoA
EndDataStorage
Dlea DebugArea,A0
MOVE.L D0,(A0)+
MOVE.L D0,A2
MOVE.L A2,-(SP)
MOVEQ #0,D3
@ -1826,21 +1815,21 @@ _SocketReuseAddr_LibraryOpen:
BNE .GetIPAddressLength
MOVE.L (SP)+,A2
Dlea DebugArea,A0
MOVE.L D3,(A0)+
MOVE.L D3,D4
AND.W #$FFFE,D3
ADDQ #2,D3
Rjsr L_Demande ; string is in A0/A1
MOVE.W D3,(A0)+
SUBQ #1,D3
LEA 2(A0,D3.W),A1
MOVE.L A1,HiChaine(A5)
MOVE.L A0,D3
MOVE.W D4,(A0)+
SUBQ #1,D4
.KeepCopying:
MOVE.B (A2,D3),(A0,D3)
DBRA D3,.KeepCopying
EvenOutStringAddress A0,D0
MOVE.L A0,HiChaine(A5)
MOVE.L A1,D3
MOVE.B (A2,D4),(A0,D4)
DBRA D4,.KeepCopying
RestoreStackFunction