Closed GWRon closed 2 years ago
Regarding the difference between
Select ev.event
and
Select ev.event()
... the generated C-Code does NOT contain a difference there ... but shouldn't it?
So this is the base code:
Method Update()
local ev:ENetEvent = New ENetEvent
local id:int
local packet:TNetworkPacket = null
If Not Self.enethost
RuntimeError "Can't update a remote server."
return
endif
Repeat
If not enet_host_service(Self.enethost, ev, 0) then exit
Select ev.event()
Case ENET_EVENT_TYPE_CONNECT
id=NET_CONNECT
Case ENET_EVENT_TYPE_DISCONNECT
id=NET_DISCONNECT
Case ENET_EVENT_TYPE_RECEIVE
local obj:TNetworkObject
?bmxng
Local size:Int=bmx_enet_packet_size(ev.packet)
?not bmxng
Local size:Int=enet_packet_size(ev.packet)
?
Local data:Byte[size]
If size
packet=New TNetworkPacket
?bmxng
packet._bank.resize(Size_T(size))
MemCopy(packet._bank.buf(),bmx_enet_packet_data(ev.packet),Size_T(size))
?not bmxng
packet._bank.resize(size)
MemCopy(packet._bank.buf(),enet_packet_data(ev.packet),size)
?
obj = TNetworkObject.FromPacket(packet)
id = obj.evType
EndIf
Default
Continue
EndSelect
EvaluateEvent(id,packet,ev.peer)
'this is not the same!!!
'If not self.enethost then Exit
If self.enethost=Null then Exit
Forever
End Method
Current BCC:
void __m_basefunctions_network_TNetworkConnection_Update(struct _m_basefunctions_network_TNetworkConnection_obj* o){
struct pub_enet_ENetEvent_obj* bbt_ev=(struct pub_enet_ENetEvent_obj*)(struct pub_enet_ENetEvent_obj*)bbObjectAtomicNew((BBClass *)&pub_enet_ENetEvent);
BBINT bbt_id=0;
struct _m_basefunctions_network_TNetworkPacket_obj* bbt_packet=(struct _m_basefunctions_network_TNetworkPacket_obj*)&bbNullObject;
if(!(o->__m_basefunctions_network_tnetworkconnection_enethost )){
brl_blitz_RuntimeError((BBString*)&_s3);
return;
}
do{
if(!(enet_host_service(o->__m_basefunctions_network_tnetworkconnection_enethost ,(bbObjectToFieldOffset((BBObject*)bbt_ev)),0U)!=0)){
break;
}
BBINT bbt_=(bbt_ev)->clas->m_event((struct pub_enet_ENetEvent_obj*)bbt_ev);
if(bbt_==1){
bbt_id=1;
}else{
if(bbt_==2){
bbt_id=2;
}else{
if(bbt_==3){
struct _m_basefunctions_network_TNetworkObject_obj* bbt_obj=(struct _m_basefunctions_network_TNetworkObject_obj*)((struct _m_basefunctions_network_TNetworkObject_obj*)&bbNullObject);
BBINT bbt_size=((BBINT)bmx_enet_packet_size((bbt_ev)->clas->m_packet((struct pub_enet_ENetEvent_obj*)bbt_ev)));
BBARRAY bbt_data=bbArrayNew1D("b", bbt_size);
if(bbt_size!=0){
bbt_packet=(struct _m_basefunctions_network_TNetworkPacket_obj*)(struct _m_basefunctions_network_TNetworkPacket_obj*)bbObjectNew((BBClass *)&_m_basefunctions_network_TNetworkPacket);
struct brl_bank_TBank_obj* bbt_2;
(((struct brl_bank_TBank_obj*)(bbt_2 = bbt_packet->_brl_bankstream_tbankstream__bank ))->clas)->m_Resize_z((struct brl_bank_TBank_obj*)bbt_2,((BBSIZET)bbt_size));
struct brl_bank_TBank_obj* bbt_3;
bbMemCopy((void*)(((struct brl_bank_TBank_obj*)(bbt_3 = bbt_packet->_brl_bankstream_tbankstream__bank ))->clas)->m_Buf((struct brl_bank_TBank_obj*)bbt_3),bmx_enet_packet_data((bbt_ev)->clas->m_packet((struct pub_enet_ENetEvent_obj*)bbt_ev)),(size_t)((BBSIZET)bbt_size));
bbt_obj=(struct _m_basefunctions_network_TNetworkObject_obj*)_m_basefunctions_network_TNetworkObject_FromPacket_TTNetworkObject_TTNetworkPacket((struct _m_basefunctions_network_TNetworkPacket_obj*)bbt_packet);
bbt_id=bbt_obj->__m_basefunctions_network_tnetworkobject_evtype ;
}
}else{
continue;
}
}
}
((struct _m_basefunctions_network_TNetworkConnection_obj*)o)->clas->m_EvaluateEvent_iTTNetworkPacketpb((struct _m_basefunctions_network_TNetworkConnection_obj*)o,bbt_id,(struct _m_basefunctions_network_TNetworkPacket_obj*)bbt_packet,(bbt_ev)->clas->m_peer((struct pub_enet_ENetEvent_obj*)bbt_ev));
if(o->__m_basefunctions_network_tnetworkconnection_enethost ==0){
break;
}
}while(!(0));
}
while the old bcc generated this:
void __m_basefunctions_network_TNetworkConnection_Update(struct _m_basefunctions_network_TNetworkConnection_obj* o){
struct pub_enet_ENetEvent_obj* bbt_ev=(struct pub_enet_ENetEvent_obj*)(struct pub_enet_ENetEvent_obj*)bbObjectAtomicNew((BBClass *)&pub_enet_ENetEvent);
BBINT bbt_id=0;
struct _m_basefunctions_network_TNetworkPacket_obj* bbt_packet=(struct _m_basefunctions_network_TNetworkPacket_obj*)&bbNullObject;
if(!(o->__m_basefunctions_network_tnetworkconnection_enethost )){
brl_blitz_RuntimeError((BBString*)&_s3);
return;
}
do{
if(!(enet_host_service(o->__m_basefunctions_network_tnetworkconnection_enethost ,(bbObjectToFieldOffset((BBObject*)bbt_ev)),0U)!=0)){
break;
}
BBINT bbt_=(bbt_ev)->clas->m_event((struct pub_enet_ENetEvent_obj*)bbt_ev);
if(bbt_==1){
bbt_id=1;
}else{
if(bbt_==2){
bbt_id=2;
}else{
if(bbt_==3){
struct _m_basefunctions_network_TNetworkObject_obj* bbt_obj=(struct _m_basefunctions_network_TNetworkObject_obj*)((struct _m_basefunctions_network_TNetworkObject_obj*)&bbNullObject);
BBINT bbt_size=((BBINT)bmx_enet_packet_size(pub_enet_ENetEvent_packet));
BBARRAY bbt_data=bbArrayNew1D("b", bbt_size);
if(bbt_size!=0){
bbt_packet=(struct _m_basefunctions_network_TNetworkPacket_obj*)(struct _m_basefunctions_network_TNetworkPacket_obj*)bbObjectNew((BBClass *)&_m_basefunctions_network_TNetworkPacket);
struct brl_bank_TBank_obj* bbt_2;
(((struct brl_bank_TBank_obj*)(bbt_2 = bbt_packet->_brl_bankstream_tbankstream__bank ))->clas)->m_Resize_z((struct brl_bank_TBank_obj*)bbt_2,((BBSIZET)bbt_size));
struct brl_bank_TBank_obj* bbt_3;
bbMemCopy((void*)(((struct brl_bank_TBank_obj*)(bbt_3 = bbt_packet->_brl_bankstream_tbankstream__bank ))->clas)->m_Buf((struct brl_bank_TBank_obj*)bbt_3),bmx_enet_packet_data(pub_enet_ENetEvent_packet),(size_t)((BBSIZET)bbt_size));
bbt_obj=(struct _m_basefunctions_network_TNetworkObject_obj*)_m_basefunctions_network_TNetworkObject_FromPacket_TTNetworkObject_TTNetworkPacket((struct _m_basefunctions_network_TNetworkPacket_obj*)bbt_packet);
bbt_id=bbt_obj->__m_basefunctions_network_tnetworkobject_evtype ;
}
}else{
continue;
}
}
}
((struct _m_basefunctions_network_TNetworkConnection_obj*)o)->clas->m_EvaluateEvent_iTTNetworkPacketpb((struct _m_basefunctions_network_TNetworkConnection_obj*)o,bbt_id,(struct _m_basefunctions_network_TNetworkPacket_obj*)bbt_packet,pub_enet_ENetEvent_peer);
if(o->__m_basefunctions_network_tnetworkconnection_enethost ==0){
break;
}
}while(!(0));
}
(the difference can be spotted in the DIFF part in the earlier post)
Arghhh .... seems I missed that ev.packet
.... is not a FIELD ... but a METHOD ... a method returning a "Byte Ptr".
So essencially both "ev.packet" and "ev.packet()" are "usable" in the position they are used.
My code used some older gnet-code ... and I seem to have missed the gnet.mod commit from August https://github.com/bmx-ng/brl.mod/commit/11e34bf7220877fb1ef5f00e5522c00c3b2f8b1d#diff-af0aa8ee4580bc077175b67f75b64ed20a77aa7a8099fc7e9c0b4d10cf4d5749
I have more of these "if not obj.method or ..." in which I missed the brackets.
Now I wonder why I saw some of these (the basefunctions network source file) on my desktop computer. In a "Cent OS 7 32bit" VM with a GCC 7.5 I compiled with the same config flags (except the 64bit stuff) as used for the gcc 7.5 on my desktop ... I see additional mistakes (other left brackets). Thought it compiles "the same" but there seem to be differences.
I reopened the issue ... because I would like to ask for ideas on how to "identify" missed brackets.
As said the self-compiled gcc blamed the missing brackets (the generated C code of bcc was incorrect). The gcc on my desktop compiled fine without the adjustments.
I now am a bit afraid to have missed some changes .... so am open for ideas on how to "ensure" I did not miss one.
In general, there should now be errors when you try to call a method without brackets.
However in this case, there was an issue where the parameter was declared as Byte Ptr
, so the method was incorrectly being passed as a function pointer. Only functions can be used as function pointers.
In my game code (basefunctions_network.bmx) I use pub.enet
Some commits earlier code was translated this way:
BBINT bbt_size=((BBINT)bmx_enet_packet_size((bbt_ev)->clas->m_packet((struct pub_enet_ENetEvent_obj*)bbt_ev)));
with current BCC it creates
BBINT bbt_size=((BBINT)bmx_enet_packet_size(pub_enet_ENetEvent_packet));
leading to this error message:
pub.enet had for old and new this definition in its generated c file:
Now ... this might also be connected to this one:
Prior I called this stuff here:
The newer BCC correctly identifies
ev.event
missing brackets - so it compared the pointer to the methodev.event
here (I guess). Now with the brackets added (and the new BCC) , I receive the above error.