as_callfunc.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2011 Andreas Jonsson
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any
  6. damages arising from the use of this software.
  7. Permission is granted to anyone to use this software for any
  8. purpose, including commercial applications, and to alter it and
  9. redistribute it freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you
  11. must not claim that you wrote the original software. If you use
  12. this software in a product, an acknowledgment in the product
  13. documentation would be appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and
  15. must not be misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source
  17. distribution.
  18. The original version of this library can be located at:
  19. http://www.angelcode.com/angelscript/
  20. Andreas Jonsson
  21. [email protected]
  22. */
  23. //
  24. // as_callfunc.cpp
  25. //
  26. // These functions handle the actual calling of system functions
  27. //
  28. #include "as_config.h"
  29. #include "as_callfunc.h"
  30. #include "as_scriptengine.h"
  31. #include "as_texts.h"
  32. BEGIN_AS_NAMESPACE
  33. int DetectCallingConvention(bool isMethod, const asSFuncPtr &ptr, int callConv, asSSystemFunctionInterface *internal)
  34. {
  35. memset(internal, 0, sizeof(asSSystemFunctionInterface));
  36. internal->func = (size_t)ptr.ptr.f.func;
  37. // Was a compatible calling convention specified?
  38. if( internal->func )
  39. {
  40. if( ptr.flag == 1 && callConv != asCALL_GENERIC )
  41. return asWRONG_CALLING_CONV;
  42. else if( ptr.flag == 2 && (callConv == asCALL_GENERIC || callConv == asCALL_THISCALL) )
  43. return asWRONG_CALLING_CONV;
  44. else if( ptr.flag == 3 && callConv != asCALL_THISCALL )
  45. return asWRONG_CALLING_CONV;
  46. }
  47. asDWORD base = callConv;
  48. if( !isMethod )
  49. {
  50. if( base == asCALL_CDECL )
  51. internal->callConv = ICC_CDECL;
  52. else if( base == asCALL_STDCALL )
  53. internal->callConv = ICC_STDCALL;
  54. else if( base == asCALL_GENERIC )
  55. internal->callConv = ICC_GENERIC_FUNC;
  56. else
  57. return asNOT_SUPPORTED;
  58. }
  59. else
  60. {
  61. #ifndef AS_NO_CLASS_METHODS
  62. if( base == asCALL_THISCALL )
  63. {
  64. internal->callConv = ICC_THISCALL;
  65. #ifdef GNU_STYLE_VIRTUAL_METHOD
  66. if( (size_t(ptr.ptr.f.func) & 1) )
  67. internal->callConv = ICC_VIRTUAL_THISCALL;
  68. #endif
  69. internal->baseOffset = ( int )MULTI_BASE_OFFSET(ptr);
  70. #if defined(AS_ARM) && defined(__GNUC__)
  71. // As the least significant bit in func is used to switch to THUMB mode
  72. // on ARM processors, the LSB in the __delta variable is used instead of
  73. // the one in __pfn on ARM processors.
  74. if( (size_t(internal->baseOffset) & 1) )
  75. internal->callConv = ICC_VIRTUAL_THISCALL;
  76. #endif
  77. #ifdef HAVE_VIRTUAL_BASE_OFFSET
  78. // We don't support virtual inheritance
  79. if( VIRTUAL_BASE_OFFSET(ptr) != 0 )
  80. return asNOT_SUPPORTED;
  81. #endif
  82. }
  83. else
  84. #endif
  85. if( base == asCALL_CDECL_OBJLAST )
  86. internal->callConv = ICC_CDECL_OBJLAST;
  87. else if( base == asCALL_CDECL_OBJFIRST )
  88. internal->callConv = ICC_CDECL_OBJFIRST;
  89. else if( base == asCALL_GENERIC )
  90. internal->callConv = ICC_GENERIC_METHOD;
  91. else
  92. return asNOT_SUPPORTED;
  93. }
  94. return 0;
  95. }
  96. // This function should prepare system functions so that it will be faster to call them
  97. int PrepareSystemFunctionGeneric(asCScriptFunction *func, asSSystemFunctionInterface *internal, asCScriptEngine * /*engine*/)
  98. {
  99. asASSERT(internal->callConv == ICC_GENERIC_METHOD || internal->callConv == ICC_GENERIC_FUNC);
  100. // Calculate the size needed for the parameters
  101. internal->paramSize = func->GetSpaceNeededForArguments();
  102. return 0;
  103. }
  104. // This function should prepare system functions so that it will be faster to call them
  105. int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *internal, asCScriptEngine *engine)
  106. {
  107. #ifdef AS_MAX_PORTABILITY
  108. // This should never happen, as when AS_MAX_PORTABILITY is on, all functions
  109. // are asCALL_GENERIC, which are prepared by PrepareSystemFunctionGeneric
  110. asASSERT(false);
  111. #endif
  112. // References are always returned as primitive data
  113. if( func->returnType.IsReference() || func->returnType.IsObjectHandle() )
  114. {
  115. internal->hostReturnInMemory = false;
  116. internal->hostReturnSize = sizeof(void*)/4;
  117. internal->hostReturnFloat = false;
  118. }
  119. // Registered types have special flags that determine how they are returned
  120. else if( func->returnType.IsObject() )
  121. {
  122. asDWORD objType = func->returnType.GetObjectType()->flags;
  123. // Only value types can be returned by value
  124. asASSERT( objType & asOBJ_VALUE );
  125. if( !(objType & (asOBJ_APP_CLASS | asOBJ_APP_PRIMITIVE | asOBJ_APP_FLOAT)) )
  126. {
  127. // If the return is by value then we need to know the true type
  128. engine->WriteMessage("", 0, 0, asMSGTYPE_INFORMATION, func->GetDeclarationStr().AddressOf());
  129. asCString str;
  130. str.Format(TXT_CANNOT_RET_TYPE_s_BY_VAL, func->returnType.GetObjectType()->name.AddressOf());
  131. engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, str.AddressOf());
  132. engine->ConfigError(asINVALID_CONFIGURATION);
  133. }
  134. else if( objType & asOBJ_APP_CLASS )
  135. {
  136. internal->hostReturnFloat = false;
  137. if( objType & COMPLEX_RETURN_MASK )
  138. {
  139. internal->hostReturnInMemory = true;
  140. internal->hostReturnSize = sizeof(void*)/4;
  141. }
  142. else
  143. {
  144. #ifdef HAS_128_BIT_PRIMITIVES
  145. if( func->returnType.GetSizeInMemoryDWords() > 4 )
  146. #else
  147. if( func->returnType.GetSizeInMemoryDWords() > 2 )
  148. #endif
  149. {
  150. internal->hostReturnInMemory = true;
  151. internal->hostReturnSize = sizeof(void*)/4;
  152. }
  153. else
  154. {
  155. internal->hostReturnInMemory = false;
  156. internal->hostReturnSize = func->returnType.GetSizeInMemoryDWords();
  157. }
  158. #ifdef THISCALL_RETURN_SIMPLE_IN_MEMORY
  159. if((internal->callConv == ICC_THISCALL ||
  160. internal->callConv == ICC_VIRTUAL_THISCALL) &&
  161. func->returnType.GetSizeInMemoryDWords() >= THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE)
  162. {
  163. internal->hostReturnInMemory = true;
  164. internal->hostReturnSize = sizeof(void*)/4;
  165. }
  166. #endif
  167. #ifdef CDECL_RETURN_SIMPLE_IN_MEMORY
  168. if((internal->callConv == ICC_CDECL ||
  169. internal->callConv == ICC_CDECL_OBJLAST ||
  170. internal->callConv == ICC_CDECL_OBJFIRST) &&
  171. func->returnType.GetSizeInMemoryDWords() >= CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE)
  172. {
  173. internal->hostReturnInMemory = true;
  174. internal->hostReturnSize = sizeof(void*)/4;
  175. }
  176. #endif
  177. #ifdef STDCALL_RETURN_SIMPLE_IN_MEMORY
  178. if( internal->callConv == ICC_STDCALL &&
  179. func->returnType.GetSizeInMemoryDWords() >= STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE)
  180. {
  181. internal->hostReturnInMemory = true;
  182. internal->hostReturnSize = sizeof(void*)/4;
  183. }
  184. #endif
  185. }
  186. }
  187. else if( objType & asOBJ_APP_PRIMITIVE )
  188. {
  189. internal->hostReturnInMemory = false;
  190. internal->hostReturnSize = func->returnType.GetSizeInMemoryDWords();
  191. internal->hostReturnFloat = false;
  192. }
  193. else if( objType & asOBJ_APP_FLOAT )
  194. {
  195. internal->hostReturnInMemory = false;
  196. internal->hostReturnSize = func->returnType.GetSizeInMemoryDWords();
  197. internal->hostReturnFloat = true;
  198. }
  199. }
  200. // Primitive types can easily be determined
  201. #ifdef HAS_128_BIT_PRIMITIVES
  202. else if( func->returnType.GetSizeInMemoryDWords() > 4 )
  203. {
  204. // Shouldn't be possible to get here
  205. asASSERT(false);
  206. }
  207. else if( func->returnType.GetSizeInMemoryDWords() == 4 )
  208. {
  209. internal->hostReturnInMemory = false;
  210. internal->hostReturnSize = 4;
  211. internal->hostReturnFloat = false;
  212. }
  213. #else
  214. else if( func->returnType.GetSizeInMemoryDWords() > 2 )
  215. {
  216. // Shouldn't be possible to get here
  217. asASSERT(false);
  218. }
  219. #endif
  220. else if( func->returnType.GetSizeInMemoryDWords() == 2 )
  221. {
  222. internal->hostReturnInMemory = false;
  223. internal->hostReturnSize = 2;
  224. internal->hostReturnFloat = func->returnType.IsEqualExceptConst(asCDataType::CreatePrimitive(ttDouble, true));
  225. }
  226. else if( func->returnType.GetSizeInMemoryDWords() == 1 )
  227. {
  228. internal->hostReturnInMemory = false;
  229. internal->hostReturnSize = 1;
  230. internal->hostReturnFloat = func->returnType.IsEqualExceptConst(asCDataType::CreatePrimitive(ttFloat, true));
  231. }
  232. else
  233. {
  234. internal->hostReturnInMemory = false;
  235. internal->hostReturnSize = 0;
  236. internal->hostReturnFloat = false;
  237. }
  238. // Calculate the size needed for the parameters
  239. internal->paramSize = func->GetSpaceNeededForArguments();
  240. // Verify if the function takes any objects by value
  241. asUINT n;
  242. internal->takesObjByVal = false;
  243. for( n = 0; n < func->parameterTypes.GetLength(); n++ )
  244. {
  245. if( func->parameterTypes[n].IsObject() && !func->parameterTypes[n].IsObjectHandle() && !func->parameterTypes[n].IsReference() )
  246. {
  247. internal->takesObjByVal = true;
  248. // Can't pass objects by value unless the application type is informed
  249. if( !(func->parameterTypes[n].GetObjectType()->flags & (asOBJ_APP_CLASS | asOBJ_APP_PRIMITIVE | asOBJ_APP_FLOAT)) )
  250. {
  251. engine->WriteMessage("", 0, 0, asMSGTYPE_INFORMATION, func->GetDeclarationStr().AddressOf());
  252. asCString str;
  253. str.Format(TXT_CANNOT_PASS_TYPE_s_BY_VAL, func->parameterTypes[n].GetObjectType()->name.AddressOf());
  254. engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, str.AddressOf());
  255. engine->ConfigError(asINVALID_CONFIGURATION);
  256. }
  257. #ifdef SPLIT_OBJS_BY_MEMBER_TYPES
  258. // It's not safe to pass objects by value because different registers
  259. // will be used depending on the memory layout of the object
  260. #ifdef COMPLEX_OBJS_PASSED_BY_REF
  261. if( !(func->parameterTypes[n].GetObjectType()->flags & COMPLEX_MASK) )
  262. #endif
  263. {
  264. engine->WriteMessage("", 0, 0, asMSGTYPE_INFORMATION, func->GetDeclarationStr().AddressOf());
  265. asCString str;
  266. str.Format(TXT_DONT_SUPPORT_TYPE_s_BY_VAL, func->parameterTypes[n].GetObjectType()->name.AddressOf());
  267. engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, str.AddressOf());
  268. engine->ConfigError(asINVALID_CONFIGURATION);
  269. }
  270. #endif
  271. break;
  272. }
  273. }
  274. // Verify if the function has any registered autohandles
  275. internal->hasAutoHandles = false;
  276. for( n = 0; n < internal->paramAutoHandles.GetLength(); n++ )
  277. {
  278. if( internal->paramAutoHandles[n] )
  279. {
  280. internal->hasAutoHandles = true;
  281. break;
  282. }
  283. }
  284. return 0;
  285. }
  286. #ifdef AS_MAX_PORTABILITY
  287. int CallSystemFunction(int id, asCContext *context, void *objectPointer)
  288. {
  289. asCScriptEngine *engine = context->engine;
  290. asSSystemFunctionInterface *sysFunc = engine->scriptFunctions[id]->sysFuncIntf;
  291. int callConv = sysFunc->callConv;
  292. if( callConv == ICC_GENERIC_FUNC || callConv == ICC_GENERIC_METHOD )
  293. return context->CallGeneric(id, objectPointer);
  294. context->SetInternalException(TXT_INVALID_CALLING_CONVENTION);
  295. return 0;
  296. }
  297. #else
  298. //
  299. // CallSystemFunctionNative
  300. //
  301. // This function is implemented for each platform where the native calling conventions is supported.
  302. // See the various as_callfunc_xxx.cpp files for their implementation. It is responsible for preparing
  303. // the arguments for the function call, calling the function, and then retrieving the return value.
  304. //
  305. // Parameters:
  306. //
  307. // context - This is the context that can be used to retrieve specific information from the engine
  308. // descr - This is the script function object that holds the information on how to call the function
  309. // obj - This is the object pointer, if the call is for a class method, otherwise it is null
  310. // args - This is the function arguments, which are packed as in AngelScript
  311. // retPointer - This points to a the memory buffer where the return object is to be placed, if the function returns the value in memory rather than in registers
  312. // retQW2 - This output parameter should be used if the function returns a value larger than 64bits in registers
  313. //
  314. // Return value:
  315. //
  316. // The function should return the value that is returned in registers.
  317. //
  318. asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &retQW2);
  319. int CallSystemFunction(int id, asCContext *context, void *objectPointer)
  320. {
  321. asCScriptEngine *engine = context->engine;
  322. asCScriptFunction *descr = engine->scriptFunctions[id];
  323. asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf;
  324. int callConv = sysFunc->callConv;
  325. if( callConv == ICC_GENERIC_FUNC || callConv == ICC_GENERIC_METHOD )
  326. return context->CallGeneric(id, objectPointer);
  327. asQWORD retQW = 0;
  328. asQWORD retQW2 = 0;
  329. asDWORD *args = context->regs.stackPointer;
  330. void *retPointer = 0;
  331. void *obj = 0;
  332. int popSize = sysFunc->paramSize;
  333. context->regs.objectType = descr->returnType.GetObjectType();
  334. if( descr->returnType.IsObject() && !descr->returnType.IsReference() && !descr->returnType.IsObjectHandle() )
  335. {
  336. // Allocate the memory for the object
  337. retPointer = engine->CallAlloc(descr->returnType.GetObjectType());
  338. }
  339. if( callConv >= ICC_THISCALL )
  340. {
  341. if( objectPointer )
  342. {
  343. obj = objectPointer;
  344. }
  345. else
  346. {
  347. // The object pointer should be popped from the context stack
  348. popSize += AS_PTR_SIZE;
  349. // Check for null pointer
  350. obj = (void*)*(size_t*)(args);
  351. if( obj == 0 )
  352. {
  353. context->SetInternalException(TXT_NULL_POINTER_ACCESS);
  354. if( retPointer )
  355. engine->CallFree(retPointer);
  356. return 0;
  357. }
  358. // Add the base offset for multiple inheritance
  359. #if defined(__GNUC__) && defined(AS_ARM)
  360. // On GNUC + ARM the lsb of the offset is used to indicate a virtual function
  361. // and the whole offset is thus shifted one bit left to keep the original
  362. // offset resolution
  363. obj = (void*)(size_t(obj) + (sysFunc->baseOffset>>1));
  364. #else
  365. obj = (void*)(size_t(obj) + sysFunc->baseOffset);
  366. #endif
  367. // Skip the object pointer
  368. args += AS_PTR_SIZE;
  369. }
  370. }
  371. retQW = CallSystemFunctionNative(context, descr, obj, args, sysFunc->hostReturnInMemory ? retPointer : 0, retQW2);
  372. #if defined(COMPLEX_OBJS_PASSED_BY_REF) || defined(AS_LARGE_OBJS_PASSED_BY_REF)
  373. if( sysFunc->takesObjByVal )
  374. {
  375. // Need to free the complex objects passed by value, but that the
  376. // calling convention implicitly passes by reference behind the scene
  377. args = context->regs.stackPointer;
  378. if( callConv >= ICC_THISCALL && !objectPointer )
  379. args += AS_PTR_SIZE;
  380. int spos = 0;
  381. for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ )
  382. {
  383. if( descr->parameterTypes[n].IsObject() &&
  384. !descr->parameterTypes[n].IsObjectHandle() &&
  385. !descr->parameterTypes[n].IsReference() && (
  386. #ifdef COMPLEX_OBJS_PASSED_BY_REF
  387. (descr->parameterTypes[n].GetObjectType()->flags & COMPLEX_MASK) ||
  388. #endif
  389. #ifdef AS_LARGE_OBJS_PASSED_BY_REF
  390. (descr->parameterTypes[n].GetSizeInMemoryDWords() >= AS_LARGE_OBJ_MIN_SIZE) ||
  391. #endif
  392. 0) )
  393. {
  394. void *obj = (void*)*(size_t*)&args[spos];
  395. spos += AS_PTR_SIZE;
  396. #ifndef AS_CALLEE_DESTROY_OBJ_BY_VAL
  397. // If the called function doesn't destroy objects passed by value we must do so here
  398. asSTypeBehaviour *beh = &descr->parameterTypes[n].GetObjectType()->beh;
  399. if( beh->destruct )
  400. engine->CallObjectMethod(obj, beh->destruct);
  401. #endif
  402. engine->CallFree(obj);
  403. }
  404. else
  405. spos += descr->parameterTypes[n].GetSizeOnStackDWords();
  406. }
  407. }
  408. #endif
  409. // Store the returned value in our stack
  410. if( descr->returnType.IsObject() && !descr->returnType.IsReference() )
  411. {
  412. if( descr->returnType.IsObjectHandle() )
  413. {
  414. #if defined(AS_BIG_ENDIAN) && AS_PTR_SIZE == 1
  415. // Since we're treating the system function as if it is returning a QWORD we are
  416. // actually receiving the value in the high DWORD of retQW.
  417. retQW >>= 32;
  418. #endif
  419. context->regs.objectRegister = (void*)(size_t)retQW;
  420. if( sysFunc->returnAutoHandle && context->regs.objectRegister )
  421. engine->CallObjectMethod(context->regs.objectRegister, descr->returnType.GetObjectType()->beh.addref);
  422. }
  423. else
  424. {
  425. if( !sysFunc->hostReturnInMemory )
  426. {
  427. // Copy the returned value to the pointer sent by the script engine
  428. if( sysFunc->hostReturnSize == 1 )
  429. {
  430. #if defined(AS_BIG_ENDIAN) && AS_PTR_SIZE == 1
  431. // Since we're treating the system function as if it is returning a QWORD we are
  432. // actually receiving the value in the high DWORD of retQW.
  433. retQW >>= 32;
  434. #endif
  435. *(asDWORD*)retPointer = (asDWORD)retQW;
  436. }
  437. else if( sysFunc->hostReturnSize == 2 )
  438. *(asQWORD*)retPointer = retQW;
  439. else if( sysFunc->hostReturnSize == 3 )
  440. {
  441. *(asQWORD*)retPointer = retQW;
  442. *(((asDWORD*)retPointer) + 2) = (asDWORD)retQW2;
  443. }
  444. else // if( sysFunc->hostReturnSize == 4 )
  445. {
  446. *(asQWORD*)retPointer = retQW;
  447. *(((asQWORD*)retPointer) + 1) = retQW2;
  448. }
  449. }
  450. // Store the object in the register
  451. context->regs.objectRegister = retPointer;
  452. }
  453. }
  454. else
  455. {
  456. // Store value in value register
  457. if( sysFunc->hostReturnSize == 1 )
  458. {
  459. #if defined(AS_BIG_ENDIAN)
  460. // Since we're treating the system function as if it is returning a QWORD we are
  461. // actually receiving the value in the high DWORD of retQW.
  462. retQW >>= 32;
  463. // Due to endian issues we need to handle return values that are
  464. // less than a DWORD (32 bits) in size specially
  465. int numBytes = descr->returnType.GetSizeInMemoryBytes();
  466. if( descr->returnType.IsReference() ) numBytes = 4;
  467. switch( numBytes )
  468. {
  469. case 1:
  470. {
  471. // 8 bits
  472. asBYTE *val = (asBYTE*)&context->regs.valueRegister;
  473. val[0] = (asBYTE)retQW;
  474. val[1] = 0;
  475. val[2] = 0;
  476. val[3] = 0;
  477. val[4] = 0;
  478. val[5] = 0;
  479. val[6] = 0;
  480. val[7] = 0;
  481. }
  482. break;
  483. case 2:
  484. {
  485. // 16 bits
  486. asWORD *val = (asWORD*)&context->regs.valueRegister;
  487. val[0] = (asWORD)retQW;
  488. val[1] = 0;
  489. val[2] = 0;
  490. val[3] = 0;
  491. }
  492. break;
  493. default:
  494. {
  495. // 32 bits
  496. asDWORD *val = (asDWORD*)&context->regs.valueRegister;
  497. val[0] = (asDWORD)retQW;
  498. val[1] = 0;
  499. }
  500. break;
  501. }
  502. #else
  503. *(asDWORD*)&context->regs.valueRegister = (asDWORD)retQW;
  504. #endif
  505. }
  506. else
  507. context->regs.valueRegister = retQW;
  508. }
  509. // Release autohandles in the arguments
  510. if( sysFunc->hasAutoHandles )
  511. {
  512. args = context->regs.stackPointer;
  513. if( callConv >= ICC_THISCALL && !objectPointer )
  514. args += AS_PTR_SIZE;
  515. int spos = 0;
  516. for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ )
  517. {
  518. if( sysFunc->paramAutoHandles[n] && *(size_t*)&args[spos] != 0 )
  519. {
  520. // Call the release method on the type
  521. engine->CallObjectMethod((void*)*(size_t*)&args[spos], descr->parameterTypes[n].GetObjectType()->beh.release);
  522. *(size_t*)&args[spos] = 0;
  523. }
  524. if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() )
  525. spos += AS_PTR_SIZE;
  526. else
  527. spos += descr->parameterTypes[n].GetSizeOnStackDWords();
  528. }
  529. }
  530. return popSize;
  531. }
  532. #endif // AS_MAX_PORTABILITY
  533. END_AS_NAMESPACE