From 4eaec951b6f675d77115f2f39b22dbf39575089d Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Tue, 29 Apr 2014 16:04:08 +0800 Subject: [PATCH 1/2] use `new` and `CC_SAFE_DELETE_ARRAY` to replace `malloc` and `free` --- .../manual/LuaBasicConversions.cpp | 6 +- .../manual/LuaOpengl.cpp.REMOVED.git-id | 2 +- .../lua_cocos2dx_manual.cpp.REMOVED.git-id | 2 +- .../manual/lua_cocos2dx_physics_manual.cpp | 96 +++++++++---------- 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp b/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp index dcb8a04dd3..1fd9c5c9d0 100644 --- a/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp +++ b/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp @@ -1081,7 +1081,7 @@ bool luaval_to_array_of_vector2(lua_State* L,int lo,cocos2d::Vector2 **points, i size_t len = lua_objlen(L, lo); if (len > 0) { - cocos2d::Vector2* array = (cocos2d::Vector2*)malloc(sizeof(cocos2d::Vector2) * len); + cocos2d::Vector2* array = (cocos2d::Vector2*) new Vector2[len]; if (NULL == array) return false; for (uint32_t i = 0; i < len; ++i) @@ -1094,14 +1094,14 @@ bool luaval_to_array_of_vector2(lua_State* L,int lo,cocos2d::Vector2 **points, i luaval_to_native_err(L,"#ferror:",&tolua_err); #endif lua_pop(L, 1); - free(array); + CC_SAFE_DELETE_ARRAY(array); return false; } ok &= luaval_to_vector2(L, lua_gettop(L), &array[i]); if (!ok) { lua_pop(L, 1); - free(array); + CC_SAFE_DELETE_ARRAY(array); return false; } lua_pop(L, 1); diff --git a/cocos/scripting/lua-bindings/manual/LuaOpengl.cpp.REMOVED.git-id b/cocos/scripting/lua-bindings/manual/LuaOpengl.cpp.REMOVED.git-id index 640433292b..d0b4876d4b 100644 --- a/cocos/scripting/lua-bindings/manual/LuaOpengl.cpp.REMOVED.git-id +++ b/cocos/scripting/lua-bindings/manual/LuaOpengl.cpp.REMOVED.git-id @@ -1 +1 @@ -8691f7305315a37ee7e7563c19d10ea5eacf15c0 \ No newline at end of file +f617e93e41d49e952e2912fca33313de2a09fd6c \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_manual.cpp.REMOVED.git-id b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_manual.cpp.REMOVED.git-id index 30c83f89ea..c810aaaa46 100644 --- a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_manual.cpp.REMOVED.git-id +++ b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_manual.cpp.REMOVED.git-id @@ -1 +1 @@ -d69918a19fbb23604827b6a99526d3231f6a3497 \ No newline at end of file +6ebba4e8a7f785f4996aa037ff2a26f65380f9ae \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_physics_manual.cpp b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_physics_manual.cpp index 6dda66b62b..882cc70ea6 100644 --- a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_physics_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_physics_manual.cpp @@ -334,11 +334,11 @@ int lua_cocos2dx_physics_PhysicsBody_createPolygon(lua_State* tolua_S) }} while (0); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createPolygon(arg0, arg1); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); do { if (nullptr != ret) { @@ -366,11 +366,11 @@ int lua_cocos2dx_physics_PhysicsBody_createPolygon(lua_State* tolua_S) ok &= luaval_to_physics_material(tolua_S, 3, &arg2); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createPolygon(arg0, arg1, arg2); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); do { if (nullptr != ret) @@ -401,11 +401,11 @@ int lua_cocos2dx_physics_PhysicsBody_createPolygon(lua_State* tolua_S) ok &= luaval_to_vector2(tolua_S, 4, &arg3); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createPolygon(arg0, arg1, arg2, arg3); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); do { if (nullptr != ret) { @@ -455,11 +455,11 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgePolygon(lua_State* tolua_S) }} while (0); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createEdgePolygon(arg0, arg1); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); do { if (nullptr != ret) { @@ -487,11 +487,11 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgePolygon(lua_State* tolua_S) ok &= luaval_to_physics_material(tolua_S, 3, &arg2); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createEdgePolygon(arg0, arg1, arg2); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); do { if (nullptr != ret) { @@ -521,11 +521,11 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgePolygon(lua_State* tolua_S) ok &= luaval_to_number(tolua_S, 4,&arg3); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createEdgePolygon(arg0, arg1, arg2, arg3); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); do { if (nullptr != ret) { @@ -575,11 +575,11 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgeChain(lua_State* tolua_S) }} while (0); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createEdgeChain(arg0, arg1); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); do { if (nullptr != ret) { @@ -607,11 +607,11 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgeChain(lua_State* tolua_S) ok &= luaval_to_physics_material(tolua_S, 3, &arg2); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createEdgeChain(arg0, arg1, arg2); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); do { if (nullptr != ret) { @@ -641,11 +641,11 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgeChain(lua_State* tolua_S) ok &= luaval_to_number(tolua_S, 4,&arg3); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createEdgeChain(arg0, arg1, arg2, arg3); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); do { if (nullptr != ret) { @@ -695,12 +695,12 @@ int lua_cocos2dx_physics_PhysicsShape_recenterPoints(lua_State* tolua_S) }} while (0); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsShape::recenterPoints(arg0, arg1); vector2_array_to_luaval(tolua_S, arg0, arg1); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } @@ -717,12 +717,12 @@ int lua_cocos2dx_physics_PhysicsShape_recenterPoints(lua_State* tolua_S) ok &= luaval_to_vector2(tolua_S, 3, &arg2); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsShape::recenterPoints(arg0, arg1, arg2); vector2_array_to_luaval(tolua_S, arg0, arg1); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "recenterPoints",argc, 2); @@ -760,11 +760,11 @@ int lua_cocos2dx_physics_PhysicsShape_getPolyonCenter(lua_State* tolua_S) }} while (0); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::Vector2 ret = cocos2d::PhysicsShape::getPolyonCenter(arg0, arg1); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); vector2_to_luaval(tolua_S, ret); return 1; } @@ -890,11 +890,11 @@ int lua_cocos2dx_physics_PhysicsShapePolygon_create(lua_State* tolua_S) if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsShapePolygon* ret = cocos2d::PhysicsShapePolygon::create(arg0, arg1); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); object_to_luaval(tolua_S, "cc.PhysicsShapePolygon",(cocos2d::PhysicsShapePolygon*)ret); return 1; } @@ -911,11 +911,11 @@ int lua_cocos2dx_physics_PhysicsShapePolygon_create(lua_State* tolua_S) ok &= luaval_to_physics_material(tolua_S, 3, &arg2); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsShapePolygon* ret = cocos2d::PhysicsShapePolygon::create(arg0, arg1, arg2); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); object_to_luaval(tolua_S, "cc.PhysicsShapePolygon",(cocos2d::PhysicsShapePolygon*)ret); return 1; } @@ -934,11 +934,11 @@ int lua_cocos2dx_physics_PhysicsShapePolygon_create(lua_State* tolua_S) ok &= luaval_to_vector2(tolua_S, 4, &arg3); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsShapePolygon* ret = cocos2d::PhysicsShapePolygon::create(arg0, arg1, arg2, arg3); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); object_to_luaval(tolua_S, "cc.PhysicsShapePolygon",(cocos2d::PhysicsShapePolygon*)ret); return 1; } @@ -976,11 +976,11 @@ int lua_cocos2dx_physics_PhysicsShapePolygon_calculateArea(lua_State* tolua_S) }} while (0); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } double ret = cocos2d::PhysicsShapePolygon::calculateArea(arg0, arg1); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } @@ -1020,11 +1020,11 @@ int lua_cocos2dx_physics_PhysicsShapePolygon_calculateMoment(lua_State* tolua_S) }} while (0); if(!ok) { - CC_SAFE_FREE(arg1); + CC_SAFE_DELETE_ARRAY(arg1); return 0; } double ret = cocos2d::PhysicsShapePolygon::calculateMoment(arg0, arg1, arg2); - CC_SAFE_FREE(arg1); + CC_SAFE_DELETE_ARRAY(arg1); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } @@ -1043,11 +1043,11 @@ int lua_cocos2dx_physics_PhysicsShapePolygon_calculateMoment(lua_State* tolua_S) ok &= luaval_to_vector2(tolua_S, 4, &arg3); if(!ok) { - CC_SAFE_FREE(arg1); + CC_SAFE_DELETE_ARRAY(arg1); return 0; } double ret = cocos2d::PhysicsShapePolygon::calculateMoment(arg0, arg1, arg2, arg3); - CC_SAFE_FREE(arg1); + CC_SAFE_DELETE_ARRAY(arg1); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } @@ -1322,11 +1322,11 @@ int lua_cocos2dx_physics_PhysicsShapeEdgePolygon_create(lua_State* tolua_S) }} while (0); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsShapeEdgePolygon* ret = cocos2d::PhysicsShapeEdgePolygon::create(arg0, arg1); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); object_to_luaval(tolua_S, "cc.PhysicsShapeEdgePolygon",(cocos2d::PhysicsShapeEdgePolygon*)ret); return 1; } @@ -1343,11 +1343,11 @@ int lua_cocos2dx_physics_PhysicsShapeEdgePolygon_create(lua_State* tolua_S) ok &= luaval_to_physics_material(tolua_S, 3, &arg2); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsShapeEdgePolygon* ret = cocos2d::PhysicsShapeEdgePolygon::create(arg0, arg1, arg2); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); object_to_luaval(tolua_S, "cc.PhysicsShapeEdgePolygon",(cocos2d::PhysicsShapeEdgePolygon*)ret); return 1; } @@ -1366,11 +1366,11 @@ int lua_cocos2dx_physics_PhysicsShapeEdgePolygon_create(lua_State* tolua_S) ok &= luaval_to_number(tolua_S, 4,&arg3); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsShapeEdgePolygon* ret = cocos2d::PhysicsShapeEdgePolygon::create(arg0, arg1, arg2, arg3); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); object_to_luaval(tolua_S, "cc.PhysicsShapeEdgePolygon",(cocos2d::PhysicsShapeEdgePolygon*)ret); return 1; } @@ -1409,11 +1409,11 @@ int lua_cocos2dx_physics_PhysicsShapeEdgeChain_create(lua_State* tolua_S) }} while (0); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsShapeEdgeChain* ret = cocos2d::PhysicsShapeEdgeChain::create(arg0, arg1); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); object_to_luaval(tolua_S, "cc.PhysicsShapeEdgeChain",(cocos2d::PhysicsShapeEdgeChain*)ret); return 1; } @@ -1430,11 +1430,11 @@ int lua_cocos2dx_physics_PhysicsShapeEdgeChain_create(lua_State* tolua_S) ok &= luaval_to_physics_material(tolua_S, 3, &arg2); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsShapeEdgeChain* ret = cocos2d::PhysicsShapeEdgeChain::create(arg0, arg1, arg2); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); object_to_luaval(tolua_S, "cc.PhysicsShapeEdgeChain",(cocos2d::PhysicsShapeEdgeChain*)ret); return 1; } @@ -1453,11 +1453,11 @@ int lua_cocos2dx_physics_PhysicsShapeEdgeChain_create(lua_State* tolua_S) ok &= luaval_to_number(tolua_S, 4,&arg3); if(!ok) { - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); return 0; } cocos2d::PhysicsShapeEdgeChain* ret = cocos2d::PhysicsShapeEdgeChain::create(arg0, arg1, arg2, arg3); - CC_SAFE_FREE(arg0); + CC_SAFE_DELETE_ARRAY(arg0); object_to_luaval(tolua_S, "cc.PhysicsShapeEdgeChain",(cocos2d::PhysicsShapeEdgeChain*)ret); return 1; } From 58a9e40b825ed61d1827b16a38ab86ee1c989574 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Tue, 29 Apr 2014 17:17:18 +0800 Subject: [PATCH 2/2] Modify some functions return value from `bool` to `int` --- .../lua-bindings/manual/lua_cocos2dx_manual.cpp.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_manual.cpp.REMOVED.git-id b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_manual.cpp.REMOVED.git-id index c810aaaa46..533e0cc0e4 100644 --- a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_manual.cpp.REMOVED.git-id +++ b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_manual.cpp.REMOVED.git-id @@ -1 +1 @@ -6ebba4e8a7f785f4996aa037ff2a26f65380f9ae \ No newline at end of file +b46d2c5875cdbcbe419922d69d7f7c6a49bd1630 \ No newline at end of file