Projects
Essentials
lightspark
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 107
View file
lightspark.spec
Changed
@@ -20,15 +20,13 @@ %bcond_without librtmp Name: lightspark -Version: 0.7.2.99+git20160424.1301 +Version: 0.7.2.99+git20160529.1025 Release: 0 Summary: Modern, free, open-source flash player implementation License: LGPL-3.0+ Group: Productivity/Multimedia/Other Url: https://launchpad.net/lightspark/ Source0: lightspark.tar.xz -Patch: 0001-s-PIX_FMT_YUV420P-AV_PIX_FMT_YUV420P-compatibility.patch -Patch2: 0002-Fix-build-with-newer-LLVM.patch BuildRequires: boost-devel BuildRequires: cmake BuildRequires: desktop-file-utils @@ -87,8 +85,6 @@ %prep %setup -q -n %{name} -%patch -p1 -%patch2 -p1 %build export CFLAGS='%{optflags}'
View file
0001-s-PIX_FMT_YUV420P-AV_PIX_FMT_YUV420P-compatibility.patch
Deleted
@@ -1,45 +0,0 @@ -From 4b64069813a87df922235582eb71ea82ca6afd9e Mon Sep 17 00:00:00 2001 -From: Johannes Obermayr <johannesobermayr@gmx.de> -Date: Mon, 21 Mar 2016 22:34:36 +0100 -Subject: [PATCH 1/2] s/PIX_FMT_YUV420P/AV_PIX_FMT_YUV420P + compatibility. - ---- - src/backends/decoder.cpp | 8 ++++++-- - 1 file changed, 6 insertions(+), 2 deletions(-) - -diff --git a/src/backends/decoder.cpp b/src/backends/decoder.cpp -index 3f84fd8..10aafdc 100755 ---- a/src/backends/decoder.cpp -+++ b/src/backends/decoder.cpp -@@ -39,6 +39,10 @@ - #define av_frame_unref avcodec_get_frame_defaults - #endif - -+#if !defined(AV_PIX_FMT_YUV420P) && defined(PIX_FMT_YUV420P) -+#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P -+#endif -+ - using namespace lightspark; - using namespace std; - -@@ -293,7 +297,7 @@ bool FFMpegVideoDecoder::decodeData(uint8_t* data, uint32_t datalen, uint32_t ti - } - if(frameOk) - { -- assert(codecContext->pix_fmt==PIX_FMT_YUV420P); -+ assert(codecContext->pix_fmt==AV_PIX_FMT_YUV420P); - - if(status==INIT && fillDataAndCheckValidity()) - status=VALID; -@@ -323,7 +327,7 @@ bool FFMpegVideoDecoder::decodePacket(AVPacket* pkt, uint32_t time) - assert_and_throw(ret==(int)pkt->size); - if(frameOk) - { -- assert(codecContext->pix_fmt==PIX_FMT_YUV420P); -+ assert(codecContext->pix_fmt==AV_PIX_FMT_YUV420P); - - if(status==INIT && fillDataAndCheckValidity()) - status=VALID; --- -2.8.1 -
View file
0002-Fix-build-with-newer-LLVM.patch
Deleted
@@ -1,66 +0,0 @@ -From 43638ba6183f984c200e207565bd10a5ab15bd53 Mon Sep 17 00:00:00 2001 -From: Johannes Obermayr <johannesobermayr@gmx.de> -Date: Mon, 11 Apr 2016 13:58:43 +0200 -Subject: [PATCH 2/2] Fix build with newer LLVM. - ---- - CMakeLists.txt | 11 +++++++++++ - src/scripting/abc_codesynt.cpp | 7 +++++-- - 2 files changed, 16 insertions(+), 2 deletions(-) - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 0b9790d..93c0829 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -250,6 +250,17 @@ ENDIF(NOT (${LLVM_STRING_VERSION} VERSION_LESS 3.6)) - IF(NOT ${LLVM_STRING_VERSION} VERSION_LESS 3.7) - ADD_DEFINITIONS(-DLLVM_37) - ENDIF(NOT ${LLVM_STRING_VERSION} VERSION_LESS 3.7) -+ -+INCLUDE(CheckCXXSourceCompiles) -+SET(CMAKE_REQUIRED_FLAGS "-std=c++11 -DNDEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS") -+SET(CMAKE_REQUIRED_INCLUDES ${LLVM_INCLUDE_DIR}) -+CHECK_CXX_SOURCE_COMPILES("#include <llvm/ExecutionEngine/ExecutionEngine.h>\nint main() { llvm::ExecutionEngine* ex; return ex->getDataLayout().isLittleEndian(); }" EXECUTIONENGINE_OWNING_DATALAYOUT) -+IF(EXECUTIONENGINE_OWNING_DATALAYOUT) -+ ADD_DEFINITIONS(-DEXECUTIONENGINE_OWNING_DATALAYOUT) -+ENDIF(EXECUTIONENGINE_OWNING_DATALAYOUT) -+SET(CMAKE_REQUIRED_FLAGS) -+SET(CMAKE_REQUIRED_INCLUDES) -+ - INCLUDE(FindZLIB REQUIRED) - INCLUDE(FindFreetype REQUIRED) - IF(NOT(ENABLE_GLES2)) -diff --git a/src/scripting/abc_codesynt.cpp b/src/scripting/abc_codesynt.cpp -index 42a0f9c..d0c8c13 100644 ---- a/src/scripting/abc_codesynt.cpp -+++ b/src/scripting/abc_codesynt.cpp -@@ -294,11 +294,15 @@ void ABCVm::registerFunctions() - llvm::FunctionType* FT=NULL; - - //Create types -+#if EXECUTIONENGINE_OWNING_DATALAYOUT -+ ptr_type=ex->getDataLayout().getIntPtrType(llvm_context()); -+#else - #if defined HAVE_DATALAYOUT_H || defined HAVE_IR_DATALAYOUT_H - ptr_type=ex->getDataLayout()->getIntPtrType(llvm_context()); - #else - ptr_type=ex->getTargetData()->getIntPtrType(llvm_context()); - #endif -+#endif - //Pointer to 8 bit type, needed for pointer arithmetic - voidptr_type=llvm::IntegerType::get(llvm_context(),8)->getPointerTo(); - number_type=llvm::Type::getDoubleTy(llvm_context()); -@@ -1883,9 +1887,8 @@ SyntheticFunction::synt_function method_info::synt_method(SystemState* sys) - constant = llvm::ConstantInt::get(ptr_type, (uintptr_t)this); - llvm::Value* th = llvm::ConstantExpr::getIntToPtr(constant, voidptr_type); - -- llvm::Function::ArgumentListType::iterator it=llvmf->getArgumentList().begin(); - //The first and only argument to this function is the call_context* -- llvm::Value* context=it; -+ llvm::Value* context = llvmf->getArgumentList().begin(); - - //let's give access to local data storage - value=Builder.CreateStructGEP( --- -2.8.1 -
View file
lightspark.tar.xz/CMakeLists.txt
Changed
@@ -205,6 +205,8 @@ SET(ENABLE_PROFILING FALSE CACHE BOOL "Enable profiling support? (Causes performance issues)") SET(ENABLE_MEMORY_USAGE_PROFILING FALSE CACHE BOOL "Enable profiling of memory usage? (Causes performance issues)") SET(PLUGIN_DIRECTORY "${LIBDIR}/mozilla/plugins" CACHE STRING "Directory to install Firefox plugin to") +SET(MANUAL_DIRECTORY "share/man" CACHE STRING "Directory to install manual to (UNIX only)") +SET(ENABLE_SSE2 TRUE CACHE BOOL "Enable use of SSE2 asm instructions (x86/x86_64 only)") IF(ENABLE_DEBIAN_ALTERNATIVES OR WIN32) SET(PLUGIN_DIRECTORY ${PRIVATELIBDIR}) @@ -250,6 +252,9 @@ IF(NOT ${LLVM_STRING_VERSION} VERSION_LESS 3.7) ADD_DEFINITIONS(-DLLVM_37) ENDIF(NOT ${LLVM_STRING_VERSION} VERSION_LESS 3.7) +IF(NOT ${LLVM_STRING_VERSION} VERSION_LESS 3.8) + ADD_DEFINITIONS(-DLLVM_38) +ENDIF(NOT ${LLVM_STRING_VERSION} VERSION_LESS 3.8) INCLUDE(FindZLIB REQUIRED) INCLUDE(FindFreetype REQUIRED) IF(NOT(ENABLE_GLES2)) @@ -317,6 +322,8 @@ CHECK_FUNCTION_EXISTS(avformat_find_stream_info HAVE_AVFORMAT_FIND_STREAM_INFO) CHECK_FUNCTION_EXISTS(av_frame_alloc HAVE_AV_FRAME_ALLOC) CHECK_FUNCTION_EXISTS(av_frame_unref HAVE_AV_FRAME_UNREF) + CHECK_FUNCTION_EXISTS(av_packet_unref HAVE_AV_PACKET_UNREF) + CHECK_C_SOURCE_COMPILES("#include <libavcodec/avcodec.h>\nint main() { enum AVCodecID c; return 0; }" HAVE_AVCODECID) SET(CMAKE_REQUIRED_FLAGS) @@ -358,6 +365,9 @@ IF(HAVE_AV_FRAME_UNREF) ADD_DEFINITIONS(-DHAVE_AV_FRAME_UNREF) ENDIF(HAVE_AV_FRAME_UNREF) + IF(HAVE_AV_PACKET_UNREF) + ADD_DEFINITIONS(-DHAVE_AV_PACKET_UNREF) + ENDIF(HAVE_AV_PACKET_UNREF) ADD_DEFINITIONS(-DENABLE_LIBAVCODEC) ENDIF(ENABLE_LIBAVCODEC)
View file
lightspark.tar.xz/ChangeLog
Changed
@@ -10,7 +10,7 @@ * fix serialization * implement data generation mode * support for avmplus classes (mostly stubs) - * Support LLVM up to version 3.6 + * Support LLVM up to version 3.8 * fix event dispatcher handling * several fixes for object initialization * partially implement AMF0 decoding
View file
lightspark.tar.xz/conf/FindLLVM.cmake
Changed
@@ -205,7 +205,11 @@ if(LLVM_SYSTEM_LIBS_FAILED) SET(LLVM_SYSTEM_LIBS "") endif(LLVM_SYSTEM_LIBS_FAILED) - FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "core ipa ipo instrumentation bitreader bitwriter linker" LLVM_LIBS_CORE_ONLY LLVM_LIBS_CORE_OBJECTS ) + IF(${LLVM_STRING_VERSION} VERSION_GREATER 3.7) + FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "core ipo instrumentation bitreader bitwriter linker" LLVM_LIBS_CORE_ONLY LLVM_LIBS_CORE_OBJECTS ) + ELSE(${LLVM_STRING_VERSION} VERSION_GREATER 3.7) + FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "core ipa ipo instrumentation bitreader bitwriter linker" LLVM_LIBS_CORE_ONLY LLVM_LIBS_CORE_OBJECTS ) + ENDIF(${LLVM_STRING_VERSION} VERSION_GREATER 3.7) SET(LLVM_LIBS_CORE ${LLVM_LIBS_CORE_ONLY} ${LLVM_SYSTEM_LIBS}) UNSET(LLVM_LIBS_CORE_ONLY) UNSET(LLVM_SYSTEM_LIBS_FAILED)
View file
lightspark.tar.xz/src/CMakeLists.txt
Changed
@@ -142,15 +142,19 @@ ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") SET(LIBSPARK_SOURCES ${LIBSPARK_SOURCES} platforms/slowpaths_generic.cpp) ELSE() - IF(${i386}) - SET(LIBSPARK_SOURCES ${LIBSPARK_SOURCES} platforms/fastpaths_x86.cpp) - SET(LIBSPARK_SOURCES ${LIBSPARK_SOURCES} platforms/fastpaths_i686.asm) - ELSEIF(${x86_64}) - SET(LIBSPARK_SOURCES ${LIBSPARK_SOURCES} platforms/fastpaths_x86.cpp) - SET(LIBSPARK_SOURCES ${LIBSPARK_SOURCES} platforms/fastpaths_amd64.asm) - ELSE() + IF(ENABLE_SSE2) + IF(${i386}) + SET(LIBSPARK_SOURCES ${LIBSPARK_SOURCES} platforms/fastpaths_x86.cpp) + SET(LIBSPARK_SOURCES ${LIBSPARK_SOURCES} platforms/fastpaths_i686.asm) + ELSEIF(${x86_64}) + SET(LIBSPARK_SOURCES ${LIBSPARK_SOURCES} platforms/fastpaths_x86.cpp) + SET(LIBSPARK_SOURCES ${LIBSPARK_SOURCES} platforms/fastpaths_amd64.asm) + ELSE() + SET(LIBSPARK_SOURCES ${LIBSPARK_SOURCES} platforms/slowpaths_generic.cpp) + ENDIF(${i386}) + ELSE(ENABLE_SSE2) SET(LIBSPARK_SOURCES ${LIBSPARK_SOURCES} platforms/slowpaths_generic.cpp) - ENDIF(${i386}) + ENDIF(ENABLE_SSE2) ENDIF(MINGW) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src) @@ -211,7 +215,7 @@ INSTALL(FILES ${PROJECT_SOURCE_DIR}/src/lightspark.vert DESTINATION ${LSDATADIR}) INSTALL(TARGETS lightspark RUNTIME DESTINATION ${BINDIR}) IF(UNIX) - INSTALL(FILES ${PROJECT_SOURCE_DIR}/docs/man/lightspark.1 DESTINATION share/man/man1) + INSTALL(FILES ${PROJECT_SOURCE_DIR}/docs/man/lightspark.1 DESTINATION ${MANUAL_DIRECTORY}/man1/) ENDIF(UNIX) ENDIF(COMPILE_LIGHTSPARK)
View file
lightspark.tar.xz/src/asobject.cpp
Changed
@@ -1090,11 +1090,6 @@ { Variables.initSlot(n,name.name_s_id,name.ns[0]); } -void ASObject::appendSlot(const multiname& name) -{ - Variables.appendSlot(name.name_s_id,name.ns[0]); -} - int32_t ASObject::getVariableByMultiname_i(const multiname& name) { check(); @@ -1394,10 +1389,10 @@ } } -void ASObject::destruct() +bool ASObject::destruct() { - finalize(); - Variables.destroyContents(); + if (Variables.size()) + Variables.destroyContents(); if (proxyMultiName) delete proxyMultiName; proxyMultiName = NULL; @@ -1409,14 +1404,16 @@ //Stuff only used in debugging initialized=false; #endif + bool dodestruct = true; if (classdef && classdef->isReusable) { - classdef->pushObjectToFreeList(this); + dodestruct = !classdef->pushObjectToFreeList(this); } - else + if (dodestruct) { - RefCountable::destruct(); + finalize(); } + return dodestruct; } void variables_map::initSlot(unsigned int n, uint32_t nameId, const nsNameAndKind& ns)
View file
lightspark.tar.xz/src/asobject.h
Changed
@@ -308,11 +308,7 @@ */ void setSlotNoCoerce(unsigned int n,ASObject* o); void initSlot(unsigned int n, uint32_t nameId, const nsNameAndKind& ns); - void appendSlot(uint32_t nameId, const nsNameAndKind& ns) - { - initSlot(slots_vars.size()+1, nameId, ns); - } - int size() const + inline unsigned int size() const { return Variables.size(); } @@ -399,8 +395,16 @@ return ret; } - //overridden from RefCountable - void destruct(); + /* + overridden from RefCountable + The destruct function is called when the reference count reaches 0 and the object is added to the free list of the class. + It should be implemented in all derived classes. + It should decRef all referenced objects. + It has to reset all data to their default state. + It has to call ASObject::destruct() as last instruction + The destruct method must be callable multiple time with the same effects (no double frees). + */ + bool destruct(); // called when object is really destroyed virtual void destroy(); public: @@ -438,8 +442,8 @@ o->decRef(); } /* - The finalize function is called when the reference count reaches 0 and the objects is added to the free list of the class. - It should be implemented in all derived class. + The finalize function is used only for classes that don't have the reusable flag set + if a class is made reusable, it should implement destruct() instead It should decRef all referenced objects. It has to reset all data to their default state. The finalize method must be callable multiple time with the same effects (no double frees). @@ -518,7 +522,6 @@ Variables.setSlotNoCoerce(n,o); } void initSlot(unsigned int n, const multiname& name); - void appendSlot(const multiname& name); unsigned int numVariables() const; inline tiny_string getNameAt(int i) const {
View file
lightspark.tar.xz/src/backends/decoder.cpp
Changed
@@ -293,7 +293,7 @@ } if(frameOk) { - assert(codecContext->pix_fmt==PIX_FMT_YUV420P); + //assert(codecContext->pix_fmt==PIX_FMT_YUV420P); if(status==INIT && fillDataAndCheckValidity()) status=VALID; @@ -323,7 +323,7 @@ assert_and_throw(ret==(int)pkt->size); if(frameOk) { - assert(codecContext->pix_fmt==PIX_FMT_YUV420P); + //assert(codecContext->pix_fmt==PIX_FMT_YUV420P); if(status==INIT && fillDataAndCheckValidity()) status=VALID; @@ -956,7 +956,11 @@ } } } +#ifdef HAVE_AV_PACKET_UNREF + av_packet_unref(&pkt); +#else av_free_packet(&pkt); +#endif return true; }
View file
lightspark.tar.xz/src/backends/extscriptobject.cpp
Changed
@@ -248,20 +248,21 @@ // Conversion to ASObject ASObject* ExtVariant::getASObject(std::map<const lightspark::ExtObject*, lightspark::ASObject*>& objectsMap) const { + //don't create ASObjects from cache, as we are not in the vm thread ASObject* asobj; switch(getType()) { case EV_STRING: - asobj = abstract_s(getSys(),getString().c_str()); + asobj = Class<ASString>::getInstanceS(getSys(),getString().c_str()); break; case EV_INT32: - asobj = abstract_i(getSys(),getInt()); + asobj = Class<Integer>::getInstanceS(getSys(),getInt()); break; case EV_DOUBLE: - asobj = abstract_d(getSys(),getDouble()); + asobj = Class<Number>::getInstanceS(getSys(),getDouble()); break; case EV_BOOLEAN: - asobj = abstract_b(getSys(),getBoolean()); + asobj = Class<Boolean>::getInstanceS(getSys(),getBoolean()); break; case EV_OBJECT: {
View file
lightspark.tar.xz/src/parsing/streams.h
Changed
@@ -101,14 +101,13 @@ const char* const code; unsigned int len; unsigned int pos; - bool read_past_end; - lightspark::method_body_info_cache* codecache; public: + lightspark::method_body_info_cache* codecache; // Create a stream from a buffer b. // // The buffer is not copied, so b must continue to exists for // the life-time of this memorystream instance. - memorystream(const char* const b, unsigned int l,lightspark::method_body_info_cache* cc): code(b), len(l), pos(0), read_past_end(false),codecache(cc) {}; + memorystream(const char* const b, unsigned int l,lightspark::method_body_info_cache* cc): code(b), len(l), pos(0),codecache(cc) {}; static void handleError(const char *msg); inline unsigned int size() const { @@ -134,7 +133,6 @@ { memcpy(out, code+pos, len-pos); pos = len; - read_past_end = true; } else { @@ -153,22 +151,16 @@ else { pos = len; - read_past_end = true; return 0; } } inline uint32_t readu30() { unsigned int currpos = pos; - if (codecache[currpos].iscached) + if (codecache[currpos].type == lightspark::method_body_info_cache::CACHE_TYPE_UINTEGER) { pos = codecache[currpos].nextpos; - if (pos >= len) - { - pos = len; - read_past_end = true; - } - return codecache[currpos].value; + return codecache[currpos].uvalue; } uint32_t val = readu32(); if(val&0xc0000000) @@ -201,22 +193,26 @@ } } while(t&0x80); - codecache[currpos].iscached = true; - codecache[currpos].value = val; + codecache[currpos].type = lightspark::method_body_info_cache::CACHE_TYPE_UINTEGER; + codecache[currpos].uvalue = val; codecache[currpos].nextpos = pos; return val; } inline int32_t reads24() { + unsigned int currpos = pos; + if (codecache[currpos].type == lightspark::method_body_info_cache::CACHE_TYPE_INTEGER) + { + pos = codecache[currpos].nextpos; + return codecache[currpos].ivalue; + } uint32_t val=0; read((char*)&val,3); - return LittleEndianToSignedHost24(val); - } - - inline bool eof() const - { - return read_past_end; + int32_t ret = LittleEndianToSignedHost24(val); + codecache[currpos].type = lightspark::method_body_info_cache::CACHE_TYPE_INTEGER; + codecache[currpos].ivalue = ret; + codecache[currpos].nextpos = pos; + return ret; } - }; #endif /* PARSING_STREAMS_H */
View file
lightspark.tar.xz/src/scripting/abc.h
Changed
@@ -276,10 +276,10 @@ { ASObject* arg1=th->runtime_stack_pop(); uint32_t addr=arg1->toUInt(); - arg1->decRef(); _R<ApplicationDomain> appDomain = getCurrentApplicationDomain(th); T ret=appDomain->readFromDomainMemory<T>(addr); th->runtime_stack_push(abstract_i(arg1->getSystemState(),ret)); + arg1->decRef(); } template<class T> static void storeIntN(call_context* th) @@ -297,20 +297,20 @@ { ASObject* arg1=th->runtime_stack_pop(); float addr=arg1->toNumber(); - arg1->decRef(); _R<ApplicationDomain> appDomain = getCurrentApplicationDomain(th); number_t ret=appDomain->readFromDomainMemory<float>(addr); th->runtime_stack_push(abstract_d(arg1->getSystemState(),ret)); + arg1->decRef(); } static void loadDouble(call_context* th) { ASObject* arg1=th->runtime_stack_pop(); double addr=arg1->toNumber(); - arg1->decRef(); _R<ApplicationDomain> appDomain = getCurrentApplicationDomain(th); number_t ret=appDomain->readFromDomainMemory<double>(addr); th->runtime_stack_push(abstract_d(arg1->getSystemState(),ret)); + arg1->decRef(); } static void storeFloat(call_context* th) {
View file
lightspark.tar.xz/src/scripting/abc_codesynt.cpp
Changed
@@ -294,11 +294,15 @@ llvm::FunctionType* FT=NULL; //Create types +#ifdef LLVM_38 + ptr_type=ex->getDataLayout().getIntPtrType(llvm_context()); +#else #if defined HAVE_DATALAYOUT_H || defined HAVE_IR_DATALAYOUT_H ptr_type=ex->getDataLayout()->getIntPtrType(llvm_context()); #else ptr_type=ex->getTargetData()->getIntPtrType(llvm_context()); #endif +#endif //Pointer to 8 bit type, needed for pointer arithmetic voidptr_type=llvm::IntegerType::get(llvm_context(),8)->getPointerTo(); number_type=llvm::Type::getDoubleTy(llvm_context()); @@ -1885,7 +1889,11 @@ llvm::Function::ArgumentListType::iterator it=llvmf->getArgumentList().begin(); //The first and only argument to this function is the call_context* +#ifdef LLVM_38 + llvm::Value* context=&(*it); +#else llvm::Value* context=it; +#endif //let's give access to local data storage value=Builder.CreateStructGEP(
View file
lightspark.tar.xz/src/scripting/abc_interpreter.cpp
Changed
@@ -66,8 +66,6 @@ uint32_t instructionPointer=code.tellg(); #endif opcode = code.readbyte(); - if(code.eof()) - throw ParseException("End of code in interpreter"); //Save ip for exception handling in SyntheticFunction::callImpl context->exec_pos = code.tellg(); @@ -492,19 +490,46 @@ } case 0x24: { - //pushbyte + uint32_t pos = code.tellg(); + if (code.codecache[pos].type == method_body_info_cache::CACHE_TYPE_OBJECT) + { + context->runtime_stack_push(code.codecache[pos].obj); + code.seekg(code.codecache[pos].nextpos); + break; + } + int8_t t = code.readbyte(); - context->runtime_stack_push(abstract_i(function->getSystemState(),t)); + code.codecache[pos].nextpos = pos+1; pushByte(t); + + ASObject* d= abstract_i(function->getSystemState(),t); + d->setConstant(); + code.codecache[pos].type =method_body_info_cache::CACHE_TYPE_OBJECT; + code.codecache[pos].obj = d; + context->runtime_stack_push(d); break; } case 0x25: { //pushshort + uint32_t pos = code.tellg(); + if (code.codecache[pos].type == method_body_info_cache::CACHE_TYPE_OBJECT) + { + context->runtime_stack_push(code.codecache[pos].obj); + code.seekg(code.codecache[pos].nextpos); + break; + } // specs say pushshort is a u30, but it's really a u32 // see https://bugs.adobe.com/jira/browse/ASC-4181 uint32_t t = code.readu32(); - context->runtime_stack_push(abstract_i(function->getSystemState(),t)); + code.codecache[pos].nextpos = code.tellg(); + + ASObject* i= abstract_i(function->getSystemState(),t); + i->setConstant(); + code.codecache[pos].type =method_body_info_cache::CACHE_TYPE_OBJECT; + code.codecache[pos].obj = i; + context->runtime_stack_push(i); + pushShort(t); break; } @@ -565,33 +590,65 @@ case 0x2d: { //pushint + uint32_t pos = code.tellg(); + if (code.codecache[pos].type == method_body_info_cache::CACHE_TYPE_OBJECT) + { + context->runtime_stack_push(code.codecache[pos].obj); + code.seekg(code.codecache[pos].nextpos); + break; + } + uint32_t t = code.readu30(); s32 val=context->context->constant_pool.integer[t]; pushInt(context, val); ASObject* i=abstract_i(function->getSystemState(),val); + i->setConstant(); + code.codecache[pos].type =method_body_info_cache::CACHE_TYPE_OBJECT; + code.codecache[pos].obj = i; context->runtime_stack_push(i); break; } case 0x2e: { //pushuint + uint32_t pos = code.tellg(); + if (code.codecache[pos].type == method_body_info_cache::CACHE_TYPE_OBJECT) + { + context->runtime_stack_push(code.codecache[pos].obj); + code.seekg(code.codecache[pos].nextpos); + break; + } + uint32_t t = code.readu30(); u32 val=context->context->constant_pool.uinteger[t]; pushUInt(context, val); ASObject* i=abstract_ui(function->getSystemState(),val); + i->setConstant(); + code.codecache[pos].type =method_body_info_cache::CACHE_TYPE_OBJECT; + code.codecache[pos].obj = i; context->runtime_stack_push(i); break; } case 0x2f: { //pushdouble + uint32_t pos = code.tellg(); + if (code.codecache[pos].type == method_body_info_cache::CACHE_TYPE_OBJECT) + { + context->runtime_stack_push(code.codecache[pos].obj); + code.seekg(code.codecache[pos].nextpos); + break; + } uint32_t t = code.readu30(); d64 val=context->context->constant_pool.doubles[t]; pushDouble(context, val); - - ASObject* d=abstract_d(function->getSystemState(),val); + + ASObject* d= abstract_d(function->getSystemState(),val); + d->setConstant(); + code.codecache[pos].type =method_body_info_cache::CACHE_TYPE_OBJECT; + code.codecache[pos].obj = d; context->runtime_stack_push(d); break; }
View file
lightspark.tar.xz/src/scripting/abc_opcodes.cpp
Changed
@@ -680,7 +680,7 @@ LOG(LOG_CALLS, _("incLocal ") << n ); number_t tmp=th->locals[n]->toNumber(); th->locals[n]->decRef(); - th->locals[n]=abstract_d(th->locals[n]->getSystemState(),tmp+1); + th->locals[n]=abstract_d(th->context->root->getSystemState(),tmp+1); } void ABCVm::incLocal_i(call_context* th, int n) @@ -688,7 +688,7 @@ LOG(LOG_CALLS, _("incLocal_i ") << n ); int32_t tmp=th->locals[n]->toInt(); th->locals[n]->decRef(); - th->locals[n]=abstract_i(th->locals[n]->getSystemState(),tmp+1); + th->locals[n]=abstract_i(th->context->root->getSystemState(),tmp+1); } void ABCVm::decLocal(call_context* th, int n) @@ -696,7 +696,7 @@ LOG(LOG_CALLS, _("decLocal ") << n ); number_t tmp=th->locals[n]->toNumber(); th->locals[n]->decRef(); - th->locals[n]=abstract_d(th->locals[n]->getSystemState(),tmp-1); + th->locals[n]=abstract_d(th->context->root->getSystemState(),tmp-1); } void ABCVm::decLocal_i(call_context* th, int n) @@ -704,7 +704,7 @@ LOG(LOG_CALLS, _("decLocal_i ") << n ); int32_t tmp=th->locals[n]->toInt(); th->locals[n]->decRef(); - th->locals[n]=abstract_i(th->locals[n]->getSystemState(),tmp-1); + th->locals[n]=abstract_i(th->context->root->getSystemState(),tmp-1); } /* This is called for expressions like @@ -818,7 +818,7 @@ { LOG(LOG_NOT_IMPLEMENTED, "constructGenericType of " << obj->getObjectType()); obj->decRef(); - obj = obj->getSystemState()->getUndefinedRef(); + obj = th->context->root->getSystemState()->getUndefinedRef(); th->runtime_stack_push(obj); for(int i=0;i<m;i++) args[i]->decRef(); @@ -905,8 +905,9 @@ default: assert_and_throw(false); } + ASObject* res = abstract_s(obj->getSystemState(),ret); obj->decRef(); - return abstract_s(obj->getSystemState(),ret); + return res; } void ABCVm::jump(int offset) @@ -1024,6 +1025,7 @@ { //Implement ECMA add algorithm, for XML and default (see avm2overview) + ASObject* res = NULL; // if both values are Integers or int Numbers the result is also an int Number if( (val1->is<Integer>() || val1->is<UInteger>() || (val1->is<Number>() && !val1->as<Number>()->isfloat)) && (val2->is<Integer>() || val1->is<UInteger>() || (val2->is<Number>() && !val2->as<Number>()->isfloat))) @@ -1031,27 +1033,30 @@ int64_t num1=val1->toInt64(); int64_t num2=val2->toInt64(); LOG(LOG_CALLS,"addI " << num1 << '+' << num2); + res = abstract_di(val1->getSystemState(), num1+num2); val1->decRef(); val2->decRef(); - return abstract_di(val1->getSystemState(), num1+num2); + return res; } else if(val1->is<Number>() && val2->is<Number>()) { double num1=val1->as<Number>()->toNumber(); double num2=val2->as<Number>()->toNumber(); LOG(LOG_CALLS,"addN " << num1 << '+' << num2); + res = abstract_d(val1->getSystemState(), num1+num2); val1->decRef(); val2->decRef(); - return abstract_d(val1->getSystemState(), num1+num2); + return res; } else if(val1->is<ASString>() || val2->is<ASString>()) { tiny_string a = val1->toString(); tiny_string b = val2->toString(); LOG(LOG_CALLS,"add " << a << '+' << b); + res = abstract_s(val1->getSystemState(),a + b); val1->decRef(); val2->decRef(); - return abstract_s(val1->getSystemState(),a + b); + return res; } else if( (val1->is<XML>() || val1->is<XMLList>()) && (val2->is<XML>() || val2->is<XMLList>()) ) { @@ -1077,14 +1082,15 @@ {//If none of the above apply, convert both to primitives with no hint _R<ASObject> val1p = val1->toPrimitive(NO_HINT); _R<ASObject> val2p = val2->toPrimitive(NO_HINT); - val1->decRef(); - val2->decRef(); if(val1p->is<ASString>() || val2p->is<ASString>()) {//If one is String, convert both to strings and concat string a(val1p->toString().raw_buf()); string b(val2p->toString().raw_buf()); LOG(LOG_CALLS,"add " << a << '+' << b); - return abstract_s(val1->getSystemState(),a+b); + res = abstract_s(val1->getSystemState(),a+b); + val1->decRef(); + val2->decRef(); + return res; } else {//Convert both to numbers and add @@ -1092,7 +1098,10 @@ number_t num2=val2p->toNumber(); LOG(LOG_CALLS,"addN " << num1 << '+' << num2); number_t result = num1 + num2; - return abstract_d(val1->getSystemState(), result); + res = abstract_d(val1->getSystemState(),result); + val1->decRef(); + val2->decRef(); + return res; } } @@ -1118,32 +1127,36 @@ ASObject* ABCVm::add_oi(ASObject* val2, int32_t val1) { + ASObject* res =NULL; //Implement ECMA add algorithm, for XML and default if(val2->getObjectType()==T_INTEGER) { Integer* ip=static_cast<Integer*>(val2); int32_t num2=ip->val; int32_t num1=val1; + res = abstract_i(val2->getSystemState(),num1+num2); val2->decRef(); LOG(LOG_CALLS,_("add ") << num1 << '+' << num2); - return abstract_i(val2->getSystemState(),num1+num2); + return res; } else if(val2->getObjectType()==T_NUMBER) { double num2=val2->toNumber(); double num1=val1; + res = abstract_d(val2->getSystemState(),num1+num2); val2->decRef(); LOG(LOG_CALLS,_("add ") << num1 << '+' << num2); - return abstract_d(val2->getSystemState(),num1+num2); + return res; } else if(val2->getObjectType()==T_STRING) { //Convert argument to int32_t tiny_string a = Integer::toString(val1); const tiny_string& b=val2->toString(); + res = abstract_s(val2->getSystemState(), a+b); val2->decRef(); LOG(LOG_CALLS,_("add ") << a << '+' << b); - return abstract_s(val2->getSystemState(), a+b); + return res; } else { @@ -1154,30 +1167,34 @@ ASObject* ABCVm::add_od(ASObject* val2, number_t val1) { + ASObject* res = NULL; //Implement ECMA add algorithm, for XML and default if(val2->getObjectType()==T_NUMBER) { double num2=val2->toNumber(); double num1=val1; + res = abstract_d(val2->getSystemState(),num1+num2); val2->decRef(); LOG(LOG_CALLS,_("add ") << num1 << '+' << num2); - return abstract_d(val2->getSystemState(),num1+num2); + return res; } else if(val2->getObjectType()==T_INTEGER) { double num2=val2->toNumber(); double num1=val1; + res = abstract_d(val2->getSystemState(),num1+num2); val2->decRef(); LOG(LOG_CALLS,_("add ") << num1 << '+' << num2); - return abstract_d(val2->getSystemState(),num1+num2); + return res; } else if(val2->getObjectType()==T_STRING) { tiny_string a = Number::toString(val1); const tiny_string& b=val2->toString(); + res = abstract_s(val2->getSystemState(),a+b); val2->decRef(); LOG(LOG_CALLS,_("add ") << a << '+' << b); - return abstract_s(val2->getSystemState(),a+b); + return res; } else { @@ -1732,12 +1749,11 @@ } else { + tiny_string clsname = obj->getClassName(); obj->decRef(); for(int i=0;i<m;i++) args[i]->decRef(); - throwError<ReferenceError>(kCallNotFoundError, "?", obj->getClassName()); - if(keepReturn) - th->runtime_stack_push(obj->getSystemState()->getUndefinedRef()); + throwError<ReferenceError>(kCallNotFoundError, "?", clsname); } LOG(LOG_CALLS,"End of callStatic "); } @@ -1782,8 +1798,6 @@ args[i]->decRef(); //LOG(LOG_ERROR,_("Calling an undefined function ") << th->context->root->getSystemState()->getStringFromUniqueId(name->name_s_id)); throwError<ReferenceError>(kCallNotFoundError, name->qualifiedString(th->context->root->getSystemState()), clsname); - if(keepReturn) - th->runtime_stack_push(th->context->root->getSystemState()->getUndefinedRef()); } LOG(LOG_CALLS,_("End of callSuper ") << *name); } @@ -1809,19 +1823,19 @@ case T_NUMBER: case T_OBJECT: case T_STRING: + LOG(LOG_ERROR,"trying to call isTypelate on object:"<<obj->toDebugString()); obj->decRef(); type->decRef(); - LOG(LOG_ERROR,"trying to call isTypelate on object:"<<obj->toDebugString()); throwError<TypeError>(kIsTypeMustBeClassError); case T_NULL: + LOG(LOG_ERROR,"trying to call isTypelate on null:"<<obj->toDebugString()); obj->decRef(); type->decRef(); - LOG(LOG_ERROR,"trying to call isTypelate on null:"<<obj->toDebugString()); throwError<TypeError>(kConvertNullToObjectError); case T_UNDEFINED: + LOG(LOG_ERROR,"trying to call isTypelate on undefined:"<<obj->toDebugString()); obj->decRef(); type->decRef(); - LOG(LOG_ERROR,"trying to call isTypelate on undefined:"<<obj->toDebugString()); throwError<TypeError>(kConvertUndefinedToObjectError); case T_CLASS: break; @@ -1879,8 +1893,9 @@ return obj; else { + ASObject* res = obj->getSystemState()->getNullRef(); obj->decRef(); - return obj->getSystemState()->getNullRef(); + return res; } } @@ -1890,9 +1905,9 @@ if(!type->is<Class_base>()) { + LOG(LOG_ERROR,"trying to call asTypelate on non class object:"<<obj->toDebugString()); obj->decRef(); type->decRef(); - LOG(LOG_ERROR,"trying to call asTypelate on non class object:"<<obj->toDebugString()); throwError<TypeError>(kConvertNullToObjectError); } Class_base* c=static_cast<Class_base*>(type); @@ -1914,8 +1929,9 @@ return obj; else { + ASObject* res = obj->getSystemState()->getNullRef(); obj->decRef(); - return obj->getSystemState()->getNullRef(); + return res; } } @@ -1924,9 +1940,10 @@ objc=obj->classdef; else { + ASObject* res = obj->getSystemState()->getNullRef(); obj->decRef(); type->decRef(); - return obj->getSystemState()->getNullRef(); + return res; } bool real_ret=objc->isSubClass(c); @@ -1937,8 +1954,9 @@ return obj; else { + ASObject* res = obj->getSystemState()->getNullRef(); obj->decRef(); - return obj->getSystemState()->getNullRef(); + return res; } } @@ -2017,12 +2035,16 @@ { for(int i=0;i<m;++i) args[i]->decRef(); - obj->decRef(); if (obj->is<Undefined>()) + { + obj->decRef(); throwError<TypeError>(kConvertUndefinedToObjectError); + } if (obj->isPrimitive()) + { + obj->decRef(); throwError<TypeError>(kConstructOfNonFunctionError); - + } throwError<ReferenceError>(kUndefinedVarError, name->normalizedNameUnresolved(th->context->root->getSystemState())); } @@ -2695,8 +2717,9 @@ t = o->as<XMLList>()->toXMLString_internal(); else t = XML::encodeToXML(o->toString(),true); + ASObject* res = abstract_s(o->getSystemState(),t); o->decRef(); - return abstract_s(o->getSystemState(),t); + return res; } ASObject* ABCVm::esc_xelem(ASObject* o) @@ -2708,8 +2731,9 @@ t = o->as<XMLList>()->toXMLString_internal(); else t = XML::encodeToXML(o->toString(),false); + ASObject* res = abstract_s(o->getSystemState(),t); o->decRef(); - return abstract_s(o->getSystemState(),t); + return res; } /* This should walk prototype chain of value, trying to find type. See ECMA.
View file
lightspark.tar.xz/src/scripting/abctypes.h
Changed
@@ -260,8 +260,13 @@ }; struct method_body_info_cache { - bool iscached; - uint32_t value; + enum method_body_info_cache_type { CACHE_TYPE_NONE = 0,CACHE_TYPE_UINTEGER,CACHE_TYPE_INTEGER, CACHE_TYPE_OBJECT }; + method_body_info_cache_type type; + union { + uint32_t uvalue; + int32_t ivalue; + ASObject* obj; + }; uint32_t nextpos; }; @@ -290,6 +295,7 @@ std::istream& operator>>(std::istream& in, u16& v); std::istream& operator>>(std::istream& in, u30& v); std::istream& operator>>(std::istream& in, u32& v); +std::istream& operator>>(std::istream& in, s24& v); std::istream& operator>>(std::istream& in, s32& v); std::istream& operator>>(std::istream& in, d64& v); std::istream& operator>>(std::istream& in, string_info& v);
View file
lightspark.tar.xz/src/scripting/class.cpp
Changed
@@ -66,12 +66,6 @@ isReusable = true; } -void Class_inherit::finalize() -{ - Class_base::finalize(); - class_scope.clear(); -} - ASObject* Class_inherit::getInstance(bool construct, ASObject* const* args, const unsigned int argslen, Class_base* realClass) { //We override the classdef
View file
lightspark.tar.xz/src/scripting/class.h
Changed
@@ -51,7 +51,11 @@ void recursiveBuild(ASObject* target) const; public: Class_inherit(const QName& name, MemoryAccount* m); - void finalize(); + bool destruct() + { + class_scope.clear(); + return Class_base::destruct(); + } void buildInstanceTraits(ASObject* o) const; void setupDeclaredTraits(ASObject *target) const; void bindToTag(DictionaryTag const* t) @@ -230,32 +234,36 @@ inline ASObject* Class<Number>::coerce(ASObject* o) const { number_t n = o->toNumber(); + ASObject* res = abstract_d(o->getSystemState(),n); o->decRef(); - return abstract_d(o->getSystemState(),n); + return res; } template<> inline ASObject* Class<UInteger>::coerce(ASObject* o) const { uint32_t n = o->toUInt(); + ASObject* res = abstract_ui(o->getSystemState(),n); o->decRef(); - return abstract_ui(o->getSystemState(),n); + return res; } template<> inline ASObject* Class<Integer>::coerce(ASObject* o) const { int32_t n = o->toInt(); + ASObject* res = abstract_i(o->getSystemState(),n); o->decRef(); - return abstract_i(o->getSystemState(),n); + return res; } template<> inline ASObject* Class<Boolean>::coerce(ASObject* o) const { bool n = Boolean_concrete(o); + ASObject* res = abstract_b(o->getSystemState(),n); o->decRef(); - return abstract_b(o->getSystemState(),n); + return res; } template<> @@ -421,8 +429,9 @@ { if (o->is<Undefined>()) { + ASObject* res = o->getSystemState()->getNullRef(); o->decRef(); - return o->getSystemState()->getNullRef(); + return res; } else if ((o->is<Vector>() && o->as<Vector>()->sameType(this)) || o->is<Null>()) @@ -433,8 +442,9 @@ } else { + tiny_string clsname = o->getClassName(); o->decRef(); - throwError<TypeError>(kCheckTypeFailedError, o->getClassName(), + throwError<TypeError>(kCheckTypeFailedError, clsname, Class<T>::getQualifiedClassName()); return NULL; // not reached }
View file
lightspark.tar.xz/src/scripting/flash/display/flashdisplay.cpp
Changed
@@ -113,9 +113,8 @@ { } -void LoaderInfo::finalize() +bool LoaderInfo::destruct() { - EventDispatcher::finalize(); sharedEvents.reset(); loader.reset(); applicationDomain.reset(); @@ -134,6 +133,7 @@ frameRate =0; parameters.reset(); uncaughtErrorEvents.reset(); + return EventDispatcher::destruct(); } void LoaderInfo::resetState() @@ -691,14 +691,14 @@ { } -void Sprite::finalize() +bool Sprite::destruct() { - DisplayObjectContainer::finalize(); graphics.reset(); hitArea.reset(); hitTarget.reset(); buttonMode = false; useHandCursor = false; + return DisplayObjectContainer::destruct(); } void Sprite::sinit(Class_base* c) @@ -1137,14 +1137,14 @@ //For the root movie, it's the frame count from the header } -void MovieClip::finalize() +bool MovieClip::destruct() { - Sprite::finalize(); frames.clear(); frameScripts.clear(); fromDefineSpriteTag = false; totalFrames_unreliable = 1; enabled = true; + return Sprite::destruct(); } /* Returns a Scene_data pointer for a scene called sceneName, or for @@ -1573,13 +1573,13 @@ } } -void DisplayObjectContainer::finalize() +bool DisplayObjectContainer::destruct() { - InteractiveObject::finalize(); //Release every child dynamicDisplayList.clear(); mouseChildren = true; tabChildren = true; + return InteractiveObject::destruct(); } InteractiveObject::InteractiveObject(Class_base* c):DisplayObject(c),mouseEnabled(true),doubleClickEnabled(false),accessibilityImplementation(NullRef),contextMenu(NullRef),tabEnabled(false),tabIndex(-1) @@ -1631,15 +1631,15 @@ return abstract_b(obj->getSystemState(),th->doubleClickEnabled); } -void InteractiveObject::finalize() +bool InteractiveObject::destruct() { - DisplayObject::finalize(); contextMenu.reset(); mouseEnabled = true; doubleClickEnabled =false; accessibilityImplementation.reset(); tabEnabled = false; tabIndex = -1; + return DisplayObject::destruct(); } void InteractiveObject::buildTraits(ASObject* o) @@ -2568,13 +2568,13 @@ { } -void Bitmap::finalize() +bool Bitmap::destruct() { if(!bitmapData.isNull()) bitmapData->removeUser(this); bitmapData.reset(); smoothing = false; - DisplayObject::finalize(); + return DisplayObject::destruct(); } void Bitmap::sinit(Class_base* c)
View file
lightspark.tar.xz/src/scripting/flash/display/flashdisplay.h
Changed
@@ -78,7 +78,7 @@ ASFUNCTION(_getMouseEnabled); ASFUNCTION(_setDoubleClickEnabled); ASFUNCTION(_getDoubleClickEnabled); - void finalize(); + bool destruct(); static void sinit(Class_base* c); static void buildTraits(ASObject* o); }; @@ -107,7 +107,7 @@ bool _removeChild(_R<DisplayObject> child); int getChildIndex(_R<DisplayObject> child); DisplayObjectContainer(Class_base* c); - void finalize(); + bool destruct(); bool hasLegacyChildAt(uint32_t depth); void deleteLegacyChildAt(uint32_t depth); void insertLegacyChildAt(uint32_t depth, DisplayObject* obj); @@ -257,7 +257,7 @@ ASPROPERTY_GETTER(number_t,frameRate); LoaderInfo(Class_base* c); LoaderInfo(Class_base* c, _R<Loader> l); - void finalize(); + bool destruct(); static void sinit(Class_base* c); static void buildTraits(ASObject* o); ASFUNCTION(_constructor); @@ -358,7 +358,7 @@ _NR<DisplayObject> hitTestImpl(_NR<DisplayObject> last, number_t x, number_t y, DisplayObject::HIT_TYPE type); public: Sprite(Class_base* c); - void finalize(); + bool destruct(); static void sinit(Class_base* c); static void buildTraits(ASObject* o); ASFUNCTION(_constructor); @@ -481,7 +481,7 @@ RunState state; MovieClip(Class_base* c); MovieClip(Class_base* c, const FrameContainer& f, bool defineSpriteTag); - void finalize(); + bool destruct(); ASObject* gotoAnd(ASObject* const* args, const unsigned int argslen, bool stop); static void sinit(Class_base* c); static void buildTraits(ASObject* o); @@ -687,7 +687,7 @@ Bitmap(Class_base* c, _NR<LoaderInfo> li=NullRef, std::istream *s = NULL, FILE_TYPE type=FT_UNKNOWN); Bitmap(Class_base* c, _R<BitmapData> data); ~Bitmap(); - void finalize(); + bool destruct(); static void sinit(Class_base* c); ASFUNCTION(_constructor); bool boundsRect(number_t& xmin, number_t& xmax, number_t& ymin, number_t& ymax) const;
View file
lightspark.tar.xz/src/scripting/flash/utils/Dictionary.cpp
Changed
@@ -34,12 +34,6 @@ { } -void Dictionary::finalize() -{ - ASObject::finalize(); - data.clear(); -} - void Dictionary::sinit(Class_base* c) { CLASS_SETUP(c, ASObject, _constructor, CLASS_DYNAMIC_NOT_FINAL);
View file
lightspark.tar.xz/src/scripting/flash/utils/Dictionary.h
Changed
@@ -37,7 +37,12 @@ dictType::iterator findKey(ASObject *); public: Dictionary(Class_base* c); - void finalize(); + bool destruct() + { + data.clear(); + return ASObject::destruct(); + } + static void sinit(Class_base*); static void buildTraits(ASObject* o); ASFUNCTION(_constructor);
View file
lightspark.tar.xz/src/scripting/flash/xml/flashxml.cpp
Changed
@@ -31,15 +31,10 @@ { } -void XMLNode::finalize() -{ - ASObject::finalize(); - root.reset(); -} - void XMLNode::sinit(Class_base* c) { CLASS_SETUP(c, ASObject, _constructor, CLASS_SEALED); + c->isReusable = true; c->setDeclaredMethodByQName("toString","",Class<IFunction>::getFunction(c->getSystemState(),_toString),NORMAL_METHOD,true); c->setDeclaredMethodByQName("attributes","",Class<IFunction>::getFunction(c->getSystemState(),attributes),GETTER_METHOD,true); c->setDeclaredMethodByQName("childNodes","",Class<IFunction>::getFunction(c->getSystemState(),XMLNode::childNodes),GETTER_METHOD,true);
View file
lightspark.tar.xz/src/scripting/flash/xml/flashxml.h
Changed
@@ -41,7 +41,11 @@ public: XMLNode(Class_base* c):ASObject(c),root(NullRef),node(NULL){} XMLNode(Class_base* c, _R<XMLDocument> _r, pugi::xml_node _n); - void finalize(); + bool destruct() + { + root.reset(); + return ASObject::destruct(); + } static void sinit(Class_base*); static void buildTraits(ASObject* o); tiny_string toString();
View file
lightspark.tar.xz/src/scripting/toplevel/ASString.h
Changed
@@ -103,7 +103,14 @@ std::string toDebugString() { return std::string("\"") + std::string(getData()) + "\""; } static bool isEcmaSpace(uint32_t c); static bool isEcmaLineTerminator(uint32_t c); - inline void finalize() { data.clear(); hasId = true, datafilled=true; stringId = BUILTIN_STRINGS::EMPTY; } + inline bool destruct() + { + data.clear(); + hasId = true; + datafilled=true; + stringId = BUILTIN_STRINGS::EMPTY; + return ASObject::destruct(); + } }; template<> @@ -114,16 +121,18 @@ //Special handling for Null and Undefined follows avm2overview's description of 'coerce_s' opcode if(o->is<Null>()) return o; + ASObject* res = NULL; if(o->is<Undefined>()) { + res = o->getSystemState()->getNullRef(); o->decRef(); - return o->getSystemState()->getNullRef(); + return res; } if(!o->isConstructed()) return o; - tiny_string n = o->toString(); + res = lightspark::abstract_s(o->getSystemState(),o->toString()); o->decRef(); - return lightspark::abstract_s(o->getSystemState(),n); + return res; } }
View file
lightspark.tar.xz/src/scripting/toplevel/Array.cpp
Changed
@@ -38,6 +38,7 @@ void Array::sinit(Class_base* c) { CLASS_SETUP(c, ASObject, _constructor, CLASS_DYNAMIC_NOT_FINAL); + c->isReusable = true; c->setVariableByQName("CASEINSENSITIVE","",abstract_di(c->getSystemState(),CASEINSENSITIVE),CONSTANT_TRAIT); c->setVariableByQName("DESCENDING","",abstract_di(c->getSystemState(),DESCENDING),CONSTANT_TRAIT); c->setVariableByQName("NUMERIC","",abstract_di(c->getSystemState(),NUMERIC),CONSTANT_TRAIT); @@ -140,7 +141,7 @@ // copy values into new array ret->resize(th->size()); - std::map<uint32_t, data_slot>::iterator it=th->data.begin(); + auto it=th->data.begin(); for(;it != th->data.end();++it) { ret->data[it->first]=it->second; @@ -155,7 +156,7 @@ // Insert the contents of the array argument uint64_t oldSize=ret->size(); Array* otherArray=args[i]->as<Array>(); - std::map<uint32_t, data_slot>::iterator itother=otherArray->data.begin(); + auto itother=otherArray->data.begin(); for(;itother!=otherArray->data.end(); ++itother) { uint32_t newIndex=ret->size()+itother->first; @@ -188,8 +189,7 @@ ASObject* params[3]; ASObject *funcRet; - std::map<uint32_t, data_slot>::iterator it=th->data.begin(); - for(;it != th->data.end();++it) + for(auto it=th->data.begin();it != th->data.end();++it) { if (it->second.type==DATA_OBJECT) { @@ -237,7 +237,7 @@ ASObject* params[3]; ASObject *funcRet; - std::map<uint32_t, data_slot>::iterator it=th->data.begin(); + auto it=th->data.begin(); for(;it != th->data.end();++it) { if (it->second.type==DATA_OBJECT) @@ -283,7 +283,7 @@ ASObject* params[3]; ASObject *funcRet; - std::map<uint32_t, data_slot>::iterator it=th->data.begin(); + auto it=th->data.begin(); for(;it != th->data.end();++it) { if (it->second.type==DATA_OBJECT) @@ -350,14 +350,14 @@ uint32_t s = th->size(); for (uint32_t i=0; i < s; i++ ) { - if (th->data.count(i)) + auto it = th->data.find(i); + if (it != th->data.end()) { - const data_slot& slot=th->data[i]; - if(slot.type==DATA_INT) - params[0]=abstract_i(obj->getSystemState(),slot.data_i); - else if(slot.type==DATA_OBJECT && slot.data) + if(it->second.type==DATA_INT) + params[0]=abstract_i(obj->getSystemState(),it->second.data_i); + else if(it->second.type==DATA_OBJECT && it->second.data) { - params[0]=slot.data; + params[0]=it->second.data; params[0]->incRef(); } else @@ -393,7 +393,7 @@ std::map<uint32_t, data_slot> tmp = std::map<uint32_t, data_slot>(th->data.begin(),th->data.end()); uint32_t size = th->size(); th->data.clear(); - std::map<uint32_t, data_slot>::iterator it=tmp.begin(); + auto it=tmp.begin(); for(;it != tmp.end();++it) { th->data[size-(it->first+1)]=it->second; @@ -435,12 +435,13 @@ } do { - if (!th->data.count(i)) + auto it = th->data.find(i); + if (it == th->data.end()) continue; - DATA_TYPE dtype = th->data[i].type; + DATA_TYPE dtype = it->second.type; assert_and_throw(dtype==DATA_OBJECT || dtype==DATA_INT); - if((dtype == DATA_OBJECT && th->data[i].data->isEqualStrict(arg0.getPtr())) || - (dtype == DATA_INT && arg0->toInt() == th->data[i].data_i)) + if((dtype == DATA_OBJECT && it->second.data->isEqualStrict(arg0.getPtr())) || + (dtype == DATA_INT && arg0->toInt() == it->second.data_i)) { ret=i; break; @@ -477,18 +478,19 @@ if(!th->size()) return obj->getSystemState()->getUndefinedRef(); ASObject* ret; - if(!th->data.count(0)) + auto it = th->data.find(0); + if(it == th->data.end()) ret = obj->getSystemState()->getUndefinedRef(); else { - if(th->data[0].type==DATA_OBJECT) - ret=th->data[0].data; + if(it->second.type==DATA_OBJECT) + ret=it->second.data; else - ret = abstract_i(obj->getSystemState(),th->data[0].data_i); + ret = abstract_i(obj->getSystemState(),it->second.data_i); } std::map<uint32_t,data_slot> tmp; - std::map<uint32_t,data_slot>::iterator it; - for ( it=th->data.begin(); it != th->data.end(); ++it ) + it=th->data.begin(); + for (; it != th->data.end(); ++it ) { if(it->first) { @@ -534,11 +536,12 @@ int j = 0; for(int i=startIndex; i<endIndex; i++) { - if (th->data.count(i)) + auto it = th->data.find(i); + if (it != th->data.end()) { - if(th->data[i].type == DATA_OBJECT) - th->data[i].data->incRef(); - ret->data[j]=th->data[i]; + if(it->second.type == DATA_OBJECT) + it->second.data->incRef(); + ret->data[j]=it->second; } j++; } @@ -569,15 +572,17 @@ // write deleted items to return array for(int i=0;i<deleteCount;i++) { - if (th->data.count(startIndex+i)) - ret->data[i] = th->data[startIndex+i]; + auto it = th->data.find(startIndex+i); + if (it != th->data.end()) + ret->data[i] = it->second; } // delete items from current array for (int i = 0; i < deleteCount; i++) { - if(th->data.count(startIndex+i)) + auto it = th->data.find(startIndex+i); + if (it != th->data.end()) { - th->data.erase(startIndex+i); + th->data.erase(it); } } } @@ -585,10 +590,11 @@ vector<data_slot> tmp = vector<data_slot>(totalSize- (startIndex+deleteCount)); for (int i = startIndex+deleteCount; i < totalSize ; i++) { - if (th->data.count(i)) + auto it = th->data.find(i); + if (it != th->data.end()) { - tmp[i-(startIndex+deleteCount)] = th->data[i]; - th->data.erase(i); + tmp[i-(startIndex+deleteCount)] = it->second; + th->data.erase(it); } } th->resize(startIndex); @@ -639,8 +645,7 @@ if (index < 0) index = 0; DATA_TYPE dtype; - std::map<uint32_t,data_slot>::iterator it; - for ( it=th->data.begin() ; it != th->data.end(); ++it ) + for (auto it=th->data.begin() ; it != th->data.end(); ++it ) { if (it->first < (uint32_t)index) continue; @@ -686,13 +691,14 @@ return obj->getSystemState()->getUndefinedRef(); ASObject* ret; - if (th->data.count(size-1)) + auto it = th->data.find(size-1); + if (it != th->data.end()) { - if(th->data[size-1].type==DATA_OBJECT) - ret=th->data[size-1].data; + if(it->second.type==DATA_OBJECT) + ret=it->second.data; else - ret = abstract_i(obj->getSystemState(),th->data[size-1].data_i); - th->data.erase(size-1); + ret = abstract_i(obj->getSystemState(),it->second.data_i); + th->data.erase(it); } else ret = obj->getSystemState()->getUndefinedRef(); @@ -818,7 +824,7 @@ } } std::vector<data_slot> tmp = vector<data_slot>(th->data.size()); - std::map<uint32_t, data_slot>::iterator it=th->data.begin(); + auto it=th->data.begin(); int i = 0; for(;it != th->data.end();++it) { @@ -908,7 +914,7 @@ { Array* obj=static_cast<Array*>(args[0]); int n = 0; - std::map<uint32_t, data_slot>::iterator it=obj->data.begin(); + auto it=obj->data.begin(); for(;it != obj->data.end();++it) { multiname sortfieldname(NULL); @@ -923,7 +929,7 @@ if (argslen == 2 && args[1]->is<Array>()) { Array* opts=static_cast<Array*>(args[1]); - std::map<uint32_t, data_slot>::iterator itopt=opts->data.begin(); + auto itopt=opts->data.begin(); int nopt = 0; for(;itopt != opts->data.end() && nopt < n;++itopt) { @@ -966,7 +972,7 @@ } std::vector<data_slot> tmp = vector<data_slot>(th->data.size()); - std::map<uint32_t, data_slot>::iterator it=th->data.begin(); + auto it=th->data.begin(); int i = 0; for(;it != th->data.end();++it) { @@ -1015,8 +1021,7 @@ { th->resize(th->size()+argslen); std::map<uint32_t,data_slot> tmp; - std::map<uint32_t,data_slot>::reverse_iterator it; - for ( it=th->data.rbegin(); it != th->data.rend(); ++it ) + for (auto it=th->data.rbegin(); it != th->data.rend(); ++it ) { tmp[it->first+argslen]=it->second; } @@ -1112,14 +1117,14 @@ for (uint32_t i=0; i < s; i++ ) { ASObject* funcArgs[3]; - if (th->data.count(i)) + auto it = th->data.find(i); + if (it != th->data.end()) { - const data_slot& slot=th->data[i]; - if(slot.type==DATA_INT) - funcArgs[0]=abstract_i(obj->getSystemState(),slot.data_i); - else if(slot.type==DATA_OBJECT && slot.data) + if(it->second.type==DATA_INT) + funcArgs[0]=abstract_i(obj->getSystemState(),it->second.data_i); + else if(it->second.type==DATA_OBJECT && it->second.data) { - funcArgs[0]=slot.data; + funcArgs[0]=it->second.data; funcArgs[0]->incRef(); } else @@ -1183,9 +1188,10 @@ if(index<size()) { - if (!data.count(index)) + auto it = data.find(index); + if (it == data.end()) return 0; - data_slot sl = data[index]; + const data_slot& sl = it->second; switch(sl.type) { case DATA_OBJECT: @@ -1224,19 +1230,17 @@ uint32_t index=0; if(!isValidMultiname(getSystemState(),name,index)) return ASObject::getVariableByMultiname(name,opt); - if(index<size() && data.count(index)) + auto it = data.find(index); + if(it != data.end()) { ASObject* ret=NULL; - data_slot sl = data[index]; + const data_slot& sl = it->second; switch(sl.type) { case DATA_OBJECT: ret=sl.data; if(ret==NULL) - { ret=getSystemState()->getUndefinedRef(); - sl.data=ret; - } ret->incRef(); break; case DATA_INT: @@ -1274,13 +1278,13 @@ return; if(index>=size()) resize(index+1); - - if(data.count(index) && data[index].type==DATA_OBJECT && data[index].data) - data[index].data->decRef(); - if(!data.count(index)) - data[index] = data_slot(); - data[index].data_i=value; - data[index].type=DATA_INT; + auto it = data.find(index); + if(it != data.end()) + it->second.clear(); + data_slot ds; + ds.data_i=value; + ds.type=DATA_INT; + data[index] = ds; } @@ -1295,11 +1299,16 @@ if(!isValidMultiname(getSystemState(),name,index)) return ASObject::hasPropertyByMultiname(name, considerDynamic, considerPrototype); - return (index<size()) && (data.count(index)); + return (data.find(index) != data.end()); } bool Array::isValidMultiname(SystemState* sys, const multiname& name, uint32_t& index) { + if (name.name_type == multiname::NAME_INT && name.name_i >= 0) + { + index = name.name_i; + return true; + } if(name.isEmpty()) return false; //First of all the multiname has to contain the null namespace @@ -1353,23 +1362,24 @@ if(index>=size()) resize((uint64_t)index+1); - if(data.count(index) && data[index].type==DATA_OBJECT && data[index].data) - data[index].data->decRef(); - if(!data.count(index)) - data[index] = data_slot(); + data_slot ds; + auto it = data.find(index); + if(it != data.end()) + it->second.clear(); if(o->getObjectType()==T_INTEGER) { Integer* i=static_cast<Integer*>(o); - data[index].data_i=i->val; - data[index].type=DATA_INT; + ds.data_i=i->val; + ds.type=DATA_INT; o->decRef(); } else { - data[index].data=o; - data[index].type=DATA_OBJECT; + ds.data=o; + ds.type=DATA_OBJECT; } + data[index] = ds; } bool Array::deleteVariableByMultiname(const multiname& name) @@ -1383,12 +1393,11 @@ if(index>=size()) return true; - if (!data.count(index)) + auto it = data.find(index); + if(it == data.end()) return true; - if(data[index].type==DATA_OBJECT && data[index].data) - data[index].data->decRef(); - - data.erase(index); + it->second.clear(); + data.erase(it); return true; } @@ -1422,9 +1431,10 @@ string ret; for(uint32_t i=0;i<size();i++) { - if (data.count(i)) + auto it = data.find(i); + if(it != data.end()) { - data_slot sl = data.at(i); + const data_slot& sl = it->second; if(sl.type==DATA_OBJECT) { if(sl.data && !sl.data->is<Undefined>() && !sl.data->is<Null>()) @@ -1456,9 +1466,10 @@ if(index<=size()) { index--; - if(!data.count(index)) + auto it = data.find(index); + if(it == data.end()) return _MR(getSystemState()->getUndefinedRef()); - data_slot sl = data[index]; + const data_slot& sl = it->second; if(sl.type==DATA_OBJECT) { if(sl.data==NULL) @@ -1519,9 +1530,10 @@ if(size()<=index) outofbounds(index); - if (!data.count(index)) + auto it = data.find(index); + if(it == data.end()) return _MR(getSystemState()->getUndefinedRef()); - data_slot sl = data.at(index); + const data_slot& sl = it->second; switch(sl.type) { case DATA_OBJECT: @@ -1561,8 +1573,7 @@ itstart = it.base(); break; } - if (it->second.type==DATA_OBJECT && it->second.data) - it->second.data->decRef(); + it->second.clear(); } if (itstart != data.end()) data.erase(itstart,data.end()); @@ -1599,7 +1610,7 @@ serializeDynamicProperties(out, stringMap, objMap, traitsMap); for(uint32_t i=0;i<denseCount;i++) { - if (!data.count(i)) + if (data.find(i) == data.end()) { out->writeByte(null_marker); } @@ -1632,10 +1643,9 @@ path.push_back(this); res += "["; - std::map<uint32_t,data_slot>::iterator it; bool bfirst = true; tiny_string newline = (spaces.empty() ? "" : "\n"); - for (it=data.begin() ; it != data.end(); ++it) + for (auto it=data.begin() ; it != data.end(); ++it) { tiny_string subres; ASObject* o = it->second.type==DATA_OBJECT ? it->second.data : abstract_i(getSystemState(),it->second.data_i); @@ -1683,39 +1693,28 @@ Array::~Array() { - Array::finalize(); -} - -void Array::finalize() -{ - ASObject::finalize(); - std::map<uint32_t,data_slot>::iterator it; - for ( it=data.begin() ; it != data.end(); ++it) - { - if(it->second.type==DATA_OBJECT && it->second.data) - it->second.data->decRef(); - } - data.clear(); } void Array::set(unsigned int index, _R<ASObject> o) { if(index<currentsize) { - if(!data.count(index)) - data[index]=data_slot(); + data_slot ds; + if(data.find(index) != data.end()) + data[index].clear(); if(o->getObjectType()==T_INTEGER) { Integer* i=o->as<Integer>(); - data[index].data_i=i->val; - data[index].type=DATA_INT; + ds.data_i=i->val; + ds.type=DATA_INT; } else { o->incRef(); - data[index].data=o.getPtr(); - data[index].type=DATA_OBJECT; + ds.data=o.getPtr(); + ds.type=DATA_OBJECT; } + data[index]=ds; } else outofbounds(index);
View file
lightspark.tar.xz/src/scripting/toplevel/Array.h
Changed
@@ -38,6 +38,11 @@ explicit data_slot(ASObject* o):data(o),type(DATA_OBJECT){} data_slot():data(NULL),type(DATA_OBJECT){} explicit data_slot(int32_t i):data_i(i),type(DATA_INT){} + void clear() + { + if (type == DATA_OBJECT && data) + data->decRef(); + } }; struct sorton_field { @@ -92,7 +97,17 @@ public: enum SORTTYPE { CASEINSENSITIVE=1, DESCENDING=2, UNIQUESORT=4, RETURNINDEXEDARRAY=8, NUMERIC=16 }; Array(Class_base* c); - void finalize(); + bool destruct() + { + for (auto it=data.begin() ; it != data.end(); ++it) + { + if(it->second.type==DATA_OBJECT && it->second.data) + it->second.data->decRef(); + } + data.clear(); + return ASObject::destruct(); + } + //These utility methods are also used by ByteArray static bool isValidMultiname(SystemState* sys,const multiname& name, uint32_t& index); static bool isValidQName(const tiny_string& name, const tiny_string& ns, unsigned int& index);
View file
lightspark.tar.xz/src/scripting/toplevel/Boolean.cpp
Changed
@@ -163,32 +163,39 @@ TRISTATE Boolean::isLess(ASObject* r) { - if(r->getObjectType()==T_BOOLEAN) + switch (r->getObjectType()) { - const Boolean* b=static_cast<const Boolean*>(r); - return (val<b->val)?TTRUE:TFALSE; - } - else if(r->getObjectType()==T_INTEGER || - r->getObjectType()==T_UINTEGER || - r->getObjectType()==T_NUMBER || - r->getObjectType()==T_STRING) - { - double d=r->toNumber(); - if(std::isnan(d)) return TUNDEFINED; - return (val<d)?TTRUE:TFALSE; - } - else if(r->getObjectType()==T_NULL) - { - return (val<0)?TTRUE:TFALSE; - } - else if(r->getObjectType()==T_UNDEFINED) - { - return TUNDEFINED; - } - else - { - double val2=r->toPrimitive()->toNumber(); - if(std::isnan(val2)) return TUNDEFINED; - return (val<val2)?TTRUE:TFALSE; + case T_BOOLEAN: + { + const Boolean* b=static_cast<const Boolean*>(r); + return (val<b->val)?TTRUE:TFALSE; + } + case T_INTEGER: + { + int32_t d=r->toInt(); + return (val<d)?TTRUE:TFALSE; + } + case T_UINTEGER: + { + uint32_t d=r->toUInt(); + return (val<d)?TTRUE:TFALSE; + } + case T_NUMBER: + case T_STRING: + { + double d=r->toNumber(); + if(std::isnan(d)) return TUNDEFINED; + return (val<d)?TTRUE:TFALSE; + } + case T_NULL: + return (val)?TFALSE:TTRUE; + case T_UNDEFINED: + return TUNDEFINED; + default: + { + double val2=r->toPrimitive()->toNumber(); + if(std::isnan(val2)) return TUNDEFINED; + return (val<val2)?TTRUE:TFALSE; + } } }
View file
lightspark.tar.xz/src/scripting/toplevel/Boolean.h
Changed
@@ -39,7 +39,7 @@ static void sinit(Class_base*); static void buildTraits(ASObject* o){}; bool val; - inline void finalize() { val=false;} + inline bool destruct() { val=false; return ASObject::destruct(); } int32_t toInt() { return val ? 1 : 0;
View file
lightspark.tar.xz/src/scripting/toplevel/Date.cpp
Changed
@@ -35,18 +35,6 @@ { } -void Date::finalize() -{ - if (datetimeUTC) - g_date_time_unref(datetimeUTC); - if (datetime) - g_date_time_unref(datetime); - datetime = NULL; - datetimeUTC = NULL; - extrayears = 0; - nan = false; -} - void Date::sinit(Class_base* c) { CLASS_SETUP_CONSTRUCTOR_LENGTH(c, ASObject, _constructor, 7, CLASS_FINAL);
View file
lightspark.tar.xz/src/scripting/toplevel/Date.h
Changed
@@ -41,7 +41,19 @@ static number_t parse(tiny_string str); public: Date(Class_base* c); - void finalize(); + bool destruct() + { + if (datetimeUTC) + g_date_time_unref(datetimeUTC); + if (datetime) + g_date_time_unref(datetime); + datetime = NULL; + datetimeUTC = NULL; + extrayears = 0; + nan = false; + return ASObject::destruct(); + } + static void sinit(Class_base*); static void buildTraits(ASObject* o); ASFUNCTION(_constructor);
View file
lightspark.tar.xz/src/scripting/toplevel/Integer.h
Changed
@@ -38,7 +38,7 @@ static void buildTraits(ASObject* o){}; static void sinit(Class_base* c); inline number_t toNumber() { return val; } - inline void finalize() { val=0;} + inline bool destruct() { val=0; return ASObject::destruct(); } ASFUNCTION(_toString); tiny_string toString(); static tiny_string toString(int32_t val);
View file
lightspark.tar.xz/src/scripting/toplevel/Number.h
Changed
@@ -46,7 +46,7 @@ }; bool isfloat; inline number_t toNumber() { return isfloat ? dval : ival; } - inline void finalize() { dval=Number::NaN; isfloat = true;} + inline bool destruct() { dval=Number::NaN; isfloat = true; return ASObject::destruct(); } ASFUNCTION(_constructor); ASFUNCTION(_toString); ASFUNCTION(toExponential);
View file
lightspark.tar.xz/src/scripting/toplevel/UInteger.h
Changed
@@ -36,7 +36,7 @@ tiny_string toString(); static tiny_string toString(uint32_t val); inline number_t toNumber() { return val; } - inline void finalize() { val=0; } + inline bool destruct() { val=0; return ASObject::destruct();} inline int32_t toInt() { return val; } inline int64_t toInt64() { return val; } inline uint32_t toUInt() { return val; }
View file
lightspark.tar.xz/src/scripting/toplevel/Vector.cpp
Changed
@@ -29,6 +29,7 @@ void Vector::sinit(Class_base* c) { CLASS_SETUP(c, ASObject, _constructor, CLASS_FINAL); + c->isReusable = true; c->setDeclaredMethodByQName("length","",Class<IFunction>::getFunction(c->getSystemState(),getLength),GETTER_METHOD,true); c->setDeclaredMethodByQName("length","",Class<IFunction>::getFunction(c->getSystemState(),setLength),SETTER_METHOD,true); c->setDeclaredMethodByQName("toString","",Class<IFunction>::getFunction(c->getSystemState(),_toString),NORMAL_METHOD,true); @@ -100,18 +101,6 @@ Vector::~Vector() { - finalize(); -} - -void Vector::finalize() -{ - for(unsigned int i=0;i<size();i++) - { - if(vec[i]) - vec[i]->decRef(); - } - vec.clear(); - ASObject::finalize(); } void Vector::setTypes(const std::vector<const Type *> &types)
View file
lightspark.tar.xz/src/scripting/toplevel/Vector.h
Changed
@@ -54,7 +54,18 @@ public: Vector(Class_base* c, const Type *vtype=NULL); ~Vector(); - void finalize(); + bool destruct() + { + for(unsigned int i=0;i<size();i++) + { + if(vec[i]) + vec[i]->decRef(); + } + vec.clear(); + return ASObject::destruct(); + } + + static void sinit(Class_base* c); static void buildTraits(ASObject* o) {}; static ASObject* generator(TemplatedClass<Vector>* o_class, ASObject* const* args, const unsigned int argslen);
View file
lightspark.tar.xz/src/scripting/toplevel/XML.cpp
Changed
@@ -63,7 +63,7 @@ createTree(_n,fromXMLList); } -void XML::finalize() +bool XML::destruct() { xmldoc.reset(); parentNode.reset(); @@ -78,7 +78,7 @@ attributelist.reset(); procinstlist.reset(); namespacedefs.clear(); - + return ASObject::destruct(); } void XML::sinit(Class_base* c) @@ -2378,6 +2378,13 @@ return value; } +number_t XML::toNumber() +{ + if (!hasSimpleContent()) + return 0; + return parseNumber(toString_priv()); +} + bool XML::nodesEqual(XML *a, XML *b) const { assert(a && b);
View file
lightspark.tar.xz/src/scripting/toplevel/XML.h
Changed
@@ -80,7 +80,8 @@ XML(Class_base* c); XML(Class_base* c,const std::string& str); XML(Class_base* c,const pugi::xml_node& _n, XML* parent=NULL, bool fromXMLList=false); - void finalize(); + bool destruct(); + ASFUNCTION(_constructor); ASFUNCTION(_toString); ASFUNCTION(toXMLString); @@ -164,6 +165,7 @@ const tiny_string toXMLString_internal(bool pretty=true, tiny_string defaultnsprefix = "", const char* indent = "", bool bfirst = true); int32_t toInt(); int64_t toInt64(); + number_t toNumber(); bool hasSimpleContent() const; bool hasComplexContent() const; pugi::xml_node_type getNodeKind() const;
View file
lightspark.tar.xz/src/scripting/toplevel/XMLList.cpp
Changed
@@ -80,7 +80,7 @@ } } -void XMLList::finalize() +bool XMLList::destruct() { if (targetobject) targetobject->decRef(); @@ -88,6 +88,7 @@ constructed = false; targetobject = NULL; targetproperty = multiname(this->getClass()->memoryAccount); + return ASObject::destruct(); } void XMLList::sinit(Class_base* c) @@ -1112,6 +1113,12 @@ return 0; return value; } +number_t XMLList::toNumber() +{ + if (!hasSimpleContent()) + return 0; + return parseNumber(toString_priv()); +} ASFUNCTIONBODY(XMLList,_toString) {
View file
lightspark.tar.xz/src/scripting/toplevel/XMLList.h
Changed
@@ -50,7 +50,8 @@ XMLList(Class_base* c,const XML::XMLVector& r); XMLList(Class_base* c,const XML::XMLVector& r,XMLList* targetobject,const multiname& targetproperty); XMLList(Class_base* c,const std::string& str); - void finalize(); + bool destruct(); + static void buildTraits(ASObject* o){} static void sinit(Class_base* c); ASFUNCTION(_constructor); @@ -108,6 +109,7 @@ tiny_string toXMLString_internal(bool pretty=true); int32_t toInt(); int64_t toInt64(); + number_t toNumber(); bool isEqual(ASObject* r); uint32_t nextNameIndex(uint32_t cur_index); _R<ASObject> nextName(uint32_t index);
View file
lightspark.tar.xz/src/scripting/toplevel/toplevel.cpp
Changed
@@ -537,7 +537,7 @@ obj->decRef(); if(ret==NULL) - ret=obj->getSystemState()->getUndefinedRef(); + ret=getSystemState()->getUndefinedRef(); return mi->returnType->coerce(ret); } @@ -695,8 +695,8 @@ void Null::setVariableByMultiname(const multiname& name, ASObject* o, CONST_ALLOWED_FLAG allowConst) { - o->decRef(); LOG(LOG_ERROR,"trying to set variable on null:"<<name<<" value:"<<o->toDebugString()); + o->decRef(); throwError<TypeError>(kConvertNullToObjectError); } @@ -773,20 +773,22 @@ typeObject = Template<Vector>::getTemplateInstance(context->root->getSystemState(),qname,context,context->root->applicationDomain).getPtr(); } } - return typeObject->as<Type>(); + return typeObject ? typeObject->as<Type>() : NULL; } Class_base::Class_base(const QName& name, MemoryAccount* m):ASObject(Class_object::getClass(getSys())),protected_ns(getSys(),"",NAMESPACE),constructor(NULL), - borrowedVariables(m), + freelistsize(0),freelistsize2(0),borrowedVariables(m), context(NULL),class_name(name),memoryAccount(m),length(1),class_index(-1),isFinal(false),isSealed(false),isInterface(false),isReusable(false),isProxy(false),use_protected(false) { + setConstant(); type=T_CLASS; } Class_base::Class_base(const Class_object*):ASObject((MemoryAccount*)NULL),protected_ns(getSys(),BUILTIN_STRINGS::EMPTY,NAMESPACE),constructor(NULL), - borrowedVariables(NULL), + freelistsize(0),freelistsize2(0),borrowedVariables(NULL), context(NULL),class_name(BUILTIN_STRINGS::STRING_CLASS,BUILTIN_STRINGS::EMPTY),memoryAccount(NULL),length(1),class_index(-1),isFinal(false),isSealed(false),isInterface(false),isReusable(false),isProxy(false),use_protected(false) { + setConstant(); type=T_CLASS; //We have tested that (Class is Class == true) so the classdef is 'this' setClass(this); @@ -845,8 +847,9 @@ { if (o->is<Undefined>()) { + ASObject* res = o->getSystemState()->getNullRef(); o->decRef(); - return o->getSystemState()->getNullRef(); + return res; } if(o->is<Null>()) return o; @@ -1057,6 +1060,13 @@ isInterface = false; isProxy = false; use_protected = false; + + for (int i = 0; i < freelistsize; i++) + delete freelist[i]; + freelistsize = 0; + for (int i = 0; i < freelistsize2; i++) + delete freelist2[i]; + freelistsize2 = 0; } Template_base::Template_base(QName name) : ASObject((Class_base*)(NULL)),template_name(name) @@ -2200,9 +2210,14 @@ ASFUNCTIONBODY(lightspark,parseFloat) { tiny_string str; + ARG_UNPACK (str, ""); + + return abstract_d(obj->getSystemState(),parseNumber(str)); +} +number_t lightspark::parseNumber(const tiny_string str) +{ const char *p; char *end; - ARG_UNPACK (str, ""); // parsing of hex numbers is not allowed char* p1 = str.strchr('x'); @@ -2214,9 +2229,9 @@ double d=strtod(p, &end); if (end==p) - return abstract_d(obj->getSystemState(),numeric_limits<double>::quiet_NaN()); + return numeric_limits<double>::quiet_NaN(); - return abstract_d(obj->getSystemState(),d); + return d; } ASFUNCTIONBODY(lightspark,isNaN) @@ -2528,7 +2543,7 @@ traitsInitialized = true; constructIndicator = true; constructorCallComplete = true; - + obj = this; } bool ObjectPrototype::isEqual(ASObject* r) { @@ -2583,6 +2598,7 @@ prevPrototype=p; //Add the prototype to the Nop function this->prototype = _MR(new_asobject(c->getSystemState())); + obj = this; } _NR<ASObject> FunctionPrototype::getVariableByMultiname(const multiname& name, GET_VARIABLE_OPTION opt)
View file
lightspark.tar.xz/src/scripting/toplevel/toplevel.h
Changed
@@ -138,6 +138,7 @@ class Prototype; class ObjectConstructor; +#define FREELIST_SIZE 16 class Class_base: public ASObject, public Type { friend class ABCVm; @@ -156,8 +157,10 @@ Mutex referencedObjectsMutex; boost::intrusive::list<ASObject, boost::intrusive::constant_time_size<false> > referencedObjects; void finalizeObjects(); - std::vector<ASObject*> freelist; - std::vector<ASObject*> freelist2; + ASObject* freelist[FREELIST_SIZE]; + int freelistsize; + ASObject* freelist2[FREELIST_SIZE]; + int freelistsize2; protected: void copyBorrowedTraitsFromSuper(); ASFUNCTION(_toString); @@ -171,11 +174,9 @@ assert_and_throw(isVmThread()); #endif ASObject* ret = NULL; - if (!freelist.empty()) + if (freelistsize) { - ret=freelist.back(); - freelist.pop_back(); - ret->incRef(); + ret=freelist[--freelistsize]; } return ret; } @@ -186,26 +187,38 @@ assert_and_throw(isVmThread()); #endif ASObject* ret = NULL; - if (!freelist2.empty()) + if (freelistsize2) { - ret=freelist2.back(); - freelist2.pop_back(); - ret->incRef(); + ret=freelist2[--freelistsize2]; } return ret; } - inline void pushObjectToFreeList(ASObject *obj) + inline bool pushObjectToFreeList(ASObject *obj) { #ifndef NDEBUG // all ASObjects must be created in the VM thread assert_and_throw(isVmThread()); #endif - assert(obj->getRefCount() == 0); + assert(obj->getRefCount() == 1); if (obj->reusableListNumber == 0) - freelist.push_back(obj); + { + if (freelistsize < FREELIST_SIZE) + { + freelist[freelistsize++]=obj; + return true; + } + return false; + } else - freelist2.push_back(obj); + { + if (freelistsize2 < FREELIST_SIZE) + { + freelist2[freelistsize2++]=obj; + return true; + } + return false; + } } variables_map borrowedVariables; ASPROPERTY_GETTER(_NR<Prototype>,prototype); @@ -327,13 +340,15 @@ class Prototype { +protected: + ASObject* obj; public: Prototype():isSealed(false) {} virtual ~Prototype() {} _NR<Prototype> prevPrototype; - virtual void incRef() = 0; - virtual void decRef() = 0; - virtual ASObject* getObj() = 0; + inline void incRef() { obj->incRef(); } + inline void decRef() { obj->decRef(); } + inline ASObject* getObj() {return obj; } bool isSealed; /* * This method is actually forwarded to the object. It's here as a shorthand. @@ -352,9 +367,6 @@ public: ObjectPrototype(Class_base* c); inline void finalize() { prevPrototype.reset(); } - void incRef() { ASObject::incRef(); } - void decRef() { ASObject::decRef(); } - inline ASObject* getObj() { return this; } _NR<ASObject> getVariableByMultiname(const multiname& name, GET_VARIABLE_OPTION opt=NONE); void setVariableByMultiname(const multiname& name, ASObject* o, CONST_ALLOWED_FLAG allowConst); bool isEqual(ASObject* r); @@ -413,12 +425,13 @@ bool isMethod() const { return inClass != NULL; } bool isBound() const { return closure_this; } bool isConstructed() const { return constructIndicator; } - inline void finalize() + inline bool destruct() { closure_this.reset(); inClass=NULL; functionname=0; length=0; + return ASObject::destruct(); } ASFUNCTION(apply); ASFUNCTION(_call); @@ -506,15 +519,12 @@ { public: FunctionPrototype(Class_base* c, _NR<Prototype> p); - inline void finalize() + inline bool destruct() { - Function::finalize(); prevPrototype.reset(); + return Function::destruct(); } - void incRef() { ASObject::incRef(); } - void decRef() { ASObject::decRef(); } - inline ASObject* getObj() { return this; } _NR<ASObject> getVariableByMultiname(const multiname& name, GET_VARIABLE_OPTION opt=NONE); }; @@ -558,12 +568,12 @@ public: ~SyntheticFunction() {} ASObject* call(ASObject* obj, ASObject* const* args, uint32_t num_args); - inline void finalize() + inline bool destruct() { - IFunction::finalize(); func_scope.reset(); val = NULL; mi = NULL; + return IFunction::destruct(); } _NR<scope_entry_list> func_scope; @@ -790,7 +800,7 @@ ASObject* trace(ASObject* obj,ASObject* const* args, const unsigned int argslen); bool isXMLName(ASObject* obj); ASObject* _isXMLName(ASObject* obj,ASObject* const* args, const unsigned int argslen); - +number_t parseNumber(const tiny_string str); }; #endif /* SCRIPTING_TOPLEVEL_TOPLEVEL_H */
View file
lightspark.tar.xz/src/smartrefs.h
Changed
@@ -29,8 +29,9 @@ class RefCountable { private: ATOMIC_INT32(ref_count); + ACQUIRE_RELEASE_FLAG(isConstant); protected: - RefCountable() : ref_count(1) {} + RefCountable() : ref_count(1),isConstant(false) {} public: virtual ~RefCountable() {} @@ -38,29 +39,44 @@ #ifndef NDEBUG int getRefCount() const { return ref_count; } #endif + inline bool isLastRef() const { return ref_count == 1; } + inline void setConstant() + { + RELEASE_WRITE(isConstant,true); + } + inline void incRef() { - ATOMIC_INCREMENT(ref_count); + if (!isConstant) + ATOMIC_INCREMENT(ref_count); assert(ref_count>0); } inline void decRef() { assert(ref_count>0); - uint32_t t=ATOMIC_DECREMENT(ref_count); - if(t==0) + if (!isConstant) { - destruct(); + if (ref_count == 1) + { + if (destruct()) + { + //Let's make refcount very invalid + ref_count=-1024; + delete this; + } + } + else + ATOMIC_DECREMENT(ref_count); } } inline void fake_decRef() { - ATOMIC_DECREMENT(ref_count); + if (!isConstant) + ATOMIC_DECREMENT(ref_count); } - virtual void destruct() + virtual bool destruct() { - //Let's make refcount very invalid - ref_count=-1024; - delete this; + return true; } }; @@ -106,7 +122,7 @@ return *this; } - template<class D> Ref<T>& operator=(const Ref<D>& r) + template<class D> inline Ref<T>& operator=(const Ref<D>& r) { //incRef before decRef to make sure this works even if the pointer is the same r.m->incRef(); @@ -118,25 +134,25 @@ return *this; } - template<class D> bool operator==(const Ref<D>& r) const + template<class D> inline bool operator==(const Ref<D>& r) const { return m==r.getPtr(); } - template<class D> bool operator!=(const Ref<D>& r) const + template<class D> inline bool operator!=(const Ref<D>& r) const { return m!=r.getPtr(); } - template<class D> bool operator==(const NullableRef<D>&r) const; - bool operator==(T* r) const + template<class D> inline bool operator==(const NullableRef<D>&r) const; + inline bool operator==(T* r) const { return m==r; } //Order operator for Dictionary map - bool operator<(const Ref<T>& r) const + inline bool operator<(const Ref<T>& r) const { return m<r.m; } - template<class D> Ref<D> cast() const + template<class D> inline Ref<D> cast() const { D* p = static_cast<D*>(m); p->incRef(); @@ -201,7 +217,7 @@ //The right hand Ref object is guaranteed to be valid m->incRef(); } - NullableRef<T>& operator=(const NullableRef<T>& r) + inline NullableRef<T>& operator=(const NullableRef<T>& r) { if(r.m) r.m->incRef(); @@ -212,7 +228,7 @@ old->decRef(); return *this; } - template<class D> NullableRef<T>& operator=(const NullableRef<D>& r) + template<class D> inline NullableRef<T>& operator=(const NullableRef<D>& r) { if(r.getPtr()) r->incRef(); @@ -223,7 +239,7 @@ old->decRef(); return *this; } - template<class D> NullableRef<T>& operator=(const Ref<D>& r) + template<class D> inline NullableRef<T>& operator=(const Ref<D>& r) { r.getPtr()->incRef(); @@ -233,37 +249,37 @@ old->decRef(); return *this; } - template<class D> bool operator==(const NullableRef<D>& r) const + template<class D> inline bool operator==(const NullableRef<D>& r) const { return m==r.getPtr(); } - template<class D> bool operator==(const Ref<D>& r) const + template<class D> inline bool operator==(const Ref<D>& r) const { return m==r.getPtr(); } template<class D> - bool operator==(const D* r) const + inline bool operator==(const D* r) const { return m==r; } - bool operator==(NullRef_t) const + inline bool operator==(NullRef_t) const { return m==NULL; } - template<class D> bool operator!=(const NullableRef<D>& r) const + template<class D> inline bool operator!=(const NullableRef<D>& r) const { return m!=r.getPtr(); } - template<class D> bool operator!=(const Ref<D>& r) const + template<class D> inline bool operator!=(const Ref<D>& r) const { return m!=r.getPtr(); } template<class D> - bool operator!=(const D* r) const + inline bool operator!=(const D* r) const { return m!=r; } - bool operator!=(NullRef_t) const + inline bool operator!=(NullRef_t) const { return m!=NULL; } @@ -276,27 +292,27 @@ if(m) m->decRef(); } - T* operator->() const + inline T* operator->() const { if(m != NULL) return m; else throw std::runtime_error("LS smart pointer: NULL pointer access"); } - T* getPtr() const { return m; } - bool isNull() const { return m==NULL; } - void reset() + inline T* getPtr() const { return m; } + inline bool isNull() const { return m==NULL; } + inline void reset() { T* old=m; m=NULL; if(old) old->decRef(); } - void fakeRelease() + inline void fakeRelease() { m=NULL; } - template<class D> NullableRef<D> cast() const + template<class D> inline NullableRef<D> cast() const { if(!m) return NullRef;
View file
lightspark.tar.xz/src/swftypes.h
Changed
@@ -86,6 +86,8 @@ class ASObject; class ASString; class ABCContext; +class URLInfo; +class DisplayObject; struct namespace_info; struct multiname; @@ -387,9 +389,9 @@ /* sets name_type, name_s/name_d based on the object n */ void setName(ASObject* n); void resetNameIfObject(); - bool isQName() const { return ns.size() == 1; } + inline bool isQName() const { return ns.size() == 1; } bool toUInt(SystemState *sys, uint32_t& out, bool acceptStringFractions=false) const; - bool isEmpty() const { return name_type == NAME_OBJECT && name_o == NULL;} + inline bool isEmpty() const { return name_type == NAME_OBJECT && name_o == NULL;} }; class FLOAT @@ -1357,6 +1359,9 @@ std::ostream& operator<<(std::ostream& s, const multiname& r); std::ostream& operator<<(std::ostream& s, const tiny_string& r) DLL_PUBLIC; std::ostream& operator<<(std::ostream& s, const QName& r); +std::ostream& operator<<(std::ostream& s, const MATRIX& r); +std::ostream& operator<<(std::ostream& s, const URLInfo& u); +std::ostream& operator<<(std::ostream& s, const DisplayObject& r); std::istream& operator>>(std::istream& s, RECT& v); std::istream& operator>>(std::istream& s, CLIPEVENTFLAGS& v); @@ -1364,6 +1369,9 @@ std::istream& operator>>(std::istream& s, CLIPACTIONS& v); std::istream& operator>>(std::istream& s, RGB& v); std::istream& operator>>(std::istream& s, RGBA& v); +std::istream& operator>>(std::istream& s, GRADRECORD& v); +std::istream& operator>>(std::istream& s, GRADIENT& v); +std::istream& operator>>(std::istream& s, FOCALGRADIENT& v); std::istream& operator>>(std::istream& stream, SHAPEWITHSTYLE& v); std::istream& operator>>(std::istream& stream, SHAPE& v); std::istream& operator>>(std::istream& stream, FILLSTYLEARRAY& v);
View file
lightspark.tar.xz/src/tiny_string.cpp
Changed
@@ -307,44 +307,6 @@ return !(*this==r); } -const char* tiny_string::raw_buf() const -{ - return buf; -} - -bool tiny_string::empty() const -{ - return stringSize == 1; -} - -/* returns the length in bytes, not counting the trailing \0 */ -uint32_t tiny_string::numBytes() const -{ - return stringSize-1; -} - -/* returns the length in utf-8 characters, not counting the trailing \0 */ -uint32_t tiny_string::numChars() const -{ - return numchars; - /* - if (isASCII) - return stringSize-1; - if (!hasNull) - return g_utf8_strlen(buf,stringSize-1); - //we cannot use g_utf8_strlen, as we may have '\0' inside our string - uint32_t len = 0; - char* end = buf+numBytes(); - char* p = buf; - while(p < end) - { - p = g_utf8_next_char(p); - ++len; - } - return len; - */ -} - char* tiny_string::strchr(char c) const { //TODO: does this handle '\0' in middle of buf gracefully?
View file
lightspark.tar.xz/src/tiny_string.h
Changed
@@ -149,8 +149,14 @@ bool operator!=(const char* r) const; bool operator==(const Glib::ustring&) const; bool operator!=(const Glib::ustring&) const; - const char* raw_buf() const; - bool empty() const; + inline const char* raw_buf() const + { + return buf; + } + inline bool empty() const + { + return stringSize == 1; + } inline void clear() { resetToStatic(); @@ -160,9 +166,16 @@ } /* returns the length in bytes, not counting the trailing \0 */ - uint32_t numBytes() const; + inline uint32_t numBytes() const + { + return stringSize-1; + } /* returns the length in utf-8 characters, not counting the trailing \0 */ - uint32_t numChars() const; + inline uint32_t numChars() const + { + return numchars; + } + /* start and len are indices of utf8-characters */ tiny_string substr(uint32_t start, uint32_t len) const; tiny_string substr(uint32_t start, const CharIterator& end) const;
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.