diff
stringlengths
41
2.03M
msg
stringlengths
1
1.5k
repo
stringlengths
5
40
sha
stringlengths
40
40
time
stringlengths
20
20
mmm a / examples / net_surgery . ipynb <nl> ppp b / examples / net_surgery . ipynb <nl> <nl> { <nl> " metadata " : { <nl> " name " : " Editing model parameters " , <nl> - " description " : " How to do net surgery and manually change model parameters . " , <nl> + " description " : " How to do net surgery and manually change model parameters , making a fully - convolutional classifier for dense feature extraction . " , <nl> " include_in_docs " : true <nl> } , <nl> " nbformat " : 3 , <nl>
[ example ] elaborate net surgery description
BVLC/caffe
0271224513e02c1d1a0421d784b02d8a0e900baf
2014-07-15T14:06:59Z
mmm a / src / runtime / base / fiber_reference_map . cpp <nl> ppp b / src / runtime / base / fiber_reference_map . cpp <nl> void FiberReferenceMap : : unmarshalDynamicGlobals <nl> <nl> FiberAsyncFunc : : Strategy strategy = <nl> ( FiberAsyncFunc : : Strategy ) default_strategy ; <nl> - hphp_string_map < char > : : const_iterator iter = <nl> + hphp_string_map < char > : : const_iterator it = <nl> additional_strategies . find ( fullKey . data ( ) ) ; <nl> - if ( iter ! = additional_strategies . end ( ) ) { <nl> - strategy = ( FiberAsyncFunc : : Strategy ) iter - > second ; <nl> + if ( it ! = additional_strategies . end ( ) ) { <nl> + strategy = ( FiberAsyncFunc : : Strategy ) it - > second ; <nl> } <nl> <nl> Variant & dval = dest . lvalAt ( key . fiberCopy ( ) ) ; <nl>
fixed a compilation error with clang
facebook/hhvm
eb0fecc12e51c3c8e93f5a5c773c8a424479dee0
2010-11-09T13:33:38Z
mmm a / src / compiler / arm / code - generator - arm . cc <nl> ppp b / src / compiler / arm / code - generator - arm . cc <nl> CodeGenerator : : CodeGenResult CodeGenerator : : AssembleArchInstruction ( <nl> i . InputSimd128Register ( 1 ) ) ; <nl> break ; <nl> } <nl> - case kArmSimd32x4Select : { <nl> - / / Select is a ternary op , so we need to move one input into the <nl> - / / destination . Use vtst to canonicalize the ' boolean ' input # 0 . <nl> - __ vtst ( Neon32 , i . OutputSimd128Register ( ) , i . InputSimd128Register ( 0 ) , <nl> - i . InputSimd128Register ( 0 ) ) ; <nl> - __ vbsl ( i . OutputSimd128Register ( ) , i . InputSimd128Register ( 1 ) , <nl> - i . InputSimd128Register ( 2 ) ) ; <nl> - break ; <nl> - } <nl> case kArmInt16x8Splat : { <nl> __ vdup ( Neon16 , i . OutputSimd128Register ( ) , i . InputRegister ( 0 ) ) ; <nl> break ; <nl> CodeGenerator : : CodeGenResult CodeGenerator : : AssembleArchInstruction ( <nl> i . InputSimd128Register ( 1 ) ) ; <nl> break ; <nl> } <nl> + case kArmSimd128And : { <nl> + __ vand ( i . OutputSimd128Register ( ) , i . InputSimd128Register ( 0 ) , <nl> + i . InputSimd128Register ( 1 ) ) ; <nl> + break ; <nl> + } <nl> + case kArmSimd128Or : { <nl> + __ vorr ( i . OutputSimd128Register ( ) , i . InputSimd128Register ( 0 ) , <nl> + i . InputSimd128Register ( 1 ) ) ; <nl> + break ; <nl> + } <nl> + case kArmSimd128Xor : { <nl> + __ veor ( i . OutputSimd128Register ( ) , i . InputSimd128Register ( 0 ) , <nl> + i . InputSimd128Register ( 1 ) ) ; <nl> + break ; <nl> + } <nl> + case kArmSimd128Not : { <nl> + __ vmvn ( i . OutputSimd128Register ( ) , i . InputSimd128Register ( 0 ) ) ; <nl> + break ; <nl> + } <nl> + case kArmSimd32x4Select : { <nl> + / / Canonicalize input 0 lanes to all 0 ' s or all 1 ' s and move to dest . <nl> + __ vtst ( Neon32 , i . OutputSimd128Register ( ) , i . InputSimd128Register ( 0 ) , <nl> + i . InputSimd128Register ( 0 ) ) ; <nl> + __ vbsl ( i . OutputSimd128Register ( ) , i . InputSimd128Register ( 1 ) , <nl> + i . InputSimd128Register ( 2 ) ) ; <nl> + break ; <nl> + } <nl> + case kArmSimd16x8Select : { <nl> + / / Canonicalize input 0 lanes to all 0 ' s or all 1 ' s and move to dest . <nl> + __ vtst ( Neon16 , i . OutputSimd128Register ( ) , i . InputSimd128Register ( 0 ) , <nl> + i . InputSimd128Register ( 0 ) ) ; <nl> + __ vbsl ( i . OutputSimd128Register ( ) , i . InputSimd128Register ( 1 ) , <nl> + i . InputSimd128Register ( 2 ) ) ; <nl> + break ; <nl> + } <nl> + case kArmSimd8x16Select : { <nl> + / / Canonicalize input 0 lanes to all 0 ' s or all 1 ' s and move to dest . <nl> + __ vtst ( Neon8 , i . OutputSimd128Register ( ) , i . InputSimd128Register ( 0 ) , <nl> + i . InputSimd128Register ( 0 ) ) ; <nl> + __ vbsl ( i . OutputSimd128Register ( ) , i . InputSimd128Register ( 1 ) , <nl> + i . InputSimd128Register ( 2 ) ) ; <nl> + break ; <nl> + } <nl> case kCheckedLoadInt8 : <nl> ASSEMBLE_CHECKED_LOAD_INTEGER ( ldrsb ) ; <nl> break ; <nl> mmm a / src / compiler / arm / instruction - codes - arm . h <nl> ppp b / src / compiler / arm / instruction - codes - arm . h <nl> namespace compiler { <nl> V ( ArmUint32x4Max ) \ <nl> V ( ArmUint32x4GreaterThan ) \ <nl> V ( ArmUint32x4GreaterThanOrEqual ) \ <nl> - V ( ArmSimd32x4Select ) \ <nl> V ( ArmInt16x8Splat ) \ <nl> V ( ArmInt16x8ExtractLane ) \ <nl> V ( ArmInt16x8ReplaceLane ) \ <nl> namespace compiler { <nl> V ( ArmUint8x16Min ) \ <nl> V ( ArmUint8x16Max ) \ <nl> V ( ArmUint8x16GreaterThan ) \ <nl> - V ( ArmUint8x16GreaterThanOrEqual ) <nl> + V ( ArmUint8x16GreaterThanOrEqual ) \ <nl> + V ( ArmSimd128And ) \ <nl> + V ( ArmSimd128Or ) \ <nl> + V ( ArmSimd128Xor ) \ <nl> + V ( ArmSimd128Not ) \ <nl> + V ( ArmSimd32x4Select ) \ <nl> + V ( ArmSimd16x8Select ) \ <nl> + V ( ArmSimd8x16Select ) <nl> <nl> / / Addressing modes represent the " shape " of inputs to an instruction . <nl> / / Many instructions support multiple addressing modes . Addressing modes <nl> mmm a / src / compiler / arm / instruction - scheduler - arm . cc <nl> ppp b / src / compiler / arm / instruction - scheduler - arm . cc <nl> int InstructionScheduler : : GetTargetInstructionFlags ( <nl> case kArmUint32x4Max : <nl> case kArmUint32x4GreaterThan : <nl> case kArmUint32x4GreaterThanOrEqual : <nl> - case kArmSimd32x4Select : <nl> case kArmInt16x8Splat : <nl> case kArmInt16x8ExtractLane : <nl> case kArmInt16x8ReplaceLane : <nl> int InstructionScheduler : : GetTargetInstructionFlags ( <nl> case kArmUint8x16Max : <nl> case kArmUint8x16GreaterThan : <nl> case kArmUint8x16GreaterThanOrEqual : <nl> + case kArmSimd128And : <nl> + case kArmSimd128Or : <nl> + case kArmSimd128Xor : <nl> + case kArmSimd128Not : <nl> + case kArmSimd32x4Select : <nl> + case kArmSimd16x8Select : <nl> + case kArmSimd8x16Select : <nl> return kNoOpcodeFlags ; <nl> <nl> case kArmVldrF32 : <nl> mmm a / src / compiler / arm / instruction - selector - arm . cc <nl> ppp b / src / compiler / arm / instruction - selector - arm . cc <nl> void VisitRRR ( InstructionSelector * selector , ArchOpcode opcode , Node * node ) { <nl> g . UseRegister ( node - > InputAt ( 1 ) ) ) ; <nl> } <nl> <nl> + void VisitRRRR ( InstructionSelector * selector , ArchOpcode opcode , Node * node ) { <nl> + ArmOperandGenerator g ( selector ) ; <nl> + selector - > Emit ( <nl> + opcode , g . DefineAsRegister ( node ) , g . UseRegister ( node - > InputAt ( 0 ) ) , <nl> + g . UseRegister ( node - > InputAt ( 1 ) ) , g . UseRegister ( node - > InputAt ( 2 ) ) ) ; <nl> + } <nl> + <nl> void VisitRRI ( InstructionSelector * selector , ArchOpcode opcode , Node * node ) { <nl> ArmOperandGenerator g ( selector ) ; <nl> int32_t imm = OpParameter < int32_t > ( node ) ; <nl> void InstructionSelector : : VisitAtomicStore ( Node * node ) { <nl> V ( Int16x8 ) \ <nl> V ( Int8x16 ) <nl> <nl> + # define SIMD_FORMAT_LIST ( V ) \ <nl> + V ( 32x4 ) \ <nl> + V ( 16x8 ) \ <nl> + V ( 8x16 ) <nl> + <nl> # define SIMD_UNOP_LIST ( V ) \ <nl> V ( Float32x4FromInt32x4 ) \ <nl> V ( Float32x4FromUint32x4 ) \ <nl> void InstructionSelector : : VisitAtomicStore ( Node * node ) { <nl> V ( Uint32x4FromFloat32x4 ) \ <nl> V ( Int32x4Neg ) \ <nl> V ( Int16x8Neg ) \ <nl> - V ( Int8x16Neg ) <nl> + V ( Int8x16Neg ) \ <nl> + V ( Simd128Not ) <nl> <nl> # define SIMD_BINOP_LIST ( V ) \ <nl> V ( Float32x4Add ) \ <nl> void InstructionSelector : : VisitAtomicStore ( Node * node ) { <nl> V ( Uint8x16Min ) \ <nl> V ( Uint8x16Max ) \ <nl> V ( Uint8x16GreaterThan ) \ <nl> - V ( Uint8x16GreaterThanOrEqual ) <nl> + V ( Uint8x16GreaterThanOrEqual ) \ <nl> + V ( Simd128And ) \ <nl> + V ( Simd128Or ) \ <nl> + V ( Simd128Xor ) <nl> <nl> # define SIMD_SHIFT_OP_LIST ( V ) \ <nl> V ( Int32x4ShiftLeftByScalar ) \ <nl> SIMD_BINOP_LIST ( SIMD_VISIT_BINOP ) <nl> SIMD_SHIFT_OP_LIST ( SIMD_VISIT_SHIFT_OP ) <nl> # undef SIMD_VISIT_SHIFT_OP <nl> <nl> - void InstructionSelector : : VisitSimd32x4Select ( Node * node ) { <nl> - ArmOperandGenerator g ( this ) ; <nl> - Emit ( kArmSimd32x4Select , g . DefineAsRegister ( node ) , <nl> - g . UseRegister ( node - > InputAt ( 0 ) ) , g . UseRegister ( node - > InputAt ( 1 ) ) , <nl> - g . UseRegister ( node - > InputAt ( 2 ) ) ) ; <nl> - } <nl> + # define SIMD_VISIT_SELECT_OP ( format ) \ <nl> + void InstructionSelector : : VisitSimd # # format # # Select ( Node * node ) { \ <nl> + VisitRRRR ( this , kArmSimd # # format # # Select , node ) ; \ <nl> + } <nl> + SIMD_FORMAT_LIST ( SIMD_VISIT_SELECT_OP ) <nl> + # undef SIMD_VISIT_SELECT_OP <nl> <nl> / / static <nl> MachineOperatorBuilder : : Flags <nl> mmm a / src / compiler / instruction - codes . h <nl> ppp b / src / compiler / instruction - codes . h <nl> typedef int32_t InstructionCode ; <nl> / / for code generation . We encode the instruction , addressing mode , and flags <nl> / / continuation into a single InstructionCode which is stored as part of <nl> / / the instruction . <nl> - typedef BitField < ArchOpcode , 0 , 8 > ArchOpcodeField ; <nl> - typedef BitField < AddressingMode , 8 , 5 > AddressingModeField ; <nl> - typedef BitField < FlagsMode , 13 , 3 > FlagsModeField ; <nl> - typedef BitField < FlagsCondition , 16 , 5 > FlagsConditionField ; <nl> - typedef BitField < int , 21 , 11 > MiscField ; <nl> + typedef BitField < ArchOpcode , 0 , 9 > ArchOpcodeField ; <nl> + typedef BitField < AddressingMode , 9 , 5 > AddressingModeField ; <nl> + typedef BitField < FlagsMode , 14 , 3 > FlagsModeField ; <nl> + typedef BitField < FlagsCondition , 17 , 5 > FlagsConditionField ; <nl> + typedef BitField < int , 22 , 10 > MiscField ; <nl> <nl> } / / namespace compiler <nl> } / / namespace internal <nl> mmm a / src / compiler / instruction - selector . cc <nl> ppp b / src / compiler / instruction - selector . cc <nl> void InstructionSelector : : VisitNode ( Node * node ) { <nl> return MarkAsSimd128 ( node ) , VisitUint32x4GreaterThan ( node ) ; <nl> case IrOpcode : : kUint32x4GreaterThanOrEqual : <nl> return MarkAsSimd128 ( node ) , VisitUint32x4GreaterThanOrEqual ( node ) ; <nl> - case IrOpcode : : kSimd32x4Select : <nl> - return MarkAsSimd128 ( node ) , VisitSimd32x4Select ( node ) ; <nl> case IrOpcode : : kCreateInt16x8 : <nl> return MarkAsSimd128 ( node ) , VisitCreateInt16x8 ( node ) ; <nl> case IrOpcode : : kInt16x8ExtractLane : <nl> void InstructionSelector : : VisitNode ( Node * node ) { <nl> return MarkAsSimd128 ( node ) , VisitUint8x16GreaterThan ( node ) ; <nl> case IrOpcode : : kUint8x16GreaterThanOrEqual : <nl> return MarkAsSimd128 ( node ) , VisitUint16x8GreaterThanOrEqual ( node ) ; <nl> + case IrOpcode : : kSimd128And : <nl> + return MarkAsSimd128 ( node ) , VisitSimd128And ( node ) ; <nl> + case IrOpcode : : kSimd128Or : <nl> + return MarkAsSimd128 ( node ) , VisitSimd128Or ( node ) ; <nl> + case IrOpcode : : kSimd128Xor : <nl> + return MarkAsSimd128 ( node ) , VisitSimd128Xor ( node ) ; <nl> + case IrOpcode : : kSimd128Not : <nl> + return MarkAsSimd128 ( node ) , VisitSimd128Not ( node ) ; <nl> + case IrOpcode : : kSimd32x4Select : <nl> + return MarkAsSimd128 ( node ) , VisitSimd32x4Select ( node ) ; <nl> + case IrOpcode : : kSimd16x8Select : <nl> + return MarkAsSimd128 ( node ) , VisitSimd16x8Select ( node ) ; <nl> + case IrOpcode : : kSimd8x16Select : <nl> + return MarkAsSimd128 ( node ) , VisitSimd8x16Select ( node ) ; <nl> default : <nl> V8_Fatal ( __FILE__ , __LINE__ , " Unexpected operator # % d : % s @ node # % d " , <nl> node - > opcode ( ) , node - > op ( ) - > mnemonic ( ) , node - > id ( ) ) ; <nl> void InstructionSelector : : VisitUint32x4GreaterThanOrEqual ( Node * node ) { <nl> UNIMPLEMENTED ( ) ; <nl> } <nl> <nl> - void InstructionSelector : : VisitSimd32x4Select ( Node * node ) { UNIMPLEMENTED ( ) ; } <nl> - <nl> void InstructionSelector : : VisitCreateInt16x8 ( Node * node ) { UNIMPLEMENTED ( ) ; } <nl> <nl> void InstructionSelector : : VisitInt16x8ExtractLane ( Node * node ) { <nl> void InstructionSelector : : VisitUint8x16GreaterThan ( Node * node ) { <nl> void InstructionSelector : : VisitUint8x16GreaterThanOrEqual ( Node * node ) { <nl> UNIMPLEMENTED ( ) ; <nl> } <nl> + <nl> + void InstructionSelector : : VisitSimd32x4Select ( Node * node ) { UNIMPLEMENTED ( ) ; } <nl> + <nl> + void InstructionSelector : : VisitSimd16x8Select ( Node * node ) { UNIMPLEMENTED ( ) ; } <nl> + <nl> + void InstructionSelector : : VisitSimd8x16Select ( Node * node ) { UNIMPLEMENTED ( ) ; } <nl> + <nl> + void InstructionSelector : : VisitSimd128And ( Node * node ) { UNIMPLEMENTED ( ) ; } <nl> + <nl> + void InstructionSelector : : VisitSimd128Or ( Node * node ) { UNIMPLEMENTED ( ) ; } <nl> + <nl> + void InstructionSelector : : VisitSimd128Xor ( Node * node ) { UNIMPLEMENTED ( ) ; } <nl> + <nl> + void InstructionSelector : : VisitSimd128Not ( Node * node ) { UNIMPLEMENTED ( ) ; } <nl> # endif / / ! V8_TARGET_ARCH_ARM <nl> <nl> void InstructionSelector : : VisitFinishRegion ( Node * node ) { EmitIdentity ( node ) ; } <nl> mmm a / src / compiler / machine - operator . cc <nl> ppp b / src / compiler / machine - operator . cc <nl> MachineRepresentation AtomicStoreRepresentationOf ( Operator const * op ) { <nl> V ( Int16x8LessThanOrEqual , Operator : : kNoProperties , 2 , 0 , 1 ) \ <nl> V ( Int16x8GreaterThan , Operator : : kNoProperties , 2 , 0 , 1 ) \ <nl> V ( Int16x8GreaterThanOrEqual , Operator : : kNoProperties , 2 , 0 , 1 ) \ <nl> - V ( Int16x8Select , Operator : : kNoProperties , 3 , 0 , 1 ) \ <nl> - V ( Int16x8Swizzle , Operator : : kNoProperties , 9 , 0 , 1 ) \ <nl> - V ( Int16x8Shuffle , Operator : : kNoProperties , 10 , 0 , 1 ) \ <nl> V ( Uint16x8AddSaturate , Operator : : kCommutative , 2 , 0 , 1 ) \ <nl> V ( Uint16x8SubSaturate , Operator : : kNoProperties , 2 , 0 , 1 ) \ <nl> V ( Uint16x8Min , Operator : : kCommutative , 2 , 0 , 1 ) \ <nl> MachineRepresentation AtomicStoreRepresentationOf ( Operator const * op ) { <nl> V ( Int8x16LessThanOrEqual , Operator : : kNoProperties , 2 , 0 , 1 ) \ <nl> V ( Int8x16GreaterThan , Operator : : kNoProperties , 2 , 0 , 1 ) \ <nl> V ( Int8x16GreaterThanOrEqual , Operator : : kNoProperties , 2 , 0 , 1 ) \ <nl> - V ( Int8x16Select , Operator : : kNoProperties , 3 , 0 , 1 ) \ <nl> - V ( Int8x16Swizzle , Operator : : kNoProperties , 17 , 0 , 1 ) \ <nl> - V ( Int8x16Shuffle , Operator : : kNoProperties , 18 , 0 , 1 ) \ <nl> V ( Uint8x16AddSaturate , Operator : : kCommutative , 2 , 0 , 1 ) \ <nl> V ( Uint8x16SubSaturate , Operator : : kNoProperties , 2 , 0 , 1 ) \ <nl> V ( Uint8x16Min , Operator : : kCommutative , 2 , 0 , 1 ) \ <nl> MachineRepresentation AtomicStoreRepresentationOf ( Operator const * op ) { <nl> V ( Simd128Xor , Operator : : kAssociative | Operator : : kCommutative , 2 , 0 , 1 ) \ <nl> V ( Simd128Not , Operator : : kNoProperties , 1 , 0 , 1 ) \ <nl> V ( Simd32x4Select , Operator : : kNoProperties , 3 , 0 , 1 ) \ <nl> - V ( Simd32x4Swizzle , Operator : : kNoProperties , 5 , 0 , 1 ) \ <nl> - V ( Simd32x4Shuffle , Operator : : kNoProperties , 6 , 0 , 1 ) <nl> + V ( Simd16x8Select , Operator : : kNoProperties , 3 , 0 , 1 ) \ <nl> + V ( Simd8x16Select , Operator : : kNoProperties , 3 , 0 , 1 ) <nl> <nl> # define PURE_OPTIONAL_OP_LIST ( V ) \ <nl> V ( Word32Ctz , Operator : : kNoProperties , 1 , 0 , 1 ) \ <nl> MachineRepresentation AtomicStoreRepresentationOf ( Operator const * op ) { <nl> V ( Int8x16 , 16 ) \ <nl> V ( Bool8x16 , 16 ) <nl> <nl> - # define SIMD_SHIFT_OP_LIST ( V ) \ <nl> - V ( 32x4 , 32 ) \ <nl> - V ( 16x8 , 16 ) \ <nl> + # define SIMD_FORMAT_LIST ( V ) \ <nl> + V ( 32x4 , 32 ) \ <nl> + V ( 16x8 , 16 ) \ <nl> V ( 8x16 , 8 ) <nl> <nl> # define STACK_SLOT_CACHED_SIZES_LIST ( V ) V ( 4 ) V ( 8 ) V ( 16 ) <nl> SIMD_LANE_OP_LIST ( SIMD_LANE_OPS ) <nl> IrOpcode : : kUint # # format # # ShiftRightByScalar , Operator : : kPure , \ <nl> " Shift right " , 1 , 0 , 0 , 1 , 0 , 0 , shift ) ; \ <nl> } <nl> - SIMD_SHIFT_OP_LIST ( SIMD_SHIFT_OPS ) <nl> + SIMD_FORMAT_LIST ( SIMD_SHIFT_OPS ) <nl> # undef SIMD_SHIFT_OPS <nl> <nl> + / / TODO ( bbudge ) Add Shuffle , DCHECKs based on format . <nl> + # define SIMD_PERMUTE_OPS ( format , bits ) \ <nl> + const Operator * MachineOperatorBuilder : : Simd # # format # # Swizzle ( \ <nl> + uint32_t swizzle ) { \ <nl> + return new ( zone_ ) \ <nl> + Operator1 < uint32_t > ( IrOpcode : : kSimd # # format # # Swizzle , Operator : : kPure , \ <nl> + " Swizzle " , 2 , 0 , 0 , 1 , 0 , 0 , swizzle ) ; \ <nl> + } <nl> + SIMD_FORMAT_LIST ( SIMD_PERMUTE_OPS ) <nl> + # undef SIMD_PERMUTE_OPS <nl> + <nl> } / / namespace compiler <nl> } / / namespace internal <nl> } / / namespace v8 <nl> mmm a / src / compiler / machine - operator . h <nl> ppp b / src / compiler / machine - operator . h <nl> class V8_EXPORT_PRIVATE MachineOperatorBuilder final <nl> const Operator * Int16x8LessThanOrEqual ( ) ; <nl> const Operator * Int16x8GreaterThan ( ) ; <nl> const Operator * Int16x8GreaterThanOrEqual ( ) ; <nl> - const Operator * Int16x8Select ( ) ; <nl> - const Operator * Int16x8Swizzle ( ) ; <nl> - const Operator * Int16x8Shuffle ( ) ; <nl> <nl> const Operator * Uint16x8AddSaturate ( ) ; <nl> const Operator * Uint16x8SubSaturate ( ) ; <nl> class V8_EXPORT_PRIVATE MachineOperatorBuilder final <nl> const Operator * Int8x16LessThanOrEqual ( ) ; <nl> const Operator * Int8x16GreaterThan ( ) ; <nl> const Operator * Int8x16GreaterThanOrEqual ( ) ; <nl> - const Operator * Int8x16Select ( ) ; <nl> - const Operator * Int8x16Swizzle ( ) ; <nl> - const Operator * Int8x16Shuffle ( ) ; <nl> <nl> const Operator * Uint8x16AddSaturate ( ) ; <nl> const Operator * Uint8x16SubSaturate ( ) ; <nl> class V8_EXPORT_PRIVATE MachineOperatorBuilder final <nl> const Operator * Simd128Xor ( ) ; <nl> const Operator * Simd128Not ( ) ; <nl> const Operator * Simd32x4Select ( ) ; <nl> - const Operator * Simd32x4Swizzle ( ) ; <nl> + const Operator * Simd32x4Swizzle ( uint32_t ) ; <nl> const Operator * Simd32x4Shuffle ( ) ; <nl> + const Operator * Simd16x8Select ( ) ; <nl> + const Operator * Simd16x8Swizzle ( uint32_t ) ; <nl> + const Operator * Simd16x8Shuffle ( ) ; <nl> + const Operator * Simd8x16Select ( ) ; <nl> + const Operator * Simd8x16Swizzle ( uint32_t ) ; <nl> + const Operator * Simd8x16Shuffle ( ) ; <nl> <nl> / / load [ base + index ] <nl> const Operator * Load ( LoadRepresentation rep ) ; <nl> mmm a / src / compiler / opcodes . h <nl> ppp b / src / compiler / opcodes . h <nl> <nl> V ( Int16x8LessThanOrEqual ) \ <nl> V ( Int16x8GreaterThan ) \ <nl> V ( Int16x8GreaterThanOrEqual ) \ <nl> - V ( Int16x8Select ) \ <nl> - V ( Int16x8Swizzle ) \ <nl> - V ( Int16x8Shuffle ) \ <nl> V ( Uint16x8AddSaturate ) \ <nl> V ( Uint16x8SubSaturate ) \ <nl> V ( Uint16x8Min ) \ <nl> <nl> V ( Int8x16LessThanOrEqual ) \ <nl> V ( Int8x16GreaterThan ) \ <nl> V ( Int8x16GreaterThanOrEqual ) \ <nl> - V ( Int8x16Select ) \ <nl> - V ( Int8x16Swizzle ) \ <nl> - V ( Int8x16Shuffle ) \ <nl> V ( Uint8x16AddSaturate ) \ <nl> V ( Uint8x16SubSaturate ) \ <nl> V ( Uint8x16Min ) \ <nl> <nl> V ( Bool8x16Swizzle ) \ <nl> V ( Bool8x16Shuffle ) \ <nl> V ( Bool8x16Equal ) \ <nl> - V ( Bool8x16NotEqual ) <nl> + V ( Bool8x16NotEqual ) \ <nl> + V ( Simd128And ) \ <nl> + V ( Simd128Or ) \ <nl> + V ( Simd128Xor ) \ <nl> + V ( Simd128Not ) \ <nl> + V ( Simd32x4Select ) \ <nl> + V ( Simd32x4Swizzle ) \ <nl> + V ( Simd32x4Shuffle ) \ <nl> + V ( Simd16x8Select ) \ <nl> + V ( Simd16x8Swizzle ) \ <nl> + V ( Simd16x8Shuffle ) \ <nl> + V ( Simd8x16Select ) \ <nl> + V ( Simd8x16Swizzle ) \ <nl> + V ( Simd8x16Shuffle ) <nl> <nl> # define MACHINE_SIMD_RETURN_NUM_OP_LIST ( V ) \ <nl> V ( Float32x4ExtractLane ) \ <nl> <nl> V ( Simd128Store ) \ <nl> V ( Simd128Store1 ) \ <nl> V ( Simd128Store2 ) \ <nl> - V ( Simd128Store3 ) \ <nl> - V ( Simd128And ) \ <nl> - V ( Simd128Or ) \ <nl> - V ( Simd128Xor ) \ <nl> - V ( Simd128Not ) \ <nl> - V ( Simd32x4Select ) \ <nl> - V ( Simd32x4Swizzle ) \ <nl> - V ( Simd32x4Shuffle ) <nl> + V ( Simd128Store3 ) <nl> <nl> # define MACHINE_SIMD_OP_LIST ( V ) \ <nl> MACHINE_SIMD_RETURN_SIMD_OP_LIST ( V ) \ <nl> mmm a / src / compiler / wasm - compiler . cc <nl> ppp b / src / compiler / wasm - compiler . cc <nl> Node * WasmGraphBuilder : : SimdOp ( wasm : : WasmOpcode opcode , <nl> return graph ( ) - > NewNode ( <nl> jsgraph ( ) - > machine ( ) - > Uint32x4GreaterThanOrEqual ( ) , inputs [ 0 ] , <nl> inputs [ 1 ] ) ; <nl> - case wasm : : kExprS32x4Select : <nl> - return graph ( ) - > NewNode ( jsgraph ( ) - > machine ( ) - > Simd32x4Select ( ) , inputs [ 0 ] , <nl> - inputs [ 1 ] , inputs [ 2 ] ) ; <nl> case wasm : : kExprI16x8Splat : <nl> return graph ( ) - > NewNode ( jsgraph ( ) - > machine ( ) - > CreateInt16x8 ( ) , inputs [ 0 ] , <nl> inputs [ 0 ] , inputs [ 0 ] , inputs [ 0 ] , inputs [ 0 ] , <nl> Node * WasmGraphBuilder : : SimdOp ( wasm : : WasmOpcode opcode , <nl> return graph ( ) - > NewNode ( <nl> jsgraph ( ) - > machine ( ) - > Uint8x16GreaterThanOrEqual ( ) , inputs [ 0 ] , <nl> inputs [ 1 ] ) ; <nl> + case wasm : : kExprS32x4Select : <nl> + return graph ( ) - > NewNode ( jsgraph ( ) - > machine ( ) - > Simd32x4Select ( ) , inputs [ 0 ] , <nl> + inputs [ 1 ] , inputs [ 2 ] ) ; <nl> + case wasm : : kExprS16x8Select : <nl> + return graph ( ) - > NewNode ( jsgraph ( ) - > machine ( ) - > Simd16x8Select ( ) , inputs [ 0 ] , <nl> + inputs [ 1 ] , inputs [ 2 ] ) ; <nl> + case wasm : : kExprS8x16Select : <nl> + return graph ( ) - > NewNode ( jsgraph ( ) - > machine ( ) - > Simd8x16Select ( ) , inputs [ 0 ] , <nl> + inputs [ 1 ] , inputs [ 2 ] ) ; <nl> + case wasm : : kExprS128And : <nl> + return graph ( ) - > NewNode ( jsgraph ( ) - > machine ( ) - > Simd128And ( ) , inputs [ 0 ] , <nl> + inputs [ 1 ] ) ; <nl> + case wasm : : kExprS128Or : <nl> + return graph ( ) - > NewNode ( jsgraph ( ) - > machine ( ) - > Simd128Or ( ) , inputs [ 0 ] , <nl> + inputs [ 1 ] ) ; <nl> + case wasm : : kExprS128Xor : <nl> + return graph ( ) - > NewNode ( jsgraph ( ) - > machine ( ) - > Simd128Xor ( ) , inputs [ 0 ] , <nl> + inputs [ 1 ] ) ; <nl> + case wasm : : kExprS128Not : <nl> + return graph ( ) - > NewNode ( jsgraph ( ) - > machine ( ) - > Simd128Not ( ) , inputs [ 0 ] ) ; <nl> default : <nl> return graph ( ) - > NewNode ( UnsupportedOpcode ( opcode ) , nullptr ) ; <nl> } <nl> Node * WasmGraphBuilder : : SimdShiftOp ( wasm : : WasmOpcode opcode , uint8_t shift , <nl> } <nl> } <nl> <nl> + Node * WasmGraphBuilder : : SimdSwizzleOp ( wasm : : WasmOpcode opcode , uint32_t swizzle , <nl> + const NodeVector & inputs ) { <nl> + has_simd_ = true ; <nl> + switch ( opcode ) { <nl> + case wasm : : kExprS32x4Swizzle : <nl> + return graph ( ) - > NewNode ( jsgraph ( ) - > machine ( ) - > Simd32x4Swizzle ( swizzle ) , <nl> + inputs [ 0 ] ) ; <nl> + case wasm : : kExprS16x8Swizzle : <nl> + return graph ( ) - > NewNode ( jsgraph ( ) - > machine ( ) - > Simd16x8Swizzle ( swizzle ) , <nl> + inputs [ 0 ] ) ; <nl> + case wasm : : kExprS8x16Swizzle : <nl> + return graph ( ) - > NewNode ( jsgraph ( ) - > machine ( ) - > Simd8x16Swizzle ( swizzle ) , <nl> + inputs [ 0 ] ) ; <nl> + default : <nl> + return graph ( ) - > NewNode ( UnsupportedOpcode ( opcode ) , nullptr ) ; <nl> + } <nl> + } <nl> + <nl> static void RecordFunctionCompilation ( CodeEventListener : : LogEventsAndTags tag , <nl> Isolate * isolate , Handle < Code > code , <nl> const char * message , uint32_t index , <nl> mmm a / src / compiler / wasm - compiler . h <nl> ppp b / src / compiler / wasm - compiler . h <nl> class WasmGraphBuilder { <nl> Node * SimdShiftOp ( wasm : : WasmOpcode opcode , uint8_t shift , <nl> const NodeVector & inputs ) ; <nl> <nl> + Node * SimdSwizzleOp ( wasm : : WasmOpcode opcode , uint32_t swizzle , <nl> + const NodeVector & inputs ) ; <nl> + <nl> bool has_simd ( ) const { return has_simd_ ; } <nl> <nl> wasm : : ModuleEnv * module_env ( ) const { return module_ ; } <nl> mmm a / src / wasm / wasm - macro - gen . h <nl> ppp b / src / wasm / wasm - macro - gen . h <nl> class LocalDeclEncoder { <nl> / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> / / Simd Operations . <nl> / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> - # define WASM_SIMD_F32x4_SPLAT ( x ) x , kSimdPrefix , kExprF32x4Splat & 0xff <nl> - # define WASM_SIMD_F32x4_EXTRACT_LANE ( lane , x ) \ <nl> - x , kSimdPrefix , kExprF32x4ExtractLane & 0xff , static_cast < byte > ( lane ) <nl> - # define WASM_SIMD_F32x4_REPLACE_LANE ( lane , x , y ) \ <nl> - x , y , kSimdPrefix , kExprF32x4ReplaceLane & 0xff , static_cast < byte > ( lane ) <nl> - # define WASM_SIMD_F32x4_FROM_I32x4 ( x ) \ <nl> - x , kSimdPrefix , kExprF32x4SConvertI32x4 & 0xff <nl> - # define WASM_SIMD_F32x4_FROM_U32x4 ( x ) \ <nl> - x , kSimdPrefix , kExprF32x4UConvertI32x4 & 0xff <nl> - # define WASM_SIMD_F32x4_ADD ( x , y ) x , y , kSimdPrefix , kExprF32x4Add & 0xff <nl> - # define WASM_SIMD_F32x4_SUB ( x , y ) x , y , kSimdPrefix , kExprF32x4Sub & 0xff <nl> - <nl> - # define WASM_SIMD_I32x4_SPLAT ( x ) x , kSimdPrefix , kExprI32x4Splat & 0xff <nl> - # define WASM_SIMD_I32x4_EXTRACT_LANE ( lane , x ) \ <nl> - x , kSimdPrefix , kExprI32x4ExtractLane & 0xff , static_cast < byte > ( lane ) <nl> - # define WASM_SIMD_I32x4_REPLACE_LANE ( lane , x , y ) \ <nl> - x , y , kSimdPrefix , kExprI32x4ReplaceLane & 0xff , static_cast < byte > ( lane ) <nl> - # define WASM_SIMD_I32x4_FROM_F32x4 ( x ) \ <nl> - x , kSimdPrefix , kExprI32x4SConvertF32x4 & 0xff <nl> - # define WASM_SIMD_U32x4_FROM_F32x4 ( x ) \ <nl> - x , kSimdPrefix , kExprI32x4UConvertF32x4 & 0xff <nl> - # define WASM_SIMD_S32x4_SELECT ( x , y , z ) \ <nl> - x , y , z , kSimdPrefix , kExprS32x4Select & 0xff <nl> - # define WASM_SIMD_I32x4_ADD ( x , y ) x , y , kSimdPrefix , kExprI32x4Add & 0xff <nl> - # define WASM_SIMD_I32x4_SUB ( x , y ) x , y , kSimdPrefix , kExprI32x4Sub & 0xff <nl> - <nl> - # define WASM_SIMD_I16x8_SPLAT ( x ) x , kSimdPrefix , kExprI16x8Splat & 0xff <nl> - # define WASM_SIMD_I16x8_EXTRACT_LANE ( lane , x ) \ <nl> - x , kSimdPrefix , kExprI16x8ExtractLane & 0xff , static_cast < byte > ( lane ) <nl> - # define WASM_SIMD_I16x8_REPLACE_LANE ( lane , x , y ) \ <nl> - x , y , kSimdPrefix , kExprI16x8ReplaceLane & 0xff , static_cast < byte > ( lane ) <nl> - <nl> - # define WASM_SIMD_I8x16_SPLAT ( x ) x , kSimdPrefix , kExprI8x16Splat & 0xff <nl> - # define WASM_SIMD_I8x16_EXTRACT_LANE ( lane , x ) \ <nl> - x , kSimdPrefix , kExprI8x16ExtractLane & 0xff , static_cast < byte > ( lane ) <nl> - # define WASM_SIMD_I8x16_REPLACE_LANE ( lane , x , y ) \ <nl> - x , y , kSimdPrefix , kExprI8x16ReplaceLane & 0xff , static_cast < byte > ( lane ) <nl> + / / TODO ( bbudge ) Migrate these into tests . <nl> + # define WASM_SIMD_F32x4_SPLAT ( x ) \ <nl> + x , kSimdPrefix , static_cast < byte > ( kExprF32x4Splat ) <nl> + # define WASM_SIMD_F32x4_EXTRACT_LANE ( lane , x ) \ <nl> + x , kSimdPrefix , static_cast < byte > ( kExprF32x4ExtractLane ) , \ <nl> + static_cast < byte > ( lane ) <nl> + # define WASM_SIMD_F32x4_REPLACE_LANE ( lane , x , y ) \ <nl> + x , y , kSimdPrefix , static_cast < byte > ( kExprF32x4ReplaceLane ) , \ <nl> + static_cast < byte > ( lane ) <nl> + # define WASM_SIMD_F32x4_ADD ( x , y ) \ <nl> + x , y , kSimdPrefix , static_cast < byte > ( kExprF32x4Add ) <nl> + # define WASM_SIMD_F32x4_SUB ( x , y ) \ <nl> + x , y , kSimdPrefix , static_cast < byte > ( kExprF32x4Sub ) <nl> + <nl> + # define WASM_SIMD_I32x4_SPLAT ( x ) \ <nl> + x , kSimdPrefix , static_cast < byte > ( kExprI32x4Splat ) <nl> + # define WASM_SIMD_I32x4_EXTRACT_LANE ( lane , x ) \ <nl> + x , kSimdPrefix , static_cast < byte > ( kExprI32x4ExtractLane ) , \ <nl> + static_cast < byte > ( lane ) <nl> + # define WASM_SIMD_I32x4_REPLACE_LANE ( lane , x , y ) \ <nl> + x , y , kSimdPrefix , static_cast < byte > ( kExprI32x4ReplaceLane ) , \ <nl> + static_cast < byte > ( lane ) <nl> + # define WASM_SIMD_I32x4_ADD ( x , y ) \ <nl> + x , y , kSimdPrefix , static_cast < byte > ( kExprI32x4Add ) <nl> + # define WASM_SIMD_I32x4_SUB ( x , y ) \ <nl> + x , y , kSimdPrefix , static_cast < byte > ( kExprI32x4Sub ) <nl> <nl> # define SIG_ENTRY_v_v kWasmFunctionTypeForm , 0 , 0 <nl> # define SIZEOF_SIG_ENTRY_v_v 3 <nl> mmm a / src / wasm / wasm - opcodes . cc <nl> ppp b / src / wasm / wasm - opcodes . cc <nl> typedef Signature < ValueType > FunctionSig ; <nl> # define CASE_I16x8_OP ( name , str ) CASE_OP ( I16x8 # # name , " i16x8 . " str ) <nl> # define CASE_I8x16_OP ( name , str ) CASE_OP ( I8x16 # # name , " i8x16 . " str ) <nl> # define CASE_S32x4_OP ( name , str ) CASE_OP ( S32x4 # # name , " s32x4 . " str ) <nl> + # define CASE_S16x8_OP ( name , str ) CASE_OP ( S16x8 # # name , " s16x8 . " str ) <nl> + # define CASE_S8x16_OP ( name , str ) CASE_OP ( S8x16 # # name , " s8x16 . " str ) <nl> # define CASE_INT_OP ( name , str ) CASE_I32_OP ( name , str ) CASE_I64_OP ( name , str ) <nl> # define CASE_FLOAT_OP ( name , str ) CASE_F32_OP ( name , str ) CASE_F64_OP ( name , str ) <nl> # define CASE_ALL_OP ( name , str ) CASE_FLOAT_OP ( name , str ) CASE_INT_OP ( name , str ) <nl> const char * WasmOpcodes : : OpcodeName ( WasmOpcode opcode ) { <nl> CASE_F32x4_OP ( Gt , " gt " ) <nl> CASE_F32x4_OP ( Ge , " ge " ) <nl> CASE_CONVERT_OP ( Convert , F32x4 , I32x4 , " i32 " , " convert " ) <nl> + CASE_CONVERT_OP ( Convert , I32x4 , F32x4 , " f32 " , " convert " ) <nl> CASE_F32x4_OP ( ExtractLane , " extract_lane " ) <nl> CASE_F32x4_OP ( ReplaceLane , " replace_lane " ) <nl> CASE_SIMDI_OP ( ExtractLane , " extract_lane " ) <nl> const char * WasmOpcodes : : OpcodeName ( WasmOpcode opcode ) { <nl> CASE_SIGN_OP ( SIMDI , Ge , " ge " ) <nl> CASE_SIGN_OP ( SIMDI , Shr , " shr " ) <nl> CASE_SIMDI_OP ( Shl , " shl " ) <nl> - CASE_SIMDI_OP ( Swizzle , " swizzle " ) <nl> - CASE_SIMDI_OP ( Shuffle , " shuffle " ) <nl> - CASE_SIMDI_OP ( Select , " select " ) <nl> - CASE_S128_OP ( Ior , " or " ) <nl> + CASE_SIGN_OP ( I16x8 , AddSaturate , " add_saturate " ) <nl> + CASE_SIGN_OP ( I8x16 , AddSaturate , " add_saturate " ) <nl> + CASE_SIGN_OP ( I16x8 , SubSaturate , " sub_saturate " ) <nl> + CASE_SIGN_OP ( I8x16 , SubSaturate , " sub_saturate " ) <nl> + CASE_S128_OP ( Or , " or " ) <nl> CASE_S128_OP ( Xor , " xor " ) <nl> CASE_S128_OP ( And , " and " ) <nl> CASE_S128_OP ( Not , " not " ) <nl> CASE_S32x4_OP ( Select , " select " ) <nl> CASE_S32x4_OP ( Swizzle , " swizzle " ) <nl> CASE_S32x4_OP ( Shuffle , " shuffle " ) <nl> - CASE_CONVERT_OP ( Convert , I32x4 , F32x4 , " f32 " , " convert " ) <nl> - CASE_SIGN_OP ( I16x8 , AddSaturate , " add_saturate " ) <nl> - CASE_SIGN_OP ( I8x16 , AddSaturate , " add_saturate " ) <nl> - CASE_SIGN_OP ( I16x8 , SubSaturate , " sub_saturate " ) <nl> - CASE_SIGN_OP ( I8x16 , SubSaturate , " sub_saturate " ) <nl> + CASE_S16x8_OP ( Select , " select " ) <nl> + CASE_S16x8_OP ( Swizzle , " swizzle " ) <nl> + CASE_S16x8_OP ( Shuffle , " shuffle " ) <nl> + CASE_S8x16_OP ( Select , " select " ) <nl> + CASE_S8x16_OP ( Swizzle , " swizzle " ) <nl> + CASE_S8x16_OP ( Shuffle , " shuffle " ) <nl> <nl> / / Atomic operations . <nl> CASE_L32_OP ( AtomicAdd , " atomic_add " ) <nl> mmm a / src / wasm / wasm - opcodes . h <nl> ppp b / src / wasm / wasm - opcodes . h <nl> const WasmCodePosition kNoCodePosition = - 1 ; <nl> V ( I32x4LeS , 0xe529 , s_ss ) \ <nl> V ( I32x4GtS , 0xe52a , s_ss ) \ <nl> V ( I32x4GeS , 0xe52b , s_ss ) \ <nl> - V ( I32x4Select , 0xe52c , s_sss ) \ <nl> - V ( I32x4Swizzle , 0xe52d , s_s ) \ <nl> - V ( I32x4Shuffle , 0xe52e , s_ss ) \ <nl> V ( I32x4SConvertF32x4 , 0xe52f , s_s ) \ <nl> V ( I32x4MinU , 0xe530 , s_ss ) \ <nl> V ( I32x4MaxU , 0xe531 , s_ss ) \ <nl> const WasmCodePosition kNoCodePosition = - 1 ; <nl> V ( I16x8LeS , 0xe548 , s_ss ) \ <nl> V ( I16x8GtS , 0xe549 , s_ss ) \ <nl> V ( I16x8GeS , 0xe54a , s_ss ) \ <nl> - V ( I16x8Select , 0xe54b , s_sss ) \ <nl> - V ( I16x8Swizzle , 0xe54c , s_s ) \ <nl> - V ( I16x8Shuffle , 0xe54d , s_ss ) \ <nl> V ( I16x8AddSaturateU , 0xe54e , s_ss ) \ <nl> V ( I16x8SubSaturateU , 0xe54f , s_ss ) \ <nl> V ( I16x8MinU , 0xe550 , s_ss ) \ <nl> const WasmCodePosition kNoCodePosition = - 1 ; <nl> V ( I8x16LeS , 0xe567 , s_ss ) \ <nl> V ( I8x16GtS , 0xe568 , s_ss ) \ <nl> V ( I8x16GeS , 0xe569 , s_ss ) \ <nl> - V ( I8x16Select , 0xe56a , s_sss ) \ <nl> - V ( I8x16Swizzle , 0xe56b , s_s ) \ <nl> - V ( I8x16Shuffle , 0xe56c , s_ss ) \ <nl> V ( I8x16AddSaturateU , 0xe56d , s_ss ) \ <nl> V ( I8x16SubSaturateU , 0xe56e , s_ss ) \ <nl> V ( I8x16MinU , 0xe56f , s_ss ) \ <nl> const WasmCodePosition kNoCodePosition = - 1 ; <nl> V ( I8x16GtU , 0xe574 , s_ss ) \ <nl> V ( I8x16GeU , 0xe575 , s_ss ) \ <nl> V ( S128And , 0xe576 , s_ss ) \ <nl> - V ( S128Ior , 0xe577 , s_ss ) \ <nl> + V ( S128Or , 0xe577 , s_ss ) \ <nl> V ( S128Xor , 0xe578 , s_ss ) \ <nl> V ( S128Not , 0xe579 , s_s ) \ <nl> - V ( S32x4Select , 0xe580 , s_sss ) \ <nl> - V ( S32x4Swizzle , 0xe581 , s_s ) \ <nl> - V ( S32x4Shuffle , 0xe582 , s_ss ) <nl> + V ( S32x4Select , 0xe52c , s_sss ) \ <nl> + V ( S32x4Swizzle , 0xe52d , s_s ) \ <nl> + V ( S32x4Shuffle , 0xe52e , s_ss ) \ <nl> + V ( S16x8Select , 0xe54b , s_sss ) \ <nl> + V ( S16x8Swizzle , 0xe54c , s_s ) \ <nl> + V ( S16x8Shuffle , 0xe54d , s_ss ) \ <nl> + V ( S8x16Select , 0xe56a , s_sss ) \ <nl> + V ( S8x16Swizzle , 0xe56b , s_s ) \ <nl> + V ( S8x16Shuffle , 0xe56c , s_ss ) <nl> <nl> # define FOREACH_SIMD_1_OPERAND_OPCODE ( V ) \ <nl> V ( F32x4ExtractLane , 0xe501 , _ ) \ <nl> mmm a / test / cctest / wasm / test - run - wasm - simd . cc <nl> ppp b / test / cctest / wasm / test - run - wasm - simd . cc <nl> T UnsignedSubSaturate ( T a , T b ) { <nl> return Clamp < UnsignedT > ( UnsignedWiden ( a ) - UnsignedWiden ( b ) ) ; <nl> } <nl> <nl> + template < typename T > <nl> + T And ( T a , T b ) { <nl> + return a & b ; <nl> + } <nl> + <nl> + template < typename T > <nl> + T Or ( T a , T b ) { <nl> + return a | b ; <nl> + } <nl> + <nl> + template < typename T > <nl> + T Xor ( T a , T b ) { <nl> + return a ^ b ; <nl> + } <nl> + <nl> + template < typename T > <nl> + T Not ( T a ) { <nl> + return ~ a ; <nl> + } <nl> + <nl> } / / namespace <nl> <nl> / / TODO ( gdeepti ) : These are tests using sample values to verify functional <nl> T UnsignedSubSaturate ( T a , T b ) { <nl> # define WASM_SIMD_CHECK_SPLAT4_F32 ( TYPE , value , lv ) \ <nl> WASM_SIMD_CHECK4_F32 ( TYPE , value , lv , lv , lv , lv ) <nl> <nl> - # define WASM_SIMD_UNOP ( opcode , x ) x , kSimdPrefix , static_cast < byte > ( opcode ) <nl> - # define WASM_SIMD_BINOP ( opcode , x , y ) \ <nl> - x , y , kSimdPrefix , static_cast < byte > ( opcode ) <nl> - # define WASM_SIMD_SHIFT_OP ( opcode , x , shift ) \ <nl> - x , kSimdPrefix , static_cast < byte > ( opcode ) , static_cast < byte > ( shift ) <nl> + # define TO_BYTE ( val ) static_cast < byte > ( val ) <nl> + # define WASM_SIMD_OP ( op ) kSimdPrefix , TO_BYTE ( op ) <nl> + # define WASM_SIMD_UNOP ( op , x ) x , WASM_SIMD_OP ( op ) <nl> + # define WASM_SIMD_BINOP ( op , x , y ) x , y , WASM_SIMD_OP ( op ) <nl> + # define WASM_SIMD_SHIFT_OP ( op , shift , x ) x , WASM_SIMD_OP ( op ) , TO_BYTE ( shift ) <nl> + # define WASM_SIMD_SELECT ( format , x , y , z ) \ <nl> + x , y , z , WASM_SIMD_OP ( kExprS # # format # # Select ) <nl> + <nl> + # define WASM_SIMD_I16x8_SPLAT ( x ) x , WASM_SIMD_OP ( kExprI16x8Splat ) <nl> + # define WASM_SIMD_I16x8_EXTRACT_LANE ( lane , x ) \ <nl> + x , WASM_SIMD_OP ( kExprI16x8ExtractLane ) , TO_BYTE ( lane ) <nl> + # define WASM_SIMD_I16x8_REPLACE_LANE ( lane , x , y ) \ <nl> + x , y , WASM_SIMD_OP ( kExprI16x8ReplaceLane ) , TO_BYTE ( lane ) <nl> + # define WASM_SIMD_I8x16_SPLAT ( x ) x , WASM_SIMD_OP ( kExprI8x16Splat ) <nl> + # define WASM_SIMD_I8x16_EXTRACT_LANE ( lane , x ) \ <nl> + x , WASM_SIMD_OP ( kExprI8x16ExtractLane ) , TO_BYTE ( lane ) <nl> + # define WASM_SIMD_I8x16_REPLACE_LANE ( lane , x , y ) \ <nl> + x , y , WASM_SIMD_OP ( kExprI8x16ReplaceLane ) , TO_BYTE ( lane ) <nl> + <nl> + # define WASM_SIMD_F32x4_FROM_I32x4 ( x ) x , WASM_SIMD_OP ( kExprF32x4SConvertI32x4 ) <nl> + # define WASM_SIMD_F32x4_FROM_U32x4 ( x ) x , WASM_SIMD_OP ( kExprF32x4UConvertI32x4 ) <nl> + # define WASM_SIMD_I32x4_FROM_F32x4 ( x ) x , WASM_SIMD_OP ( kExprI32x4SConvertF32x4 ) <nl> + # define WASM_SIMD_U32x4_FROM_F32x4 ( x ) x , WASM_SIMD_OP ( kExprI32x4UConvertF32x4 ) <nl> <nl> # if V8_TARGET_ARCH_ARM <nl> WASM_EXEC_TEST ( F32x4Splat ) { <nl> WASM_EXEC_TEST ( F32x4FromInt32x4 ) { <nl> } <nl> } <nl> <nl> - WASM_EXEC_TEST ( S32x4Select ) { <nl> - FLAG_wasm_simd_prototype = true ; <nl> - WasmRunner < int32_t , int32_t , int32_t > r ( kExecuteCompiled ) ; <nl> - byte val1 = 0 ; <nl> - byte val2 = 1 ; <nl> - byte mask = r . AllocateLocal ( kWasmS128 ) ; <nl> - byte src1 = r . AllocateLocal ( kWasmS128 ) ; <nl> - byte src2 = r . AllocateLocal ( kWasmS128 ) ; <nl> - BUILD ( r , <nl> - <nl> - WASM_SET_LOCAL ( mask , WASM_SIMD_I32x4_SPLAT ( WASM_ZERO ) ) , <nl> - WASM_SET_LOCAL ( src1 , WASM_SIMD_I32x4_SPLAT ( WASM_GET_LOCAL ( val1 ) ) ) , <nl> - WASM_SET_LOCAL ( src2 , WASM_SIMD_I32x4_SPLAT ( WASM_GET_LOCAL ( val2 ) ) ) , <nl> - WASM_SET_LOCAL ( mask , WASM_SIMD_I32x4_REPLACE_LANE ( <nl> - 1 , WASM_GET_LOCAL ( mask ) , WASM_I32V ( - 1 ) ) ) , <nl> - WASM_SET_LOCAL ( mask , WASM_SIMD_I32x4_REPLACE_LANE ( <nl> - 2 , WASM_GET_LOCAL ( mask ) , WASM_I32V ( - 1 ) ) ) , <nl> - WASM_SET_LOCAL ( mask , WASM_SIMD_S32x4_SELECT ( WASM_GET_LOCAL ( mask ) , <nl> - WASM_GET_LOCAL ( src1 ) , <nl> - WASM_GET_LOCAL ( src2 ) ) ) , <nl> - WASM_SIMD_CHECK_LANE ( I32x4 , mask , I32 , val2 , 0 ) , <nl> - WASM_SIMD_CHECK_LANE ( I32x4 , mask , I32 , val1 , 1 ) , <nl> - WASM_SIMD_CHECK_LANE ( I32x4 , mask , I32 , val1 , 2 ) , <nl> - WASM_SIMD_CHECK_LANE ( I32x4 , mask , I32 , val2 , 3 ) , WASM_ONE ) ; <nl> - <nl> - CHECK_EQ ( 1 , r . Call ( 0x1234 , 0x5678 ) ) ; <nl> - } <nl> - <nl> void RunF32x4UnOpTest ( WasmOpcode simd_op , FloatUnOp expected_op ) { <nl> FLAG_wasm_simd_prototype = true ; <nl> WasmRunner < int32_t , float , float > r ( kExecuteCompiled ) ; <nl> void RunI32x4UnOpTest ( WasmOpcode simd_op , Int32UnOp expected_op ) { <nl> } <nl> <nl> WASM_EXEC_TEST ( I32x4Neg ) { RunI32x4UnOpTest ( kExprI32x4Neg , Negate ) ; } <nl> + <nl> + WASM_EXEC_TEST ( S128Not ) { RunI32x4UnOpTest ( kExprS128Not , Not ) ; } <nl> # endif / / V8_TARGET_ARCH_ARM <nl> <nl> void RunI32x4BinOpTest ( WasmOpcode simd_op , Int32BinOp expected_op ) { <nl> WASM_EXEC_TEST ( Ui32x4LessEqual ) { <nl> RunI32x4BinOpTest ( kExprI32x4LeU , UnsignedLessEqual ) ; <nl> } <nl> <nl> + WASM_EXEC_TEST ( S128And ) { RunI32x4BinOpTest ( kExprS128And , And ) ; } <nl> + <nl> + WASM_EXEC_TEST ( S128Or ) { RunI32x4BinOpTest ( kExprS128Or , Or ) ; } <nl> + <nl> + WASM_EXEC_TEST ( S128Xor ) { RunI32x4BinOpTest ( kExprS128Xor , Xor ) ; } <nl> + <nl> void RunI32x4ShiftOpTest ( WasmOpcode simd_op , Int32ShiftOp expected_op , <nl> int shift ) { <nl> FLAG_wasm_simd_prototype = true ; <nl> void RunI32x4ShiftOpTest ( WasmOpcode simd_op , Int32ShiftOp expected_op , <nl> byte simd = r . AllocateLocal ( kWasmS128 ) ; <nl> BUILD ( r , WASM_SET_LOCAL ( simd , WASM_SIMD_I32x4_SPLAT ( WASM_GET_LOCAL ( a ) ) ) , <nl> WASM_SET_LOCAL ( <nl> - simd , WASM_SIMD_SHIFT_OP ( simd_op , WASM_GET_LOCAL ( simd ) , shift ) ) , <nl> + simd , WASM_SIMD_SHIFT_OP ( simd_op , shift , WASM_GET_LOCAL ( simd ) ) ) , <nl> WASM_SIMD_CHECK_SPLAT4 ( I32x4 , simd , I32 , expected ) , WASM_ONE ) ; <nl> <nl> FOR_INT32_INPUTS ( i ) { CHECK_EQ ( 1 , r . Call ( * i , expected_op ( * i , shift ) ) ) ; } <nl> void RunI16x8ShiftOpTest ( WasmOpcode simd_op , Int16ShiftOp expected_op , <nl> byte simd = r . AllocateLocal ( kWasmS128 ) ; <nl> BUILD ( r , WASM_SET_LOCAL ( simd , WASM_SIMD_I16x8_SPLAT ( WASM_GET_LOCAL ( a ) ) ) , <nl> WASM_SET_LOCAL ( <nl> - simd , WASM_SIMD_SHIFT_OP ( simd_op , WASM_GET_LOCAL ( simd ) , shift ) ) , <nl> + simd , WASM_SIMD_SHIFT_OP ( simd_op , shift , WASM_GET_LOCAL ( simd ) ) ) , <nl> WASM_SIMD_CHECK_SPLAT8 ( I16x8 , simd , I32 , expected ) , WASM_ONE ) ; <nl> <nl> FOR_INT16_INPUTS ( i ) { CHECK_EQ ( 1 , r . Call ( * i , expected_op ( * i , shift ) ) ) ; } <nl> void RunI8x16ShiftOpTest ( WasmOpcode simd_op , Int8ShiftOp expected_op , <nl> byte simd = r . AllocateLocal ( kWasmS128 ) ; <nl> BUILD ( r , WASM_SET_LOCAL ( simd , WASM_SIMD_I8x16_SPLAT ( WASM_GET_LOCAL ( a ) ) ) , <nl> WASM_SET_LOCAL ( <nl> - simd , WASM_SIMD_SHIFT_OP ( simd_op , WASM_GET_LOCAL ( simd ) , shift ) ) , <nl> + simd , WASM_SIMD_SHIFT_OP ( simd_op , shift , WASM_GET_LOCAL ( simd ) ) ) , <nl> WASM_SIMD_CHECK_SPLAT16 ( I8x16 , simd , I32 , expected ) , WASM_ONE ) ; <nl> <nl> FOR_INT8_INPUTS ( i ) { CHECK_EQ ( 1 , r . Call ( * i , expected_op ( * i , shift ) ) ) ; } <nl> WASM_EXEC_TEST ( I8x16ShrS ) { <nl> WASM_EXEC_TEST ( I8x16ShrU ) { <nl> RunI8x16ShiftOpTest ( kExprI8x16ShrU , LogicalShiftRight , 1 ) ; <nl> } <nl> + <nl> + # define WASM_SIMD_SELECT_TEST ( format ) \ <nl> + WASM_EXEC_TEST ( S # # format # # Select ) { \ <nl> + FLAG_wasm_simd_prototype = true ; \ <nl> + WasmRunner < int32_t , int32_t , int32_t > r ( kExecuteCompiled ) ; \ <nl> + byte val1 = 0 ; \ <nl> + byte val2 = 1 ; \ <nl> + byte mask = r . AllocateLocal ( kWasmS128 ) ; \ <nl> + byte src1 = r . AllocateLocal ( kWasmS128 ) ; \ <nl> + byte src2 = r . AllocateLocal ( kWasmS128 ) ; \ <nl> + BUILD ( r , WASM_SET_LOCAL ( mask , WASM_SIMD_I # # format # # _SPLAT ( WASM_ZERO ) ) , \ <nl> + WASM_SET_LOCAL ( src1 , \ <nl> + WASM_SIMD_I # # format # # _SPLAT ( WASM_GET_LOCAL ( val1 ) ) ) , \ <nl> + WASM_SET_LOCAL ( src2 , \ <nl> + WASM_SIMD_I # # format # # _SPLAT ( WASM_GET_LOCAL ( val2 ) ) ) , \ <nl> + WASM_SET_LOCAL ( mask , WASM_SIMD_I # # format # # _REPLACE_LANE ( \ <nl> + 1 , WASM_GET_LOCAL ( mask ) , WASM_I32V ( - 1 ) ) ) , \ <nl> + WASM_SET_LOCAL ( mask , WASM_SIMD_I # # format # # _REPLACE_LANE ( \ <nl> + 2 , WASM_GET_LOCAL ( mask ) , WASM_I32V ( - 1 ) ) ) , \ <nl> + WASM_SET_LOCAL ( mask , WASM_SIMD_SELECT ( format , WASM_GET_LOCAL ( mask ) , \ <nl> + WASM_GET_LOCAL ( src1 ) , \ <nl> + WASM_GET_LOCAL ( src2 ) ) ) , \ <nl> + WASM_SIMD_CHECK_LANE ( I # # format , mask , I32 , val2 , 0 ) , \ <nl> + WASM_SIMD_CHECK_LANE ( I # # format , mask , I32 , val1 , 1 ) , \ <nl> + WASM_SIMD_CHECK_LANE ( I # # format , mask , I32 , val1 , 2 ) , \ <nl> + WASM_SIMD_CHECK_LANE ( I # # format , mask , I32 , val2 , 3 ) , WASM_ONE ) ; \ <nl> + \ <nl> + CHECK_EQ ( 1 , r . Call ( 0x12 , 0x34 ) ) ; \ <nl> + } <nl> + <nl> + WASM_SIMD_SELECT_TEST ( 32x4 ) <nl> + WASM_SIMD_SELECT_TEST ( 16x8 ) <nl> + WASM_SIMD_SELECT_TEST ( 8x16 ) <nl> # endif / / V8_TARGET_ARCH_ARM <nl>
[ Turbofan ] Add more non - arithmetic SIMD operations .
v8/v8
11f88ef53f8e7c5aecfccd52e2a076a73efd413a
2017-02-13T20:24:43Z
mmm a / src / cpp / thread_manager / thread_manager . cc <nl> ppp b / src / cpp / thread_manager / thread_manager . cc <nl> <nl> namespace grpc { <nl> <nl> ThreadManager : : WorkerThread : : WorkerThread ( ThreadManager * thd_mgr ) <nl> - : thd_mgr_ ( thd_mgr ) , <nl> - thd_ ( & ThreadManager : : WorkerThread : : Run , this ) { } <nl> + : thd_mgr_ ( thd_mgr ) , thd_ ( & ThreadManager : : WorkerThread : : Run , this ) { } <nl> <nl> void ThreadManager : : WorkerThread : : Run ( ) { <nl> thd_mgr_ - > MainWorkLoop ( ) ; <nl> thd_mgr_ - > MarkAsCompleted ( this ) ; <nl> } <nl> <nl> - ThreadManager : : WorkerThread : : ~ WorkerThread ( ) { <nl> - thd_ . join ( ) ; <nl> - } <nl> + ThreadManager : : WorkerThread : : ~ WorkerThread ( ) { thd_ . join ( ) ; } <nl> <nl> ThreadManager : : ThreadManager ( int min_pollers , int max_pollers ) <nl> : shutdown_ ( false ) , <nl> mmm a / test / cpp / thread_manager / thread_manager_test . cc <nl> ppp b / test / cpp / thread_manager / thread_manager_test . cc <nl> grpc : : ThreadManager : : WorkStatus ThreadManagerTest : : PollForWork ( void * * tag , <nl> <nl> void ThreadManagerTest : : DoWork ( void * tag , bool ok ) { <nl> num_do_work_ + + ; <nl> - SleepForMs ( kDoWorkDurationMsec ) ; / / Simulate doing work by sleeping <nl> + SleepForMs ( kDoWorkDurationMsec ) ; / / Simulate doing work by sleeping <nl> } <nl> <nl> void ThreadManagerTest : : PerformTest ( ) { <nl>
clang formatting fixes
grpc/grpc
85399f082442c290be81fc6d3323e53acceaa66a
2016-10-24T16:41:20Z
mmm a / admin / static / coffee / dataexplorer . coffee <nl> ppp b / admin / static / coffee / dataexplorer . coffee <nl> module ' DataExplorerView ' , - > <nl> else # The user wants suggestion <nl> if event . which is 27 # ESC <nl> event . preventDefault ( ) # Keep focus on code mirror <nl> + @ current_suggestions . length = 0 # Let ' s get rid of suggestions <nl> @ hide_suggestion_and_description ( ) <nl> return true <nl> else if event . which is 13 and ( event . shiftKey is false and event . ctrlKey is false and event . metaKey is false ) <nl>
Fix issue with ESC / Tab behavior . Related to and
rethinkdb/rethinkdb
a6a0ed5a4d3f35d024b2c5d84462ce6b3ee0a75b
2013-04-16T23:31:58Z
mmm a / . travis . yml <nl> ppp b / . travis . yml <nl> before_install : <nl> - sudo apt - get - y install wget git curl python - dev python - numpy libprotobuf - dev libleveldb - dev libsnappy - dev libopencv - dev libboost - all - dev libhdf5 - serial - dev protobuf - compiler libatlas - dev libatlas - base - dev bc <nl> <nl> install : <nl> + # CMake 2 . 8 . 12 <nl> + - wget http : / / www . cmake . org / files / v2 . 8 / cmake - 2 . 8 . 12 . tar . gz - O / tmp / cmake . tar . gz & & tar - C / tmp - xvf / tmp / cmake . tar . gz & & rm / tmp / cmake . tar . gz <nl> + - cd / tmp / cmake - 2 . 8 . 12 & & . / bootstrap - - prefix = / usr & & make - j4 & & sudo make install - j4 & & cd - # & & rm - r / tmp / cmake - 2 . 8 . 12 <nl> + # <nl> - wget https : / / google - glog . googlecode . com / files / glog - 0 . 3 . 3 . tar . gz - O / tmp / glog - 0 . 3 . 3 . tar . gz & & tar - C / tmp - xzvf / tmp / glog - 0 . 3 . 3 . tar . gz & & rm / tmp / glog - 0 . 3 . 3 . tar . gz <nl> - - cd / tmp / glog - 0 . 3 . 3 & & . / configure & & make & & sudo make install & & cd - <nl> + - cd / tmp / glog - 0 . 3 . 3 & & . / configure & & make - j4 & & sudo make install - j4 & & cd - <nl> - wget https : / / github . com / schuhschuh / gflags / archive / master . zip - O / tmp / gflags - master . zip & & pushd / tmp / & & unzip gflags - master . zip & & cd gflags - master & & mkdir build & & cd build & & export CXXFLAGS = " - fPIC " & & cmake . . & & make VERBOSE = 1 & & sudo make install & & popd <nl> - curl http : / / developer . download . nvidia . com / compute / cuda / repos / ubuntu1204 / x86_64 / cuda - repo - ubuntu1204_6 . 0 - 37_amd64 . deb - o / tmp / cuda_install . deb & & sudo dpkg - i / tmp / cuda_install . deb & & rm / tmp / cuda_install . deb <nl> - sudo apt - get - y update <nl> install : <nl> # manually since we did a partial installation . ) <nl> - sudo ln - s / usr / local / cuda - 6 . 0 / usr / local / cuda <nl> - curl https : / / gitorious . org / mdb / mdb / archive / 7f038d0f15bec57b4c07aa3f31cd5564c88a1897 . tar . gz - o / tmp / mdb . tar . gz & & tar - C / tmp - xzvf / tmp / mdb . tar . gz & & rm / tmp / mdb . tar . gz <nl> - - cd / tmp / mdb - mdb / libraries / liblmdb / & & make & & sudo make install & & cd - <nl> + - cd / tmp / mdb - mdb / libraries / liblmdb / & & make - j4 & & sudo make install - j4 & & cd - <nl> <nl> before_script : <nl> - mv Makefile . config . example Makefile . config <nl> before_script : <nl> - export NUM_THREADS = 4 <nl> <nl> script : <nl> - # CPU - GPU : build only . <nl> - - export CPU_ONLY = 0 <nl> - - make - - keep - going - - jobs = $ NUM_THREADS all <nl> + # CMake build . <nl> + - mkdir build <nl> + - cd build <nl> + # # CPU - only build <nl> + # - cmake - DBUILD_PYTHON = ON - DBUILD_EXAMPLES = ON - DCMAKE_BUILD_TYPE = Release - DCPU_ONLY = ON . . <nl> + # - make - - keep - going - - jobs = $ NUM_THREADS <nl> + # - make clean <nl> + # - rm - rf * <nl> + # # GPU + CPU build <nl> + - cmake - DBUILD_PYTHON = ON - DBUILD_EXAMPLES = ON - DCMAKE_BUILD_TYPE = Release . . <nl> + - make - - keep - going - - jobs = $ NUM_THREADS <nl> - make clean <nl> - # CPU - only : comprehensive . <nl> - - export CPU_ONLY = 1 <nl> - - make - - keep - going - - jobs = $ NUM_THREADS all test warn lint <nl> - - make runtest <nl> - - make - - jobs = $ NUM_THREADS all <nl> - - make - - jobs = $ NUM_THREADS test <nl> - - make - - jobs = $ NUM_THREADS warn <nl> - - make - - jobs = $ NUM_THREADS lint <nl> - - make - - jobs = $ NUM_THREADS pycaffe <nl> + - cd . . <nl> + - rm - r build <nl> + <nl> + # # CPU - GPU : build only . <nl> + # - export CPU_ONLY = 0 <nl> + # - make - - keep - going - - jobs = $ NUM_THREADS all <nl> + # - make clean <nl> + # # CPU - only : comprehensive . <nl> + # - export CPU_ONLY = 1 <nl> + # - make - - keep - going - - jobs = $ NUM_THREADS all test warn lint <nl> + # - make runtest <nl> + # - make - - jobs = $ NUM_THREADS all <nl> + # - make - - jobs = $ NUM_THREADS test <nl> + # - make - - jobs = $ NUM_THREADS warn <nl> + # - make - - jobs = $ NUM_THREADS lint <nl> + # - make - - jobs = $ NUM_THREADS pycaffe <nl> <nl> notifications : <nl> # Emails are sent to the committer ' s git - configured email address by default , <nl> mmm a / CMakeLists . txt <nl> ppp b / CMakeLists . txt <nl> <nl> - cmake_minimum_required ( VERSION 2 . 8 ) <nl> + cmake_minimum_required ( VERSION 2 . 8 . 8 ) <nl> project ( Caffe ) <nl> <nl> # # # Build Options # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> enable_testing ( ) <nl> # Compiler Flags <nl> set ( CMAKE_CXX_COMPILER_FLAGS $ { CMAKE_CXX_COMPILER_FLAGS } - Wall ) <nl> set ( CMAKE_CXX_FLAGS $ { CMAKE_CXX_FLAGS } - fPIC ) <nl> - set ( CMAKE_CXX_FLAGS_RELEASE $ { CMAKE_CXX_FLAGS_RELEASE } - O3 ) <nl> + set ( CMAKE_CXX_FLAGS_RELEASE $ { CMAKE_CXX_FLAGS_RELEASE } ) # - O3 ) <nl> <nl> # Include Directories <nl> set ( $ { PROJECT_NAME } _INCLUDE_DIRS $ { CMAKE_SOURCE_DIR } / include ) <nl> set ( CMAKE_MODULE_PATH $ { CMAKE_MODULE_PATH } $ { CMAKE_SOURCE_DIR } / CMakeScripts ) <nl> find_package ( CUDA 5 . 5 REQUIRED ) <nl> include_directories ( $ { CUDA_INCLUDE_DIRS } ) <nl> <nl> - <nl> # # # Subdirectories # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> <nl> add_subdirectory ( src / gtest ) <nl> new file mode 100644 <nl> index 00000000000 . . d769b442812 <nl> mmm / dev / null <nl> ppp b / CMakeScripts / FindSnappy . cmake <nl> <nl> + # Find the Snappy libraries <nl> + # <nl> + # The following variables are optionally searched for defaults <nl> + # Snappy_ROOT_DIR : Base directory where all Snappy components are found <nl> + # <nl> + # The following are set after configuration is done : <nl> + # Snappy_FOUND <nl> + # Snappy_INCLUDE_DIRS <nl> + # Snappy_LIBS <nl> + <nl> + find_path ( SNAPPY_INCLUDE_DIR <nl> + NAMES snappy . h <nl> + HINTS $ { SNAPPY_ROOT_DIR } <nl> + $ { SNAPPY_ROOT_DIR } / include <nl> + ) <nl> + <nl> + find_library ( SNAPPY_LIBS <nl> + NAMES snappy <nl> + HINTS $ { SNAPPY_ROOT_DIR } <nl> + $ { SNAPPY_ROOT_DIR } / lib <nl> + ) <nl> + <nl> + include ( FindPackageHandleStandardArgs ) <nl> + find_package_handle_standard_args ( Snappy <nl> + DEFAULT_MSG <nl> + SNAPPY_LIBS <nl> + SNAPPY_INCLUDE_DIR <nl> + ) <nl> + <nl> + mark_as_advanced ( <nl> + SNAPPY_LIBS <nl> + SNAPPY_INCLUDE_DIR <nl> + ) <nl> mmm a / python / CMakeLists . txt <nl> ppp b / python / CMakeLists . txt <nl> find_package ( PythonLibs REQUIRED ) <nl> include_directories ( $ { PYTHON_INCLUDE_DIRS } ) <nl> <nl> # Boost . Python <nl> - find_package ( Boost 1 . 49 COMPONENTS python REQUIRED ) <nl> + find_package ( Boost 1 . 46 COMPONENTS python REQUIRED ) <nl> include_directories ( $ { Boost_INCLUDE_DIRS } ) <nl> <nl> file ( GLOB_RECURSE Python_SOURCES $ { CMAKE_CURRENT_SOURCE_DIR } / * . cpp ) <nl> mmm a / src / caffe / CMakeLists . txt <nl> ppp b / src / caffe / CMakeLists . txt <nl> include_directories ( $ { OpenCV_INCLUDE_DIRS } ) <nl> # LevelDB <nl> find_package ( LevelDB REQUIRED ) <nl> include_directories ( $ { LEVELDB_INCLUDE } ) <nl> + if ( LEVELDB_FOUND ) <nl> + find_package ( Snappy REQUIRED ) <nl> + include_directories ( $ { SNAPPY_INCLUDE_DIR } ) <nl> + set ( LEVELDB_LIBS <nl> + $ { LEVELDB_LIBS } <nl> + $ { SNAPPY_LIBS } <nl> + ) <nl> + endif ( ) <nl> <nl> # LMDB <nl> find_package ( LMDB REQUIRED ) <nl> add_dependencies ( caffe_cu proto ) <nl> <nl> target_link_libraries ( caffe caffe_cu proto <nl> $ { GLOG_LIBRARIES } <nl> - $ { CUDA_curand_LIBRARY } <nl> $ { HDF5_LIBRARIES } <nl> $ { OpenCV_LIBS } <nl> $ { LEVELDB_LIBS } <nl> $ { LMDB_LIBRARIES } <nl> $ { CUDA_CUBLAS_LIBRARIES } <nl> + $ { CUDA_curand_LIBRARY } <nl> $ { BLAS_LIBRARIES } <nl> $ { CMAKE_THREAD_LIBS_INIT } <nl> ) <nl> mmm a / src / caffe / proto / CMakeLists . txt <nl> ppp b / src / caffe / proto / CMakeLists . txt <nl> <nl> - cmake_minimum_required ( VERSION 2 . 8 ) <nl> project ( Proto ) <nl> <nl> # Google Protocol Buffers <nl> add_library ( proto <nl> <nl> target_link_libraries ( proto $ { PROTOBUF_LIBRARIES } ) <nl> <nl> + # Create proto include directory <nl> + file ( MAKE_DIRECTORY $ { CMAKE_SOURCE_DIR } / include / caffe / proto ) <nl> + <nl> # Copy proto headers to include / caffe / proto / <nl> foreach ( header $ { ProtoHeaders } ) <nl> <nl> mmm a / src / caffe / test / CMakeLists . txt <nl> ppp b / src / caffe / test / CMakeLists . txt <nl> <nl> # All test files ' names must begin with a " test_ " prefix <nl> # <nl> # <nl> - cmake_minimum_required ( VERSION 2 . 8 ) <nl> project ( Test ) <nl> <nl> # Set CUDA Device number and CMAKE_SOURCE_DIR <nl>
cmake build configuration for travis - ci
BVLC/caffe
a2a4d636c9cb4a8f071b1703acfe0aeb6f8d7771
2014-08-17T08:07:16Z
mmm a / scene / gui / grid_container . cpp <nl> ppp b / scene / gui / grid_container . cpp <nl> void GridContainer : : _notification ( int p_what ) { <nl> int hsep = get_constant ( " hseparation " ) ; <nl> int vsep = get_constant ( " vseparation " ) ; <nl> int max_col = MIN ( get_child_count ( ) , columns ) ; <nl> - int max_row = get_child_count ( ) / columns ; <nl> + int max_row = ceil ( ( float ) get_child_count ( ) / ( float ) columns ) ; <nl> <nl> / / Compute the per - column / per - row data <nl> valid_controls_index = 0 ; <nl>
Fix GridContainer ' s children overflowing it when not all slots of a row are occupied
godotengine/godot
07f3a129c66d2139655cf7a741a4e37db415b088
2019-09-28T05:57:11Z
mmm a / bindings / python / cntk / ops / __init__ . py <nl> ppp b / bindings / python / cntk / ops / __init__ . py <nl> def dropout ( x , dropout_rate = 0 . 0 , name = ' ' ) : <nl> <nl> <nl> @ typemap <nl> - def input_variable ( shape , dtype = np . float32 , needs_gradient = True , is_sparse = False , <nl> + def input_variable ( shape , dtype = np . float32 , needs_gradient = False , is_sparse = False , <nl> dynamic_axes = Axis . default_input_variable_dynamic_axes ( ) , name = ' ' ) : <nl> ' ' ' <nl> It creates an input node . <nl> def input_variable ( shape , dtype = np . float32 , needs_gradient = True , is_sparse = False <nl> Args : <nl> shape ( tuple or int ) : the shape of the input tensor <nl> dtype ( type , optional ) : np . float32 ( default ) or np . float64 <nl> - needs_gradients ( bool , optional ) : whether to back - propagates to it or not . True by default . <nl> + needs_gradients ( bool , optional ) : whether to back - propagates to it or not . False by default . <nl> is_sparse ( bool , optional ) : whether the variable is sparse ( ` False ` by default ) <nl> dynamic_axes ( list or tuple , default ) : a list of dynamic axis ( e . g . , batch axis , time axis ) <nl> name ( str , optional ) : the name of the Function instance in the network <nl>
input_variable needs_gradient off by default
microsoft/CNTK
3195785d3363527f47456539cd6fd99436e65a6e
2016-11-23T02:50:14Z
mmm a / tools / run - tests . py <nl> ppp b / tools / run - tests . py <nl> def ProcessOptions ( options ) : <nl> # Buildbots run presubmit tests as a separate step . <nl> options . no_presubmit = True <nl> options . no_network = True <nl> - <nl> - # FIXME ( machenbach ) : Temporary hack to debug landmines on buildbot . <nl> - # Hardcoded for make / ninja . <nl> - src_dir = os . path . dirname ( os . path . dirname ( os . path . realpath ( __file__ ) ) ) <nl> - out_dir = os . path . join ( src_dir , ' out ' , options . mode , ' . landmines ' ) <nl> - if os . path . exists ( out_dir ) : <nl> - print " [ INFO ] Landmines tracker exists . " <nl> if options . command_prefix : <nl> print ( " Specifying - - command - prefix disables network distribution , " <nl> " running tests locally . " ) <nl>
Revert " Add temporary output to debug landmines . "
v8/v8
b59ed8d062b0ed71a3d1c6ef91e36b035ecc82b8
2014-08-08T16:11:41Z
mmm a / cocos / base / CCConfiguration . cpp <nl> ppp b / cocos / base / CCConfiguration . cpp <nl> void Configuration : : loadConfigFile ( const std : : string & filename ) <nl> <nl> / / light info <nl> std : : string name = " cocos2d . x . 3d . max_dir_light_in_shader " ; <nl> - if ( _valueDict . find ( name ) ! = dataMap . end ( ) ) <nl> + if ( _valueDict . find ( name ) ! = _valueDict . end ( ) ) <nl> _maxDirLightInShader = _valueDict [ name ] . asInt ( ) ; <nl> else <nl> _valueDict [ name ] = Value ( _maxDirLightInShader ) ; <nl> <nl> name = " cocos2d . x . 3d . max_point_light_in_shader " ; <nl> - if ( _valueDict . find ( name ) ! = dataMap . end ( ) ) <nl> + if ( _valueDict . find ( name ) ! = _valueDict . end ( ) ) <nl> _maxPointLightInShader = _valueDict [ name ] . asInt ( ) ; <nl> else <nl> _valueDict [ name ] = Value ( _maxPointLightInShader ) ; <nl> <nl> name = " cocos2d . x . 3d . max_spot_light_in_shader " ; <nl> - if ( _valueDict . find ( name ) ! = dataMap . end ( ) ) <nl> + if ( _valueDict . find ( name ) ! = _valueDict . end ( ) ) <nl> _maxSpotLightInShader = _valueDict [ name ] . asInt ( ) ; <nl> else <nl> _valueDict [ name ] = Value ( _maxSpotLightInShader ) ; <nl>
Merge pull request from ricardoquesada / win32_fixes
cocos2d/cocos2d-x
0c2fcaa0ca37ad5b813aa4f1c963a2bb320372cb
2014-10-03T00:16:19Z
mmm a / src / library . js <nl> ppp b / src / library . js <nl> LibraryManager . library = { <nl> strcat : function ( pdest , psrc ) { <nl> pdest = pdest | 0 ; psrc = psrc | 0 ; <nl> var i = 0 ; <nl> - pdest = ( pdest + _strlen ( pdest ) ) | 0 ; <nl> + pdest = ( pdest + ( _strlen ( pdest ) | 0 ) ) | 0 ; <nl> do { <nl> { { { makeCopyValues ( ' pdest + i ' , ' psrc + i ' , 1 , ' i8 ' , null , 1 ) } } } ; <nl> i = ( i + 1 ) | 0 ; <nl>
add missing coercion in strcat
emscripten-core/emscripten
57331dbc8dbc8b88c29f1067a32d5631fda0bcc3
2013-04-24T01:28:26Z
mmm a / stdlib / public / core / Repeat . swift <nl> ppp b / stdlib / public / core / Repeat . swift <nl> <nl> / / / / / " Humperdinck " <nl> / / / / / " Humperdinck " <nl> @ _fixed_layout <nl> - public struct Repeated < Element > : RandomAccessCollection { <nl> + public struct Repeated < Element > { <nl> + / / / The number of elements in this collection . <nl> + public let count : Int <nl> + <nl> + / / / The value of every element in this collection . <nl> + public let repeatedValue : Element <nl> + } <nl> <nl> + extension Repeated : RandomAccessCollection { <nl> public typealias Indices = CountableRange < Int > <nl> <nl> / / / A type that represents a valid position in the collection . <nl> public struct Repeated < Element > : RandomAccessCollection { <nl> _precondition ( position > = 0 & & position < count , " Index out of range " ) <nl> return repeatedValue <nl> } <nl> - <nl> - / / / The number of elements in this collection . <nl> - public let count : Int <nl> - <nl> - / / / The value of every element in this collection . <nl> - public let repeatedValue : Element <nl> } <nl> <nl> / / / Creates a collection containing the specified number of the given element . <nl> mmm a / stdlib / public / core / Reverse . swift <nl> ppp b / stdlib / public / core / Reverse . swift <nl> extension ReversedIndex : Hashable where Base . Index : Hashable { <nl> / / / <nl> / / / - See also : ` ReversedRandomAccessCollection ` <nl> @ _fixed_layout <nl> - public struct ReversedCollection < Base : BidirectionalCollection > : BidirectionalCollection { <nl> + public struct ReversedCollection < Base : BidirectionalCollection > { <nl> + public let _base : Base <nl> + <nl> / / / Creates an instance that presents the elements of ` base ` in <nl> / / / reverse order . <nl> / / / <nl> public struct ReversedCollection < Base : BidirectionalCollection > : BidirectionalCo <nl> internal init ( _base : Base ) { <nl> self . _base = _base <nl> } <nl> + } <nl> <nl> + extension ReversedCollection : BidirectionalCollection { <nl> / / / A type that represents a valid position in the collection . <nl> / / / <nl> / / / Valid indices consist of the position of every element and a <nl> / / / " past the end " position that ' s not valid for use as a subscript . <nl> public typealias Index = ReversedIndex < Base > <nl> - <nl> public typealias IndexDistance = Base . IndexDistance <nl> <nl> @ _fixed_layout <nl> public struct ReversedCollection < Base : BidirectionalCollection > : BidirectionalCo <nl> public subscript ( bounds : Range < Index > ) - > Slice < ReversedCollection > { <nl> return Slice ( base : self , bounds : bounds ) <nl> } <nl> - <nl> - public let _base : Base <nl> } <nl> <nl> extension ReversedCollection : RandomAccessCollection where Base : RandomAccessCollection { } <nl> mmm a / stdlib / public / core / Sequence . swift <nl> ppp b / stdlib / public / core / Sequence . swift <nl> extension Sequence { <nl> / / / <nl> / / / for x in IteratorSequence ( i ) { . . . } <nl> @ _fixed_layout <nl> - public struct IteratorSequence < <nl> - Base : IteratorProtocol <nl> - > : IteratorProtocol , Sequence { <nl> + public struct IteratorSequence < Base : IteratorProtocol > { <nl> + @ _versioned <nl> + internal var _base : Base <nl> + <nl> / / / Creates an instance whose iterator is a copy of ` base ` . <nl> @ _inlineable <nl> public init ( _ base : Base ) { <nl> _base = base <nl> } <nl> + } <nl> <nl> + extension IteratorSequence : IteratorProtocol , Sequence { <nl> / / / Advances to the next element and returns it , or ` nil ` if no next element <nl> / / / exists . <nl> / / / <nl> public struct IteratorSequence < <nl> public mutating func next ( ) - > Base . Element ? { <nl> return _base . next ( ) <nl> } <nl> - <nl> - @ _versioned <nl> - internal var _base : Base <nl> } <nl> mmm a / stdlib / public / core / Slice . swift <nl> ppp b / stdlib / public / core / Slice . swift <nl> <nl> / / / requirements into account . <nl> @ _fixed_layout / / FIXME ( sil - serialize - all ) <nl> public struct Slice < Base : Collection > { <nl> + public var _startIndex : Base . Index <nl> + public var _endIndex : Base . Index <nl> + <nl> + @ _versioned / / FIXME ( sil - serialize - all ) <nl> + internal var _base : Base <nl> + <nl> / / / Creates a view into the given collection that allows access to elements <nl> / / / within the specified range . <nl> / / / <nl> public struct Slice < Base : Collection > { <nl> self . _endIndex = bounds . upperBound <nl> } <nl> <nl> - public var _startIndex : Base . Index <nl> - public var _endIndex : Base . Index <nl> - <nl> - @ _versioned / / FIXME ( sil - serialize - all ) <nl> - internal var _base : Base <nl> - <nl> / / / The underlying collection of the slice . <nl> / / / <nl> / / / You can use a slice ' s ` base ` property to access its base collection . The <nl> mmm a / stdlib / public / core / Stride . swift . gyb <nl> ppp b / stdlib / public / core / Stride . swift . gyb <nl> extension Strideable where Self : FloatingPoint , Self = = Stride { <nl> <nl> / / / An iterator for ` StrideTo < Element > ` . <nl> @ _fixed_layout <nl> - public struct StrideToIterator < Element : Strideable > : IteratorProtocol { <nl> + public struct StrideToIterator < Element : Strideable > { <nl> @ _versioned <nl> internal let _start : Element <nl> <nl> public struct StrideToIterator < Element : Strideable > : IteratorProtocol { <nl> _stride = stride <nl> _current = ( 0 , _start ) <nl> } <nl> + } <nl> <nl> + extension StrideToIterator : IteratorProtocol { <nl> / / / Advances to the next element and returns it , or ` nil ` if no next element <nl> / / / exists . <nl> / / / <nl> / / / Once ` nil ` has been returned , all subsequent calls return ` nil ` . <nl> - <nl> @ _inlineable <nl> public mutating func next ( ) - > Element ? { <nl> let result = _current . value <nl> public struct StrideToIterator < Element : Strideable > : IteratorProtocol { <nl> } <nl> <nl> / / / A ` Sequence ` of values formed by striding over a half - open interval . <nl> + / / FIXME : should really be a Collection , as it is multipass <nl> @ _fixed_layout <nl> - public struct StrideTo < Element : Strideable > : Sequence , CustomReflectable { <nl> - / / FIXME : should really be a Collection , as it is multipass <nl> + public struct StrideTo < Element : Strideable > { <nl> + @ _versioned <nl> + internal let _start : Element <nl> + <nl> + @ _versioned <nl> + internal let _end : Element <nl> + <nl> + @ _versioned <nl> + internal let _stride : Element . Stride <nl> <nl> + @ _inlineable <nl> + @ _versioned <nl> + internal init ( _start : Element , end : Element , stride : Element . Stride ) { <nl> + _precondition ( stride ! = 0 , " Stride size must not be zero " ) <nl> + / / At start , striding away from end is allowed ; it just makes for an <nl> + / / already - empty Sequence . <nl> + self . _start = _start <nl> + self . _end = end <nl> + self . _stride = stride <nl> + } <nl> + } <nl> + <nl> + extension StrideTo : Sequence { <nl> / / / Returns an iterator over the elements of this sequence . <nl> / / / <nl> / / / - Complexity : O ( 1 ) . <nl> public struct StrideTo < Element : Strideable > : Sequence , CustomReflectable { <nl> return StrideToIterator ( _start : _start , end : _end , stride : _stride ) <nl> } <nl> <nl> + / / FIXME ( conditional - conformances ) : this is O ( N ) instead of O ( 1 ) , leaving it <nl> + / / here until a proper Collection conformance is possible <nl> + @ _inlineable <nl> + public var underestimatedCount : Int { <nl> + var it = self . makeIterator ( ) <nl> + var count = 0 <nl> + while it . next ( ) ! = nil { <nl> + count + = 1 <nl> + } <nl> + return count <nl> + } <nl> + <nl> @ _inlineable <nl> public func _preprocessingPass < R > ( <nl> _ preprocess : ( ) throws - > R <nl> public struct StrideTo < Element : Strideable > : Sequence , CustomReflectable { <nl> } <nl> return nil <nl> } <nl> + } <nl> <nl> - @ _inlineable <nl> - @ _versioned <nl> - internal init ( _start : Element , end : Element , stride : Element . Stride ) { <nl> - _precondition ( stride ! = 0 , " Stride size must not be zero " ) <nl> - / / At start , striding away from end is allowed ; it just makes for an <nl> - / / already - empty Sequence . <nl> - self . _start = _start <nl> - self . _end = end <nl> - self . _stride = stride <nl> - } <nl> - <nl> - @ _versioned <nl> - internal let _start : Element <nl> - <nl> - @ _versioned <nl> - internal let _end : Element <nl> - <nl> - @ _versioned <nl> - internal let _stride : Element . Stride <nl> - <nl> + extension StrideTo : CustomReflectable { <nl> @ _inlineable / / FIXME ( sil - serialize - all ) <nl> public var customMirror : Mirror { <nl> return Mirror ( self , children : [ " from " : _start , " to " : _end , " by " : _stride ] ) <nl> } <nl> - <nl> - / / FIXME ( conditional - conformances ) : this is O ( N ) instead of O ( 1 ) , leaving it <nl> - / / here until a proper Collection conformance is possible <nl> - @ _inlineable <nl> - public var underestimatedCount : Int { <nl> - var it = self . makeIterator ( ) <nl> - var count = 0 <nl> - while it . next ( ) ! = nil { <nl> - count + = 1 <nl> - } <nl> - return count <nl> - } <nl> } <nl> <nl> / / FIXME ( conditional - conformances ) : This does not yet compile ( SR - 6474 ) . <nl> public func stride < T > ( <nl> <nl> / / / An iterator for ` StrideThrough < Element > ` . <nl> @ _fixed_layout <nl> - public struct StrideThroughIterator < Element : Strideable > : IteratorProtocol { <nl> + public struct StrideThroughIterator < Element : Strideable > { <nl> @ _versioned <nl> internal let _start : Element <nl> <nl> public struct StrideThroughIterator < Element : Strideable > : IteratorProtocol { <nl> _stride = stride <nl> _current = ( 0 , _start ) <nl> } <nl> + } <nl> <nl> + extension StrideThroughIterator : IteratorProtocol { <nl> / / / Advances to the next element and returns it , or ` nil ` if no next element <nl> / / / exists . <nl> / / / <nl> public struct StrideThroughIterator < Element : Strideable > : IteratorProtocol { <nl> } <nl> <nl> / / / A ` Sequence ` of values formed by striding over a closed interval . <nl> + / / FIXME : should really be a CollectionType , as it is multipass <nl> @ _fixed_layout <nl> - public struct StrideThrough < <nl> - Element : Strideable <nl> - > : Sequence , CustomReflectable { <nl> - / / FIXME : should really be a CollectionType , as it is multipass <nl> + public struct StrideThrough < Element : Strideable > { <nl> + @ _versioned <nl> + internal let _start : Element <nl> + @ _versioned <nl> + internal let _end : Element <nl> + @ _versioned <nl> + internal let _stride : Element . Stride <nl> + <nl> + @ _inlineable <nl> + @ _versioned <nl> + internal init ( _start : Element , end : Element , stride : Element . Stride ) { <nl> + _precondition ( stride ! = 0 , " Stride size must not be zero " ) <nl> + self . _start = _start <nl> + self . _end = end <nl> + self . _stride = stride <nl> + } <nl> + } <nl> <nl> + extension StrideThrough : Sequence { <nl> / / / Returns an iterator over the elements of this sequence . <nl> / / / <nl> / / / - Complexity : O ( 1 ) . <nl> public struct StrideThrough < <nl> return StrideThroughIterator ( _start : _start , end : _end , stride : _stride ) <nl> } <nl> <nl> + / / FIXME ( conditional - conformances ) : this is O ( N ) instead of O ( 1 ) , leaving it <nl> + / / here until a proper Collection conformance is possible <nl> + @ _inlineable <nl> + public var underestimatedCount : Int { <nl> + var it = self . makeIterator ( ) <nl> + var count = 0 <nl> + while it . next ( ) ! = nil { <nl> + count + = 1 <nl> + } <nl> + return count <nl> + } <nl> + <nl> @ _inlineable <nl> public func _preprocessingPass < R > ( <nl> _ preprocess : ( ) throws - > R <nl> public struct StrideThrough < <nl> } <nl> return nil <nl> } <nl> + } <nl> <nl> - @ _inlineable <nl> - @ _versioned <nl> - internal init ( _start : Element , end : Element , stride : Element . Stride ) { <nl> - _precondition ( stride ! = 0 , " Stride size must not be zero " ) <nl> - self . _start = _start <nl> - self . _end = end <nl> - self . _stride = stride <nl> - } <nl> - <nl> - @ _versioned <nl> - internal let _start : Element <nl> - @ _versioned <nl> - internal let _end : Element <nl> - @ _versioned <nl> - internal let _stride : Element . Stride <nl> - <nl> + extension StrideThrough : CustomReflectable { <nl> @ _inlineable / / FIXME ( sil - serialize - all ) <nl> public var customMirror : Mirror { <nl> return Mirror ( self , <nl> children : [ " from " : _start , " through " : _end , " by " : _stride ] ) <nl> } <nl> - <nl> - / / FIXME ( conditional - conformances ) : this is O ( N ) instead of O ( 1 ) , leaving it <nl> - / / here until a proper Collection conformance is possible <nl> - @ _inlineable <nl> - public var underestimatedCount : Int { <nl> - var it = self . makeIterator ( ) <nl> - var count = 0 <nl> - while it . next ( ) ! = nil { <nl> - count + = 1 <nl> - } <nl> - return count <nl> - } <nl> } <nl> <nl> / / FIXME ( conditional - conformances ) : This does not yet compile ( SR - 6474 ) . <nl> mmm a / stdlib / public / core / UnsafeRawPointer . swift . gyb <nl> ppp b / stdlib / public / core / UnsafeRawPointer . swift . gyb <nl> public struct Unsafe $ { Mutable } RawPointer : _Pointer { <nl> _memmove ( dest : self , src : source , size : UInt ( byteCount ) ) <nl> } <nl> % end # mutable <nl> + } <nl> <nl> extension $ { Self } : Strideable { <nl> / / / Returns the distance from this pointer to the given pointer . <nl> mmm a / stdlib / public / core / ValidUTF8Buffer . swift <nl> ppp b / stdlib / public / core / ValidUTF8Buffer . swift <nl> <nl> / / <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> @ _fixed_layout <nl> - public struct _ValidUTF8Buffer < <nl> - Storage : UnsignedInteger & FixedWidthInteger <nl> - > { <nl> + public struct _ValidUTF8Buffer < Storage : UnsignedInteger & FixedWidthInteger > { <nl> public typealias Element = Unicode . UTF8 . CodeUnit <nl> internal typealias _Storage = Storage <nl> <nl> mmm a / stdlib / public / core / Zip . swift <nl> ppp b / stdlib / public / core / Zip . swift <nl> public func zip < Sequence1 , Sequence2 > ( <nl> <nl> / / / An iterator for ` Zip2Sequence ` . <nl> @ _fixed_layout / / FIXME ( sil - serialize - all ) <nl> - public struct Zip2Iterator < <nl> - Iterator1 : IteratorProtocol , Iterator2 : IteratorProtocol <nl> - > : IteratorProtocol { <nl> + public struct Zip2Iterator < Iterator1 : IteratorProtocol , Iterator2 : IteratorProtocol > { <nl> / / / The type of element returned by ` next ( ) ` . <nl> public typealias Element = ( Iterator1 . Element , Iterator2 . Element ) <nl> <nl> + @ _versioned / / FIXME ( sil - serialize - all ) <nl> + internal var _baseStream1 : Iterator1 <nl> + @ _versioned / / FIXME ( sil - serialize - all ) <nl> + internal var _baseStream2 : Iterator2 <nl> + @ _versioned / / FIXME ( sil - serialize - all ) <nl> + internal var _reachedEnd : Bool = false <nl> + <nl> / / / Creates an instance around a pair of underlying iterators . <nl> @ _inlineable / / FIXME ( sil - serialize - all ) <nl> @ _versioned / / FIXME ( sil - serialize - all ) <nl> internal init ( _ iterator1 : Iterator1 , _ iterator2 : Iterator2 ) { <nl> ( _baseStream1 , _baseStream2 ) = ( iterator1 , iterator2 ) <nl> } <nl> + } <nl> <nl> + extension Zip2Iterator : IteratorProtocol { <nl> / / / Advances to the next element and returns it , or ` nil ` if no next element <nl> / / / exists . <nl> / / / <nl> public struct Zip2Iterator < <nl> <nl> return ( element1 , element2 ) <nl> } <nl> - <nl> - @ _versioned / / FIXME ( sil - serialize - all ) <nl> - internal var _baseStream1 : Iterator1 <nl> - @ _versioned / / FIXME ( sil - serialize - all ) <nl> - internal var _baseStream2 : Iterator2 <nl> - @ _versioned / / FIXME ( sil - serialize - all ) <nl> - internal var _reachedEnd : Bool = false <nl> } <nl> <nl> / / / A sequence of pairs built out of two underlying sequences . <nl> public struct Zip2Iterator < <nl> / / / / / Prints " three : 3 " <nl> / / / / / Prints " four : 4 " <nl> @ _fixed_layout / / FIXME ( sil - serialize - all ) <nl> - public struct Zip2Sequence < Sequence1 : Sequence , Sequence2 : Sequence > <nl> - : Sequence { <nl> + public struct Zip2Sequence < Sequence1 : Sequence , Sequence2 : Sequence > { <nl> + @ _versioned / / FIXME ( sil - serialize - all ) <nl> + internal let _sequence1 : Sequence1 <nl> + @ _versioned / / FIXME ( sil - serialize - all ) <nl> + internal let _sequence2 : Sequence2 <nl> <nl> - <nl> @ available ( * , deprecated , renamed : " Sequence1 . Iterator " ) <nl> public typealias Stream1 = Sequence1 . Iterator <nl> @ available ( * , deprecated , renamed : " Sequence2 . Iterator " ) <nl> public typealias Stream2 = Sequence2 . Iterator <nl> <nl> - / / / A type whose instances can produce the elements of this <nl> - / / / sequence , in order . <nl> - public typealias Iterator = Zip2Iterator < Sequence1 . Iterator , Sequence2 . Iterator > <nl> - <nl> / / / Creates an instance that makes pairs of elements from ` sequence1 ` and <nl> / / / ` sequence2 ` . <nl> @ _inlineable / / FIXME ( sil - serialize - all ) <nl> public struct Zip2Sequence < Sequence1 : Sequence , Sequence2 : Sequence > <nl> init ( _sequence1 sequence1 : Sequence1 , _sequence2 sequence2 : Sequence2 ) { <nl> ( _sequence1 , _sequence2 ) = ( sequence1 , sequence2 ) <nl> } <nl> + } <nl> + <nl> + extension Zip2Sequence : Sequence { <nl> + / / / A type whose instances can produce the elements of this <nl> + / / / sequence , in order . <nl> + public typealias Iterator = Zip2Iterator < Sequence1 . Iterator , Sequence2 . Iterator > <nl> <nl> / / / Returns an iterator over the elements of this sequence . <nl> @ _inlineable / / FIXME ( sil - serialize - all ) <nl> public struct Zip2Sequence < Sequence1 : Sequence , Sequence2 : Sequence > <nl> _sequence1 . makeIterator ( ) , <nl> _sequence2 . makeIterator ( ) ) <nl> } <nl> - <nl> - @ _versioned / / FIXME ( sil - serialize - all ) <nl> - internal let _sequence1 : Sequence1 <nl> - @ _versioned / / FIXME ( sil - serialize - all ) <nl> - internal let _sequence2 : Sequence2 <nl> } <nl>
Part the third
apple/swift
e7b668e705072fbc043945c7692ebb49ff5c5693
2017-12-01T20:40:19Z
mmm a / tools / cmgen / src / CubemapIBL . cpp <nl> ppp b / tools / cmgen / src / CubemapIBL . cpp <nl> static double DFV_Charlie ( double NoV , double linearRoughness , size_t numSamples ) <nl> const double3 V ( std : : sqrt ( 1 - NoV * NoV ) , 0 , NoV ) ; <nl> for ( size_t i = 0 ; i < numSamples ; i + + ) { <nl> const double2 u = hammersley ( uint32_t ( i ) , 1 . 0f / numSamples ) ; <nl> - const double3 H = hemisphereCosSample ( u ) ; <nl> + const double3 H = hemisphereUniformSample ( u ) ; <nl> const double3 L = 2 * dot ( V , H ) * H - V ; <nl> const double VoH = saturate ( dot ( V , H ) ) ; <nl> const double NoL = saturate ( L . z ) ; <nl>
Use uniform sampling for cloth DFG ( )
google/filament
9558f0d6cadcf8f7e919407a36abe04f50c16c87
2019-03-02T22:10:38Z
mmm a / caffe2 / opt / onnxifi_transformer . cc <nl> ppp b / caffe2 / opt / onnxifi_transformer . cc <nl> void mergeFp32InputsAndConvertToFp16 ( <nl> } <nl> <nl> for ( auto & op : ops ) { <nl> - if ( ! op . device_option ( ) . node_name ( ) . empty ( ) & & <nl> - op . device_option ( ) . node_name ( ) = = partition ) { <nl> + if ( ( ! op . device_option ( ) . node_name ( ) . empty ( ) & & <nl> + op . device_option ( ) . node_name ( ) = = partition ) | | <nl> + ( op . device_option ( ) . node_name ( ) . empty ( ) & & partition = = " default " ) ) { <nl> for ( auto & i : * op . mutable_input ( ) ) { <nl> if ( user_input_set . count ( i ) ) { <nl> i = partition + " _ " + i + " _split " ; <nl>
Fix merge_fp32_inputs_into_fp16 with no partition ( )
pytorch/pytorch
67cd2638763917918ac6563afb644e0bd94d606d
2020-05-18T18:45:35Z
mmm a / hphp / compiler / analysis / emitter . cpp <nl> ppp b / hphp / compiler / analysis / emitter . cpp <nl> namespace Compiler { <nl> <nl> namespace { <nl> <nl> - static HHBBC : : UnitEmitterQueue s_ueq ; <nl> - <nl> void genText ( UnitEmitter * ue , const std : : string & outputPath ) { <nl> std : : unique_ptr < Unit > unit ( ue - > create ( true ) ) ; <nl> auto const basePath = AnalysisResult : : prepareFile ( <nl> void emitAllHHBC ( AnalysisResultPtr & & ar ) { <nl> commitSome ( ues ) ; <nl> } <nl> <nl> + HHBBC : : UnitEmitterQueue ueq ; <nl> + <nl> auto commitLoop = [ & ] { <nl> folly : : Optional < Timer > commitTime ; <nl> / / kBatchSize needs to strike a balance between reducing <nl> void emitAllHHBC ( AnalysisResultPtr & & ar ) { <nl> / / the 2 - 10 range is reasonable . <nl> static const unsigned kBatchSize = 8 ; <nl> <nl> - while ( auto ue = s_ueq . pop ( ) ) { <nl> + while ( auto ue = ueq . pop ( ) ) { <nl> if ( ! commitTime ) { <nl> commitTime . emplace ( Timer : : WallTime , " committing units to repo " ) ; <nl> } <nl> void emitAllHHBC ( AnalysisResultPtr & & ar ) { <nl> } ; <nl> <nl> HHBBC : : whole_program ( <nl> - std : : move ( ues ) , s_ueq , arrTable , <nl> + std : : move ( ues ) , ueq , arrTable , <nl> Option : : ParserThreadCount > 0 ? Option : : ParserThreadCount : 0 ) ; <nl> } ) ; <nl> <nl>
The UnitEmitterQueue doesn ' t need to be static
facebook/hhvm
6c0571e758a9771d89eef96f7f4344e00e96830f
2019-04-15T21:52:59Z
mmm a / xbmc / cores / AudioEngine / Sinks / AESinkPULSE . cpp <nl> ppp b / xbmc / cores / AudioEngine / Sinks / AESinkPULSE . cpp <nl> bool CAESinkPULSE : : Initialize ( AEAudioFormat & format , std : : string & device ) <nl> m_BytesPerSecond = pa_bytes_per_second ( & spec ) ; <nl> unsigned int frameSize = pa_frame_size ( & spec ) ; <nl> <nl> - m_Stream = pa_stream_new_extended ( m_Context , " xbmc audio stream " , info , 1 , NULL ) ; <nl> + m_Stream = pa_stream_new_extended ( m_Context , " kodi audio stream " , info , 1 , NULL ) ; <nl> pa_format_info_free ( info [ 0 ] ) ; <nl> <nl> if ( m_Stream = = NULL ) <nl> bool CAESinkPULSE : : SetupContext ( const char * host , pa_context * * context , pa_threa <nl> return false ; <nl> } <nl> <nl> - if ( ( ( * context ) = pa_context_new ( pa_threaded_mainloop_get_api ( * mainloop ) , " XBMC " ) ) = = NULL ) <nl> + if ( ( ( * context ) = pa_context_new ( pa_threaded_mainloop_get_api ( * mainloop ) , " Kodi " ) ) = = NULL ) <nl> { <nl> CLog : : Log ( LOGERROR , " PulseAudio : Failed to allocate context " ) ; <nl> return false ; <nl>
AESinkPULSE : Rebrand pulseaudio sink name to reflect kodi
xbmc/xbmc
0450fc1dab5794d3ae7056c3b3b0c7c2558cafc4
2014-11-13T17:26:25Z
mmm a / stdlib / objc / Foundation / ExtraStringAPIs . swift <nl> ppp b / stdlib / objc / Foundation / ExtraStringAPIs . swift <nl> extension String { <nl> _asciiUpperCaseTable > > <nl> UInt64 ( ( ( value & - 1 ) & 0b0111_1111 ) > > 1 ) <nl> let add = ( isUpper & 0x1 ) < < 5 <nl> + / / Since we are left with either 0x0 or 0x20 , we can safely truncate to <nl> + / / a UInt8 and add to our ASCII value ( this will not overflow numbers in <nl> + / / the ASCII range ) . <nl> dest [ i ] = value & + UInt8 ( truncatingBitPattern : add ) <nl> } <nl> return String ( _storage : buffer ) <nl>
[ stdlib ] added safe unchecked comment
apple/swift
74aa8b1a3c6b48594c672d358c75f23a46ba7fff
2014-12-11T18:52:21Z
mmm a / scripts / eosio_build_darwin . sh <nl> ppp b / scripts / eosio_build_darwin . sh <nl> <nl> $ XCODESELECT - - install 2 > / dev / null ; <nl> printf " \ tUpdating Home Brew . \ n " <nl> brew update <nl> + if [ $ ? - ne 0 ] ; then <nl> + printf " \ tUnable to update Home Brew at this time . \ n " <nl> + printf " \ tExiting now . \ n \ n " <nl> + exit ; <nl> + fi <nl> printf " \ tInstalling Dependencies . \ n " <nl> brew install - - force $ DEP <nl> + if [ $ ? - ne 0 ] ; then <nl> + printf " \ tHomebrew exited with the above errors . \ n " <nl> + printf " \ tExiting now . \ n \ n " <nl> + exit ; <nl> + fi <nl> brew unlink $ DEP & & brew link - - force $ DEP <nl> + if [ $ ? - ne 0 ] ; then <nl> + printf " \ tHomebrew exited with the above errors . \ n " <nl> + printf " \ tExiting now . \ n \ n " <nl> + exit ; <nl> + fi <nl> break ; ; <nl> [ Nn ] * ) echo " User aborting installation of required dependencies , Exiting now . " ; exit ; ; <nl> * ) echo " Please type 1 for yes or 2 for no . " ; ; <nl>
Merge pull request from pacificcode / eosio_build_darwin
EOSIO/eos
124c62d0e1b3974bcd551b885518ff05301b39c9
2018-04-06T16:41:33Z
mmm a / contrib / bitcoin - cli . bash - completion <nl> ppp b / contrib / bitcoin - cli . bash - completion <nl> _bitcoin_cli ( ) { <nl> COMPREPLY = ( $ ( compgen - W " true false " - - " $ cur " ) ) <nl> return 0 <nl> ; ; <nl> - signrawtransaction ) <nl> + signrawtransactionwithkey | signrawtransactionwithwallet ) <nl> COMPREPLY = ( $ ( compgen - W " ALL NONE SINGLE ALL | ANYONECANPAY NONE | ANYONECANPAY SINGLE | ANYONECANPAY " - - " $ cur " ) ) <nl> return 0 <nl> ; ; <nl> mmm a / src / bitcoin - tx . cpp <nl> ppp b / src / bitcoin - tx . cpp <nl> static void SetupBitcoinTxArgs ( ) <nl> " This command requires JSON registers : " <nl> " prevtxs = JSON object , " <nl> " privatekeys = JSON object . " <nl> - " See signrawtransaction docs for format of sighash flags , JSON objects . " , false , OptionsCategory : : COMMANDS ) ; <nl> + " See signrawtransactionwithkey docs for format of sighash flags , JSON objects . " , false , OptionsCategory : : COMMANDS ) ; <nl> <nl> gArgs . AddArg ( " load = NAME : FILENAME " , " Load JSON file FILENAME into register NAME " , false , OptionsCategory : : REGISTER_COMMANDS ) ; <nl> gArgs . AddArg ( " set = NAME : JSON - STRING " , " Set register NAME to given JSON - STRING " , false , OptionsCategory : : REGISTER_COMMANDS ) ; <nl> mmm a / src / rpc / client . cpp <nl> ppp b / src / rpc / client . cpp <nl> static const CRPCConvertParam vRPCConvertParams [ ] = <nl> { " createrawtransaction " , 2 , " locktime " } , <nl> { " createrawtransaction " , 3 , " replaceable " } , <nl> { " decoderawtransaction " , 1 , " iswitness " } , <nl> - { " signrawtransaction " , 1 , " prevtxs " } , <nl> - { " signrawtransaction " , 2 , " privkeys " } , <nl> { " signrawtransactionwithkey " , 1 , " privkeys " } , <nl> { " signrawtransactionwithkey " , 2 , " prevtxs " } , <nl> { " signrawtransactionwithwallet " , 1 , " prevtxs " } , <nl> mmm a / src / txmempool . h <nl> ppp b / src / txmempool . h <nl> class CTxMemPool <nl> * This allows transaction replacement to work as expected , as you want to <nl> * have all inputs " available " to check signatures , and any cycles in the <nl> * dependency graph are checked directly in AcceptToMemoryPool . <nl> - * It also allows you to sign a double - spend directly in signrawtransaction , <nl> + * It also allows you to sign a double - spend directly in <nl> + * signrawtransactionwithkey and signrawtransactionwithwallet , <nl> * as long as the conflicting transaction is not yet confirmed . <nl> * / <nl> class CCoinsViewMemPool : public CCoinsViewBacked <nl> mmm a / src / wallet / rpcwallet . cpp <nl> ppp b / src / wallet / rpcwallet . cpp <nl> static UniValue fundrawtransaction ( const JSONRPCRequest & request ) <nl> " This will not modify existing inputs , and will add at most one change output to the outputs . \ n " <nl> " No existing outputs will be modified unless \ " subtractFeeFromOutputs \ " is specified . \ n " <nl> " Note that inputs which were signed may need to be resigned after completion since in / outputs have been added . \ n " <nl> - " The inputs added will not be signed , use signrawtransaction for that . \ n " <nl> + " The inputs added will not be signed , use signrawtransactionwithkey \ n " <nl> + " or signrawtransactionwithwallet for that . \ n " <nl> " Note that all existing inputs must have their previous output transaction be in the wallet . \ n " <nl> " Note that all inputs selected must be of standard form and P2SH scripts must be \ n " <nl> " in the wallet using importaddress or addmultisigaddress ( to calculate fees ) . \ n " <nl> static UniValue fundrawtransaction ( const JSONRPCRequest & request ) <nl> " \ nAdd sufficient unsigned inputs to meet the output value \ n " <nl> + HelpExampleCli ( " fundrawtransaction " , " \ " rawtransactionhex \ " " ) + <nl> " \ nSign the transaction \ n " <nl> - + HelpExampleCli ( " signrawtransaction " , " \ " fundedtransactionhex \ " " ) + <nl> + + HelpExampleCli ( " signrawtransactionwithwallet " , " \ " fundedtransactionhex \ " " ) + <nl> " \ nSend the transaction \ n " <nl> + HelpExampleCli ( " sendrawtransaction " , " \ " signedtransactionhex \ " " ) <nl> } , <nl>
Merge : remove deprecated mentions of signrawtransaction from fundraw help
bitcoin/bitcoin
fc21bb4e359053961c776203d6ea5d6d3b2b626a
2019-02-05T15:48:36Z
mmm a / modules / drivers / velodyne / velodyne_driver / CMakeLists . txt <nl> ppp b / modules / drivers / velodyne / velodyne_driver / CMakeLists . txt <nl> if ( CATKIN_ENABLE_TESTING ) <nl> # these dependencies are only needed for unit testing <nl> find_package ( roslaunch REQUIRED ) <nl> find_package ( rostest REQUIRED ) <nl> - <nl> + <nl> # parse check all the launch / * . launch files <nl> roslaunch_add_file_check ( launch ) <nl> <nl> mmm a / modules / drivers / velodyne / velodyne_driver / src / driver / CMakeLists . txt <nl> ppp b / modules / drivers / velodyne / velodyne_driver / src / driver / CMakeLists . txt <nl> <nl> # build the driver node <nl> - add_executable ( driver_node <nl> - driver_node . cpp <nl> - driver . cpp <nl> + add_executable ( driver_node <nl> + driver_node . cpp <nl> + driver . cpp <nl> driver16 . cpp <nl> driver32 . cpp <nl> driver64 . cpp <nl> target_link_libraries ( driver_node <nl> ) <nl> <nl> # build the nodelet version <nl> - add_library ( driver_nodelet <nl> + add_library ( <nl> + driver_nodelet <nl> driver_nodelet . cpp <nl> - driver . cpp <nl> + driver . cpp <nl> driver16 . cpp <nl> driver32 . cpp <nl> driver64 . cpp <nl> ) <nl> - target_link_libraries ( driver_nodelet <nl> + target_link_libraries ( <nl> + driver_nodelet <nl> velodyne_input <nl> $ { catkin_LIBRARIES } <nl> ) <nl> mmm a / modules / drivers / velodyne / velodyne_driver / src / driver / driver . cpp <nl> ppp b / modules / drivers / velodyne / velodyne_driver / src / driver / driver . cpp <nl> <nl> <nl> # include " driver . h " <nl> <nl> - # include < ros / ros . h > <nl> - # include < time . h > <nl> # include < cmath > <nl> + # include < ctime > <nl> # include < string > <nl> <nl> + # include < ros / ros . h > <nl> + <nl> namespace apollo { <nl> namespace drivers { <nl> namespace velodyne { <nl> void VelodyneDriver : : update_gps_top_hour ( uint32_t current_time ) { <nl> last_gps_time_ = current_time ; <nl> } <nl> <nl> + bool VelodyneDriver : : check_angle ( velodyne_msgs : : VelodynePacket & packet ) { <nl> + / / check the angel in every packet <nl> + / / for each model of velodyne 64 the data struct is same , <nl> + / / so we don ' t need to check the lidar model <nl> + const unsigned char * raw_ptr = ( const unsigned char * ) & packet . data [ 0 ] ; <nl> + for ( int i = 0 ; i < BLOCKS_PER_PACKET ; + + i ) { <nl> + uint16_t angle = <nl> + raw_ptr [ i * BLOCK_SIZE + 3 ] * 256 + raw_ptr [ i * BLOCK_SIZE + 2 ] ; <nl> + / / for the velodyne64 angle resolution is 0 . 17 ~ 0 . 2 , so take the angle diff <nl> + / / at 0 . 2 ~ 0 . 3 should be a good choice <nl> + if ( angle > config_ . prefix_angle & & <nl> + std : : abs ( angle - config_ . prefix_angle ) < 30 ) { <nl> + return true ; <nl> + } <nl> + } <nl> + return false ; <nl> + } <nl> + <nl> VelodyneDriver * VelodyneDriverFactory : : create_driver ( <nl> ros : : NodeHandle private_nh ) { <nl> Config config ; <nl> mmm a / modules / drivers / velodyne / velodyne_driver / src / driver / driver . h <nl> ppp b / modules / drivers / velodyne / velodyne_driver / src / driver / driver . h <nl> <nl> * limitations under the License . <nl> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> <nl> - # ifndef VELODYNE_DRIVER_H <nl> - # define VELODYNE_DRIVER_H <nl> + # ifndef VELODYNE_DRIVER_H_ <nl> + # define VELODYNE_DRIVER_H_ <nl> <nl> # include < ros / ros . h > <nl> # include < string > <nl> namespace apollo { <nl> namespace drivers { <nl> namespace velodyne { <nl> <nl> + constexpr int BLOCKS_PER_PACKET = 12 ; <nl> + constexpr int BLOCK_SIZE = 100 ; <nl> + <nl> / / configuration parameters <nl> struct Config { <nl> - Config ( ) <nl> - : npackets ( 0 ) , rpm ( 0 . 0 ) , firing_data_port ( 0 ) , positioning_data_port ( 0 ) { } <nl> std : : string frame_id ; / / / < tf frame ID <nl> std : : string model ; / / / < device model name <nl> std : : string topic ; <nl> - int npackets ; / / / < number of packets to collect <nl> - double rpm ; / / / < device rotation rate ( RPMs ) <nl> - int firing_data_port ; <nl> - int positioning_data_port ; <nl> + int npackets = 0 ; / / / < number of packets to collect <nl> + double rpm = 0 . 0 ; / / / < device rotation rate ( RPMs ) <nl> + int firing_data_port = 0 ; <nl> + int positioning_data_port = 0 ; <nl> + int prefix_angle = 0 ; / / prefix angle to recv <nl> } ; <nl> <nl> class VelodyneDriver { <nl> class VelodyneDriver { <nl> void set_base_time_from_nmea_time ( NMEATimePtr nmea_time , <nl> uint64_t & basetime ) ; <nl> void update_gps_top_hour ( unsigned int current_time ) ; <nl> + <nl> + bool check_angle ( velodyne_msgs : : VelodynePacket & packet ) ; <nl> } ; <nl> <nl> class Velodyne64Driver : public VelodyneDriver { <nl> class Velodyne64Driver : public VelodyneDriver { <nl> } ; <nl> <nl> class Velodyne32Driver : public VelodyneDriver { <nl> - public : <nl> - explicit Velodyne32Driver ( const Config & config ) ; <nl> - virtual ~ Velodyne32Driver ( ) { } <nl> - void init ( ros : : NodeHandle & node ) ; <nl> - bool poll ( void ) ; <nl> - void poll_positioning_packet ( ) ; <nl> - private : <nl> + public : <nl> + explicit Velodyne32Driver ( const Config & config ) ; <nl> + virtual ~ Velodyne32Driver ( ) { } <nl> + void init ( ros : : NodeHandle & node ) ; <nl> + bool poll ( void ) ; <nl> + void poll_positioning_packet ( ) ; <nl> + <nl> + private : <nl> std : : shared_ptr < Input > positioning_input_ ; <nl> } ; <nl> <nl> class VelodyneDriverFactory { <nl> } / / namespace drivers <nl> } / / namespace apollo <nl> <nl> - # endif / / VELODYNE_DRIVER_H__ <nl> + # endif / / VELODYNE_DRIVER_H_ <nl> mmm a / modules / drivers / velodyne / velodyne_driver / src / driver / driver32 . cpp <nl> ppp b / modules / drivers / velodyne / velodyne_driver / src / driver / driver32 . cpp <nl> <nl> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> # include " driver . h " <nl> <nl> - # include < ros / ros . h > <nl> - # include < tf / transform_listener . h > <nl> # include < time . h > <nl> # include < unistd . h > <nl> # include < cmath > <nl> # include < string > <nl> # include < thread > <nl> <nl> + # include < ros / ros . h > <nl> + # include < tf / transform_listener . h > <nl> + <nl> namespace apollo { <nl> namespace drivers { <nl> namespace velodyne { <nl> <nl> - Velodyne32Driver : : Velodyne32Driver ( const Config & config ) { <nl> - config_ = config ; <nl> - } <nl> + Velodyne32Driver : : Velodyne32Driver ( const Config & config ) { config_ = config ; } <nl> <nl> void Velodyne32Driver : : init ( ros : : NodeHandle & node ) { <nl> - double packet_rate = 0 . 0 ; / / packet frequency ( Hz ) <nl> - packet_rate = 1808 . 0 ; <nl> - <nl> + double packet_rate = 1808 . 0 ; / / packet frequency ( Hz ) <nl> double frequency = ( config_ . rpm / 60 . 0 ) ; / / expected Hz rate <nl> <nl> / / default number of packets for each scan is a single revolution <nl> mmm a / modules / drivers / velodyne / velodyne_driver / src / driver / driver64 . cpp <nl> ppp b / modules / drivers / velodyne / velodyne_driver / src / driver / driver64 . cpp <nl> namespace apollo { <nl> namespace drivers { <nl> namespace velodyne { <nl> <nl> - Velodyne64Driver : : Velodyne64Driver ( const Config & config ) { <nl> - config_ = config ; <nl> - } <nl> + Velodyne64Driver : : Velodyne64Driver ( const Config & config ) { config_ = config ; } <nl> <nl> void Velodyne64Driver : : init ( ros : : NodeHandle & node ) { <nl> double packet_rate = 0 ; / / packet frequency ( Hz ) <nl>
Driver : added check angle function in velodyne driver .
ApolloAuto/apollo
d862a5e0a493300a1325565353fb871bcd0210a4
2018-06-06T16:03:32Z
mmm a / include / swift / AST / ASTContext . h <nl> ppp b / include / swift / AST / ASTContext . h <nl> <nl> # define SWIFT_AST_ASTCONTEXT_H <nl> <nl> # include " llvm / Support / DataTypes . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / ClangModuleLoader . h " <nl> # include " swift / AST / Identifier . h " <nl> # include " swift / AST / ProtocolConformance . h " <nl> namespace swift { <nl> class TypeVariableType ; <nl> class TupleType ; <nl> class FunctionType ; <nl> + class ArchetypeBuilder ; <nl> class ArchetypeType ; <nl> class Identifier ; <nl> class InheritedNameSet ; <nl> class ASTContext { <nl> DeclContext * gpContext , <nl> ArrayRef < Substitution > Subs ) const ; <nl> <nl> - / / / Retrieve the archetype builder and potential archetype <nl> - / / / corresponding to the given archetype type . <nl> - / / / <nl> - / / / This facility is only used by the archetype builder when forming <nl> - / / / archetypes . a <nl> - std : : pair < ArchetypeBuilder * , ArchetypeBuilder : : PotentialArchetype * > <nl> - getLazyArchetype ( const ArchetypeType * archetype ) ; <nl> - <nl> - / / / Register information for a lazily - constructed archetype . <nl> - void registerLazyArchetype ( <nl> - const ArchetypeType * archetype , <nl> - ArchetypeBuilder & builder , <nl> - ArchetypeBuilder : : PotentialArchetype * potentialArchetype ) ; <nl> - <nl> - / / / Unregister information about the given lazily - constructed archetype . <nl> - void unregisterLazyArchetype ( const ArchetypeType * archetype ) ; <nl> - <nl> friend ArchetypeType ; <nl> - friend ArchetypeBuilder : : PotentialArchetype ; <nl> <nl> / / / Provide context - level uniquing for SIL lowered type layouts and boxes . <nl> friend SILLayout ; <nl> mmm a / include / swift / AST / AnyFunctionRef . h <nl> ppp b / include / swift / AST / AnyFunctionRef . h <nl> <nl> # define SWIFT_AST_ANY_FUNCTION_REF_H <nl> <nl> # include " swift / Basic / LLVM . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / Decl . h " <nl> # include " swift / AST / Expr . h " <nl> # include " swift / AST / Types . h " <nl> class AnyFunctionRef { <nl> Type getBodyResultType ( ) const { <nl> if ( auto * AFD = TheFunction . dyn_cast < AbstractFunctionDecl * > ( ) ) { <nl> if ( auto * FD = dyn_cast < FuncDecl > ( AFD ) ) <nl> - return ArchetypeBuilder : : mapTypeIntoContext ( <nl> - FD , FD - > getResultInterfaceType ( ) ) ; <nl> + return FD - > mapTypeIntoContext ( FD - > getResultInterfaceType ( ) ) ; <nl> return TupleType : : getEmpty ( AFD - > getASTContext ( ) ) ; <nl> } <nl> return TheFunction . get < AbstractClosureExpr * > ( ) - > getResultType ( ) ; <nl> mmm a / include / swift / AST / ArchetypeBuilder . h <nl> ppp b / include / swift / AST / ArchetypeBuilder . h <nl> class ArchetypeBuilder { <nl> / / / For any type that cannot refer to an archetype , this routine returns null . <nl> PotentialArchetype * resolveArchetype ( Type type ) ; <nl> <nl> - / / / Map an interface type to a contextual type . <nl> - static Type mapTypeIntoContext ( const DeclContext * dc , Type type ) ; <nl> - <nl> - / / / Map an interface type to a contextual type . <nl> - static Type mapTypeIntoContext ( ModuleDecl * M , <nl> - GenericEnvironment * genericEnv , <nl> - Type type ) ; <nl> - <nl> - / / / Map a contextual type to an interface type . <nl> - static Type mapTypeOutOfContext ( const DeclContext * dc , Type type ) ; <nl> - <nl> - / / / Map a contextual type to an interface type . <nl> - static Type mapTypeOutOfContext ( GenericEnvironment * genericEnv , <nl> - Type type ) ; <nl> - <nl> / / / \ brief Dump all of the requirements , both specified and inferred . <nl> LLVM_ATTRIBUTE_DEPRECATED ( <nl> void dump ( ) , <nl> mmm a / include / swift / AST / Decl . h <nl> ppp b / include / swift / AST / Decl . h <nl> <nl> # include " swift / AST / ClangNode . h " <nl> # include " swift / AST / ConcreteDeclRef . h " <nl> # include " swift / AST / DefaultArgumentKind . h " <nl> - # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / AST / GenericSignature . h " <nl> # include " swift / AST / GenericParamKey . h " <nl> # include " swift / AST / LazyResolver . h " <nl> <nl> namespace swift { <nl> enum class AccessSemantics : unsigned char ; <nl> class ApplyExpr ; <nl> - class ArchetypeBuilder ; <nl> class GenericEnvironment ; <nl> class ArchetypeType ; <nl> class ASTContext ; <nl> class ExtensionDecl final : public Decl , public DeclContext , <nl> } <nl> <nl> / / / Retrieve the generic signature for this type . <nl> - GenericSignature * getGenericSignature ( ) const { <nl> - if ( auto genericEnv = GenericSigOrEnv . dyn_cast < GenericEnvironment * > ( ) ) <nl> - return genericEnv - > getGenericSignature ( ) ; <nl> - <nl> - if ( auto genericSig = GenericSigOrEnv . dyn_cast < GenericSignature * > ( ) ) <nl> - return genericSig ; <nl> - <nl> - return nullptr ; <nl> - } <nl> + GenericSignature * getGenericSignature ( ) const ; <nl> <nl> / / / Retrieve the generic context for this type . <nl> - GenericEnvironment * getGenericEnvironment ( ) const { <nl> - / / Fast case : we already have a generic environment . <nl> - if ( auto genericEnv = GenericSigOrEnv . dyn_cast < GenericEnvironment * > ( ) ) <nl> - return genericEnv ; <nl> - <nl> - / / If we only have a generic signature , build the generic environment . <nl> - if ( GenericSigOrEnv . dyn_cast < GenericSignature * > ( ) ) <nl> - return getLazyGenericEnvironmentSlow ( ) ; <nl> - <nl> - return nullptr ; <nl> - } <nl> + GenericEnvironment * getGenericEnvironment ( ) const ; <nl> <nl> / / / Set a lazy generic environment . <nl> void setLazyGenericEnvironment ( LazyMemberLoader * lazyLoader , <nl> class ExtensionDecl final : public Decl , public DeclContext , <nl> uint64_t genericEnvData ) ; <nl> <nl> / / / Set the generic context of this extension . <nl> - void setGenericEnvironment ( GenericEnvironment * genericEnv ) { <nl> - assert ( ( GenericSigOrEnv . isNull ( ) | | <nl> - getGenericSignature ( ) - > getCanonicalSignature ( ) = = <nl> - genericEnv - > getGenericSignature ( ) - > getCanonicalSignature ( ) ) & & <nl> - " set a generic environment with a different generic signature " ) ; <nl> - this - > GenericSigOrEnv = genericEnv ; <nl> - if ( genericEnv ) <nl> - genericEnv - > setOwningDeclContext ( this ) ; <nl> - } <nl> + void setGenericEnvironment ( GenericEnvironment * genericEnv ) ; <nl> <nl> / / / Retrieve the type being extended . <nl> Type getExtendedType ( ) const { return ExtendedType . getType ( ) ; } <nl> class GenericTypeDecl : public TypeDecl , public DeclContext { <nl> } <nl> <nl> / / / Retrieve the generic signature for this type . <nl> - GenericSignature * getGenericSignature ( ) const { <nl> - if ( auto genericEnv = GenericSigOrEnv . dyn_cast < GenericEnvironment * > ( ) ) <nl> - return genericEnv - > getGenericSignature ( ) ; <nl> - <nl> - if ( auto genericSig = GenericSigOrEnv . dyn_cast < GenericSignature * > ( ) ) <nl> - return genericSig ; <nl> - <nl> - return nullptr ; <nl> - } <nl> + GenericSignature * getGenericSignature ( ) const ; <nl> <nl> / / / Retrieve the generic context for this type . <nl> - GenericEnvironment * getGenericEnvironment ( ) const { <nl> - / / Fast case : we already have a generic environment . <nl> - if ( auto genericEnv = GenericSigOrEnv . dyn_cast < GenericEnvironment * > ( ) ) <nl> - return genericEnv ; <nl> - <nl> - / / If we only have a generic signature , build the generic environment . <nl> - if ( GenericSigOrEnv . dyn_cast < GenericSignature * > ( ) ) <nl> - return getLazyGenericEnvironmentSlow ( ) ; <nl> - <nl> - return nullptr ; <nl> - } <nl> + GenericEnvironment * getGenericEnvironment ( ) const ; <nl> <nl> void setIsValidatingGenericSignature ( bool validating = true ) { <nl> ValidatingGenericSignature = validating ; <nl> class GenericTypeDecl : public TypeDecl , public DeclContext { <nl> uint64_t genericEnvData ) ; <nl> <nl> / / / Set the generic context of this function . <nl> - void setGenericEnvironment ( GenericEnvironment * genericEnv ) { <nl> - assert ( ( GenericSigOrEnv . isNull ( ) | | <nl> - getGenericSignature ( ) - > getCanonicalSignature ( ) = = <nl> - genericEnv - > getGenericSignature ( ) - > getCanonicalSignature ( ) ) & & <nl> - " set a generic environment with a different generic signature " ) ; <nl> - this - > GenericSigOrEnv = genericEnv ; <nl> - <nl> - if ( genericEnv ) <nl> - genericEnv - > setOwningDeclContext ( this ) ; <nl> - } <nl> + void setGenericEnvironment ( GenericEnvironment * genericEnv ) ; <nl> <nl> / / Resolve ambiguity due to multiple base classes . <nl> using TypeDecl : : getASTContext ; <nl> class AbstractFunctionDecl : public ValueDecl , public DeclContext { <nl> bool isTransparent ( ) const ; <nl> <nl> / / / Retrieve the generic signature for this function . <nl> - GenericSignature * getGenericSignature ( ) const { <nl> - if ( auto genericEnv = GenericSigOrEnv . dyn_cast < GenericEnvironment * > ( ) ) <nl> - return genericEnv - > getGenericSignature ( ) ; <nl> - <nl> - if ( auto genericSig = GenericSigOrEnv . dyn_cast < GenericSignature * > ( ) ) <nl> - return genericSig ; <nl> - <nl> - return nullptr ; <nl> - } <nl> + GenericSignature * getGenericSignature ( ) const ; <nl> <nl> / / / Retrieve the generic context for this function . <nl> - GenericEnvironment * getGenericEnvironment ( ) const { <nl> - / / Fast case : we already have a generic environment . <nl> - if ( auto genericEnv = GenericSigOrEnv . dyn_cast < GenericEnvironment * > ( ) ) <nl> - return genericEnv ; <nl> - <nl> - / / If we only have a generic signature , build the generic environment . <nl> - if ( GenericSigOrEnv . dyn_cast < GenericSignature * > ( ) ) <nl> - return getLazyGenericEnvironmentSlow ( ) ; <nl> - <nl> - return nullptr ; <nl> - } <nl> + GenericEnvironment * getGenericEnvironment ( ) const ; <nl> <nl> / / / Set a lazy generic environment . <nl> void setLazyGenericEnvironment ( LazyMemberLoader * lazyLoader , <nl> class AbstractFunctionDecl : public ValueDecl , public DeclContext { <nl> uint64_t genericEnvData ) ; <nl> <nl> / / / Set the generic context of this function . <nl> - void setGenericEnvironment ( GenericEnvironment * genericEnv ) { <nl> - assert ( ( GenericSigOrEnv . isNull ( ) | | <nl> - getGenericSignature ( ) - > getCanonicalSignature ( ) = = <nl> - genericEnv - > getGenericSignature ( ) - > getCanonicalSignature ( ) ) & & <nl> - " set a generic environment with a different generic signature " ) ; <nl> - this - > GenericSigOrEnv = genericEnv ; <nl> - <nl> - if ( genericEnv ) <nl> - genericEnv - > setOwningDeclContext ( this ) ; <nl> - } <nl> + void setGenericEnvironment ( GenericEnvironment * genericEnv ) ; <nl> <nl> / / Expose our import as member status <nl> bool isImportAsMember ( ) const { return IAMStatus . isImportAsMember ( ) ; } <nl> mmm a / include / swift / AST / GenericEnvironment . h <nl> ppp b / include / swift / AST / GenericEnvironment . h <nl> class alignas ( 1 < < DeclAlignInBits ) GenericEnvironment final <nl> return Mem ; <nl> } <nl> <nl> + / / / Map an interface type to a contextual type . <nl> + static Type mapTypeIntoContext ( ModuleDecl * M , <nl> + GenericEnvironment * genericEnv , <nl> + Type type ) ; <nl> + <nl> + / / / Map a contextual type to an interface type . <nl> + static Type mapTypeOutOfContext ( GenericEnvironment * genericEnv , <nl> + Type type ) ; <nl> + <nl> / / / Map a contextual type to an interface type . <nl> Type mapTypeOutOfContext ( Type type ) const ; <nl> <nl> mmm a / include / swift / AST / TypeRepr . h <nl> ppp b / include / swift / AST / TypeRepr . h <nl> <nl> <nl> # include " swift / AST / Attr . h " <nl> # include " swift / AST / DeclContext . h " <nl> - # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / AST / Identifier . h " <nl> # include " swift / AST / Type . h " <nl> # include " swift / AST / TypeAlignments . h " <nl> <nl> namespace swift { <nl> class ASTWalker ; <nl> class DeclContext ; <nl> + class GenericEnvironment ; <nl> class IdentTypeRepr ; <nl> class ValueDecl ; <nl> <nl> class FunctionTypeRepr : public TypeRepr { <nl> <nl> GenericParamList * getGenericParams ( ) const { return GenericParams ; } <nl> GenericEnvironment * getGenericEnvironment ( ) const { return GenericEnv ; } <nl> - GenericSignature * getGenericSignature ( ) const { <nl> - return GenericEnv ? GenericEnv - > getGenericSignature ( ) : nullptr ; <nl> - } <nl> <nl> void setGenericEnvironment ( GenericEnvironment * genericEnv ) { <nl> assert ( GenericEnv = = nullptr ) ; <nl> class SILBoxTypeRepr : public TypeRepr { <nl> GenericParamList * getGenericParams ( ) const { <nl> return GenericParams ; <nl> } <nl> - GenericSignature * getGenericSignature ( ) const { <nl> - return GenericEnv - > getGenericSignature ( ) ; <nl> - } <nl> GenericEnvironment * getGenericEnvironment ( ) const { <nl> return GenericEnv ; <nl> } <nl> mmm a / include / swift / AST / Witness . h <nl> ppp b / include / swift / AST / Witness . h <nl> class Witness { <nl> return getDeclRef ( ) . getSubstitutions ( ) ; <nl> } <nl> <nl> - / / / Retrieve the generic signature of the synthetic environment . <nl> - GenericSignature * getSyntheticSignature ( ) const { <nl> - assert ( requiresSubstitution ( ) & & " No substitutions required for witness " ) ; <nl> - if ( auto * env = getSyntheticEnvironment ( ) ) <nl> - return env - > getGenericSignature ( ) ; <nl> - else <nl> - return nullptr ; <nl> - } <nl> - <nl> / / / Retrieve the synthetic generic environment . <nl> GenericEnvironment * getSyntheticEnvironment ( ) const { <nl> assert ( requiresSubstitution ( ) & & " No substitutions required for witness " ) ; <nl> mmm a / lib / AST / ASTMangler . cpp <nl> ppp b / lib / AST / ASTMangler . cpp <nl> void ASTMangler : : appendType ( Type type ) { <nl> <nl> / / Find the archetype information . <nl> const DeclContext * DC = DeclCtx ; <nl> - auto GTPT = ArchetypeBuilder : : mapTypeOutOfContext ( DC , archetype ) <nl> - - > castTo < GenericTypeParamType > ( ) ; <nl> + auto GTPT = DC - > mapTypeOutOfContext ( archetype ) <nl> + - > castTo < GenericTypeParamType > ( ) ; <nl> <nl> if ( DWARFMangling ) { <nl> Buffer < < ' q ' < < Index ( GTPT - > getIndex ( ) ) ; <nl> void ASTMangler : : appendClosureComponents ( Type Ty , unsigned discriminator , <nl> if ( ! Ty ) <nl> Ty = ErrorType : : get ( localContext - > getASTContext ( ) ) ; <nl> <nl> - Ty = ArchetypeBuilder : : mapTypeOutOfContext ( parentContext , Ty ) ; <nl> + Ty = parentContext - > mapTypeOutOfContext ( Ty ) ; <nl> appendType ( Ty - > getCanonicalType ( ) ) ; <nl> appendOperator ( isImplicit ? " fu " : " fU " , Index ( discriminator ) ) ; <nl> } <nl> mmm a / lib / AST / ASTPrinter . cpp <nl> ppp b / lib / AST / ASTPrinter . cpp <nl> <nl> # include " swift / AST / ASTPrinter . h " <nl> # include " swift / AST / ASTContext . h " <nl> # include " swift / AST / ASTVisitor . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / Attr . h " <nl> # include " swift / AST / Decl . h " <nl> # include " swift / AST / Expr . h " <nl> class PrintAST : public ASTVisitor < PrintAST > { <nl> if ( T - > hasArchetype ( ) ) { <nl> / / Get the interface type , since TypeLocs still have <nl> / / contextual types in them . <nl> - T = ArchetypeBuilder : : mapTypeOutOfContext ( <nl> - Current - > getInnermostDeclContext ( ) , T ) ; <nl> + T = Current - > getInnermostDeclContext ( ) - > mapTypeOutOfContext ( T ) ; <nl> } <nl> <nl> / / Get the innermost nominal type context . <nl> mmm a / lib / AST / ASTVerifier . cpp <nl> ppp b / lib / AST / ASTVerifier . cpp <nl> <nl> <nl> # include " swift / Subsystems . h " <nl> # include " swift / AST / AccessScope . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / AST . h " <nl> # include " swift / AST / ASTContext . h " <nl> # include " swift / AST / ASTWalker . h " <nl> struct ASTNodeBase { } ; <nl> Type resultType ; <nl> if ( FuncDecl * FD = dyn_cast < FuncDecl > ( func ) ) { <nl> resultType = FD - > getResultInterfaceType ( ) ; <nl> - resultType = ArchetypeBuilder : : mapTypeIntoContext ( FD , resultType ) ; <nl> + resultType = FD - > mapTypeIntoContext ( resultType ) ; <nl> } else if ( auto closure = dyn_cast < AbstractClosureExpr > ( func ) ) { <nl> resultType = closure - > getResultType ( ) ; <nl> } else { <nl> struct ASTNodeBase { } ; <nl> Type typeForAccessors = <nl> var - > getInterfaceType ( ) - > getReferenceStorageReferent ( ) ; <nl> typeForAccessors = <nl> - ArchetypeBuilder : : mapTypeIntoContext ( var - > getDeclContext ( ) , <nl> - typeForAccessors ) ; <nl> + var - > getDeclContext ( ) - > mapTypeIntoContext ( typeForAccessors ) ; <nl> if ( const FuncDecl * getter = var - > getGetter ( ) ) { <nl> if ( getter - > getParameterLists ( ) . back ( ) - > size ( ) ! = 0 ) { <nl> Out < < " property getter has parameters \ n " ; <nl> struct ASTNodeBase { } ; <nl> } <nl> Type getterResultType = getter - > getResultInterfaceType ( ) ; <nl> getterResultType = <nl> - ArchetypeBuilder : : mapTypeIntoContext ( var - > getDeclContext ( ) , <nl> - getterResultType ) ; <nl> + var - > getDeclContext ( ) - > mapTypeIntoContext ( getterResultType ) ; <nl> if ( ! getterResultType - > isEqual ( typeForAccessors ) ) { <nl> Out < < " property and getter have mismatched types : ' " ; <nl> typeForAccessors . print ( Out ) ; <nl> struct ASTNodeBase { } ; <nl> } <nl> const ParamDecl * param = setter - > getParameterLists ( ) . back ( ) - > get ( 0 ) ; <nl> Type paramType = param - > getInterfaceType ( ) ; <nl> - paramType = ArchetypeBuilder : : mapTypeIntoContext ( var - > getDeclContext ( ) , <nl> - paramType ) ; <nl> + paramType = var - > getDeclContext ( ) - > mapTypeIntoContext ( paramType ) ; <nl> if ( ! paramType - > isEqual ( typeForAccessors ) ) { <nl> Out < < " property and setter param have mismatched types : ' " ; <nl> typeForAccessors . print ( Out ) ; <nl> mmm a / lib / AST / ArchetypeBuilder . cpp <nl> ppp b / lib / AST / ArchetypeBuilder . cpp <nl> static void maybeAddSameTypeRequirementForNestedType ( <nl> if ( ! concreteType ) return ; <nl> <nl> / / Add the same - type constraint . <nl> - concreteType = ArchetypeBuilder : : mapTypeOutOfContext ( <nl> - superConformance - > getDeclContext ( ) , concreteType ) ; <nl> + concreteType = superConformance - > getDeclContext ( ) <nl> + - > mapTypeOutOfContext ( concreteType ) ; <nl> if ( auto otherPA = builder . resolveArchetype ( concreteType ) ) <nl> builder . addSameTypeRequirementBetweenArchetypes ( <nl> nestedPA , otherPA , fromSource ) ; <nl> bool ArchetypeBuilder : : addAbstractTypeParamRequirements ( <nl> / / use that information . <nl> if ( isa < AssociatedTypeDecl > ( decl ) & & <nl> decl - > getDeclContext ( ) - > isValidGenericContext ( ) ) { <nl> - auto * archetype = mapTypeIntoContext ( decl - > getDeclContext ( ) , <nl> - decl - > getDeclaredInterfaceType ( ) ) <nl> - - > getAs < ArchetypeType > ( ) ; <nl> + auto * archetype = decl - > getDeclContext ( ) - > mapTypeIntoContext ( <nl> + decl - > getDeclaredInterfaceType ( ) ) <nl> + - > getAs < ArchetypeType > ( ) ; <nl> <nl> if ( archetype ) { <nl> SourceLoc loc = decl - > getLoc ( ) ; <nl> void ArchetypeBuilder : : dump ( llvm : : raw_ostream & out ) { <nl> out < < " \ n " ; <nl> } <nl> <nl> - Type ArchetypeBuilder : : mapTypeIntoContext ( const DeclContext * dc , Type type ) { <nl> - return mapTypeIntoContext ( dc - > getParentModule ( ) , <nl> - dc - > getGenericEnvironmentOfContext ( ) , <nl> - type ) ; <nl> - } <nl> - <nl> - Type ArchetypeBuilder : : mapTypeIntoContext ( ModuleDecl * M , <nl> - GenericEnvironment * env , <nl> - Type type ) { <nl> - assert ( ! type - > hasArchetype ( ) & & " already have a contextual type " ) ; <nl> - <nl> - if ( ! env ) <nl> - return type . substDependentTypesWithErrorTypes ( ) ; <nl> - <nl> - return env - > mapTypeIntoContext ( M , type ) ; <nl> - } <nl> - <nl> - Type <nl> - ArchetypeBuilder : : mapTypeOutOfContext ( const DeclContext * dc , Type type ) { <nl> - return mapTypeOutOfContext ( dc - > getGenericEnvironmentOfContext ( ) , <nl> - type ) ; <nl> - } <nl> - <nl> - Type <nl> - ArchetypeBuilder : : mapTypeOutOfContext ( GenericEnvironment * env , <nl> - Type type ) { <nl> - assert ( ! type - > hasTypeParameter ( ) & & " already have an interface type " ) ; <nl> - <nl> - if ( ! env ) <nl> - return type . substDependentTypesWithErrorTypes ( ) ; <nl> - <nl> - return env - > mapTypeOutOfContext ( type ) ; <nl> - } <nl> - <nl> void ArchetypeBuilder : : addGenericSignature ( GenericSignature * sig ) { <nl> if ( ! sig ) return ; <nl> <nl> mmm a / lib / AST / Builtins . cpp <nl> ppp b / lib / AST / Builtins . cpp <nl> <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> # include " swift / AST / AST . h " <nl> + # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / Basic / LLVMContext . h " <nl> # include " swift / AST / Builtins . h " <nl> # include " swift / AST / GenericEnvironment . h " <nl> mmm a / lib / AST / Decl . cpp <nl> ppp b / lib / AST / Decl . cpp <nl> <nl> <nl> # include " swift / AST / Decl . h " <nl> # include " swift / AST / AccessScope . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / AST . h " <nl> # include " swift / AST / ASTContext . h " <nl> # include " swift / AST / ASTWalker . h " <nl> void ExtensionDecl : : setGenericParams ( GenericParamList * params ) { <nl> } <nl> } <nl> <nl> + GenericSignature * ExtensionDecl : : getGenericSignature ( ) const { <nl> + if ( auto genericEnv = GenericSigOrEnv . dyn_cast < GenericEnvironment * > ( ) ) <nl> + return genericEnv - > getGenericSignature ( ) ; <nl> + <nl> + if ( auto genericSig = GenericSigOrEnv . dyn_cast < GenericSignature * > ( ) ) <nl> + return genericSig ; <nl> + <nl> + return nullptr ; <nl> + } <nl> + <nl> + GenericEnvironment * ExtensionDecl : : getGenericEnvironment ( ) const { <nl> + / / Fast case : we already have a generic environment . <nl> + if ( auto genericEnv = GenericSigOrEnv . dyn_cast < GenericEnvironment * > ( ) ) <nl> + return genericEnv ; <nl> + <nl> + / / If we only have a generic signature , build the generic environment . <nl> + if ( GenericSigOrEnv . dyn_cast < GenericSignature * > ( ) ) <nl> + return getLazyGenericEnvironmentSlow ( ) ; <nl> + <nl> + return nullptr ; <nl> + } <nl> + <nl> + void ExtensionDecl : : setGenericEnvironment ( GenericEnvironment * genericEnv ) { <nl> + assert ( ( GenericSigOrEnv . isNull ( ) | | <nl> + getGenericSignature ( ) - > getCanonicalSignature ( ) = = <nl> + genericEnv - > getGenericSignature ( ) - > getCanonicalSignature ( ) ) & & <nl> + " set a generic environment with a different generic signature " ) ; <nl> + this - > GenericSigOrEnv = genericEnv ; <nl> + if ( genericEnv ) <nl> + genericEnv - > setOwningDeclContext ( this ) ; <nl> + } <nl> + <nl> GenericEnvironment * <nl> ExtensionDecl : : getLazyGenericEnvironmentSlow ( ) const { <nl> assert ( GenericSigOrEnv . is < GenericSignature * > ( ) & & <nl> void GenericTypeDecl : : setGenericParams ( GenericParamList * params ) { <nl> Param - > setDeclContext ( this ) ; <nl> } <nl> <nl> + GenericSignature * GenericTypeDecl : : getGenericSignature ( ) const { <nl> + if ( auto genericEnv = GenericSigOrEnv . dyn_cast < GenericEnvironment * > ( ) ) <nl> + return genericEnv - > getGenericSignature ( ) ; <nl> + <nl> + if ( auto genericSig = GenericSigOrEnv . dyn_cast < GenericSignature * > ( ) ) <nl> + return genericSig ; <nl> + <nl> + return nullptr ; <nl> + } <nl> + <nl> + GenericEnvironment * GenericTypeDecl : : getGenericEnvironment ( ) const { <nl> + / / Fast case : we already have a generic environment . <nl> + if ( auto genericEnv = GenericSigOrEnv . dyn_cast < GenericEnvironment * > ( ) ) <nl> + return genericEnv ; <nl> + <nl> + / / If we only have a generic signature , build the generic environment . <nl> + if ( GenericSigOrEnv . dyn_cast < GenericSignature * > ( ) ) <nl> + return getLazyGenericEnvironmentSlow ( ) ; <nl> + <nl> + return nullptr ; <nl> + } <nl> + <nl> + / / / Set the generic context of this function . <nl> + void GenericTypeDecl : : setGenericEnvironment ( GenericEnvironment * genericEnv ) { <nl> + assert ( ( GenericSigOrEnv . isNull ( ) | | <nl> + getGenericSignature ( ) - > getCanonicalSignature ( ) = = <nl> + genericEnv - > getGenericSignature ( ) - > getCanonicalSignature ( ) ) & & <nl> + " set a generic environment with a different generic signature " ) ; <nl> + this - > GenericSigOrEnv = genericEnv ; <nl> + <nl> + if ( genericEnv ) <nl> + genericEnv - > setOwningDeclContext ( this ) ; <nl> + } <nl> + <nl> GenericEnvironment * <nl> GenericTypeDecl : : getLazyGenericEnvironmentSlow ( ) const { <nl> assert ( GenericSigOrEnv . is < GenericSignature * > ( ) & & <nl> SourceRange SubscriptDecl : : getSourceRange ( ) const { <nl> return { getSubscriptLoc ( ) , ElementTy . getSourceRange ( ) . End } ; <nl> } <nl> <nl> + GenericSignature * AbstractFunctionDecl : : getGenericSignature ( ) const { <nl> + if ( auto genericEnv = GenericSigOrEnv . dyn_cast < GenericEnvironment * > ( ) ) <nl> + return genericEnv - > getGenericSignature ( ) ; <nl> + <nl> + if ( auto genericSig = GenericSigOrEnv . dyn_cast < GenericSignature * > ( ) ) <nl> + return genericSig ; <nl> + <nl> + return nullptr ; <nl> + } <nl> + <nl> + GenericEnvironment * AbstractFunctionDecl : : getGenericEnvironment ( ) const { <nl> + / / Fast case : we already have a generic environment . <nl> + if ( auto genericEnv = GenericSigOrEnv . dyn_cast < GenericEnvironment * > ( ) ) <nl> + return genericEnv ; <nl> + <nl> + / / If we only have a generic signature , build the generic environment . <nl> + if ( GenericSigOrEnv . dyn_cast < GenericSignature * > ( ) ) <nl> + return getLazyGenericEnvironmentSlow ( ) ; <nl> + <nl> + return nullptr ; <nl> + } <nl> + <nl> + void <nl> + AbstractFunctionDecl : : setGenericEnvironment ( GenericEnvironment * genericEnv ) { <nl> + assert ( ( GenericSigOrEnv . isNull ( ) | | <nl> + getGenericSignature ( ) - > getCanonicalSignature ( ) = = <nl> + genericEnv - > getGenericSignature ( ) - > getCanonicalSignature ( ) ) & & <nl> + " set a generic environment with a different generic signature " ) ; <nl> + this - > GenericSigOrEnv = genericEnv ; <nl> + <nl> + if ( genericEnv ) <nl> + genericEnv - > setOwningDeclContext ( this ) ; <nl> + } <nl> + <nl> GenericEnvironment * <nl> AbstractFunctionDecl : : getLazyGenericEnvironmentSlow ( ) const { <nl> assert ( GenericSigOrEnv . is < GenericSignature * > ( ) & & <nl> mmm a / lib / AST / DeclContext . cpp <nl> ppp b / lib / AST / DeclContext . cpp <nl> <nl> # include " swift / AST / DeclContext . h " <nl> # include " swift / AST / AccessScope . h " <nl> # include " swift / AST / ASTWalker . h " <nl> + # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / AST / Types . h " <nl> # include " swift / Basic / SourceManager . h " <nl> # include " llvm / ADT / DenseMap . h " <nl> GenericEnvironment * DeclContext : : getGenericEnvironmentOfContext ( ) const { <nl> } <nl> <nl> Type DeclContext : : mapTypeIntoContext ( Type type ) const { <nl> - return ArchetypeBuilder : : mapTypeIntoContext ( <nl> + return GenericEnvironment : : mapTypeIntoContext ( <nl> getParentModule ( ) , getGenericEnvironmentOfContext ( ) , type ) ; <nl> } <nl> <nl> Type DeclContext : : mapTypeOutOfContext ( Type type ) const { <nl> - return ArchetypeBuilder : : mapTypeOutOfContext ( <nl> + return GenericEnvironment : : mapTypeOutOfContext ( <nl> getGenericEnvironmentOfContext ( ) , type ) ; <nl> } <nl> <nl> mmm a / lib / AST / GenericEnvironment . cpp <nl> ppp b / lib / AST / GenericEnvironment . cpp <nl> <nl> <nl> # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / AST / ASTContext . h " <nl> + # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / ProtocolConformance . h " <nl> <nl> using namespace swift ; <nl> bool GenericEnvironment : : containsPrimaryArchetype ( <nl> QueryArchetypeToInterfaceSubstitutions ( this ) ( archetype ) ) ; <nl> } <nl> <nl> + Type GenericEnvironment : : mapTypeIntoContext ( ModuleDecl * M , <nl> + GenericEnvironment * env , <nl> + Type type ) { <nl> + assert ( ! type - > hasArchetype ( ) & & " already have a contextual type " ) ; <nl> + <nl> + if ( ! env ) <nl> + return type . substDependentTypesWithErrorTypes ( ) ; <nl> + <nl> + return env - > mapTypeIntoContext ( M , type ) ; <nl> + } <nl> + <nl> + Type <nl> + GenericEnvironment : : mapTypeOutOfContext ( GenericEnvironment * env , <nl> + Type type ) { <nl> + assert ( ! type - > hasTypeParameter ( ) & & " already have an interface type " ) ; <nl> + <nl> + if ( ! env ) <nl> + return type . substDependentTypesWithErrorTypes ( ) ; <nl> + <nl> + return env - > mapTypeOutOfContext ( type ) ; <nl> + } <nl> + <nl> Type GenericEnvironment : : mapTypeOutOfContext ( Type type ) const { <nl> type = type . subst ( QueryArchetypeToInterfaceSubstitutions ( this ) , <nl> MakeAbstractConformanceForGenericType ( ) , <nl> mmm a / lib / AST / GenericSignature . cpp <nl> ppp b / lib / AST / GenericSignature . cpp <nl> <nl> <nl> # include " swift / AST / GenericSignature . h " <nl> # include " swift / AST / ASTContext . h " <nl> + # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / Decl . h " <nl> # include " swift / AST / Module . h " <nl> # include " swift / AST / Types . h " <nl> mmm a / lib / AST / Mangle . cpp <nl> ppp b / lib / AST / Mangle . cpp <nl> void Mangler : : mangleType ( Type type , unsigned uncurryLevel ) { <nl> <nl> / / Find the archetype information . <nl> const DeclContext * DC = DeclCtx ; <nl> - auto GTPT = ArchetypeBuilder : : mapTypeOutOfContext ( DC , archetype ) <nl> + auto GTPT = DC - > mapTypeOutOfContext ( archetype ) <nl> - > castTo < GenericTypeParamType > ( ) ; <nl> <nl> if ( DWARFMangling ) { <nl> void Mangler : : mangleClosureComponents ( Type Ty , unsigned discriminator , <nl> if ( ! Ty ) <nl> Ty = ErrorType : : get ( localContext - > getASTContext ( ) ) ; <nl> <nl> - Ty = ArchetypeBuilder : : mapTypeOutOfContext ( parentContext , Ty ) ; <nl> + Ty = parentContext - > mapTypeOutOfContext ( Ty ) ; <nl> mangleType ( Ty - > getCanonicalType ( ) , / * uncurry * / 0 ) ; <nl> } <nl> <nl> mmm a / lib / AST / Pattern . cpp <nl> ppp b / lib / AST / Pattern . cpp <nl> <nl> # include " swift / AST / Pattern . h " <nl> # include " swift / AST / AST . h " <nl> # include " swift / AST / ASTWalker . h " <nl> + # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / AST / TypeLoc . h " <nl> # include " llvm / ADT / APFloat . h " <nl> # include " llvm / Support / raw_ostream . h " <nl> mmm a / lib / AST / Type . cpp <nl> ppp b / lib / AST / Type . cpp <nl> <nl> <nl> # include " swift / AST / Types . h " <nl> # include " ForeignRepresentationInfo . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / TypeVisitor . h " <nl> # include " swift / AST / TypeWalker . h " <nl> # include " swift / AST / Decl . h " <nl> mmm a / lib / ClangImporter / ImportDecl . cpp <nl> ppp b / lib / ClangImporter / ImportDecl . cpp <nl> <nl> # include " ImporterImpl . h " <nl> # include " swift / Strings . h " <nl> # include " swift / AST / ASTContext . h " <nl> + # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / Attr . h " <nl> # include " swift / AST / Builtins . h " <nl> # include " swift / AST / Decl . h " <nl> static FuncDecl * buildSubscriptSetterDecl ( ClangImporter : : Implementation & Impl , <nl> <nl> / / ' self ' <nl> auto selfDecl = ParamDecl : : createSelf ( SourceLoc ( ) , dc ) ; <nl> - auto elementTy = ArchetypeBuilder : : mapTypeIntoContext ( dc , elementInterfaceTy ) ; <nl> + auto elementTy = dc - > mapTypeIntoContext ( elementInterfaceTy ) ; <nl> <nl> auto paramVarDecl = <nl> new ( C ) ParamDecl ( / * isLet = * / false , SourceLoc ( ) , SourceLoc ( ) , Identifier ( ) , <nl> namespace { <nl> isInSystemModule ( dc ) , <nl> / * isFullyBridgeable * / false ) ; <nl> if ( superclassType ) { <nl> - superclassType = <nl> - ArchetypeBuilder : : mapTypeOutOfContext ( result , superclassType ) ; <nl> + superclassType = result - > mapTypeOutOfContext ( superclassType ) ; <nl> assert ( superclassType - > is < ClassType > ( ) | | <nl> superclassType - > is < BoundGenericClassType > ( ) ) ; <nl> inheritedTypes . push_back ( TypeLoc : : withoutLoc ( superclassType ) ) ; <nl> namespace { <nl> decl - > isClassProperty ( ) , / * IsLet * / false , <nl> Impl . importSourceLoc ( decl - > getLocation ( ) ) , <nl> name , type , dc ) ; <nl> - result - > setInterfaceType ( ArchetypeBuilder : : mapTypeOutOfContext ( dc , type ) ) ; <nl> + result - > setInterfaceType ( dc - > mapTypeOutOfContext ( type ) ) ; <nl> <nl> / / Turn this into a computed property . <nl> / / FIXME : Fake locations for ' { ' and ' } ' ? <nl> Decl * SwiftDeclConverter : : importSwift2TypeAlias ( const clang : : NamedDecl * decl , <nl> genericParams = generic - > getGenericParams ( ) ; <nl> genericEnv = generic - > getGenericEnvironment ( ) ; <nl> <nl> - underlyingType = <nl> - ArchetypeBuilder : : mapTypeIntoContext ( generic , underlyingType ) ; <nl> + underlyingType = generic - > mapTypeIntoContext ( underlyingType ) ; <nl> } <nl> } <nl> <nl> SwiftDeclConverter : : importSubscript ( Decl * decl , <nl> - > getResult ( ) <nl> - > castTo < AnyFunctionType > ( ) <nl> - > getResult ( ) ; <nl> - auto elementContextTy = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - getter , elementTy ) ; <nl> + auto elementContextTy = getter - > mapTypeIntoContext ( elementTy ) ; <nl> <nl> / / Local function to mark the setter unavailable . <nl> auto makeSetterUnavailable = [ & ] { <nl> mmm a / lib / ClangImporter / ImportType . cpp <nl> ppp b / lib / ClangImporter / ImportType . cpp <nl> Type ClangImporter : : Implementation : : importFunctionReturnType ( <nl> if ( ! type ) <nl> return type ; <nl> <nl> - return ArchetypeBuilder : : mapTypeOutOfContext ( dc , type ) ; <nl> + return dc - > mapTypeOutOfContext ( type ) ; <nl> } <nl> <nl> Type ClangImporter : : Implementation : : <nl> ParameterList * ClangImporter : : Implementation : : importFunctionParameterList ( <nl> importSourceLoc ( param - > getLocation ( ) ) , bodyName , swiftParamTy , <nl> ImportedHeaderUnit ) ; <nl> paramInfo - > setInterfaceType ( <nl> - ArchetypeBuilder : : mapTypeOutOfContext ( dc , swiftParamTy ) ) ; <nl> + dc - > mapTypeOutOfContext ( swiftParamTy ) ) ; <nl> <nl> if ( addNoEscapeAttr ) <nl> paramInfo - > getAttrs ( ) . add ( new ( SwiftContext ) <nl> Type ClangImporter : : Implementation : : importMethodType ( <nl> auto mapTypeIntoContext = [ & ] ( Type type ) - > Type { <nl> if ( dc ! = origDC ) { <nl> / / Replace origDC ' s archetypes with interface types . <nl> - type = ArchetypeBuilder : : mapTypeOutOfContext ( origDC , type ) ; <nl> + type = origDC - > mapTypeOutOfContext ( type ) ; <nl> <nl> / / Get the substitutions that we need to access a member of <nl> / / ' origDC ' on ' dc ' . <nl> Type ClangImporter : : Implementation : : importMethodType ( <nl> bodyName , swiftParamTy , <nl> ImportedHeaderUnit ) ; <nl> paramInfo - > setInterfaceType ( <nl> - ArchetypeBuilder : : mapTypeOutOfContext ( dc , swiftParamTy ) ) ; <nl> + dc - > mapTypeOutOfContext ( swiftParamTy ) ) ; <nl> <nl> if ( addNoEscapeAttr ) { <nl> paramInfo - > getAttrs ( ) . add ( <nl> Type ClangImporter : : Implementation : : importMethodType ( <nl> extInfo = extInfo . withThrows ( true ) ; <nl> } <nl> <nl> - swiftResultTy = ArchetypeBuilder : : mapTypeOutOfContext ( dc , swiftResultTy ) ; <nl> + swiftResultTy = dc - > mapTypeOutOfContext ( swiftResultTy ) ; <nl> <nl> / / Form the function type . <nl> return FunctionType : : get ( <nl> mmm a / lib / IDE / CodeCompletion . cpp <nl> ppp b / lib / IDE / CodeCompletion . cpp <nl> class CompletionLookup final : public swift : : VisibleDeclConsumer { <nl> DeclContext * DC ; <nl> if ( VD ) { <nl> DC = VD - > getInnermostDeclContext ( ) ; <nl> - this - > ExprType = ArchetypeBuilder : : mapTypeIntoContext ( DC , ExprType ) ; <nl> + this - > ExprType = DC - > mapTypeIntoContext ( ExprType ) ; <nl> } else if ( auto NTD = ExprType - > getRValueType ( ) - > getRValueInstanceType ( ) <nl> - > getAnyNominal ( ) ) { <nl> DC = NTD ; <nl> - this - > ExprType = ArchetypeBuilder : : mapTypeIntoContext ( DC , ExprType ) ; <nl> + this - > ExprType = DC - > mapTypeIntoContext ( ExprType ) ; <nl> } <nl> } <nl> <nl> mmm a / lib / IDE / TypeReconstruction . cpp <nl> ppp b / lib / IDE / TypeReconstruction . cpp <nl> static void VisitNodeQualifiedArchetype ( <nl> if ( sig ) { <nl> auto params = sig - > getInnermostGenericParams ( ) ; <nl> if ( index < params . size ( ) ) { <nl> - auto argTy = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - dc , params [ index ] ) - > getAs < ArchetypeType > ( ) ; <nl> + auto argTy = dc - > mapTypeIntoContext ( params [ index ] ) <nl> + - > getAs < ArchetypeType > ( ) ; <nl> if ( argTy ) <nl> result . _types . push_back ( argTy ) ; <nl> } <nl> mmm a / lib / IRGen / GenCall . cpp <nl> ppp b / lib / IRGen / GenCall . cpp <nl> <nl> # include " clang / Basic / TargetInfo . h " <nl> # include " clang / CodeGen / CodeGenABITypes . h " <nl> # include " clang / CodeGen / ModuleBuilder . h " <nl> + # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / Basic / Fallthrough . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " llvm / IR / CallSite . h " <nl> <nl> # include " CallEmission . h " <nl> mmm a / lib / IRGen / GenHeap . cpp <nl> ppp b / lib / IRGen / GenHeap . cpp <nl> <nl> # include " swift / Basic / Fallthrough . h " <nl> # include " swift / Basic / SourceLoc . h " <nl> # include " swift / ABI / MetadataValues . h " <nl> + # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / AST / IRGenOptions . h " <nl> <nl> # include " Explosion . h " <nl> mmm a / lib / IRGen / GenMeta . cpp <nl> ppp b / lib / IRGen / GenMeta . cpp <nl> <nl> / / <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / ASTContext . h " <nl> # include " swift / AST / CanTypeVisitor . h " <nl> # include " swift / AST / Decl . h " <nl> static void emitPolymorphicParametersFromArray ( IRGenFunction & IGF , <nl> array = IGF . Builder . CreateElementBitCast ( array , IGF . IGM . TypeMetadataPtrTy ) ; <nl> <nl> auto getInContext = [ & ] ( CanType type ) - > CanType { <nl> - return ArchetypeBuilder : : mapTypeIntoContext ( typeDecl , type ) <nl> + return typeDecl - > mapTypeIntoContext ( type ) <nl> - > getCanonicalType ( ) ; <nl> } ; <nl> <nl> irgen : : emitFieldTypeAccessor ( IRGenModule & IGM , <nl> auto declCtxt = type ; <nl> if ( auto generics = declCtxt - > getGenericSignatureOfContext ( ) ) { <nl> auto getInContext = [ & ] ( CanType type ) - > CanType { <nl> - return ArchetypeBuilder : : mapTypeIntoContext ( declCtxt , type ) <nl> + return declCtxt - > mapTypeIntoContext ( type ) <nl> - > getCanonicalType ( ) ; <nl> } ; <nl> bindArchetypeAccessPaths ( IGF , generics , getInContext ) ; <nl> namespace { <nl> return ; <nl> } <nl> <nl> - Type superclassTy <nl> - = ArchetypeBuilder : : mapTypeIntoContext ( Target , <nl> - Target - > getSuperclass ( ) ) ; <nl> + Type superclassTy = Target - > mapTypeIntoContext ( Target - > getSuperclass ( ) ) ; <nl> <nl> if ( ! addReferenceToHeapMetadata ( superclassTy - > getCanonicalType ( ) , <nl> / * allowUninit * / false ) ) { <nl> namespace { <nl> llvm : : Value * superMetadata ; <nl> if ( Target - > hasSuperclass ( ) ) { <nl> Type superclass = Target - > getSuperclass ( ) ; <nl> - superclass = ArchetypeBuilder : : mapTypeIntoContext ( Target , superclass ) ; <nl> + superclass = Target - > mapTypeIntoContext ( superclass ) ; <nl> superMetadata = <nl> emitClassHeapMetadataRef ( IGF , superclass - > getCanonicalType ( ) , <nl> MetadataValueType : : ObjCClass ) ; <nl> mmm a / lib / IRGen / GenPoly . cpp <nl> ppp b / lib / IRGen / GenPoly . cpp <nl> <nl> # include " swift / AST / ASTVisitor . h " <nl> # include " swift / AST / Types . h " <nl> # include " swift / AST / Decl . h " <nl> + # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / SIL / SILInstruction . h " <nl> # include " swift / SIL / SILModule . h " <nl> # include " swift / SIL / SILType . h " <nl> mmm a / lib / IRGen / GenProto . cpp <nl> ppp b / lib / IRGen / GenProto . cpp <nl> class AccessorConformanceInfo : public ConformanceInfo { <nl> auto declCtx = Conformance . getDeclContext ( ) ; <nl> if ( auto generics = declCtx - > getGenericSignatureOfContext ( ) ) { <nl> auto getInContext = [ & ] ( CanType type ) - > CanType { <nl> - return ArchetypeBuilder : : mapTypeIntoContext ( declCtx , type ) <nl> - - > getCanonicalType ( ) ; <nl> + return declCtx - > mapTypeIntoContext ( type ) - > getCanonicalType ( ) ; <nl> } ; <nl> bindArchetypeAccessPaths ( IGF , generics , getInContext ) ; <nl> } <nl> mmm a / lib / IRGen / GenReflection . cpp <nl> ppp b / lib / IRGen / GenReflection . cpp <nl> <nl> / / stored properties and enum cases for use with reflection . <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / Decl . h " <nl> # include " swift / AST / IRGenOptions . h " <nl> # include " swift / AST / PrettyStackTrace . h " <nl> emitAssociatedTypeMetadataRecord ( const ProtocolConformance * Conformance ) { <nl> const Substitution & Sub , <nl> const TypeDecl * TD ) - > bool { <nl> <nl> - auto Subst = ArchetypeBuilder : : mapTypeOutOfContext ( <nl> - Conformance - > getDeclContext ( ) , Sub . getReplacement ( ) ) ; <nl> + auto Subst = Conformance - > getDeclContext ( ) - > mapTypeOutOfContext ( <nl> + Sub . getReplacement ( ) ) ; <nl> <nl> AssociatedTypes . push_back ( { <nl> AssocTy - > getNameStr ( ) , <nl> mmm a / lib / IRGen / GenType . cpp <nl> ppp b / lib / IRGen / GenType . cpp <nl> <nl> <nl> # include " swift / AST / CanTypeVisitor . h " <nl> # include " swift / AST / Decl . h " <nl> + # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / AST / IRGenOptions . h " <nl> # include " swift / AST / PrettyStackTrace . h " <nl> # include " swift / AST / Types . h " <nl> mmm a / lib / Parse / ParseSIL . cpp <nl> ppp b / lib / Parse / ParseSIL . cpp <nl> <nl> / / <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / ASTWalker . h " <nl> # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / AST / NameLookup . h " <nl> mmm a / lib / SIL / SILFunction . cpp <nl> ppp b / lib / SIL / SILFunction . cpp <nl> <nl> # include " swift / SIL / SILInstruction . h " <nl> # include " swift / SIL / SILArgument . h " <nl> # include " swift / SIL / CFG . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / GenericEnvironment . h " <nl> # include " llvm / ADT / Optional . h " <nl> # include " llvm / Support / CommandLine . h " <nl> bool SILFunction : : shouldOptimize ( ) const { <nl> } <nl> <nl> Type SILFunction : : mapTypeIntoContext ( Type type ) const { <nl> - return ArchetypeBuilder : : mapTypeIntoContext ( getModule ( ) . getSwiftModule ( ) , <nl> - getGenericEnvironment ( ) , <nl> - type ) ; <nl> + return GenericEnvironment : : mapTypeIntoContext ( <nl> + getModule ( ) . getSwiftModule ( ) , <nl> + getGenericEnvironment ( ) , <nl> + type ) ; <nl> } <nl> <nl> namespace { <nl> SILType GenericEnvironment : : mapTypeIntoContext ( SILModule & M , <nl> } <nl> <nl> Type SILFunction : : mapTypeOutOfContext ( Type type ) const { <nl> - return ArchetypeBuilder : : mapTypeOutOfContext ( getGenericEnvironment ( ) , <nl> - type ) ; <nl> + return GenericEnvironment : : mapTypeOutOfContext ( <nl> + getGenericEnvironment ( ) , <nl> + type ) ; <nl> } <nl> <nl> bool SILFunction : : isNoReturnFunction ( ) const { <nl> mmm a / lib / SIL / SILType . cpp <nl> ppp b / lib / SIL / SILType . cpp <nl> <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> # include " swift / SIL / SILType . h " <nl> + # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / AST / Type . h " <nl> # include " swift / SIL / SILModule . h " <nl> # include " swift / SIL / TypeLowering . h " <nl> mmm a / lib / SIL / TypeLowering . cpp <nl> ppp b / lib / SIL / TypeLowering . cpp <nl> <nl> <nl> # define DEBUG_TYPE " libsil " <nl> # include " swift / AST / AnyFunctionRef . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / ASTContext . h " <nl> # include " swift / AST / CanTypeVisitor . h " <nl> # include " swift / AST / Decl . h " <nl> # include " swift / AST / DiagnosticEngine . h " <nl> # include " swift / AST / DiagnosticsSIL . h " <nl> # include " swift / AST / Expr . h " <nl> + # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / AST / Module . h " <nl> # include " swift / AST / NameLookup . h " <nl> # include " swift / AST / Pattern . h " <nl> static CanAnyFunctionType getStoredPropertyInitializerInterfaceType ( <nl> ASTContext & context ) { <nl> auto * DC = VD - > getDeclContext ( ) ; <nl> CanType resultTy = <nl> - ArchetypeBuilder : : mapTypeOutOfContext ( <nl> - DC , VD - > getParentInitializer ( ) - > getType ( ) ) <nl> + DC - > mapTypeOutOfContext ( VD - > getParentInitializer ( ) - > getType ( ) ) <nl> - > getCanonicalType ( ) ; <nl> GenericSignature * sig = DC - > getGenericSignatureOfContext ( ) ; <nl> <nl> CanAnyFunctionType TypeConverter : : makeConstantInterfaceType ( SILDeclRef c ) { <nl> / / FIXME : Closures could have an interface type computed by Sema . <nl> auto funcTy = cast < AnyFunctionType > ( ACE - > getType ( ) - > getCanonicalType ( ) ) ; <nl> funcTy = cast < AnyFunctionType > ( <nl> - ArchetypeBuilder : : mapTypeOutOfContext ( ACE - > getParent ( ) , funcTy ) <nl> + ACE - > mapTypeOutOfContext ( funcTy ) <nl> - > getCanonicalType ( ) ) ; <nl> return getFunctionInterfaceTypeWithCaptures ( funcTy , ACE ) ; <nl> } <nl> mmm a / lib / SILGen / SILGenBridging . cpp <nl> ppp b / lib / SILGen / SILGenBridging . cpp <nl> <nl> # include " SILGenFunction . h " <nl> # include " RValue . h " <nl> # include " Scope . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / AST . h " <nl> # include " swift / AST / DiagnosticsSIL . h " <nl> # include " swift / AST / ForeignErrorConvention . h " <nl> void SILGenFunction : : emitForeignToNativeThunk ( SILDeclRef thunk ) { <nl> fnType = fnType - > substGenericArgs ( SGM . M , subs ) ; <nl> <nl> auto substResultTy = <nl> - ArchetypeBuilder : : mapTypeIntoContext ( fd , nativeFormalResultTy ) <nl> + fd - > mapTypeIntoContext ( nativeFormalResultTy ) <nl> - > getCanonicalType ( ) ; <nl> <nl> auto resultMV = emitApply ( fd , ManagedValue : : forUnmanaged ( fn ) , <nl> mmm a / lib / SILGen / SILGenConstructor . cpp <nl> ppp b / lib / SILGen / SILGenConstructor . cpp <nl> void SILGenFunction : : emitValueConstructor ( ConstructorDecl * ctor ) { <nl> / / failure . <nl> SILBasicBlock * failureExitBB = nullptr ; <nl> SILArgument * failureExitArg = nullptr ; <nl> - auto resultType = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - ctor , ctor - > getResultInterfaceType ( ) ) ; <nl> + auto resultType = ctor - > mapTypeIntoContext ( ctor - > getResultInterfaceType ( ) ) ; <nl> auto & resultLowering = getTypeLowering ( resultType ) ; <nl> <nl> if ( ctor - > getFailability ( ) ! = OTK_None ) { <nl> void SILGenFunction : : emitClassConstructorInitializer ( ConstructorDecl * ctor ) { <nl> prepareEpilog ( Type ( ) , ctor - > hasThrows ( ) , <nl> CleanupLocation : : get ( endOfInitLoc ) ) ; <nl> <nl> - auto resultType = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - ctor , ctor - > getResultInterfaceType ( ) ) ; <nl> + auto resultType = ctor - > mapTypeIntoContext ( ctor - > getResultInterfaceType ( ) ) ; <nl> <nl> / / If the constructor can fail , set up an alternative epilog for constructor <nl> / / failure . <nl> static SILValue getBehaviorSetterFn ( SILGenFunction & gen , VarDecl * behaviorVar ) { <nl> static Type getInitializationTypeInContext ( <nl> DeclContext * fromDC , DeclContext * toDC , <nl> Expr * init ) { <nl> - auto interfaceType = <nl> - ArchetypeBuilder : : mapTypeOutOfContext ( fromDC , init - > getType ( ) ) ; <nl> - auto resultType = <nl> - ArchetypeBuilder : : mapTypeIntoContext ( toDC , interfaceType ) ; <nl> + auto interfaceType = fromDC - > mapTypeOutOfContext ( init - > getType ( ) ) ; <nl> + auto resultType = toDC - > mapTypeIntoContext ( interfaceType ) ; <nl> <nl> return resultType ; <nl> } <nl> mmm a / lib / SILGen / SILGenDecl . cpp <nl> ppp b / lib / SILGen / SILGenDecl . cpp <nl> SILGenModule : : emitProtocolWitness ( ProtocolConformance * conformance , <nl> CanAnyFunctionType reqtSubstTy ; <nl> ArrayRef < Substitution > witnessSubs ; <nl> if ( witness . requiresSubstitution ( ) ) { <nl> - GenericSignature * genericSig = witness . getSyntheticSignature ( ) ; ; <nl> genericEnv = witness . getSyntheticEnvironment ( ) ; <nl> witnessSubs = witness . getSubstitutions ( ) ; <nl> <nl> SILGenModule : : emitProtocolWitness ( ProtocolConformance * conformance , <nl> auto input = reqtOrigTy - > getInput ( ) . subst ( reqtSubs ) - > getCanonicalType ( ) ; <nl> auto result = reqtOrigTy - > getResult ( ) . subst ( reqtSubs ) - > getCanonicalType ( ) ; <nl> <nl> - if ( genericSig ) { <nl> + if ( genericEnv ) { <nl> + auto * genericSig = genericEnv - > getGenericSignature ( ) ; <nl> reqtSubstTy = cast < GenericFunctionType > ( <nl> GenericFunctionType : : get ( genericSig , input , result , <nl> reqtOrigTy - > getExtInfo ( ) ) <nl> SILGenModule : : emitProtocolWitness ( ProtocolConformance * conformance , <nl> selfInterfaceType = proto - > getSelfInterfaceType ( ) ; <nl> } <nl> <nl> - selfType = ArchetypeBuilder : : mapTypeIntoContext ( <nl> + selfType = GenericEnvironment : : mapTypeIntoContext ( <nl> M . getSwiftModule ( ) , genericEnv , selfInterfaceType ) ; <nl> } <nl> <nl> getOrCreateReabstractionThunk ( GenericEnvironment * genericEnv , <nl> <nl> / / Substitute context parameters out of the " from " and " to " types . <nl> auto fromInterfaceType <nl> - = ArchetypeBuilder : : mapTypeOutOfContext ( genericEnv , fromType ) <nl> + = GenericEnvironment : : mapTypeOutOfContext ( genericEnv , fromType ) <nl> - > getCanonicalType ( ) ; <nl> auto toInterfaceType <nl> - = ArchetypeBuilder : : mapTypeOutOfContext ( genericEnv , toType ) <nl> + = GenericEnvironment : : mapTypeOutOfContext ( genericEnv , toType ) <nl> - > getCanonicalType ( ) ; <nl> <nl> mangler . mangleType ( fromInterfaceType , / * uncurry * / 0 ) ; <nl> mmm a / lib / SILGen / SILGenExpr . cpp <nl> ppp b / lib / SILGen / SILGenExpr . cpp <nl> emitRValueForDecl ( SILLocation loc , ConcreteDeclRef declRef , Type ncRefType , <nl> ValueDecl * decl = declRef . getDecl ( ) ; <nl> <nl> if ( ! ncRefType ) { <nl> - ncRefType = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - decl - > getInnermostDeclContext ( ) , <nl> + ncRefType = decl - > getInnermostDeclContext ( ) - > mapTypeIntoContext ( <nl> decl - > getInterfaceType ( ) ) ; <nl> } <nl> CanType refType = ncRefType - > getCanonicalType ( ) ; <nl> mmm a / lib / SILGen / SILGenFunction . cpp <nl> ppp b / lib / SILGen / SILGenFunction . cpp <nl> void SILGenFunction : : emitFunction ( FuncDecl * fd ) { <nl> <nl> emitProlog ( fd , fd - > getParameterLists ( ) , fd - > getResultInterfaceType ( ) , <nl> fd - > hasThrows ( ) ) ; <nl> - Type resultTy = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - fd , fd - > getResultInterfaceType ( ) ) ; <nl> + Type resultTy = fd - > mapTypeIntoContext ( fd - > getResultInterfaceType ( ) ) ; <nl> prepareEpilog ( resultTy , fd - > hasThrows ( ) , CleanupLocation ( fd ) ) ; <nl> <nl> emitProfilerIncrement ( fd - > getBody ( ) ) ; <nl> void SILGenFunction : : emitCurryThunk ( ValueDecl * vd , <nl> F . setBare ( IsBare ) ; <nl> auto selfMetaTy = vd - > getInterfaceType ( ) - > getAs < AnyFunctionType > ( ) <nl> - > getInput ( ) ; <nl> - selfMetaTy = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - vd - > getInnermostDeclContext ( ) , selfMetaTy ) ; <nl> + selfMetaTy = vd - > getInnermostDeclContext ( ) - > mapTypeIntoContext ( selfMetaTy ) ; <nl> auto metatypeVal = <nl> F . begin ( ) - > createFunctionArgument ( getLoweredLoadableType ( selfMetaTy ) ) ; <nl> curriedArgs . push_back ( metatypeVal ) ; <nl> mmm a / lib / SILGen / SILGenProlog . cpp <nl> ppp b / lib / SILGen / SILGenProlog . cpp <nl> <nl> # include " ManagedValue . h " <nl> # include " Scope . h " <nl> # include " swift / SIL / SILArgument . h " <nl> + # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / AST / ParameterList . h " <nl> # include " swift / Basic / Fallthrough . h " <nl> <nl> mmm a / lib / Sema / CSApply . cpp <nl> ppp b / lib / Sema / CSApply . cpp <nl> <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> # include " ConstraintSystem . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / ASTVisitor . h " <nl> # include " swift / AST / ASTWalker . h " <nl> # include " swift / Basic / StringExtras . h " <nl> mmm a / lib / Sema / CSGen . cpp <nl> ppp b / lib / Sema / CSGen . cpp <nl> namespace { <nl> auto overloadChoice = favoredConstraints [ 0 ] - > getOverloadChoice ( ) ; <nl> auto overloadType = overloadChoice . getDecl ( ) - > getInterfaceType ( ) ; <nl> auto resultType = overloadType - > getAs < AnyFunctionType > ( ) - > getResult ( ) ; <nl> - resultType = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - overloadChoice . getDecl ( ) - > getInnermostDeclContext ( ) , <nl> - resultType ) ; <nl> + resultType = overloadChoice . getDecl ( ) - > getInnermostDeclContext ( ) <nl> + - > mapTypeIntoContext ( resultType ) ; <nl> CS . setFavoredType ( expr , resultType . getPointer ( ) ) ; <nl> } <nl> <nl> namespace { <nl> fnTy = fnTy - > getResult ( ) - > castTo < AnyFunctionType > ( ) ; <nl> } <nl> <nl> - Type paramTy = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - value - > getInnermostDeclContext ( ) , fnTy - > getInput ( ) ) ; <nl> - auto resultTy = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - value - > getInnermostDeclContext ( ) , fnTy - > getResult ( ) ) ; <nl> + Type paramTy = value - > getInnermostDeclContext ( ) <nl> + - > mapTypeIntoContext ( fnTy - > getInput ( ) ) ; <nl> + auto resultTy = value - > getInnermostDeclContext ( ) <nl> + - > mapTypeIntoContext ( fnTy - > getResult ( ) ) ; <nl> auto contextualTy = CS . getContextualType ( expr ) ; <nl> <nl> return isFavoredParamAndArg ( <nl> namespace { <nl> } <nl> } <nl> Type paramTy = fnTy - > getInput ( ) ; <nl> - paramTy = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - value - > getInnermostDeclContext ( ) , paramTy ) ; <nl> + paramTy = value - > getInnermostDeclContext ( ) <nl> + - > mapTypeIntoContext ( paramTy ) ; <nl> <nl> return favoredTy - > isEqual ( paramTy ) ; <nl> } ; <nl> namespace { <nl> fnTy = fnTy - > getResult ( ) - > castTo < AnyFunctionType > ( ) ; <nl> } <nl> <nl> - Type paramTy = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - value - > getInnermostDeclContext ( ) , fnTy - > getInput ( ) ) ; <nl> + Type paramTy = value - > getInnermostDeclContext ( ) <nl> + - > mapTypeIntoContext ( fnTy - > getInput ( ) ) ; <nl> auto paramTupleTy = paramTy - > getAs < TupleType > ( ) ; <nl> if ( ! paramTupleTy | | paramTupleTy - > getNumElements ( ) ! = 2 ) <nl> return false ; <nl> namespace { <nl> auto firstParamTy = paramTupleTy - > getElement ( 0 ) . getType ( ) ; <nl> auto secondParamTy = paramTupleTy - > getElement ( 1 ) . getType ( ) ; <nl> <nl> - auto resultTy = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - value - > getInnermostDeclContext ( ) , fnTy - > getResult ( ) ) ; <nl> + auto resultTy = value - > getInnermostDeclContext ( ) <nl> + - > mapTypeIntoContext ( fnTy - > getResult ( ) ) ; <nl> auto contextualTy = CS . getContextualType ( expr ) ; <nl> <nl> return <nl> namespace { <nl> if ( FD - > getHaveFoundCommonOverloadReturnType ( ) ) { <nl> outputTy = FD - > getInterfaceType ( ) - > getAs < AnyFunctionType > ( ) <nl> - > getResult ( ) ; <nl> - outputTy = ArchetypeBuilder : : mapTypeIntoContext ( FD , outputTy ) ; <nl> + outputTy = FD - > mapTypeIntoContext ( outputTy ) ; <nl> } <nl> <nl> } else { <nl> namespace { <nl> } <nl> <nl> resultType = OFT - > getResult ( ) ; <nl> - resultType = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - OFD , resultType ) ; <nl> + resultType = OFD - > mapTypeIntoContext ( resultType ) ; <nl> <nl> if ( commonType . isNull ( ) ) { <nl> commonType = resultType ; <nl> mmm a / lib / Sema / CSRanking . cpp <nl> ppp b / lib / Sema / CSRanking . cpp <nl> <nl> / / <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> # include " ConstraintSystem . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " llvm / ADT / Statistic . h " <nl> <nl> using namespace swift ; <nl> static bool isProtocolExtensionAsSpecializedAs ( TypeChecker & tc , <nl> Type selfType2 = sig2 - > getGenericParams ( ) [ 0 ] ; <nl> cs . addConstraint ( ConstraintKind : : Bind , <nl> replacements [ selfType2 - > getCanonicalType ( ) ] , <nl> - ArchetypeBuilder : : mapTypeIntoContext ( dc1 , selfType1 ) , <nl> + dc1 - > mapTypeIntoContext ( selfType1 ) , <nl> nullptr ) ; <nl> <nl> / / Solve the system . If the first extension is at least as specialized as the <nl> static bool isDeclAsSpecializedAs ( TypeChecker & tc , DeclContext * dc , <nl> } <nl> <nl> for ( const auto & replacement : replacements ) { <nl> - if ( auto mapped = <nl> - ArchetypeBuilder : : mapTypeIntoContext ( dc1 , <nl> - replacement . first ) ) { <nl> + if ( auto mapped = dc1 - > mapTypeIntoContext ( replacement . first ) ) { <nl> cs . addConstraint ( ConstraintKind : : Bind , replacement . second , mapped , <nl> locator ) ; <nl> } <nl> ConstraintSystem : : compareSolutions ( ConstraintSystem & cs , <nl> <nl> / / If both are convenience initializers , and the instance type of <nl> / / one is a subtype of the other ' s , favor the subtype constructor . <nl> - auto resType1 = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - ctor1 , ctor1 - > getResultInterfaceType ( ) ) ; <nl> - auto resType2 = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - ctor2 , ctor2 - > getResultInterfaceType ( ) ) ; <nl> + auto resType1 = ctor1 - > mapTypeIntoContext ( <nl> + ctor1 - > getResultInterfaceType ( ) ) ; <nl> + auto resType2 = ctor2 - > mapTypeIntoContext ( <nl> + ctor2 - > getResultInterfaceType ( ) ) ; <nl> <nl> if ( ! resType1 - > isEqual ( resType2 ) ) { <nl> if ( tc . isSubtypeOf ( resType1 , resType2 , cs . DC ) ) { <nl> mmm a / lib / Sema / CSSimplify . cpp <nl> ppp b / lib / Sema / CSSimplify . cpp <nl> performMemberLookup ( ConstraintKind constraintKind , DeclName memberName , <nl> fnTypeWithSelf - > getResult ( ) - > getAs < FunctionType > ( ) ) { <nl> <nl> auto argType = fnType - > getInput ( ) - > getWithoutParens ( ) ; <nl> - argType = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - ctor . Decl - > getInnermostDeclContext ( ) , argType ) ; <nl> + argType = ctor . Decl - > getInnermostDeclContext ( ) <nl> + - > mapTypeIntoContext ( argType ) ; <nl> if ( argType - > isEqual ( favoredType ) ) <nl> result . FavoredChoice = result . ViableCandidates . size ( ) ; <nl> } <nl> mmm a / lib / Sema / CodeSynthesis . cpp <nl> ppp b / lib / Sema / CodeSynthesis . cpp <nl> swift : : createDesignatedInitOverride ( TypeChecker & tc , <nl> / / immediate superclass . <nl> Type superclassTyInCtor = superclassCtor - > getDeclContext ( ) - > getDeclaredTypeOfContext ( ) ; <nl> Type superclassTy = classDecl - > getSuperclass ( ) ; <nl> - Type superclassTyInContext = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - classDecl , superclassTy ) ; <nl> + Type superclassTyInContext = classDecl - > mapTypeIntoContext ( superclassTy ) ; <nl> NominalTypeDecl * superclassDecl = superclassTy - > getAnyNominal ( ) ; <nl> if ( superclassTyInCtor - > getAnyNominal ( ) ! = superclassDecl ) { <nl> return nullptr ; <nl> swift : : createDesignatedInitOverride ( TypeChecker & tc , <nl> <nl> / / Map it to an interface type in terms of the derived class <nl> / / generic signature . <nl> - decl - > setInterfaceType ( ArchetypeBuilder : : mapTypeOutOfContext ( <nl> - classDecl , paramSubstTy ) ) ; <nl> + decl - > setInterfaceType ( classDecl - > mapTypeOutOfContext ( paramSubstTy ) ) ; <nl> } <nl> } else { <nl> for ( auto * decl : * bodyParams ) { <nl> mmm a / lib / Sema / ConstraintSystem . cpp <nl> ppp b / lib / Sema / ConstraintSystem . cpp <nl> ConstraintSystem : : getTypeOfMemberReference ( <nl> Type memberTy = isTypeReference <nl> ? assocType - > getDeclaredInterfaceType ( ) <nl> : assocType - > getInterfaceType ( ) ; <nl> - memberTy = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - assocType - > getProtocol ( ) , memberTy ) ; <nl> + memberTy = assocType - > getProtocol ( ) - > mapTypeIntoContext ( memberTy ) ; <nl> auto openedType = FunctionType : : get ( baseObjTy , memberTy ) ; <nl> return { openedType , memberTy } ; <nl> } <nl> mmm a / lib / Sema / DerivedConformanceEquatableHashable . cpp <nl> ppp b / lib / Sema / DerivedConformanceEquatableHashable . cpp <nl> <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> # include " TypeChecker . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / Decl . h " <nl> # include " swift / AST / Stmt . h " <nl> # include " swift / AST / Expr . h " <nl> mmm a / lib / Sema / DerivedConformanceError . cpp <nl> ppp b / lib / Sema / DerivedConformanceError . cpp <nl> <nl> <nl> # include " TypeChecker . h " <nl> # include " DerivedConformances . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / Decl . h " <nl> # include " swift / AST / Stmt . h " <nl> # include " swift / AST / Expr . h " <nl> mmm a / lib / Sema / DerivedConformanceRawRepresentable . cpp <nl> ppp b / lib / Sema / DerivedConformanceRawRepresentable . cpp <nl> <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> # include " TypeChecker . h " <nl> - # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / Decl . h " <nl> # include " swift / AST / Stmt . h " <nl> # include " swift / AST / Expr . h " <nl> static Type deriveRawRepresentable_Raw ( TypeChecker & tc , Decl * parentDecl , <nl> / / typealias Raw = SomeType <nl> / / } <nl> auto rawInterfaceType = enumDecl - > getRawType ( ) ; <nl> - return ArchetypeBuilder : : mapTypeIntoContext ( cast < DeclContext > ( parentDecl ) , <nl> - rawInterfaceType ) ; <nl> + return cast < DeclContext > ( parentDecl ) - > mapTypeIntoContext ( rawInterfaceType ) ; <nl> } <nl> <nl> static void deriveBodyRawRepresentable_raw ( AbstractFunctionDecl * toRawDecl ) { <nl> static void deriveBodyRawRepresentable_raw ( AbstractFunctionDecl * toRawDecl ) { <nl> <nl> Type rawTy = enumDecl - > getRawType ( ) ; <nl> assert ( rawTy ) ; <nl> - rawTy = ArchetypeBuilder : : mapTypeIntoContext ( toRawDecl , rawTy ) ; <nl> + rawTy = toRawDecl - > mapTypeIntoContext ( rawTy ) ; <nl> <nl> for ( auto elt : enumDecl - > getAllElements ( ) ) { <nl> assert ( elt - > getTypeCheckedRawValueExpr ( ) & & <nl> deriveBodyRawRepresentable_init ( AbstractFunctionDecl * initDecl ) { <nl> <nl> Type rawTy = enumDecl - > getRawType ( ) ; <nl> assert ( rawTy ) ; <nl> - rawTy = ArchetypeBuilder : : mapTypeIntoContext ( initDecl , rawTy ) ; <nl> + rawTy = initDecl - > mapTypeIntoContext ( rawTy ) ; <nl> <nl> for ( auto elt : enumDecl - > getAllElements ( ) ) { <nl> assert ( elt - > getTypeCheckedRawValueExpr ( ) & & <nl> static bool canSynthesizeRawRepresentable ( TypeChecker & tc , Decl * parentDecl , Enu <nl> if ( ! rawType ) <nl> return false ; <nl> auto parentDC = cast < DeclContext > ( parentDecl ) ; <nl> - rawType = ArchetypeBuilder : : mapTypeIntoContext ( parentDC , rawType ) ; <nl> + rawType = parentDC - > mapTypeIntoContext ( rawType ) ; <nl> <nl> if ( ! enumDecl - > getInherited ( ) . empty ( ) & & <nl> enumDecl - > getInherited ( ) . front ( ) . isError ( ) ) <nl> mmm a / lib / Sema / MiscDiagnostics . cpp <nl> ppp b / lib / Sema / MiscDiagnostics . cpp <nl> bool swift : : fixItOverrideDeclarationTypes ( InFlightDiagnostic & diag , <nl> } ) ; <nl> } <nl> if ( auto * method = dyn_cast < FuncDecl > ( decl ) ) { <nl> - auto resultType = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - method , method - > getResultInterfaceType ( ) ) ; <nl> + auto resultType = method - > mapTypeIntoContext ( <nl> + method - > getResultInterfaceType ( ) ) ; <nl> <nl> auto * baseMethod = cast < FuncDecl > ( base ) ; <nl> - auto baseResultType = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - baseMethod , baseMethod - > getResultInterfaceType ( ) ) ; <nl> + auto baseResultType = baseMethod - > mapTypeIntoContext ( <nl> + baseMethod - > getResultInterfaceType ( ) ) ; <nl> <nl> fixedAny | = checkType ( resultType , baseResultType , <nl> method - > getBodyResultTypeLoc ( ) . getSourceRange ( ) ) ; <nl> bool swift : : fixItOverrideDeclarationTypes ( InFlightDiagnostic & diag , <nl> fixedAny | = fixItOverrideDeclarationTypes ( diag , param , baseParam ) ; <nl> } ) ; <nl> <nl> - auto resultType = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - subscript - > getDeclContext ( ) , <nl> + auto resultType = subscript - > getDeclContext ( ) - > mapTypeIntoContext ( <nl> subscript - > getElementInterfaceType ( ) ) ; <nl> - auto baseResultType = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - baseSubscript - > getDeclContext ( ) , <nl> + auto baseResultType = baseSubscript - > getDeclContext ( ) - > mapTypeIntoContext ( <nl> baseSubscript - > getElementInterfaceType ( ) ) ; <nl> fixedAny | = checkType ( resultType , baseResultType , <nl> subscript - > getElementTypeLoc ( ) . getSourceRange ( ) ) ; <nl> Optional < DeclName > TypeChecker : : omitNeedlessWords ( AbstractFunctionDecl * afd ) { <nl> <nl> if ( auto func = dyn_cast < FuncDecl > ( afd ) ) { <nl> resultType = func - > getResultInterfaceType ( ) ; <nl> - resultType = ArchetypeBuilder : : mapTypeIntoContext ( func , resultType ) ; <nl> + resultType = func - > mapTypeIntoContext ( resultType ) ; <nl> returnsSelf = func - > hasDynamicSelf ( ) ; <nl> } else if ( isa < ConstructorDecl > ( afd ) ) { <nl> resultType = contextType ; <nl> mmm a / lib / Sema / TypeCheckDecl . cpp <nl> ppp b / lib / Sema / TypeCheckDecl . cpp <nl> void TypeChecker : : checkInheritanceClause ( Decl * decl , <nl> / / the only time we get an interface type here is with invalid <nl> / / circular cases . That should be diagnosed elsewhere . <nl> if ( inheritedTy - > hasArchetype ( ) & & ! isa < GenericTypeParamDecl > ( decl ) ) <nl> - inheritedTy = ArchetypeBuilder : : mapTypeOutOfContext ( DC , inheritedTy ) ; <nl> + inheritedTy = DC - > mapTypeOutOfContext ( inheritedTy ) ; <nl> <nl> / / Check whether we inherited from the same type twice . <nl> CanType inheritedCanTy = inheritedTy - > getCanonicalType ( ) ; <nl> static void checkEnumRawValues ( TypeChecker & TC , EnumDecl * ED ) { <nl> } <nl> <nl> if ( ED - > getGenericEnvironmentOfContext ( ) ! = nullptr ) <nl> - rawTy = ArchetypeBuilder : : mapTypeIntoContext ( ED , rawTy ) ; <nl> + rawTy = ED - > mapTypeIntoContext ( rawTy ) ; <nl> if ( rawTy - > hasError ( ) ) <nl> return ; <nl> <nl> class DeclChecker : public DeclVisitor < DeclChecker > { <nl> <nl> configureImplicitSelf ( TC , CD ) ; <nl> <nl> - Optional < ArchetypeBuilder > builder ; <nl> if ( auto gp = CD - > getGenericParams ( ) ) { <nl> / / Write up generic parameters and check the generic parameter list . <nl> gp - > setOuterParameters ( CD - > getDeclContext ( ) - > getGenericParamsOfContext ( ) ) ; <nl> void TypeChecker : : addImplicitEnumConformances ( EnumDecl * ED ) { <nl> assert ( elt - > hasRawValueExpr ( ) ) ; <nl> if ( elt - > getTypeCheckedRawValueExpr ( ) ) continue ; <nl> Expr * typeChecked = elt - > getRawValueExpr ( ) ; <nl> - Type rawTy = ArchetypeBuilder : : mapTypeIntoContext ( ED , ED - > getRawType ( ) ) ; <nl> + Type rawTy = ED - > mapTypeIntoContext ( ED - > getRawType ( ) ) ; <nl> bool error = typeCheckExpression ( typeChecked , ED , <nl> TypeLoc : : withoutLoc ( rawTy ) , <nl> CTP_EnumCaseRawValue ) ; <nl> mmm a / lib / Sema / TypeCheckGeneric . cpp <nl> ppp b / lib / Sema / TypeCheckGeneric . cpp <nl> Type GenericTypeToArchetypeResolver : : resolveTypeOfContext ( DeclContext * dc ) { <nl> ! dc - > isValidGenericContext ( ) ) <nl> return dc - > getSelfInterfaceType ( ) ; <nl> <nl> - return ArchetypeBuilder : : mapTypeIntoContext ( <nl> + return GenericEnvironment : : mapTypeIntoContext ( <nl> dc - > getParentModule ( ) , GenericEnv , <nl> dc - > getSelfInterfaceType ( ) ) ; <nl> } <nl> Type GenericTypeToArchetypeResolver : : resolveTypeOfDecl ( TypeDecl * decl ) { <nl> return dc - > mapTypeIntoContext ( paramDecl - > getDeclaredInterfaceType ( ) ) ; <nl> } <nl> <nl> - return ArchetypeBuilder : : mapTypeIntoContext ( <nl> + return GenericEnvironment : : mapTypeIntoContext ( <nl> dc - > getParentModule ( ) , GenericEnv , <nl> decl - > getDeclaredInterfaceType ( ) ) ; <nl> } <nl> void GenericTypeToArchetypeResolver : : recordParamType ( ParamDecl * decl , Type type ) <nl> / / When type checking functions , the CompleteGenericTypeResolver sets <nl> / / the interface type . <nl> if ( ! decl - > hasInterfaceType ( ) ) <nl> - decl - > setInterfaceType ( ArchetypeBuilder : : mapTypeOutOfContext ( GenericEnv , <nl> - type ) ) ; <nl> + decl - > setInterfaceType ( GenericEnvironment : : mapTypeOutOfContext ( <nl> + GenericEnv , type ) ) ; <nl> } <nl> <nl> Type CompleteGenericTypeResolver : : resolveGenericTypeParamType ( <nl> mmm a / lib / Sema / TypeCheckProtocol . cpp <nl> ppp b / lib / Sema / TypeCheckProtocol . cpp <nl> void ConformanceChecker : : recordTypeWitness ( AssociatedTypeDecl * assocType , <nl> } <nl> <nl> / / Record the type witness . <nl> - auto * archetype = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - Conformance - > getProtocol ( ) , assocType - > getDeclaredInterfaceType ( ) ) <nl> + auto * archetype = Conformance - > getProtocol ( ) - > mapTypeIntoContext ( <nl> + assocType - > getDeclaredInterfaceType ( ) ) <nl> - > getAs < ArchetypeType > ( ) ; <nl> if ( archetype ) <nl> Conformance - > setTypeWitness ( <nl> void ConformanceChecker : : resolveTypeWitnesses ( ) { <nl> / / Create a set of type substitutions for all known associated type . <nl> / / FIXME : Base this on dependent types rather than archetypes ? <nl> TypeSubstitutionMap substitutions ; <nl> - substitutions [ ArchetypeBuilder : : mapTypeIntoContext ( Proto , selfType ) <nl> - - > getCanonicalType ( ) - > castTo < ArchetypeType > ( ) ] = Adoptee ; <nl> + substitutions [ Proto - > mapTypeIntoContext ( selfType ) <nl> + - > castTo < ArchetypeType > ( ) ] = Adoptee ; <nl> for ( auto member : Proto - > getMembers ( ) ) { <nl> if ( auto assocType = dyn_cast < AssociatedTypeDecl > ( member ) ) { <nl> - auto archetype = ArchetypeBuilder : : mapTypeIntoContext ( <nl> - Proto , assocType - > getDeclaredInterfaceType ( ) ) <nl> + auto archetype = Proto - > mapTypeIntoContext ( <nl> + assocType - > getDeclaredInterfaceType ( ) ) <nl> - > getAs < ArchetypeType > ( ) ; <nl> if ( ! archetype ) <nl> continue ; <nl> mmm a / lib / Sema / TypeCheckType . cpp <nl> ppp b / lib / Sema / TypeCheckType . cpp <nl> Type TypeResolver : : resolveASTFunctionType ( FunctionTypeRepr * repr , <nl> <nl> / / SIL uses polymorphic function types to resolve overloaded member functions . <nl> if ( auto genericEnv = repr - > getGenericEnvironment ( ) ) { <nl> - auto * genericSig = repr - > getGenericSignature ( ) ; <nl> - assert ( genericSig ! = nullptr & & " Did not call handleSILGenericParams ( ) ? " ) ; <nl> - inputTy = ArchetypeBuilder : : mapTypeOutOfContext ( genericEnv , inputTy ) ; <nl> - outputTy = ArchetypeBuilder : : mapTypeOutOfContext ( genericEnv , outputTy ) ; <nl> - return GenericFunctionType : : get ( genericSig , inputTy , outputTy , extInfo ) ; <nl> + inputTy = genericEnv - > mapTypeOutOfContext ( inputTy ) ; <nl> + outputTy = genericEnv - > mapTypeOutOfContext ( outputTy ) ; <nl> + return GenericFunctionType : : get ( genericEnv - > getGenericSignature ( ) , <nl> + inputTy , outputTy , extInfo ) ; <nl> } <nl> <nl> auto fnTy = FunctionType : : get ( inputTy , outputTy , extInfo ) ; <nl> Type TypeResolver : : resolveSILBoxType ( SILBoxTypeRepr * repr , <nl> fields . push_back ( { fieldTy - > getCanonicalType ( ) , fieldRepr . Mutable } ) ; <nl> } <nl> } <nl> - <nl> + <nl> / / Substitute out parsed context types into interface types . <nl> CanGenericSignature genericSig ; <nl> if ( auto * genericEnv = repr - > getGenericEnvironment ( ) ) { <nl> - genericSig = repr - > getGenericSignature ( ) - > getCanonicalSignature ( ) ; <nl> + genericSig = genericEnv - > getGenericSignature ( ) - > getCanonicalSignature ( ) ; <nl> <nl> for ( auto & field : fields ) { <nl> auto transTy = genericEnv - > mapTypeOutOfContext ( field . getLoweredType ( ) ) ; <nl> Type TypeResolver : : resolveSILFunctionType ( FunctionTypeRepr * repr , <nl> SmallVector < SILResultInfo , 4 > interfaceResults ; <nl> Optional < SILResultInfo > interfaceErrorResult ; <nl> if ( auto * genericEnv = repr - > getGenericEnvironment ( ) ) { <nl> - genericSig = repr - > getGenericSignature ( ) - > getCanonicalSignature ( ) ; <nl> + genericSig = genericEnv - > getGenericSignature ( ) - > getCanonicalSignature ( ) ; <nl> <nl> for ( auto & param : params ) { <nl> - auto transParamType = ArchetypeBuilder : : mapTypeOutOfContext ( <nl> - genericEnv , param . getType ( ) ) - > getCanonicalType ( ) ; <nl> + auto transParamType = genericEnv - > mapTypeOutOfContext ( <nl> + param . getType ( ) ) - > getCanonicalType ( ) ; <nl> interfaceParams . push_back ( param . getWithType ( transParamType ) ) ; <nl> } <nl> for ( auto & result : results ) { <nl> - auto transResultType = <nl> - ArchetypeBuilder : : mapTypeOutOfContext ( <nl> - genericEnv , result . getType ( ) ) - > getCanonicalType ( ) ; <nl> + auto transResultType = genericEnv - > mapTypeOutOfContext ( <nl> + result . getType ( ) ) - > getCanonicalType ( ) ; <nl> interfaceResults . push_back ( result . getWithType ( transResultType ) ) ; <nl> } <nl> <nl> if ( errorResult ) { <nl> - auto transErrorResultType = ArchetypeBuilder : : mapTypeOutOfContext ( <nl> - genericEnv , errorResult - > getType ( ) ) - > getCanonicalType ( ) ; <nl> + auto transErrorResultType = genericEnv - > mapTypeOutOfContext ( <nl> + errorResult - > getType ( ) ) - > getCanonicalType ( ) ; <nl> interfaceErrorResult = <nl> errorResult - > getWithType ( transErrorResultType ) ; <nl> } <nl> mmm a / lib / Serialization / Deserialization . cpp <nl> ppp b / lib / Serialization / Deserialization . cpp <nl> <nl> # include " swift / Serialization / ModuleFormat . h " <nl> # include " swift / AST / AST . h " <nl> # include " swift / AST / ASTContext . h " <nl> + # include " swift / AST / ArchetypeBuilder . h " <nl> # include " swift / AST / ForeignErrorConvention . h " <nl> # include " swift / AST / GenericEnvironment . h " <nl> # include " swift / AST / PrettyStackTrace . h " <nl> mmm a / lib / Serialization / Serialization . cpp <nl> ppp b / lib / Serialization / Serialization . cpp <nl> void Serializer : : writeNormalConformance ( <nl> / / If there is no witness , we ' re done . <nl> if ( ! witness . getDecl ( ) ) return ; <nl> <nl> - if ( auto genericSig = witness . requiresSubstitution ( ) <nl> - ? witness . getSyntheticSignature ( ) <nl> + if ( auto genericEnv = witness . requiresSubstitution ( ) <nl> + ? witness . getSyntheticEnvironment ( ) <nl> : nullptr ) { <nl> + auto * genericSig = genericEnv - > getGenericSignature ( ) ; <nl> + <nl> / / Generic parameters . <nl> data . push_back ( genericSig - > getGenericParams ( ) . size ( ) ) ; <nl> for ( auto gp : genericSig - > getGenericParams ( ) ) <nl> void Serializer : : writeNormalConformance ( <nl> / / Bail out early for simple witnesses . <nl> if ( ! witness . getDecl ( ) ) return ; <nl> <nl> - if ( auto genericSig = witness . requiresSubstitution ( ) <nl> - ? witness . getSyntheticSignature ( ) <nl> + if ( auto genericEnv = witness . requiresSubstitution ( ) <nl> + ? witness . getSyntheticEnvironment ( ) <nl> : nullptr ) { <nl> + auto * genericSig = genericEnv - > getGenericSignature ( ) ; <nl> + <nl> / / Write the generic requirements of the synthetic environment . <nl> writeGenericRequirements ( genericSig - > getRequirements ( ) , <nl> DeclTypeAbbrCodes ) ; <nl>
Merge pull request from slavapestov / refactor - map - type - into - outof - context
apple/swift
2ea7951d05a3ff06447a7ee8e7c4baf1917cc2ef
2016-12-19T04:54:54Z
mmm a / modules / prediction / prediction . cc <nl> ppp b / modules / prediction / prediction . cc <nl> void Prediction : : Stop ( ) { <nl> } <nl> <nl> void Prediction : : OnLocalization ( const LocalizationEstimate & localization ) { <nl> - ObstaclesContainer * obstacles_container = dynamic_cast < ObstaclesContainer * > ( <nl> - ContainerManager : : instance ( ) - > GetContainer ( <nl> - AdapterConfig : : PERCEPTION_OBSTACLES ) ) ; <nl> - CHECK_NOTNULL ( obstacles_container ) ; <nl> - <nl> PoseContainer * pose_container = dynamic_cast < PoseContainer * > ( <nl> ContainerManager : : instance ( ) - > GetContainer ( AdapterConfig : : LOCALIZATION ) ) ; <nl> CHECK_NOTNULL ( pose_container ) ; <nl> void Prediction : : RunOnce ( const PerceptionObstacles & perception_obstacles ) { <nl> ros : : shutdown ( ) ; <nl> } <nl> <nl> - ADEBUG < < " Received a perception message [ " <nl> - < < perception_obstacles . ShortDebugString ( ) < < " ] . " ; <nl> - <nl> double start_timestamp = Clock : : NowInSeconds ( ) ; <nl> <nl> / / Insert obstacle <nl> void Prediction : : RunOnce ( const PerceptionObstacles & perception_obstacles ) { <nl> CHECK_NOTNULL ( obstacles_container ) ; <nl> obstacles_container - > Insert ( perception_obstacles ) ; <nl> <nl> + ADEBUG < < " Received a perception message [ " <nl> + < < perception_obstacles . ShortDebugString ( ) < < " ] . " ; <nl> + <nl> / / Update ADC status <nl> PoseContainer * pose_container = dynamic_cast < PoseContainer * > ( <nl> ContainerManager : : instance ( ) - > GetContainer ( AdapterConfig : : LOCALIZATION ) ) ; <nl> void Prediction : : RunOnce ( const PerceptionObstacles & perception_obstacles ) { <nl> adc_container - > SetPosition ( adc_position ) ; <nl> } <nl> <nl> - / / Make predictions <nl> + / / Make evaluations <nl> EvaluatorManager : : instance ( ) - > Run ( perception_obstacles ) ; <nl> <nl> / / No prediction for offline mode <nl> void Prediction : : RunOnce ( const PerceptionObstacles & perception_obstacles ) { <nl> return ; <nl> } <nl> <nl> + / / Make predictions <nl> PredictorManager : : instance ( ) - > Run ( perception_obstacles ) ; <nl> <nl> auto prediction_obstacles = <nl>
Prediction : removed unnecessary logic ( )
ApolloAuto/apollo
d4613ab9ee9f7f1d7e4366b4957afa5c4ddf814a
2018-02-01T01:28:08Z
similarity index 100 % <nl> rename from kokoro / release / macos / build_artifacts . cfg <nl> rename to kokoro / release / macos / release . cfg <nl>
Rename build_artifacts . cfg to release . cfg ( )
protocolbuffers/protobuf
56d27530ab573d8c8a9808bff9542ca2e8a9291a
2018-06-22T20:00:55Z
mmm a / mshadow <nl> ppp b / mshadow <nl> @ @ - 1 + 1 @ @ <nl> - Subproject commit 68d900f4ec1e006872e4bce5d6f9f8b032cd55f9 <nl> + Subproject commit 7ed6fbbbb4b77352f5c212cd52a20bf681250bd8 <nl> mmm a / src / operator / embedding - inl . h <nl> ppp b / src / operator / embedding - inl . h <nl> class EmbeddingOp : public Operator { <nl> CHECK_EQ ( req [ embedding : : kOut ] , kWriteTo ) ; <nl> CHECK_EQ ( in_data . size ( ) , 2 ) ; <nl> CHECK_EQ ( out_data . size ( ) , 1 ) ; <nl> - CHECK_EQ ( in_data [ embedding : : kData ] . ndim ( ) , 1 ) <nl> - < < " Embedding layer expects its input to be one - dimensional . " <nl> - < < in_data [ embedding : : kData ] . ndim ( ) <nl> - < < " dimensional input is given instead " ; <nl> CHECK_EQ ( in_data [ embedding : : kWeight ] . ndim ( ) , 2 ) <nl> < < " Embedding layer expects its weight to be two - dimensional . " <nl> < < in_data [ embedding : : kWeight ] . ndim ( ) <nl> < < " dimensional input is given instead " ; <nl> + <nl> + const TShape & ishape = in_data [ embedding : : kData ] . shape_ ; <nl> + const TShape & oshape = out_data [ embedding : : kOut ] . shape_ ; <nl> + <nl> Stream < xpu > * s = ctx . get_stream < xpu > ( ) ; <nl> - Tensor < xpu , 1 > data = in_data [ embedding : : kData ] . get < xpu , 1 , real_t > ( s ) ; <nl> + Tensor < xpu , 1 > data = in_data [ embedding : : kData ] . get_with_shape < xpu , 1 , real_t > ( <nl> + Shape1 ( ishape . ProdShape ( 0 , ishape . ndim ( ) ) ) , s ) ; <nl> Tensor < xpu , 2 > wmat = in_data [ embedding : : kWeight ] . get < xpu , 2 , real_t > ( s ) ; <nl> - Tensor < xpu , 2 > out = out_data [ embedding : : kOut ] . get < xpu , 2 , real_t > ( s ) ; <nl> + Tensor < xpu , 2 > out = out_data [ embedding : : kOut ] . get_with_shape < xpu , 2 , real_t > ( <nl> + Shape2 ( oshape . ProdShape ( 0 , oshape . ndim ( ) - 1 ) , oshape [ oshape . ndim ( ) - 1 ] ) , s ) ; <nl> out = take ( data , wmat ) ; <nl> } <nl> <nl> class EmbeddingOp : public Operator { <nl> CHECK_EQ ( in_grad . size ( ) , 2 ) ; <nl> CHECK_EQ ( req [ embedding : : kData ] , kNullOp ) <nl> < < " Embedding layer doesn ' t support calculate data gradient " ; <nl> + <nl> + const TShape & ishape = in_data [ embedding : : kData ] . shape_ ; <nl> + const TShape & oshape = out_data [ embedding : : kOut ] . shape_ ; <nl> + <nl> Stream < xpu > * s = ctx . get_stream < xpu > ( ) ; <nl> - Tensor < xpu , 1 > data = in_data [ embedding : : kData ] . get < xpu , 1 , real_t > ( s ) ; <nl> - Tensor < xpu , 2 > grad_out = out_grad [ embedding : : kOut ] . get < xpu , 2 , real_t > ( s ) ; <nl> + Tensor < xpu , 1 > data = in_data [ embedding : : kData ] . get_with_shape < xpu , 1 , real_t > ( <nl> + Shape1 ( ishape . ProdShape ( 0 , ishape . ndim ( ) ) ) , s ) ; <nl> + Tensor < xpu , 2 > grad_out = out_grad [ embedding : : kOut ] . get_with_shape < xpu , 2 , real_t > ( <nl> + Shape2 ( oshape . ProdShape ( 0 , oshape . ndim ( ) - 1 ) , oshape [ oshape . ndim ( ) - 1 ] ) , s ) ; <nl> Tensor < xpu , 2 > grad_in = in_grad [ embedding : : kWeight ] . get < xpu , 2 , real_t > ( s ) ; <nl> if ( req [ embedding : : kWeight ] = = kWriteTo ) { <nl> grad_in = 0 . 0f ; <nl> class EmbeddingProp : public OperatorProperty { <nl> SHAPE_ASSIGN_CHECK ( * in_shape , embedding : : kWeight , Shape2 ( param_ . input_dim , <nl> param_ . output_dim ) ) ; <nl> out_shape - > clear ( ) ; <nl> - out_shape - > push_back ( Shape2 ( dshape [ 0 ] , param_ . output_dim ) ) ; <nl> + <nl> + TShape oshape ( dshape . ndim ( ) + 1 ) ; <nl> + for ( size_t i = 0 ; i < dshape . ndim ( ) ; + + i ) { <nl> + oshape [ i ] = dshape [ i ] ; <nl> + } <nl> + oshape [ dshape . ndim ( ) ] = param_ . output_dim ; <nl> + <nl> + out_shape - > push_back ( oshape ) ; <nl> return true ; <nl> } <nl> <nl>
allow multi - dimension for embedding layer
apache/incubator-mxnet
32a245284610aec08adcd5679ee0708e21cc3301
2016-04-13T15:01:54Z
mmm a / include / swift / AST / Decl . h <nl> ppp b / include / swift / AST / Decl . h <nl> <nl> # include " swift / AST / ConcreteDeclRef . h " <nl> # include " swift / AST / DefaultArgumentKind . h " <nl> # include " swift / AST / DiagnosticConsumer . h " <nl> + # include " swift / AST / DiagnosticEngine . h " <nl> # include " swift / AST / GenericParamKey . h " <nl> # include " swift / AST / IfConfigClause . h " <nl> # include " swift / AST / LayoutConstraint . h " <nl> class alignas ( 1 < < DeclAlignInBits ) Decl { <nl> / / / If this returns true , the decl can be safely casted to ValueDecl . <nl> bool isPotentiallyOverridable ( ) const ; <nl> <nl> + / / / Emit a diagnostic tied to this declaration . <nl> + template < typename . . . ArgTypes > <nl> + InFlightDiagnostic diagnose ( <nl> + Diag < ArgTypes . . . > ID , <nl> + typename detail : : PassArgument < ArgTypes > : : type . . . Args ) const { <nl> + return getDiags ( ) . diagnose ( this , ID , std : : move ( Args ) . . . ) ; <nl> + } <nl> + <nl> + / / / Retrieve the diagnostic engine for diagnostics emission . <nl> + DiagnosticEngine & getDiags ( ) const ; <nl> + <nl> / / Make vanilla new / delete illegal for Decls . <nl> void * operator new ( size_t Bytes ) = delete ; <nl> void operator delete ( void * Data ) SWIFT_DELETE_OPERATOR_DELETED ; <nl> mmm a / lib / AST / Decl . cpp <nl> ppp b / lib / AST / Decl . cpp <nl> ModuleDecl * Decl : : getModuleContext ( ) const { <nl> return getDeclContext ( ) - > getParentModule ( ) ; <nl> } <nl> <nl> + / / / Retrieve the diagnostic engine for diagnostics emission . <nl> + DiagnosticEngine & Decl : : getDiags ( ) const { <nl> + return getASTContext ( ) . Diags ; <nl> + } <nl> + <nl> / / Helper functions to verify statically whether source - location <nl> / / functions have been overridden . <nl> typedef const char ( & TwoChars ) [ 2 ] ; <nl>
[ AST ] Add Decl : : diagnose ( ) .
apple/swift
9a73d79da7310d2074dba70232c60077aa99e821
2018-07-05T16:20:53Z
mmm a / src / elements . cc <nl> ppp b / src / elements . cc <nl> class SloppyArgumentsElementsAccessor <nl> Handle < FixedArrayBase > backing_store , GetKeysConversion convert , <nl> PropertyFilter filter , Handle < FixedArray > list , uint32_t * nof_indices , <nl> uint32_t insertion_index = 0 ) { <nl> - FixedArray * parameter_map = FixedArray : : cast ( * backing_store ) ; <nl> + Handle < FixedArray > parameter_map ( FixedArray : : cast ( * backing_store ) , isolate ) ; <nl> uint32_t length = parameter_map - > length ( ) - 2 ; <nl> <nl> for ( uint32_t i = 0 ; i < length ; + + i ) { <nl> class SloppyArgumentsElementsAccessor <nl> uint32_t start_from , uint32_t length ) { <nl> DCHECK ( JSObject : : PrototypeHasNoElements ( isolate , * object ) ) ; <nl> Handle < Map > original_map = handle ( object - > map ( ) , isolate ) ; <nl> - FixedArray * parameter_map = FixedArray : : cast ( object - > elements ( ) ) ; <nl> + Handle < FixedArray > parameter_map ( FixedArray : : cast ( object - > elements ( ) ) , <nl> + isolate ) ; <nl> bool search_for_hole = value - > IsUndefined ( isolate ) ; <nl> <nl> for ( uint32_t k = start_from ; k < length ; + + k ) { <nl> uint32_t entry = <nl> - GetEntryForIndexImpl ( * object , parameter_map , k , ALL_PROPERTIES ) ; <nl> + GetEntryForIndexImpl ( * object , * parameter_map , k , ALL_PROPERTIES ) ; <nl> if ( entry = = kMaxUInt32 ) { <nl> if ( search_for_hole ) return Just ( true ) ; <nl> continue ; <nl> } <nl> <nl> - Handle < Object > element_k = GetImpl ( parameter_map , entry ) ; <nl> + Handle < Object > element_k = GetImpl ( * parameter_map , entry ) ; <nl> <nl> if ( element_k - > IsAccessorPair ( ) ) { <nl> LookupIterator it ( isolate , object , k , LookupIterator : : OWN ) ; <nl> new file mode 100644 <nl> index 00000000000 . . d586b804959 <nl> mmm / dev / null <nl> ppp b / test / mjsunit / regress / regress - 648373 - sloppy - arguments - includesValues . js <nl> <nl> + / / Copyright 2016 the V8 project authors . All rights reserved . <nl> + / / Use of this source code is governed by a BSD - style license that can be <nl> + / / found in the LICENSE file . <nl> + <nl> + / / Flags : - - allow - natives - syntax - - expose - gc <nl> + <nl> + function getRandomProperty ( v , rand ) { var properties = Object . getOwnPropertyNames ( v ) ; var proto = Object . getPrototypeOf ( v ) ; if ( proto ) { ; } if ( " constructor " & & v . constructor . hasOwnProperty ( ) ) { ; } if ( properties . length = = 0 ) { return " 0 " ; } return properties [ rand % properties . length ] ; } <nl> + var __v_4 = { } ; <nl> + <nl> + __v_2 = { <nl> + FAST_ELEMENTS ( ) { <nl> + return { <nl> + get 0 ( ) { <nl> + } } ; <nl> + } , <nl> + Arguments : { <nl> + FAST_SLOPPY_ARGUMENTS_ELEMENTS ( ) { <nl> + var __v_11 = ( function ( b ) { return arguments ; } ) ( " foo " , NaN , " bar " ) ; <nl> + __v_11 . __p_2006760047 = __v_11 [ getRandomProperty ( 2006760047 ) ] ; <nl> + __v_11 . __defineGetter__ ( getRandomProperty ( 1698457573 ) , function ( ) { gc ( ) ; __v_4 [ 1486458228 ] = __v_2 [ 1286067691 ] ; return __v_11 . __p_2006760047 ; } ) ; <nl> + ; <nl> + Array . prototype . includes . call ( __v_11 ) ; <nl> + } , <nl> + Detached_Float64Array ( ) { <nl> + } } <nl> + } ; <nl> + function __f_3 ( suites ) { <nl> + Object . keys ( suites ) . forEach ( suite = > __f_4 ( suites [ suite ] ) ) ; <nl> + function __f_4 ( suite ) { <nl> + Object . keys ( suite ) . forEach ( test = > suite [ test ] ( ) ) ; <nl> + } <nl> + } <nl> + __f_3 ( __v_2 ) ; <nl>
[ elements ] Handlify raw parameter_map pointers for SloppyArgumentsAccessor
v8/v8
2fd6d6093e746b561e8711897707ef7ce0e14467
2016-09-21T10:22:53Z
mmm a / docs / source / type_info . rst <nl> ppp b / docs / source / type_info . rst <nl> max float The largest representable number . <nl> tiny float The smallest positive representable number . <nl> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> <nl> + . . note : : <nl> + The constructor of : class : ` torch . finfo ` can be called without argument , in which case the class is created for the pytorch default dtype ( as returned by ` ` torch . get_default_dtype ( ) ` ` ) . <nl> + <nl> <nl> . . _iinfo - doc : <nl> <nl> mmm a / test / test_type_info . py <nl> ppp b / test / test_type_info . py <nl> def test_iinfo ( self ) : <nl> <nl> @ unittest . skipIf ( not TEST_NUMPY , " Numpy not found " ) <nl> def test_finfo ( self ) : <nl> + initial_default_type = torch . get_default_dtype ( ) <nl> for dtype in [ torch . float32 , torch . float64 ] : <nl> x = torch . zeros ( ( 2 , 2 ) , dtype = dtype ) <nl> xinfo = torch . finfo ( x . dtype ) <nl> def test_finfo ( self ) : <nl> self . assertEqual ( xinfo . max , xninfo . max ) <nl> self . assertEqual ( xinfo . eps , xninfo . eps ) <nl> self . assertEqual ( xinfo . tiny , xninfo . tiny ) <nl> - <nl> + torch . set_default_dtype ( dtype ) <nl> + self . assertEqual ( torch . finfo ( dtype ) , torch . finfo ( ) ) <nl> + # Restore the default type to ensure that the test has no side effect <nl> + torch . set_default_dtype ( initial_default_type ) <nl> <nl> if __name__ = = ' __main__ ' : <nl> run_tests ( ) <nl> mmm a / torch / csrc / TypeInfo . cpp <nl> ppp b / torch / csrc / TypeInfo . cpp <nl> PyObject * THPFInfo_pynew ( PyTypeObject * type , PyObject * args , PyObject * kwargs ) { <nl> HANDLE_TH_ERRORS <nl> static torch : : PythonArgParser parser ( { <nl> " finfo ( ScalarType type ) " , <nl> + " finfo ( ) " , <nl> } ) ; <nl> + <nl> torch : : ParsedArgs < 1 > parsed_args ; <nl> auto r = parser . parse ( args , kwargs , parsed_args ) ; <nl> - AT_CHECK ( r . idx = = 0 , " Not a type " ) ; <nl> - at : : ScalarType scalar_type = r . scalartype ( 0 ) ; <nl> - if ( ! at : : isFloatingType ( scalar_type ) ) { <nl> - return PyErr_Format ( <nl> - PyExc_TypeError , <nl> - " torch . finfo ( ) requires a floating point input type . Use torch . iinfo to handle ' % s ' " , <nl> - type - > tp_name ) ; <nl> + AT_CHECK ( r . idx < 2 , " Not a type " ) ; <nl> + at : : ScalarType scalar_type ; <nl> + if ( r . idx = = 1 ) { <nl> + scalar_type = torch : : tensors : : get_default_tensor_type ( ) . scalarType ( ) ; <nl> + / / The default tensor type can only be set to a floating point type / <nl> + AT_ASSERT ( at : : isFloatingType ( scalar_type ) ) ; <nl> + } else { <nl> + scalar_type = r . scalartype ( 0 ) ; <nl> + if ( ! at : : isFloatingType ( scalar_type ) ) { <nl> + return PyErr_Format ( <nl> + PyExc_TypeError , <nl> + " torch . finfo ( ) requires a floating point input type . Use torch . iinfo to handle ' % s ' " , <nl> + type - > tp_name ) ; <nl> + } <nl> } <nl> return THPFInfo_New ( scalar_type ) ; <nl> END_HANDLE_TH_ERRORS <nl> PyObject * THPIInfo_pynew ( PyTypeObject * type , PyObject * args , PyObject * kwargs ) { <nl> END_HANDLE_TH_ERRORS <nl> } <nl> <nl> + PyObject * THPDTypeInfo_compare ( THPDTypeInfo * a , THPDTypeInfo * b , int op ) { <nl> + switch ( op ) { <nl> + case Py_EQ : <nl> + if ( a - > type = = b - > type ) { <nl> + Py_RETURN_TRUE ; <nl> + } else { <nl> + Py_RETURN_FALSE ; <nl> + } <nl> + case Py_NE : <nl> + if ( a - > type ! = b - > type ) { <nl> + Py_RETURN_TRUE ; <nl> + } else { <nl> + Py_RETURN_FALSE ; <nl> + } <nl> + } <nl> + return Py_INCREF ( Py_NotImplemented ) , Py_NotImplemented ; <nl> + } <nl> + <nl> static PyObject * THPDTypeInfo_bits ( THPDTypeInfo * self , void * ) { <nl> int bits = elementSize ( self - > type ) * 8 ; <nl> return THPUtils_packInt64 ( bits ) ; <nl> PyTypeObject THPFInfoType = { <nl> nullptr , / * tp_doc * / <nl> 0 , / * tp_traverse * / <nl> 0 , / * tp_clear * / <nl> - 0 , / * tp_richcompare * / <nl> + ( richcmpfunc ) THPDTypeInfo_compare , / * tp_richcompare * / <nl> 0 , / * tp_weaklistoffset * / <nl> 0 , / * tp_iter * / <nl> 0 , / * tp_iternext * / <nl> PyTypeObject THPIInfoType = { <nl> nullptr , / * tp_doc * / <nl> 0 , / * tp_traverse * / <nl> 0 , / * tp_clear * / <nl> - 0 , / * tp_richcompare * / <nl> + ( richcmpfunc ) THPDTypeInfo_compare , / * tp_richcompare * / <nl> 0 , / * tp_weaklistoffset * / <nl> 0 , / * tp_iter * / <nl> 0 , / * tp_iternext * / <nl>
Added a default constructor for torch . finfo .
pytorch/pytorch
3fb3a07f54ea240dab686b123974f2d1f812fb2d
2018-10-23T16:03:24Z
mmm a / src / Common / ZooKeeper / ZooKeeper . cpp <nl> ppp b / src / Common / ZooKeeper / ZooKeeper . cpp <nl> void ZooKeeper : : init ( const std : : string & implementation_ , const std : : string & ho <nl> Coordination : : ZooKeeper : : Nodes nodes ; <nl> nodes . reserve ( hosts_strings . size ( ) ) ; <nl> <nl> + bool dns_error = false ; <nl> for ( auto & host_string : hosts_strings ) <nl> { <nl> try <nl> void ZooKeeper : : init ( const std : : string & implementation_ , const std : : string & ho <nl> <nl> nodes . emplace_back ( Coordination : : ZooKeeper : : Node { Poco : : Net : : SocketAddress { host_string } , secure } ) ; <nl> } <nl> - catch ( const Poco : : Net : : DNSException & e ) <nl> + catch ( const Poco : : Net : : HostNotFoundException & e ) <nl> { <nl> + / / / Most likely it ' s misconfiguration and wrong hostname was specified <nl> LOG_ERROR ( log , " Cannot use ZooKeeper host { } , reason : { } " , host_string , e . displayText ( ) ) ; <nl> } <nl> + catch ( const Poco : : Net : : DNSException & e ) <nl> + { <nl> + / / / Most likely DNS is not available now <nl> + dns_error = true ; <nl> + LOG_ERROR ( log , " Cannot use ZooKeeper host { } due to DNS error : { } " , host_string , e . displayText ( ) ) ; <nl> + } <nl> } <nl> <nl> if ( nodes . empty ( ) ) <nl> - throw KeeperException ( " Cannot use any of provided ZooKeeper nodes " , Coordination : : Error : : ZBADARGUMENTS ) ; <nl> + { <nl> + / / / For DNS errors we throw exception with ZCONNECTIONLOSS code , so it will be considered as hardware error , not user error <nl> + if ( dns_error ) <nl> + throw KeeperException ( " Cannot resolve any of provided ZooKeeper hosts due to DNS error " , Coordination : : Error : : ZCONNECTIONLOSS ) ; <nl> + else <nl> + throw KeeperException ( " Cannot use any of provided ZooKeeper nodes " , Coordination : : Error : : ZBADARGUMENTS ) ; <nl> + } <nl> <nl> impl = std : : make_unique < Coordination : : ZooKeeper > ( <nl> nodes , <nl> mmm a / src / Interpreters / DDLWorker . cpp <nl> ppp b / src / Interpreters / DDLWorker . cpp <nl> DDLWorker : : DDLWorker ( int pool_size_ , const std : : string & zk_root_dir , Context & <nl> : context ( context_ ) <nl> , log ( & Poco : : Logger : : get ( " DDLWorker " ) ) <nl> , pool_size ( pool_size_ ) <nl> - , worker_pool ( pool_size_ ) <nl> + , worker_pool ( std : : make_unique < ThreadPool > ( pool_size ) ) <nl> { <nl> CurrentMetrics : : set ( CurrentMetrics : : MaxDDLEntryID , 0 ) ; <nl> last_tasks . reserve ( pool_size ) ; <nl> DDLWorker : : ~ DDLWorker ( ) <nl> stop_flag = true ; <nl> queue_updated_event - > set ( ) ; <nl> cleanup_event - > set ( ) ; <nl> - worker_pool . wait ( ) ; <nl> + worker_pool . reset ( ) ; <nl> main_thread . join ( ) ; <nl> cleanup_thread . join ( ) ; <nl> } <nl> void DDLWorker : : scheduleTasks ( ) <nl> <nl> if ( ! already_processed ) <nl> { <nl> - worker_pool . scheduleOrThrowOnError ( [ this , task_ptr = task . release ( ) ] ( ) <nl> + worker_pool - > scheduleOrThrowOnError ( [ this , task_ptr = task . release ( ) ] ( ) <nl> { <nl> setThreadName ( " DDLWorkerExec " ) ; <nl> enqueueTask ( DDLTaskPtr ( task_ptr ) ) ; <nl> String DDLWorker : : enqueueQuery ( DDLLogEntry & entry ) <nl> <nl> void DDLWorker : : runMainThread ( ) <nl> { <nl> + auto reset_state = [ & ] ( bool reset_pool = true ) <nl> + { <nl> + / / / It will wait for all threads in pool to finish and will not rethrow exceptions ( if any ) . <nl> + / / / We create new thread pool to forget previous exceptions . <nl> + if ( reset_pool ) <nl> + worker_pool = std : : make_unique < ThreadPool > ( pool_size ) ; <nl> + / / / Clear other in - memory state , like server just started . <nl> + last_tasks . clear ( ) ; <nl> + max_id = 0 ; <nl> + } ; <nl> + <nl> setThreadName ( " DDLWorker " ) ; <nl> LOG_DEBUG ( log , " Started DDLWorker thread " ) ; <nl> <nl> void DDLWorker : : runMainThread ( ) <nl> if ( ! Coordination : : isHardwareError ( e . code ) ) <nl> { <nl> / / / A logical error . <nl> - LOG_FATAL ( log , " ZooKeeper error : { } . Failed to start DDLWorker . " , getCurrentExceptionMessage ( true ) ) ; <nl> - abort ( ) ; <nl> + LOG_ERROR ( log , " ZooKeeper error : { } . Failed to start DDLWorker . " , getCurrentExceptionMessage ( true ) ) ; <nl> + reset_state ( false ) ; <nl> + assert ( false ) ; / / / Catch such failures in tests with debug build <nl> } <nl> <nl> tryLogCurrentException ( __PRETTY_FUNCTION__ ) ; <nl> void DDLWorker : : runMainThread ( ) <nl> } <nl> catch ( . . . ) <nl> { <nl> - tryLogCurrentException ( log , " Terminating . Cannot initialize DDL queue . " ) ; <nl> - return ; <nl> + tryLogCurrentException ( log , " Cannot initialize DDL queue . " ) ; <nl> + reset_state ( false ) ; <nl> } <nl> } <nl> while ( ! initialized & & ! stop_flag ) ; <nl> void DDLWorker : : runMainThread ( ) <nl> } <nl> else <nl> { <nl> - LOG_ERROR ( log , " Unexpected ZooKeeper error : { } . Terminating . " , getCurrentExceptionMessage ( true ) ) ; <nl> - return ; <nl> + LOG_ERROR ( log , " Unexpected ZooKeeper error : { } " , getCurrentExceptionMessage ( true ) ) ; <nl> + reset_state ( ) ; <nl> } <nl> } <nl> catch ( . . . ) <nl> { <nl> - tryLogCurrentException ( log , " Unexpected error , will terminate : " ) ; <nl> - return ; <nl> + tryLogCurrentException ( log , " Unexpected error : " ) ; <nl> + reset_state ( ) ; <nl> } <nl> } <nl> } <nl> mmm a / src / Interpreters / DDLWorker . h <nl> ppp b / src / Interpreters / DDLWorker . h <nl> class DDLWorker <nl> <nl> / / / Size of the pool for query execution . <nl> size_t pool_size = 1 ; <nl> - ThreadPool worker_pool ; <nl> + std : : unique_ptr < ThreadPool > worker_pool ; <nl> <nl> / / / Cleaning starts after new node event is received if the last cleaning wasn ' t made sooner than N seconds ago <nl> Int64 cleanup_delay_period = 60 ; / / minute ( in seconds ) <nl>
try fix it better way
ClickHouse/ClickHouse
f2fca15393756a25efd507b193afea0e1818b6c7
2020-12-30T12:25:00Z
mmm a / include / osquery / tables . h <nl> ppp b / include / osquery / tables . h <nl> enum ColumnType { <nl> / / / Map of type constant to the SQLite string - name representation . <nl> extern const std : : map < ColumnType , std : : string > kColumnTypeNames ; <nl> <nl> - / / / Helper alias for TablePlugin names . <nl> - using TableName = std : : string ; <nl> - using TableColumns = std : : vector < std : : pair < std : : string , ColumnType > > ; <nl> - struct QueryContext ; <nl> - <nl> / * * <nl> * @ brief A ConstraintOperator is applied in an query predicate . <nl> * <nl> enum ConstraintOperator : unsigned char { <nl> <nl> / / / Type for flags for what constraint operators are admissible . <nl> typedef unsigned char ConstraintOperatorFlag ; <nl> + <nl> / / / Flag for any operator type . <nl> # define ANY_OP 0xFFU <nl> <nl> struct Constraint { <nl> : op ( _op ) , expr ( _expr ) { } <nl> } ; <nl> <nl> + / * <nl> + * @ brief Column options allow for more - complicated modeling of concepts . <nl> + * <nl> + * To accommodate the oddities of operating system concepts we make use of <nl> + * simple SQLite abstractions like indexs / keys and foreign keys , we also <nl> + * allow for optimizing based on query constraints ( WHERE ) . <nl> + * <nl> + * There are several ' complications ' where the default table filter ( SELECT ) <nl> + * behavior attempts to mimic reality . Browser plugins or shell history are <nl> + * good examples , a SELECT without using a WHERE returns the plugins or <nl> + * history as it applies to the user running the query . If osquery is meant <nl> + * to be a daemon with absolute visibility this introduces an abnormality , <nl> + * as the expected result will only include the superuser ' s view , even if <nl> + * the superuser can view everything if they intended . <nl> + * <nl> + * The solution is to explicitly ask for everything , by joining against the <nl> + * users table . This options structure will allow the table implementations <nl> + * to communicate these subtleties to the user . <nl> + * / <nl> + enum ColumnOptions { <nl> + / / / Default / no options . <nl> + DEFAULT = 0 , <nl> + <nl> + / / / Treat this column as a primary key . <nl> + INDEX = 1 , <nl> + <nl> + / / / This column MUST be included in the query predicate . <nl> + REQUIRED = 2 , <nl> + <nl> + / * <nl> + * @ brief This column is used to generate additional information . <nl> + * <nl> + * If this column is included in the query predicate , the table will generate <nl> + * additional information . Consider the browser_plugins or shell history <nl> + * tables : by default they list the plugins or history relative to the user <nl> + * running the query . However , if the calling query specifies a UID explicitly <nl> + * in the predicate , the meaning of the table changes and results for that <nl> + * user are returned instead . <nl> + * / <nl> + ADDITIONAL = 4 , <nl> + <nl> + / * <nl> + * @ brief This column can be used to optimize the query . <nl> + * <nl> + * If this column is included in the query predicate , the table will generate <nl> + * optimized information . Consider the system_controls table , a default filter <nl> + * without a query predicate lists all of the keys . When a specific domain is <nl> + * included in the predicate then the table will only issue syscalls / lookups <nl> + * for that domain , greatly optimizing the time and utilization . <nl> + * <nl> + * This optimization does not mean the column is an index . <nl> + * / <nl> + OPTIMIZED = 8 , <nl> + } ; <nl> + <nl> + / / / Treat column options as a set of flags . <nl> + inline ColumnOptions operator | ( ColumnOptions a , ColumnOptions b ) { <nl> + return static_cast < ColumnOptions > ( static_cast < int > ( a ) | static_cast < int > ( b ) ) ; <nl> + } <nl> + <nl> + / / / Helper alias for TablePlugin names . <nl> + using TableName = std : : string ; <nl> + <nl> + / / / Alias for an ordered list of column name and corresponding SQL type . <nl> + using TableColumns = <nl> + std : : vector < std : : tuple < std : : string , ColumnType , ColumnOptions > > ; <nl> + <nl> + / / / Forward declaration of QueryContext for ConstraintList relationships . <nl> + struct QueryContext ; <nl> + <nl> / * * <nl> * @ brief A ConstraintList is a set of constraints for a column . This list <nl> * should be mapped to a left - hand - side column name . <nl> struct Constraint { <nl> * A constraint list supports all AS_LITERAL types , and all ConstraintOperators . <nl> * / <nl> struct ConstraintList : private boost : : noncopyable { <nl> + public : <nl> + ConstraintList ( ) : affinity ( TEXT_TYPE ) { } <nl> + <nl> / / / The SQLite affinity type . <nl> ColumnType affinity ; <nl> <nl> struct ConstraintList : private boost : : noncopyable { <nl> / / / See ConstraintList : : unserialize . <nl> void unserialize ( const boost : : property_tree : : ptree & tree ) ; <nl> <nl> - ConstraintList ( ) : affinity ( TEXT_TYPE ) { } <nl> - <nl> private : <nl> / / / List of constraint operator / expressions . <nl> std : : vector < struct Constraint > constraints_ ; <nl> struct ConstraintList : private boost : : noncopyable { <nl> <nl> / / / Pass a constraint map to the query request . <nl> using ConstraintMap = std : : map < std : : string , struct ConstraintList > ; <nl> + <nl> / / / Populate a constraint list from a query ' s parsed predicate . <nl> using ConstraintSet = std : : vector < std : : pair < std : : string , struct Constraint > > ; <nl> <nl> using ConstraintSet = std : : vector < std : : pair < std : : string , struct Constraint > > ; <nl> struct VirtualTableContent { <nl> / / / Friendly name for the table . <nl> TableName name ; <nl> + <nl> / / / Table column structure , retrieved once via the TablePlugin call API . <nl> TableColumns columns ; <nl> + <nl> / / / Transient set of virtual table access constraints . <nl> std : : unordered_map < size_t , ConstraintSet > constraints ; <nl> <nl> struct QueryContext : private boost : : noncopyable { <nl> friend class TablePlugin ; <nl> } ; <nl> <nl> - typedef struct QueryContext QueryContext ; <nl> - typedef struct Constraint Constraint ; <nl> + using QueryContext = struct QueryContext ; <nl> + using Constraint = struct Constraint ; <nl> <nl> / * * <nl> * @ brief The TablePlugin defines the name , types , and column information . <nl> mmm a / osquery / core / tables . cpp <nl> ppp b / osquery / core / tables . cpp <nl> Status TablePlugin : : call ( const PluginRequest & request , <nl> / / information such as name and type . <nl> const auto & column_list = columns ( ) ; <nl> for ( const auto & column : column_list ) { <nl> - response . push_back ( <nl> - { { " name " , column . first } , { " type " , columnTypeName ( column . second ) } } ) ; <nl> + response . push_back ( { { " name " , std : : get < 0 > ( column ) } , <nl> + { " type " , columnTypeName ( std : : get < 1 > ( column ) ) } , <nl> + { " op " , INTEGER ( std : : get < 2 > ( column ) ) } } ) ; <nl> } <nl> } else if ( request . at ( " action " ) = = " definition " ) { <nl> response . push_back ( { { " definition " , columnDefinition ( ) } } ) ; <nl> PluginResponse TablePlugin : : routeInfo ( ) const { <nl> / / Route info consists of only the serialized column information . <nl> PluginResponse response ; <nl> for ( const auto & column : columns ( ) ) { <nl> - response . push_back ( <nl> - { { " name " , column . first } , { " type " , columnTypeName ( column . second ) } } ) ; <nl> + response . push_back ( { { " name " , std : : get < 0 > ( column ) } , <nl> + { " type " , columnTypeName ( std : : get < 1 > ( column ) ) } , <nl> + { " op " , INTEGER ( std : : get < 2 > ( column ) ) } } ) ; <nl> } <nl> return response ; <nl> } <nl> void TablePlugin : : setCache ( size_t step , <nl> std : : string columnDefinition ( const TableColumns & columns ) { <nl> std : : string statement = " ( " ; <nl> for ( size_t i = 0 ; i < columns . size ( ) ; + + i ) { <nl> + const auto & column = columns . at ( i ) ; <nl> statement + = <nl> - " ` " + columns . at ( i ) . first + " ` " + columnTypeName ( columns . at ( i ) . second ) ; <nl> + " ` " + std : : get < 0 > ( column ) + " ` " + columnTypeName ( std : : get < 1 > ( column ) ) ; <nl> if ( i < columns . size ( ) - 1 ) { <nl> statement + = " , " ; <nl> } <nl> std : : string columnDefinition ( const TableColumns & columns ) { <nl> std : : string columnDefinition ( const PluginResponse & response ) { <nl> TableColumns columns ; <nl> for ( const auto & column : response ) { <nl> - columns . push_back ( <nl> - make_pair ( column . at ( " name " ) , columnTypeName ( column . at ( " type " ) ) ) ) ; <nl> + columns . push_back ( make_tuple ( <nl> + column . at ( " name " ) , <nl> + columnTypeName ( column . at ( " type " ) ) , <nl> + ( ColumnOptions ) AS_LITERAL ( INTEGER_LITERAL , column . at ( " op " ) ) ) ) ; <nl> } <nl> return columnDefinition ( columns ) ; <nl> } <nl> mmm a / osquery / examples / example_extension . cpp <nl> ppp b / osquery / examples / example_extension . cpp <nl> class ExampleConfigPlugin : public ConfigPlugin { <nl> class ExampleTable : public TablePlugin { <nl> private : <nl> TableColumns columns ( ) const { <nl> - return { { " example_text " , TEXT_TYPE } , { " example_integer " , INTEGER_TYPE } } ; <nl> + return { <nl> + std : : make_tuple ( " example_text " , TEXT_TYPE , DEFAULT ) , <nl> + std : : make_tuple ( " example_integer " , INTEGER_TYPE , DEFAULT ) , <nl> + } ; <nl> } <nl> <nl> QueryData generate ( QueryContext & request ) { <nl> class ExampleTable : public TablePlugin { <nl> class ComplexExampleTable : public TablePlugin { <nl> private : <nl> TableColumns columns ( ) const { <nl> - return { { " flag_test " , TEXT_TYPE } , { " database_test " , TEXT_TYPE } } ; <nl> + return { <nl> + std : : make_tuple ( " flag_test " , TEXT_TYPE , DEFAULT ) , <nl> + std : : make_tuple ( " database_test " , TEXT_TYPE , DEFAULT ) , <nl> + } ; <nl> } <nl> <nl> QueryData generate ( QueryContext & request ) { <nl> mmm a / osquery / examples / example_module . cpp <nl> ppp b / osquery / examples / example_module . cpp <nl> using namespace osquery ; <nl> <nl> class ExampleTable : public TablePlugin { <nl> private : <nl> - TableColumns columns ( ) const { <nl> - return { { " example_text " , TEXT_TYPE } , { " example_integer " , INTEGER_TYPE } } ; <nl> + TableColumns columns ( ) const override { <nl> + return { <nl> + std : : make_tuple ( " example_text " , TEXT_TYPE , DEFAULT ) , <nl> + std : : make_tuple ( " example_integer " , INTEGER_TYPE , DEFAULT ) , <nl> + } ; <nl> } <nl> <nl> - QueryData generate ( QueryContext & request ) { <nl> + QueryData generate ( QueryContext & request ) override { <nl> QueryData results ; <nl> <nl> Row r ; <nl> mmm a / osquery / extensions / extensions . cpp <nl> ppp b / osquery / extensions / extensions . cpp <nl> Status getQueryColumnsExternal ( const std : : string & manager_path , <nl> / / Translate response map : { string : string } to a vector : pair ( name , type ) . <nl> for ( const auto & column : response . response ) { <nl> for ( const auto & col : column ) { <nl> - columns . push_back ( make_pair ( col . first , columnTypeName ( col . second ) ) ) ; <nl> + columns . push_back ( <nl> + std : : make_tuple ( col . first , columnTypeName ( col . second ) , DEFAULT ) ) ; <nl> } <nl> } <nl> <nl> mmm a / osquery / extensions / interface . cpp <nl> ppp b / osquery / extensions / interface . cpp <nl> void ExtensionManagerHandler : : getQueryColumns ( ExtensionResponse & _return , <nl> <nl> if ( status . ok ( ) ) { <nl> for ( const auto & col : columns ) { <nl> - _return . response . push_back ( { { col . first , columnTypeName ( col . second ) } } ) ; <nl> + _return . response . push_back ( <nl> + { { std : : get < 0 > ( col ) , columnTypeName ( std : : get < 1 > ( col ) ) } } ) ; <nl> } <nl> } <nl> } <nl> mmm a / osquery / sql / benchmarks / sql_benchmarks . cpp <nl> ppp b / osquery / sql / benchmarks / sql_benchmarks . cpp <nl> namespace osquery { <nl> class BenchmarkTablePlugin : public TablePlugin { <nl> private : <nl> TableColumns columns ( ) const { <nl> - return { { " test_int " , INTEGER_TYPE } , { " test_text " , TEXT_TYPE } } ; <nl> + return { <nl> + std : : make_tuple ( " test_int " , INTEGER_TYPE , DEFAULT ) , <nl> + std : : make_tuple ( " test_text " , TEXT_TYPE , DEFAULT ) , <nl> + } ; <nl> } <nl> <nl> QueryData generate ( QueryContext & ctx ) { <nl> BENCHMARK ( SQL_virtual_table_internal_unique ) ; <nl> class BenchmarkLongTablePlugin : public TablePlugin { <nl> private : <nl> TableColumns columns ( ) const { <nl> - return { { " test_int " , INTEGER_TYPE } , { " test_text " , TEXT_TYPE } } ; <nl> + return { <nl> + std : : make_tuple ( " test_int " , INTEGER_TYPE , DEFAULT ) , <nl> + std : : make_tuple ( " test_text " , TEXT_TYPE , DEFAULT ) , <nl> + } ; <nl> } <nl> <nl> QueryData generate ( QueryContext & ctx ) { <nl> BENCHMARK ( SQL_virtual_table_internal_long ) ; <nl> <nl> class BenchmarkWideTablePlugin : public TablePlugin { <nl> private : <nl> - TableColumns columns ( ) const { <nl> + TableColumns columns ( ) const override { <nl> TableColumns cols ; <nl> for ( int i = 0 ; i < 20 ; i + + ) { <nl> - cols . push_back ( { " test_ " + std : : to_string ( i ) , INTEGER_TYPE } ) ; <nl> + cols . push_back ( <nl> + std : : make_tuple ( " test_ " + std : : to_string ( i ) , INTEGER_TYPE , DEFAULT ) ) ; <nl> } <nl> return cols ; <nl> } <nl> <nl> - QueryData generate ( QueryContext & ctx ) { <nl> + QueryData generate ( QueryContext & ctx ) override { <nl> QueryData results ; <nl> for ( int k = 0 ; k < 50 ; k + + ) { <nl> Row r ; <nl> mmm a / osquery / sql / sql . cpp <nl> ppp b / osquery / sql / sql . cpp <nl> std : : string SQL : : getMessageString ( ) { return status_ . toString ( ) ; } <nl> <nl> static inline void escapeNonPrintableBytes ( std : : string & data ) { <nl> std : : string escaped ; <nl> - / / clang - format off <nl> char const hex_chars [ 16 ] = { <nl> - ' 0 ' , <nl> - ' 1 ' , <nl> - ' 2 ' , <nl> - ' 3 ' , <nl> - ' 4 ' , <nl> - ' 5 ' , <nl> - ' 6 ' , <nl> - ' 7 ' , <nl> - ' 8 ' , <nl> - ' 9 ' , <nl> - ' A ' , <nl> - ' B ' , <nl> - ' C ' , <nl> - ' D ' , <nl> - ' E ' , <nl> - ' F ' , <nl> + ' 0 ' , ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' , <nl> + ' 8 ' , ' 9 ' , ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' , <nl> } ; <nl> - / / clang - format on <nl> <nl> bool needs_replacement = false ; <nl> for ( size_t i = 0 ; i < data . length ( ) ; i + + ) { <nl> Status SQLPlugin : : call ( const PluginRequest & request , PluginResponse & response ) { <nl> auto status = this - > getQueryColumns ( request . at ( " query " ) , columns ) ; <nl> / / Convert columns to response <nl> for ( const auto & column : columns ) { <nl> - response . push_back ( <nl> - { { " n " , column . first } , { " t " , columnTypeName ( column . second ) } } ) ; <nl> + response . push_back ( { { " n " , std : : get < 0 > ( column ) } , <nl> + { " t " , columnTypeName ( std : : get < 1 > ( column ) ) } , <nl> + { " o " , INTEGER ( std : : get < 2 > ( column ) ) } } ) ; <nl> } <nl> return status ; <nl> } else if ( request . at ( " action " ) = = " attach " ) { <nl> Status getQueryColumns ( const std : : string & q , TableColumns & columns ) { <nl> <nl> / / Convert response to columns <nl> for ( const auto & item : response ) { <nl> - columns . push_back ( make_pair ( item . at ( " n " ) , columnTypeName ( item . at ( " t " ) ) ) ) ; <nl> + columns . push_back ( <nl> + make_tuple ( item . at ( " n " ) , columnTypeName ( item . at ( " t " ) ) , DEFAULT ) ) ; <nl> } <nl> return status ; <nl> } <nl> mmm a / osquery / sql / sqlite_util . cpp <nl> ppp b / osquery / sql / sqlite_util . cpp <nl> using SQLiteDBInstanceRef = std : : shared_ptr < SQLiteDBInstance > ; <nl> * Details of this map are defined at : http : / / www . sqlite . org / c3ref / c_abort . html <nl> * / <nl> const std : : map < int , std : : string > kSQLiteReturnCodes = { <nl> - { 0 , " SQLITE_OK " } , { 1 , " SQLITE_ERROR " } , { 2 , " SQLITE_INTERNAL " } , <nl> - { 3 , " SQLITE_PERM " } , { 4 , " SQLITE_ABORT " } , { 5 , " SQLITE_BUSY " } , <nl> - { 6 , " SQLITE_LOCKED " } , { 7 , " SQLITE_NOMEM " } , { 8 , " SQLITE_READONLY " } , <nl> - { 9 , " SQLITE_INTERRUPT " } , { 10 , " SQLITE_IOERR " } , { 11 , " SQLITE_CORRUPT " } , <nl> - { 12 , " SQLITE_NOTFOUND " } , { 13 , " SQLITE_FULL " } , { 14 , " SQLITE_CANTOPEN " } , <nl> - { 15 , " SQLITE_PROTOCOL " } , { 16 , " SQLITE_EMPTY " } , { 17 , " SQLITE_SCHEMA " } , <nl> - { 18 , " SQLITE_TOOBIG " } , { 19 , " SQLITE_CONSTRAINT " } , { 20 , " SQLITE_MISMATCH " } , <nl> - { 21 , " SQLITE_MISUSE " } , { 22 , " SQLITE_NOLFS " } , { 23 , " SQLITE_AUTH " } , <nl> - { 24 , " SQLITE_FORMAT " } , { 25 , " SQLITE_RANGE " } , { 26 , " SQLITE_NOTADB " } , <nl> - { 27 , " SQLITE_NOTICE " } , { 28 , " SQLITE_WARNING " } , { 100 , " SQLITE_ROW " } , <nl> + { 0 , " SQLITE_OK " } , <nl> + { 1 , " SQLITE_ERROR " } , <nl> + { 2 , " SQLITE_INTERNAL " } , <nl> + { 3 , " SQLITE_PERM " } , <nl> + { 4 , " SQLITE_ABORT " } , <nl> + { 5 , " SQLITE_BUSY " } , <nl> + { 6 , " SQLITE_LOCKED " } , <nl> + { 7 , " SQLITE_NOMEM " } , <nl> + { 8 , " SQLITE_READONLY " } , <nl> + { 9 , " SQLITE_INTERRUPT " } , <nl> + { 10 , " SQLITE_IOERR " } , <nl> + { 11 , " SQLITE_CORRUPT " } , <nl> + { 12 , " SQLITE_NOTFOUND " } , <nl> + { 13 , " SQLITE_FULL " } , <nl> + { 14 , " SQLITE_CANTOPEN " } , <nl> + { 15 , " SQLITE_PROTOCOL " } , <nl> + { 16 , " SQLITE_EMPTY " } , <nl> + { 17 , " SQLITE_SCHEMA " } , <nl> + { 18 , " SQLITE_TOOBIG " } , <nl> + { 19 , " SQLITE_CONSTRAINT " } , <nl> + { 20 , " SQLITE_MISMATCH " } , <nl> + { 21 , " SQLITE_MISUSE " } , <nl> + { 22 , " SQLITE_NOLFS " } , <nl> + { 23 , " SQLITE_AUTH " } , <nl> + { 24 , " SQLITE_FORMAT " } , <nl> + { 25 , " SQLITE_RANGE " } , <nl> + { 26 , " SQLITE_NOTADB " } , <nl> + { 27 , " SQLITE_NOTICE " } , <nl> + { 28 , " SQLITE_WARNING " } , <nl> + { 100 , " SQLITE_ROW " } , <nl> { 101 , " SQLITE_DONE " } , <nl> } ; <nl> <nl> const std : : map < std : : string , std : : string > kMemoryDBSettings = { <nl> - { " synchronous " , " OFF " } , { " count_changes " , " OFF " } , <nl> - { " default_temp_store " , " 0 " } , { " auto_vacuum " , " FULL " } , <nl> - { " journal_mode " , " OFF " } , { " cache_size " , " 0 " } , <nl> + { " synchronous " , " OFF " } , <nl> + { " count_changes " , " OFF " } , <nl> + { " default_temp_store " , " 0 " } , <nl> + { " auto_vacuum " , " FULL " } , <nl> + { " journal_mode " , " OFF " } , <nl> + { " cache_size " , " 0 " } , <nl> { " page_count " , " 0 " } , <nl> } ; <nl> <nl> Status QueryPlanner : : applyTypes ( TableColumns & columns ) { <nl> auto k = boost : : lexical_cast < size_t > ( row . at ( " p1 " ) ) ; <nl> for ( const auto & type : column_types ) { <nl> if ( type . first - k < columns . size ( ) ) { <nl> - columns [ type . first - k ] . second = type . second ; <nl> + std : : get < 1 > ( columns [ type . first - k ] ) = type . second ; <nl> } <nl> } <nl> } <nl> Status getQueryColumnsInternal ( const std : : string & q , <nl> col_type = " UNKNOWN " ; <nl> unknown_type = true ; <nl> } <nl> - results . push_back ( { col_name , columnTypeName ( col_type ) } ) ; <nl> + results . push_back ( <nl> + std : : make_tuple ( col_name , columnTypeName ( col_type ) , DEFAULT ) ) ; <nl> } <nl> <nl> / / An unknown type means we have to parse the plan and SQLite opcodes . <nl> mmm a / osquery / sql / tests / sql_tests . cpp <nl> ppp b / osquery / sql / tests / sql_tests . cpp <nl> TEST_F ( SQLTests , test_raw_access ) { <nl> class TestTablePlugin : public TablePlugin { <nl> private : <nl> TableColumns columns ( ) const { <nl> - return { { " test_int " , INTEGER_TYPE } , { " test_text " , TEXT_TYPE } } ; <nl> + return { <nl> + std : : make_tuple ( " test_int " , INTEGER_TYPE , DEFAULT ) , <nl> + std : : make_tuple ( " test_text " , TEXT_TYPE , DEFAULT ) , <nl> + } ; <nl> } <nl> <nl> QueryData generate ( QueryContext & ctx ) { <nl> mmm a / osquery / sql / tests / sqlite_util_tests . cpp <nl> ppp b / osquery / sql / tests / sqlite_util_tests . cpp <nl> TEST_F ( SQLiteUtilTests , test_get_query_columns ) { <nl> auto status = getQueryColumnsInternal ( query , results , dbc - > db ( ) ) ; <nl> ASSERT_TRUE ( status . ok ( ) ) ; <nl> ASSERT_EQ ( 2U , results . size ( ) ) ; <nl> - EXPECT_EQ ( std : : make_pair ( std : : string ( " seconds " ) , INTEGER_TYPE ) , results [ 0 ] ) ; <nl> - EXPECT_EQ ( std : : make_pair ( std : : string ( " version " ) , TEXT_TYPE ) , results [ 1 ] ) ; <nl> + EXPECT_EQ ( std : : make_tuple ( std : : string ( " seconds " ) , INTEGER_TYPE , DEFAULT ) , <nl> + results [ 0 ] ) ; <nl> + EXPECT_EQ ( std : : make_tuple ( std : : string ( " version " ) , TEXT_TYPE , DEFAULT ) , <nl> + results [ 1 ] ) ; <nl> <nl> query = " SELECT * FROM foo " ; <nl> status = getQueryColumnsInternal ( query , results , dbc - > db ( ) ) ; <nl> TEST_F ( SQLiteUtilTests , test_get_query_columns ) { <nl> std : : vector < ColumnType > getTypes ( const TableColumns & columns ) { <nl> std : : vector < ColumnType > types ; <nl> for ( const auto & col : columns ) { <nl> - types . push_back ( col . second ) ; <nl> + types . push_back ( std : : get < 1 > ( col ) ) ; <nl> } <nl> return types ; <nl> } <nl> mmm a / osquery / sql / tests / virtual_table_tests . cpp <nl> ppp b / osquery / sql / tests / virtual_table_tests . cpp <nl> class sampleTablePlugin : public TablePlugin { <nl> private : <nl> TableColumns columns ( ) const override { <nl> return { <nl> - { " foo " , INTEGER_TYPE } , { " bar " , TEXT_TYPE } , <nl> + std : : make_tuple ( " foo " , INTEGER_TYPE , DEFAULT ) , <nl> + std : : make_tuple ( " bar " , TEXT_TYPE , DEFAULT ) , <nl> } ; <nl> } <nl> } ; <nl> TEST_F ( VirtualTableTests , test_tableplugin_columndefinition ) { <nl> EXPECT_EQ ( " ( ` foo ` INTEGER , ` bar ` TEXT ) " , table - > columnDefinition ( ) ) ; <nl> } <nl> <nl> + class optionsTablePlugin : public TablePlugin { <nl> + private : <nl> + TableColumns columns ( ) const override { <nl> + return { <nl> + std : : make_tuple ( " id " , INTEGER_TYPE , INDEX | REQUIRED ) , <nl> + std : : make_tuple ( " username " , TEXT_TYPE , OPTIMIZED ) , <nl> + std : : make_tuple ( " name " , TEXT_TYPE , DEFAULT ) , <nl> + } ; <nl> + } <nl> + <nl> + private : <nl> + FRIEND_TEST ( VirtualTableTests , test_tableplugin_options ) ; <nl> + } ; <nl> + <nl> + TEST_F ( VirtualTableTests , test_tableplugin_options ) { <nl> + auto table = std : : make_shared < optionsTablePlugin > ( ) ; <nl> + EXPECT_EQ ( std : : get < 2 > ( table - > columns ( ) [ 0 ] ) , INDEX | REQUIRED ) ; <nl> + <nl> + PluginResponse response ; <nl> + PluginRequest request = { { " action " , " columns " } } ; <nl> + EXPECT_TRUE ( table - > call ( request , response ) . ok ( ) ) ; <nl> + EXPECT_EQ ( response [ 0 ] [ " op " ] , INTEGER ( INDEX | REQUIRED ) ) ; <nl> + <nl> + response = table - > routeInfo ( ) ; <nl> + EXPECT_EQ ( response [ 0 ] [ " op " ] , INTEGER ( INDEX | REQUIRED ) ) ; <nl> + } <nl> + <nl> TEST_F ( VirtualTableTests , test_sqlite3_attach_vtable ) { <nl> auto table = std : : make_shared < sampleTablePlugin > ( ) ; <nl> table - > setName ( " sample " ) ; <nl> class pTablePlugin : public TablePlugin { <nl> private : <nl> TableColumns columns ( ) const override { <nl> return { <nl> - { " x " , INTEGER_TYPE } , { " y " , INTEGER_TYPE } , <nl> + std : : make_tuple ( " x " , INTEGER_TYPE , DEFAULT ) , <nl> + std : : make_tuple ( " y " , INTEGER_TYPE , DEFAULT ) , <nl> } ; <nl> } <nl> <nl> class kTablePlugin : public TablePlugin { <nl> private : <nl> TableColumns columns ( ) const override { <nl> return { <nl> - { " x " , INTEGER_TYPE } , { " z " , INTEGER_TYPE } , <nl> + std : : make_tuple ( " x " , INTEGER_TYPE , DEFAULT ) , <nl> + std : : make_tuple ( " z " , INTEGER_TYPE , DEFAULT ) , <nl> } ; <nl> } <nl> <nl> TEST_F ( VirtualTableTests , test_constraints_stacking ) { <nl> } <nl> <nl> std : : vector < QueryData > union_results = { <nl> - makeResult ( " x " , { " 1 " , " 2 " } ) , makeResult ( " k . x " , { " 1 " , " 2 " } ) , <nl> - makeResult ( " k . x " , { " 1 " , " 2 " } ) , makeResult ( " k . x " , { " 1 " , " 2 " } ) , <nl> - makeResult ( " k . x " , { " 1 " , " 2 " } ) , makeResult ( " k . x " , { " 1 " , " 2 " } ) , <nl> - makeResult ( " k . x " , { " 1 " , " 2 " } ) , makeResult ( " p . x " , { " 1 " } ) , <nl> + makeResult ( " x " , { " 1 " , " 2 " } ) , <nl> + makeResult ( " k . x " , { " 1 " , " 2 " } ) , <nl> + makeResult ( " k . x " , { " 1 " , " 2 " } ) , <nl> + makeResult ( " k . x " , { " 1 " , " 2 " } ) , <nl> + makeResult ( " k . x " , { " 1 " , " 2 " } ) , <nl> + makeResult ( " k . x " , { " 1 " , " 2 " } ) , <nl> + makeResult ( " k . x " , { " 1 " , " 2 " } ) , <nl> + makeResult ( " p . x " , { " 1 " } ) , <nl> makeResult ( " p . x " , { " 1 " } ) , <nl> } ; <nl> <nl> class jsonTablePlugin : public TablePlugin { <nl> private : <nl> TableColumns columns ( ) const override { <nl> return { <nl> - { " data " , TEXT_TYPE } , <nl> + std : : make_tuple ( " data " , TEXT_TYPE , DEFAULT ) , <nl> } ; <nl> } <nl> <nl> class cacheTablePlugin : public TablePlugin { <nl> private : <nl> TableColumns columns ( ) const override { <nl> return { <nl> - { " data " , TEXT_TYPE } , <nl> + std : : make_tuple ( " data " , TEXT_TYPE , DEFAULT ) , <nl> } ; <nl> } <nl> <nl> mmm a / osquery / sql / virtual_table . cpp <nl> ppp b / osquery / sql / virtual_table . cpp <nl> int xCreate ( sqlite3 * db , <nl> PluginResponse response ; <nl> pVtab - > content - > name = std : : string ( argv [ 0 ] ) ; <nl> / / Get the table column information . <nl> - auto status = Registry : : call ( <nl> - " table " , pVtab - > content - > name , { { " action " , " columns " } } , response ) ; <nl> + auto status = Registry : : call ( " table " , pVtab - > content - > name , <nl> + { { " action " , " columns " } } , response ) ; <nl> if ( ! status . ok ( ) | | response . size ( ) = = 0 ) { <nl> delete pVtab - > content ; <nl> delete pVtab ; <nl> int xCreate ( sqlite3 * db , <nl> / / Keep a local copy of the column details in the VirtualTableContent struct . <nl> / / This allows introspection into the column type without additional calls . <nl> for ( const auto & column : response ) { <nl> - pVtab - > content - > columns . push_back ( <nl> - std : : make_pair ( column . at ( " name " ) , columnTypeName ( column . at ( " type " ) ) ) ) ; <nl> + pVtab - > content - > columns . push_back ( std : : make_tuple ( <nl> + column . at ( " name " ) , columnTypeName ( column . at ( " type " ) ) , <nl> + ( ColumnOptions ) AS_LITERAL ( INTEGER_LITERAL , column . at ( " op " ) ) ) ) ; <nl> } <nl> * ppVtab = ( sqlite3_vtab * ) pVtab ; <nl> return rc ; <nl> int xColumn ( sqlite3_vtab_cursor * cur , sqlite3_context * ctx , int col ) { <nl> return SQLITE_ERROR ; <nl> } <nl> <nl> - const auto & column_name = pVtab - > content - > columns [ col ] . first ; <nl> - const auto & type = pVtab - > content - > columns [ col ] . second ; <nl> + const auto & column_name = std : : get < 0 > ( pVtab - > content - > columns [ col ] ) ; <nl> + const auto & type = std : : get < 1 > ( pVtab - > content - > columns [ col ] ) ; <nl> if ( pCur - > row > = pCur - > data . size ( ) ) { <nl> / / Request row index greater than row set size . <nl> return SQLITE_ERROR ; <nl> static int xBestIndex ( sqlite3_vtab * tab , sqlite3_index_info * pIdxInfo ) { <nl> cost + = 10 ; <nl> continue ; <nl> } <nl> - const auto & name = pVtab - > content - > columns [ constraint_info . iColumn ] . first ; <nl> + const auto & name = <nl> + std : : get < 0 > ( pVtab - > content - > columns [ constraint_info . iColumn ] ) ; <nl> / / Save a pair of the name and the constraint operator . <nl> / / Use this constraint during xFilter by performing a scan and column <nl> / / name lookup through out all cursor constraint lists . <nl> static int xFilter ( sqlite3_vtab_cursor * pVtabCursor , <nl> for ( size_t i = 0 ; i < content - > columns . size ( ) ; + + i ) { <nl> / / Set the column affinity for each optional constraint list . <nl> / / There is a separate list for each column name . <nl> - context . constraints [ content - > columns [ i ] . first ] . affinity = <nl> - content - > columns [ i ] . second ; <nl> + context . constraints [ std : : get < 0 > ( content - > columns [ i ] ) ] . affinity = <nl> + std : : get < 1 > ( content - > columns [ i ] ) ; <nl> } <nl> <nl> / / Filtering between cursors happens iteratively , not consecutively . <nl> Status attachTableInternal ( const std : : string & name , <nl> / / Note , if the clientData API is used then this will save a registry call <nl> / / within xCreate . <nl> WriteLock lock ( kAttachMutex ) ; <nl> - int rc = sqlite3_create_module ( <nl> - instance - > db ( ) , name . c_str ( ) , & module , ( void * ) & ( * instance ) ) ; <nl> + int rc = sqlite3_create_module ( instance - > db ( ) , name . c_str ( ) , & module , <nl> + ( void * ) & ( * instance ) ) ; <nl> if ( rc = = SQLITE_OK | | rc = = SQLITE_MISUSE ) { <nl> auto format = <nl> " CREATE VIRTUAL TABLE temp . " + name + " USING " + name + statement ; <nl> mmm a / specs / centos / rpm_packages . table <nl> ppp b / specs / centos / rpm_packages . table <nl> schema ( [ <nl> Column ( " sha1 " , TEXT , " SHA1 hash of the package contents " ) , <nl> Column ( " arch " , TEXT , " Architecture ( s ) supported " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " @ genRpmPackages " ) <nl> mmm a / specs / crontab . table <nl> ppp b / specs / crontab . table <nl> schema ( [ <nl> Column ( " command " , TEXT , " Raw command string " ) , <nl> Column ( " path " , TEXT , " File parsed " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " crontab @ genCronTab " ) <nl> mmm a / specs / darwin / apps . table <nl> ppp b / specs / darwin / apps . table <nl> schema ( [ <nl> " Info properties NSAppleScriptEnabled label " ) , <nl> Column ( " copyright " , TEXT , " Info properties NSHumanReadableCopyright label " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " apps @ genApps " ) <nl> mmm a / specs / darwin / authorization_mechanisms . table <nl> ppp b / specs / darwin / authorization_mechanisms . table <nl> examples ( [ <nl> " select * from authorization_mechanisms ; " , <nl> " select * from authorization_mechanisms where label = ' system . login . console ' ; " , <nl> " select * from authorization_mechanisms where label = ' authenticate ' ; " <nl> - ] ) <nl> \ No newline at end of file <nl> + ] ) <nl> mmm a / specs / darwin / authorizations . table <nl> ppp b / specs / darwin / authorizations . table <nl> examples ( [ <nl> " select * from authorizations where label = ' system . login . console ' ; " , <nl> " select * from authorizations where label = ' authenticate ' ; " , <nl> " select * from authorizations where label = ' system . preferences . softwareupdate ' ; " <nl> - ] ) <nl> \ No newline at end of file <nl> + ] ) <nl> mmm a / specs / darwin / certificates . table <nl> ppp b / specs / darwin / certificates . table <nl> schema ( [ <nl> Column ( " path " , TEXT , " Path to Keychain or PEM bundle " ) , <nl> <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " certificates @ genCerts " ) <nl> mmm a / specs / darwin / homebrew_packages . table <nl> ppp b / specs / darwin / homebrew_packages . table <nl> schema ( [ <nl> Column ( " path " , TEXT , " Package install path " ) , <nl> Column ( " version " , TEXT , " Current ' linked ' version " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " system / homebrew_packages @ genHomebrewPackages " ) <nl> mmm a / specs / darwin / iokit_devicetree . table <nl> ppp b / specs / darwin / iokit_devicetree . table <nl> schema ( [ <nl> Column ( " retain_count " , INTEGER , " The device reference count " ) , <nl> Column ( " depth " , INTEGER , " Device nested depth " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " system / iokit_registry @ genIOKitDeviceTree " ) <nl> mmm a / specs / darwin / iokit_registry . table <nl> ppp b / specs / darwin / iokit_registry . table <nl> schema ( [ <nl> Column ( " retain_count " , INTEGER , " The node reference count " ) , <nl> Column ( " depth " , INTEGER , " Node nested depth " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " system / iokit_registry @ genIOKitRegistry " ) <nl> mmm a / specs / darwin / keychain_acls . table <nl> ppp b / specs / darwin / keychain_acls . table <nl> schema ( [ <nl> Column ( " description " , TEXT , " The description included with the ACL entry " ) , <nl> Column ( " label " , TEXT , " An optional label tag that may be included with the keychain entry " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " keychain_acl @ genKeychainACLApps " ) <nl> examples ( [ <nl> " select label , description , authorizations , path , count ( path ) as c from keychain_acls where label ! = ' ' and path ! = ' ' group by label having c > 1 ; " , <nl> mmm a / specs / darwin / keychain_items . table <nl> ppp b / specs / darwin / keychain_items . table <nl> schema ( [ <nl> Column ( " type " , TEXT , " Keychain item type ( class ) " ) , <nl> Column ( " path " , TEXT , " Path to keychain containing item " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " keychain_items @ genKeychainItems " ) <nl> mmm a / specs / darwin / launchd . table <nl> ppp b / specs / darwin / launchd . table <nl> schema ( [ <nl> Column ( " process_type " , TEXT , <nl> " Key describes the intended purpose of the job " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " launchd @ genLaunchd " ) <nl> mmm a / specs / darwin / launchd_overrides . table <nl> ppp b / specs / darwin / launchd_overrides . table <nl> schema ( [ <nl> Column ( " uid " , BIGINT , " User ID applied to the override , 0 applies to all " ) , <nl> Column ( " path " , TEXT , " Path to daemon or agent plist " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " launchd @ genLaunchdOverrides " ) <nl> mmm a / specs / darwin / managed_policies . table <nl> ppp b / specs / darwin / managed_policies . table <nl> schema ( [ <nl> Column ( " uuid " , TEXT , " Optional UUID assigned to policy set " ) , <nl> Column ( " name " , TEXT , " Policy key name " ) , <nl> Column ( " value " , TEXT , " Policy value " ) , <nl> - Column ( " username " , TEXT , " Policy applies only this user " , superuser = True ) , <nl> + Column ( " username " , TEXT , " Policy applies only this user " ) , <nl> Column ( " manual " , INTEGER , " 1 if policy was loaded manually , otherwise 0 " ) , <nl> ] ) <nl> implementation ( " managed_policy @ genManagedPolicies " ) <nl> mmm a / specs / darwin / sandboxes . table <nl> ppp b / specs / darwin / sandboxes . table <nl> schema ( [ <nl> Column ( " bundle_path " , TEXT , " Application bundle used by the sandbox " ) , <nl> Column ( " path " , TEXT , " Path to sandbox container directory " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " sandboxes @ genSandboxContainers " ) <nl> mmm a / specs / darwin / startup_items . table <nl> ppp b / specs / darwin / startup_items . table <nl> schema ( [ <nl> Column ( " type " , TEXT , " Startup Item or Login Item " ) , <nl> Column ( " source " , TEXT , " Directory or plist containing startup item " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " startup_items @ genStartupItems " ) <nl> mmm a / specs / darwin / wifi_networks . table <nl> ppp b / specs / darwin / wifi_networks . table <nl> schema ( [ <nl> Column ( " temporarily_disabled " , INTEGER , " 1 if this network is temporarily disabled , 0 otherwise " ) , <nl> Column ( " disabled " , INTEGER , " 1 if this network is disabled , 0 otherwise " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " networking / wifi @ genKnownWifiNetworks " ) <nl> mmm a / specs / darwin / xprotect_entries . table <nl> ppp b / specs / darwin / xprotect_entries . table <nl> schema ( [ <nl> Column ( " optional " , INTEGER , " Match any of the identities / patterns for this XProtect name " ) , <nl> Column ( " uses_pattern " , INTEGER , " Uses a match pattern instead of identity " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " xprotect @ genXProtectEntries " ) <nl> mmm a / specs / darwin / xprotect_meta . table <nl> ppp b / specs / darwin / xprotect_meta . table <nl> schema ( [ <nl> Column ( " developer_id " , TEXT , " Developer identity ( SHA1 ) of extension " ) , <nl> Column ( " min_version " , TEXT , " The minimum allowed plugin version . " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " xprotect @ genXProtectMeta " ) <nl> mmm a / specs / etc_hosts . table <nl> ppp b / specs / etc_hosts . table <nl> schema ( [ <nl> Column ( " address " , TEXT , " IP address mapping " ) , <nl> Column ( " hostnames " , TEXT , " Raw hosts mapping " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " etc_hosts @ genEtcHosts " ) <nl> mmm a / specs / etc_protocols . table <nl> ppp b / specs / etc_protocols . table <nl> schema ( [ <nl> Column ( " alias " , TEXT , " Protocol alias " ) , <nl> Column ( " comment " , TEXT , " Comment with protocol description " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " etc_protocols @ genEtcProtocols " ) <nl> <nl> mmm a / specs / etc_services . table <nl> ppp b / specs / etc_services . table <nl> schema ( [ <nl> Column ( " aliases " , TEXT , " Optional space separated list of other names for a service " ) , <nl> Column ( " comment " , TEXT , " Optional comment for a service . " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " etc_services @ genEtcServices " ) <nl> mmm a / specs / interface_addresses . table <nl> ppp b / specs / interface_addresses . table <nl> schema ( [ <nl> Column ( " broadcast " , TEXT , " Broadcast address for the interface " ) , <nl> Column ( " point_to_point " , TEXT , " PtP address for the interface " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " interfaces @ genInterfaceAddresses " ) <nl> mmm a / specs / interface_details . table <nl> ppp b / specs / interface_details . table <nl> schema ( [ <nl> Column ( " oerrors " , BIGINT , " Output errors " ) , <nl> Column ( " last_change " , BIGINT , " Time of last device modification ( optional ) " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " interfaces @ genInterfaceDetails " ) <nl> mmm a / specs / kernel_info . table <nl> ppp b / specs / kernel_info . table <nl> schema ( [ <nl> Column ( " path " , TEXT , " Kernel path " ) , <nl> Column ( " device " , TEXT , " Kernel device identifier " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " system / kernel_info @ genKernelInfo " ) <nl> mmm a / specs / last . table <nl> ppp b / specs / last . table <nl> schema ( [ <nl> Column ( " time " , INTEGER , " Entry timestamp " ) , <nl> Column ( " host " , TEXT , " Entry hostname " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " last @ genLastAccess " ) <nl> mmm a / specs / listening_ports . table <nl> ppp b / specs / listening_ports . table <nl> schema ( [ <nl> Column ( " family " , INTEGER , " Network protocol ( IPv4 , IPv6 ) " ) , <nl> Column ( " address " , TEXT , " Specific address for bind " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " listening_ports @ genListeningPorts " ) <nl> mmm a / specs / logged_in_users . table <nl> ppp b / specs / logged_in_users . table <nl> schema ( [ <nl> Column ( " time " , INTEGER , " Time entry was made " ) , <nl> Column ( " pid " , INTEGER , " Process ( or thread ) ID " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " logged_in_users @ genLoggedInUsers " ) <nl> mmm a / specs / routes . table <nl> ppp b / specs / routes . table <nl> schema ( [ <nl> Column ( " metric " , INTEGER , " Cost of route . Lowest is preferred " ) , <nl> Column ( " type " , TEXT , " Type of route " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " networking / routes @ genRoutes " ) <nl> mmm a / specs / suid_bin . table <nl> ppp b / specs / suid_bin . table <nl> schema ( [ <nl> Column ( " groupname " , TEXT , " Binary owner group " ) , <nl> Column ( " permissions " , TEXT , " Binary permissions " ) , <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " suid_bin @ genSuidBin " ) <nl> mmm a / specs / ubuntu / deb_packages . table <nl> ppp b / specs / ubuntu / deb_packages . table <nl> schema ( [ <nl> Column ( " arch " , TEXT , " Package architecture " ) , <nl> Column ( " revision " , TEXT , " Package revision " ) <nl> ] ) <nl> - attributes ( cachable = True ) <nl> + attributes ( cacheable = True ) <nl> implementation ( " system / deb_packages @ genDebs " ) <nl> mmm a / specs / utility / hash . table <nl> ppp b / specs / utility / hash . table <nl> <nl> table_name ( " hash " ) <nl> description ( " Filesystem hash data . " ) <nl> schema ( [ <nl> - Column ( " path " , TEXT , " Must provide a path or directory " , required = True ) , <nl> + Column ( " path " , TEXT , " Must provide a path or directory " , index = True , required = True ) , <nl> Column ( " directory " , TEXT , " Must provide a path or directory " , required = True ) , <nl> Column ( " md5 " , TEXT , " MD5 hash of provided filesystem data " ) , <nl> Column ( " sha1 " , TEXT , " SHA1 hash of provided filesystem data " ) , <nl> mmm a / tools / codegen / gentable . py <nl> ppp b / tools / codegen / gentable . py <nl> def __repr__ ( self ) : <nl> EVENTS = " EVENTS " <nl> APPLICATION = " APPLICATION " <nl> <nl> + # This should mimic the C + + enumeration ColumnOptions in table . h <nl> + COLUMN_OPTIONS = { <nl> + " index " : " INDEX " , <nl> + " additional " : " ADDITIONAL " , <nl> + " required " : " REQUIRED " , <nl> + " optimized " : " OPTIMIZED " , <nl> + } <nl> + <nl> + # Column options that render tables uncacheable . <nl> + NON_CACHEABLE = [ <nl> + " INDEX " , <nl> + " REQUIRED " , <nl> + " ADDITIONAL " , <nl> + " OPTIMIZED " , <nl> + ] <nl> + <nl> <nl> def usage ( ) : <nl> " " " print program usage " " " <nl> def __init__ ( self ) : <nl> self . description = " " <nl> self . attributes = { } <nl> self . examples = [ ] <nl> + self . has_options = False <nl> <nl> def columns ( self ) : <nl> return [ i for i in self . schema if isinstance ( i , Column ) ] <nl> def foreign_keys ( self ) : <nl> def generate ( self , path , template = " default " ) : <nl> " " " Generate the virtual table files " " " <nl> logging . debug ( " TableState . generate " ) <nl> - self . impl_content = jinja2 . Template ( TEMPLATES [ template ] ) . render ( <nl> - table_name = self . table_name , <nl> - table_name_cc = to_camel_case ( self . table_name ) , <nl> - schema = self . columns ( ) , <nl> - header = self . header , <nl> - impl = self . impl , <nl> - function = self . function , <nl> - class_name = self . class_name , <nl> - attributes = self . attributes , <nl> - examples = self . examples , <nl> - ) <nl> <nl> - column_options = [ ] <nl> + all_options = [ ] <nl> + # Create a list of column options from the kwargs passed to the column . <nl> for column in self . columns ( ) : <nl> - column_options + = column . options <nl> - non_cachable = [ " index " , " required " , " additional " , " superuser " ] <nl> - if " cachable " in self . attributes : <nl> - if len ( set ( column_options ) . intersection ( non_cachable ) ) > 0 : <nl> - print ( lightred ( " Table cannot be marked cachable : % s " % ( path ) ) ) <nl> + column_options = [ ] <nl> + for option in column . options : <nl> + # Only allow explicitly - defined options . <nl> + if option in COLUMN_OPTIONS : <nl> + column_options . append ( COLUMN_OPTIONS [ option ] ) <nl> + all_options . append ( COLUMN_OPTIONS [ option ] ) <nl> + column . options_set = " | " . join ( column_options ) <nl> + if len ( all_options ) > 0 : <nl> + self . has_options = True <nl> + if " cacheable " in self . attributes : <nl> + if len ( set ( all_options ) . intersection ( NON_CACHEABLE ) ) > 0 : <nl> + print ( lightred ( " Table cannot be marked cacheable : % s " % ( path ) ) ) <nl> exit ( 1 ) <nl> if self . table_name = = " " or self . function = = " " : <nl> print ( lightred ( " Invalid table spec : % s " % ( path ) ) ) <nl> def generate ( self , path , template = " default " ) : <nl> # May encounter a race when using a make jobserver . <nl> pass <nl> logging . debug ( " generating % s " % path ) <nl> + self . impl_content = jinja2 . Template ( TEMPLATES [ template ] ) . render ( <nl> + table_name = self . table_name , <nl> + table_name_cc = to_camel_case ( self . table_name ) , <nl> + schema = self . columns ( ) , <nl> + header = self . header , <nl> + impl = self . impl , <nl> + function = self . function , <nl> + class_name = self . class_name , <nl> + attributes = self . attributes , <nl> + examples = self . examples , <nl> + has_options = self . has_options , <nl> + ) <nl> + <nl> with open ( path , " w + " ) as file_h : <nl> file_h . write ( self . impl_content ) <nl> <nl> mmm a / tools / codegen / templates / default . cpp . in <nl> ppp b / tools / codegen / templates / default . cpp . in <nl> class { { table_name_cc } } TablePlugin : public TablePlugin { <nl> TableColumns columns ( ) const override { <nl> return { <nl> { % for column in schema % } \ <nl> - { " { { column . name } } " , { { column . type . affinity } } } \ <nl> - { % if not loop . last % } , { % endif % } <nl> + std : : make_tuple ( " { { column . name } } " , { { column . type . affinity } } , \ <nl> + { % if column . options | length > 0 % } { { column . options_set } } \ <nl> + { % else % } DEFAULT \ <nl> + { % endif % } \ <nl> + ) , <nl> { % endfor % } \ <nl> } ; <nl> } <nl> class { { table_name_cc } } TablePlugin : public TablePlugin { <nl> return QueryData ( ) ; <nl> } <nl> { % else % } \ <nl> - { % if attributes . cachable % } \ <nl> + { % if attributes . cacheable % } \ <nl> if ( isCached ( kCacheStep ) ) { <nl> return getCache ( ) ; <nl> } <nl> { % endif % } \ <nl> auto results = tables : : { { function } } ( request ) ; <nl> - { % if attributes . cachable % } \ <nl> + { % if attributes . cacheable % } \ <nl> setCache ( kCacheStep , kCacheInterval , results ) ; <nl> { % endif % } <nl> return results ; <nl> mmm a / tools / codegen / templates / foreign . cpp . in <nl> ppp b / tools / codegen / templates / foreign . cpp . in <nl> auto { { table_name_cc } } Register = [ ] ( ) { <nl> / / / BEGIN [ GENTABLE ] <nl> class { { table_name_cc } } TablePlugin : public TablePlugin { <nl> private : <nl> - TableColumns columns ( ) const { <nl> + TableColumns columns ( ) const override { <nl> return { <nl> { % for column in schema % } \ <nl> - { " { { column . name } } " , { { column . type . affinity } } } \ <nl> - { % if not loop . last % } , { % endif % } <nl> + std : : make_tuple ( " { { column . name } } " , { { column . type . affinity } } , \ <nl> + { % if column . options | length > 0 % } { { column . options_set } } \ <nl> + { % else % } DEFAULT \ <nl> + { % endif % } \ <nl> + ) , <nl> { % endfor % } \ <nl> } ; <nl> } <nl> <nl> - QueryData generate ( QueryContext & request ) { return QueryData ( ) ; } <nl> + QueryData generate ( QueryContext & request ) override { return QueryData ( ) ; } <nl> } ; <nl> <nl> Registry : : add < { { table_name_cc } } TablePlugin > ( " table " , " { { table_name } } " ) ; <nl>
Introduce table options ( )
osquery/osquery
b28c4d8d0f0b845c03d93cd4ab809da4fd515451
2016-05-18T19:23:52Z
mmm a / spec / api - menu - spec . js <nl> ppp b / spec / api - menu - spec . js <nl> describe ( ' menu module ' , function ( ) { <nl> } ) <nl> } ) <nl> <nl> - describe ( ' MenuItem with custom properties in constructor ' , function ( ) { <nl> + describe . only ( ' MenuItem with custom properties in constructor ' , function ( ) { <nl> it ( ' preserves the custom properties ' , function ( ) { <nl> var template = [ { <nl> label : ' menu 1 ' , <nl> describe ( ' MenuItem with custom properties in constructor ' , function ( ) { <nl> submenu : [ ] <nl> } ] <nl> <nl> - var menu = new Menu . buildFromTemplate ( template ) <nl> + var menu = Menu . buildFromTemplate ( template ) <nl> menu . items [ 0 ] . submenu . append ( new MenuItem ( { <nl> label : ' item 1 ' , <nl> customProp : ' bar ' <nl>
remove unneeded new keyword
electron/electron
fdf3f6ce306a83258a604e42d3f914e92bbcd01c
2016-10-05T20:44:28Z
mmm a / lib / Basics / memory - map . h <nl> ppp b / lib / Basics / memory - map . h <nl> int TRI_MMFileUnlock ( void * memoryAddress , size_t numOfBytes ) ; <nl> <nl> static inline int TRI_MSync ( int fd , char const * begin , char const * end ) { <nl> size_t pageSize = arangodb : : PageSizeFeature : : getPageSize ( ) ; <nl> - uintptr_t p = ( intptr_t ) begin ; <nl> - uintptr_t q = ( intptr_t ) end ; <nl> - uintptr_t g = ( intptr_t ) pageSize ; <nl> + uintptr_t p = ( uintptr_t ) begin ; <nl> + uintptr_t g = ( uintptr_t ) pageSize ; <nl> <nl> char * b = ( char * ) ( ( p / g ) * g ) ; <nl> - char * e = ( char * ) ( ( ( q + g - 1 ) / g ) * g ) ; <nl> <nl> - return TRI_FlushMMFile ( fd , b , e - b , MS_SYNC ) ; <nl> + return TRI_FlushMMFile ( fd , b , end - b , MS_SYNC ) ; <nl> } <nl> <nl> # endif <nl>
modify msync code so that only base address is page - aligned ( )
arangodb/arangodb
5a13afd96d28f5695979899238beed16c0f841b6
2018-09-25T07:37:03Z
mmm a / tensorflow / g3doc / api_docs / python / control_flow_ops . md <nl> ppp b / tensorflow / g3doc / api_docs / python / control_flow_ops . md <nl> Example with nesting : <nl> ` ` ` python <nl> ijk_0 = ( tf . constant ( 0 ) , ( tf . constant ( 1 ) , tf . constant ( 2 ) ) ) <nl> c = lambda i , ( j , k ) : i < 10 <nl> - b = lambda i , ( j , k ) : ( i , ( j + k ) , ( j - k ) ) <nl> + b = lambda i , ( j , k ) : ( i + 1 , ( ( j + k ) , ( j - k ) ) ) <nl> ijk_final = tf . while_loop ( c , b , ijk_0 ) <nl> ` ` ` <nl> <nl> mmm a / tensorflow / g3doc / api_docs / python / functions_and_classes / shard4 / tf . while_loop . md <nl> ppp b / tensorflow / g3doc / api_docs / python / functions_and_classes / shard4 / tf . while_loop . md <nl> Example with nesting : <nl> ` ` ` python <nl> ijk_0 = ( tf . constant ( 0 ) , ( tf . constant ( 1 ) , tf . constant ( 2 ) ) ) <nl> c = lambda i , ( j , k ) : i < 10 <nl> - b = lambda i , ( j , k ) : ( i , ( j + k ) , ( j - k ) ) <nl> + b = lambda i , ( j , k ) : ( i + 1 , ( ( j + k ) , ( j - k ) ) ) <nl> ijk_final = tf . while_loop ( c , b , ijk_0 ) <nl> ` ` ` <nl> <nl>
Update generated Python Op docs .
tensorflow/tensorflow
94ce162cc335cccc41ab458671d0d73d53af0c07
2016-06-23T16:32:41Z
mmm a / tools / js - optimizer . js <nl> ppp b / tools / js - optimizer . js <nl> var ASM_FLOAT_ZERO = null ; / / TODO : share the entire node ? <nl> function detectAsmCoercion ( node , asmInfo , inVarDef ) { <nl> / / for params , + x vs x | 0 , for vars , 0 . 0 vs 0 <nl> if ( node [ 0 ] = = = ' num ' & & node [ 1 ] . toString ( ) . indexOf ( ' . ' ) > = 0 ) return ASM_DOUBLE ; <nl> - if ( node [ 0 ] = = = ' unary - prefix ' ) return ASM_DOUBLE ; <nl> + if ( node [ 0 ] = = = ' unary - prefix ' & & node [ 1 ] = = = ' + ' ) return ASM_DOUBLE ; <nl> if ( node [ 0 ] = = = ' call ' & & node [ 1 ] [ 0 ] = = = ' name ' & & node [ 1 ] [ 1 ] = = = ' Math_fround ' ) return ASM_FLOAT ; <nl> if ( asmInfo & & node [ 0 ] = = ' name ' ) return getAsmType ( node [ 1 ] , asmInfo ) ; <nl> if ( node [ 0 ] = = = ' name ' ) { <nl>
make detectAsmCoercion not see unary - as double
emscripten-core/emscripten
8c900f3dce6e410ee18609d3661af3a491ce19b7
2014-09-22T00:59:12Z
mmm a / etc / system_perf . yml <nl> ppp b / etc / system_perf . yml <nl> tasks : <nl> - func : " prepare environment " <nl> vars : <nl> storageEngine : " wiredTiger " <nl> - test : " ycsb . noise_test " <nl> + test : " ycsb " <nl> - func : " infrastructure provisioning " <nl> - func : " configure mongodb cluster " <nl> vars : <nl> tasks : <nl> - func : " prepare environment " <nl> vars : <nl> storageEngine : " mmapv1 " <nl> - test : " ycsb . noise_test " <nl> + test : " ycsb " <nl> - func : " infrastructure provisioning " <nl> - func : " configure mongodb cluster " <nl> vars : <nl>
SERVER - 28731 system_perf . yml : Remove accidental change of which ycsb test to run
mongodb/mongo
1db2940cbc397b3fd8b5250024b85ffa175cccd8
2017-04-12T19:50:52Z
mmm a / README . md <nl> ppp b / README . md <nl> make <nl> <nl> # # CNN - based Face Detection on ARM Linux ( Raspberry Pi 3 B + ) <nl> <nl> - ( * to be updated ) <nl> + ( To be updated ) <nl> + <nl> | Method | Time | FPS | Time | FPS | <nl> | mmmmmmmmmmmmmmmmmm - - | mmmmmmmmmmmm - - | mmmmmmmmmmmm - | mmmmmmmmmmmm - - | mmmmmmmmmmmm - | <nl> | | Single - thread | Single - thread | Multi - thread | Multi - thread | <nl>
Merge pull request from harshithdwivedi / patch - 1
ShiqiYu/libfacedetection
4b87167f03533d076f15aa00fcf96c89e0527ff3
2019-12-06T03:13:17Z
mmm a / src / btree / iteration . hpp <nl> ppp b / src / btree / iteration . hpp <nl> struct key_value_pair_t { <nl> std : : string key ; <nl> boost : : shared_array < char > value ; <nl> <nl> + / / TODO ! Going to change with templated btrees . . . <nl> + bool operator = = ( const key_value_pair_t & k ) const { <nl> + return key = = k . key ; <nl> + } <nl> + bool operator < ( const key_value_pair_t & k ) const { <nl> + return key < k . key ; <nl> + } <nl> + <nl> key_value_pair_t ( value_sizer_t * sizer , const std : : string & _key , const value_type_t * _value ) : key ( _key ) { <nl> int size = sizer - > size ( _value ) ; <nl> value . reset ( new char [ size ] ) ; <nl> mmm a / src / containers / iterators . hpp <nl> ppp b / src / containers / iterators . hpp <nl> class merge_ordered_data_iterator_t : public one_way_iterator_t < T > { <nl> <nl> } ; <nl> <nl> + / * <nl> + unique_iterator_t removes duplicates . It requires the input iterator to be sorted . <nl> + T has to implement operator = = ( ) . <nl> + * / <nl> + template < class T > <nl> + class unique_filter_iterator_t : public one_way_iterator_t < T > { <nl> + public : <nl> + unique_filter_iterator_t ( one_way_iterator_t < T > * _ownee ) : previous ( boost : : none ) , ownee ( _ownee ) { } <nl> + ~ unique_filter_iterator_t ( ) { <nl> + delete ownee ; <nl> + } <nl> + virtual typename boost : : optional < T > next ( ) { <nl> + for ( ; ; ) { <nl> + boost : : optional < T > value = ownee - > next ( ) ; <nl> + if ( ! value ) { <nl> + previous = value ; <nl> + return boost : : none ; <nl> + } else { <nl> + / / Is this element different from what we had before ? <nl> + if ( ! previous | | ! ( previous . get ( ) = = value . get ( ) ) ) { <nl> + previous = value ; <nl> + return value ; <nl> + } <nl> + / / otherwise , continue . <nl> + } <nl> + } <nl> + } <nl> + void prefetch ( ) { <nl> + / / TODO : Should we implement this ? <nl> + ownee - > prefetch ( ) ; <nl> + } <nl> + <nl> + private : <nl> + boost : : optional < T > previous ; <nl> + one_way_iterator_t < T > * ownee ; <nl> + } ; <nl> + <nl> + / / TODO : Union of sets can be implemented as a unque iterator around a merge iterator . <nl> + <nl> + / * TODO ! Document ( especially what happens in case of more than n repetitions ) * / <nl> + template < class T > <nl> + class repetition_filter_iterator_t : public one_way_iterator_t < T > { <nl> + public : <nl> + repetition_filter_iterator_t ( one_way_iterator_t < T > * _ownee , int _n_repetitions ) : previous ( boost : : none ) , previous_repetitions ( 0 ) , ownee ( _ownee ) , n_repetitions ( _n_repetitions ) { <nl> + rassert ( n_repetitions > 0 ) ; <nl> + } <nl> + ~ repetition_filter_iterator_t ( ) { <nl> + delete ownee ; <nl> + } <nl> + virtual typename boost : : optional < T > next ( ) { <nl> + for ( ; ; ) { <nl> + boost : : optional < T > value = ownee - > next ( ) ; <nl> + if ( ! value ) { <nl> + previous = value ; <nl> + previous_repetitions = 0 ; <nl> + return boost : : none ; <nl> + } else { <nl> + / / Is this element different from what we had before ? <nl> + if ( ! previous | | ! ( previous . get ( ) = = value . get ( ) ) ) { <nl> + / / Different , start over <nl> + previous_repetitions = 1 ; <nl> + previous = value ; <nl> + } else { <nl> + / / The same , increment counter <nl> + + + previous_repetitions ; <nl> + } <nl> + <nl> + / / Have we got enough repetitions ? <nl> + rassert ( previous_repetitions < = n_repetitions ) ; <nl> + if ( previous_repetitions = = n_repetitions ) { <nl> + previous_repetitions = 0 ; <nl> + return value ; <nl> + } <nl> + / / otherwise , continue . <nl> + } <nl> + } <nl> + } <nl> + void prefetch ( ) { <nl> + / / TODO : Should we implement this ? <nl> + ownee - > prefetch ( ) ; <nl> + } <nl> + <nl> + private : <nl> + boost : : optional < T > previous ; <nl> + int previous_repetitions ; <nl> + one_way_iterator_t < T > * ownee ; <nl> + int n_repetitions ; <nl> + } ; <nl> + <nl> + / / TODO : Intersection of sets can be implemented as a repetition iterator around a merge iterator . <nl> + <nl> # endif / * __CONTAINERS_ITERATOR_HPP__ * / <nl>
Implement unique filter and repetition filter iterators
rethinkdb/rethinkdb
4097c7b99a4a4081e52a7f0feef7e695f547d517
2011-07-18T23:25:30Z
mmm a / hphp / runtime / vm / jit / inlining - decider . cpp <nl> ppp b / hphp / runtime / vm / jit / inlining - decider . cpp <nl> bool traceRefusal ( const Func * caller , const Func * callee , const char * why ) { <nl> <nl> std : : atomic < bool > hasCalledDisableInliningIntrinsic ; <nl> hphp_hash_set < const StringData * , <nl> - string_data_hash , <nl> - string_data_isame > forbiddenInlinees ; <nl> + string_data_hash , <nl> + string_data_isame > forbiddenInlinees ; <nl> SimpleMutex forbiddenInlineesLock ; <nl> <nl> bool inliningIsForbiddenFor ( const Func * callee ) { <nl> bool InliningDecider : : canInlineAt ( SrcKey callSK , const Func * callee ) const { <nl> if ( auto cls = callee - > implCls ( ) ) { <nl> if ( ! classHasPersistentRDS ( cls ) ) { <nl> if ( callee - > isClosureBody ( ) ) { <nl> - return callee - > unit ( ) = = callSK . unit ( ) ; <nl> - } <nl> - / / if the callee ' s class is not persistent , its still ok <nl> - / / to use it if we ' re jitting into a method of a subclass <nl> - auto ctx = callSK . func ( ) - > cls ( ) ; <nl> - if ( ! ctx | | ! ctx - > classof ( cls ) ) { <nl> - return false ; <nl> + if ( callee - > unit ( ) ! = callSK . unit ( ) ) return false ; <nl> + } else { <nl> + / / if the callee ' s class is not persistent , its still ok <nl> + / / to use it if we ' re jitting into a method of a subclass <nl> + auto ctx = callSK . func ( ) - > cls ( ) ; <nl> + if ( ! ctx | | ! ctx - > classof ( cls ) ) { <nl> + return false ; <nl> + } <nl> } <nl> } <nl> } else { <nl>
Fix a bug deciding whether to inline closures
facebook/hhvm
62b7051e07a36ab91fb391e12e8982316f3df141
2016-08-13T14:36:06Z
mmm a / test / test_torch . py <nl> ppp b / test / test_torch . py <nl> def test_bmm ( self , device , dtype ) : <nl> self . assertRaises ( RuntimeError , lambda : torch . bmm ( b1 . cuda ( ) , b2 ) ) <nl> <nl> @ onlyCUDA <nl> - @ unittest . skipIf ( IS_WINDOWS , " Test is broken on Windows . See https : / / github . com / pytorch / pytorch / issues / 42501 " ) <nl> @ wrapDeterministicFlagAPITest <nl> def test_cublas_config_deterministic_error ( self , device ) : <nl> test_cases = [ <nl>
Enable test_cublas_config_deterministic_error for windows ( )
pytorch/pytorch
6cecf7ec68d4902e7d756537fa99cb78414ad115
2020-09-04T16:52:57Z
mmm a / cocos / scripting / js - bindings / manual / extension / jsb_cocos2dx_extension_manual . cpp <nl> ppp b / cocos / scripting / js - bindings / manual / extension / jsb_cocos2dx_extension_manual . cpp <nl> static bool js_cocos2dx_CCTableView_init ( JSContext * cx , uint32_t argc , jsval * vp <nl> cocos2d : : Node * arg2 ; <nl> do <nl> { <nl> - js_proxy_t * proxy ; <nl> JSObject * tmpObj = args . get ( 2 ) . toObjectOrNull ( ) ; <nl> proxy = jsb_get_js_proxy ( tmpObj ) ; <nl> arg2 = ( cocos2d : : Node * ) ( proxy ? proxy - > ptr : NULL ) ; <nl> class JSB_ControlButtonTarget : public Ref <nl> { <nl> public : <nl> JSB_ControlButtonTarget ( ) <nl> - : _jsFunc ( nullptr ) , <nl> + : _callback ( nullptr ) , <nl> + _jsFunc ( nullptr ) , <nl> _type ( Control : : EventType : : TOUCH_DOWN ) , <nl> - _jsTarget ( nullptr ) , <nl> _needUnroot ( false ) <nl> { } <nl> <nl> virtual ~ JSB_ControlButtonTarget ( ) <nl> { <nl> CCLOGINFO ( " In the destruction of JSB_ControlButtonTarget . . . " ) ; <nl> - JSContext * cx = ScriptingCore : : getInstance ( ) - > getGlobalContext ( ) ; <nl> - if ( _needUnroot ) <nl> + if ( _callback ! = nullptr ) <nl> { <nl> - JS : : RemoveObjectRoot ( cx , & _jsTarget ) ; <nl> + CC_SAFE_DELETE ( _callback ) ; <nl> } <nl> - <nl> - JS : : RemoveObjectRoot ( cx , & _jsFunc ) ; <nl> <nl> for ( auto iter = _jsNativeTargetMap . begin ( ) ; iter ! = _jsNativeTargetMap . end ( ) ; + + iter ) <nl> { <nl> class JSB_ControlButtonTarget : public Ref <nl> return ; <nl> } <nl> <nl> + JSContext * cx = ScriptingCore : : getInstance ( ) - > getGlobalContext ( ) ; <nl> + <nl> jsval dataVal [ 2 ] ; <nl> dataVal [ 0 ] = OBJECT_TO_JSVAL ( p - > obj ) ; <nl> int arg1 = ( int ) event ; <nl> dataVal [ 1 ] = INT_TO_JSVAL ( arg1 ) ; <nl> - <nl> - JSContext * cx = ScriptingCore : : getInstance ( ) - > getGlobalContext ( ) ; <nl> JS : : RootedValue jsRet ( cx ) ; <nl> - <nl> - ScriptingCore : : getInstance ( ) - > executeJSFunctionWithThisObj ( JS : : RootedValue ( cx , OBJECT_TO_JSVAL ( _jsTarget ) ) , JS : : RootedValue ( cx , OBJECT_TO_JSVAL ( _jsFunc ) ) , JS : : HandleValueArray : : fromMarkedLocation ( 2 , dataVal ) , & jsRet ) ; <nl> + <nl> + _callback - > invoke ( 2 , dataVal , & jsRet ) ; <nl> } <nl> <nl> - void setJSTarget ( JSObject * pJSTarget ) <nl> + void setJSCallback ( jsval jsFunc , JSObject * jsTarget ) <nl> { <nl> - _jsTarget = pJSTarget ; <nl> - <nl> - js_proxy_t * p = jsb_get_js_proxy ( _jsTarget ) ; <nl> - if ( ! p ) <nl> + if ( _callback ! = nullptr ) <nl> { <nl> - JSContext * cx = ScriptingCore : : getInstance ( ) - > getGlobalContext ( ) ; <nl> - JS : : AddNamedObjectRoot ( cx , & _jsTarget , " JSB_ControlButtonTarget , target " ) ; <nl> - _needUnroot = true ; <nl> + CC_SAFE_DELETE ( _callback ) ; <nl> } <nl> - } <nl> - <nl> - void setJSAction ( JSObject * jsFunc ) <nl> - { <nl> - _jsFunc = jsFunc ; <nl> - <nl> JSContext * cx = ScriptingCore : : getInstance ( ) - > getGlobalContext ( ) ; <nl> - JS : : AddNamedObjectRoot ( cx , & _jsFunc , " JSB_ControlButtonTarget , func " ) ; <nl> + _callback = new JSFunctionWrapper ( cx , jsTarget , jsFunc ) ; <nl> + _jsFunc = jsFunc . toObjectOrNull ( ) ; <nl> } <nl> <nl> void setEventType ( Control : : EventType type ) <nl> class JSB_ControlButtonTarget : public Ref <nl> public : <nl> <nl> static std : : multimap < JSObject * , JSB_ControlButtonTarget * > _jsNativeTargetMap ; <nl> - JS : : Heap < JSObject * > _jsFunc ; <nl> + JSFunctionWrapper * _callback ; <nl> Control : : EventType _type ; <nl> + JSObject * _jsFunc ; <nl> private : <nl> - JS : : Heap < JSObject * > _jsTarget ; <nl> bool _needUnroot ; <nl> } ; <nl> <nl> static bool js_cocos2dx_CCControl_addTargetWithActionForControlEvents ( JSContext <nl> / / save the delegate <nl> JSB_ControlButtonTarget * nativeDelegate = new JSB_ControlButtonTarget ( ) ; <nl> <nl> - nativeDelegate - > setJSTarget ( jsDelegate ) ; <nl> - nativeDelegate - > setJSAction ( jsFunc ) ; <nl> + nativeDelegate - > setJSCallback ( args . get ( 1 ) , jsDelegate ) ; <nl> nativeDelegate - > setEventType ( arg2 ) ; <nl> <nl> __Array * nativeDelegateArray = static_cast < __Array * > ( cobj - > getUserObject ( ) ) ; <nl> mmm a / cocos / scripting / js - bindings / manual / network / jsb_socketio . cpp <nl> ppp b / cocos / scripting / js - bindings / manual / network / jsb_socketio . cpp <nl> <nl> <nl> using namespace cocos2d : : network ; <nl> <nl> - class JSB_SIOEvent : public cocos2d : : Object { <nl> - public : <nl> - JSB_SIOEvent ( ) ; <nl> - virtual ~ JSB_SIOEvent ( ) ; <nl> - void setJSCallbackFunc ( jsval obj ) ; <nl> - const jsval & getJSCallbackFunc ( ) const ; <nl> - <nl> - private : <nl> - JS : : Heap < jsval > _jsCallback ; <nl> - JS : : Heap < jsval > _extraData ; <nl> - <nl> - } ; <nl> - <nl> - JSB_SIOEvent : : JSB_SIOEvent ( ) <nl> - : _jsCallback ( JSVAL_VOID ) , _extraData ( JSVAL_VOID ) <nl> - { <nl> - <nl> - } <nl> - <nl> - JSB_SIOEvent : : ~ JSB_SIOEvent ( ) <nl> - { <nl> - JSContext * cx = ScriptingCore : : getInstance ( ) - > getGlobalContext ( ) ; <nl> - JS : : RemoveValueRoot ( cx , & _jsCallback ) ; <nl> - } <nl> - <nl> - void JSB_SIOEvent : : setJSCallbackFunc ( jsval func ) { <nl> - _jsCallback = func ; <nl> - JSContext * cx = ScriptingCore : : getInstance ( ) - > getGlobalContext ( ) ; <nl> - / / Root the callback function . <nl> - JS : : AddNamedValueRoot ( cx , & _jsCallback , " JSB_SIOEvent_callback_func " ) ; <nl> - } <nl> - <nl> - const jsval & JSB_SIOEvent : : getJSCallbackFunc ( ) const <nl> - { <nl> - return _jsCallback ; <nl> - } <nl> - <nl> / / c + + 11 map to callbacks <nl> - typedef std : : unordered_map < std : : string , JSB_SIOEvent > JSB_SIOEventRegistry ; <nl> + typedef std : : unordered_map < std : : string , std : : shared_ptr < JSFunctionWrapper > > JSB_SIOCallbackRegistry ; <nl> <nl> - class JSB_SocketIODelegate : public SocketIO : : SIODelegate { <nl> + class JSB_SocketIODelegate : public SocketIO : : SIODelegate <nl> + { <nl> public : <nl> <nl> - JSB_SocketIODelegate ( ) { <nl> - JSB_SIOEvent tmp ; <nl> + JSB_SocketIODelegate ( ) <nl> + { <nl> std : : string s = " default " ; <nl> - _eventRegistry [ s ] = tmp ; <nl> + _eventRegistry [ s ] = nullptr ; <nl> } <nl> <nl> - virtual void onConnect ( SIOClient * client ) { <nl> + virtual void onConnect ( SIOClient * client ) <nl> + { <nl> CCLOG ( " JSB SocketIO : : SIODelegate - > onConnect method called from native " ) ; <nl> - <nl> this - > fireEventToScript ( client , " connect " , " " ) ; <nl> - <nl> } <nl> <nl> - virtual void onMessage ( SIOClient * client , const std : : string & data ) { <nl> + virtual void onMessage ( SIOClient * client , const std : : string & data ) <nl> + { <nl> CCLOG ( " JSB SocketIO : : SIODelegate - > onMessage method called from native with data : % s " , data . c_str ( ) ) ; <nl> - <nl> this - > fireEventToScript ( client , " message " , data ) ; <nl> - <nl> } <nl> <nl> - virtual void onClose ( SIOClient * client ) { <nl> + virtual void onClose ( SIOClient * client ) <nl> + { <nl> CCLOG ( " JSB SocketIO : : SIODelegate - > onClose method called from native " ) ; <nl> - <nl> this - > fireEventToScript ( client , " disconnect " , " " ) ; <nl> - <nl> } <nl> <nl> - virtual void onError ( SIOClient * client , const std : : string & data ) { <nl> + virtual void onError ( SIOClient * client , const std : : string & data ) <nl> + { <nl> CCLOG ( " JSB SocketIO : : SIODelegate - > onError method called from native with data : % s " , data . c_str ( ) ) ; <nl> - <nl> this - > fireEventToScript ( client , " error " , data ) ; <nl> - <nl> } <nl> <nl> - virtual void fireEventToScript ( SIOClient * client , const std : : string & eventName , const std : : string & data ) { <nl> + virtual void fireEventToScript ( SIOClient * client , const std : : string & eventName , const std : : string & data ) <nl> + { <nl> CCLOG ( " JSB SocketIO : : SIODelegate - > fireEventToScript method called from native with name ' % s ' data : % s " , eventName . c_str ( ) , data . c_str ( ) ) ; <nl> <nl> js_proxy_t * p = jsb_get_native_proxy ( client ) ; <nl> class JSB_SocketIODelegate : public SocketIO : : SIODelegate { <nl> JSContext * cx = ScriptingCore : : getInstance ( ) - > getGlobalContext ( ) ; <nl> <nl> jsval args ; <nl> - if ( data = = " " ) { <nl> + if ( data = = " " ) <nl> + { <nl> args = JSVAL_NULL ; <nl> - } else { <nl> + } else <nl> + { <nl> args = std_string_to_jsval ( cx , data ) ; <nl> } <nl> <nl> / / ScriptingCore : : getInstance ( ) - > executeFunctionWithOwner ( OBJECT_TO_JSVAL ( _JSDelegate ) , eventName . c_str ( ) , 1 , & args ) ; <nl> <nl> - JSB_SIOEventRegistry : : iterator it = _eventRegistry . find ( eventName ) ; <nl> + JSB_SIOCallbackRegistry : : iterator it = _eventRegistry . find ( eventName ) ; <nl> <nl> - if ( it ! = _eventRegistry . end ( ) ) { <nl> - JSB_SIOEvent e = it - > second ; <nl> - JS : : RootedValue rval ( cx ) ; <nl> - ScriptingCore : : getInstance ( ) - > executeJSFunctionWithThisObj ( JS : : RootedValue ( cx , OBJECT_TO_JSVAL ( p - > obj ) ) , JS : : RootedValue ( cx , e . getJSCallbackFunc ( ) ) , JS : : HandleValueArray : : fromMarkedLocation ( 1 , & args ) , & rval ) ; <nl> + if ( it ! = _eventRegistry . end ( ) ) <nl> + { <nl> + std : : shared_ptr < JSFunctionWrapper > callback = it - > second ; <nl> + if ( callback ! = nullptr ) <nl> + { <nl> + JS : : RootedValue rval ( cx ) ; <nl> + callback - > invoke ( 1 , & args , & rval ) ; <nl> + } <nl> } <nl> <nl> } <nl> <nl> - void setJSDelegate ( JSObject * pJSDelegate ) { <nl> + void setJSDelegate ( JSObject * pJSDelegate ) <nl> + { <nl> _JSDelegate = pJSDelegate ; <nl> } <nl> <nl> - void addEvent ( const std : : string & eventName , JSB_SIOEvent jsevent ) { <nl> - _eventRegistry [ eventName ] = jsevent ; <nl> + void addEvent ( const std : : string & eventName , std : : shared_ptr < JSFunctionWrapper > callback ) <nl> + { <nl> + _eventRegistry [ eventName ] = callback ; <nl> } <nl> <nl> private : <nl> JS : : Heap < JSObject * > _JSDelegate ; <nl> - <nl> - JSB_SIOEventRegistry _eventRegistry ; <nl> + JSB_SIOCallbackRegistry _eventRegistry ; <nl> <nl> } ; <nl> <nl> JSClass * js_cocos2dx_socketio_class ; <nl> JSObject * js_cocos2dx_socketio_prototype ; <nl> <nl> - void js_cocos2dx_SocketIO_finalize ( JSFreeOp * fop , JSObject * obj ) { <nl> + void js_cocos2dx_SocketIO_finalize ( JSFreeOp * fop , JSObject * obj ) <nl> + { <nl> CCLOG ( " jsbindings : finalizing JS object % p ( SocketIO ) " , obj ) ; <nl> } <nl> <nl> bool js_cocos2dx_SocketIO_constructor ( JSContext * cx , uint32_t argc , jsval * vp ) <nl> { <nl> JS_ReportError ( cx , " SocketIO isn ' t meant to be instantiated , use SocketIO . connect ( ) instead " ) ; <nl> - <nl> return false ; <nl> } <nl> <nl> - bool js_cocos2dx_SocketIO_connect ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> + bool js_cocos2dx_SocketIO_connect ( JSContext * cx , uint32_t argc , jsval * vp ) <nl> + { <nl> CCLOG ( " JSB SocketIO . connect method called " ) ; <nl> <nl> JS : : CallArgs args = JS : : CallArgsFromVp ( argc , vp ) ; <nl> - <nl> - if ( argc = = 1 | | argc = = 2 ) { <nl> - <nl> + if ( argc = = 1 | | argc = = 2 ) <nl> + { <nl> std : : string url ; <nl> <nl> - do { <nl> + do <nl> + { <nl> bool ok = jsval_to_std_string ( cx , args . get ( 0 ) , & url ) ; <nl> JSB_PRECONDITION2 ( ok , cx , false , " Error processing arguments " ) ; <nl> } while ( 0 ) ; <nl> bool js_cocos2dx_SocketIO_connect ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> JSB_SocketIODelegate * siodelegate = new JSB_SocketIODelegate ( ) ; <nl> <nl> CCLOG ( " Calling native SocketIO . connect method " ) ; <nl> - SIOClient * ret = SocketIO : : connect ( * siodelegate , url ) ; <nl> + SIOClient * ret = SocketIO : : connect ( url , * siodelegate ) ; <nl> <nl> jsval jsret ; <nl> - do { <nl> - if ( ret ) { <nl> + do <nl> + { <nl> + if ( ret ) <nl> + { <nl> / / link the native object with the javascript object <nl> js_proxy_t * p ; <nl> HASH_FIND_PTR ( _native_js_global_ht , & ret , p ) ; <nl> - if ( ! p ) { <nl> + if ( ! p ) <nl> + { <nl> / / previous connection not found , create a new one <nl> JSObject * obj = JS_NewObject ( cx , js_cocos2dx_socketio_class , JS : : RootedObject ( cx , js_cocos2dx_socketio_prototype ) , JS : : NullPtr ( ) ) ; <nl> p = jsb_new_proxy ( ret , obj ) ; <nl> JS : : AddNamedObjectRoot ( cx , & p - > obj , " SocketIO " ) ; <nl> siodelegate - > setJSDelegate ( p - > obj ) ; <nl> } <nl> - <nl> jsret = OBJECT_TO_JSVAL ( p - > obj ) ; <nl> - <nl> } <nl> - else { <nl> + else <nl> + { <nl> jsret = JSVAL_NULL ; <nl> } <nl> } while ( 0 ) ; <nl> <nl> args . rval ( ) . set ( jsret ) ; <nl> - <nl> return true ; <nl> - <nl> } <nl> - <nl> JS_ReportError ( cx , " JSB SocketIO . connect : Wrong number of arguments " ) ; <nl> return false ; <nl> } <nl> <nl> - bool js_cocos2dx_SocketIO_send ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> + bool js_cocos2dx_SocketIO_send ( JSContext * cx , uint32_t argc , jsval * vp ) <nl> + { <nl> CCLOG ( " JSB SocketIO . send method called " ) ; <nl> <nl> JS : : CallArgs args = JS : : CallArgsFromVp ( argc , vp ) ; <nl> bool js_cocos2dx_SocketIO_send ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> SIOClient * cobj = ( SIOClient * ) ( proxy ? proxy - > ptr : NULL ) ; <nl> JSB_PRECONDITION2 ( cobj , cx , false , " Invalid Native Object " ) ; <nl> <nl> - if ( argc = = 1 ) { <nl> - <nl> + if ( argc = = 1 ) <nl> + { <nl> std : : string payload ; <nl> <nl> - do { <nl> + do <nl> + { <nl> bool ok = jsval_to_std_string ( cx , args . get ( 0 ) , & payload ) ; <nl> JSB_PRECONDITION2 ( ok , cx , false , " Error processing arguments " ) ; <nl> } while ( 0 ) ; <nl> bool js_cocos2dx_SocketIO_send ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> CCLOG ( " JSB SocketIO send mesage : % s " , payload . c_str ( ) ) ; <nl> <nl> cobj - > send ( payload ) ; <nl> - <nl> return true ; <nl> <nl> } <nl> - <nl> JS_ReportError ( cx , " Wrong number of arguments " ) ; <nl> return false ; <nl> - <nl> } <nl> <nl> - bool js_cocos2dx_SocketIO_emit ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> + bool js_cocos2dx_SocketIO_emit ( JSContext * cx , uint32_t argc , jsval * vp ) <nl> + { <nl> CCLOG ( " JSB SocketIO . emit method called " ) ; <nl> <nl> JS : : CallArgs args = JS : : CallArgsFromVp ( argc , vp ) ; <nl> bool js_cocos2dx_SocketIO_emit ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> SIOClient * cobj = ( SIOClient * ) ( proxy ? proxy - > ptr : NULL ) ; <nl> JSB_PRECONDITION2 ( cobj , cx , false , " Invalid Native Object " ) ; <nl> <nl> - if ( argc = = 2 ) { <nl> - <nl> + if ( argc = = 2 ) <nl> + { <nl> std : : string eventName ; <nl> - <nl> - do { <nl> + do <nl> + { <nl> bool ok = jsval_to_std_string ( cx , args . get ( 0 ) , & eventName ) ; <nl> JSB_PRECONDITION2 ( ok , cx , false , " Error processing arguments " ) ; <nl> } while ( 0 ) ; <nl> <nl> std : : string payload ; <nl> - <nl> do { <nl> bool ok = jsval_to_std_string ( cx , args . get ( 1 ) , & payload ) ; <nl> JSB_PRECONDITION2 ( ok , cx , false , " Error processing arguments " ) ; <nl> bool js_cocos2dx_SocketIO_emit ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> CCLOG ( " JSB SocketIO emit event ' % s ' with payload : % s " , eventName . c_str ( ) , payload . c_str ( ) ) ; <nl> <nl> cobj - > emit ( eventName , payload ) ; <nl> - <nl> return true ; <nl> - <nl> } <nl> - <nl> JS_ReportError ( cx , " JSB SocketIO . emit : Wrong number of arguments " ) ; <nl> return false ; <nl> - <nl> } <nl> <nl> - bool js_cocos2dx_SocketIO_disconnect ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> + bool js_cocos2dx_SocketIO_disconnect ( JSContext * cx , uint32_t argc , jsval * vp ) <nl> + { <nl> CCLOG ( " JSB SocketIO . disconnect method called " ) ; <nl> <nl> JS : : CallArgs args = JS : : CallArgsFromVp ( argc , vp ) ; <nl> bool js_cocos2dx_SocketIO_disconnect ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> SIOClient * cobj = ( SIOClient * ) ( proxy ? proxy - > ptr : NULL ) ; <nl> JSB_PRECONDITION2 ( cobj , cx , false , " Invalid Native Object " ) ; <nl> <nl> - if ( argc = = 0 ) { <nl> - <nl> + if ( argc = = 0 ) <nl> + { <nl> cobj - > disconnect ( ) ; <nl> args . rval ( ) . setUndefined ( ) ; <nl> return true ; <nl> bool js_cocos2dx_SocketIO_disconnect ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> <nl> JS_ReportError ( cx , " JSB SocketIO . disconnect : Wrong number of arguments " ) ; <nl> return false ; <nl> - <nl> } <nl> <nl> - bool js_cocos2dx_SocketIO_close ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> + bool js_cocos2dx_SocketIO_close ( JSContext * cx , uint32_t argc , jsval * vp ) <nl> + { <nl> CCLOG ( " JSB SocketIO . close method called " ) ; <nl> <nl> - if ( argc = = 0 ) { <nl> + if ( argc = = 0 ) <nl> + { <nl> <nl> / / This method was previously implemented to take care of the HTTPClient instance not being destroyed properly <nl> / / SocketIO : : close ( ) ; <nl> bool js_cocos2dx_SocketIO_close ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> <nl> JS_ReportError ( cx , " JSB SocketIO . close : Wrong number of arguments " ) ; <nl> return false ; <nl> - <nl> } <nl> <nl> static bool _js_set_SIOClient_tag ( JSContext * cx , uint32_t argc , jsval * vp ) <nl> static bool _js_set_SIOClient_tag ( JSContext * cx , uint32_t argc , jsval * vp ) <nl> SIOClient * cobj = ( SIOClient * ) ( proxy ? proxy - > ptr : NULL ) ; <nl> JSB_PRECONDITION2 ( cobj , cx , false , " Invalid Native Object " ) ; <nl> <nl> - if ( cobj ) { <nl> + if ( cobj ) <nl> + { <nl> std : : string out = " " ; <nl> <nl> jsval_to_std_string ( cx , args . get ( 0 ) , & out ) ; <nl> cobj - > setTag ( out . c_str ( ) ) ; <nl> return true ; <nl> - } else { <nl> + } else <nl> + { <nl> JS_ReportError ( cx , " Error : SocketIO instance is invalid . " ) ; <nl> return false ; <nl> } <nl> - <nl> } <nl> <nl> static bool _js_get_SIOClient_tag ( JSContext * cx , uint32_t argc , jsval * vp ) <nl> static bool _js_get_SIOClient_tag ( JSContext * cx , uint32_t argc , jsval * vp ) <nl> SIOClient * cobj = ( SIOClient * ) ( proxy ? proxy - > ptr : NULL ) ; <nl> JSB_PRECONDITION2 ( cobj , cx , false , " Invalid Native Object " ) ; <nl> <nl> - if ( cobj ) { <nl> + if ( cobj ) <nl> + { <nl> args . rval ( ) . set ( std_string_to_jsval ( cx , cobj - > getTag ( ) ) ) ; <nl> return true ; <nl> - } else { <nl> + } else <nl> + { <nl> JS_ReportError ( cx , " Error : SocketIO instance is invalid . " ) ; <nl> return false ; <nl> } <nl> - <nl> } <nl> <nl> <nl> - bool js_cocos2dx_SocketIO_on ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> + bool js_cocos2dx_SocketIO_on ( JSContext * cx , uint32_t argc , jsval * vp ) <nl> + { <nl> CCLOG ( " JSB SocketIO . on method called " ) ; <nl> <nl> JS : : CallArgs args = JS : : CallArgsFromVp ( argc , vp ) ; <nl> bool js_cocos2dx_SocketIO_on ( JSContext * cx , uint32_t argc , jsval * vp ) { <nl> SIOClient * cobj = ( SIOClient * ) ( proxy ? proxy - > ptr : NULL ) ; <nl> JSB_PRECONDITION2 ( cobj , cx , false , " Invalid Native Object " ) ; <nl> <nl> - if ( argc = = 2 ) { <nl> - <nl> + if ( argc = = 2 ) <nl> + { <nl> std : : string eventName ; <nl> - <nl> - do { <nl> + do <nl> + { <nl> bool ok = jsval_to_std_string ( cx , args . get ( 0 ) , & eventName ) ; <nl> JSB_PRECONDITION2 ( ok , cx , false , " Error processing arguments " ) ; <nl> } while ( 0 ) ; <nl> <nl> CCLOG ( " JSB SocketIO eventName to : ' % s ' " , eventName . c_str ( ) ) ; <nl> + <nl> + std : : shared_ptr < JSFunctionWrapper > callback ( new JSFunctionWrapper ( cx , JS_THIS_OBJECT ( cx , vp ) , args . get ( 1 ) ) ) ; <nl> <nl> - JSB_SIOEvent tmpCobj ; <nl> - tmpCobj . setJSCallbackFunc ( args . get ( 1 ) ) ; <nl> - <nl> - ( ( JSB_SocketIODelegate * ) cobj - > getDelegate ( ) ) - > addEvent ( eventName , tmpCobj ) ; <nl> + ( ( JSB_SocketIODelegate * ) cobj - > getDelegate ( ) ) - > addEvent ( eventName , callback ) ; <nl> <nl> args . rval ( ) . set ( OBJECT_TO_JSVAL ( proxy - > obj ) ) ; <nl> - <nl> JS_SetReservedSlot ( proxy - > obj , 0 , args . get ( 1 ) ) ; <nl> - <nl> return true ; <nl> } <nl> - <nl> JS_ReportError ( cx , " JSB SocketIO . close : Wrong number of arguments " ) ; <nl> return false ; <nl> - <nl> } <nl> <nl> - void register_jsb_socketio ( JSContext * cx , JS : : HandleObject global ) { <nl> - <nl> + void register_jsb_socketio ( JSContext * cx , JS : : HandleObject global ) <nl> + { <nl> js_cocos2dx_socketio_class = ( JSClass * ) calloc ( 1 , sizeof ( JSClass ) ) ; <nl> js_cocos2dx_socketio_class - > name = " SocketIO " ; <nl> js_cocos2dx_socketio_class - > addProperty = JS_PropertyStub ; <nl> void register_jsb_socketio ( JSContext * cx , JS : : HandleObject global ) { <nl> js_cocos2dx_socketio_class - > finalize = js_cocos2dx_SocketIO_finalize ; <nl> js_cocos2dx_socketio_class - > flags = JSCLASS_HAS_RESERVED_SLOTS ( 2 ) ; <nl> <nl> - static JSPropertySpec properties [ ] = { <nl> + static JSPropertySpec properties [ ] = <nl> + { <nl> JS_PSGS ( " tag " , _js_get_SIOClient_tag , _js_set_SIOClient_tag , JSPROP_PERMANENT | JSPROP_ENUMERATE ) , <nl> JS_PS_END <nl> } ; <nl> <nl> - static JSFunctionSpec funcs [ ] = { <nl> + static JSFunctionSpec funcs [ ] = <nl> + { <nl> JS_FN ( " send " , js_cocos2dx_SocketIO_send , 1 , JSPROP_PERMANENT | JSPROP_ENUMERATE ) , <nl> JS_FN ( " emit " , js_cocos2dx_SocketIO_emit , 2 , JSPROP_PERMANENT | JSPROP_ENUMERATE ) , <nl> JS_FN ( " disconnect " , js_cocos2dx_SocketIO_disconnect , 0 , JSPROP_PERMANENT | JSPROP_ENUMERATE ) , <nl> void register_jsb_socketio ( JSContext * cx , JS : : HandleObject global ) { <nl> JS_FS_END <nl> } ; <nl> <nl> - static JSFunctionSpec st_funcs [ ] = { <nl> + static JSFunctionSpec st_funcs [ ] = <nl> + { <nl> JS_FN ( " connect " , js_cocos2dx_SocketIO_connect , 1 , JSPROP_PERMANENT | JSPROP_ENUMERATE ) , <nl> JS_FN ( " close " , js_cocos2dx_SocketIO_close , 0 , JSPROP_PERMANENT | JSPROP_ENUMERATE ) , <nl> JS_FS_END <nl> void register_jsb_socketio ( JSContext * cx , JS : : HandleObject global ) { <nl> js_cocos2dx_SocketIO_constructor , 0 , / / constructor <nl> nullptr , <nl> funcs , <nl> - nullptr , / / no static properties <nl> + properties , <nl> st_funcs ) ; <nl> <nl> - JSObject * jsclassObj = anonEvaluate ( cx , global , " ( function ( ) { return SocketIO ; } ) ( ) " ) . toObjectOrNull ( ) ; <nl> - <nl> + anonEvaluate ( cx , global , " ( function ( ) { return SocketIO ; } ) ( ) " ) . toObjectOrNull ( ) ; <nl> } <nl> <nl> mmm a / cocos / scripting / js - bindings / proj . ios_mac / cocos2d_js_bindings . xcodeproj / project . pbxproj <nl> ppp b / cocos / scripting / js - bindings / proj . ios_mac / cocos2d_js_bindings . xcodeproj / project . pbxproj <nl> <nl> 1A119E5418BDF19200352BAA / * js_bindings_ccbreader . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; path = js_bindings_ccbreader . h ; sourceTree = " < group > " ; } ; <nl> 1A119E5718BDF19200352BAA / * jsb_cocos2dx_studio_manual . cpp * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . cpp . cpp ; path = jsb_cocos2dx_studio_manual . cpp ; sourceTree = " < group > " ; } ; <nl> 1A119E5818BDF19200352BAA / * jsb_cocos2dx_studio_manual . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; path = jsb_cocos2dx_studio_manual . h ; sourceTree = " < group > " ; } ; <nl> - 1A119E5A18BDF19200352BAA / * Android . mk * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = text ; path = Android . mk ; sourceTree = " < group > " ; } ; <nl> 1A119E5B18BDF19200352BAA / * jsb_cocos2dx_extension_manual . cpp * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . cpp . cpp ; path = jsb_cocos2dx_extension_manual . cpp ; sourceTree = " < group > " ; } ; <nl> 1A119E5C18BDF19200352BAA / * jsb_cocos2dx_extension_manual . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; path = jsb_cocos2dx_extension_manual . h ; sourceTree = " < group > " ; } ; <nl> 1A119E6118BDF19200352BAA / * js_bindings_config . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; path = js_bindings_config . h ; sourceTree = " < group > " ; } ; <nl> <nl> 1A119E7318BDF19200352BAA / * js_bindings_system_functions_registration . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; path = js_bindings_system_functions_registration . h ; sourceTree = " < group > " ; } ; <nl> 1A119E7418BDF19200352BAA / * js_bindings_system_registration . cpp * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . cpp . cpp ; path = js_bindings_system_registration . cpp ; sourceTree = " < group > " ; } ; <nl> 1A119E7518BDF19200352BAA / * js_bindings_system_registration . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; path = js_bindings_system_registration . h ; sourceTree = " < group > " ; } ; <nl> - 1A119E7718BDF19200352BAA / * Android . mk * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = text ; path = Android . mk ; sourceTree = " < group > " ; } ; <nl> 1A119E7818BDF19200352BAA / * jsb_websocket . cpp * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . cpp . cpp ; path = jsb_websocket . cpp ; sourceTree = " < group > " ; } ; <nl> 1A119E7918BDF19200352BAA / * jsb_websocket . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; path = jsb_websocket . h ; sourceTree = " < group > " ; } ; <nl> 1A119E7A18BDF19200352BAA / * XMLHTTPRequest . cpp * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . cpp . cpp ; path = XMLHTTPRequest . cpp ; sourceTree = " < group > " ; } ; <nl> <nl> 1A119E5918BDF19200352BAA / * extension * / = { <nl> isa = PBXGroup ; <nl> children = ( <nl> - 1A119E5A18BDF19200352BAA / * Android . mk * / , <nl> 1A119E5B18BDF19200352BAA / * jsb_cocos2dx_extension_manual . cpp * / , <nl> 1A119E5C18BDF19200352BAA / * jsb_cocos2dx_extension_manual . h * / , <nl> ) ; <nl> <nl> 1A119E7618BDF19200352BAA / * network * / = { <nl> isa = PBXGroup ; <nl> children = ( <nl> - 1A119E7718BDF19200352BAA / * Android . mk * / , <nl> 83A5661718DA878400FC31A0 / * jsb_socketio . cpp * / , <nl> 83A5661818DA878400FC31A0 / * jsb_socketio . h * / , <nl> 1A119E7818BDF19200352BAA / * jsb_websocket . cpp * / , <nl>
Merge pull request from pandamicro / v3
cocos2d/cocos2d-x
1471936c2fe5f29154b2c8a7fe7e91018d2bc343
2015-08-10T05:32:09Z
mmm a / modules / dnn / perf / perf_convolution . cpp <nl> ppp b / modules / dnn / perf / perf_convolution . cpp <nl> <nl> # include " perf_precomp . hpp " <nl> # include < opencv2 / dnn / shape_utils . hpp > <nl> <nl> - namespace cvtest <nl> + namespace <nl> { <nl> <nl> - using std : : tr1 : : tuple ; <nl> - using std : : tr1 : : get ; <nl> - using std : : tr1 : : make_tuple ; <nl> - using std : : make_pair ; <nl> - using namespace perf ; <nl> - using namespace testing ; <nl> - using namespace cv ; <nl> - using namespace cv : : dnn ; <nl> - <nl> enum { STRIDE_OFF = 1 , STRIDE_ON = 2 } ; <nl> CV_ENUM ( StrideSize , STRIDE_OFF , STRIDE_ON ) ; <nl> <nl> enum { GROUP_OFF = 1 , GROUP_2 = 2 } ; <nl> CV_ENUM ( GroupSize , GROUP_OFF , GROUP_2 ) ; <nl> <nl> - / / Squared Size <nl> - # define SSZ ( n ) cv : : Size ( n , n ) <nl> - <nl> typedef std : : pair < MatShape , int > InpShapeNumOut ; <nl> typedef tuple < Size , InpShapeNumOut , GroupSize , StrideSize > ConvParam ; / / kernel_size , inp shape , groups , stride <nl> typedef TestBaseWithParam < ConvParam > ConvolutionPerfTest ; <nl> PERF_TEST_P ( ConvolutionPerfTest , perf , Combine ( <nl> Ptr < Layer > layer = cv : : dnn : : LayerFactory : : createLayerInstance ( " Convolution " , lp ) ; <nl> std : : vector < MatShape > inputShapes ( 1 , shape ( inpBlob ) ) , outShapes , internals ; <nl> layer - > getMemoryShapes ( inputShapes , 0 , outShapes , internals ) ; <nl> - for ( int i = 0 ; i < outShapes . size ( ) ; i + + ) <nl> + for ( size_t i = 0 ; i < outShapes . size ( ) ; i + + ) <nl> { <nl> outBlobs . push_back ( Mat ( outShapes [ i ] , CV_32F ) ) ; <nl> } <nl> - for ( int i = 0 ; i < internals . size ( ) ; i + + ) <nl> + for ( size_t i = 0 ; i < internals . size ( ) ; i + + ) <nl> { <nl> internalBlobs . push_back ( Mat ( ) ) ; <nl> if ( total ( internals [ i ] ) ) <nl> PERF_TEST_P ( ConvolutionPerfTest , perf , Combine ( <nl> Mat outBlob2D = outBlobs [ 0 ] . reshape ( 1 , outBlobs [ 0 ] . size [ 0 ] ) ; <nl> declare . in ( inpBlob2D , wgtBlob2D , WARMUP_RNG ) . out ( outBlob2D ) . tbb_threads ( cv : : getNumThreads ( ) ) ; <nl> <nl> - TEST_CYCLE_N ( 10 ) <nl> - { <nl> + layer - > forward ( inpBlobs , outBlobs , internalBlobs ) ; / / / warmup <nl> + <nl> + PERF_SAMPLE_BEGIN ( ) <nl> layer - > forward ( inpBlobs , outBlobs , internalBlobs ) ; <nl> - } <nl> + PERF_SAMPLE_END ( ) <nl> <nl> SANITY_CHECK_NOTHING ( ) ; <nl> } <nl> <nl> - } <nl> + } / / namespace <nl> deleted file mode 100644 <nl> index 84e6305f52a . . 00000000000 <nl> mmm a / modules / dnn / perf / perf_halide_net . cpp <nl> ppp / dev / null <nl> <nl> - / / This file is part of OpenCV project . <nl> - / / It is subject to the license terms in the LICENSE file found in the top - level directory <nl> - / / of this distribution and at http : / / opencv . org / license . html . <nl> - / / <nl> - / / Copyright ( C ) 2017 , Intel Corporation , all rights reserved . <nl> - / / Third party copyrights are property of their respective owners . <nl> - <nl> - # include " perf_precomp . hpp " <nl> - <nl> - namespace cvtest <nl> - { <nl> - <nl> - # ifdef HAVE_HALIDE <nl> - using namespace cv ; <nl> - using namespace dnn ; <nl> - <nl> - static void loadNet ( std : : string weights , std : : string proto , std : : string scheduler , <nl> - int inWidth , int inHeight , const std : : string & outputLayer , <nl> - const std : : string & framework , int targetId , Net * net ) <nl> - { <nl> - Mat input ( inHeight , inWidth , CV_32FC3 ) ; <nl> - randu ( input , 0 . 0f , 1 . 0f ) ; <nl> - <nl> - weights = findDataFile ( weights , false ) ; <nl> - if ( ! proto . empty ( ) ) <nl> - proto = findDataFile ( proto , false ) ; <nl> - if ( ! scheduler . empty ( ) ) <nl> - scheduler = findDataFile ( scheduler , false ) ; <nl> - if ( framework = = " caffe " ) <nl> - { <nl> - * net = cv : : dnn : : readNetFromCaffe ( proto , weights ) ; <nl> - } <nl> - else if ( framework = = " torch " ) <nl> - { <nl> - * net = cv : : dnn : : readNetFromTorch ( weights ) ; <nl> - } <nl> - else if ( framework = = " tensorflow " ) <nl> - { <nl> - * net = cv : : dnn : : readNetFromTensorflow ( weights ) ; <nl> - } <nl> - else <nl> - CV_Error ( Error : : StsNotImplemented , " Unknown framework " + framework ) ; <nl> - <nl> - net - > setInput ( blobFromImage ( input , 1 . 0 , Size ( ) , Scalar ( ) , false ) ) ; <nl> - net - > setPreferableBackend ( DNN_BACKEND_HALIDE ) ; <nl> - net - > setPreferableTarget ( targetId ) ; <nl> - net - > setHalideScheduler ( scheduler ) ; <nl> - net - > forward ( outputLayer ) ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / CPU target <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - PERF_TEST ( GoogLeNet , HalidePerfTest ) <nl> - { <nl> - Net net ; <nl> - loadNet ( " dnn / bvlc_googlenet . caffemodel " , " dnn / bvlc_googlenet . prototxt " , <nl> - " " , 224 , 224 , " prob " , " caffe " , DNN_TARGET_CPU , & net ) ; <nl> - TEST_CYCLE ( ) net . forward ( ) ; <nl> - SANITY_CHECK_NOTHING ( ) ; <nl> - } <nl> - <nl> - PERF_TEST ( AlexNet , HalidePerfTest ) <nl> - { <nl> - Net net ; <nl> - loadNet ( " dnn / bvlc_alexnet . caffemodel " , " dnn / bvlc_alexnet . prototxt " , <nl> - " dnn / halide_scheduler_alexnet . yml " , 227 , 227 , " prob " , " caffe " , <nl> - DNN_TARGET_CPU , & net ) ; <nl> - TEST_CYCLE ( ) net . forward ( ) ; <nl> - SANITY_CHECK_NOTHING ( ) ; <nl> - } <nl> - <nl> - PERF_TEST ( ResNet50 , HalidePerfTest ) <nl> - { <nl> - Net net ; <nl> - loadNet ( " dnn / ResNet - 50 - model . caffemodel " , " dnn / ResNet - 50 - deploy . prototxt " , <nl> - " dnn / halide_scheduler_resnet_50 . yml " , 224 , 224 , " prob " , " caffe " , <nl> - DNN_TARGET_CPU , & net ) ; <nl> - TEST_CYCLE ( ) net . forward ( ) ; <nl> - SANITY_CHECK_NOTHING ( ) ; <nl> - } <nl> - <nl> - PERF_TEST ( SqueezeNet_v1_1 , HalidePerfTest ) <nl> - { <nl> - Net net ; <nl> - loadNet ( " dnn / squeezenet_v1 . 1 . caffemodel " , " dnn / squeezenet_v1 . 1 . prototxt " , <nl> - " dnn / halide_scheduler_squeezenet_v1_1 . yml " , 227 , 227 , " prob " , <nl> - " caffe " , DNN_TARGET_CPU , & net ) ; <nl> - TEST_CYCLE ( ) net . forward ( ) ; <nl> - SANITY_CHECK_NOTHING ( ) ; <nl> - } <nl> - <nl> - PERF_TEST ( Inception_5h , HalidePerfTest ) <nl> - { <nl> - Net net ; <nl> - loadNet ( " dnn / tensorflow_inception_graph . pb " , " " , <nl> - " dnn / halide_scheduler_inception_5h . yml " , <nl> - 224 , 224 , " softmax2 " , " tensorflow " , DNN_TARGET_CPU , & net ) ; <nl> - TEST_CYCLE ( ) net . forward ( " softmax2 " ) ; <nl> - SANITY_CHECK_NOTHING ( ) ; <nl> - } <nl> - <nl> - PERF_TEST ( ENet , HalidePerfTest ) <nl> - { <nl> - Net net ; <nl> - loadNet ( " dnn / Enet - model - best . net " , " " , " dnn / halide_scheduler_enet . yml " , <nl> - 512 , 256 , " l367_Deconvolution " , " torch " , DNN_TARGET_CPU , & net ) ; <nl> - TEST_CYCLE ( ) net . forward ( ) ; <nl> - SANITY_CHECK_NOTHING ( ) ; <nl> - } <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / OpenCL target <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - PERF_TEST ( GoogLeNet_opencl , HalidePerfTest ) <nl> - { <nl> - Net net ; <nl> - loadNet ( " dnn / bvlc_googlenet . caffemodel " , " dnn / bvlc_googlenet . prototxt " , <nl> - " " , 227 , 227 , " prob " , " caffe " , DNN_TARGET_OPENCL , & net ) ; <nl> - TEST_CYCLE ( ) net . forward ( ) ; <nl> - SANITY_CHECK_NOTHING ( ) ; <nl> - } <nl> - <nl> - PERF_TEST ( AlexNet_opencl , HalidePerfTest ) <nl> - { <nl> - Net net ; <nl> - loadNet ( " dnn / bvlc_alexnet . caffemodel " , " dnn / bvlc_alexnet . prototxt " , <nl> - " dnn / halide_scheduler_opencl_alexnet . yml " , 227 , 227 , " prob " , " caffe " , <nl> - DNN_TARGET_OPENCL , & net ) ; <nl> - TEST_CYCLE ( ) net . forward ( ) ; <nl> - SANITY_CHECK_NOTHING ( ) ; <nl> - } <nl> - <nl> - PERF_TEST ( ResNet50_opencl , HalidePerfTest ) <nl> - { <nl> - Net net ; <nl> - loadNet ( " dnn / ResNet - 50 - model . caffemodel " , " dnn / ResNet - 50 - deploy . prototxt " , <nl> - " dnn / halide_scheduler_opencl_resnet_50 . yml " , 224 , 224 , " prob " , " caffe " , <nl> - DNN_TARGET_OPENCL , & net ) ; <nl> - TEST_CYCLE ( ) net . forward ( ) ; <nl> - SANITY_CHECK_NOTHING ( ) ; <nl> - } <nl> - <nl> - <nl> - PERF_TEST ( SqueezeNet_v1_1_opencl , HalidePerfTest ) <nl> - { <nl> - Net net ; <nl> - loadNet ( " dnn / squeezenet_v1 . 1 . caffemodel " , " dnn / squeezenet_v1 . 1 . prototxt " , <nl> - " dnn / halide_scheduler_opencl_squeezenet_v1_1 . yml " , 227 , 227 , " prob " , <nl> - " caffe " , DNN_TARGET_OPENCL , & net ) ; <nl> - TEST_CYCLE ( ) net . forward ( ) ; <nl> - SANITY_CHECK_NOTHING ( ) ; <nl> - } <nl> - <nl> - PERF_TEST ( Inception_5h_opencl , HalidePerfTest ) <nl> - { <nl> - Net net ; <nl> - loadNet ( " dnn / tensorflow_inception_graph . pb " , " " , <nl> - " dnn / halide_scheduler_opencl_inception_5h . yml " , <nl> - 224 , 224 , " softmax2 " , " tensorflow " , DNN_TARGET_OPENCL , & net ) ; <nl> - TEST_CYCLE ( ) net . forward ( " softmax2 " ) ; <nl> - SANITY_CHECK_NOTHING ( ) ; <nl> - } <nl> - <nl> - PERF_TEST ( ENet_opencl , HalidePerfTest ) <nl> - { <nl> - Net net ; <nl> - loadNet ( " dnn / Enet - model - best . net " , " " , " dnn / halide_scheduler_opencl_enet . yml " , <nl> - 512 , 256 , " l367_Deconvolution " , " torch " , DNN_TARGET_OPENCL , & net ) ; <nl> - TEST_CYCLE ( ) net . forward ( ) ; <nl> - SANITY_CHECK_NOTHING ( ) ; <nl> - } <nl> - # endif / / HAVE_HALIDE <nl> - <nl> - } / / namespace cvtest <nl> new file mode 100644 <nl> index 00000000000 . . 55f5ce69e67 <nl> mmm / dev / null <nl> ppp b / modules / dnn / perf / perf_net . cpp <nl> <nl> + / / This file is part of OpenCV project . <nl> + / / It is subject to the license terms in the LICENSE file found in the top - level directory <nl> + / / of this distribution and at http : / / opencv . org / license . html . <nl> + / / <nl> + / / Copyright ( C ) 2017 , Intel Corporation , all rights reserved . <nl> + / / Third party copyrights are property of their respective owners . <nl> + <nl> + # include " perf_precomp . hpp " <nl> + # include " opencv2 / core / ocl . hpp " <nl> + <nl> + # include " opencv2 / dnn / shape_utils . hpp " <nl> + <nl> + namespace <nl> + { <nl> + <nl> + # ifdef HAVE_HALIDE <nl> + # define TEST_DNN_BACKEND DNN_BACKEND_DEFAULT , DNN_BACKEND_HALIDE <nl> + # else <nl> + # define TEST_DNN_BACKEND DNN_BACKEND_DEFAULT <nl> + # endif <nl> + # define TEST_DNN_TARGET DNN_TARGET_CPU , DNN_TARGET_OPENCL <nl> + <nl> + CV_ENUM ( DNNBackend , DNN_BACKEND_DEFAULT , DNN_BACKEND_HALIDE ) <nl> + CV_ENUM ( DNNTarget , DNN_TARGET_CPU , DNN_TARGET_OPENCL ) <nl> + <nl> + class DNNTestNetwork : public : : perf : : TestBaseWithParam < tuple < DNNBackend , DNNTarget > > <nl> + { <nl> + public : <nl> + dnn : : Backend backend ; <nl> + dnn : : Target target ; <nl> + <nl> + dnn : : Net net ; <nl> + <nl> + void processNet ( std : : string weights , std : : string proto , std : : string halide_scheduler , <nl> + int inWidth , int inHeight , const std : : string & outputLayer , <nl> + const std : : string & framework ) <nl> + { <nl> + backend = ( dnn : : Backend ) ( int ) get < 0 > ( GetParam ( ) ) ; <nl> + target = ( dnn : : Target ) ( int ) get < 1 > ( GetParam ( ) ) ; <nl> + <nl> + if ( backend = = DNN_BACKEND_DEFAULT & & target = = DNN_TARGET_OPENCL ) <nl> + { <nl> + # if 0 / / defined ( HAVE_OPENCL ) <nl> + if ( ! cv : : ocl : : useOpenCL ( ) ) <nl> + # endif <nl> + { <nl> + throw : : SkipTestException ( " OpenCL is not available / disabled in OpenCV " ) ; <nl> + } <nl> + } <nl> + <nl> + Mat input ( inHeight , inWidth , CV_32FC3 ) ; <nl> + randu ( input , 0 . 0f , 1 . 0f ) ; <nl> + <nl> + <nl> + weights = findDataFile ( weights , false ) ; <nl> + if ( ! proto . empty ( ) ) <nl> + proto = findDataFile ( proto , false ) ; <nl> + if ( ! halide_scheduler . empty ( ) & & backend = = DNN_BACKEND_HALIDE ) <nl> + halide_scheduler = findDataFile ( std : : string ( " dnn / halide_scheduler_ " ) + ( target = = DNN_TARGET_OPENCL ? " opencl_ " : " " ) + halide_scheduler , true ) ; <nl> + if ( framework = = " caffe " ) <nl> + { <nl> + net = cv : : dnn : : readNetFromCaffe ( proto , weights ) ; <nl> + } <nl> + else if ( framework = = " torch " ) <nl> + { <nl> + net = cv : : dnn : : readNetFromTorch ( weights ) ; <nl> + } <nl> + else if ( framework = = " tensorflow " ) <nl> + { <nl> + net = cv : : dnn : : readNetFromTensorflow ( weights ) ; <nl> + } <nl> + else <nl> + CV_Error ( Error : : StsNotImplemented , " Unknown framework " + framework ) ; <nl> + <nl> + net . setInput ( blobFromImage ( input , 1 . 0 , Size ( ) , Scalar ( ) , false ) ) ; <nl> + net . setPreferableBackend ( backend ) ; <nl> + net . setPreferableTarget ( target ) ; <nl> + if ( backend = = DNN_BACKEND_HALIDE ) <nl> + { <nl> + net . setHalideScheduler ( halide_scheduler ) ; <nl> + } <nl> + <nl> + MatShape netInputShape = shape ( 1 , 3 , inHeight , inWidth ) ; <nl> + size_t weightsMemory = 0 , blobsMemory = 0 ; <nl> + net . getMemoryConsumption ( netInputShape , weightsMemory , blobsMemory ) ; <nl> + int64 flops = net . getFLOPS ( netInputShape ) ; <nl> + <nl> + net . forward ( outputLayer ) ; / / warmup <nl> + <nl> + std : : cout < < " Memory consumption : " < < std : : endl ; <nl> + std : : cout < < " Weights ( parameters ) : " < < divUp ( weightsMemory , 1u < < 20 ) < < " Mb " < < std : : endl ; <nl> + std : : cout < < " Blobs : " < < divUp ( blobsMemory , 1u < < 20 ) < < " Mb " < < std : : endl ; <nl> + std : : cout < < " Calculation complexity : " < < flops * 1e - 9 < < " GFlops " < < std : : endl ; <nl> + <nl> + PERF_SAMPLE_BEGIN ( ) <nl> + net . forward ( ) ; <nl> + PERF_SAMPLE_END ( ) <nl> + <nl> + SANITY_CHECK_NOTHING ( ) ; <nl> + } <nl> + } ; <nl> + <nl> + <nl> + PERF_TEST_P_ ( DNNTestNetwork , AlexNet ) <nl> + { <nl> + processNet ( " dnn / bvlc_alexnet . caffemodel " , " dnn / bvlc_alexnet . prototxt " , <nl> + " alexnet . yml " , 227 , 227 , " prob " , " caffe " ) ; <nl> + } <nl> + <nl> + PERF_TEST_P_ ( DNNTestNetwork , GoogLeNet ) <nl> + { <nl> + processNet ( " dnn / bvlc_googlenet . caffemodel " , " dnn / bvlc_googlenet . prototxt " , <nl> + " " , 224 , 224 , " prob " , " caffe " ) ; <nl> + } <nl> + <nl> + PERF_TEST_P_ ( DNNTestNetwork , ResNet50 ) <nl> + { <nl> + processNet ( " dnn / ResNet - 50 - model . caffemodel " , " dnn / ResNet - 50 - deploy . prototxt " , <nl> + " resnet_50 . yml " , 224 , 224 , " prob " , " caffe " ) ; <nl> + } <nl> + <nl> + PERF_TEST_P_ ( DNNTestNetwork , SqueezeNet_v1_1 ) <nl> + { <nl> + processNet ( " dnn / squeezenet_v1 . 1 . caffemodel " , " dnn / squeezenet_v1 . 1 . prototxt " , <nl> + " squeezenet_v1_1 . yml " , 227 , 227 , " prob " , " caffe " ) ; <nl> + } <nl> + <nl> + PERF_TEST_P_ ( DNNTestNetwork , Inception_5h ) <nl> + { <nl> + processNet ( " dnn / tensorflow_inception_graph . pb " , " " , <nl> + " inception_5h . yml " , <nl> + 224 , 224 , " softmax2 " , " tensorflow " ) ; <nl> + } <nl> + <nl> + PERF_TEST_P_ ( DNNTestNetwork , ENet ) <nl> + { <nl> + processNet ( " dnn / Enet - model - best . net " , " " , " enet . yml " , <nl> + 512 , 256 , " l367_Deconvolution " , " torch " ) ; <nl> + } <nl> + <nl> + <nl> + INSTANTIATE_TEST_CASE_P ( / * nothing * / , DNNTestNetwork , <nl> + testing : : Combine ( <nl> + : : testing : : Values ( TEST_DNN_BACKEND ) , <nl> + DNNTarget : : all ( ) <nl> + ) <nl> + ) ; <nl> + <nl> + } / / namespace <nl> mmm a / modules / dnn / perf / perf_precomp . hpp <nl> ppp b / modules / dnn / perf / perf_precomp . hpp <nl> <nl> - # ifdef __GNUC__ <nl> - # pragma GCC diagnostic ignored " - Wmissing - declarations " <nl> - # if defined __clang__ | | defined __APPLE__ <nl> - # pragma GCC diagnostic ignored " - Wmissing - prototypes " <nl> - # pragma GCC diagnostic ignored " - Wextra " <nl> - # endif <nl> - # endif <nl> - <nl> # ifndef __OPENCV_PERF_PRECOMP_HPP__ <nl> # define __OPENCV_PERF_PRECOMP_HPP__ <nl> <nl> <nl> # include < opencv2 / highgui . hpp > <nl> # include < opencv2 / dnn . hpp > <nl> <nl> + using namespace cvtest ; <nl> + using namespace perf ; <nl> + using namespace cv ; <nl> + using namespace dnn ; <nl> + <nl> # endif <nl> mmm a / modules / ts / include / opencv2 / ts . hpp <nl> ppp b / modules / ts / include / opencv2 / ts . hpp <nl> <nl> # define GTEST_USES_POSIX_RE 0 <nl> # endif <nl> <nl> - # define PARAM_TEST_CASE ( name , . . . ) struct name : testing : : TestWithParam < std : : tr1 : : tuple < __VA_ARGS__ > > <nl> - # define GET_PARAM ( k ) std : : tr1 : : get < k > ( GetParam ( ) ) <nl> + # define PARAM_TEST_CASE ( name , . . . ) struct name : testing : : TestWithParam < testing : : tuple < __VA_ARGS__ > > <nl> + # define GET_PARAM ( k ) testing : : get < k > ( GetParam ( ) ) <nl> <nl> namespace cvtest <nl> { <nl> using namespace cv ; <nl> using testing : : Values ; <nl> using testing : : Combine ; <nl> <nl> + / / Tuple stuff from Google Tests <nl> + using testing : : get ; <nl> + using testing : : make_tuple ; <nl> + using testing : : tuple ; <nl> + using testing : : tuple_size ; <nl> + using testing : : tuple_element ; <nl> + <nl> <nl> class SkipTestException : public cv : : Exception <nl> { <nl> mmm a / modules / ts / include / opencv2 / ts / cuda_perf . hpp <nl> ppp b / modules / ts / include / opencv2 / ts / cuda_perf . hpp <nl> namespace perf <nl> # define CUDA_CHANNELS_1_3_4 testing : : Values ( MatCn ( Gray ) , MatCn ( BGR ) , MatCn ( BGRA ) ) <nl> # define CUDA_CHANNELS_1_3 testing : : Values ( MatCn ( Gray ) , MatCn ( BGR ) ) <nl> <nl> - # define GET_PARAM ( k ) std : : tr1 : : get < k > ( GetParam ( ) ) <nl> + # define GET_PARAM ( k ) testing : : get < k > ( GetParam ( ) ) <nl> <nl> - # define DEF_PARAM_TEST ( name , . . . ) typedef : : perf : : TestBaseWithParam < std : : tr1 : : tuple < __VA_ARGS__ > > name <nl> + # define DEF_PARAM_TEST ( name , . . . ) typedef : : perf : : TestBaseWithParam < testing : : tuple < __VA_ARGS__ > > name <nl> # define DEF_PARAM_TEST_1 ( name , param_type ) typedef : : perf : : TestBaseWithParam < param_type > name <nl> <nl> DEF_PARAM_TEST_1 ( Sz , cv : : Size ) ; <nl> mmm a / modules / ts / include / opencv2 / ts / ocl_perf . hpp <nl> ppp b / modules / ts / include / opencv2 / ts / ocl_perf . hpp <nl> namespace ocl { <nl> <nl> using namespace perf ; <nl> <nl> - using std : : tr1 : : get ; <nl> - using std : : tr1 : : tuple ; <nl> - <nl> # define OCL_PERF_STRATEGY PERF_STRATEGY_SIMPLE <nl> <nl> # define OCL_PERF_TEST ( fixture , name ) SIMPLE_PERF_TEST ( fixture , name ) <nl> mmm a / modules / ts / include / opencv2 / ts / ocl_test . hpp <nl> ppp b / modules / ts / include / opencv2 / ts / ocl_test . hpp <nl> struct CV_EXPORTS TSTestWithParam : public TestUtils , public : : testing : : TestWith <nl> } ; <nl> <nl> # undef PARAM_TEST_CASE <nl> - # define PARAM_TEST_CASE ( name , . . . ) struct name : public : : cvtest : : ocl : : TSTestWithParam < std : : tr1 : : tuple < __VA_ARGS__ > > <nl> + # define PARAM_TEST_CASE ( name , . . . ) struct name : public : : cvtest : : ocl : : TSTestWithParam < testing : : tuple < __VA_ARGS__ > > <nl> <nl> # ifndef IMPLEMENT_PARAM_CLASS <nl> # define IMPLEMENT_PARAM_CLASS ( name , type ) \ <nl> mmm a / modules / ts / include / opencv2 / ts / ts_ext . hpp <nl> ppp b / modules / ts / include / opencv2 / ts / ts_ext . hpp <nl> namespace cvtest { <nl> void checkIppStatus ( ) ; <nl> } <nl> <nl> - # define CV_TEST_INIT \ <nl> + # define CV__TEST_INIT \ <nl> cv : : ipp : : setIppStatus ( 0 ) ; \ <nl> cv : : theRNG ( ) . state = cvtest : : param_seed ; <nl> - # define CV_TEST_CLEANUP : : cvtest : : checkIppStatus ( ) ; <nl> - # define CV_TEST_BODY_IMPL ( name ) \ <nl> + # define CV__TEST_CLEANUP : : cvtest : : checkIppStatus ( ) ; <nl> + # define CV__TEST_BODY_IMPL ( name ) \ <nl> { \ <nl> CV__TRACE_APP_FUNCTION_NAME ( name ) ; \ <nl> try { \ <nl> - CV_TEST_INIT \ <nl> + CV__TEST_INIT \ <nl> Body ( ) ; \ <nl> - CV_TEST_CLEANUP \ <nl> + CV__TEST_CLEANUP \ <nl> } \ <nl> catch ( cvtest : : SkipTestException & e ) \ <nl> { \ <nl> void checkIppStatus ( ) ; <nl> : : testing : : Test : : TearDownTestCase , \ <nl> new : : testing : : internal : : TestFactoryImpl < \ <nl> GTEST_TEST_CLASS_NAME_ ( test_case_name , test_name ) > ) ; \ <nl> - void GTEST_TEST_CLASS_NAME_ ( test_case_name , test_name ) : : TestBody ( ) CV_TEST_BODY_IMPL ( # test_case_name " _ " # test_name ) \ <nl> + void GTEST_TEST_CLASS_NAME_ ( test_case_name , test_name ) : : TestBody ( ) CV__TEST_BODY_IMPL ( # test_case_name " _ " # test_name ) \ <nl> void GTEST_TEST_CLASS_NAME_ ( test_case_name , test_name ) : : Body ( ) <nl> <nl> # undef TEST_F <nl> void checkIppStatus ( ) ; <nl> test_fixture : : TearDownTestCase , \ <nl> new : : testing : : internal : : TestFactoryImpl < \ <nl> GTEST_TEST_CLASS_NAME_ ( test_fixture , test_name ) > ) ; \ <nl> - void GTEST_TEST_CLASS_NAME_ ( test_fixture , test_name ) : : TestBody ( ) CV_TEST_BODY_IMPL ( # test_fixture " _ " # test_name ) \ <nl> + void GTEST_TEST_CLASS_NAME_ ( test_fixture , test_name ) : : TestBody ( ) CV__TEST_BODY_IMPL ( # test_fixture " _ " # test_name ) \ <nl> void GTEST_TEST_CLASS_NAME_ ( test_fixture , test_name ) : : Body ( ) <nl> <nl> - # undef TEST_P <nl> - # define TEST_P ( test_case_name , test_name ) \ <nl> + / / Don ' t use directly <nl> + # define CV__TEST_P ( test_case_name , test_name , bodyMethodName , BODY_IMPL / * ( name_str ) * / ) \ <nl> class GTEST_TEST_CLASS_NAME_ ( test_case_name , test_name ) \ <nl> : public test_case_name { \ <nl> public : \ <nl> GTEST_TEST_CLASS_NAME_ ( test_case_name , test_name ) ( ) { } \ <nl> private : \ <nl> - virtual void Body ( ) ; \ <nl> + virtual void bodyMethodName ( ) ; \ <nl> virtual void TestBody ( ) ; \ <nl> static int AddToRegistry ( ) { \ <nl> : : testing : : UnitTest : : GetInstance ( ) - > parameterized_test_registry ( ) . \ <nl> void checkIppStatus ( ) ; <nl> int GTEST_TEST_CLASS_NAME_ ( test_case_name , \ <nl> test_name ) : : gtest_registering_dummy_ = \ <nl> GTEST_TEST_CLASS_NAME_ ( test_case_name , test_name ) : : AddToRegistry ( ) ; \ <nl> - void GTEST_TEST_CLASS_NAME_ ( test_case_name , test_name ) : : TestBody ( ) CV_TEST_BODY_IMPL ( # test_case_name " _ " # test_name ) \ <nl> - void GTEST_TEST_CLASS_NAME_ ( test_case_name , test_name ) : : Body ( ) <nl> + void GTEST_TEST_CLASS_NAME_ ( test_case_name , test_name ) : : TestBody ( ) BODY_IMPL ( # test_case_name " _ " # test_name ) \ <nl> + void GTEST_TEST_CLASS_NAME_ ( test_case_name , test_name ) : : bodyMethodName ( ) <nl> + <nl> + # undef TEST_P <nl> + # define TEST_P ( test_case_name , test_name ) CV__TEST_P ( test_case_name , test_name , Body , CV__TEST_BODY_IMPL ) <nl> <nl> # endif / / OPENCV_TS_EXT_HPP <nl> mmm a / modules / ts / include / opencv2 / ts / ts_perf . hpp <nl> ppp b / modules / ts / include / opencv2 / ts / ts_perf . hpp <nl> <nl> <nl> / / declare major namespaces to avoid errors on unknown namespace <nl> namespace cv { namespace cuda { } namespace ocl { } } <nl> + namespace cvtest { } <nl> <nl> namespace perf <nl> { <nl> + <nl> + / / Tuple stuff from Google Tests <nl> + using testing : : get ; <nl> + using testing : : make_tuple ; <nl> + using testing : : tuple ; <nl> + using testing : : tuple_size ; <nl> + using testing : : tuple_element ; <nl> + <nl> class TestBase ; <nl> <nl> / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ <nl> * Predefined typical frame sizes and typical test parameters * <nl> \ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> - const cv : : Size szQVGA = cv : : Size ( 320 , 240 ) ; <nl> - const cv : : Size szVGA = cv : : Size ( 640 , 480 ) ; <nl> - const cv : : Size szSVGA = cv : : Size ( 800 , 600 ) ; <nl> - const cv : : Size szXGA = cv : : Size ( 1024 , 768 ) ; <nl> - const cv : : Size szSXGA = cv : : Size ( 1280 , 1024 ) ; <nl> - const cv : : Size szWQHD = cv : : Size ( 2560 , 1440 ) ; <nl> - <nl> - const cv : : Size sznHD = cv : : Size ( 640 , 360 ) ; <nl> - const cv : : Size szqHD = cv : : Size ( 960 , 540 ) ; <nl> - const cv : : Size sz240p = szQVGA ; <nl> - const cv : : Size sz720p = cv : : Size ( 1280 , 720 ) ; <nl> - const cv : : Size sz1080p = cv : : Size ( 1920 , 1080 ) ; <nl> - const cv : : Size sz1440p = szWQHD ; <nl> - const cv : : Size sz2160p = cv : : Size ( 3840 , 2160 ) ; / / UHDTV1 4K <nl> - const cv : : Size sz4320p = cv : : Size ( 7680 , 4320 ) ; / / UHDTV2 8K <nl> - <nl> - const cv : : Size sz3MP = cv : : Size ( 2048 , 1536 ) ; <nl> - const cv : : Size sz5MP = cv : : Size ( 2592 , 1944 ) ; <nl> - const cv : : Size sz2K = cv : : Size ( 2048 , 2048 ) ; <nl> - <nl> - const cv : : Size szODD = cv : : Size ( 127 , 61 ) ; <nl> - <nl> - const cv : : Size szSmall24 = cv : : Size ( 24 , 24 ) ; <nl> - const cv : : Size szSmall32 = cv : : Size ( 32 , 32 ) ; <nl> - const cv : : Size szSmall64 = cv : : Size ( 64 , 64 ) ; <nl> - const cv : : Size szSmall128 = cv : : Size ( 128 , 128 ) ; <nl> + const static cv : : Size szQVGA = cv : : Size ( 320 , 240 ) ; <nl> + const static cv : : Size szVGA = cv : : Size ( 640 , 480 ) ; <nl> + const static cv : : Size szSVGA = cv : : Size ( 800 , 600 ) ; <nl> + const static cv : : Size szXGA = cv : : Size ( 1024 , 768 ) ; <nl> + const static cv : : Size szSXGA = cv : : Size ( 1280 , 1024 ) ; <nl> + const static cv : : Size szWQHD = cv : : Size ( 2560 , 1440 ) ; <nl> + <nl> + const static cv : : Size sznHD = cv : : Size ( 640 , 360 ) ; <nl> + const static cv : : Size szqHD = cv : : Size ( 960 , 540 ) ; <nl> + const static cv : : Size sz240p = szQVGA ; <nl> + const static cv : : Size sz720p = cv : : Size ( 1280 , 720 ) ; <nl> + const static cv : : Size sz1080p = cv : : Size ( 1920 , 1080 ) ; <nl> + const static cv : : Size sz1440p = szWQHD ; <nl> + const static cv : : Size sz2160p = cv : : Size ( 3840 , 2160 ) ; / / UHDTV1 4K <nl> + const static cv : : Size sz4320p = cv : : Size ( 7680 , 4320 ) ; / / UHDTV2 8K <nl> + <nl> + const static cv : : Size sz3MP = cv : : Size ( 2048 , 1536 ) ; <nl> + const static cv : : Size sz5MP = cv : : Size ( 2592 , 1944 ) ; <nl> + const static cv : : Size sz2K = cv : : Size ( 2048 , 2048 ) ; <nl> + <nl> + const static cv : : Size szODD = cv : : Size ( 127 , 61 ) ; <nl> + <nl> + const static cv : : Size szSmall24 = cv : : Size ( 24 , 24 ) ; <nl> + const static cv : : Size szSmall32 = cv : : Size ( 32 , 32 ) ; <nl> + const static cv : : Size szSmall64 = cv : : Size ( 64 , 64 ) ; <nl> + const static cv : : Size szSmall128 = cv : : Size ( 128 , 128 ) ; <nl> <nl> # define SZ_ALL_VGA : : testing : : Values ( : : perf : : szQVGA , : : perf : : szVGA , : : perf : : szSVGA ) <nl> # define SZ_ALL_GA : : testing : : Values ( : : perf : : szQVGA , : : perf : : szVGA , : : perf : : szSVGA , : : perf : : szXGA , : : perf : : szSXGA ) <nl> class CV_EXPORTS TestBase : public : : testing : : Test <nl> <nl> template < typename T > class TestBaseWithParam : public TestBase , public : : testing : : WithParamInterface < T > { } ; <nl> <nl> - typedef std : : tr1 : : tuple < cv : : Size , MatType > Size_MatType_t ; <nl> + typedef tuple < cv : : Size , MatType > Size_MatType_t ; <nl> typedef TestBaseWithParam < Size_MatType_t > Size_MatType ; <nl> <nl> / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ <nl> CV_EXPORTS void PrintTo ( const Size & sz , : : std : : ostream * os ) ; <nl> / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ <nl> * Macro definitions for performance tests * <nl> \ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> + <nl> + # define CV__PERF_TEST_BODY_IMPL ( name ) \ <nl> + { \ <nl> + CV__TRACE_APP_FUNCTION_NAME ( " PERF_TEST : " name ) ; \ <nl> + RunPerfTestBody ( ) ; \ <nl> + } <nl> + <nl> # define PERF_PROXY_NAMESPACE_NAME_ ( test_case_name , test_name ) \ <nl> test_case_name # # _ # # test_name # # _perf_namespace_proxy <nl> <nl> CV_EXPORTS void PrintTo ( const Size & sz , : : std : : ostream * os ) ; <nl> protected : \ <nl> virtual void PerfTestBody ( ) ; \ <nl> } ; \ <nl> - TEST_F ( test_case_name , test_name ) { CV_TRACE_REGION ( " PERF_TEST : " # test_case_name " _ " # test_name ) ; RunPerfTestBody ( ) ; } \ <nl> + TEST_F ( test_case_name , test_name ) { CV__PERF_TEST_BODY_IMPL ( # test_case_name " _ " # test_name ) ; } \ <nl> } \ <nl> void PERF_PROXY_NAMESPACE_NAME_ ( test_case_name , test_name ) : : test_case_name : : PerfTestBody ( ) <nl> <nl> CV_EXPORTS void PrintTo ( const Size & sz , : : std : : ostream * os ) ; <nl> protected : \ <nl> virtual void PerfTestBody ( ) ; \ <nl> } ; \ <nl> - TEST_F ( fixture , testname ) { CV_TRACE_REGION ( " PERF_TEST : " # fixture " _ " # testname ) ; RunPerfTestBody ( ) ; } \ <nl> + TEST_F ( fixture , testname ) { CV__PERF_TEST_BODY_IMPL ( # fixture " _ " # testname ) ; } \ <nl> } \ <nl> void PERF_PROXY_NAMESPACE_NAME_ ( fixture , testname ) : : fixture : : PerfTestBody ( ) <nl> <nl> / / Defines a parametrized performance test . <nl> / / <nl> + / / @ Note PERF_TEST_P ( ) below violates behavior of original Google Tests - there is no tests instantiation in original TEST_P ( ) <nl> + / / This macro is intended for usage with separate INSTANTIATE_TEST_CASE_P macro <nl> + # define PERF_TEST_P_ ( test_case_name , test_name ) CV__TEST_P ( test_case_name , test_name , PerfTestBody , CV__PERF_TEST_BODY_IMPL ) <nl> + <nl> + / / Defines a parametrized performance test . <nl> + / / <nl> + / / @ Note Original TEST_P ( ) macro doesn ' t instantiate tests with parameters . To keep original usage use PERF_TEST_P_ ( ) macro <nl> + / / <nl> / / The first parameter is the name of the test fixture class , which <nl> / / also doubles as the test case name . The second parameter is the <nl> / / name of the test within the test case . <nl> CV_EXPORTS void PrintTo ( const Size & sz , : : std : : ostream * os ) ; <nl> protected : \ <nl> virtual void PerfTestBody ( ) ; \ <nl> } ; \ <nl> - TEST_P ( fixture # # _ # # name , name / * perf * / ) { CV_TRACE_REGION ( " PERF_TEST : " # fixture " _ " # name ) ; RunPerfTestBody ( ) ; } \ <nl> + CV__TEST_P ( fixture # # _ # # name , name , PerfTestBodyDummy , CV__PERF_TEST_BODY_IMPL ) { } \ <nl> INSTANTIATE_TEST_CASE_P ( / * none * / , fixture # # _ # # name , params ) ; \ <nl> void fixture # # _ # # name : : PerfTestBody ( ) <nl> <nl>
Merge pull request from alalek : dnn_perf_net
opencv/opencv
22467599c468d260564c78d9e2a3a9b861689752
2017-09-28T13:44:24Z
mmm a / cocos / audio / win32 / AudioEngine - win32 . cpp <nl> ppp b / cocos / audio / win32 / AudioEngine - win32 . cpp <nl> bool AudioEngineImpl : : init ( ) <nl> s_ALDevice = alcOpenDevice ( nullptr ) ; <nl> <nl> if ( s_ALDevice ) { <nl> - auto alError = alGetError ( ) ; <nl> + alGetError ( ) ; <nl> s_ALContext = alcCreateContext ( s_ALDevice , nullptr ) ; <nl> alcMakeContextCurrent ( s_ALContext ) ; <nl> <nl> alGenSources ( MAX_AUDIOINSTANCES , _alSources ) ; <nl> - alError = alGetError ( ) ; <nl> + auto alError = alGetError ( ) ; <nl> if ( alError ! = AL_NO_ERROR ) <nl> { <nl> ALOGE ( " % s : generating sources failed ! error = % x \ n " , __FUNCTION__ , alError ) ; <nl>
Mitigate cppcheck message ( )
cocos2d/cocos2d-x
5d748f941b4ad862e2d90f9ce0af83f8f6f73e7d
2017-02-08T07:32:01Z
mmm a / scene / resources / visual_shader . cpp <nl> ppp b / scene / resources / visual_shader . cpp <nl> Error VisualShader : : _write_node ( Type type , StringBuilder & global_code , StringBui <nl> <nl> VisualShaderNodeUniform * uniform = ( VisualShaderNodeUniform * ) graph [ type ] . nodes [ from_node ] . node . ptr ( ) ; <nl> if ( uniform ) { <nl> - inputs [ i ] = " " ; <nl> - switch ( uniform - > get_uniform_type ( ) ) { <nl> - case VisualShaderNodeUniform : : UTYPE_CUBEMAP : <nl> - inputs [ i ] + = " cube_ " ; <nl> - break ; <nl> - case VisualShaderNodeUniform : : UTYPE_SAMPLER2D : <nl> - inputs [ i ] + = " s2d_ " ; <nl> - break ; <nl> - } <nl> - inputs [ i ] + = uniform - > get_uniform_name ( ) ; <nl> + inputs [ i ] = uniform - > get_uniform_name ( ) ; <nl> } else { <nl> inputs [ i ] = " " ; <nl> } <nl> void VisualShaderNodeUniform : : _bind_methods ( ) { <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " uniform_name " ) , " set_uniform_name " , " get_uniform_name " ) ; <nl> } <nl> <nl> - int VisualShaderNodeUniform : : get_uniform_type ( ) const { <nl> - return ( int ) uniform_type ; <nl> - } <nl> - <nl> - void VisualShaderNodeUniform : : set_uniform_type ( int p_type ) { <nl> - uniform_type = ( UniformType ) p_type ; <nl> - } <nl> - <nl> VisualShaderNodeUniform : : VisualShaderNodeUniform ( ) { <nl> - uniform_type = UTYPE_NONE ; <nl> } <nl> <nl> / / / / / / / / / / / / / / GroupBase <nl> mmm a / scene / resources / visual_shader . h <nl> ppp b / scene / resources / visual_shader . h <nl> class VisualShaderNodeOutput : public VisualShaderNode { <nl> class VisualShaderNodeUniform : public VisualShaderNode { <nl> GDCLASS ( VisualShaderNodeUniform , VisualShaderNode ) ; <nl> <nl> - public : <nl> - enum UniformType { <nl> - UTYPE_NONE , <nl> - UTYPE_CUBEMAP , <nl> - UTYPE_SAMPLER2D , <nl> - } ; <nl> - <nl> private : <nl> String uniform_name ; <nl> - UniformType uniform_type ; <nl> <nl> protected : <nl> static void _bind_methods ( ) ; <nl> class VisualShaderNodeUniform : public VisualShaderNode { <nl> void set_uniform_name ( const String & p_name ) ; <nl> String get_uniform_name ( ) const ; <nl> <nl> - int get_uniform_type ( ) const ; <nl> - void set_uniform_type ( int p_type ) ; <nl> - <nl> VisualShaderNodeUniform ( ) ; <nl> } ; <nl> <nl> mmm a / scene / resources / visual_shader_nodes . cpp <nl> ppp b / scene / resources / visual_shader_nodes . cpp <nl> String VisualShaderNodeTexture : : get_input_port_name ( int p_port ) const { <nl> case 1 : <nl> return " lod " ; <nl> case 2 : <nl> - return " sampler " ; <nl> + return " sampler2D " ; <nl> default : <nl> return " " ; <nl> } <nl> String VisualShaderNodeTexture : : generate_code ( Shader : : Mode p_mode , VisualShader : <nl> if ( source = = SOURCE_PORT ) { <nl> String id = p_input_vars [ 2 ] ; <nl> <nl> - VisualShaderNodeUniform : : UniformType utype = VisualShaderNodeUniform : : UTYPE_NONE ; <nl> - if ( id . begins_with ( " cube_ " ) ) { <nl> - utype = VisualShaderNodeUniform : : UTYPE_CUBEMAP ; <nl> - id = id . substr ( 5 ) ; <nl> - } else if ( id . begins_with ( " s2d_ " ) ) { <nl> - utype = VisualShaderNodeUniform : : UTYPE_SAMPLER2D ; <nl> - id = id . substr ( 4 ) ; <nl> - } <nl> - <nl> String code ; <nl> if ( id = = String ( ) ) { <nl> code + = " \ tvec4 " + id + " _tex_read = vec4 ( 0 . 0 ) ; \ n " ; <nl> } else { <nl> if ( p_input_vars [ 0 ] = = String ( ) ) { / / Use UV by default . <nl> - switch ( utype ) { <nl> - case VisualShaderNodeUniform : : UTYPE_CUBEMAP : <nl> - if ( p_input_vars [ 1 ] = = String ( ) ) { <nl> - code + = " \ tvec4 " + id + " _tex_read = texture ( " + id + " , vec3 ( UV , 0 . 0 ) ) ; \ n " ; <nl> - } else { <nl> - code + = " \ tvec4 " + id + " _tex_read = textureLod ( " + id + " , vec3 ( UV , 0 . 0 ) , " + p_input_vars [ 1 ] + " ) ; \ n " ; <nl> - } <nl> - break ; <nl> - case VisualShaderNodeUniform : : UTYPE_SAMPLER2D : <nl> - if ( p_input_vars [ 1 ] = = String ( ) ) { <nl> - code + = " \ tvec4 " + id + " _tex_read = texture ( " + id + " , UV . xy ) ; \ n " ; <nl> - } else { <nl> - code + = " \ tvec4 " + id + " _tex_read = textureLod ( " + id + " , UV . xy , " + p_input_vars [ 1 ] + " ) ; \ n " ; <nl> - } <nl> - break ; <nl> - default : <nl> - break ; <nl> + <nl> + if ( p_input_vars [ 1 ] = = String ( ) ) { <nl> + code + = " \ tvec4 " + id + " _tex_read = texture ( " + id + " , UV . xy ) ; \ n " ; <nl> + } else { <nl> + code + = " \ tvec4 " + id + " _tex_read = textureLod ( " + id + " , UV . xy , " + p_input_vars [ 1 ] + " ) ; \ n " ; <nl> } <nl> + <nl> } else if ( p_input_vars [ 1 ] = = String ( ) ) { <nl> / / no lod <nl> - <nl> - switch ( utype ) { <nl> - case VisualShaderNodeUniform : : UTYPE_CUBEMAP : <nl> - code + = " \ tvec4 " + id + " _tex_read = texture ( " + id + " , " + p_input_vars [ 0 ] + " ) ; \ n " ; <nl> - break ; <nl> - case VisualShaderNodeUniform : : UTYPE_SAMPLER2D : <nl> - code + = " \ tvec4 " + id + " _tex_read = texture ( " + id + " , " + p_input_vars [ 0 ] + " . xy ) ; \ n " ; <nl> - break ; <nl> - default : <nl> - break ; <nl> - } <nl> + code + = " \ tvec4 " + id + " _tex_read = texture ( " + id + " , " + p_input_vars [ 0 ] + " . xy ) ; \ n " ; <nl> } else { <nl> - switch ( utype ) { <nl> - case VisualShaderNodeUniform : : UTYPE_CUBEMAP : <nl> - code + = " \ tvec4 " + id + " _tex_read = textureLod ( " + id + " , " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ) ; \ n " ; <nl> - break ; <nl> - case VisualShaderNodeUniform : : UTYPE_SAMPLER2D : <nl> - code + = " \ tvec4 " + id + " _tex_read = textureLod ( " + id + " , " + p_input_vars [ 0 ] + " . xy , " + p_input_vars [ 1 ] + " ) ; \ n " ; <nl> - break ; <nl> - default : <nl> - break ; <nl> - } <nl> + code + = " \ tvec4 " + id + " _tex_read = textureLod ( " + id + " , " + p_input_vars [ 0 ] + " . xy , " + p_input_vars [ 1 ] + " ) ; \ n " ; <nl> } <nl> <nl> code + = " \ t " + p_output_vars [ 0 ] + " = " + id + " _tex_read . rgb ; \ n " ; <nl> String VisualShaderNodeCubeMap : : get_caption ( ) const { <nl> } <nl> <nl> int VisualShaderNodeCubeMap : : get_input_port_count ( ) const { <nl> - return 2 ; <nl> + return 3 ; <nl> } <nl> <nl> VisualShaderNodeCubeMap : : PortType VisualShaderNodeCubeMap : : get_input_port_type ( int p_port ) const { <nl> - return p_port = = 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR ; <nl> + switch ( p_port ) { <nl> + case 0 : <nl> + return PORT_TYPE_VECTOR ; <nl> + case 1 : <nl> + return PORT_TYPE_SCALAR ; <nl> + case 2 : <nl> + return PORT_TYPE_SAMPLER ; <nl> + default : <nl> + return PORT_TYPE_SCALAR ; <nl> + } <nl> } <nl> <nl> String VisualShaderNodeCubeMap : : get_input_port_name ( int p_port ) const { <nl> - return p_port = = 0 ? " uv " : " lod " ; <nl> + switch ( p_port ) { <nl> + case 0 : <nl> + return " uv " ; <nl> + case 1 : <nl> + return " lod " ; <nl> + case 2 : <nl> + return " samplerCube " ; <nl> + default : <nl> + return " " ; <nl> + } <nl> } <nl> <nl> int VisualShaderNodeCubeMap : : get_output_port_count ( ) const { <nl> Vector < VisualShader : : DefaultTextureParam > VisualShaderNodeCubeMap : : get_default_t <nl> <nl> String VisualShaderNodeCubeMap : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const { <nl> <nl> - String u = " uniform samplerCube " + make_unique_id ( p_type , p_id , " cube " ) ; <nl> - switch ( texture_type ) { <nl> - case TYPE_DATA : break ; <nl> - case TYPE_COLOR : u + = " : hint_albedo " ; break ; <nl> - case TYPE_NORMALMAP : u + = " : hint_normal " ; break ; <nl> + if ( source = = SOURCE_TEXTURE ) { <nl> + String u = " uniform samplerCube " + make_unique_id ( p_type , p_id , " cube " ) ; <nl> + switch ( texture_type ) { <nl> + case TYPE_DATA : break ; <nl> + case TYPE_COLOR : u + = " : hint_albedo " ; break ; <nl> + case TYPE_NORMALMAP : u + = " : hint_normal " ; break ; <nl> + } <nl> + return u + " ; " ; <nl> } <nl> - return u + " ; " ; <nl> + return String ( ) ; <nl> } <nl> <nl> String VisualShaderNodeCubeMap : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const { <nl> <nl> - String id = make_unique_id ( p_type , p_id , " cube " ) ; <nl> String code ; <nl> + String id ; <nl> + if ( source = = SOURCE_TEXTURE ) { <nl> + id = make_unique_id ( p_type , p_id , " cube " ) ; <nl> + } else if ( source = = SOURCE_PORT ) { <nl> + id = p_input_vars [ 2 ] ; <nl> + } else { <nl> + return String ( ) ; <nl> + } <nl> + <nl> + if ( id = = String ( ) ) { <nl> + code + = " \ tvec4 " + id + " _read = vec4 ( 0 . 0 ) ; \ n " ; <nl> + code + = " \ t " + p_output_vars [ 0 ] + " = " + id + " _read . rgb ; \ n " ; <nl> + code + = " \ t " + p_output_vars [ 1 ] + " = " + id + " _read . a ; \ n " ; <nl> + return code ; <nl> + } <nl> + <nl> if ( p_input_vars [ 0 ] = = String ( ) ) { / / Use UV by default . <nl> <nl> if ( p_input_vars [ 1 ] = = String ( ) ) { <nl> String VisualShaderNodeCubeMap : : generate_code ( Shader : : Mode p_mode , VisualShader : <nl> } else { <nl> code + = " \ tvec4 " + id + " _read = textureLod ( " + id + " , " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ) ; \ n " ; <nl> } <nl> - <nl> code + = " \ t " + p_output_vars [ 0 ] + " = " + id + " _read . rgb ; \ n " ; <nl> code + = " \ t " + p_output_vars [ 1 ] + " = " + id + " _read . a ; \ n " ; <nl> + <nl> return code ; <nl> } <nl> <nl> String VisualShaderNodeCubeMap : : get_input_port_default_hint ( int p_port ) const { <nl> return " " ; <nl> } <nl> <nl> + void VisualShaderNodeCubeMap : : set_source ( Source p_source ) { <nl> + source = p_source ; <nl> + emit_changed ( ) ; <nl> + emit_signal ( " editor_refresh_request " ) ; <nl> + } <nl> + <nl> + VisualShaderNodeCubeMap : : Source VisualShaderNodeCubeMap : : get_source ( ) const { <nl> + return source ; <nl> + } <nl> + <nl> void VisualShaderNodeCubeMap : : set_cube_map ( Ref < CubeMap > p_value ) { <nl> <nl> cube_map = p_value ; <nl> VisualShaderNodeCubeMap : : TextureType VisualShaderNodeCubeMap : : get_texture_type ( ) <nl> <nl> Vector < StringName > VisualShaderNodeCubeMap : : get_editable_properties ( ) const { <nl> Vector < StringName > props ; <nl> - props . push_back ( " cube_map " ) ; <nl> - props . push_back ( " texture_type " ) ; <nl> + props . push_back ( " source " ) ; <nl> + if ( source = = SOURCE_TEXTURE ) { <nl> + props . push_back ( " cube_map " ) ; <nl> + props . push_back ( " texture_type " ) ; <nl> + } <nl> return props ; <nl> } <nl> <nl> void VisualShaderNodeCubeMap : : _bind_methods ( ) { <nl> <nl> + ClassDB : : bind_method ( D_METHOD ( " set_source " , " value " ) , & VisualShaderNodeCubeMap : : set_source ) ; <nl> + ClassDB : : bind_method ( D_METHOD ( " get_source " ) , & VisualShaderNodeCubeMap : : get_source ) ; <nl> + <nl> ClassDB : : bind_method ( D_METHOD ( " set_cube_map " , " value " ) , & VisualShaderNodeCubeMap : : set_cube_map ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " get_cube_map " ) , & VisualShaderNodeCubeMap : : get_cube_map ) ; <nl> <nl> ClassDB : : bind_method ( D_METHOD ( " set_texture_type " , " value " ) , & VisualShaderNodeCubeMap : : set_texture_type ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " get_texture_type " ) , & VisualShaderNodeCubeMap : : get_texture_type ) ; <nl> <nl> + ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " source " , PROPERTY_HINT_ENUM , " Texture , SamplerPort " ) , " set_source " , " get_source " ) ; <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " cube_map " , PROPERTY_HINT_RESOURCE_TYPE , " CubeMap " ) , " set_cube_map " , " get_cube_map " ) ; <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " texture_type " , PROPERTY_HINT_ENUM , " Data , Color , Normalmap " ) , " set_texture_type " , " get_texture_type " ) ; <nl> <nl> + BIND_ENUM_CONSTANT ( SOURCE_TEXTURE ) ; <nl> + BIND_ENUM_CONSTANT ( SOURCE_PORT ) ; <nl> + <nl> BIND_ENUM_CONSTANT ( TYPE_DATA ) ; <nl> BIND_ENUM_CONSTANT ( TYPE_COLOR ) ; <nl> BIND_ENUM_CONSTANT ( TYPE_NORMALMAP ) ; <nl> String VisualShaderNodeTextureUniform : : get_output_port_name ( int p_port ) const { <nl> case 1 : <nl> return " alpha " ; <nl> case 2 : <nl> - return " sampler " ; <nl> + return " sampler2D " ; <nl> default : <nl> return " " ; <nl> } <nl> String VisualShaderNodeTextureUniform : : get_input_port_default_hint ( int p_port ) c <nl> VisualShaderNodeTextureUniform : : VisualShaderNodeTextureUniform ( ) { <nl> texture_type = TYPE_DATA ; <nl> color_default = COLOR_DEFAULT_WHITE ; <nl> - set_uniform_type ( VisualShaderNodeUniform : : UTYPE_SAMPLER2D ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / Texture Uniform ( Triplanar ) <nl> VisualShaderNodeCubeMapUniform : : PortType VisualShaderNodeCubeMapUniform : : get_out <nl> } <nl> <nl> String VisualShaderNodeCubeMapUniform : : get_output_port_name ( int p_port ) const { <nl> - return " sampler " ; <nl> + return " samplerCube " ; <nl> } <nl> <nl> int VisualShaderNodeCubeMapUniform : : get_input_port_count ( ) const { <nl> String VisualShaderNodeCubeMapUniform : : generate_code ( Shader : : Mode p_mode , Visual <nl> } <nl> <nl> VisualShaderNodeCubeMapUniform : : VisualShaderNodeCubeMapUniform ( ) { <nl> - set_uniform_type ( VisualShaderNodeUniform : : UTYPE_CUBEMAP ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / If <nl> mmm a / scene / resources / visual_shader_nodes . h <nl> ppp b / scene / resources / visual_shader_nodes . h <nl> class VisualShaderNodeCubeMap : public VisualShaderNode { <nl> Ref < CubeMap > cube_map ; <nl> <nl> public : <nl> + enum Source { <nl> + SOURCE_TEXTURE , <nl> + SOURCE_PORT <nl> + } ; <nl> + <nl> enum TextureType { <nl> TYPE_DATA , <nl> TYPE_COLOR , <nl> class VisualShaderNodeCubeMap : public VisualShaderNode { <nl> } ; <nl> <nl> private : <nl> + Source source ; <nl> TextureType texture_type ; <nl> <nl> protected : <nl> class VisualShaderNodeCubeMap : public VisualShaderNode { <nl> virtual String generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const ; <nl> virtual String generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview = false ) const ; / / if no output is connected , the output var passed will be empty . if no input is connected and input is NIL , the input var passed will be empty <nl> <nl> + void set_source ( Source p_source ) ; <nl> + Source get_source ( ) const ; <nl> + <nl> void set_cube_map ( Ref < CubeMap > p_value ) ; <nl> Ref < CubeMap > get_cube_map ( ) const ; <nl> <nl> class VisualShaderNodeCubeMap : public VisualShaderNode { <nl> } ; <nl> <nl> VARIANT_ENUM_CAST ( VisualShaderNodeCubeMap : : TextureType ) <nl> + VARIANT_ENUM_CAST ( VisualShaderNodeCubeMap : : Source ) <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> / / / OPS <nl>
[ VShaders ] Added sampler port to CubeMap , fixed parsing in expresssion s
godotengine/godot
b217babca2374575a5b725c48e6dc044c1b78aab
2019-10-11T07:36:04Z
mmm a / . azure - pipelines / linux . yml <nl> ppp b / . azure - pipelines / linux . yml <nl> jobs : <nl> vmImage : ' Ubuntu 16 . 04 ' <nl> container : envoy - build <nl> steps : <nl> - # bazel . dev isn ' t for CI purpose but we use it here to experiment with Azure Pipeline <nl> - # as it builds faster , before Azure can provision larger VM or we can use RBE . <nl> - - script : ci / do_ci . sh bazel . dev <nl> + - bash : | <nl> + echo " disk space at beginning of build : " <nl> + df - h <nl> + <nl> + - script : ci / do_ci . sh bazel . release <nl> env : <nl> ENVOY_SRCDIR : $ ( Build . SourcesDirectory ) <nl> BUILD_DIR : $ ( Build . StagingDirectory ) <nl> - BAZEL_EXTRA_TEST_OPTIONS : " - - test_env = ENVOY_IP_TEST_VERSIONS = v4only " <nl> - BAZEL_REMOTE_CACHE : remotebuildexecution . googleapis . com <nl> + BAZEL_BUILD_EXTRA_OPTIONS : " - - config = remote - clang - - config = remote - ci - - jobs = 100 - - curses = no " <nl> + # / / test / integration : echo_integration_test is marked exclusive so it will be run locally , no IPv6 locally in container . <nl> + BAZEL_EXTRA_TEST_OPTIONS : " - - test_filter = - IpVersions / EchoIntegrationTest . * / IPv6 " <nl> + BAZEL_REMOTE_CACHE : grpcs : / / remotebuildexecution . googleapis . com <nl> BAZEL_REMOTE_INSTANCE : projects / envoy - ci / instances / default_instance <nl> GCP_SERVICE_ACCOUNT_KEY : $ ( GcpServiceAccountKey ) <nl> <nl> - - task : PublishTestResults @ 2 <nl> - inputs : <nl> - testResultsFiles : ' * * / testlogs / * * / test . xml ' <nl> - testRunTitle : ' bazel . dev ' <nl> - searchFolder : $ ( Build . StagingDirectory ) <nl> + - bash : | <nl> + echo " disk space at end of build : " <nl> + df - h <nl> condition : always ( ) <nl> + <nl> + - task : PublishBuildArtifacts @ 1 <nl> + inputs : <nl> + pathtoPublish : " $ ( Build . StagingDirectory ) / envoy " <nl> + artifactName : ' envoy ' <nl> mmm a / . azure - pipelines / macos . yml <nl> ppp b / . azure - pipelines / macos . yml <nl> jobs : <nl> - script : . / ci / mac_ci_steps . sh <nl> displayName : ' Run Mac CI ' <nl> env : <nl> - BAZEL_REMOTE_CACHE : remotebuildexecution . googleapis . com <nl> + BAZEL_REMOTE_CACHE : grpcs : / / remotebuildexecution . googleapis . com <nl> BAZEL_REMOTE_INSTANCE : projects / envoy - ci / instances / default_instance <nl> GCP_SERVICE_ACCOUNT_KEY : $ ( GcpServiceAccountKey ) <nl> <nl> mmm a / . bazelrc <nl> ppp b / . bazelrc <nl> build : sizeopt - c opt - - copt - Os <nl> <nl> # Test options <nl> build - - test_env = HEAPCHECK = normal - - test_env = PPROF_PATH <nl> + <nl> + # Remote execution : https : / / docs . bazel . build / versions / master / remote - execution . html <nl> + build : rbe - toolchain - - host_javabase = @ rbe_ubuntu_clang / / java : jdk <nl> + build : rbe - toolchain - - javabase = @ rbe_ubuntu_clang / / java : jdk <nl> + build : rbe - toolchain - - host_java_toolchain = @ bazel_tools / / tools / jdk : toolchain_hostjdk8 <nl> + build : rbe - toolchain - - java_toolchain = @ bazel_tools / / tools / jdk : toolchain_hostjdk8 <nl> + build : rbe - toolchain - - host_platform = @ envoy / / bazel / toolchains : rbe_ubuntu_clang_platform <nl> + build : rbe - toolchain - - platforms = @ envoy / / bazel / toolchains : rbe_ubuntu_clang_platform <nl> + build : rbe - toolchain - - action_env = BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN = 1 <nl> + build : rbe - toolchain - - crosstool_top = @ rbe_ubuntu_clang / / cc : toolchain <nl> + build : rbe - toolchain - - extra_toolchains = @ rbe_ubuntu_clang / / config : cc - toolchain <nl> + build : rbe - toolchain - - linkopt = - fuse - ld = lld <nl> + build : rbe - toolchain - - action_env = CC = clang - - action_env = CXX = clang + + - - action_env = PATH = / usr / sbin : / usr / bin : / sbin : / bin : / usr / lib / llvm - 8 / bin <nl> + <nl> + build : remote - - spawn_strategy = remote , sandboxed , local <nl> + build : remote - - strategy = Javac = remote , sandboxed , local <nl> + build : remote - - strategy = Closure = remote , sandboxed , local <nl> + build : remote - - strategy = Genrule = remote , sandboxed , local <nl> + build : remote - - remote_timeout = 3600 <nl> + build : remote - - auth_enabled = true <nl> + build : remote - - experimental_inmemory_jdeps_files <nl> + build : remote - - experimental_inmemory_dotd_files <nl> + build : remote - - experimental_remote_download_outputs = toplevel <nl> + test : remote - - experimental_remote_download_outputs = minimal <nl> + <nl> + build : remote - clang - - config = remote <nl> + build : remote - clang - - config = rbe - toolchain <nl> + <nl> + # Docker sandbox <nl> + build : docker - sandbox - - experimental_docker_image = envoyproxy / envoy - build : cfc514546bc0284536893cca5fa43d7128edcd35 <nl> + build : docker - sandbox - - spawn_strategy = docker <nl> + build : docker - sandbox - - strategy = Javac = docker <nl> + build : docker - sandbox - - strategy = Closure = docker <nl> + build : docker - sandbox - - strategy = Genrule = docker <nl> + build : docker - sandbox - - define = EXECUTOR = remote <nl> + build : docker - sandbox - - experimental_docker_verbose <nl> + build : docker - sandbox - - experimental_enable_docker_sandbox <nl> + <nl> + build : docker - clang - - config = docker - sandbox <nl> + build : docker - clang - - config = rbe - toolchain <nl> + <nl> + # CI configurations <nl> + build : remote - ci - - remote_cache = grpcs : / / remotebuildexecution . googleapis . com <nl> + build : remote - ci - - remote_executor = grpcs : / / remotebuildexecution . googleapis . com <nl> mmm a / . circleci / config . yml <nl> ppp b / . circleci / config . yml <nl> executors : <nl> ubuntu - build : <nl> description : " A regular build executor based on ubuntu image " <nl> docker : <nl> + # NOTE : Update bazel / toolchains / rbe_toolchains_config . bzl with sha256 digest to match the image here . <nl> - image : envoyproxy / envoy - build : 8246167b9d238797cbc6c03dccc9e3921c37617d <nl> resource_class : xlarge <nl> working_directory : / source <nl> mmm a / WORKSPACE <nl> ppp b / WORKSPACE <nl> load ( " @ io_bazel_rules_go / / go : deps . bzl " , " go_register_toolchains " , " go_rules_depe <nl> go_rules_dependencies ( ) <nl> <nl> go_register_toolchains ( go_version = GO_VERSION ) <nl> + <nl> + load ( " @ envoy / / bazel / toolchains : rbe_toolchains_config . bzl " , " rbe_toolchains_config " ) <nl> + <nl> + rbe_toolchains_config ( ) <nl> mmm a / bazel / BUILD <nl> ppp b / bazel / BUILD <nl> package ( default_visibility = [ " / / visibility : public " ] ) <nl> exports_files ( [ <nl> " gen_sh_test_runner . sh " , <nl> " sh_test_wrapper . sh " , <nl> + " cc_wrapper . py " , <nl> ] ) <nl> <nl> genrule ( <nl> mmm a / bazel / repositories . bzl <nl> ppp b / bazel / repositories . bzl <nl> def envoy_dependencies ( skip_targets = [ ] ) : <nl> _com_lightstep_tracer_cpp ( ) <nl> _io_opentracing_cpp ( ) <nl> _net_zlib ( ) <nl> + _repository_impl ( " bazel_toolchains " ) <nl> <nl> _python_deps ( ) <nl> _cc_deps ( ) <nl> mmm a / bazel / repository_locations . bzl <nl> ppp b / bazel / repository_locations . bzl <nl> REPOSITORY_LOCATIONS = dict ( <nl> sha256 = " 3c681998538231a2d24d0c07ed5a7658cb72bfb5fd4bf9911157c0e9ac6a2687 " , <nl> urls = [ " https : / / github . com / bazelbuild / bazel - gazelle / releases / download / 0 . 17 . 0 / bazel - gazelle - 0 . 17 . 0 . tar . gz " ] , <nl> ) , <nl> + bazel_toolchains = dict ( <nl> + sha256 = " 68e7678473090542e679ce7e6aa8a3ba5669577dede2b404f9865d556bd99f10 " , <nl> + strip_prefix = " bazel - toolchains - 0 . 28 . 0 " , <nl> + urls = [ <nl> + " https : / / mirror . bazel . build / github . com / bazelbuild / bazel - toolchains / archive / 0 . 28 . 0 . tar . gz " , <nl> + " https : / / github . com / bazelbuild / bazel - toolchains / archive / 0 . 28 . 0 . tar . gz " , <nl> + ] , <nl> + ) , <nl> boringssl = dict ( <nl> # Use commits from branch " chromium - stable - with - bazel " <nl> sha256 = " 448773376d063b1e9a19e4fd41002d1a31a968a13be20b3b66ecd4aab9cf14a8 " , <nl> new file mode 100644 <nl> index 00000000000 . . e6a68336502 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / BUILD <nl> <nl> + licenses ( [ " notice " ] ) # Apache 2 <nl> + <nl> + platform ( <nl> + name = " rbe_ubuntu_clang_platform " , <nl> + parents = [ " @ rbe_ubuntu_clang / / config : platform " ] , <nl> + remote_execution_properties = " " " <nl> + { PARENT_REMOTE_EXECUTION_PROPERTIES } <nl> + properties : { <nl> + name : " dockerAddCapabilities " <nl> + value : " SYS_PTRACE , NET_RAW , NET_ADMIN " <nl> + } <nl> + properties : { <nl> + name : " dockerNetwork " <nl> + value : " standard " <nl> + } <nl> + " " " , <nl> + ) <nl> new file mode 100644 <nl> index 00000000000 . . 38e01600e86 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / README . md <nl> <nl> + # Bazel Toolchains <nl> + <nl> + This directory contains toolchains config generated for Bazel [ RBE ] ( https : / / docs . bazel . build / versions / master / remote - execution . html ) and <nl> + [ Docker sandbox ] ( https : / / docs . bazel . build / versions / master / remote - execution - sandbox . html ) . <nl> + <nl> + To regenerate toolchain configs , update the docker image information in ` rbe_toolchains_config . bzl ` and run following command in an <nl> + environment with the latest Bazel and Docker installed : <nl> + <nl> + ` ` ` <nl> + bazel / toolchains / regenerate . sh <nl> + ` ` ` <nl> + <nl> + This will generate configs in ` bazel / toolchains / configs ` , check in those files so they can be used in CI . <nl> new file mode 100644 <nl> index 00000000000 . . 9683e8aa4d5 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / . gitignore <nl> <nl> + # RBE autoconfig generator will generate a . bazelrc but we don ' t need it . <nl> + . latest . bazelrc <nl> new file mode 100755 <nl> index 00000000000 . . 7de0f268224 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / clang / bazel_0 . 28 . 0 / cc / BUILD <nl> <nl> + # Copyright 2016 The Bazel Authors . All rights reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # This becomes the BUILD file for @ local_config_cc / / under non - FreeBSD unixes . <nl> + <nl> + package ( default_visibility = [ " / / visibility : public " ] ) <nl> + <nl> + load ( " : cc_toolchain_config . bzl " , " cc_toolchain_config " ) <nl> + load ( " : armeabi_cc_toolchain_config . bzl " , " armeabi_cc_toolchain_config " ) <nl> + <nl> + licenses ( [ " notice " ] ) # Apache 2 . 0 <nl> + <nl> + cc_library ( <nl> + name = " malloc " , <nl> + ) <nl> + <nl> + filegroup ( <nl> + name = " empty " , <nl> + srcs = [ ] , <nl> + ) <nl> + <nl> + filegroup ( <nl> + name = " cc_wrapper " , <nl> + srcs = [ " cc_wrapper . sh " ] , <nl> + ) <nl> + <nl> + filegroup ( <nl> + name = " compiler_deps " , <nl> + srcs = glob ( [ " extra_tools / * * " ] , allow_empty = True ) + [ " : empty " ] , <nl> + ) <nl> + <nl> + # This is the entry point for - - crosstool_top . Toolchains are found <nl> + # by lopping off the name of - - crosstool_top and searching for <nl> + # the " $ { CPU } " entry in the toolchains attribute . <nl> + cc_toolchain_suite ( <nl> + name = " toolchain " , <nl> + toolchains = { <nl> + " k8 | clang " : " : cc - compiler - k8 " , <nl> + " k8 " : " : cc - compiler - k8 " , <nl> + " armeabi - v7a | compiler " : " : cc - compiler - armeabi - v7a " , <nl> + " armeabi - v7a " : " : cc - compiler - armeabi - v7a " , <nl> + } , <nl> + ) <nl> + <nl> + cc_toolchain ( <nl> + name = " cc - compiler - k8 " , <nl> + toolchain_identifier = " local " , <nl> + toolchain_config = " : local " , <nl> + all_files = " : compiler_deps " , <nl> + ar_files = " : compiler_deps " , <nl> + as_files = " : compiler_deps " , <nl> + compiler_files = " : compiler_deps " , <nl> + dwp_files = " : empty " , <nl> + linker_files = " : compiler_deps " , <nl> + objcopy_files = " : empty " , <nl> + strip_files = " : empty " , <nl> + supports_param_files = 1 , <nl> + ) <nl> + <nl> + cc_toolchain_config ( <nl> + name = " local " , <nl> + cpu = " k8 " , <nl> + compiler = " clang " , <nl> + toolchain_identifier = " local " , <nl> + host_system_name = " local " , <nl> + target_system_name = " local " , <nl> + target_libc = " local " , <nl> + abi_version = " local " , <nl> + abi_libc_version = " local " , <nl> + cxx_builtin_include_directories = [ " / usr / local / include " , <nl> + " / usr / lib / llvm - 8 / lib / clang / 8 . 0 . 1 / include " , <nl> + " / usr / include / x86_64 - linux - gnu " , <nl> + " / usr / include " , <nl> + " / usr / include / c + + / 7 . 4 . 0 " , <nl> + " / usr / include / x86_64 - linux - gnu / c + + / 7 . 4 . 0 " , <nl> + " / usr / include / c + + / 7 . 4 . 0 / backward " , <nl> + " / usr / include / clang / 8 . 0 . 1 / include " ] , <nl> + tool_paths = { " ar " : " / usr / bin / ar " , <nl> + " ld " : " / usr / bin / ld " , <nl> + " cpp " : " / usr / bin / cpp " , <nl> + " gcc " : " / usr / lib / llvm - 8 / bin / clang " , <nl> + " dwp " : " / usr / bin / dwp " , <nl> + " gcov " : " / usr / lib / llvm - 8 / bin / llvm - profdata " , <nl> + " nm " : " / usr / bin / nm " , <nl> + " objcopy " : " / usr / bin / objcopy " , <nl> + " objdump " : " / usr / bin / objdump " , <nl> + " strip " : " / usr / bin / strip " } , <nl> + compile_flags = [ " - U_FORTIFY_SOURCE " , <nl> + " - fstack - protector " , <nl> + " - Wall " , <nl> + " - Wthread - safety " , <nl> + " - Wself - assign " , <nl> + " - fcolor - diagnostics " , <nl> + " - fno - omit - frame - pointer " ] , <nl> + opt_compile_flags = [ " - g0 " , <nl> + " - O2 " , <nl> + " - D_FORTIFY_SOURCE = 1 " , <nl> + " - DNDEBUG " , <nl> + " - ffunction - sections " , <nl> + " - fdata - sections " ] , <nl> + dbg_compile_flags = [ " - g " ] , <nl> + cxx_flags = [ " - std = c + + 0x " ] , <nl> + link_flags = [ " - fuse - ld = gold " , <nl> + " - Wl , - no - as - needed " , <nl> + " - Wl , - z , relro , - z , now " , <nl> + " - B / usr / lib / llvm - 8 / bin " , <nl> + " - lm " , <nl> + " - static - libgcc " ] , <nl> + link_libs = [ " - l : libstdc + + . a " ] , <nl> + opt_link_flags = [ " - Wl , - - gc - sections " ] , <nl> + unfiltered_compile_flags = [ " - no - canonical - prefixes " , <nl> + " - Wno - builtin - macro - redefined " , <nl> + " - D__DATE__ = \ " redacted \ " " , <nl> + " - D__TIMESTAMP__ = \ " redacted \ " " , <nl> + " - D__TIME__ = \ " redacted \ " " ] , <nl> + coverage_compile_flags = [ " - fprofile - instr - generate " , " - fcoverage - mapping " ] , <nl> + coverage_link_flags = [ " - fprofile - instr - generate " ] , <nl> + supports_start_end_lib = True , <nl> + ) <nl> + <nl> + # Android tooling requires a default toolchain for the armeabi - v7a cpu . <nl> + cc_toolchain ( <nl> + name = " cc - compiler - armeabi - v7a " , <nl> + toolchain_identifier = " stub_armeabi - v7a " , <nl> + toolchain_config = " : stub_armeabi - v7a " , <nl> + all_files = " : empty " , <nl> + ar_files = " : empty " , <nl> + as_files = " : empty " , <nl> + compiler_files = " : empty " , <nl> + dwp_files = " : empty " , <nl> + linker_files = " : empty " , <nl> + objcopy_files = " : empty " , <nl> + strip_files = " : empty " , <nl> + supports_param_files = 1 , <nl> + ) <nl> + <nl> + armeabi_cc_toolchain_config ( name = " stub_armeabi - v7a " ) <nl> new file mode 100755 <nl> index 00000000000 . . 94e0720bf6c <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / clang / bazel_0 . 28 . 0 / cc / armeabi_cc_toolchain_config . bzl <nl> <nl> + # Copyright 2019 The Bazel Authors . All rights reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + " " " A Starlark cc_toolchain configuration rule " " " <nl> + <nl> + load ( <nl> + " @ bazel_tools / / tools / cpp : cc_toolchain_config_lib . bzl " , <nl> + " feature " , <nl> + " tool_path " , <nl> + ) <nl> + <nl> + def _impl ( ctx ) : <nl> + toolchain_identifier = " stub_armeabi - v7a " <nl> + host_system_name = " armeabi - v7a " <nl> + target_system_name = " armeabi - v7a " <nl> + target_cpu = " armeabi - v7a " <nl> + target_libc = " armeabi - v7a " <nl> + compiler = " compiler " <nl> + abi_version = " armeabi - v7a " <nl> + abi_libc_version = " armeabi - v7a " <nl> + cc_target_os = None <nl> + builtin_sysroot = None <nl> + action_configs = [ ] <nl> + <nl> + supports_pic_feature = feature ( name = " supports_pic " , enabled = True ) <nl> + supports_dynamic_linker_feature = feature ( name = " supports_dynamic_linker " , enabled = True ) <nl> + features = [ supports_dynamic_linker_feature , supports_pic_feature ] <nl> + <nl> + cxx_builtin_include_directories = [ ] <nl> + artifact_name_patterns = [ ] <nl> + make_variables = [ ] <nl> + <nl> + tool_paths = [ <nl> + tool_path ( name = " ar " , path = " / bin / false " ) , <nl> + tool_path ( name = " compat - ld " , path = " / bin / false " ) , <nl> + tool_path ( name = " cpp " , path = " / bin / false " ) , <nl> + tool_path ( name = " dwp " , path = " / bin / false " ) , <nl> + tool_path ( name = " gcc " , path = " / bin / false " ) , <nl> + tool_path ( name = " gcov " , path = " / bin / false " ) , <nl> + tool_path ( name = " ld " , path = " / bin / false " ) , <nl> + tool_path ( name = " nm " , path = " / bin / false " ) , <nl> + tool_path ( name = " objcopy " , path = " / bin / false " ) , <nl> + tool_path ( name = " objdump " , path = " / bin / false " ) , <nl> + tool_path ( name = " strip " , path = " / bin / false " ) , <nl> + ] <nl> + <nl> + return cc_common . create_cc_toolchain_config_info ( <nl> + ctx = ctx , <nl> + features = features , <nl> + action_configs = action_configs , <nl> + artifact_name_patterns = artifact_name_patterns , <nl> + cxx_builtin_include_directories = cxx_builtin_include_directories , <nl> + toolchain_identifier = toolchain_identifier , <nl> + host_system_name = host_system_name , <nl> + target_system_name = target_system_name , <nl> + target_cpu = target_cpu , <nl> + target_libc = target_libc , <nl> + compiler = compiler , <nl> + abi_version = abi_version , <nl> + abi_libc_version = abi_libc_version , <nl> + tool_paths = tool_paths , <nl> + make_variables = make_variables , <nl> + builtin_sysroot = builtin_sysroot , <nl> + cc_target_os = cc_target_os , <nl> + ) <nl> + <nl> + armeabi_cc_toolchain_config = rule ( <nl> + implementation = _impl , <nl> + attrs = { } , <nl> + provides = [ CcToolchainConfigInfo ] , <nl> + ) <nl> new file mode 100755 <nl> index 00000000000 . . f2b12d96296 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / clang / bazel_0 . 28 . 0 / cc / cc_toolchain_config . bzl <nl> <nl> + # Copyright 2019 The Bazel Authors . All rights reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + " " " A Starlark cc_toolchain configuration rule " " " <nl> + <nl> + load ( <nl> + " @ bazel_tools / / tools / cpp : cc_toolchain_config_lib . bzl " , <nl> + " feature " , <nl> + " feature_set " , <nl> + " flag_group " , <nl> + " flag_set " , <nl> + " tool_path " , <nl> + " variable_with_value " , <nl> + " with_feature_set " , <nl> + ) <nl> + load ( " @ bazel_tools / / tools / build_defs / cc : action_names . bzl " , " ACTION_NAMES " ) <nl> + <nl> + all_compile_actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . clif_match , <nl> + ACTION_NAMES . lto_backend , <nl> + ] <nl> + <nl> + all_cpp_compile_actions = [ <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . clif_match , <nl> + ] <nl> + <nl> + preprocessor_compile_actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . clif_match , <nl> + ] <nl> + <nl> + codegen_compile_actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ] <nl> + <nl> + all_link_actions = [ <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ] <nl> + <nl> + def _impl ( ctx ) : <nl> + tool_paths = [ <nl> + tool_path ( name = name , path = path ) <nl> + for name , path in ctx . attr . tool_paths . items ( ) <nl> + ] <nl> + action_configs = [ ] <nl> + <nl> + supports_pic_feature = feature ( <nl> + name = " supports_pic " , <nl> + enabled = True , <nl> + ) <nl> + supports_start_end_lib_feature = feature ( <nl> + name = " supports_start_end_lib " , <nl> + enabled = True , <nl> + ) <nl> + <nl> + default_compile_flags_feature = feature ( <nl> + name = " default_compile_flags " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . compile_flags , <nl> + ) , <nl> + ] if ctx . attr . compile_flags else [ ] ) , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . dbg_compile_flags , <nl> + ) , <nl> + ] if ctx . attr . dbg_compile_flags else [ ] ) , <nl> + with_features = [ with_feature_set ( features = [ " dbg " ] ) ] , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . opt_compile_flags , <nl> + ) , <nl> + ] if ctx . attr . opt_compile_flags else [ ] ) , <nl> + with_features = [ with_feature_set ( features = [ " opt " ] ) ] , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . cxx_flags , <nl> + ) , <nl> + ] if ctx . attr . cxx_flags else [ ] ) , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + default_link_flags_feature = feature ( <nl> + name = " default_link_flags " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . link_flags , <nl> + ) , <nl> + ] if ctx . attr . link_flags else [ ] ) , <nl> + ) , <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . opt_link_flags , <nl> + ) , <nl> + ] if ctx . attr . opt_link_flags else [ ] ) , <nl> + with_features = [ with_feature_set ( features = [ " opt " ] ) ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + dbg_feature = feature ( name = " dbg " ) <nl> + <nl> + opt_feature = feature ( name = " opt " ) <nl> + <nl> + sysroot_feature = feature ( <nl> + name = " sysroot " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - - sysroot = % { sysroot } " ] , <nl> + expand_if_available = " sysroot " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + fdo_optimize_feature = feature ( <nl> + name = " fdo_optimize " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ ACTION_NAMES . c_compile , ACTION_NAMES . cpp_compile ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - fprofile - use = % { fdo_profile_path } " , <nl> + " - fprofile - correction " , <nl> + ] , <nl> + expand_if_available = " fdo_profile_path " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + provides = [ " profile " ] , <nl> + ) <nl> + <nl> + supports_dynamic_linker_feature = feature ( name = " supports_dynamic_linker " , enabled = True ) <nl> + <nl> + user_compile_flags_feature = feature ( <nl> + name = " user_compile_flags " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " % { user_compile_flags } " ] , <nl> + iterate_over = " user_compile_flags " , <nl> + expand_if_available = " user_compile_flags " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + unfiltered_compile_flags_feature = feature ( <nl> + name = " unfiltered_compile_flags " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . unfiltered_compile_flags , <nl> + ) , <nl> + ] if ctx . attr . unfiltered_compile_flags else [ ] ) , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + library_search_directories_feature = feature ( <nl> + name = " library_search_directories " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - L % { library_search_directories } " ] , <nl> + iterate_over = " library_search_directories " , <nl> + expand_if_available = " library_search_directories " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + static_libgcc_feature = feature ( <nl> + name = " static_libgcc " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ] , <nl> + flag_groups = [ flag_group ( flags = [ " - static - libgcc " ] ) ] , <nl> + with_features = [ <nl> + with_feature_set ( features = [ " static_link_cpp_runtimes " ] ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + pic_feature = feature ( <nl> + name = " pic " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( flags = [ " - fPIC " ] , expand_if_available = " pic " ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + per_object_debug_info_feature = feature ( <nl> + name = " per_object_debug_info " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - gsplit - dwarf " ] , <nl> + expand_if_available = " per_object_debug_info_file " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + preprocessor_defines_feature = feature ( <nl> + name = " preprocessor_defines " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - D % { preprocessor_defines } " ] , <nl> + iterate_over = " preprocessor_defines " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + cs_fdo_optimize_feature = feature ( <nl> + name = " cs_fdo_optimize " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ ACTION_NAMES . lto_backend ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - fprofile - use = % { fdo_profile_path } " , <nl> + " - Xclang - only = - Wno - profile - instr - unprofiled " , <nl> + " - Xclang - only = - Wno - profile - instr - out - of - date " , <nl> + " - fprofile - correction " , <nl> + ] , <nl> + expand_if_available = " fdo_profile_path " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + provides = [ " csprofile " ] , <nl> + ) <nl> + <nl> + autofdo_feature = feature ( <nl> + name = " autofdo " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ ACTION_NAMES . c_compile , ACTION_NAMES . cpp_compile ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - fauto - profile = % { fdo_profile_path } " , <nl> + " - fprofile - correction " , <nl> + ] , <nl> + expand_if_available = " fdo_profile_path " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + provides = [ " profile " ] , <nl> + ) <nl> + <nl> + runtime_library_search_directories_feature = feature ( <nl> + name = " runtime_library_search_directories " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + iterate_over = " runtime_library_search_directories " , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - Wl , - rpath , $ EXEC_ORIGIN / % { runtime_library_search_directories } " , <nl> + ] , <nl> + expand_if_true = " is_cc_test " , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ <nl> + " - Wl , - rpath , $ ORIGIN / % { runtime_library_search_directories } " , <nl> + ] , <nl> + expand_if_false = " is_cc_test " , <nl> + ) , <nl> + ] , <nl> + expand_if_available = <nl> + " runtime_library_search_directories " , <nl> + ) , <nl> + ] , <nl> + with_features = [ <nl> + with_feature_set ( features = [ " static_link_cpp_runtimes " ] ) , <nl> + ] , <nl> + ) , <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + iterate_over = " runtime_library_search_directories " , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - Wl , - rpath , $ ORIGIN / % { runtime_library_search_directories } " , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + expand_if_available = <nl> + " runtime_library_search_directories " , <nl> + ) , <nl> + ] , <nl> + with_features = [ <nl> + with_feature_set ( <nl> + not_features = [ " static_link_cpp_runtimes " ] , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + fission_support_feature = feature ( <nl> + name = " fission_support " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - Wl , - - gdb - index " ] , <nl> + expand_if_available = " is_using_fission " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + shared_flag_feature = feature ( <nl> + name = " shared_flag " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ] , <nl> + flag_groups = [ flag_group ( flags = [ " - shared " ] ) ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + random_seed_feature = feature ( <nl> + name = " random_seed " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - frandom - seed = % { output_file } " ] , <nl> + expand_if_available = " output_file " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + includes_feature = feature ( <nl> + name = " includes " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . clif_match , <nl> + ACTION_NAMES . objc_compile , <nl> + ACTION_NAMES . objcpp_compile , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - include " , " % { includes } " ] , <nl> + iterate_over = " includes " , <nl> + expand_if_available = " includes " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + fdo_instrument_feature = feature ( <nl> + name = " fdo_instrument " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - fprofile - generate = % { fdo_instrument_path } " , <nl> + " - fno - data - sections " , <nl> + ] , <nl> + expand_if_available = " fdo_instrument_path " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + provides = [ " profile " ] , <nl> + ) <nl> + <nl> + cs_fdo_instrument_feature = feature ( <nl> + name = " cs_fdo_instrument " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - fcs - profile - generate = % { cs_fdo_instrument_path } " , <nl> + ] , <nl> + expand_if_available = " cs_fdo_instrument_path " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + provides = [ " csprofile " ] , <nl> + ) <nl> + <nl> + include_paths_feature = feature ( <nl> + name = " include_paths " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . clif_match , <nl> + ACTION_NAMES . objc_compile , <nl> + ACTION_NAMES . objcpp_compile , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - iquote " , " % { quote_include_paths } " ] , <nl> + iterate_over = " quote_include_paths " , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - I % { include_paths } " ] , <nl> + iterate_over = " include_paths " , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - isystem " , " % { system_include_paths } " ] , <nl> + iterate_over = " system_include_paths " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + symbol_counts_feature = feature ( <nl> + name = " symbol_counts " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - Wl , - - print - symbol - counts = % { symbol_counts_output } " , <nl> + ] , <nl> + expand_if_available = " symbol_counts_output " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + llvm_coverage_map_format_feature = feature ( <nl> + name = " llvm_coverage_map_format " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . objc_compile , <nl> + ACTION_NAMES . objcpp_compile , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - fprofile - instr - generate " , <nl> + " - fcoverage - mapping " , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + " objc - executable " , <nl> + " objc + + - executable " , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( flags = [ " - fprofile - instr - generate " ] ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + requires = [ feature_set ( features = [ " coverage " ] ) ] , <nl> + provides = [ " profile " ] , <nl> + ) <nl> + <nl> + strip_debug_symbols_feature = feature ( <nl> + name = " strip_debug_symbols " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - Wl , - S " ] , <nl> + expand_if_available = " strip_debug_symbols " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + build_interface_libraries_feature = feature ( <nl> + name = " build_interface_libraries " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " % { generate_interface_library } " , <nl> + " % { interface_library_builder_path } " , <nl> + " % { interface_library_input_path } " , <nl> + " % { interface_library_output_path } " , <nl> + ] , <nl> + expand_if_available = " generate_interface_library " , <nl> + ) , <nl> + ] , <nl> + with_features = [ <nl> + with_feature_set ( <nl> + features = [ " supports_interface_shared_libraries " ] , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + libraries_to_link_feature = feature ( <nl> + name = " libraries_to_link " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + iterate_over = " libraries_to_link " , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - Wl , - - start - lib " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " object_file_group " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - Wl , - whole - archive " ] , <nl> + expand_if_true = <nl> + " libraries_to_link . is_whole_archive " , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " % { libraries_to_link . object_files } " ] , <nl> + iterate_over = " libraries_to_link . object_files " , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " object_file_group " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " % { libraries_to_link . name } " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " object_file " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " % { libraries_to_link . name } " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " interface_library " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " % { libraries_to_link . name } " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " static_library " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - l % { libraries_to_link . name } " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " dynamic_library " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - l : % { libraries_to_link . name } " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " versioned_dynamic_library " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - Wl , - no - whole - archive " ] , <nl> + expand_if_true = " libraries_to_link . is_whole_archive " , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - Wl , - - end - lib " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " object_file_group " , <nl> + ) , <nl> + ) , <nl> + ] , <nl> + expand_if_available = " libraries_to_link " , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - Wl , @ % { thinlto_param_file } " ] , <nl> + expand_if_true = " thinlto_param_file " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + user_link_flags_feature = feature ( <nl> + name = " user_link_flags " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " % { user_link_flags } " ] , <nl> + iterate_over = " user_link_flags " , <nl> + expand_if_available = " user_link_flags " , <nl> + ) , <nl> + ] + ( [ flag_group ( flags = ctx . attr . link_libs ) ] if ctx . attr . link_libs else [ ] ) , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + fdo_prefetch_hints_feature = feature ( <nl> + name = " fdo_prefetch_hints " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . lto_backend , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - Xclang - only = - mllvm " , <nl> + " - Xclang - only = - prefetch - hints - file = % { fdo_prefetch_hints_path } " , <nl> + ] , <nl> + expand_if_available = " fdo_prefetch_hints_path " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + linkstamps_feature = feature ( <nl> + name = " linkstamps " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " % { linkstamp_paths } " ] , <nl> + iterate_over = " linkstamp_paths " , <nl> + expand_if_available = " linkstamp_paths " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + gcc_coverage_map_format_feature = feature ( <nl> + name = " gcc_coverage_map_format " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . objc_compile , <nl> + ACTION_NAMES . objcpp_compile , <nl> + " objc - executable " , <nl> + " objc + + - executable " , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - fprofile - arcs " , " - ftest - coverage " ] , <nl> + expand_if_available = " gcov_gcno_file " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ] , <nl> + flag_groups = [ flag_group ( flags = [ " - - coverage " ] ) ] , <nl> + ) , <nl> + ] , <nl> + requires = [ feature_set ( features = [ " coverage " ] ) ] , <nl> + provides = [ " profile " ] , <nl> + ) <nl> + <nl> + archiver_flags_feature = feature ( <nl> + name = " archiver_flags " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ ACTION_NAMES . cpp_link_static_library ] , <nl> + flag_groups = [ <nl> + flag_group ( flags = [ " rcsD " ] ) , <nl> + flag_group ( <nl> + flags = [ " % { output_execpath } " ] , <nl> + expand_if_available = " output_execpath " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ ACTION_NAMES . cpp_link_static_library ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + iterate_over = " libraries_to_link " , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " % { libraries_to_link . name } " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " object_file " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " % { libraries_to_link . object_files } " ] , <nl> + iterate_over = " libraries_to_link . object_files " , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " object_file_group " , <nl> + ) , <nl> + ) , <nl> + ] , <nl> + expand_if_available = " libraries_to_link " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + force_pic_flags_feature = feature ( <nl> + name = " force_pic_flags " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ ACTION_NAMES . cpp_link_executable ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - pie " ] , <nl> + expand_if_available = " force_pic " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + dependency_file_feature = feature ( <nl> + name = " dependency_file " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . objc_compile , <nl> + ACTION_NAMES . objcpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - MD " , " - MF " , " % { dependency_file } " ] , <nl> + expand_if_available = " dependency_file " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + dynamic_library_linker_tool_feature = feature ( <nl> + name = " dynamic_library_linker_tool " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " + cppLinkDynamicLibraryToolPath + " ] , <nl> + expand_if_available = " generate_interface_library " , <nl> + ) , <nl> + ] , <nl> + with_features = [ <nl> + with_feature_set ( <nl> + features = [ " supports_interface_shared_libraries " ] , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + output_execpath_flags_feature = feature ( <nl> + name = " output_execpath_flags " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - o " , " % { output_execpath } " ] , <nl> + expand_if_available = " output_execpath " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + # Note that we also set - - coverage for c + + - link - nodeps - dynamic - library . The <nl> + # generated code contains references to gcov symbols , and the dynamic linker <nl> + # can ' t resolve them unless the library is linked against gcov . <nl> + coverage_feature = feature ( <nl> + name = " coverage " , <nl> + provides = [ " profile " ] , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( flags = ctx . attr . coverage_compile_flags ) , <nl> + ] if ctx . attr . coverage_compile_flags else [ ] ) , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( flags = ctx . attr . coverage_link_flags ) , <nl> + ] if ctx . attr . coverage_link_flags else [ ] ) , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + is_linux = ctx . attr . target_libc ! = " macosx " <nl> + <nl> + # TODO ( # 8303 ) : Mac crosstool should also declare every feature . <nl> + if is_linux : <nl> + features = [ <nl> + dependency_file_feature , <nl> + random_seed_feature , <nl> + pic_feature , <nl> + per_object_debug_info_feature , <nl> + preprocessor_defines_feature , <nl> + includes_feature , <nl> + include_paths_feature , <nl> + fdo_instrument_feature , <nl> + cs_fdo_instrument_feature , <nl> + cs_fdo_optimize_feature , <nl> + fdo_prefetch_hints_feature , <nl> + autofdo_feature , <nl> + build_interface_libraries_feature , <nl> + dynamic_library_linker_tool_feature , <nl> + symbol_counts_feature , <nl> + shared_flag_feature , <nl> + linkstamps_feature , <nl> + output_execpath_flags_feature , <nl> + runtime_library_search_directories_feature , <nl> + library_search_directories_feature , <nl> + archiver_flags_feature , <nl> + force_pic_flags_feature , <nl> + fission_support_feature , <nl> + strip_debug_symbols_feature , <nl> + coverage_feature , <nl> + supports_pic_feature , <nl> + ] + ( <nl> + [ <nl> + supports_start_end_lib_feature , <nl> + ] if ctx . attr . supports_start_end_lib else [ ] <nl> + ) + [ <nl> + default_compile_flags_feature , <nl> + default_link_flags_feature , <nl> + libraries_to_link_feature , <nl> + user_link_flags_feature , <nl> + static_libgcc_feature , <nl> + fdo_optimize_feature , <nl> + supports_dynamic_linker_feature , <nl> + dbg_feature , <nl> + opt_feature , <nl> + user_compile_flags_feature , <nl> + sysroot_feature , <nl> + unfiltered_compile_flags_feature , <nl> + ] <nl> + else : <nl> + features = [ <nl> + supports_pic_feature , <nl> + ] + ( <nl> + [ <nl> + supports_start_end_lib_feature , <nl> + ] if ctx . attr . supports_start_end_lib else [ ] <nl> + ) + [ <nl> + coverage_feature , <nl> + default_compile_flags_feature , <nl> + default_link_flags_feature , <nl> + fdo_optimize_feature , <nl> + supports_dynamic_linker_feature , <nl> + dbg_feature , <nl> + opt_feature , <nl> + user_compile_flags_feature , <nl> + sysroot_feature , <nl> + unfiltered_compile_flags_feature , <nl> + ] <nl> + <nl> + return cc_common . create_cc_toolchain_config_info ( <nl> + ctx = ctx , <nl> + features = features , <nl> + action_configs = action_configs , <nl> + cxx_builtin_include_directories = ctx . attr . cxx_builtin_include_directories , <nl> + toolchain_identifier = ctx . attr . toolchain_identifier , <nl> + host_system_name = ctx . attr . host_system_name , <nl> + target_system_name = ctx . attr . target_system_name , <nl> + target_cpu = ctx . attr . cpu , <nl> + target_libc = ctx . attr . target_libc , <nl> + compiler = ctx . attr . compiler , <nl> + abi_version = ctx . attr . abi_version , <nl> + abi_libc_version = ctx . attr . abi_libc_version , <nl> + tool_paths = tool_paths , <nl> + ) <nl> + <nl> + cc_toolchain_config = rule ( <nl> + implementation = _impl , <nl> + attrs = { <nl> + " cpu " : attr . string ( mandatory = True ) , <nl> + " compiler " : attr . string ( mandatory = True ) , <nl> + " toolchain_identifier " : attr . string ( mandatory = True ) , <nl> + " host_system_name " : attr . string ( mandatory = True ) , <nl> + " target_system_name " : attr . string ( mandatory = True ) , <nl> + " target_libc " : attr . string ( mandatory = True ) , <nl> + " abi_version " : attr . string ( mandatory = True ) , <nl> + " abi_libc_version " : attr . string ( mandatory = True ) , <nl> + " cxx_builtin_include_directories " : attr . string_list ( ) , <nl> + " tool_paths " : attr . string_dict ( ) , <nl> + " compile_flags " : attr . string_list ( ) , <nl> + " dbg_compile_flags " : attr . string_list ( ) , <nl> + " opt_compile_flags " : attr . string_list ( ) , <nl> + " cxx_flags " : attr . string_list ( ) , <nl> + " link_flags " : attr . string_list ( ) , <nl> + " link_libs " : attr . string_list ( ) , <nl> + " opt_link_flags " : attr . string_list ( ) , <nl> + " unfiltered_compile_flags " : attr . string_list ( ) , <nl> + " coverage_compile_flags " : attr . string_list ( ) , <nl> + " coverage_link_flags " : attr . string_list ( ) , <nl> + " supports_start_end_lib " : attr . bool ( ) , <nl> + } , <nl> + provides = [ CcToolchainConfigInfo ] , <nl> + ) <nl> new file mode 100755 <nl> index 00000000000 . . b7ff6355883 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / clang / bazel_0 . 28 . 0 / cc / cc_wrapper . sh <nl> <nl> + # ! / bin / bash <nl> + # <nl> + # Copyright 2015 The Bazel Authors . All rights reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + # <nl> + # Ship the environment to the C + + action <nl> + # <nl> + set - eu <nl> + <nl> + # Set - up the environment <nl> + <nl> + <nl> + # Call the C + + compiler <nl> + / usr / lib / llvm - 8 / bin / clang " $ @ " <nl> new file mode 100644 <nl> index 00000000000 . . ac2d4d5f1c5 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / clang / bazel_0 . 28 . 0 / config / BUILD <nl> <nl> + # Copyright 2016 The Bazel Authors . All rights reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # This file is auto - generated by an rbe_autoconfig repository rule <nl> + # and should not be modified directly . <nl> + # See @ bazel_toolchains / / rules : rbe_repo . bzl <nl> + <nl> + package ( default_visibility = [ " / / visibility : public " ] ) <nl> + <nl> + toolchain ( <nl> + name = " cc - toolchain " , <nl> + exec_compatible_with = [ <nl> + " @ bazel_tools / / platforms : x86_64 " , <nl> + " @ bazel_tools / / platforms : linux " , <nl> + " @ bazel_tools / / tools / cpp : clang " , <nl> + ] , <nl> + target_compatible_with = [ <nl> + " @ bazel_tools / / platforms : linux " , <nl> + " @ bazel_tools / / platforms : x86_64 " , <nl> + ] , <nl> + toolchain = " / / bazel / toolchains / configs / clang / bazel_0 . 28 . 0 / cc : cc - compiler - k8 " , <nl> + toolchain_type = " @ bazel_tools / / tools / cpp : toolchain_type " , <nl> + ) <nl> + <nl> + platform ( <nl> + name = " platform " , <nl> + constraint_values = [ <nl> + " @ bazel_tools / / platforms : x86_64 " , <nl> + " @ bazel_tools / / platforms : linux " , <nl> + " @ bazel_tools / / tools / cpp : clang " , <nl> + ] , <nl> + remote_execution_properties = " " " <nl> + properties : { <nl> + name : " container - image " <nl> + value : " docker : / / gcr . io / envoy - ci / envoy - build @ sha256 : 9dbe1cba2b3340d49a25a1d286c8d49083ec986a6fead27f487e80ca334f065f " <nl> + } <nl> + properties { <nl> + name : " OSFamily " <nl> + value : " Linux " <nl> + } <nl> + " " " , <nl> + ) <nl> new file mode 100644 <nl> index 00000000000 . . 7c273a5b0e4 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / clang / bazel_0 . 28 . 0 / java / BUILD <nl> <nl> + # Copyright 2016 The Bazel Authors . All rights reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # This file is auto - generated by an rbe_autoconfig repository rule <nl> + # and should not be modified directly . <nl> + # See @ bazel_toolchains / / rules : rbe_repo . bzl <nl> + <nl> + package ( default_visibility = [ " / / visibility : public " ] ) <nl> + <nl> + java_runtime ( <nl> + name = " jdk " , <nl> + srcs = [ ] , <nl> + java_home = " / usr / lib / jvm / java - 8 - openjdk - amd64 " , <nl> + ) <nl> new file mode 100755 <nl> index 00000000000 . . eb9ab72263f <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / gcc / bazel_0 . 28 . 0 / cc / BUILD <nl> <nl> + # Copyright 2016 The Bazel Authors . All rights reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # This becomes the BUILD file for @ local_config_cc / / under non - FreeBSD unixes . <nl> + <nl> + package ( default_visibility = [ " / / visibility : public " ] ) <nl> + <nl> + load ( " : cc_toolchain_config . bzl " , " cc_toolchain_config " ) <nl> + load ( " : armeabi_cc_toolchain_config . bzl " , " armeabi_cc_toolchain_config " ) <nl> + <nl> + licenses ( [ " notice " ] ) # Apache 2 . 0 <nl> + <nl> + cc_library ( <nl> + name = " malloc " , <nl> + ) <nl> + <nl> + filegroup ( <nl> + name = " empty " , <nl> + srcs = [ ] , <nl> + ) <nl> + <nl> + filegroup ( <nl> + name = " cc_wrapper " , <nl> + srcs = [ " cc_wrapper . sh " ] , <nl> + ) <nl> + <nl> + filegroup ( <nl> + name = " compiler_deps " , <nl> + srcs = glob ( [ " extra_tools / * * " ] , allow_empty = True ) + [ " : empty " ] , <nl> + ) <nl> + <nl> + # This is the entry point for - - crosstool_top . Toolchains are found <nl> + # by lopping off the name of - - crosstool_top and searching for <nl> + # the " $ { CPU } " entry in the toolchains attribute . <nl> + cc_toolchain_suite ( <nl> + name = " toolchain " , <nl> + toolchains = { <nl> + " k8 | gcc " : " : cc - compiler - k8 " , <nl> + " k8 " : " : cc - compiler - k8 " , <nl> + " armeabi - v7a | compiler " : " : cc - compiler - armeabi - v7a " , <nl> + " armeabi - v7a " : " : cc - compiler - armeabi - v7a " , <nl> + } , <nl> + ) <nl> + <nl> + cc_toolchain ( <nl> + name = " cc - compiler - k8 " , <nl> + toolchain_identifier = " local " , <nl> + toolchain_config = " : local " , <nl> + all_files = " : compiler_deps " , <nl> + ar_files = " : compiler_deps " , <nl> + as_files = " : compiler_deps " , <nl> + compiler_files = " : compiler_deps " , <nl> + dwp_files = " : empty " , <nl> + linker_files = " : compiler_deps " , <nl> + objcopy_files = " : empty " , <nl> + strip_files = " : empty " , <nl> + supports_param_files = 1 , <nl> + ) <nl> + <nl> + cc_toolchain_config ( <nl> + name = " local " , <nl> + cpu = " k8 " , <nl> + compiler = " gcc " , <nl> + toolchain_identifier = " local " , <nl> + host_system_name = " local " , <nl> + target_system_name = " local " , <nl> + target_libc = " local " , <nl> + abi_version = " local " , <nl> + abi_libc_version = " local " , <nl> + cxx_builtin_include_directories = [ " / usr / lib / gcc / x86_64 - linux - gnu / 7 / include " , <nl> + " / usr / local / include " , <nl> + " / usr / lib / gcc / x86_64 - linux - gnu / 7 / include - fixed " , <nl> + " / usr / include / x86_64 - linux - gnu " , <nl> + " / usr / include " , <nl> + " / usr / include / c + + / 7 " , <nl> + " / usr / include / x86_64 - linux - gnu / c + + / 7 " , <nl> + " / usr / include / c + + / 7 / backward " ] , <nl> + tool_paths = { " ar " : " / usr / bin / ar " , <nl> + " ld " : " / usr / bin / ld " , <nl> + " cpp " : " / usr / bin / cpp " , <nl> + " gcc " : " / usr / bin / gcc " , <nl> + " dwp " : " / usr / bin / dwp " , <nl> + " gcov " : " / usr / bin / gcov " , <nl> + " nm " : " / usr / bin / nm " , <nl> + " objcopy " : " / usr / bin / objcopy " , <nl> + " objdump " : " / usr / bin / objdump " , <nl> + " strip " : " / usr / bin / strip " } , <nl> + compile_flags = [ " - U_FORTIFY_SOURCE " , <nl> + " - fstack - protector " , <nl> + " - Wall " , <nl> + " - Wunused - but - set - parameter " , <nl> + " - Wno - free - nonheap - object " , <nl> + " - fno - omit - frame - pointer " ] , <nl> + opt_compile_flags = [ " - g0 " , <nl> + " - O2 " , <nl> + " - D_FORTIFY_SOURCE = 1 " , <nl> + " - DNDEBUG " , <nl> + " - ffunction - sections " , <nl> + " - fdata - sections " ] , <nl> + dbg_compile_flags = [ " - g " ] , <nl> + cxx_flags = [ " - std = c + + 0x " ] , <nl> + link_flags = [ " - fuse - ld = gold " , <nl> + " - Wl , - no - as - needed " , <nl> + " - Wl , - z , relro , - z , now " , <nl> + " - B / usr / bin " , <nl> + " - pass - exit - codes " , <nl> + " - lm " , <nl> + " - static - libgcc " ] , <nl> + link_libs = [ " - l : libstdc + + . a " ] , <nl> + opt_link_flags = [ " - Wl , - - gc - sections " ] , <nl> + unfiltered_compile_flags = [ " - fno - canonical - system - headers " , <nl> + " - Wno - builtin - macro - redefined " , <nl> + " - D__DATE__ = \ " redacted \ " " , <nl> + " - D__TIMESTAMP__ = \ " redacted \ " " , <nl> + " - D__TIME__ = \ " redacted \ " " ] , <nl> + coverage_compile_flags = [ " - - coverage " ] , <nl> + coverage_link_flags = [ " - - coverage " ] , <nl> + supports_start_end_lib = True , <nl> + ) <nl> + <nl> + # Android tooling requires a default toolchain for the armeabi - v7a cpu . <nl> + cc_toolchain ( <nl> + name = " cc - compiler - armeabi - v7a " , <nl> + toolchain_identifier = " stub_armeabi - v7a " , <nl> + toolchain_config = " : stub_armeabi - v7a " , <nl> + all_files = " : empty " , <nl> + ar_files = " : empty " , <nl> + as_files = " : empty " , <nl> + compiler_files = " : empty " , <nl> + dwp_files = " : empty " , <nl> + linker_files = " : empty " , <nl> + objcopy_files = " : empty " , <nl> + strip_files = " : empty " , <nl> + supports_param_files = 1 , <nl> + ) <nl> + <nl> + armeabi_cc_toolchain_config ( name = " stub_armeabi - v7a " ) <nl> new file mode 100755 <nl> index 00000000000 . . 94e0720bf6c <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / gcc / bazel_0 . 28 . 0 / cc / armeabi_cc_toolchain_config . bzl <nl> <nl> + # Copyright 2019 The Bazel Authors . All rights reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + " " " A Starlark cc_toolchain configuration rule " " " <nl> + <nl> + load ( <nl> + " @ bazel_tools / / tools / cpp : cc_toolchain_config_lib . bzl " , <nl> + " feature " , <nl> + " tool_path " , <nl> + ) <nl> + <nl> + def _impl ( ctx ) : <nl> + toolchain_identifier = " stub_armeabi - v7a " <nl> + host_system_name = " armeabi - v7a " <nl> + target_system_name = " armeabi - v7a " <nl> + target_cpu = " armeabi - v7a " <nl> + target_libc = " armeabi - v7a " <nl> + compiler = " compiler " <nl> + abi_version = " armeabi - v7a " <nl> + abi_libc_version = " armeabi - v7a " <nl> + cc_target_os = None <nl> + builtin_sysroot = None <nl> + action_configs = [ ] <nl> + <nl> + supports_pic_feature = feature ( name = " supports_pic " , enabled = True ) <nl> + supports_dynamic_linker_feature = feature ( name = " supports_dynamic_linker " , enabled = True ) <nl> + features = [ supports_dynamic_linker_feature , supports_pic_feature ] <nl> + <nl> + cxx_builtin_include_directories = [ ] <nl> + artifact_name_patterns = [ ] <nl> + make_variables = [ ] <nl> + <nl> + tool_paths = [ <nl> + tool_path ( name = " ar " , path = " / bin / false " ) , <nl> + tool_path ( name = " compat - ld " , path = " / bin / false " ) , <nl> + tool_path ( name = " cpp " , path = " / bin / false " ) , <nl> + tool_path ( name = " dwp " , path = " / bin / false " ) , <nl> + tool_path ( name = " gcc " , path = " / bin / false " ) , <nl> + tool_path ( name = " gcov " , path = " / bin / false " ) , <nl> + tool_path ( name = " ld " , path = " / bin / false " ) , <nl> + tool_path ( name = " nm " , path = " / bin / false " ) , <nl> + tool_path ( name = " objcopy " , path = " / bin / false " ) , <nl> + tool_path ( name = " objdump " , path = " / bin / false " ) , <nl> + tool_path ( name = " strip " , path = " / bin / false " ) , <nl> + ] <nl> + <nl> + return cc_common . create_cc_toolchain_config_info ( <nl> + ctx = ctx , <nl> + features = features , <nl> + action_configs = action_configs , <nl> + artifact_name_patterns = artifact_name_patterns , <nl> + cxx_builtin_include_directories = cxx_builtin_include_directories , <nl> + toolchain_identifier = toolchain_identifier , <nl> + host_system_name = host_system_name , <nl> + target_system_name = target_system_name , <nl> + target_cpu = target_cpu , <nl> + target_libc = target_libc , <nl> + compiler = compiler , <nl> + abi_version = abi_version , <nl> + abi_libc_version = abi_libc_version , <nl> + tool_paths = tool_paths , <nl> + make_variables = make_variables , <nl> + builtin_sysroot = builtin_sysroot , <nl> + cc_target_os = cc_target_os , <nl> + ) <nl> + <nl> + armeabi_cc_toolchain_config = rule ( <nl> + implementation = _impl , <nl> + attrs = { } , <nl> + provides = [ CcToolchainConfigInfo ] , <nl> + ) <nl> new file mode 100755 <nl> index 00000000000 . . f2b12d96296 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / gcc / bazel_0 . 28 . 0 / cc / cc_toolchain_config . bzl <nl> <nl> + # Copyright 2019 The Bazel Authors . All rights reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + " " " A Starlark cc_toolchain configuration rule " " " <nl> + <nl> + load ( <nl> + " @ bazel_tools / / tools / cpp : cc_toolchain_config_lib . bzl " , <nl> + " feature " , <nl> + " feature_set " , <nl> + " flag_group " , <nl> + " flag_set " , <nl> + " tool_path " , <nl> + " variable_with_value " , <nl> + " with_feature_set " , <nl> + ) <nl> + load ( " @ bazel_tools / / tools / build_defs / cc : action_names . bzl " , " ACTION_NAMES " ) <nl> + <nl> + all_compile_actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . clif_match , <nl> + ACTION_NAMES . lto_backend , <nl> + ] <nl> + <nl> + all_cpp_compile_actions = [ <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . clif_match , <nl> + ] <nl> + <nl> + preprocessor_compile_actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . clif_match , <nl> + ] <nl> + <nl> + codegen_compile_actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ] <nl> + <nl> + all_link_actions = [ <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ] <nl> + <nl> + def _impl ( ctx ) : <nl> + tool_paths = [ <nl> + tool_path ( name = name , path = path ) <nl> + for name , path in ctx . attr . tool_paths . items ( ) <nl> + ] <nl> + action_configs = [ ] <nl> + <nl> + supports_pic_feature = feature ( <nl> + name = " supports_pic " , <nl> + enabled = True , <nl> + ) <nl> + supports_start_end_lib_feature = feature ( <nl> + name = " supports_start_end_lib " , <nl> + enabled = True , <nl> + ) <nl> + <nl> + default_compile_flags_feature = feature ( <nl> + name = " default_compile_flags " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . compile_flags , <nl> + ) , <nl> + ] if ctx . attr . compile_flags else [ ] ) , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . dbg_compile_flags , <nl> + ) , <nl> + ] if ctx . attr . dbg_compile_flags else [ ] ) , <nl> + with_features = [ with_feature_set ( features = [ " dbg " ] ) ] , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . opt_compile_flags , <nl> + ) , <nl> + ] if ctx . attr . opt_compile_flags else [ ] ) , <nl> + with_features = [ with_feature_set ( features = [ " opt " ] ) ] , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . cxx_flags , <nl> + ) , <nl> + ] if ctx . attr . cxx_flags else [ ] ) , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + default_link_flags_feature = feature ( <nl> + name = " default_link_flags " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . link_flags , <nl> + ) , <nl> + ] if ctx . attr . link_flags else [ ] ) , <nl> + ) , <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . opt_link_flags , <nl> + ) , <nl> + ] if ctx . attr . opt_link_flags else [ ] ) , <nl> + with_features = [ with_feature_set ( features = [ " opt " ] ) ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + dbg_feature = feature ( name = " dbg " ) <nl> + <nl> + opt_feature = feature ( name = " opt " ) <nl> + <nl> + sysroot_feature = feature ( <nl> + name = " sysroot " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - - sysroot = % { sysroot } " ] , <nl> + expand_if_available = " sysroot " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + fdo_optimize_feature = feature ( <nl> + name = " fdo_optimize " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ ACTION_NAMES . c_compile , ACTION_NAMES . cpp_compile ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - fprofile - use = % { fdo_profile_path } " , <nl> + " - fprofile - correction " , <nl> + ] , <nl> + expand_if_available = " fdo_profile_path " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + provides = [ " profile " ] , <nl> + ) <nl> + <nl> + supports_dynamic_linker_feature = feature ( name = " supports_dynamic_linker " , enabled = True ) <nl> + <nl> + user_compile_flags_feature = feature ( <nl> + name = " user_compile_flags " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " % { user_compile_flags } " ] , <nl> + iterate_over = " user_compile_flags " , <nl> + expand_if_available = " user_compile_flags " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + unfiltered_compile_flags_feature = feature ( <nl> + name = " unfiltered_compile_flags " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( <nl> + flags = ctx . attr . unfiltered_compile_flags , <nl> + ) , <nl> + ] if ctx . attr . unfiltered_compile_flags else [ ] ) , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + library_search_directories_feature = feature ( <nl> + name = " library_search_directories " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - L % { library_search_directories } " ] , <nl> + iterate_over = " library_search_directories " , <nl> + expand_if_available = " library_search_directories " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + static_libgcc_feature = feature ( <nl> + name = " static_libgcc " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ] , <nl> + flag_groups = [ flag_group ( flags = [ " - static - libgcc " ] ) ] , <nl> + with_features = [ <nl> + with_feature_set ( features = [ " static_link_cpp_runtimes " ] ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + pic_feature = feature ( <nl> + name = " pic " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( flags = [ " - fPIC " ] , expand_if_available = " pic " ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + per_object_debug_info_feature = feature ( <nl> + name = " per_object_debug_info " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - gsplit - dwarf " ] , <nl> + expand_if_available = " per_object_debug_info_file " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + preprocessor_defines_feature = feature ( <nl> + name = " preprocessor_defines " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - D % { preprocessor_defines } " ] , <nl> + iterate_over = " preprocessor_defines " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + cs_fdo_optimize_feature = feature ( <nl> + name = " cs_fdo_optimize " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ ACTION_NAMES . lto_backend ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - fprofile - use = % { fdo_profile_path } " , <nl> + " - Xclang - only = - Wno - profile - instr - unprofiled " , <nl> + " - Xclang - only = - Wno - profile - instr - out - of - date " , <nl> + " - fprofile - correction " , <nl> + ] , <nl> + expand_if_available = " fdo_profile_path " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + provides = [ " csprofile " ] , <nl> + ) <nl> + <nl> + autofdo_feature = feature ( <nl> + name = " autofdo " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ ACTION_NAMES . c_compile , ACTION_NAMES . cpp_compile ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - fauto - profile = % { fdo_profile_path } " , <nl> + " - fprofile - correction " , <nl> + ] , <nl> + expand_if_available = " fdo_profile_path " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + provides = [ " profile " ] , <nl> + ) <nl> + <nl> + runtime_library_search_directories_feature = feature ( <nl> + name = " runtime_library_search_directories " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + iterate_over = " runtime_library_search_directories " , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - Wl , - rpath , $ EXEC_ORIGIN / % { runtime_library_search_directories } " , <nl> + ] , <nl> + expand_if_true = " is_cc_test " , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ <nl> + " - Wl , - rpath , $ ORIGIN / % { runtime_library_search_directories } " , <nl> + ] , <nl> + expand_if_false = " is_cc_test " , <nl> + ) , <nl> + ] , <nl> + expand_if_available = <nl> + " runtime_library_search_directories " , <nl> + ) , <nl> + ] , <nl> + with_features = [ <nl> + with_feature_set ( features = [ " static_link_cpp_runtimes " ] ) , <nl> + ] , <nl> + ) , <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + iterate_over = " runtime_library_search_directories " , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - Wl , - rpath , $ ORIGIN / % { runtime_library_search_directories } " , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + expand_if_available = <nl> + " runtime_library_search_directories " , <nl> + ) , <nl> + ] , <nl> + with_features = [ <nl> + with_feature_set ( <nl> + not_features = [ " static_link_cpp_runtimes " ] , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + fission_support_feature = feature ( <nl> + name = " fission_support " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - Wl , - - gdb - index " ] , <nl> + expand_if_available = " is_using_fission " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + shared_flag_feature = feature ( <nl> + name = " shared_flag " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ] , <nl> + flag_groups = [ flag_group ( flags = [ " - shared " ] ) ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + random_seed_feature = feature ( <nl> + name = " random_seed " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_module_codegen , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - frandom - seed = % { output_file } " ] , <nl> + expand_if_available = " output_file " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + includes_feature = feature ( <nl> + name = " includes " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . clif_match , <nl> + ACTION_NAMES . objc_compile , <nl> + ACTION_NAMES . objcpp_compile , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - include " , " % { includes } " ] , <nl> + iterate_over = " includes " , <nl> + expand_if_available = " includes " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + fdo_instrument_feature = feature ( <nl> + name = " fdo_instrument " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - fprofile - generate = % { fdo_instrument_path } " , <nl> + " - fno - data - sections " , <nl> + ] , <nl> + expand_if_available = " fdo_instrument_path " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + provides = [ " profile " ] , <nl> + ) <nl> + <nl> + cs_fdo_instrument_feature = feature ( <nl> + name = " cs_fdo_instrument " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . lto_backend , <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - fcs - profile - generate = % { cs_fdo_instrument_path } " , <nl> + ] , <nl> + expand_if_available = " cs_fdo_instrument_path " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + provides = [ " csprofile " ] , <nl> + ) <nl> + <nl> + include_paths_feature = feature ( <nl> + name = " include_paths " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . linkstamp_compile , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . clif_match , <nl> + ACTION_NAMES . objc_compile , <nl> + ACTION_NAMES . objcpp_compile , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - iquote " , " % { quote_include_paths } " ] , <nl> + iterate_over = " quote_include_paths " , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - I % { include_paths } " ] , <nl> + iterate_over = " include_paths " , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - isystem " , " % { system_include_paths } " ] , <nl> + iterate_over = " system_include_paths " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + symbol_counts_feature = feature ( <nl> + name = " symbol_counts " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - Wl , - - print - symbol - counts = % { symbol_counts_output } " , <nl> + ] , <nl> + expand_if_available = " symbol_counts_output " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + llvm_coverage_map_format_feature = feature ( <nl> + name = " llvm_coverage_map_format " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . objc_compile , <nl> + ACTION_NAMES . objcpp_compile , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - fprofile - instr - generate " , <nl> + " - fcoverage - mapping " , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + " objc - executable " , <nl> + " objc + + - executable " , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( flags = [ " - fprofile - instr - generate " ] ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + requires = [ feature_set ( features = [ " coverage " ] ) ] , <nl> + provides = [ " profile " ] , <nl> + ) <nl> + <nl> + strip_debug_symbols_feature = feature ( <nl> + name = " strip_debug_symbols " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - Wl , - S " ] , <nl> + expand_if_available = " strip_debug_symbols " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + build_interface_libraries_feature = feature ( <nl> + name = " build_interface_libraries " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " % { generate_interface_library } " , <nl> + " % { interface_library_builder_path } " , <nl> + " % { interface_library_input_path } " , <nl> + " % { interface_library_output_path } " , <nl> + ] , <nl> + expand_if_available = " generate_interface_library " , <nl> + ) , <nl> + ] , <nl> + with_features = [ <nl> + with_feature_set ( <nl> + features = [ " supports_interface_shared_libraries " ] , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + libraries_to_link_feature = feature ( <nl> + name = " libraries_to_link " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + iterate_over = " libraries_to_link " , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - Wl , - - start - lib " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " object_file_group " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - Wl , - whole - archive " ] , <nl> + expand_if_true = <nl> + " libraries_to_link . is_whole_archive " , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " % { libraries_to_link . object_files } " ] , <nl> + iterate_over = " libraries_to_link . object_files " , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " object_file_group " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " % { libraries_to_link . name } " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " object_file " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " % { libraries_to_link . name } " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " interface_library " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " % { libraries_to_link . name } " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " static_library " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - l % { libraries_to_link . name } " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " dynamic_library " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - l : % { libraries_to_link . name } " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " versioned_dynamic_library " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - Wl , - no - whole - archive " ] , <nl> + expand_if_true = " libraries_to_link . is_whole_archive " , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - Wl , - - end - lib " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " object_file_group " , <nl> + ) , <nl> + ) , <nl> + ] , <nl> + expand_if_available = " libraries_to_link " , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " - Wl , @ % { thinlto_param_file } " ] , <nl> + expand_if_true = " thinlto_param_file " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + user_link_flags_feature = feature ( <nl> + name = " user_link_flags " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " % { user_link_flags } " ] , <nl> + iterate_over = " user_link_flags " , <nl> + expand_if_available = " user_link_flags " , <nl> + ) , <nl> + ] + ( [ flag_group ( flags = ctx . attr . link_libs ) ] if ctx . attr . link_libs else [ ] ) , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + fdo_prefetch_hints_feature = feature ( <nl> + name = " fdo_prefetch_hints " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . lto_backend , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ <nl> + " - Xclang - only = - mllvm " , <nl> + " - Xclang - only = - prefetch - hints - file = % { fdo_prefetch_hints_path } " , <nl> + ] , <nl> + expand_if_available = " fdo_prefetch_hints_path " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + linkstamps_feature = feature ( <nl> + name = " linkstamps " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = all_link_actions , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " % { linkstamp_paths } " ] , <nl> + iterate_over = " linkstamp_paths " , <nl> + expand_if_available = " linkstamp_paths " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + gcc_coverage_map_format_feature = feature ( <nl> + name = " gcc_coverage_map_format " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . objc_compile , <nl> + ACTION_NAMES . objcpp_compile , <nl> + " objc - executable " , <nl> + " objc + + - executable " , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - fprofile - arcs " , " - ftest - coverage " ] , <nl> + expand_if_available = " gcov_gcno_file " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ] , <nl> + flag_groups = [ flag_group ( flags = [ " - - coverage " ] ) ] , <nl> + ) , <nl> + ] , <nl> + requires = [ feature_set ( features = [ " coverage " ] ) ] , <nl> + provides = [ " profile " ] , <nl> + ) <nl> + <nl> + archiver_flags_feature = feature ( <nl> + name = " archiver_flags " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ ACTION_NAMES . cpp_link_static_library ] , <nl> + flag_groups = [ <nl> + flag_group ( flags = [ " rcsD " ] ) , <nl> + flag_group ( <nl> + flags = [ " % { output_execpath } " ] , <nl> + expand_if_available = " output_execpath " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ ACTION_NAMES . cpp_link_static_library ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + iterate_over = " libraries_to_link " , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " % { libraries_to_link . name } " ] , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " object_file " , <nl> + ) , <nl> + ) , <nl> + flag_group ( <nl> + flags = [ " % { libraries_to_link . object_files } " ] , <nl> + iterate_over = " libraries_to_link . object_files " , <nl> + expand_if_equal = variable_with_value ( <nl> + name = " libraries_to_link . type " , <nl> + value = " object_file_group " , <nl> + ) , <nl> + ) , <nl> + ] , <nl> + expand_if_available = " libraries_to_link " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + force_pic_flags_feature = feature ( <nl> + name = " force_pic_flags " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ ACTION_NAMES . cpp_link_executable ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - pie " ] , <nl> + expand_if_available = " force_pic " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + dependency_file_feature = feature ( <nl> + name = " dependency_file " , <nl> + enabled = True , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . assemble , <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ACTION_NAMES . objc_compile , <nl> + ACTION_NAMES . objcpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . clif_match , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - MD " , " - MF " , " % { dependency_file } " ] , <nl> + expand_if_available = " dependency_file " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + dynamic_library_linker_tool_feature = feature ( <nl> + name = " dynamic_library_linker_tool " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " + cppLinkDynamicLibraryToolPath + " ] , <nl> + expand_if_available = " generate_interface_library " , <nl> + ) , <nl> + ] , <nl> + with_features = [ <nl> + with_feature_set ( <nl> + features = [ " supports_interface_shared_libraries " ] , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + output_execpath_flags_feature = feature ( <nl> + name = " output_execpath_flags " , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ] , <nl> + flag_groups = [ <nl> + flag_group ( <nl> + flags = [ " - o " , " % { output_execpath } " ] , <nl> + expand_if_available = " output_execpath " , <nl> + ) , <nl> + ] , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + # Note that we also set - - coverage for c + + - link - nodeps - dynamic - library . The <nl> + # generated code contains references to gcov symbols , and the dynamic linker <nl> + # can ' t resolve them unless the library is linked against gcov . <nl> + coverage_feature = feature ( <nl> + name = " coverage " , <nl> + provides = [ " profile " ] , <nl> + flag_sets = [ <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . preprocess_assemble , <nl> + ACTION_NAMES . c_compile , <nl> + ACTION_NAMES . cpp_compile , <nl> + ACTION_NAMES . cpp_header_parsing , <nl> + ACTION_NAMES . cpp_module_compile , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( flags = ctx . attr . coverage_compile_flags ) , <nl> + ] if ctx . attr . coverage_compile_flags else [ ] ) , <nl> + ) , <nl> + flag_set ( <nl> + actions = [ <nl> + ACTION_NAMES . cpp_link_dynamic_library , <nl> + ACTION_NAMES . cpp_link_nodeps_dynamic_library , <nl> + ACTION_NAMES . cpp_link_executable , <nl> + ] , <nl> + flag_groups = ( [ <nl> + flag_group ( flags = ctx . attr . coverage_link_flags ) , <nl> + ] if ctx . attr . coverage_link_flags else [ ] ) , <nl> + ) , <nl> + ] , <nl> + ) <nl> + <nl> + is_linux = ctx . attr . target_libc ! = " macosx " <nl> + <nl> + # TODO ( # 8303 ) : Mac crosstool should also declare every feature . <nl> + if is_linux : <nl> + features = [ <nl> + dependency_file_feature , <nl> + random_seed_feature , <nl> + pic_feature , <nl> + per_object_debug_info_feature , <nl> + preprocessor_defines_feature , <nl> + includes_feature , <nl> + include_paths_feature , <nl> + fdo_instrument_feature , <nl> + cs_fdo_instrument_feature , <nl> + cs_fdo_optimize_feature , <nl> + fdo_prefetch_hints_feature , <nl> + autofdo_feature , <nl> + build_interface_libraries_feature , <nl> + dynamic_library_linker_tool_feature , <nl> + symbol_counts_feature , <nl> + shared_flag_feature , <nl> + linkstamps_feature , <nl> + output_execpath_flags_feature , <nl> + runtime_library_search_directories_feature , <nl> + library_search_directories_feature , <nl> + archiver_flags_feature , <nl> + force_pic_flags_feature , <nl> + fission_support_feature , <nl> + strip_debug_symbols_feature , <nl> + coverage_feature , <nl> + supports_pic_feature , <nl> + ] + ( <nl> + [ <nl> + supports_start_end_lib_feature , <nl> + ] if ctx . attr . supports_start_end_lib else [ ] <nl> + ) + [ <nl> + default_compile_flags_feature , <nl> + default_link_flags_feature , <nl> + libraries_to_link_feature , <nl> + user_link_flags_feature , <nl> + static_libgcc_feature , <nl> + fdo_optimize_feature , <nl> + supports_dynamic_linker_feature , <nl> + dbg_feature , <nl> + opt_feature , <nl> + user_compile_flags_feature , <nl> + sysroot_feature , <nl> + unfiltered_compile_flags_feature , <nl> + ] <nl> + else : <nl> + features = [ <nl> + supports_pic_feature , <nl> + ] + ( <nl> + [ <nl> + supports_start_end_lib_feature , <nl> + ] if ctx . attr . supports_start_end_lib else [ ] <nl> + ) + [ <nl> + coverage_feature , <nl> + default_compile_flags_feature , <nl> + default_link_flags_feature , <nl> + fdo_optimize_feature , <nl> + supports_dynamic_linker_feature , <nl> + dbg_feature , <nl> + opt_feature , <nl> + user_compile_flags_feature , <nl> + sysroot_feature , <nl> + unfiltered_compile_flags_feature , <nl> + ] <nl> + <nl> + return cc_common . create_cc_toolchain_config_info ( <nl> + ctx = ctx , <nl> + features = features , <nl> + action_configs = action_configs , <nl> + cxx_builtin_include_directories = ctx . attr . cxx_builtin_include_directories , <nl> + toolchain_identifier = ctx . attr . toolchain_identifier , <nl> + host_system_name = ctx . attr . host_system_name , <nl> + target_system_name = ctx . attr . target_system_name , <nl> + target_cpu = ctx . attr . cpu , <nl> + target_libc = ctx . attr . target_libc , <nl> + compiler = ctx . attr . compiler , <nl> + abi_version = ctx . attr . abi_version , <nl> + abi_libc_version = ctx . attr . abi_libc_version , <nl> + tool_paths = tool_paths , <nl> + ) <nl> + <nl> + cc_toolchain_config = rule ( <nl> + implementation = _impl , <nl> + attrs = { <nl> + " cpu " : attr . string ( mandatory = True ) , <nl> + " compiler " : attr . string ( mandatory = True ) , <nl> + " toolchain_identifier " : attr . string ( mandatory = True ) , <nl> + " host_system_name " : attr . string ( mandatory = True ) , <nl> + " target_system_name " : attr . string ( mandatory = True ) , <nl> + " target_libc " : attr . string ( mandatory = True ) , <nl> + " abi_version " : attr . string ( mandatory = True ) , <nl> + " abi_libc_version " : attr . string ( mandatory = True ) , <nl> + " cxx_builtin_include_directories " : attr . string_list ( ) , <nl> + " tool_paths " : attr . string_dict ( ) , <nl> + " compile_flags " : attr . string_list ( ) , <nl> + " dbg_compile_flags " : attr . string_list ( ) , <nl> + " opt_compile_flags " : attr . string_list ( ) , <nl> + " cxx_flags " : attr . string_list ( ) , <nl> + " link_flags " : attr . string_list ( ) , <nl> + " link_libs " : attr . string_list ( ) , <nl> + " opt_link_flags " : attr . string_list ( ) , <nl> + " unfiltered_compile_flags " : attr . string_list ( ) , <nl> + " coverage_compile_flags " : attr . string_list ( ) , <nl> + " coverage_link_flags " : attr . string_list ( ) , <nl> + " supports_start_end_lib " : attr . bool ( ) , <nl> + } , <nl> + provides = [ CcToolchainConfigInfo ] , <nl> + ) <nl> new file mode 100755 <nl> index 00000000000 . . f246528abf2 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / gcc / bazel_0 . 28 . 0 / cc / cc_wrapper . sh <nl> <nl> + # ! / bin / bash <nl> + # <nl> + # Copyright 2015 The Bazel Authors . All rights reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + # <nl> + # Ship the environment to the C + + action <nl> + # <nl> + set - eu <nl> + <nl> + # Set - up the environment <nl> + <nl> + <nl> + # Call the C + + compiler <nl> + / usr / bin / gcc " $ @ " <nl> new file mode 100644 <nl> index 00000000000 . . 2d431bd2ce0 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / gcc / bazel_0 . 28 . 0 / config / BUILD <nl> <nl> + # Copyright 2016 The Bazel Authors . All rights reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # This file is auto - generated by an rbe_autoconfig repository rule <nl> + # and should not be modified directly . <nl> + # See @ bazel_toolchains / / rules : rbe_repo . bzl <nl> + <nl> + package ( default_visibility = [ " / / visibility : public " ] ) <nl> + <nl> + toolchain ( <nl> + name = " cc - toolchain " , <nl> + exec_compatible_with = [ <nl> + " @ bazel_tools / / platforms : x86_64 " , <nl> + " @ bazel_tools / / platforms : linux " , <nl> + " @ bazel_tools / / tools / cpp : clang " , <nl> + ] , <nl> + target_compatible_with = [ <nl> + " @ bazel_tools / / platforms : linux " , <nl> + " @ bazel_tools / / platforms : x86_64 " , <nl> + ] , <nl> + toolchain = " / / bazel / toolchains / configs / gcc / bazel_0 . 28 . 0 / cc : cc - compiler - k8 " , <nl> + toolchain_type = " @ bazel_tools / / tools / cpp : toolchain_type " , <nl> + ) <nl> + <nl> + platform ( <nl> + name = " platform " , <nl> + constraint_values = [ <nl> + " @ bazel_tools / / platforms : x86_64 " , <nl> + " @ bazel_tools / / platforms : linux " , <nl> + " @ bazel_tools / / tools / cpp : clang " , <nl> + ] , <nl> + remote_execution_properties = " " " <nl> + properties : { <nl> + name : " container - image " <nl> + value : " docker : / / gcr . io / envoy - ci / envoy - build @ sha256 : 9dbe1cba2b3340d49a25a1d286c8d49083ec986a6fead27f487e80ca334f065f " <nl> + } <nl> + properties { <nl> + name : " OSFamily " <nl> + value : " Linux " <nl> + } <nl> + " " " , <nl> + ) <nl> new file mode 100644 <nl> index 00000000000 . . 7c273a5b0e4 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / gcc / bazel_0 . 28 . 0 / java / BUILD <nl> <nl> + # Copyright 2016 The Bazel Authors . All rights reserved . <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # This file is auto - generated by an rbe_autoconfig repository rule <nl> + # and should not be modified directly . <nl> + # See @ bazel_toolchains / / rules : rbe_repo . bzl <nl> + <nl> + package ( default_visibility = [ " / / visibility : public " ] ) <nl> + <nl> + java_runtime ( <nl> + name = " jdk " , <nl> + srcs = [ ] , <nl> + java_home = " / usr / lib / jvm / java - 8 - openjdk - amd64 " , <nl> + ) <nl> new file mode 100644 <nl> index 00000000000 . . 6704b14fa54 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / configs / versions . bzl <nl> <nl> + # Generated file , do not modify by hand <nl> + # Generated by ' rbe_ubuntu_gcc_gen ' rbe_autoconfig rule <nl> + " " " Definitions to be used in rbe_repo attr of an rbe_autoconf rule " " " <nl> + toolchain_config_spec0 = struct ( config_repos = [ ] , create_cc_configs = True , create_java_configs = True , env = { " BAZEL_COMPILER " : " clang " , " BAZEL_LINKLIBS " : " - l % : libstdc + + . a " , " BAZEL_LINKOPTS " : " - lm : - static - libgcc " , " BAZEL_USE_LLVM_NATIVE_COVERAGE " : " 1 " , " GCOV " : " llvm - profdata " , " CC " : " clang " , " CXX " : " clang + + " , " PATH " : " / usr / sbin : / usr / bin : / sbin : / bin : / usr / lib / llvm - 8 / bin " } , java_home = " / usr / lib / jvm / java - 8 - openjdk - amd64 " , name = " clang " ) <nl> + toolchain_config_spec1 = struct ( config_repos = [ ] , create_cc_configs = True , create_java_configs = True , env = { " BAZEL_COMPILER " : " gcc " , " BAZEL_LINKLIBS " : " - l % : libstdc + + . a " , " BAZEL_LINKOPTS " : " - lm : - static - libgcc " , " CC " : " gcc " , " CXX " : " g + + " , " PATH " : " / usr / sbin : / usr / bin : / sbin : / bin : / usr / lib / llvm - 8 / bin " } , java_home = " / usr / lib / jvm / java - 8 - openjdk - amd64 " , name = " gcc " ) <nl> + _TOOLCHAIN_CONFIG_SPECS = [ toolchain_config_spec0 , toolchain_config_spec1 ] <nl> + _BAZEL_TO_CONFIG_SPEC_NAMES = { " 0 . 28 . 0 " : [ " clang " , " gcc " ] } <nl> + LATEST = " sha256 : 9dbe1cba2b3340d49a25a1d286c8d49083ec986a6fead27f487e80ca334f065f " <nl> + _CONTAINER_TO_CONFIG_SPEC_NAMES = { " sha256 : 9dbe1cba2b3340d49a25a1d286c8d49083ec986a6fead27f487e80ca334f065f " : [ " clang " , " gcc " ] } <nl> + _DEFAULT_TOOLCHAIN_CONFIG_SPEC = toolchain_config_spec0 <nl> + TOOLCHAIN_CONFIG_AUTOGEN_SPEC = struct ( <nl> + bazel_to_config_spec_names_map = _BAZEL_TO_CONFIG_SPEC_NAMES , <nl> + container_to_config_spec_names_map = _CONTAINER_TO_CONFIG_SPEC_NAMES , <nl> + default_toolchain_config_spec = _DEFAULT_TOOLCHAIN_CONFIG_SPEC , <nl> + latest_container = LATEST , <nl> + toolchain_config_specs = _TOOLCHAIN_CONFIG_SPECS , <nl> + ) <nl> \ No newline at end of file <nl> new file mode 100644 <nl> index 00000000000 . . 3fc95e43532 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / empty . bzl <nl> <nl> + _BAZEL_TO_CONFIG_SPEC_NAMES = { } <nl> + <nl> + # sha256 digest of the latest version of the toolchain container . <nl> + LATEST = " " <nl> + <nl> + _CONTAINER_TO_CONFIG_SPEC_NAMES = { } <nl> + <nl> + _DEFAULT_TOOLCHAIN_CONFIG_SPEC = " " <nl> + <nl> + _TOOLCHAIN_CONFIG_SPECS = [ ] <nl> + <nl> + TOOLCHAIN_CONFIG_AUTOGEN_SPEC = struct ( <nl> + bazel_to_config_spec_names_map = _BAZEL_TO_CONFIG_SPEC_NAMES , <nl> + container_to_config_spec_names_map = _CONTAINER_TO_CONFIG_SPEC_NAMES , <nl> + default_toolchain_config_spec = _DEFAULT_TOOLCHAIN_CONFIG_SPEC , <nl> + latest_container = LATEST , <nl> + toolchain_config_specs = _TOOLCHAIN_CONFIG_SPECS , <nl> + ) <nl> new file mode 100644 <nl> index 00000000000 . . c1f32be5d78 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / rbe_toolchains_config . bzl <nl> <nl> + load ( " @ bazel_toolchains / / rules : rbe_repo . bzl " , " rbe_autoconfig " ) <nl> + load ( " @ envoy / / bazel / toolchains : configs / versions . bzl " , _generated_toolchain_config_suite_autogen_spec = " TOOLCHAIN_CONFIG_AUTOGEN_SPEC " ) <nl> + <nl> + _ENVOY_BUILD_IMAGE_REGISTRY = " gcr . io " <nl> + _ENVOY_BUILD_IMAGE_REPOSITORY = " envoy - ci / envoy - build " <nl> + _ENVOY_BUILD_IMAGE_DIGEST = " sha256 : 9dbe1cba2b3340d49a25a1d286c8d49083ec986a6fead27f487e80ca334f065f " <nl> + _ENVOY_BUILD_IMAGE_JAVA_HOME = " / usr / lib / jvm / java - 8 - openjdk - amd64 " <nl> + _CONFIGS_OUTPUT_BASE = " bazel / toolchains / configs " <nl> + <nl> + _CLANG_ENV = { <nl> + " BAZEL_COMPILER " : " clang " , <nl> + " BAZEL_LINKLIBS " : " - l % : libstdc + + . a " , <nl> + " BAZEL_LINKOPTS " : " - lm : - static - libgcc " , <nl> + " BAZEL_USE_LLVM_NATIVE_COVERAGE " : " 1 " , <nl> + " GCOV " : " llvm - profdata " , <nl> + " CC " : " clang " , <nl> + " CXX " : " clang + + " , <nl> + " PATH " : " / usr / sbin : / usr / bin : / sbin : / bin : / usr / lib / llvm - 8 / bin " , <nl> + } <nl> + <nl> + _GCC_ENV = { <nl> + " BAZEL_COMPILER " : " gcc " , <nl> + " BAZEL_LINKLIBS " : " - l % : libstdc + + . a " , <nl> + " BAZEL_LINKOPTS " : " - lm : - static - libgcc " , <nl> + " CC " : " gcc " , <nl> + " CXX " : " g + + " , <nl> + " PATH " : " / usr / sbin : / usr / bin : / sbin : / bin : / usr / lib / llvm - 8 / bin " , <nl> + } <nl> + <nl> + _TOOLCHAIN_CONFIG_SUITE_SPEC = { <nl> + " container_registry " : _ENVOY_BUILD_IMAGE_REGISTRY , <nl> + " container_repo " : _ENVOY_BUILD_IMAGE_REPOSITORY , <nl> + " output_base " : _CONFIGS_OUTPUT_BASE , <nl> + " repo_name " : " envoy " , <nl> + " toolchain_config_suite_autogen_spec " : _generated_toolchain_config_suite_autogen_spec , <nl> + } <nl> + <nl> + def _rbe_toolchains_generator ( ) : <nl> + rbe_autoconfig ( <nl> + name = " rbe_ubuntu_clang_gen " , <nl> + digest = _ENVOY_BUILD_IMAGE_DIGEST , <nl> + export_configs = True , <nl> + java_home = _ENVOY_BUILD_IMAGE_JAVA_HOME , <nl> + registry = _ENVOY_BUILD_IMAGE_REGISTRY , <nl> + repository = _ENVOY_BUILD_IMAGE_REPOSITORY , <nl> + env = _CLANG_ENV , <nl> + toolchain_config_spec_name = " clang " , <nl> + toolchain_config_suite_spec = _TOOLCHAIN_CONFIG_SUITE_SPEC , <nl> + use_checked_in_confs = " False " , <nl> + ) <nl> + <nl> + rbe_autoconfig ( <nl> + name = " rbe_ubuntu_gcc_gen " , <nl> + digest = _ENVOY_BUILD_IMAGE_DIGEST , <nl> + export_configs = True , <nl> + java_home = _ENVOY_BUILD_IMAGE_JAVA_HOME , <nl> + registry = _ENVOY_BUILD_IMAGE_REGISTRY , <nl> + repository = _ENVOY_BUILD_IMAGE_REPOSITORY , <nl> + env = _GCC_ENV , <nl> + toolchain_config_spec_name = " gcc " , <nl> + toolchain_config_suite_spec = _TOOLCHAIN_CONFIG_SUITE_SPEC , <nl> + use_checked_in_confs = " False " , <nl> + ) <nl> + <nl> + def _generated_rbe_toolchains ( ) : <nl> + rbe_autoconfig ( <nl> + name = " rbe_ubuntu_clang " , <nl> + digest = _ENVOY_BUILD_IMAGE_DIGEST , <nl> + export_configs = True , <nl> + java_home = _ENVOY_BUILD_IMAGE_JAVA_HOME , <nl> + registry = _ENVOY_BUILD_IMAGE_REGISTRY , <nl> + repository = _ENVOY_BUILD_IMAGE_REPOSITORY , <nl> + toolchain_config_spec_name = " clang " , <nl> + toolchain_config_suite_spec = _TOOLCHAIN_CONFIG_SUITE_SPEC , <nl> + use_checked_in_confs = " Force " , <nl> + ) <nl> + <nl> + def rbe_toolchains_config ( ) : <nl> + _rbe_toolchains_generator ( ) <nl> + _generated_rbe_toolchains ( ) <nl> new file mode 100755 <nl> index 00000000000 . . c71a0506d17 <nl> mmm / dev / null <nl> ppp b / bazel / toolchains / regenerate . sh <nl> <nl> + # ! / bin / bash <nl> + <nl> + set - e <nl> + <nl> + export RBE_AUTOCONF_ROOT = $ ( bazel info workspace ) <nl> + <nl> + rm - rf " $ { RBE_AUTOCONF_ROOT } / bazel / toolchains / configs / * " <nl> + cp - vf " $ { RBE_AUTOCONF_ROOT } / bazel / toolchains / empty . bzl " " $ { RBE_AUTOCONF_ROOT } / bazel / toolchains / configs / versions . bzl " <nl> + <nl> + # Bazel query is the right command so bazel won ' t fail itself . <nl> + bazel query " @ rbe_ubuntu_clang_gen / / . . . " <nl> + bazel query " @ rbe_ubuntu_gcc_gen / / . . . " <nl> mmm a / ci / WORKSPACE . filter . example <nl> ppp b / ci / WORKSPACE . filter . example <nl> workspace ( name = " envoy_filter_example " ) <nl> <nl> local_repository ( <nl> name = " envoy " , <nl> - path = " / source " , <nl> + path = " { ENVOY_SRCDIR } " , <nl> ) <nl> <nl> load ( " @ envoy / / bazel : api_repositories . bzl " , " envoy_api_dependencies " ) <nl> mmm a / ci / build_setup . sh <nl> ppp b / ci / build_setup . sh <nl> fi <nl> <nl> # Not sandboxing , since non - privileged Docker can ' t do nested namespaces . <nl> export BAZEL_QUERY_OPTIONS = " $ { BAZEL_OPTIONS } " <nl> - export BAZEL_BUILD_OPTIONS = " - - strategy = Genrule = standalone - - spawn_strategy = standalone \ <nl> - - - verbose_failures $ { BAZEL_OPTIONS } - - action_env = HOME - - action_env = PYTHONUSERBASE \ <nl> + export BAZEL_BUILD_OPTIONS = " - - verbose_failures $ { BAZEL_OPTIONS } - - action_env = HOME - - action_env = PYTHONUSERBASE \ <nl> - - local_cpu_resources = $ { NUM_CPUS } - - show_task_finish - - experimental_generate_json_trace_profile \ <nl> - - test_env = HOME - - test_env = PYTHONUSERBASE - - cache_test_results = no - - test_output = all \ <nl> $ { BAZEL_BUILD_EXTRA_OPTIONS } $ { BAZEL_EXTRA_TEST_OPTIONS } " <nl> if [ " $ 1 " ! = " - nofetch " ] ; then <nl> <nl> # This is the hash on https : / / github . com / envoyproxy / envoy - filter - example . git we pin to . <nl> ( cd " $ { ENVOY_FILTER_EXAMPLE_SRCDIR } " & & git fetch origin & & git checkout - f dcd3374baa9365ab7ab505018232994d6c8a8d81 ) <nl> - cp - f " $ { ENVOY_SRCDIR } " / ci / WORKSPACE . filter . example " $ { ENVOY_FILTER_EXAMPLE_SRCDIR } " / WORKSPACE <nl> + sed - e " s | { ENVOY_SRCDIR } | $ { ENVOY_SRCDIR } | " " $ { ENVOY_SRCDIR } " / ci / WORKSPACE . filter . example > " $ { ENVOY_FILTER_EXAMPLE_SRCDIR } " / WORKSPACE <nl> fi <nl> <nl> # Also setup some space for building Envoy standalone . <nl> mmm a / ci / do_ci . sh <nl> ppp b / ci / do_ci . sh <nl> elif [ [ " $ CI_TARGET " = = " bazel . asan " ] ] ; then <nl> rm - rf " $ { TAP_TMP } " <nl> mkdir - p " $ { TAP_TMP } " <nl> bazel_with_collection test $ { BAZEL_BUILD_OPTIONS } - c dbg - - config = clang - asan \ <nl> - / / test / extensions / transport_sockets / tls / integration : ssl_integration_test \ <nl> - - - test_env = TAP_PATH = " $ { TAP_TMP } / tap " <nl> + - - strategy = TestRunner = local - - test_env = TAP_PATH = " $ { TAP_TMP } / tap " \ <nl> + / / test / extensions / transport_sockets / tls / integration : ssl_integration_test <nl> # Verify that some pb_text files have been created . We can ' t check for pcap , <nl> # since tcpdump is not available in general due to CircleCI lack of support <nl> # for privileged Docker executors . <nl> mmm a / ci / setup_cache . sh <nl> ppp b / ci / setup_cache . sh <nl> elif [ [ ! - z " $ { BAZEL_REMOTE_CACHE } " ] ] ; then <nl> - - remote_cache = $ { BAZEL_REMOTE_CACHE } \ <nl> - - remote_instance_name = $ { BAZEL_REMOTE_INSTANCE } \ <nl> - - google_credentials = $ { GCP_SERVICE_ACCOUNT_KEY_FILE } \ <nl> - - - tls_enabled = true - - auth_enabled = true " <nl> + - - auth_enabled = true " <nl> echo " Set up bazel remote read / write cache at $ { BAZEL_REMOTE_CACHE } instance : $ { BAZEL_REMOTE_INSTANCE } . " <nl> else <nl> echo " No remote cache bucket is set , skipping setup remote cache . " <nl> mmm a / tools / check_format . py <nl> ppp b / tools / check_format . py <nl> <nl> <nl> EXCLUDED_PREFIXES = ( " . / generated / " , " . / thirdparty / " , " . / build " , " . / . git / " , " . / bazel - " , " . / . cache " , <nl> " . / source / extensions / extensions_build_config . bzl " , <nl> - " . / tools / testdata / check_format / " , " . / tools / pyformat / " ) <nl> + " . / bazel / toolchains / configs / " , " . / tools / testdata / check_format / " , <nl> + " . / tools / pyformat / " ) <nl> SUFFIXES = ( " BUILD " , " WORKSPACE " , " . bzl " , " . cc " , " . h " , " . java " , " . m " , " . md " , " . mm " , " . proto " , <nl> " . rst " ) <nl> DOCS_SUFFIX = ( " . md " , " . rst " ) <nl> mmm a / tools / envoy_build_fixer . py <nl> ppp b / tools / envoy_build_fixer . py <nl> def FixBuild ( path ) : <nl> if line ! = ' \ n ' : <nl> outlines . append ( ' \ n ' ) <nl> first = False <nl> - if path . startswith ( ' . / bazel / external / ' ) : <nl> + if path . startswith ( ' . / bazel / external / ' ) or path . startswith ( ' . / bazel / toolchains / ' ) : <nl> outlines . append ( line ) <nl> continue <nl> if line . startswith ( ' package ( ' ) and not path . endswith ( ' bazel / BUILD ' ) and not path . endswith ( <nl>
ci : enable clang based RBE in Azure pipelines ( )
envoyproxy/envoy
14c5371735e34ca3659b8332a19de24b5c776163
2019-07-18T21:42:19Z
mmm a / tensorflow / core / graph / mkl_layout_pass . cc <nl> ppp b / tensorflow / core / graph / mkl_layout_pass . cc <nl> MklLayoutRewritePass : : CheckForNodeFusion ( Node * a ) const { <nl> all_succ_has_been_visited = false ; <nl> break ; <nl> } <nl> - <nl> - / / All successor nodes of current node has been visited ( no match found ) , <nl> - / / pop the stack and mark current node as " visited " . <nl> - if ( all_succ_has_been_visited ) { <nl> - visited_nodes . insert ( current_node ) ; <nl> - work_stack . pop ( ) ; <nl> - - - node_checker ; <nl> - } <nl> } <nl> } <nl> + <nl> + / / All successor nodes of current node has been visited ( no match found ) , <nl> + / / pop the stack and mark current node as " visited " . <nl> + if ( all_succ_has_been_visited ) { <nl> + visited_nodes . insert ( current_node ) ; <nl> + work_stack . pop ( ) ; <nl> + - - node_checker ; <nl> + } <nl> + <nl> } else { <nl> - / / current node doesn ' t match , just break and stack will help us roll back . <nl> - break ; <nl> + / / current node doesn ' t match , pop stack to roll back . <nl> + visited_nodes . insert ( current_node ) ; <nl> + work_stack . pop ( ) ; <nl> + - - node_checker ; <nl> } <nl> } <nl> } <nl>
Fix 2 bugs in CheckNodeForFusion ( ) :
tensorflow/tensorflow
13ed0286c40c81f23a73a9cd773da4d1dd27197a
2018-10-31T05:35:28Z
mmm a / src / core / lib / surface / alarm_internal . h <nl> ppp b / src / core / lib / surface / alarm_internal . h <nl> extern grpc_tracer_flag grpc_trace_alarm_refcount ; <nl> <nl> # endif / * defined ( NDEBUG ) * / <nl> <nl> - # endif / / GRPC_CORE_LIB_SURFACE_ALARM_INTERNAL_H <nl> + # endif / * GRPC_CORE_LIB_SURFACE_ALARM_INTERNAL_H * / <nl>
Sanity tests ( header guard format
grpc/grpc
ad9dd52e595e877d2ddfd29a50a32765e9865422
2017-06-23T19:00:09Z
mmm a / Telegram / SourceFiles / apiwrap . cpp <nl> ppp b / Telegram / SourceFiles / apiwrap . cpp <nl> void ApiWrap : : forwardMessages ( <nl> + + shared - > requestsLeft ; <nl> } <nl> const auto requestType = Data : : Histories : : RequestType : : Send ; <nl> + const auto idsCopy = localIds ; <nl> histories . sendRequest ( history , requestType , [ = ] ( Fn < void ( ) > finish ) { <nl> history - > sendRequestId = request ( MTPmessages_ForwardMessages ( <nl> MTP_flags ( sendFlags ) , <nl> void ApiWrap : : forwardMessages ( <nl> shared - > callback ( ) ; <nl> } <nl> finish ( ) ; <nl> - } ) . fail ( [ = , ids = localIds ] ( const RPCError & error ) { <nl> - if ( ids ) { <nl> - for ( const auto & [ randomId , itemId ] : * ids ) { <nl> + } ) . fail ( [ = ] ( const RPCError & error ) { <nl> + if ( idsCopy ) { <nl> + for ( const auto & [ randomId , itemId ] : * idsCopy ) { <nl> sendMessageFail ( error , peer , randomId , itemId ) ; <nl> } <nl> } else { <nl> mmm a / Telegram / SourceFiles / calls / calls_top_bar . cpp <nl> ppp b / Telegram / SourceFiles / calls / calls_top_bar . cpp <nl> constexpr auto kMinorBlobAlpha = 76 . / 255 . ; <nl> <nl> constexpr auto kBlobLevelDuration1 = 250 ; <nl> constexpr auto kBlobLevelDuration2 = 120 ; <nl> + constexpr auto kBlobUpdateInterval = crl : : time ( 100 ) ; <nl> <nl> auto LinearBlobs ( ) - > std : : array < Ui : : Paint : : LinearBlobs : : BlobData , 3 > { <nl> return { { <nl> TopBar : : TopBar ( <nl> kBlobLevelDuration1 , <nl> kBlobLevelDuration2 , <nl> 1 . ) ) <nl> - , _gradients ( Colors ( ) , QPointF ( ) , QPointF ( ) ) { <nl> + , _blobsLevelTimer ( [ = ] { _blobsLastLevel = 0 . ; } ) <nl> + , _gradients ( Colors ( ) , QPointF ( ) , QPointF ( ) ) <nl> + , _updateDurationTimer ( [ = ] { updateDurationText ( ) ; } ) { <nl> initControls ( ) ; <nl> resize ( width ( ) , st : : callBarHeight ) ; <nl> } <nl> void TopBar : : initControls ( ) { <nl> BoxContext : : MainWindow ) ) ; <nl> } <nl> } ) ; <nl> - _updateDurationTimer . setCallback ( [ this ] { updateDurationText ( ) ; } ) ; <nl> updateDurationText ( ) ; <nl> <nl> initBlobs ( ) ; <nl> void TopBar : : initBlobs ( ) { <nl> return false ; <nl> } ) | rpl : : distinct_until_changed ( ) <nl> ) | rpl : : map ( [ ] ( bool animDisabled , bool hide , bool isBadState ) { <nl> - return isBadState | | ! ( ! animDisabled & & ! hide ) ; <nl> + return isBadState | | animDisabled | | hide ; <nl> } ) ; <nl> <nl> std : : move ( <nl> void TopBar : : initBlobs ( ) { <nl> if ( ! hide & & ! _blobsAnimation . animating ( ) ) { <nl> _blobsAnimation . start ( ) ; <nl> } <nl> + if ( hide ) { <nl> + _blobsLevelTimer . cancel ( ) ; <nl> + } else { <nl> + _blobsLastLevel = 0 . ; <nl> + _blobsLevelTimer . callEach ( kBlobUpdateInterval ) ; <nl> + } <nl> <nl> const auto from = hide ? 0 . : 1 . ; <nl> const auto to = hide ? 1 . : 0 . ; <nl> void TopBar : : initBlobs ( ) { <nl> <nl> _groupCall - > levelUpdates ( <nl> ) | rpl : : filter ( [ = ] ( const LevelUpdate & update ) { <nl> - return update . self ; <nl> + return ! * hideLastTime & & ( update . value > _blobsLastLevel ) ; <nl> } ) | rpl : : start_with_next ( [ = ] ( const LevelUpdate & update ) { <nl> - if ( * hideLastTime ) { <nl> - return ; <nl> - } <nl> - _blobsPaint - > setLevel ( update . value ) ; <nl> + _blobsLastLevel = update . value ; <nl> + _blobsPaint - > setLevel ( _blobsLastLevel ) ; <nl> } , _blobs - > lifetime ( ) ) ; <nl> <nl> _blobs - > setAttribute ( Qt : : WA_TransparentForMouseEvents ) ; <nl> mmm a / Telegram / SourceFiles / calls / calls_top_bar . h <nl> ppp b / Telegram / SourceFiles / calls / calls_top_bar . h <nl> class TopBar : public Ui : : RpWidget { <nl> object_ptr < Ui : : IconButton > _hangup ; <nl> base : : unique_qptr < Ui : : RpWidget > _blobs ; <nl> std : : unique_ptr < Ui : : Paint : : LinearBlobs > _blobsPaint ; <nl> + float _blobsLastLevel = 0 . ; <nl> + base : : Timer _blobsLevelTimer ; <nl> <nl> QBrush _groupBrush ; <nl> anim : : linear_gradients < MuteState > _gradients ; <nl> mmm a / Telegram / SourceFiles / settings / settings_codes . cpp <nl> ppp b / Telegram / SourceFiles / settings / settings_codes . cpp <nl> auto GenerateCodes ( ) { <nl> if ( const auto strong = weak . get ( ) ) { <nl> loadFor ( strong ) ; <nl> } else { <nl> - for ( const auto & [ index , account ] : Core : : App ( ) . domain ( ) . accounts ( ) ) { <nl> - loadFor ( account . get ( ) ) ; <nl> + for ( const auto & pair : Core : : App ( ) . domain ( ) . accounts ( ) ) { <nl> + loadFor ( pair . account . get ( ) ) ; <nl> } <nl> } <nl> } <nl>
Show bar waves from any member - s level .
telegramdesktop/tdesktop
e523687328d7ac1851e78d719684069e8750ea2e
2020-12-09T09:08:36Z
mmm a / src / mongo / db / storage / wiredtiger / wiredtiger_index . cpp <nl> ppp b / src / mongo / db / storage / wiredtiger / wiredtiger_index . cpp <nl> class WiredTigerIndex : : UniqueBulkBuilder : public BulkBuilder { <nl> / * * <nl> * Bulk builds a V2 format unique index . <nl> * <nl> - * This is a copy of ` UniqueBulkBuilder ` at the moment ; it would change later . <nl> - * <nl> - * In order to support V2 format unique indexes in dupsAllowed mode this class only does an actual <nl> - * insert after it sees a key after the one we are trying to insert . This allows us to gather up all <nl> - * duplicate ids and insert them all together . This is necessary since bulk cursors can only <nl> - * append data . <nl> + * This is similar to ` StandardBulkBuilder ` , with duplicate check added in . <nl> * / <nl> class WiredTigerIndex : : UniqueV2BulkBuilder : public BulkBuilder { <nl> public : <nl> class WiredTigerIndex : : UniqueV2BulkBuilder : public BulkBuilder { <nl> OperationContext * opCtx , <nl> bool dupsAllowed , <nl> KVPrefix prefix ) <nl> - : BulkBuilder ( idx , opCtx , prefix ) , <nl> - _idx ( idx ) , <nl> - _dupsAllowed ( dupsAllowed ) , <nl> - _keyString ( idx - > keyStringVersion ( ) ) { } <nl> + : BulkBuilder ( idx , opCtx , prefix ) , _idx ( idx ) , _dupsAllowed ( dupsAllowed ) { } <nl> <nl> Status addKey ( const BSONObj & newKey , const RecordId & id ) { <nl> { <nl> class WiredTigerIndex : : UniqueV2BulkBuilder : public BulkBuilder { <nl> return s ; <nl> } <nl> <nl> - const int cmp = newKey . woCompare ( _key , _ordering ) ; <nl> - if ( cmp ! = 0 ) { <nl> - if ( ! _key . isEmpty ( ) ) { / / _key . isEmpty ( ) is only true on the first call to addKey ( ) . <nl> - invariant ( cmp > 0 ) ; / / newKey must be > the last key <nl> - / / We are done with dups of the last key so we can insert it now . <nl> - doInsert ( ) ; <nl> - } <nl> - invariant ( _records . empty ( ) ) ; <nl> - } else { <nl> - / / Dup found ! <nl> + / / Do a duplicate check <nl> + const int cmp = newKey . woCompare ( _previousKey , _ordering ) ; <nl> + if ( cmp = = 0 ) { <nl> + / / Duplicate found ! <nl> if ( ! _dupsAllowed ) { <nl> return _idx - > dupKeyError ( newKey ) ; <nl> } <nl> - <nl> - / / If we get here , we are in the weird mode where dups are allowed on a unique <nl> - / / index , so add ourselves to the list of duplicate ids . This also replaces the <nl> - / / _key which is correct since any dups seen later are likely to be newer . <nl> - } <nl> - <nl> - _key = newKey . getOwned ( ) ; <nl> - _keyString . resetToKey ( _key , _idx - > ordering ( ) ) ; <nl> - _records . push_back ( std : : make_pair ( id , _keyString . getTypeBits ( ) ) ) ; <nl> - <nl> - return Status : : OK ( ) ; <nl> - } <nl> - <nl> - void commit ( bool mayInterrupt ) { <nl> - WriteUnitOfWork uow ( _opCtx ) ; <nl> - if ( ! _records . empty ( ) ) { <nl> - / / This handles inserting the last unique key . <nl> - doInsert ( ) ; <nl> + } else { <nl> + / / _previousKey . isEmpty ( ) is only true on the first call to addKey ( ) . <nl> + / / newKey must be > the last key <nl> + invariant ( _previousKey . isEmpty ( ) | | cmp > 0 ) ; <nl> } <nl> - uow . commit ( ) ; <nl> - } <nl> <nl> - private : <nl> - void doInsert ( ) { <nl> - invariant ( ! _records . empty ( ) ) ; <nl> + KeyString keyString ( _idx - > keyStringVersion ( ) , newKey , _idx - > _ordering , id ) ; <nl> <nl> - KeyString value ( _idx - > keyStringVersion ( ) ) ; <nl> - for ( size_t i = 0 ; i < _records . size ( ) ; i + + ) { <nl> - value . appendRecordId ( _records [ i ] . first ) ; <nl> - / / When there is only one record , we can omit AllZeros TypeBits . Otherwise they need <nl> - / / to be included . <nl> - if ( ! ( _records [ i ] . second . isAllZeros ( ) & & _records . size ( ) = = 1 ) ) { <nl> - value . appendTypeBits ( _records [ i ] . second ) ; <nl> - } <nl> - } <nl> + / / Can ' t use WiredTigerCursor since we aren ' t using the cache . <nl> + WiredTigerItem keyItem ( keyString . getBuffer ( ) , keyString . getSize ( ) ) ; <nl> + setKey ( _cursor , keyItem . Get ( ) ) ; <nl> <nl> - WiredTigerItem keyItem ( _keyString . getBuffer ( ) , _keyString . getSize ( ) ) ; <nl> - WiredTigerItem valueItem ( value . getBuffer ( ) , value . getSize ( ) ) ; <nl> + WiredTigerItem valueItem = keyString . getTypeBits ( ) . isAllZeros ( ) <nl> + ? emptyItem <nl> + : WiredTigerItem ( keyString . getTypeBits ( ) . getBuffer ( ) , <nl> + keyString . getTypeBits ( ) . getSize ( ) ) ; <nl> <nl> - setKey ( _cursor , keyItem . Get ( ) ) ; <nl> _cursor - > set_value ( _cursor , valueItem . Get ( ) ) ; <nl> <nl> invariantWTOK ( _cursor - > insert ( _cursor ) ) ; <nl> <nl> - _records . clear ( ) ; <nl> + _previousKey = newKey . getOwned ( ) ; <nl> + return Status : : OK ( ) ; <nl> } <nl> <nl> + private : <nl> WiredTigerIndex * _idx ; <nl> const bool _dupsAllowed ; <nl> - BSONObj _key ; <nl> - KeyString _keyString ; <nl> - std : : vector < std : : pair < RecordId , KeyString : : TypeBits > > _records ; <nl> + BSONObj _previousKey ; <nl> } ; <nl> <nl> namespace { <nl>
SERVER - 33415 Implement Bulk build for new unique indexes
mongodb/mongo
ce91d96dc6fe04db3327653c145a54b3768a88ac
2018-02-28T02:41:14Z
mmm a / stdlib / private / StdlibUnittest / StdlibUnittest . swift <nl> ppp b / stdlib / private / StdlibUnittest / StdlibUnittest . swift <nl> class _ParentProcess { <nl> let ( _ , stdoutThread ) = _stdlib_thread_create_block ( { <nl> while ! self . _childStdout . isEOF { <nl> self . _childStdout . read ( ) <nl> - while let line = self . _childStdout . getline ( ) { <nl> + while var line = self . _childStdout . getline ( ) { <nl> + if let cr = line . firstIndex ( of : " \ r " ) { <nl> + line . remove ( at : cr ) <nl> + } <nl> var done : Bool <nl> ( done : done , ( ) ) = onStdoutLine ( line ) <nl> if done { return } <nl>
StdlibUnittest : consume the carriage return on stdout
apple/swift
1d1c362aba8062d5908383e1398cc40e6ea2e93b
2019-06-05T20:59:22Z
mmm a / plugins / producer_plugin / producer_plugin . cpp <nl> ppp b / plugins / producer_plugin / producer_plugin . cpp <nl> class producer_plugin_impl : public std : : enable_shared_from_this < producer_plugin <nl> uint32_t _last_signed_block_num = 0 ; <nl> <nl> producer_plugin * _self = nullptr ; <nl> + chain_plugin * chain_plug = nullptr ; <nl> <nl> incoming : : channels : : block : : channel_type : : handle _incoming_block_subscription ; <nl> incoming : : channels : : transaction : : channel_type : : handle _incoming_transaction_subscription ; <nl> class producer_plugin_impl : public std : : enable_shared_from_this < producer_plugin <nl> <nl> / / since the watermark has to be set before a block is created , we are looking into the future to <nl> / / determine the new schedule to identify producers that have become active <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = chain_plug - > chain ( ) ; <nl> const auto hbn = bsp - > block_num ; <nl> auto new_block_header = bsp - > header ; <nl> new_block_header . timestamp = new_block_header . timestamp . next ( ) ; <nl> class producer_plugin_impl : public std : : enable_shared_from_this < producer_plugin <nl> EOS_ASSERT ( block - > timestamp < ( fc : : time_point : : now ( ) + fc : : seconds ( 7 ) ) , block_from_the_future , <nl> " received a block from the future , ignoring it : $ { id } " , ( " id " , id ) ) ; <nl> <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = chain_plug - > chain ( ) ; <nl> <nl> / * de - dupe here . . . no point in aborting block if we already know the block * / <nl> auto existing = chain . fetch_block_by_id ( id ) ; <nl> class producer_plugin_impl : public std : : enable_shared_from_this < producer_plugin <nl> try { <nl> chain . push_block ( bsf ) ; <nl> } catch ( const guard_exception & e ) { <nl> - app ( ) . get_plugin < chain_plugin > ( ) . handle_guard_exception ( e ) ; <nl> + chain_plug - > handle_guard_exception ( e ) ; <nl> return ; <nl> } catch ( const fc : : exception & e ) { <nl> elog ( ( e . to_detail_string ( ) ) ) ; <nl> class producer_plugin_impl : public std : : enable_shared_from_this < producer_plugin <nl> std : : deque < std : : tuple < packed_transaction_ptr , bool , next_function < transaction_trace_ptr > > > _pending_incoming_transactions ; <nl> <nl> void on_incoming_transaction_async ( const packed_transaction_ptr & trx , bool persist_until_expired , next_function < transaction_trace_ptr > next ) { <nl> - / / todo remove chain_plugin lookup <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = chain_plug - > chain ( ) ; <nl> if ( ! chain . pending_block_state ( ) ) { <nl> _pending_incoming_transactions . emplace_back ( trx , persist_until_expired , next ) ; <nl> return ; <nl> class producer_plugin_impl : public std : : enable_shared_from_this < producer_plugin <nl> } <nl> <nl> } catch ( const guard_exception & e ) { <nl> - app ( ) . get_plugin < chain_plugin > ( ) . handle_guard_exception ( e ) ; <nl> + chain_plug - > handle_guard_exception ( e ) ; <nl> } catch ( boost : : interprocess : : bad_alloc & ) { <nl> chain_plugin : : handle_db_exhaustion ( ) ; <nl> } CATCH_AND_CALL ( send_response ) ; <nl> make_keosd_signature_provider ( const std : : shared_ptr < producer_plugin_impl > & impl , <nl> <nl> void producer_plugin : : plugin_initialize ( const boost : : program_options : : variables_map & options ) <nl> { try { <nl> + my - > chain_plug = app ( ) . find_plugin < chain_plugin > ( ) ; <nl> + EOS_ASSERT ( my - > chain_plug , plugin_config_exception , " chain_plugin not found " ) ; <nl> my - > _options = & options ; <nl> LOAD_VALUE_SET ( options , " producer - name " , my - > _producers , types : : account_name ) <nl> <nl> void producer_plugin : : plugin_startup ( ) <nl> <nl> ilog ( " producer plugin : plugin_startup ( ) begin " ) ; <nl> <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = my - > chain_plug - > chain ( ) ; <nl> EOS_ASSERT ( my - > _producers . empty ( ) | | chain . get_read_mode ( ) = = chain : : db_read_mode : : SPECULATIVE , plugin_config_exception , <nl> " node cannot have any producer - name configured because block production is impossible when read_mode is not \ " speculative \ " " ) ; <nl> <nl> void producer_plugin : : resume ( ) { <nl> / / re - evaluate that now <nl> / / <nl> if ( my - > _pending_block_mode = = pending_block_mode : : speculating ) { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = my - > chain_plug - > chain ( ) ; <nl> chain . abort_block ( ) ; <nl> my - > schedule_production_loop ( ) ; <nl> } <nl> void producer_plugin : : update_runtime_options ( const runtime_options & options ) { <nl> } <nl> <nl> if ( check_speculating & & my - > _pending_block_mode = = pending_block_mode : : speculating ) { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = my - > chain_plug - > chain ( ) ; <nl> chain . abort_block ( ) ; <nl> my - > schedule_production_loop ( ) ; <nl> } <nl> <nl> if ( options . subjective_cpu_leeway_us ) { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = my - > chain_plug - > chain ( ) ; <nl> chain . set_subjective_cpu_leeway ( fc : : microseconds ( * options . subjective_cpu_leeway_us ) ) ; <nl> } <nl> } <nl> producer_plugin : : runtime_options producer_plugin : : get_runtime_options ( ) const { <nl> } <nl> <nl> void producer_plugin : : add_greylist_accounts ( const greylist_params & params ) { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = my - > chain_plug - > chain ( ) ; <nl> for ( auto & acc : params . accounts ) { <nl> chain . add_resource_greylist ( acc ) ; <nl> } <nl> } <nl> <nl> void producer_plugin : : remove_greylist_accounts ( const greylist_params & params ) { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = my - > chain_plug - > chain ( ) ; <nl> for ( auto & acc : params . accounts ) { <nl> chain . remove_resource_greylist ( acc ) ; <nl> } <nl> } <nl> <nl> producer_plugin : : greylist_params producer_plugin : : get_greylist ( ) const { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = my - > chain_plug - > chain ( ) ; <nl> greylist_params result ; <nl> const auto & list = chain . get_resource_greylist ( ) ; <nl> result . accounts . reserve ( list . size ( ) ) ; <nl> producer_plugin : : greylist_params producer_plugin : : get_greylist ( ) const { <nl> } <nl> <nl> producer_plugin : : whitelist_blacklist producer_plugin : : get_whitelist_blacklist ( ) const { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = my - > chain_plug - > chain ( ) ; <nl> return { <nl> chain . get_actor_whitelist ( ) , <nl> chain . get_actor_blacklist ( ) , <nl> producer_plugin : : whitelist_blacklist producer_plugin : : get_whitelist_blacklist ( ) <nl> } <nl> <nl> void producer_plugin : : set_whitelist_blacklist ( const producer_plugin : : whitelist_blacklist & params ) { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = my - > chain_plug - > chain ( ) ; <nl> if ( params . actor_whitelist . valid ( ) ) chain . set_actor_whitelist ( * params . actor_whitelist ) ; <nl> if ( params . actor_blacklist . valid ( ) ) chain . set_actor_blacklist ( * params . actor_blacklist ) ; <nl> if ( params . contract_whitelist . valid ( ) ) chain . set_contract_whitelist ( * params . contract_whitelist ) ; <nl> void producer_plugin : : set_whitelist_blacklist ( const producer_plugin : : whitelist_b <nl> } <nl> <nl> producer_plugin : : integrity_hash_information producer_plugin : : get_integrity_hash ( ) const { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = my - > chain_plug - > chain ( ) ; <nl> <nl> auto reschedule = fc : : make_scoped_exit ( [ this ] ( ) { <nl> my - > schedule_production_loop ( ) ; <nl> producer_plugin : : integrity_hash_information producer_plugin : : get_integrity_hash ( <nl> } <nl> <nl> producer_plugin : : snapshot_information producer_plugin : : create_snapshot ( ) const { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = my - > chain_plug - > chain ( ) ; <nl> <nl> auto reschedule = fc : : make_scoped_exit ( [ this ] ( ) { <nl> my - > schedule_production_loop ( ) ; <nl> producer_plugin : : snapshot_information producer_plugin : : create_snapshot ( ) const { <nl> } <nl> <nl> optional < fc : : time_point > producer_plugin_impl : : calculate_next_block_time ( const account_name & producer_name , const block_timestamp_type & current_block_time ) const { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = chain_plug - > chain ( ) ; <nl> const auto & hbs = chain . head_block_state ( ) ; <nl> const auto & active_schedule = hbs - > active_schedule . producers ; <nl> <nl> optional < fc : : time_point > producer_plugin_impl : : calculate_next_block_time ( const a <nl> } <nl> <nl> fc : : time_point producer_plugin_impl : : calculate_pending_block_time ( ) const { <nl> - const chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + const chain : : controller & chain = chain_plug - > chain ( ) ; <nl> const fc : : time_point now = fc : : time_point : : now ( ) ; <nl> const fc : : time_point base = std : : max < fc : : time_point > ( now , chain . head_block_time ( ) ) ; <nl> const int64_t min_time_to_next_block = ( config : : block_interval_us ) - ( base . time_since_epoch ( ) . count ( ) % ( config : : block_interval_us ) ) ; <nl> enum class tx_category { <nl> <nl> <nl> producer_plugin_impl : : start_block_result producer_plugin_impl : : start_block ( bool & last_block ) { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = chain_plug - > chain ( ) ; <nl> <nl> if ( chain . get_read_mode ( ) = = chain : : db_read_mode : : READ_ONLY ) <nl> return start_block_result : : waiting ; <nl> producer_plugin_impl : : start_block_result producer_plugin_impl : : start_block ( bool <nl> num_applied + + ; <nl> } <nl> } catch ( const guard_exception & e ) { <nl> - app ( ) . get_plugin < chain_plugin > ( ) . handle_guard_exception ( e ) ; <nl> + chain_plug - > handle_guard_exception ( e ) ; <nl> return start_block_result : : failed ; <nl> } FC_LOG_AND_DROP ( ) ; <nl> } <nl> producer_plugin_impl : : start_block_result producer_plugin_impl : : start_block ( bool <nl> num_applied + + ; <nl> } <nl> } catch ( const guard_exception & e ) { <nl> - app ( ) . get_plugin < chain_plugin > ( ) . handle_guard_exception ( e ) ; <nl> + chain_plug - > handle_guard_exception ( e ) ; <nl> return start_block_result : : failed ; <nl> } FC_LOG_AND_DROP ( ) ; <nl> <nl> producer_plugin_impl : : start_block_result producer_plugin_impl : : start_block ( bool <nl> } <nl> <nl> void producer_plugin_impl : : schedule_production_loop ( ) { <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = chain_plug - > chain ( ) ; <nl> _timer . cancel ( ) ; <nl> std : : weak_ptr < producer_plugin_impl > weak_this = shared_from_this ( ) ; <nl> <nl> bool producer_plugin_impl : : maybe_produce_block ( ) { <nl> produce_block ( ) ; <nl> return true ; <nl> } catch ( const guard_exception & e ) { <nl> - app ( ) . get_plugin < chain_plugin > ( ) . handle_guard_exception ( e ) ; <nl> + chain_plug - > handle_guard_exception ( e ) ; <nl> return false ; <nl> } FC_LOG_AND_DROP ( ) ; <nl> } catch ( boost : : interprocess : : bad_alloc & ) { <nl> bool producer_plugin_impl : : maybe_produce_block ( ) { <nl> } <nl> <nl> fc_dlog ( _log , " Aborting block due to produce_block error " ) ; <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = chain_plug - > chain ( ) ; <nl> chain . abort_block ( ) ; <nl> return false ; <nl> } <nl> static auto maybe_make_debug_time_logger ( ) - > fc : : optional < decltype ( make_debug_t <nl> void producer_plugin_impl : : produce_block ( ) { <nl> / / ilog ( " produce_block $ { t } " , ( " t " , fc : : time_point : : now ( ) ) ) ; / / for testing _produce_time_offset_us <nl> EOS_ASSERT ( _pending_block_mode = = pending_block_mode : : producing , producer_exception , " called produce_block while not actually producing " ) ; <nl> - chain : : controller & chain = app ( ) . get_plugin < chain_plugin > ( ) . chain ( ) ; <nl> + chain : : controller & chain = chain_plug - > chain ( ) ; <nl> const auto & pbs = chain . pending_block_state ( ) ; <nl> const auto & hbs = chain . head_block_state ( ) ; <nl> EOS_ASSERT ( pbs , missing_pending_block_state , " pending_block_state does not exist but it should , another plugin may have corrupted it " ) ; <nl>
Cache chain_plugin lookup
EOSIO/eos
8109f0aa1b4534e3632a92f549f83f43b6c51827
2018-12-06T17:04:35Z
mmm a / src / clustering / administration / real_reql_cluster_interface . cc <nl> ppp b / src / clustering / administration / real_reql_cluster_interface . cc <nl> bool real_reql_cluster_interface_t : : table_create ( const name_string_t & name , <nl> " The table was not created . " , <nl> " The table may or may not have been created . " ) <nl> <nl> - / / This could hang because of a node disconnecting or the user deleting the table . <nl> - / / In that case , timeout after 10 seconds and pretend everything ' s alright . <nl> + / * Because ` wait_for_table_readiness ( ) ` succeeded , we know that the replicas are all <nl> + set up . However , ` wait_for_table_readiness ( ) ` doesn ' t check that we ' ve established a <nl> + ` namespace_interface_t ` for the table . If we haven ' t done so yet , this could cause <nl> + the first few queries to fail . So we have to run dummy queries until we get a query <nl> + through , and only then we return to the user . <nl> + <nl> + This could hang because of a node disconnecting or the user deleting the table . In <nl> + that case , timeout after 10 seconds and pretend everything ' s alright . * / <nl> signal_timer_t timer_interruptor ; <nl> wait_any_t combined_interruptor ( interruptor , & timer_interruptor ) ; <nl> timer_interruptor . start ( 10000 ) ; <nl> mmm a / src / clustering / immediate_consistency / backfill_metadata . hpp <nl> ppp b / src / clustering / immediate_consistency / backfill_metadata . hpp <nl> implicitly defines the range that the backfill will apply to . The backfiller com <nl> backfillee ' s initial version with its own version and finds their closest common <nl> ancestor . Then it sends back an ` intro_2_t ` via the ` intro_1_t : : intro_mailbox ` . The <nl> ` intro_2_t ` contains the common version which the backfiller calculated , along with its <nl> - own set of mailbox addresses . <nl> + own set of mailbox addresses . It also includes the branch history for the branch that the <nl> + backfiller is currently on . The backfiller is guaranteed not to change branches during <nl> + the backfill , so this is the only time branch history needs to be transmitted from the <nl> + backfiller to the backfillee . <nl> <nl> Once the initial handshake is completed , two processes happen in parallel : the backfillee <nl> transmits ` backfill_pre_item_t ` s to the backfiller , and the backfiller transmits <nl> mmm a / src / clustering / immediate_consistency / primary_dispatcher . cc <nl> ppp b / src / clustering / immediate_consistency / primary_dispatcher . cc <nl> void primary_dispatcher_t : : background_write ( <nl> } <nl> <nl> void primary_dispatcher_t : : refresh_ready_dispatchees_as_set ( ) { <nl> + / * Note that it ' s possible that we ' ll have multiple dispatchees with the same server <nl> + ID . This won ' t happen during normal operation , but it can happen temporarily during <nl> + a transition . For example , a secondary might disconnect and reconnect as a different <nl> + dispatchee before we realize that its original dispatchee is no longer valid . * / <nl> std : : set < server_id_t > ready ; <nl> for ( const auto & pair : dispatchees ) { <nl> if ( pair . first - > is_ready ) { <nl> mmm a / src / clustering / immediate_consistency / remote_replicator_client . cc <nl> ppp b / src / clustering / immediate_consistency / remote_replicator_client . cc <nl> class remote_replicator_client_t : : backfill_end_timestamps_t { <nl> key_range_t : : right_bound_t ( next . region . inner . left ) ) ; <nl> region . inner . right = next . region . inner . right ; <nl> guarantee ( ! steps . empty ( ) & & ! next . steps . empty ( ) ) ; <nl> - guarantee ( steps . back ( ) . second < = next . steps . front ( ) . second , <nl> - " address is : % p steps is : % s next . steps is : % s " , <nl> - this , debug_strprint ( steps ) . c_str ( ) , debug_strprint ( next . steps ) . c_str ( ) ) ; <nl> + guarantee ( steps . back ( ) . second < = next . steps . front ( ) . second ) ; <nl> auto begin = next . steps . begin ( ) ; <nl> if ( steps . back ( ) . second = = next . steps . front ( ) . second ) { <nl> + + begin ; <nl> void remote_replicator_client_t : : on_write_async ( <nl> queue_entry . order_token = queue_order_checkpoint_ . check_through ( order_token ) ; <nl> ( * queue_fun_ ) ( std : : move ( queue_entry ) , & queue_throttler ) ; <nl> } else { <nl> + / * Usually the only reason for ` queue_fun_ ` to be null would be if we ' re <nl> + currently between two queueing phases . But it could also be null if the <nl> + constructor just got interrupted . * / <nl> queue_throttler . pulse ( ) ; <nl> } <nl> <nl> mmm a / src / clustering / table_contract / exec_primary . cc <nl> ppp b / src / clustering / table_contract / exec_primary . cc <nl> void primary_execution_t : : update_contract_on_store_thread ( <nl> / * If we have a broadcaster , then try to sync with replicas so we can ack the <nl> contract * / <nl> if ( our_dispatcher ! = nullptr ) { <nl> + / * We ' re going to hold a pointer to the ` primary_dispatcher_t ` that lives <nl> + on the stack in ` run ( ) ` , so we need to make sure we ' ll stop before <nl> + ` run ( ) ` stops . We do this by acquiring a lock on the ` auto_drainer_t ` on <nl> + the stack in ` run ( ) ` . * / <nl> auto_drainer_t : : lock_t keepalive2 = our_dispatcher_drainer - > lock ( ) ; <nl> wait_any_t combiner ( <nl> & interruptor_store_thread , keepalive2 . get_drain_signal ( ) ) ; <nl> mmm a / src / clustering / table_contract / exec_secondary . cc <nl> ppp b / src / clustering / table_contract / exec_secondary . cc <nl> secondary_execution_t : : secondary_execution_t ( <nl> const contract_t & c = raft_state . contracts . at ( cid ) . second ; <nl> guarantee ( c . replicas . count ( context - > server_id ) = = 1 ) ; <nl> guarantee ( raft_state . contracts . at ( cid ) . first = = region ) ; <nl> + <nl> + / * If the current contract doesn ' t have a primary , we won ' t attempt to connect to the <nl> + primary . Also , if the current contract ' s region doesn ' t match the branch ' s region , we <nl> + won ' t attempt to connect . This is because the only way that can happen is if the <nl> + table was just resharded , so the primary is about to stop and restart with a <nl> + different branch ID , and there ' s no point in trying to connect to the existing <nl> + primary . In fact , we can ' t connect to the existing primary , since it ' s impossible to <nl> + subscribe to a primary with a different region . * / <nl> if ( static_cast < bool > ( c . primary ) & & ! c . branch . is_nil ( ) & & <nl> raft_state . branch_history . branches . at ( c . branch ) . region = = region ) { <nl> connect_to_primary = true ; <nl> secondary_execution_t : : secondary_execution_t ( <nl> connect_to_primary = false ; <nl> primary = nil_uuid ( ) ; <nl> } <nl> + <nl> branch = c . branch ; <nl> contract_id = cid ; <nl> coro_t : : spawn_sometime ( std : : bind ( & secondary_execution_t : : run , this , drainer . lock ( ) ) ) ; <nl> mmm a / src / clustering / table_contract / executor . cc <nl> ppp b / src / clustering / table_contract / executor . cc <nl> void contract_executor_t : : send_ack ( const execution_key_t & key , const contract_id <nl> const contract_ack_t & ack ) { <nl> assert_thread ( ) ; <nl> / * If the contract is out of date , don ' t send the ack * / <nl> - if ( executions . at ( key ) . has ( ) & & executions . at ( key ) - > contract_id = = cid ) { <nl> + if ( executions . at ( key ) - > contract_id = = cid ) { <nl> ack_map . set_key_no_equals ( std : : make_pair ( server_id , cid ) , ack ) ; <nl> } <nl> } <nl>
Add a bunch of comments clarifying corner cases .
rethinkdb/rethinkdb
47c174c1cc5235bf05943107844c43e999db8f2c
2015-05-07T20:32:59Z
mmm a / lib / Parse / ParseDecl . cpp <nl> ppp b / lib / Parse / ParseDecl . cpp <nl> parseIdentifierDeclName ( Parser & P , Identifier & Result , SourceLoc & Loc , <nl> return makeParserError ( ) ; <nl> } <nl> <nl> + / / If there is expected tokens after the code completion token , just eat the <nl> + / / code completion token . We don ' t need code completion here . <nl> + / / E . g . : <nl> + / / ' func ' < completion > ( ' ( ' | ' < ' ) <nl> + / / ' typealias ' < completion > ( ' = ' | ' < ' ) <nl> + / / If there ' s no expected token after the completion , override completion may <nl> + / / kicks in . So leave the token here . <nl> + / / E . g . <nl> + / / ' func ' < completion > <nl> + / / ' init ' < completion > <nl> + if ( P . Tok . is ( tok : : code_complete ) & & canRecover ( P . peekToken ( ) ) ) { <nl> + P . consumeToken ( tok : : code_complete ) ; <nl> + return makeParserCodeCompletionStatus ( ) ; <nl> + } <nl> + <nl> P . diagnose ( P . Tok , diag : : expected_identifier_in_decl , DeclKindName ) ; <nl> return makeParserError ( ) ; <nl> } <nl> parseDeclTypeAlias ( Parser : : ParseDeclOptions Flags , DeclAttributes & Attributes ) { <nl> [ ] ( const Token & next ) { return next . isAny ( tok : : colon , tok : : equal ) ; } ) ; <nl> if ( Status . isError ( ) ) { <nl> TmpCtxt - > setTransparent ( ) ; <nl> - return nullptr ; <nl> + return Status ; <nl> } <nl> <nl> DebuggerContextChange DCC ( * this , Id , DeclKind : : TypeAlias ) ; <nl> ParserResult < TypeDecl > Parser : : parseDeclAssociatedType ( Parser : : ParseDeclOptions <nl> * this , Id , IdLoc , " associatedtype " , <nl> [ ] ( const Token & next ) { return next . isAny ( tok : : colon , tok : : equal ) ; } ) ; <nl> if ( Status . isError ( ) ) <nl> - return nullptr ; <nl> - <nl> + return Status ; <nl> + <nl> DebuggerContextChange DCC ( * this , Id , DeclKind : : AssociatedType ) ; <nl> <nl> / / Reject generic parameters with a specific error . <nl> ParserResult < FuncDecl > Parser : : parseDeclFunc ( SourceLoc StaticLoc , <nl> startsWithLess ( next ) ; <nl> } ) ; <nl> if ( NameStatus . isError ( ) ) <nl> - return nullptr ; <nl> + return NameStatus ; <nl> } <nl> <nl> DebuggerContextChange DCC ( * this , SimpleName , DeclKind : : Func ) ; <nl> ParserResult < EnumDecl > Parser : : parseDeclEnum ( ParseDeclOptions Flags , <nl> return next . isAny ( tok : : colon , tok : : l_brace ) | | startsWithLess ( next ) ; <nl> } ) ; <nl> if ( Status . isError ( ) ) <nl> - return nullptr ; <nl> + return Status ; <nl> <nl> DebuggerContextChange DCC ( * this , EnumName , DeclKind : : Enum ) ; <nl> <nl> ParserResult < StructDecl > Parser : : parseDeclStruct ( ParseDeclOptions Flags , <nl> return next . isAny ( tok : : colon , tok : : l_brace ) | | startsWithLess ( next ) ; <nl> } ) ; <nl> if ( Status . isError ( ) ) <nl> - return nullptr ; <nl> + return Status ; <nl> <nl> DebuggerContextChange DCC ( * this , StructName , DeclKind : : Struct ) ; <nl> <nl> ParserResult < ClassDecl > Parser : : parseDeclClass ( ParseDeclOptions Flags , <nl> return next . isAny ( tok : : colon , tok : : l_brace ) | | startsWithLess ( next ) ; <nl> } ) ; <nl> if ( Status . isError ( ) ) <nl> - return nullptr ; <nl> + return Status ; <nl> <nl> DebuggerContextChange DCC ( * this , ClassName , DeclKind : : Class ) ; <nl> <nl> parseDeclProtocol ( ParseDeclOptions Flags , DeclAttributes & Attributes ) { <nl> * this , ProtocolName , NameLoc , " protocol " , <nl> [ & ] ( const Token & next ) { return next . isAny ( tok : : colon , tok : : l_brace ) ; } ) ; <nl> if ( Status . isError ( ) ) <nl> - return nullptr ; <nl> + return Status ; <nl> <nl> / / Protocols don ' t support generic parameters , but people often want them and <nl> / / we want to have good error recovery if they try them out . Parse them and <nl> mmm a / test / IDE / complete_declname . swift <nl> ppp b / test / IDE / complete_declname . swift <nl> <nl> / / RUN : % target - swift - ide - test - code - completion - source - filename % s - code - completion - keywords = false - code - completion - token = METHODNAME_PROTOCOL | % FileCheck % s - - check - prefix = NO_COMPLETIONS <nl> / / RUN : % target - swift - ide - test - code - completion - source - filename % s - code - completion - keywords = false - code - completion - token = METHODNAME_CONFORMANCE | % FileCheck % s - - check - prefix = METHODNAME_CONFORMANCE <nl> / / RUN : % target - swift - ide - test - code - completion - source - filename % s - code - completion - keywords = false - code - completion - token = TYPEALIASNAME_CONFORMANCE | % FileCheck % s - - check - prefix = TYPEALIASNAME_CONFORMANCE <nl> + / / RUN : % target - swift - ide - test - code - completion - source - filename % s - code - completion - keywords = false - code - completion - token = METHODNAME_HASSIG | % FileCheck % s - - check - prefix = NO_COMPLETIONS <nl> + / / RUN : % target - swift - ide - test - code - completion - source - filename % s - code - completion - keywords = false - code - completion - token = TYPEALIASNAME_HASSIG | % FileCheck % s - - check - prefix = NO_COMPLETIONS <nl> <nl> / / NO_COMPLETIONS - NOT : Begin completions <nl> <nl> struct MyStruct : P { <nl> / / METHODNAME_CONFORMANCE : Begin completions , 1 items <nl> / / METHODNAME_CONFORMANCE - NEXT : Decl [ InstanceMethod ] / Super : foo ( ) { | } ; name = foo ( ) <nl> / / METHODNAME_CONFORMANCE - NEXT : End completions <nl> + <nl> typealias # ^ TYPEALIASNAME_CONFORMANCE ^ # <nl> / / TYPEALIASNAME_CONFORMANCE : Begin completions , 1 items <nl> / / TYPEALIASNAME_CONFORMANCE - NEXT : Decl [ AssociatedType ] / Super : Assoc = { # ( Type ) # } ; name = Assoc = Type <nl> / / TYPEALIASNAME_CONFORMANCE - NEXT : End completions <nl> } <nl> + struct MyStruct2 : P { <nl> + func # ^ METHODNAME_HASSIG ^ # ( ) ( < # parameters # > } { } <nl> + / / INVALID <nl> + typealias # ^ TYPEALIASNAME_HASSIG ^ # = < # type # > <nl> + / / INVALID <nl> + } <nl>
[ CodeCompletion ] Don ' t perform completion at declaration name position
apple/swift
619fbe1a1632760e16a02d816c81e0e725696b37
2020-04-24T06:12:44Z
mmm a / etc / longevity . yml <nl> ppp b / etc / longevity . yml <nl> post : <nl> params : <nl> working_dir : work <nl> script : | <nl> - set - v <nl> source . / dsienv . sh <nl> - $ DSI_PATH / bin / make_artifact . sh <nl> + make_artifact . sh <nl> - command : s3 . put <nl> params : <nl> aws_key : $ { aws_key } <nl> aws_secret : $ { aws_secret } <nl> local_file : work / reports . tgz <nl> - remote_file : $ { project } / $ { build_variant } / $ { revision } / $ { task_id } / $ { version_id } / logs / $ { task_name } - $ { build_id } . $ { ext | tgz } <nl> + remote_file : $ { project } / $ { build_variant } / $ { revision } / $ { task_id } / $ { version_id } / logs / $ { task_name } - $ { build_id } - $ { execution } . $ { ext | tgz } <nl> bucket : mciuploads <nl> permissions : public - read <nl> content_type : $ { content_type | application / x - gzip } <nl> - display_name : test - log <nl> + display_name : test - log - Execution $ { execution } <nl> - command : attach . results <nl> params : <nl> file_location : work / report . json <nl> - - command : shell . exec <nl> - # destroy the cluster <nl> - params : <nl> - working_dir : work <nl> - script : | <nl> - set - e <nl> - set - o verbose <nl> - # call terraform destroy twice to avoid AWS timeout <nl> - yes yes | . / terraform destroy - - var - file = cluster . json <nl> - yes yes | . / terraform destroy - - var - file = cluster . json <nl> - # clean all file to be safe <nl> - rm - rf * <nl> - echo " Cluster DESTROYED . " <nl> + - func : " destroy cluster " <nl> - command : shell . exec <nl> params : <nl> working_dir : src <nl> functions : <nl> storageEngine : $ { storageEngine } <nl> test : $ { test } . longevity <nl> production : true <nl> + <nl> + # compositions of expansions <nl> + mongodb_binary_archive : " https : / / s3 . amazonaws . com / mciuploads / $ { project } / $ { version_id } / $ { revision } / $ { platform } / mongod - $ { version_id } . tar . gz " <nl> EOF <nl> <nl> cat > runtime . yml < < EOF <nl> functions : <nl> ext : $ { ext } <nl> script_flags : $ { script_flags } <nl> dsi_rev : $ { dsi_rev } <nl> - compare_task : $ { compare_task } <nl> - workloads_rev : $ { workloads_rev } <nl> - <nl> - # compositions of expansions <nl> - mongodb_binary_archive : " https : / / s3 . amazonaws . com / mciuploads / $ { project } / $ { version_id } / $ { revision } / $ { platform } / mongod - $ { version_id } . tar . gz " <nl> EOF <nl> - command : shell . exec <nl> params : <nl> functions : <nl> - command : shell . exec <nl> params : <nl> working_dir : work <nl> - # setup execution environment <nl> - # configure environment <nl> script : | <nl> set - e <nl> virtualenv . / venv <nl> functions : <nl> set - v <nl> set - e <nl> source work / dsienv . sh <nl> - $ DSI_PATH / bin / setup - dsi - env . sh <nl> + setup - dsi - env . sh <nl> ls - a work <nl> <nl> - " infrastructure provisioning " : <nl> + " deploy cluster " : <nl> - command : shell . exec <nl> - # call infrastructure - provisioning . py . This will either create a cluster , or update tags on existing instances . <nl> params : <nl> working_dir : work <nl> script : | <nl> functions : <nl> set - v <nl> source . / dsienv . sh <nl> source . / venv / bin / activate <nl> - $ DSI_PATH / bin / infrastructure_provisioning . py <nl> - <nl> - " configure mongodb cluster " : <nl> - - command : shell . exec <nl> - # bring up the mongod <nl> - params : <nl> - working_dir : work <nl> - script : | <nl> - set - e <nl> - set - o verbose <nl> - source . / dsienv . sh <nl> - source . / venv / bin / activate <nl> - $ DSI_PATH / bin / mongodb_setup . py & & echo " $ { setup } MongoDB Cluster STARTED . " <nl> + infrastructure_provisioning . py <nl> + mongodb_setup . py <nl> <nl> " run test " : <nl> - command : shell . exec <nl> + type : test <nl> params : <nl> working_dir : work <nl> script : | <nl> functions : <nl> set - v <nl> source . / dsienv . sh <nl> source . / venv / bin / activate <nl> - echo " Run test for $ { test } - $ { storageEngine } with setup $ { setup } " <nl> - $ DSI_PATH / bin / run_test . py $ { storageEngine } $ { test } $ { cluster } <nl> - echo " Complete test for $ { test } with setup $ { setup } ! " <nl> + test_control . py <nl> - command : " json . send " <nl> params : <nl> name : " perf " <nl> functions : <nl> script : | <nl> set - e <nl> set - o verbose <nl> - source . / dsienv . sh <nl> # Longevity runs so rarely , we simply teardown the cluster when done . <nl> # Note that nowadays infrastructure_teardown . py is actually copying the terraform . tfstate into / data / infrastructure_provisioning <nl> # but as of this writing the rhel70 - perf - longevity distro didn ' t actually use the teardown hook . <nl> source . / dsienv . sh <nl> source . / venv / bin / activate <nl> - $ DSI_PATH / bin / infrastructure_teardown . py <nl> + infrastructure_teardown . py <nl> echo " Cluster DESTROYED . " <nl> echo <nl> echo " All perf results " <nl> functions : <nl> params : <nl> working_dir : work <nl> script : | <nl> - set - v <nl> source . / dsienv . sh <nl> - $ DSI_PATH / bin / make_artifact . sh <nl> + make_artifact . sh <nl> <nl> " analyze " : <nl> - command : json . get_history <nl> tasks : <nl> script : | <nl> set - o errexit <nl> set - o verbose <nl> - <nl> - $ { python | / opt / mongodbtoolchain / v2 / bin / python2 } . / buildscripts / scons . py $ { compile_flags | } $ { scons_cache_args | } mongo mongod mongos <nl> - <nl> - # strip binaries here <nl> - strip mongo <nl> - strip mongos <nl> - strip mongod <nl> + $ { python | / opt / mongodbtoolchain / v2 / bin / python2 } . / buildscripts / scons . py $ { compile_flags | } $ { scons_cache_args | } mongo $ { extension } mongod $ { extension } mongos $ { extension } MONGO_VERSION = $ { version } <nl> mkdir - p mongodb / bin <nl> - mv mongo mongodb / bin <nl> - mv mongod mongodb / bin <nl> - mv mongos mongodb / bin <nl> + mv mongo $ { extension | } mongodb / bin <nl> + mv mongod $ { extension | } mongodb / bin <nl> + mv mongos $ { extension | } mongodb / bin <nl> tar cvf mongodb . tar mongodb <nl> gzip mongodb . tar <nl> - command : s3 . put <nl> tasks : <nl> vars : <nl> storageEngine : " wiredTiger " <nl> test : " ycsb " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> - test : " ycsb " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> vars : <nl> tasks : <nl> vars : <nl> storageEngine : " mmapv1 " <nl> test : " ycsb " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> - test : " ycsb " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> vars : <nl> modules : <nl> branch : master <nl> <nl> <nl> + <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + # Linux Buildvariants # <nl> + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # <nl> + <nl> buildvariants : <nl> - name : linux - wt - shard <nl> display_name : Linux WT Shard <nl> mmm a / etc / system_perf . yml <nl> ppp b / etc / system_perf . yml <nl> post : <nl> working_dir : work <nl> script : | <nl> source . / dsienv . sh <nl> - $ DSI_PATH / bin / make_artifact . sh <nl> + make_artifact . sh <nl> - command : s3 . put <nl> params : <nl> aws_key : $ { aws_key } <nl> post : <nl> - command : attach . results <nl> params : <nl> file_location : work / report . json <nl> + - command : " json . send " <nl> + params : <nl> + name : " perf " <nl> + file : " work / perf . json " <nl> - command : shell . exec <nl> params : <nl> working_dir : work <nl> script : | <nl> source . / dsienv . sh <nl> if [ - e / data / infrastructure_provisioning / terraform / provisioned . $ { cluster } ] ; then <nl> - $ DSI_PATH / bin / mark_idle . sh <nl> + mark_idle . sh <nl> fi <nl> <nl> - command : shell . exec <nl> functions : <nl> storageEngine : $ { storageEngine } <nl> test : $ { test } <nl> production : true <nl> + mongodb_binary_archive : " https : / / s3 . amazonaws . com / mciuploads / $ { project } / $ { version_id } / $ { revision } / $ { platform } / mongod - $ { version_id } . tar . gz " <nl> EOF <nl> <nl> cat > runtime . yml < < EOF <nl> functions : <nl> script_flags : $ { script_flags } <nl> dsi_rev : $ { dsi_rev } <nl> workloads_rev : $ { workloads_rev } <nl> - <nl> - # compositions of expansions <nl> - mongodb_binary_archive : " https : / / s3 . amazonaws . com / mciuploads / $ { project } / $ { version_id } / $ { revision } / $ { platform } / mongod - $ { version_id } . tar . gz " <nl> EOF <nl> - command : shell . exec <nl> params : <nl> functions : <nl> virtualenv . / venv <nl> source . / venv / bin / activate <nl> pip install - r . . / src / dsi / dsi / requirements . txt <nl> - python . . / src / dsi / dsi / bin / bootstrap . py - - production <nl> - ls <nl> - pwd <nl> + python . . / src / dsi / dsi / bin / bootstrap . py <nl> - command : shell . exec <nl> params : <nl> script : | <nl> set - v <nl> set - e <nl> source work / dsienv . sh <nl> - $ DSI_PATH / bin / setup - dsi - env . sh <nl> + setup - dsi - env . sh <nl> ls - a work <nl> <nl> - " infrastructure provisioning " : <nl> + " deploy cluster " : <nl> - command : shell . exec <nl> - # call infrastructure - provisioning . py . This will either create a cluster , or update tags on existing instances . <nl> params : <nl> working_dir : work <nl> script : | <nl> functions : <nl> set - v <nl> source . / dsienv . sh <nl> source . / venv / bin / activate <nl> - $ DSI_PATH / bin / infrastructure_provisioning . py <nl> - <nl> - " configure mongodb cluster " : <nl> - - command : shell . exec <nl> - # bring up the mongod <nl> - params : <nl> - working_dir : work <nl> - script : | <nl> - set - e <nl> - set - o verbose <nl> - source . / dsienv . sh <nl> - source . / venv / bin / activate <nl> - $ DSI_PATH / bin / mongodb_setup . py & & echo " $ { setup } MongoDB Cluster STARTED . " <nl> + infrastructure_provisioning . py <nl> + mongodb_setup . py <nl> <nl> " run test " : <nl> - command : shell . exec <nl> + type : test <nl> params : <nl> working_dir : work <nl> script : | <nl> functions : <nl> set - v <nl> source . / dsienv . sh <nl> source . / venv / bin / activate <nl> - echo " Run test for $ { test } - $ { storageEngine } with setup $ { setup } " <nl> - $ DSI_PATH / bin / run_test . py $ { storageEngine } $ { test } $ { cluster } <nl> + test_control . py <nl> - command : " json . send " <nl> params : <nl> name : " perf " <nl> functions : <nl> working_dir : work <nl> script : | <nl> source . / dsienv . sh <nl> - $ DSI_PATH / bin / make_artifact . sh <nl> + make_artifact . sh <nl> <nl> " analyze " : <nl> - command : json . get_history <nl> tasks : <nl> vars : <nl> storageEngine : " wiredTiger " <nl> test : " ycsb " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> - test : " ycsb " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> vars : <nl> tasks : <nl> vars : <nl> storageEngine : " mmapv1 " <nl> test : " ycsb " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> - test : " ycsb " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> vars : <nl> tasks : <nl> vars : <nl> storageEngine : " wiredTiger " <nl> test : " ycsb - wmajority " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> - test : " ycsb - wmajority " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> vars : <nl> tasks : <nl> vars : <nl> storageEngine : " mmapv1 " <nl> test : " ycsb - wmajority " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> - test : " ycsb - wmajority " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> vars : <nl> tasks : <nl> vars : <nl> storageEngine : " wiredTiger " <nl> test : " core " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> - test : " core " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> vars : <nl> storageEngine : " mmapv1 " <nl> test : " core " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> - test : " core " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> vars : <nl> storageEngine : " wiredTiger " <nl> test : " agg_query_comparison_bestbuy " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> - test : " agg_query_comparison_bestbuy " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> vars : <nl> storageEngine : " mmapv1 " <nl> test : " agg_query_comparison_bestbuy " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> - test : " agg_query_comparison_bestbuy " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> vars : <nl> storageEngine : " wiredTiger " <nl> test : " non_sharded " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> - test : " non_sharded " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> vars : <nl> storageEngine : " mmapv1 " <nl> test : " non_sharded " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> - test : " non_sharded " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> vars : <nl> storageEngine : " wiredTiger " <nl> test : " mongos " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> - test : " mongos " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> vars : <nl> storageEngine : " mmapv1 " <nl> test : " mongos " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> - test : " mongos " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> vars : <nl> storageEngine : " wiredTiger " <nl> test : " move_chunk " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> - test : " move_chunk " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> vars : <nl> storageEngine : " mmapv1 " <nl> test : " move_chunk " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> - test : " move_chunk " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> storageEngine : " wiredTiger " <nl> test : " secondary_performance " <nl> setup : " replica - 2node " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> - setup : " replica - 2node " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> - test : " secondary_performance " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> storageEngine : " mmapv1 " <nl> test : " secondary_performance " <nl> setup : " replica - 2node " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> - setup : " replica - 2node " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> - test : " secondary_performance " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> - func : " prepare environment " <nl> vars : <nl> storageEngine : " wiredTiger " <nl> - test : " initialSync " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> + test : " initialsync " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> - test : " initialSync " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> - func : " prepare environment " <nl> vars : <nl> storageEngine : " mmapv1 " <nl> - test : " initialSync " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> + test : " initialsync " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " mmapv1 " <nl> - test : " initialSync " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl> tasks : <nl> vars : <nl> storageEngine : " wiredTiger " <nl> test : " initialsync - logkeeper " <nl> - - func : " infrastructure provisioning " <nl> - - func : " configure mongodb cluster " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> + - func : " deploy cluster " <nl> - func : " run test " <nl> - vars : <nl> - storageEngine : " wiredTiger " <nl> - test : " initialsync - logkeeper " <nl> - func : " make test log artifact " <nl> - func : " analyze " <nl> <nl>
SERVER - 30770 : system_perf . yml : Use new DSI interface and cleanup
mongodb/mongo
2b9095818a4b6fc0a797ff1dd25fdfe0792b99c1
2017-11-22T15:56:11Z
mmm a / Marlin / src / HAL / HAL_DUE / Servo_Due . cpp <nl> ppp b / Marlin / src / HAL / HAL_DUE / Servo_Due . cpp <nl> void Servo_Handler ( timer16_Sequence_t timer , Tc * tc , uint8_t channel ) { <nl> tc - > TC_CHANNEL [ channel ] . TC_SR ; <nl> if ( Channel [ timer ] < 0 ) <nl> tc - > TC_CHANNEL [ channel ] . TC_CCR | = TC_CCR_SWTRG ; / / channel set to - 1 indicated that refresh interval completed so reset the timer <nl> - else if ( SERVO_INDEX ( timer , Channel [ timer ] ) < ServoCount & & SERVO ( timer , Channel [ timer ] ) . Pin . isActive ) <nl> - digitalWrite ( SERVO ( timer , Channel [ timer ] ) . Pin . nbr , LOW ) ; / / pulse this channel low if activated <nl> + else if ( SERVO_INDEX ( timer , Channel [ timer ] ) < ServoCount & & SERVO ( timer , Channel [ timer ] ) . Pin . isActive ) <nl> + digitalWrite ( SERVO ( timer , Channel [ timer ] ) . Pin . nbr , LOW ) ; / / pulse this channel low if activated <nl> <nl> Channel [ timer ] + + ; / / increment to the next channel <nl> if ( SERVO_INDEX ( timer , Channel [ timer ] ) < ServoCount & & Channel [ timer ] < SERVOS_PER_TIMER ) { <nl> tc - > TC_CHANNEL [ channel ] . TC_RA = tc - > TC_CHANNEL [ channel ] . TC_CV + SERVO ( timer , Channel [ timer ] ) . ticks ; <nl> if ( SERVO ( timer , Channel [ timer ] ) . Pin . isActive ) / / check if activated <nl> - digitalWrite ( SERVO ( timer , Channel [ timer ] ) . Pin . nbr , HIGH ) ; / / its an active channel so pulse it high <nl> + digitalWrite ( SERVO ( timer , Channel [ timer ] ) . Pin . nbr , HIGH ) ; / / its an active channel so pulse it high <nl> } <nl> else { <nl> / / finished all channels so wait for the refresh period to expire before starting over <nl> mmm a / Marlin / src / HAL / HAL_LPC1768 / SanityCheck . h <nl> ppp b / Marlin / src / HAL / HAL_LPC1768 / SanityCheck . h <nl> <nl> | | MB ( RAMPS_14_RE_ARM_SF ) ) <nl> # error " Re - ARM with REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and TMC2130 require TMC_USE_SW_SPI " <nl> # endif <nl> + <nl> + # if 1 < ( ENABLED ( LPC_SD_CUSTOM_CABLE ) + ENABLED ( LPC_SD_LCD ) + ENABLED ( LPC_SD_ONBOARD ) ) <nl> + # error " Enable only one of LPC_SD_CUSTOM_CABLE , LPC_SD_LCD , or LPC_SD_ONBOARD . " <nl> + # endif <nl> + <nl> + # if 1 < ( ENABLED ( USB_SD_DISABLED ) + ENABLED ( USB_SD_ONBOARD ) ) <nl> + # error " Enable only one of USB_SD_DISABLED or USB_SD_ONBOARD . " <nl> + # endif <nl> mmm a / Marlin / src / HAL / HAL_LPC1768 / main . cpp <nl> ppp b / Marlin / src / HAL / HAL_LPC1768 / main . cpp <nl> void HAL_init ( ) { <nl> / / debug_frmwrk_init ( ) ; <nl> / / _DBG ( " \ n \ nDebug running \ n " ) ; <nl> / / Initialise the SD card chip select pins as soon as possible <nl> - # ifdef SS_PIN <nl> - digitalWrite ( SS_PIN , HIGH ) ; <nl> - pinMode ( SS_PIN , OUTPUT ) ; <nl> + # if PIN_EXISTS ( SS ) <nl> + WRITE ( SS_PIN , HIGH ) ; <nl> + SET_OUTPUT ( SS_PIN ) ; <nl> # endif <nl> - # ifdef ONBOARD_SD_CS <nl> - digitalWrite ( ONBOARD_SD_CS , HIGH ) ; <nl> - pinMode ( ONBOARD_SD_CS , OUTPUT ) ; <nl> + <nl> + # if defined ( ONBOARD_SD_CS ) & & ONBOARD_SD_CS > - 1 <nl> + WRITE ( ONBOARD_SD_CS , HIGH ) ; <nl> + SET_OUTPUT ( ONBOARD_SD_CS ) ; <nl> # endif <nl> + <nl> USB_Init ( ) ; / / USB Initialization <nl> USB_Connect ( FALSE ) ; / / USB clear connection <nl> delay ( 1000 ) ; / / Give OS time to notice <nl> USB_Connect ( TRUE ) ; <nl> - # ifndef USB_SD_DISABLED <nl> + <nl> + # if DISABLED ( USB_SD_DISABLED ) <nl> MSC_SD_Init ( 0 ) ; / / Enable USB SD card access <nl> # endif <nl> + <nl> const millis_t usb_timeout = millis ( ) + 2000 ; <nl> while ( ! USB_Configuration & & PENDING ( millis ( ) , usb_timeout ) ) { <nl> delay ( 50 ) ; <nl> void HAL_init ( ) { <nl> <nl> / / HAL idle task <nl> void HAL_idletask ( void ) { <nl> - # if ENABLED ( SDSUPPORT ) & & defined ( SHARED_SD_CARD ) <nl> + # if ENABLED ( SDSUPPORT ) & & ENABLED ( SHARED_SD_CARD ) <nl> / / If Marlin is using the SD card we need to lock it to prevent access from <nl> / / a PC via USB . <nl> / / Other HALs use IS_SD_PRINTING ( ) and IS_SD_FILE_OPEN ( ) to check for access but <nl> mmm a / Marlin / src / HAL / HAL_STM32F7 / HAL_timers_STM32F7 . cpp <nl> ppp b / Marlin / src / HAL / HAL_STM32F7 / HAL_timers_STM32F7 . cpp <nl> void HAL_timer_start ( const uint8_t timer_num , const uint32_t frequency ) { <nl> timerConfig [ 0 ] . IRQ_Id = TIM5_IRQn ; <nl> timerConfig [ 0 ] . callback = ( uint32_t ) TC5_Handler ; <nl> HAL_NVIC_SetPriority ( timerConfig [ 0 ] . IRQ_Id , 1 , 0 ) ; <nl> - pinMode ( STEPPER_ENABLE_PIN , OUTPUT ) ; <nl> - digitalWrite ( STEPPER_ENABLE_PIN , LOW ) ; <nl> + SET_OUTPUT ( STEPPER_ENABLE_PIN ) ; <nl> + WRITE ( STEPPER_ENABLE_PIN ) ; <nl> break ; <nl> case TEMP_TIMER_NUM : <nl> / / TEMP TIMER TIM7 / / any available 16bit Timer ( 1 already used for PWM ) <nl> mmm a / Marlin / src / HAL / HAL_STM32F7 / TMC2660 . cpp <nl> ppp b / Marlin / src / HAL / HAL_STM32F7 / TMC2660 . cpp <nl> void TMC26XStepper : : start ( ) { <nl> pinMode ( step_pin , OUTPUT ) ; <nl> pinMode ( dir_pin , OUTPUT ) ; <nl> pinMode ( cs_pin , OUTPUT ) ; <nl> - / / pinMode ( STEPPER_ENABLE_PIN , OUTPUT ) ; <nl> + / / SET_OUTPUT ( STEPPER_ENABLE_PIN ) ; <nl> digitalWrite ( step_pin , LOW ) ; <nl> digitalWrite ( dir_pin , LOW ) ; <nl> digitalWrite ( cs_pin , HIGH ) ; <nl> inline void TMC26XStepper : : send262 ( uint32_t datagram ) { <nl> / / } <nl> <nl> / / select the TMC driver <nl> - digitalWrite ( cs_pin , LOW ) ; <nl> + digitalWrite ( cs_pin , LOW ) ; <nl> <nl> / / ensure that only valid bist are set ( 0 - 19 ) <nl> / / datagram & = REGISTER_BIT_PATTERN ; <nl> inline void TMC26XStepper : : send262 ( uint32_t datagram ) { <nl> # endif <nl> <nl> / / deselect the TMC chip <nl> - digitalWrite ( cs_pin , HIGH ) ; <nl> + digitalWrite ( cs_pin , HIGH ) ; <nl> <nl> / / restore the previous SPI mode if neccessary <nl> / / if the mode is not correct set it to mode 3 <nl> mmm a / Marlin / src / pins / pins_AZTEEG_X5_MINI_WIFI . h <nl> ppp b / Marlin / src / pins / pins_AZTEEG_X5_MINI_WIFI . h <nl> <nl> / / is powered on to enable SD access . <nl> <nl> # if ENABLED ( LPC_SD_LCD ) <nl> + <nl> # define SCK_PIN P0_15 <nl> # define MISO_PIN P0_17 <nl> # define MOSI_PIN P0_18 <nl> # define SS_PIN P1_23 / / Chip select for SD card used by Marlin <nl> # define ONBOARD_SD_CS P0_06 / / Chip select for " System " SD card <nl> - # endif <nl> <nl> - # if ENABLED ( LPC_SD_ONBOARD ) <nl> + # elif ENABLED ( LPC_SD_ONBOARD ) <nl> + <nl> # if ENABLED ( USB_SD_ONBOARD ) <nl> / / When sharing the SD card with a PC we want the menu options to <nl> / / mount / unmount the card and refresh it . So we disable card detect . <nl> <nl> # define MOSI_PIN P0_09 <nl> # define SS_PIN P0_06 / / Chip select for SD card used by Marlin <nl> # define ONBOARD_SD_CS P0_06 / / Chip select for " System " SD card <nl> + <nl> # endif <nl> mmm a / Marlin / src / pins / pins_MKS_SBASE . h <nl> ppp b / Marlin / src / pins / pins_MKS_SBASE . h <nl> <nl> <nl> / * <nl> * There are a number of configurations available for the SBase SD card reader . <nl> - * A custom cable can be used to allow access to the LCD based SD card . <nl> - * A standard cable can be used for access to the LCD SD card ( but no SD detect ) . <nl> - * The onboard SD card can be used and optionally shared with a PC via USB . <nl> + * - A custom cable can be used to allow access to the LCD based SD card . <nl> + * - A standard cable can be used for access to the LCD SD card ( but no SD detect ) . <nl> + * - The onboard SD card can be used and optionally shared with a PC via USB . <nl> * / <nl> <nl> / / # define LPC_SD_CUSTOM_CABLE / / Use a custom cable to access the SD <nl> / / # define LPC_SD_LCD / / Marlin uses the SD drive attached to the LCD <nl> # define LPC_SD_ONBOARD / / Marlin uses the SD drive attached to the control board <nl> <nl> - # ifdef LPC_SD_CUSTOM_CABLE <nl> + # if ENABLED ( LPC_SD_CUSTOM_CABLE ) <nl> + <nl> / * * <nl> * A custom cable is needed . See the README file in the <nl> * Marlin \ src \ config \ examples \ Mks \ Sbase directory <nl> <nl> * If you can ' t find a pin to use for the LCD ' s SD_DETECT then comment out <nl> * SD_DETECT_PIN entirely and remove that wire from the the custom cable . <nl> * / <nl> - # define SD_DETECT_PIN P2_11 / / J8 - 5 ( moved from EXP2 P0 . 27 ) <nl> - # define SCK_PIN P1_22 / / J8 - 2 ( moved from EXP2 P0 . 7 ) <nl> - # define MISO_PIN P1_23 / / J8 - 3 ( moved from EXP2 P0 . 8 ) <nl> - # define MOSI_PIN P2_12 / / J8 - 4 ( moved from EXP2 P0 . 9 ) <nl> - # define SS_PIN P0_28 / / Chip select for SD card used by Marlin <nl> - # define ONBOARD_SD_CS P0_06 / / Chip select for " System " SD card <nl> + # define SD_DETECT_PIN P2_11 / / J8 - 5 ( moved from EXP2 P0 . 27 ) <nl> + # define SCK_PIN P1_22 / / J8 - 2 ( moved from EXP2 P0 . 7 ) <nl> + # define MISO_PIN P1_23 / / J8 - 3 ( moved from EXP2 P0 . 8 ) <nl> + # define MOSI_PIN P2_12 / / J8 - 4 ( moved from EXP2 P0 . 9 ) <nl> + # define SS_PIN P0_28 / / Chip select for SD card used by Marlin <nl> + # define ONBOARD_SD_CS P0_06 / / Chip select for " System " SD card <nl> # define LPC_SOFTWARE_SPI / / With a custom cable we need software SPI because the <nl> / / selected pins are not on a hardware SPI controller <nl> - # endif <nl> + # elif ENABLED ( LPC_SD_LCD ) <nl> <nl> - # ifdef LPC_SD_LCD <nl> / / use standard cable and header , SPI and SD detect sre shared with on - board SD card <nl> / / hardware SPI is used for both SD cards . The detect pin is shred between the <nl> / / LCD and onboard SD readers so we disable it . <nl> - # undef SD_DETECT_PIN <nl> - # define SCK_PIN P0_07 <nl> - # define MISO_PIN P0_08 <nl> - # define MOSI_PIN P0_09 <nl> - # define SS_PIN P0_28 / / Chip select for SD card used by Marlin <nl> - # define ONBOARD_SD_CS P0_06 / / Chip select for " System " SD card <nl> - # endif <nl> + # define SCK_PIN P0_07 <nl> + # define MISO_PIN P0_08 <nl> + # define MOSI_PIN P0_09 <nl> + # define SS_PIN P0_28 / / Chip select for SD card used by Marlin <nl> + # define ONBOARD_SD_CS P0_06 / / Chip select for " System " SD card <nl> + <nl> + # elif ENABLED ( LPC_SD_ONBOARD ) <nl> <nl> - # ifdef LPC_SD_ONBOARD <nl> / / The external SD card is not used . Hardware SPI is used to access the card . <nl> - # ifdef USB_SD_ONBOARD <nl> + # if ENABLED ( USB_SD_ONBOARD ) <nl> / / When sharing the SD card with a PC we want the menu options to <nl> / / mount / unmount the card and refresh it . So we disable card detect . <nl> # define SHARED_SD_CARD <nl> - # undef SD_DETECT_PIN <nl> # else <nl> - # define SD_DETECT_PIN P0_27 <nl> + # define SD_DETECT_PIN P0_27 <nl> # endif <nl> - # define SCK_PIN P0_07 <nl> - # define MISO_PIN P0_08 <nl> - # define MOSI_PIN P0_09 <nl> - # define SS_PIN P0_06 / / Chip select for SD card used by Marlin <nl> - # define ONBOARD_SD_CS P0_06 / / Chip select for " System " SD card <nl> + # define SCK_PIN P0_07 <nl> + # define MISO_PIN P0_08 <nl> + # define MOSI_PIN P0_09 <nl> + # define SS_PIN P0_06 / / Chip select for SD card used by Marlin <nl> + # define ONBOARD_SD_CS P0_06 / / Chip select for " System " SD card <nl> + <nl> # endif <nl> <nl> / * * <nl> <nl> # endif <nl> # endif <nl> # endif <nl> + <nl> # if HAS_DRIVER ( TMC2208 ) <nl> / / The shortage of pins becomes apparent . <nl> / / Worst case you may have to give up the LCD <nl> mmm a / Marlin / src / pins / pins_RAMPS_RE_ARM . h <nl> ppp b / Marlin / src / pins / pins_RAMPS_RE_ARM . h <nl> <nl> # define ENET_TXD0 P1_00 / / ( 78 ) J12 - 11 <nl> # define ENET_TXD1 P1_01 / / ( 79 ) J12 - 12 <nl> <nl> - <nl> / / # define USB_SD_DISABLED <nl> # define USB_SD_ONBOARD / / Provide the onboard SD card to the host as a USB mass storage device <nl> <nl> / / # define LPC_SD_LCD / / Marlin uses the SD drive attached to the LCD <nl> # define LPC_SD_ONBOARD / / Marlin uses the SD drive on the control board <nl> <nl> - # ifdef LPC_SD_LCD <nl> + # if ENABLED ( LPC_SD_LCD ) <nl> + <nl> # define SCK_PIN P0_15 <nl> # define MISO_PIN P0_17 <nl> # define MOSI_PIN P0_18 <nl> # define SS_PIN P1_23 / / Chip select for SD card used by Marlin <nl> # define ONBOARD_SD_CS P0_06 / / Chip select for " System " SD card <nl> - # endif <nl> <nl> - # ifdef LPC_SD_ONBOARD <nl> - # ifdef USB_SD_ONBOARD <nl> + # elif ENABLED ( LPC_SD_ONBOARD ) <nl> + <nl> + # if ENABLED ( USB_SD_ONBOARD ) <nl> / / When sharing the SD card with a PC we want the menu options to <nl> / / mount / unmount the card and refresh it . So we disable card detect . <nl> # define SHARED_SD_CARD <nl> <nl> # define MOSI_PIN P0_09 <nl> # define SS_PIN P0_06 / / Chip select for SD card used by Marlin <nl> # define ONBOARD_SD_CS P0_06 / / Chip select for " System " SD card <nl> + <nl> # endif <nl> <nl> / * * <nl> - * Fast PWMS <nl> + * Fast PWMs <nl> * <nl> * The LPC1768 ' s hardware PWM controller has 6 channels . Each channel <nl> * can be setup to either control a dedicated pin directly or to generate <nl> <nl> * / <nl> <nl> / * * <nl> - * special pins <nl> + * Special pins <nl> * P1_30 ( 37 ) - not 5V tolerant <nl> * P1_31 ( 49 ) - not 5V tolerant <nl> * P0_27 ( 57 ) - open collector <nl>
Use FastIO , sanity - check LPC SD options , apply formatting ( )
MarlinFirmware/Marlin
55807731918625b527a75668bc7fa069640f83b9
2018-10-26T20:23:02Z
mmm a / src / ccmain / tessedit . cpp <nl> ppp b / src / ccmain / tessedit . cpp <nl> <nl> # include " stopper . h " <nl> # include " intmatcher . h " <nl> # include " chop . h " <nl> - # include " efio . h " <nl> # include " danerror . h " <nl> # include " globals . h " <nl> # ifndef ANDROID_BUILD <nl> mmm a / src / classify / blobclass . cpp <nl> ppp b / src / classify / blobclass . cpp <nl> <nl> # include < cstdio > <nl> <nl> # include " classify . h " <nl> - # include " efio . h " <nl> # include " featdefs . h " <nl> # include " mf . h " <nl> # include " normfeat . h " <nl> void Classify : : LearnBlob ( const STRING & fontname , TBLOB * blob , <nl> / / Writes stored training data to a . tr file based on the given filename . <nl> / / Returns false on error . <nl> bool Classify : : WriteTRFile ( const STRING & filename ) { <nl> + bool result = false ; <nl> STRING tr_filename = filename + " . tr " ; <nl> - FILE * fp = Efopen ( tr_filename . string ( ) , " wb " ) ; <nl> - const size_t len = tr_file_data_ . length ( ) ; <nl> - const bool result = <nl> - fwrite ( & tr_file_data_ [ 0 ] , sizeof ( tr_file_data_ [ 0 ] ) , len , fp ) = = len ; <nl> - fclose ( fp ) ; <nl> + FILE * fp = fopen ( tr_filename . string ( ) , " wb " ) ; <nl> + if ( fp ) { <nl> + const size_t len = tr_file_data_ . length ( ) ; <nl> + result = <nl> + fwrite ( & tr_file_data_ [ 0 ] , sizeof ( tr_file_data_ [ 0 ] ) , len , fp ) = = len ; <nl> + fclose ( fp ) ; <nl> + } <nl> tr_file_data_ . truncate_at ( 0 ) ; <nl> return result ; <nl> } <nl> mmm a / src / classify / cutoffs . cpp <nl> ppp b / src / classify / cutoffs . cpp <nl> <nl> # include < cstdio > <nl> <nl> # include " classify . h " <nl> - # include " efio . h " <nl> # include " globals . h " <nl> # include " helpers . h " <nl> # include " serialis . h " <nl> mmm a / src / classify / mastertrainer . cpp <nl> ppp b / src / classify / mastertrainer . cpp <nl> <nl> # include " allheaders . h " <nl> # include " boxread . h " <nl> # include " classify . h " <nl> - # include " efio . h " <nl> # include " errorcounter . h " <nl> # include " featdefs . h " <nl> # include " sampleiterator . h " <nl> void MasterTrainer : : ReadTrainingSamples ( const char * page_name , <nl> const int cn_feature_type = ShortNameToFeatureType ( feature_defs , kCNFeatureType ) ; <nl> const int geo_feature_type = ShortNameToFeatureType ( feature_defs , kGeoFeatureType ) ; <nl> <nl> - FILE * fp = Efopen ( page_name , " rb " ) ; <nl> + FILE * fp = fopen ( page_name , " rb " ) ; <nl> if ( fp = = nullptr ) { <nl> tprintf ( " Failed to open tr file : % s \ n " , page_name ) ; <nl> return ; <nl> mmm a / src / classify / normmatch . cpp <nl> ppp b / src / classify / normmatch . cpp <nl> <nl> # include " classify . h " <nl> # include " clusttool . h " <nl> # include " const . h " <nl> - # include " efio . h " <nl> # include " emalloc . h " <nl> # include " globals . h " <nl> # include " helpers . h " <nl> mmm a / src / classify / outfeat . cpp <nl> ppp b / src / classify / outfeat . cpp <nl> <nl> # include " outfeat . h " <nl> <nl> # include " classify . h " <nl> - # include " efio . h " <nl> # include " featdefs . h " <nl> # include " mfoutline . h " <nl> # include " ocrfeatures . h " <nl> mmm a / src / classify / picofeat . cpp <nl> ppp b / src / classify / picofeat . cpp <nl> <nl> # include " picofeat . h " <nl> <nl> # include " classify . h " <nl> - # include " efio . h " <nl> # include " featdefs . h " <nl> # include " fpoint . h " <nl> # include " mfoutline . h " <nl> mmm a / src / cutil / Makefile . am <nl> ppp b / src / cutil / Makefile . am <nl> AM_CPPFLAGS + = - DTESS_EXPORTS \ <nl> endif <nl> <nl> noinst_HEADERS = \ <nl> - bitvec . h callcpp . h const . h cutil . h cutil_class . h danerror . h efio . h \ <nl> + bitvec . h callcpp . h const . h cutil . h cutil_class . h danerror . h \ <nl> emalloc . h globals . h \ <nl> oldlist . h structures . h <nl> <nl> noinst_LTLIBRARIES = libtesseract_cutil . la <nl> <nl> libtesseract_cutil_la_SOURCES = \ <nl> - bitvec . cpp callcpp . cpp cutil . cpp cutil_class . cpp danerror . cpp efio . cpp \ <nl> + bitvec . cpp callcpp . cpp cutil . cpp cutil_class . cpp danerror . cpp \ <nl> emalloc . cpp \ <nl> oldlist . cpp structures . cpp <nl> deleted file mode 100644 <nl> index 943efc9ba . . 000000000 <nl> mmm a / src / cutil / efio . cpp <nl> ppp / dev / null <nl> <nl> - / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> - * * Filename : efio . c <nl> - * * Purpose : Utility I / O routines <nl> - * * Author : Dan Johnson <nl> - * * History : 5 / 21 / 89 , DSJ , Created . <nl> - * * <nl> - * * ( c ) Copyright Hewlett - Packard Company , 1988 . <nl> - * * Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> - * * you may not use this file except in compliance with the License . <nl> - * * You may obtain a copy of the License at <nl> - * * http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> - * * Unless required by applicable law or agreed to in writing , software <nl> - * * distributed under the License is distributed on an " AS IS " BASIS , <nl> - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> - * * See the License for the specific language governing permissions and <nl> - * * limitations under the License . <nl> - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> - / * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> - Include Files and Type Defines <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - * / <nl> - # include " efio . h " <nl> - # include " danerror . h " <nl> - # include < cstdio > <nl> - # include < cstring > <nl> - <nl> - # define MAXERRORMESSAGE 256 <nl> - <nl> - / * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> - Public Code <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - * / <nl> - / * * <nl> - * This routine attempts to open the specified file in the <nl> - * specified mode . If the file can be opened , a pointer to <nl> - * the open file is returned . If the file cannot be opened , <nl> - * an error is trapped . <nl> - * @ param Name name of file to be opened <nl> - * @ param Mode mode to be used to open file <nl> - * @ return Pointer to open file . <nl> - * @ note Globals : None <nl> - * @ note Exceptions : # FOPENERROR unable to open specified file <nl> - * @ note History : 5 / 21 / 89 , DSJ , Created . <nl> - * / <nl> - FILE * Efopen ( const char * Name , const char * Mode ) { <nl> - FILE * File ; <nl> - char ErrorMessage [ MAXERRORMESSAGE ] ; <nl> - <nl> - File = fopen ( Name , Mode ) ; <nl> - if ( File = = nullptr ) { <nl> - sprintf ( ErrorMessage , " Unable to open % s " , Name ) ; <nl> - DoError ( FOPENERROR , ErrorMessage ) ; <nl> - return ( nullptr ) ; <nl> - } <nl> - else <nl> - return ( File ) ; <nl> - } / * Efopen * / <nl> deleted file mode 100644 <nl> index 593e6b66c . . 000000000 <nl> mmm a / src / cutil / efio . h <nl> ppp / dev / null <nl> <nl> - / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> - * * Filename : efio . h <nl> - * * Purpose : Definition of file I / O routines <nl> - * * Author : Dan Johnson <nl> - * * History : 5 / 21 / 89 , DSJ , Created . <nl> - * * <nl> - * * ( c ) Copyright Hewlett - Packard Company , 1988 . <nl> - * * Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> - * * you may not use this file except in compliance with the License . <nl> - * * You may obtain a copy of the License at <nl> - * * http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> - * * Unless required by applicable law or agreed to in writing , software <nl> - * * distributed under the License is distributed on an " AS IS " BASIS , <nl> - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> - * * See the License for the specific language governing permissions and <nl> - * * limitations under the License . <nl> - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> - # ifndef EFIO_H <nl> - # define EFIO_H <nl> - <nl> - / * * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> - Include Files and Type Defines <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - * * / <nl> - # include < cstdio > <nl> - <nl> - # define FOPENERROR 3000 <nl> - <nl> - / * * mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> - Public Function Prototype <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - * * / <nl> - FILE * Efopen ( const char * Name , const char * Mode ) ; <nl> - # endif <nl> mmm a / src / dict / stopper . cpp <nl> ppp b / src / dict / stopper . cpp <nl> <nl> # include " const . h " <nl> # include " danerror . h " <nl> # include " dict . h " <nl> - # include " efio . h " <nl> # include " helpers . h " <nl> # include " matchdefs . h " <nl> # include " pageres . h " <nl> mmm a / src / training / cntraining . cpp <nl> ppp b / src / training / cntraining . cpp <nl> <nl> Include Files and Type Defines <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - * / <nl> # include " oldlist . h " <nl> - # include " efio . h " <nl> # include " emalloc . h " <nl> # include " featdefs . h " <nl> # include " tessopt . h " <nl> int main ( int argc , char * argv [ ] ) { <nl> Config = CNConfig ; <nl> <nl> const char * PageName ; <nl> - FILE * TrainingPage ; <nl> LIST CharList = NIL_LIST ; <nl> CLUSTERER * Clusterer = nullptr ; <nl> LIST ProtoList = NIL_LIST ; <nl> int main ( int argc , char * argv [ ] ) { <nl> int num_fonts = 0 ; <nl> while ( ( PageName = GetNextFilename ( argc , argv ) ) ! = nullptr ) { <nl> printf ( " Reading % s . . . \ n " , PageName ) ; <nl> - TrainingPage = Efopen ( PageName , " rb " ) ; <nl> - ReadTrainingSamples ( FeatureDefs , PROGRAM_FEATURE_TYPE , 100 , nullptr , <nl> - TrainingPage , & CharList ) ; <nl> - fclose ( TrainingPage ) ; <nl> - + + num_fonts ; <nl> + FILE * TrainingPage = fopen ( PageName , " rb " ) ; <nl> + ASSERT_HOST ( TrainingPage ) ; <nl> + if ( TrainingPage ) { <nl> + ReadTrainingSamples ( FeatureDefs , PROGRAM_FEATURE_TYPE , 100 , nullptr , <nl> + TrainingPage , & CharList ) ; <nl> + fclose ( TrainingPage ) ; <nl> + + + num_fonts ; <nl> + } <nl> } <nl> printf ( " Clustering . . . \ n " ) ; <nl> / / To allow an individual font to form a separate cluster , <nl> static void WriteNormProtos ( const char * Directory , LIST LabeledProtoList , <nl> } <nl> Filename + = " normproto " ; <nl> printf ( " \ nWriting % s . . . " , Filename . string ( ) ) ; <nl> - File = Efopen ( Filename . string ( ) , " wb " ) ; <nl> + File = fopen ( Filename . string ( ) , " wb " ) ; <nl> + ASSERT_HOST ( File ) ; <nl> fprintf ( File , " % 0d \ n " , feature_desc - > NumParams ) ; <nl> WriteParamDesc ( File , feature_desc - > NumParams , feature_desc - > ParamDesc ) ; <nl> iterate ( LabeledProtoList ) <nl> mmm a / src / training / commontraining . cpp <nl> ppp b / src / training / commontraining . cpp <nl> <nl> # include " classify . h " <nl> # include " cluster . h " <nl> # include " clusttool . h " <nl> - # include " efio . h " <nl> # include " emalloc . h " <nl> # include " featdefs . h " <nl> # include " fontinfo . h " <nl> mmm a / src / training / mergenf . cpp <nl> ppp b / src / training / mergenf . cpp <nl> <nl> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> # include " mergenf . h " <nl> # include " host . h " <nl> - # include " efio . h " <nl> # include " clusttool . h " <nl> # include " cluster . h " <nl> # include " oldlist . h " <nl> mmm a / src / training / mftraining . cpp <nl> ppp b / src / training / mftraining . cpp <nl> <nl> # include " clusttool . h " <nl> # include " commontraining . h " <nl> # include " danerror . h " <nl> - # include " efio . h " <nl> # include " emalloc . h " <nl> # include " featdefs . h " <nl> # include " fontinfo . h " <nl>
Replace Efopen by fopen and remove efio . cpp , efio . h
tesseract-ocr/tesseract
b57afc7c784c6b6aea55f3f25af0b491103992ef
2018-07-02T15:46:28Z
mmm a / include / swift / Basic / ByteTreeSerialization . h <nl> ppp b / include / swift / Basic / ByteTreeSerialization . h <nl> <nl> <nl> # include " llvm / Support / BinaryStreamError . h " <nl> # include " llvm / Support / BinaryStreamWriter . h " <nl> + # include " swift / Basic / ExponentialGrowthAppendingBinaryByteStream . h " <nl> # include < map > <nl> <nl> namespace { <nl> class ByteTreeWriter ; <nl> <nl> using UserInfoMap = std : : map < void * , void * > ; <nl> <nl> - / / / Add a template specialization of \ c ObjectTraits for any that type <nl> + / / / Add a template specialization of \ c ObjectTraits for any type that <nl> / / / serializes as an object consisting of multiple fields . <nl> template < class T > <nl> struct ObjectTraits { <nl> struct ObjectTraits { <nl> / / UserInfoMap & UserInfo ) ; <nl> } ; <nl> <nl> - / / / Add a template specialization of \ c ScalarTraits for any that type <nl> + / / / Add a template specialization of \ c ScalarTraits for any type that <nl> / / / serializes into a raw set of bytes . <nl> template < class T > <nl> struct ScalarTraits { <nl> struct ScalarTraits { <nl> / / static llvm : : Error write ( llvm : : BinaryStreamWriter & Writer , const T & Value ) ; <nl> } ; <nl> <nl> - / / / Add a template specialization of \ c WrapperTypeTraits for any that type <nl> + / / / Add a template specialization of \ c DirectlyEncodable for any type whose <nl> + / / / serialized form is equal to its binary representation on the serializing <nl> + / / / machine . <nl> + template < class T > <nl> + struct DirectlyEncodable { <nl> + / / Must provide : <nl> + <nl> + / / static bool const value = true ; <nl> + } ; <nl> + <nl> + / / / Add a template specialization of \ c WrapperTypeTraits for any type that <nl> / / / serializes as a type that already has a specialization of \ c ScalarTypes . <nl> / / / This will typically be useful for types like enums that have a 1 - to - 1 <nl> / / / mapping to e . g . an integer . <nl> class ByteTreeWriter { <nl> / / / The writer to which the binary data is written . <nl> llvm : : BinaryStreamWriter & StreamWriter ; <nl> <nl> + / / / The underlying stream of the StreamWriter . We need this reference so that <nl> + / / / we can call \ c ExponentialGrowthAppendingBinaryByteStream . writeRaw <nl> + / / / which is more efficient than the generic \ c writeBytes of <nl> + / / / \ c llvm : : BinaryStreamWriter since it avoids the arbitrary size memcopy . <nl> + ExponentialGrowthAppendingBinaryByteStream & Stream ; <nl> + <nl> / / / The number of fields this object contains . \ c UINT_MAX if it has not been <nl> / / / set yet . No member may be written to the object if expected number of <nl> / / / fields has not been set yet . <nl> class ByteTreeWriter { <nl> <nl> / / / The \ c ByteTreeWriter can only be constructed internally . Use <nl> / / / \ c ByteTreeWriter . write to serialize a new object . <nl> - ByteTreeWriter ( llvm : : BinaryStreamWriter & StreamWriter , UserInfoMap & UserInfo ) <nl> - : StreamWriter ( StreamWriter ) , UserInfo ( UserInfo ) { } <nl> + / / / \ p Stream must be the underlying stream of \ p SteamWriter . <nl> + ByteTreeWriter ( ExponentialGrowthAppendingBinaryByteStream & Stream , <nl> + llvm : : BinaryStreamWriter & StreamWriter , UserInfoMap & UserInfo ) <nl> + : StreamWriter ( StreamWriter ) , Stream ( Stream ) , UserInfo ( UserInfo ) { } <nl> + <nl> + / / / Write the given value to the ByteTree in the same form in which it is <nl> + / / / represented on the serializing machine . <nl> + template < typename T > <nl> + llvm : : Error writeRaw ( T Value ) { <nl> + / / FIXME : We implicitly inherit the endianess of the serializing machine . <nl> + / / Since we ' re currently only supporting macOS that ' s not a problem for now . <nl> + auto Error = Stream . writeRaw ( StreamWriter . getOffset ( ) , Value ) ; <nl> + StreamWriter . setOffset ( StreamWriter . getOffset ( ) + sizeof ( T ) ) ; <nl> + return Error ; <nl> + } <nl> <nl> / / / Set the expected number of fields the object written by this writer is <nl> / / / expected to have . <nl> class ByteTreeWriter { <nl> / / Set the most significant bit to indicate that the next construct is an <nl> / / object and not a scalar . <nl> uint32_t ToWrite = NumFields | ( 1 < < 31 ) ; <nl> - auto Error = StreamWriter . writeInteger ( ToWrite ) ; <nl> + auto Error = writeRaw ( ToWrite ) ; <nl> ( void ) Error ; <nl> assert ( ! Error ) ; <nl> <nl> class ByteTreeWriter { <nl> / / / the stream by the specified ProtocolVersion . <nl> template < typename T > <nl> typename std : : enable_if < has_ObjectTraits < T > : : value , void > : : type <nl> - static write ( uint32_t ProtocolVersion , llvm : : BinaryStreamWriter & StreamWriter , <nl> - const T & Object , UserInfoMap & UserInfo ) { <nl> - ByteTreeWriter Writer ( StreamWriter , UserInfo ) ; <nl> + static write ( ExponentialGrowthAppendingBinaryByteStream & Stream , <nl> + uint32_t ProtocolVersion , const T & Object , <nl> + UserInfoMap & UserInfo ) { <nl> + llvm : : BinaryStreamWriter StreamWriter ( Stream ) ; <nl> + ByteTreeWriter Writer ( Stream , StreamWriter , UserInfo ) ; <nl> <nl> - auto Error = Writer . StreamWriter . writeInteger ( ProtocolVersion ) ; <nl> + auto Error = Writer . writeRaw ( ProtocolVersion ) ; <nl> ( void ) Error ; <nl> assert ( ! Error ) ; <nl> <nl> class ByteTreeWriter { <nl> write ( const T & Object , unsigned Index ) { <nl> validateAndIncreaseFieldIndex ( Index ) ; <nl> <nl> - auto ObjectWriter = ByteTreeWriter ( StreamWriter , UserInfo ) ; <nl> + auto ObjectWriter = ByteTreeWriter ( Stream , StreamWriter , UserInfo ) ; <nl> ObjectWriter . setNumFields ( ObjectTraits < T > : : numFields ( Object , UserInfo ) ) ; <nl> <nl> ObjectTraits < T > : : write ( ObjectWriter , Object , UserInfo ) ; <nl> class ByteTreeWriter { <nl> / / bitflag that indicates if the next construct in the tree is an object <nl> / / or a scalar . <nl> assert ( ( ValueSize & ( ( uint32_t ) 1 < < 31 ) ) = = 0 & & " Value size too large " ) ; <nl> - auto SizeError = StreamWriter . writeInteger ( ValueSize ) ; <nl> + auto SizeError = writeRaw ( ValueSize ) ; <nl> ( void ) SizeError ; <nl> assert ( ! SizeError ) ; <nl> <nl> class ByteTreeWriter { <nl> " ScalarTraits < T > : : size " ) ; <nl> } <nl> <nl> + template < typename T > <nl> + typename std : : enable_if < DirectlyEncodable < T > : : value , void > : : type <nl> + write ( const T & Value , unsigned Index ) { <nl> + validateAndIncreaseFieldIndex ( Index ) ; <nl> + <nl> + uint32_t ValueSize = sizeof ( T ) ; <nl> + auto SizeError = writeRaw ( ValueSize ) ; <nl> + ( void ) SizeError ; <nl> + assert ( ! SizeError ) ; <nl> + <nl> + auto ContentError = writeRaw ( Value ) ; <nl> + ( void ) ContentError ; <nl> + assert ( ! ContentError ) ; <nl> + } <nl> + <nl> template < typename T > <nl> typename std : : enable_if < has_WrapperTypeTraits < T > : : value , void > : : type <nl> write ( const T & Value , unsigned Index ) { <nl> class ByteTreeWriter { <nl> / / Define serialization schemes for common types <nl> <nl> template < > <nl> - struct ScalarTraits < uint8_t > { <nl> - static unsigned size ( const uint8_t & Value ) { return 1 ; } <nl> - static llvm : : Error write ( llvm : : BinaryStreamWriter & Writer , <nl> - const uint8_t & Value ) { <nl> - return Writer . writeInteger ( Value ) ; <nl> - } <nl> + struct DirectlyEncodable < uint8_t > { <nl> + static bool const value = true ; <nl> } ; <nl> <nl> template < > <nl> - struct ScalarTraits < uint16_t > { <nl> - static unsigned size ( const uint16_t & Value ) { return 2 ; } <nl> - static llvm : : Error write ( llvm : : BinaryStreamWriter & Writer , <nl> - const uint16_t & Value ) { <nl> - return Writer . writeInteger ( Value ) ; <nl> - } <nl> + struct DirectlyEncodable < uint16_t > { <nl> + static bool const value = true ; <nl> } ; <nl> <nl> template < > <nl> - struct ScalarTraits < uint32_t > { <nl> - static unsigned size ( const uint32_t & Value ) { return 4 ; } <nl> - static llvm : : Error write ( llvm : : BinaryStreamWriter & Writer , <nl> - const uint32_t & Value ) { <nl> - return Writer . writeInteger ( Value ) ; <nl> - } <nl> + struct DirectlyEncodable < uint32_t > { <nl> + static bool const value = true ; <nl> } ; <nl> <nl> template < > <nl> mmm a / include / swift / Basic / ExponentialGrowthAppendingBinaryByteStream . h <nl> ppp b / include / swift / Basic / ExponentialGrowthAppendingBinaryByteStream . h <nl> class ExponentialGrowthAppendingBinaryByteStream <nl> <nl> llvm : : Error writeBytes ( uint32_t Offset , ArrayRef < uint8_t > Buffer ) override ; <nl> <nl> + / / / This is an optimized version of \ c writeBytes that assumes we know the <nl> + / / / size of \ p Value at compile time ( which in particular holds for integers ) . <nl> + / / / It does so by avoiding the memcopy that \ c writeBytes requires to copy <nl> + / / / the arbitrarily sized Buffer to the output buffer and using a direct <nl> + / / / memory assignment instead . <nl> + / / / This assumes that the enianess of this steam is the same as the native <nl> + / / / endianess on the executing machine . No endianess transformations are <nl> + / / / performed . <nl> + template < typename T > <nl> + llvm : : Error writeRaw ( uint32_t Offset , T Value ) { <nl> + if ( auto Error = checkOffsetForWrite ( Offset , sizeof ( T ) ) ) { <nl> + return Error ; <nl> + } <nl> + <nl> + / / Resize the internal buffer if needed . <nl> + uint32_t RequiredSize = Offset + sizeof ( T ) ; <nl> + if ( RequiredSize > Data . size ( ) ) { <nl> + Data . resize ( RequiredSize ) ; <nl> + } <nl> + <nl> + * ( T * ) ( Data . data ( ) + Offset ) = Value ; <nl> + <nl> + return llvm : : Error : : success ( ) ; <nl> + } <nl> + <nl> llvm : : Error commit ( ) override { return llvm : : Error : : success ( ) ; } <nl> <nl> virtual llvm : : BinaryStreamFlags getFlags ( ) const override { <nl> mmm a / tools / SourceKit / tools / sourcekitd / lib / API / Requests . cpp <nl> ppp b / tools / SourceKit / tools / sourcekitd / lib / API / Requests . cpp <nl> void serializeSyntaxTreeAsByteTree ( <nl> swift : : ExponentialGrowthAppendingBinaryByteStream Stream ( <nl> llvm : : support : : endianness : : little ) ; <nl> Stream . reserve ( 32 * 1024 ) ; <nl> - llvm : : BinaryStreamWriter Writer ( Stream ) ; <nl> std : : map < void * , void * > UserInfo ; <nl> UserInfo [ swift : : byteTree : : UserInfoKeyReusedNodeIds ] = & ReusedNodeIds ; <nl> - swift : : byteTree : : ByteTreeWriter : : write ( / * ProtocolVersion = * / 1 , Writer , <nl> + swift : : byteTree : : ByteTreeWriter : : write ( Stream , / * ProtocolVersion = * / 1 , <nl> * SyntaxTree . getRaw ( ) , UserInfo ) ; <nl> <nl> std : : unique_ptr < llvm : : WritableMemoryBuffer > Buf = <nl> mmm a / tools / swift - syntax - test / swift - syntax - test . cpp <nl> ppp b / tools / swift - syntax - test / swift - syntax - test . cpp <nl> int doSerializeRawTree ( const char * MainExecutablePath , <nl> return EXIT_FAILURE ; <nl> } <nl> <nl> - llvm : : AppendingBinaryByteStream Stream ( llvm : : support : : endianness : : little ) ; <nl> - llvm : : BinaryStreamWriter Writer ( Stream ) ; <nl> + swift : : ExponentialGrowthAppendingBinaryByteStream Stream ( <nl> + llvm : : support : : endianness : : little ) ; <nl> + Stream . reserve ( 32 * 1024 ) ; <nl> std : : map < void * , void * > UserInfo ; <nl> UserInfo [ swift : : byteTree : : UserInfoKeyReusedNodeIds ] = & ReusedNodeIds ; <nl> if ( options : : AddByteTreeFields ) { <nl> UserInfo [ swift : : byteTree : : UserInfoKeyAddInvalidFields ] = ( void * ) true ; <nl> } <nl> - swift : : byteTree : : ByteTreeWriter : : write ( / * ProtocolVersion = * / 1 , Writer , <nl> + swift : : byteTree : : ByteTreeWriter : : write ( Stream , / * ProtocolVersion = * / 1 , <nl> * Root , UserInfo ) ; <nl> auto OutputBufferOrError = llvm : : FileOutputBuffer : : create ( <nl> options : : OutputFilename , Stream . data ( ) . size ( ) ) ; <nl> mmm a / unittests / Basic / ExponentialGrowthAppendingBinaryByteStreamTests . cpp <nl> ppp b / unittests / Basic / ExponentialGrowthAppendingBinaryByteStreamTests . cpp <nl> TEST_F ( ExponentialGrowthAppendingBinaryByteStreamTest , GrowMultipleSteps ) { <nl> } <nl> <nl> TEST_F ( ExponentialGrowthAppendingBinaryByteStreamTest , WriteIntoMiddle ) { <nl> - / / Test that the stream resizes correctly if we write into its middle <nl> - <nl> ExponentialGrowthAppendingBinaryByteStream Stream ( llvm : : support : : little ) ; <nl> <nl> - / / Test that the buffer can grow multiple steps at once , e . g . 1 - > 2 - > 4 <nl> + / / Test that the stream resizes correctly if we write into its middle <nl> std : : vector < uint8_t > InitialData = { ' T ' , ' e ' , ' s ' , ' t ' } ; <nl> auto InitialDataRef = makeArrayRef ( InitialData ) ; <nl> EXPECT_THAT_ERROR ( Stream . writeBytes ( 0 , InitialDataRef ) , Succeeded ( ) ) ; <nl> TEST_F ( ExponentialGrowthAppendingBinaryByteStreamTest , WriteIntoMiddle ) { <nl> EXPECT_EQ ( DataAfterInsertRef , Stream . data ( ) ) ; <nl> EXPECT_EQ ( 6u , Stream . getLength ( ) ) ; <nl> } <nl> + <nl> + TEST_F ( ExponentialGrowthAppendingBinaryByteStreamTest , WriteRaw ) { <nl> + ExponentialGrowthAppendingBinaryByteStream Stream ( llvm : : support : : little ) ; <nl> + <nl> + / / Test the writeRaw method <nl> + std : : vector < uint8_t > InitialData = { ' H ' , ' e ' , ' l ' , ' l ' , ' o ' } ; <nl> + auto InitialDataRef = makeArrayRef ( InitialData ) ; <nl> + EXPECT_THAT_ERROR ( Stream . writeBytes ( 0 , InitialDataRef ) , Succeeded ( ) ) ; <nl> + EXPECT_EQ ( InitialDataRef , Stream . data ( ) ) ; <nl> + <nl> + EXPECT_THAT_ERROR ( Stream . writeRaw ( 5 , ( uint8_t ) ' ' ) , Succeeded ( ) ) ; <nl> + std : : vector < uint8_t > AfterFirstInsert = { ' H ' , ' e ' , ' l ' , ' l ' , ' o ' , ' ' } ; <nl> + auto AfterFirstInsertRef = makeArrayRef ( AfterFirstInsert ) ; <nl> + EXPECT_EQ ( AfterFirstInsertRef , Stream . data ( ) ) ; <nl> + EXPECT_EQ ( 6u , Stream . getLength ( ) ) ; <nl> + <nl> + uint32_t ToInsert = ' w ' | <nl> + ' o ' < < 8 | <nl> + ' r ' < < 16 | <nl> + ' l ' < < 24 ; <nl> + EXPECT_THAT_ERROR ( Stream . writeRaw ( 6 , ToInsert ) , Succeeded ( ) ) ; <nl> + std : : vector < uint8_t > AfterSecondInsert = { ' H ' , ' e ' , ' l ' , ' l ' , ' o ' , ' ' , <nl> + ' w ' , ' o ' , ' r ' , ' l ' } ; <nl> + auto AfterSecondInsertRef = makeArrayRef ( AfterSecondInsert ) ; <nl> + EXPECT_EQ ( AfterSecondInsertRef , Stream . data ( ) ) ; <nl> + EXPECT_EQ ( 10u , Stream . getLength ( ) ) ; <nl> + } <nl>
Merge remote - tracking branch ' origin / master ' into master - next
apple/swift
d2ba4d3c06ad11bc95e5fa50bd414be619c08e5b
2018-08-27T22:39:51Z
mmm a / dbms / src / Functions / FunctionsLLVMTest . cpp <nl> ppp b / dbms / src / Functions / FunctionsLLVMTest . cpp <nl> <nl> - # include < Columns / ColumnVector . h > <nl> # include < DataTypes / DataTypesNumber . h > <nl> # include < Functions / FunctionFactory . h > <nl> # include < Functions / IFunction . h > <nl> class FunctionSomething : public IFunction <nl> return static_cast < llvm : : IRBuilder < > & > ( builder ) . CreateFAdd ( values [ 0 ] , values [ 1 ] ) ; <nl> return static_cast < llvm : : IRBuilder < > & > ( builder ) . CreateAdd ( values [ 0 ] , values [ 1 ] ) ; <nl> } <nl> - <nl> - IColumn : : Ptr createResultColumn ( const DataTypes & types , size_t size ) const <nl> - { <nl> - if ( types [ 0 ] - > equals ( DataTypeInt8 { } ) ) <nl> - return ColumnVector < Int8 > : : create ( size ) ; <nl> - if ( types [ 0 ] - > equals ( DataTypeInt16 { } ) ) <nl> - return ColumnVector < Int16 > : : create ( size ) ; <nl> - if ( types [ 0 ] - > equals ( DataTypeInt32 { } ) ) <nl> - return ColumnVector < Int32 > : : create ( size ) ; <nl> - if ( types [ 0 ] - > equals ( DataTypeInt64 { } ) ) <nl> - return ColumnVector < Int64 > : : create ( size ) ; <nl> - if ( types [ 0 ] - > equals ( DataTypeUInt8 { } ) ) <nl> - return ColumnVector < UInt8 > : : create ( size ) ; <nl> - if ( types [ 0 ] - > equals ( DataTypeUInt16 { } ) ) <nl> - return ColumnVector < UInt16 > : : create ( size ) ; <nl> - if ( types [ 0 ] - > equals ( DataTypeUInt32 { } ) ) <nl> - return ColumnVector < UInt32 > : : create ( size ) ; <nl> - if ( types [ 0 ] - > equals ( DataTypeUInt64 { } ) ) <nl> - return ColumnVector < UInt64 > : : create ( size ) ; <nl> - if ( types [ 0 ] - > equals ( DataTypeFloat32 { } ) ) <nl> - return ColumnVector < Float32 > : : create ( size ) ; <nl> - if ( types [ 0 ] - > equals ( DataTypeFloat64 { } ) ) <nl> - return ColumnVector < Float64 > : : create ( size ) ; <nl> - throw Exception ( " invalid input type " , ErrorCodes : : LOGICAL_ERROR ) ; <nl> - } <nl> / / # endif <nl> <nl> static FunctionPtr create ( const Context & ) { return std : : make_shared < FunctionSomething > ( ) ; } <nl> mmm a / dbms / src / Functions / IFunction . h <nl> ppp b / dbms / src / Functions / IFunction . h <nl> <nl> <nl> # include < memory > <nl> <nl> - # include < Columns / IColumn . h > <nl> # include < Core / Names . h > <nl> # include < Core / Field . h > <nl> # include < Core / Block . h > <nl> class IFunctionBase <nl> virtual const DataTypes & getArgumentTypes ( ) const = 0 ; <nl> virtual const DataTypePtr & getReturnType ( ) const = 0 ; <nl> <nl> - / / / Create an empty result column of a given size . Only called on JIT - compilable functions . <nl> - virtual IColumn : : Ptr createResultColumn ( size_t / * size * / ) const <nl> - { <nl> - throw Exception ( getName ( ) + " is not JIT - compilable " , ErrorCodes : : NOT_IMPLEMENTED ) ; <nl> - } <nl> - <nl> / / / Do preparations and return executable . <nl> / / / sample_block should contain data types of arguments and values of constants , if relevant . <nl> virtual PreparedFunctionPtr prepare ( const Block & sample_block ) const = 0 ; <nl> class IFunction : public std : : enable_shared_from_this < IFunction > , <nl> throw Exception ( " getReturnType is not implemented for IFunction " , ErrorCodes : : NOT_IMPLEMENTED ) ; <nl> } <nl> <nl> - virtual IColumn : : Ptr createResultColumn ( const DataTypes & / * arguments * / , size_t / * size * / ) const <nl> - { <nl> - throw Exception ( getName ( ) + " is not JIT - compilable " , ErrorCodes : : NOT_IMPLEMENTED ) ; <nl> - } <nl> - <nl> protected : <nl> FunctionBasePtr buildImpl ( const ColumnsWithTypeAndName & / * arguments * / , const DataTypePtr & / * return_type * / ) const final <nl> { <nl> class DefaultFunction final : public IFunctionBase <nl> const DataTypes & getArgumentTypes ( ) const override { return arguments ; } <nl> const DataTypePtr & getReturnType ( ) const override { return return_type ; } <nl> <nl> - IColumn : : Ptr createResultColumn ( size_t size ) const override { return function - > createResultColumn ( arguments , size ) ; } <nl> - <nl> bool isCompilable ( ) const override { return function - > isCompilable ( arguments ) ; } <nl> <nl> llvm : : Value * compile ( llvm : : IRBuilderBase & builder , const ValuePlaceholders & values ) const override { return function - > compile ( builder , arguments , values ) ; } <nl> mmm a / dbms / src / Interpreters / ExpressionJIT . cpp <nl> ppp b / dbms / src / Interpreters / ExpressionJIT . cpp <nl> <nl> - # include < DataTypes / DataTypesNumber . h > <nl> # include < Interpreters / ExpressionJIT . h > <nl> <nl> # include < llvm / IR / BasicBlock . h > <nl> mmm a / dbms / src / Interpreters / ExpressionJIT . h <nl> ppp b / dbms / src / Interpreters / ExpressionJIT . h <nl> <nl> # pragma once <nl> <nl> + # include < Columns / ColumnVector . h > <nl> + # include < DataTypes / DataTypesNumber . h > <nl> # include < Functions / IFunction . h > <nl> <nl> # include < Interpreters / ExpressionActions . h > <nl> <nl> namespace DB <nl> { <nl> <nl> + namespace ErrorCodes <nl> + { <nl> + extern const int LOGICAL_ERROR ; <nl> + } <nl> + <nl> class LLVMContext <nl> { <nl> struct Data ; <nl> class LLVMPreparedFunction : public PreparedFunctionImpl <nl> is_const [ i ] = column - > isColumnConst ( ) ; <nl> block_size = column - > size ( ) ; <nl> } <nl> - auto col_res = parent - > createResultColumn ( block_size ) ; <nl> - if ( ! col_res - > isColumnConst ( ) & & ! col_res - > isDummy ( ) & & block_size ) <nl> + auto col_res = createColumn ( parent - > getReturnType ( ) , block_size ) ; <nl> + if ( block_size ) <nl> function ( columns . data ( ) , is_const . data ( ) , const_cast < char * > ( col_res - > getDataAt ( 0 ) . data ) , block_size ) ; <nl> block . getByPosition ( result ) . column = std : : move ( col_res ) ; <nl> } ; <nl> + <nl> + private : <nl> + static IColumn : : Ptr createColumn ( const DataTypePtr & type , size_t size ) <nl> + { <nl> + if ( type - > equals ( DataTypeInt8 { } ) ) <nl> + return ColumnVector < Int8 > : : create ( size ) ; <nl> + if ( type - > equals ( DataTypeInt16 { } ) ) <nl> + return ColumnVector < Int16 > : : create ( size ) ; <nl> + if ( type - > equals ( DataTypeInt32 { } ) ) <nl> + return ColumnVector < Int32 > : : create ( size ) ; <nl> + if ( type - > equals ( DataTypeInt64 { } ) ) <nl> + return ColumnVector < Int64 > : : create ( size ) ; <nl> + if ( type - > equals ( DataTypeUInt8 { } ) ) <nl> + return ColumnVector < UInt8 > : : create ( size ) ; <nl> + if ( type - > equals ( DataTypeUInt16 { } ) ) <nl> + return ColumnVector < UInt16 > : : create ( size ) ; <nl> + if ( type - > equals ( DataTypeUInt32 { } ) ) <nl> + return ColumnVector < UInt32 > : : create ( size ) ; <nl> + if ( type - > equals ( DataTypeUInt64 { } ) ) <nl> + return ColumnVector < UInt64 > : : create ( size ) ; <nl> + if ( type - > equals ( DataTypeFloat32 { } ) ) <nl> + return ColumnVector < Float32 > : : create ( size ) ; <nl> + if ( type - > equals ( DataTypeFloat64 { } ) ) <nl> + return ColumnVector < Float64 > : : create ( size ) ; <nl> + throw Exception ( " LLVMPreparedFunction : : createColumn received an unsupported data type ; check " <nl> + " that the list is consistent with LLVMContext : : Data : : toNativeType " , ErrorCodes : : LOGICAL_ERROR ) ; <nl> + } <nl> } ; <nl> <nl> class LLVMFunction : public std : : enable_shared_from_this < LLVMFunction > , public IFunctionBase <nl> class LLVMFunction : public std : : enable_shared_from_this < LLVMFunction > , public I <nl> <nl> PreparedFunctionPtr prepare ( const Block & ) const override { return std : : make_shared < LLVMPreparedFunction > ( context , shared_from_this ( ) ) ; } <nl> <nl> - IColumn : : Ptr createResultColumn ( size_t size ) const override { return actions . back ( ) . function - > createResultColumn ( size ) ; } <nl> - <nl> bool isDeterministic ( ) override <nl> { <nl> for ( const auto & action : actions ) <nl>
Remove IFunction : : createResultColumn .
ClickHouse/ClickHouse
3810173103e87b173ec993ce9e3d62445952eb69
2018-04-25T10:37:26Z
mmm a / gRPC - Core . podspec <nl> ppp b / gRPC - Core . podspec <nl> <nl> # GRPC CocoaPods podspec <nl> - # This file has been automatically generated from a template file . <nl> - # Please look at the templates directory instead . <nl> - # This file can be regenerated from the template by running <nl> - # tools / buildgen / generate_projects . sh <nl> + # This file has been automatically generated from a template file . Please make modifications to <nl> + # ` templates / gRPC - Core . podspec . template ` instead . This file can be regenerated from the template by <nl> + # running ` tools / buildgen / generate_projects . sh ` . <nl> <nl> # Copyright 2015 , Google Inc . <nl> # All rights reserved . <nl> Pod : : Spec . new do | s | <nl> # A module map is necessary for a dynamic framework to be correctly created by Cocoapods . <nl> s . module_map = ' include / grpc / module . modulemap ' <nl> <nl> - # List of source files generated by a template . To save you from scrolling , this is the last part <nl> - # of the podspec . <nl> + # List of source files generated by a template : ` templates / gRPC - Core . podspec . template ` . It can be <nl> + # regenerated from the template by running ` tools / buildgen / generate_projects . sh ` . <nl> + # To save you from scrolling , this is the last part of the podspec . <nl> s . source_files = ' src / core / lib / profiling / timers . h ' , <nl> ' src / core / lib / support / backoff . h ' , <nl> ' src / core / lib / support / block_annotate . h ' , <nl> mmm a / templates / gRPC - Core . podspec . template <nl> ppp b / templates / gRPC - Core . podspec . template <nl> <nl> % YAML 1 . 2 <nl> mmm | <nl> # GRPC CocoaPods podspec <nl> - # This file has been automatically generated from a template file . <nl> - # Please look at the templates directory instead . <nl> - # This file can be regenerated from the template by running <nl> - # tools / buildgen / generate_projects . sh <nl> + # This file has been automatically generated from a template file . Please make modifications to <nl> + # ` templates / gRPC - Core . podspec . template ` instead . This file can be regenerated from the template by <nl> + # running ` tools / buildgen / generate_projects . sh ` . <nl> <nl> # Copyright 2015 , Google Inc . <nl> # All rights reserved . <nl> <nl> # A module map is necessary for a dynamic framework to be correctly created by Cocoapods . <nl> s . module_map = ' include / grpc / module . modulemap ' <nl> <nl> - # List of source files generated by a template . To save you from scrolling , this is the last part <nl> - # of the podspec . <nl> + # List of source files generated by a template : ` templates / gRPC - Core . podspec . template ` . It can be <nl> + # regenerated from the template by running ` tools / buildgen / generate_projects . sh ` . <nl> + # To save you from scrolling , this is the last part of the podspec . <nl> s . source_files = $ { ( ' , \ n ' + 19 * ' ' ) . join ( ' \ ' % s \ ' ' % f for f in grpc_files ( libs ) ) } <nl> <nl> s . private_header_files = $ { ( ' , \ n ' + 27 * ' ' ) . join ( ' \ ' % s \ ' ' % f for f in grpc_private_headers ( libs ) ) } <nl>
gRPC - Core . podspec : Clarify where the template is
grpc/grpc
667557f22b1cc601c60d3227f209b8cf848738b5
2016-06-09T16:15:28Z
mmm a / Documentation / Books / Manual / Administration / Configuration / Cluster . md <nl> ppp b / Documentation / Books / Manual / Administration / Configuration / Cluster . md <nl> This server ' s role : <nl> The server ' s role . Is this instance a db server ( backend data server ) <nl> or a coordinator ( frontend server for external and application access ) <nl> <nl> + Require existing ID <nl> + mmmmmmmmmmmmmmmmmm - <nl> + <nl> + Require an existing server id : ` - - cluster . require - persisted - id bool ` <nl> + <nl> + If set to true , then the instance will only start if a UUID file is found <nl> + in the database on startup . Setting this option will make sure the instance <nl> + is started using an already existing database directory from a previous <nl> + start , and not a new one . For the first start , the UUID file must either be <nl> + created manually in the database directory , or the option must be set to <nl> + false for the initial startup and only turned on for restarts . <nl> + <nl> More advanced options <nl> mmmmmmmmmmmmmmmmmmmmm <nl> <nl> These options should generally remain untouched . <nl> < ! - - arangod / Cluster / ClusterFeature . h - - > <nl> <nl> <nl> - Synchroneous replication timing : ` - - cluster . synchronous - replication - timeout - factor double ` <nl> + Synchronous replication timing : ` - - cluster . synchronous - replication - timeout - factor double ` <nl> <nl> Strech or clinch timeouts for internal synchroneous replication <nl> mechanism between db servers . All such timeouts are affected by this <nl> mmm a / arangod / Cluster / ClusterFeature . cpp <nl> ppp b / arangod / Cluster / ClusterFeature . cpp <nl> ClusterFeature : : ClusterFeature ( application_features : : ApplicationServer * server ) <nl> : ApplicationFeature ( server , " Cluster " ) , <nl> _unregisterOnShutdown ( false ) , <nl> _enableCluster ( false ) , <nl> + _requirePersistedId ( false ) , <nl> _heartbeatThread ( nullptr ) , <nl> _heartbeatInterval ( 0 ) , <nl> _disableHeartbeat ( false ) , <nl> void ClusterFeature : : collectOptions ( std : : shared_ptr < ProgramOptions > options ) { <nl> options - > addObsoleteOption ( " - - cluster . arangod - path " , <nl> " path to the arangod for the cluster " , <nl> true ) ; <nl> + <nl> + options - > addOption ( " - - cluster . require - persisted - id " , <nl> + " if set to true , then the instance will only start if a UUID file is found in the database on startup . Setting this option will make sure the instance is started using an already existing database directory and not a new one . For the first start , the UUID file must either be created manually or the option must be set to false for the initial startup " , <nl> + new BooleanParameter ( & _requirePersistedId ) ) ; <nl> <nl> options - > addOption ( " - - cluster . agency - endpoint " , <nl> " agency endpoint to connect to " , <nl> void ClusterFeature : : reportRole ( arangodb : : ServerState : : RoleEnum role ) { <nl> <nl> void ClusterFeature : : prepare ( ) { <nl> auto v8Dealer = ApplicationServer : : getFeature < V8DealerFeature > ( " V8Dealer " ) ; <nl> + <nl> + if ( _enableCluster & & <nl> + _requirePersistedId & & <nl> + ! ServerState : : instance ( ) - > hasPersistedId ( ) ) { <nl> + LOG_TOPIC ( FATAL , arangodb : : Logger : : CLUSTER ) < < " required persisted UUID file ' " < < ServerState : : instance ( ) - > getUuidFilename ( ) < < " ' not found . Please make sure this instance is started using an already existing database directory " ; <nl> + FATAL_ERROR_EXIT ( ) ; <nl> + } <nl> <nl> v8Dealer - > defineDouble ( " SYS_DEFAULT_REPLICATION_FACTOR_SYSTEM " , <nl> _systemReplicationFactor ) ; <nl> mmm a / arangod / Cluster / ClusterFeature . h <nl> ppp b / arangod / Cluster / ClusterFeature . h <nl> class ClusterFeature : public application_features : : ApplicationFeature { <nl> private : <nl> bool _unregisterOnShutdown ; <nl> bool _enableCluster ; <nl> + bool _requirePersistedId ; <nl> std : : shared_ptr < HeartbeatThread > _heartbeatThread ; <nl> uint64_t _heartbeatInterval ; <nl> bool _disableHeartbeat ; <nl> mmm a / arangod / Cluster / ServerState . cpp <nl> ppp b / arangod / Cluster / ServerState . cpp <nl> std : : string ServerState : : getUuidFilename ( ) { <nl> application_features : : ApplicationServer : : getFeature < DatabasePathFeature > ( <nl> " DatabasePath " ) ; <nl> TRI_ASSERT ( dbpath ! = nullptr ) ; <nl> - mkdir ( dbpath - > directory ( ) ) ; <nl> - <nl> - return dbpath - > directory ( ) + " / UUID " ; <nl> + return FileUtils : : buildFilename ( dbpath - > directory ( ) , " UUID " ) ; <nl> } <nl> <nl> bool ServerState : : hasPersistedId ( ) { <nl> bool ServerState : : hasPersistedId ( ) { <nl> <nl> bool ServerState : : writePersistedId ( std : : string const & id ) { <nl> std : : string uuidFilename = getUuidFilename ( ) ; <nl> + mkdir ( FileUtils : : dirname ( uuidFilename ) ) ; <nl> std : : ofstream ofs ( uuidFilename ) ; <nl> if ( ! ofs . is_open ( ) ) { <nl> LOG_TOPIC ( FATAL , Logger : : CLUSTER ) <nl> std : : string ServerState : : generatePersistedId ( RoleEnum const & role ) { <nl> } <nl> <nl> std : : string ServerState : : getPersistedId ( ) { <nl> - std : : string uuidFilename = getUuidFilename ( ) ; <nl> - std : : ifstream ifs ( uuidFilename ) ; <nl> - <nl> - std : : string id ; <nl> - if ( ifs . is_open ( ) ) { <nl> - std : : getline ( ifs , id ) ; <nl> - ifs . close ( ) ; <nl> - } else { <nl> - LOG_TOPIC ( FATAL , Logger : : STARTUP ) < < " Couldn ' t open " < < uuidFilename ; <nl> - FATAL_ERROR_EXIT ( ) ; <nl> + if ( hasPersistedId ( ) ) { <nl> + std : : string uuidFilename = getUuidFilename ( ) ; <nl> + std : : ifstream ifs ( uuidFilename ) ; <nl> + <nl> + std : : string id ; <nl> + if ( ifs . is_open ( ) ) { <nl> + std : : getline ( ifs , id ) ; <nl> + ifs . close ( ) ; <nl> + return id ; <nl> + } <nl> } <nl> - return id ; <nl> + <nl> + LOG_TOPIC ( FATAL , Logger : : STARTUP ) < < " Couldn ' t open UUID file ' " < < getUuidFilename ( ) < < " ' " ; <nl> + FATAL_ERROR_EXIT ( ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> mmm a / arangod / Cluster / ServerState . h <nl> ppp b / arangod / Cluster / ServerState . h <nl> class ServerState { <nl> <nl> / / / @ brief sets server mode and propagates new mode to agency <nl> Result propagateClusterServerMode ( Mode ) ; <nl> + <nl> + std : : string getUuidFilename ( ) ; <nl> <nl> - private : <nl> + private : <nl> / / / @ brief atomically fetches the server role <nl> RoleEnum loadRole ( ) { <nl> return static_cast < RoleEnum > ( _role . load ( std : : memory_order_consume ) ) ; <nl> class ServerState { <nl> / / / @ brief register shortname for an id <nl> bool registerShortName ( std : : string const & id , const RoleEnum & ) ; <nl> <nl> - / / / <nl> - std : : string getUuidFilename ( ) ; <nl> - <nl> / / / @ brief the pointer to the singleton instance <nl> static ServerState * _theinstance ; <nl> <nl>
added option ` - - cluster . require - persisted - id ` ( )
arangodb/arangodb
76dcd6ded544452df2922d0457610530793bdfb9
2018-04-13T09:08:49Z
mmm a / dbms / src / Common / HashTable / FixedClearableHashMap . h <nl> ppp b / dbms / src / Common / HashTable / FixedClearableHashMap . h <nl> struct FixedClearableHashMapCell <nl> } <nl> Key key ; <nl> FixedClearableHashMapCell * ptr ; <nl> - Key & getFirstMutable ( ) { return key ; } <nl> const Key & getFirst ( ) const { return key ; } <nl> Mapped & getSecond ( ) { return ptr - > mapped ; } <nl> const Mapped & getSecond ( ) const { return * ptr - > mapped ; } <nl> mmm a / dbms / src / Common / HashTable / FixedClearableHashSet . h <nl> ppp b / dbms / src / Common / HashTable / FixedClearableHashSet . h <nl> struct FixedClearableHashTableCell <nl> struct CellExt <nl> { <nl> Key key ; <nl> - value_type & getValueMutable ( ) { return key ; } <nl> const value_type & getValue ( ) const { return key ; } <nl> void update ( Key & & key_ , FixedClearableHashTableCell * ) { key = key_ ; } <nl> } ; <nl> mmm a / dbms / src / Common / HashTable / FixedHashMap . h <nl> ppp b / dbms / src / Common / HashTable / FixedHashMap . h <nl> struct FixedHashMapCell <nl> Key key ; <nl> FixedHashMapCell * ptr ; <nl> <nl> - Key & getFirstMutable ( ) { return key ; } <nl> const Key & getFirst ( ) const { return key ; } <nl> Mapped & getSecond ( ) { return ptr - > mapped ; } <nl> const Mapped & getSecond ( ) const { return ptr - > mapped ; } <nl> mmm a / dbms / src / Common / HashTable / FixedHashTable . h <nl> ppp b / dbms / src / Common / HashTable / FixedHashTable . h <nl> struct FixedHashTableCell <nl> { <nl> Key key ; <nl> <nl> - value_type & getValueMutable ( ) { return key ; } <nl> const value_type & getValue ( ) const { return key ; } <nl> void update ( Key & & key_ , FixedHashTableCell * ) { key = key_ ; } <nl> } ; <nl> mmm a / dbms / src / Common / HashTable / HashMap . h <nl> ppp b / dbms / src / Common / HashTable / HashMap . h <nl> struct HashMapCell <nl> HashMapCell ( const Key & key_ , const State & ) : value ( key_ , NoInitTag ( ) ) { } <nl> HashMapCell ( const value_type & value_ , const State & ) : value ( value_ ) { } <nl> <nl> - Key & getFirstMutable ( ) { return value . first ; } <nl> const Key & getFirst ( ) const { return value . first ; } <nl> Mapped & getSecond ( ) { return value . second ; } <nl> const Mapped & getSecond ( ) const { return value . second ; } <nl> <nl> - value_type & getValueMutable ( ) { return value ; } <nl> const value_type & getValue ( ) const { return value ; } <nl> <nl> static const Key & getKey ( const value_type & value ) { return value . first ; } <nl> mmm a / dbms / src / Common / HashTable / HashTable . h <nl> ppp b / dbms / src / Common / HashTable / HashTable . h <nl> struct HashTableCell <nl> HashTableCell ( const Key & key_ , const State & ) : key ( key_ ) { } <nl> <nl> / / / Get what the value_type of the container will be . <nl> - value_type & getValueMutable ( ) { return key ; } <nl> const value_type & getValue ( ) const { return key ; } <nl> <nl> / / / Get the key . <nl>
Do not provide mutable key access in hash map cells .
ClickHouse/ClickHouse
8e9a8584e088752ede4c962702d5bdb15d6811ac
2019-09-10T17:12:30Z
mmm a / doc / statuscodes . md <nl> ppp b / doc / statuscodes . md <nl> statuses are defined as such : <nl> | OUT_OF_RANGE | 11 | The operation was attempted past the valid range . E . g . , seeking or reading past end - of - file . Unlike ` INVALID_ARGUMENT ` , this error indicates a problem that may be fixed if the system state changes . For example , a 32 - bit file system will generate ` INVALID_ARGUMENT ` if asked to read at an offset that is not in the range [ 0 , 2 ^ 32 - 1 ] , but it will generate ` OUT_OF_RANGE ` if asked to read from an offset past the current file size . There is a fair bit of overlap between ` FAILED_PRECONDITION ` and ` OUT_OF_RANGE ` . We recommend using ` OUT_OF_RANGE ` ( the more specific error ) when it applies so that callers who are iterating through a space can easily look for an ` OUT_OF_RANGE ` error to detect when they are done . | 400 Bad Request | <nl> | UNIMPLEMENTED | 12 | The operation is not implemented or is not supported / enabled in this service . | 501 Not Implemented | <nl> | INTERNAL | 13 | Internal errors . This means that some invariants expected by the underlying system have been broken . This error code is reserved for serious errors . | 500 Internal Server Error | <nl> - | UNAVAILABLE | 14 | The service is currently unavailable . This is most likely a transient condition , which can be corrected by retrying with a backoff . | 503 Service Unavailable | <nl> + | UNAVAILABLE | 14 | The service is currently unavailable . This is most likely a transient condition , which can be corrected by retrying with a backoff . Note that it is not always safe to retry non - idempotent operations . | 503 Service Unavailable | <nl> | DATA_LOSS | 15 | Unrecoverable data loss or corruption . | 500 Internal Server Error | <nl> <nl> All RPCs started at a client return a ` status ` object composed of an integer <nl> mmm a / include / grpc / impl / codegen / port_platform . h <nl> ppp b / include / grpc / impl / codegen / port_platform . h <nl> <nl> # define GPR_WINDOWS 1 <nl> # define GPR_WINDOWS_SUBPROCESS 1 <nl> # define GPR_WINDOWS_ENV <nl> - # define GPR_HAS_ALIGNED_MALLOC 1 <nl> # ifdef __MSYS__ <nl> # define GPR_GETPID_IN_UNISTD_H 1 <nl> # define GPR_MSYS_TMPFILE <nl> <nl> # define GPR_POSIX_SYNC 1 <nl> # define GPR_POSIX_TIME 1 <nl> # define GPR_HAS_PTHREAD_H 1 <nl> - # define GPR_HAS_ALIGNED_ALLOC 1 <nl> # define GPR_GETPID_IN_UNISTD_H 1 <nl> # ifdef _LP64 <nl> # define GPR_ARCH_64 1 <nl> <nl> # define GPR_POSIX_SUBPROCESS 1 <nl> # define GPR_POSIX_SYNC 1 <nl> # define GPR_POSIX_TIME 1 <nl> - # define GPR_HAS_POSIX_MEMALIGN 1 <nl> # define GPR_HAS_PTHREAD_H 1 <nl> # define GPR_GETPID_IN_UNISTD_H 1 <nl> # ifndef GRPC_CFSTREAM <nl> mmm a / include / grpc / impl / codegen / status . h <nl> ppp b / include / grpc / impl / codegen / status . h <nl> typedef enum { <nl> <nl> / * * The service is currently unavailable . This is a most likely a <nl> transient condition and may be corrected by retrying with <nl> - a backoff . <nl> + a backoff . Note that it is not always safe to retry non - idempotent <nl> + operations . <nl> <nl> WARNING : Although data MIGHT not have been transmitted when this <nl> status occurs , there is NOT A GUARANTEE that the server has not seen <nl> mmm a / include / grpc / support / alloc . h <nl> ppp b / include / grpc / support / alloc . h <nl> typedef struct gpr_allocation_functions { <nl> void * ( * zalloc_fn ) ( size_t size ) ; / * * if NULL , uses malloc_fn then memset * / <nl> void * ( * realloc_fn ) ( void * ptr , size_t size ) ; <nl> void ( * free_fn ) ( void * ptr ) ; <nl> - void * ( * aligned_alloc_fn ) ( size_t size , size_t alignment ) ; <nl> - void ( * aligned_free_fn ) ( void * ptr ) ; <nl> } gpr_allocation_functions ; <nl> <nl> / * * malloc . <nl> mmm a / include / grpcpp / impl / codegen / status_code_enum . h <nl> ppp b / include / grpcpp / impl / codegen / status_code_enum . h <nl> enum StatusCode { <nl> INTERNAL = 13 , <nl> <nl> / / / The service is currently unavailable . This is a most likely a transient <nl> - / / / condition and may be corrected by retrying with a backoff . <nl> + / / / condition and may be corrected by retrying with a backoff . Note that it is <nl> + / / / not always safe to retry non - idempotent operations . <nl> / / / <nl> / / / \ warning Although data MIGHT not have been transmitted when this <nl> / / / status occurs , there is NOT A GUARANTEE that the server has not seen <nl> mmm a / src / core / ext / filters / client_channel / subchannel . cc <nl> ppp b / src / core / ext / filters / client_channel / subchannel . cc <nl> <nl> # define GRPC_SUBCHANNEL_RECONNECT_JITTER 0 . 2 <nl> <nl> / / Conversion between subchannel call and call stack . <nl> - # define SUBCHANNEL_CALL_TO_CALL_STACK ( call ) \ <nl> - ( grpc_call_stack * ) ( ( char * ) ( call ) + GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( \ <nl> - sizeof ( SubchannelCall ) ) ) <nl> - # define CALL_STACK_TO_SUBCHANNEL_CALL ( callstack ) \ <nl> - ( SubchannelCall * ) ( ( ( char * ) ( call_stack ) ) - \ <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( \ <nl> - sizeof ( SubchannelCall ) ) ) <nl> + # define SUBCHANNEL_CALL_TO_CALL_STACK ( call ) \ <nl> + ( grpc_call_stack * ) ( ( char * ) ( call ) + \ <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( SubchannelCall ) ) ) <nl> + # define CALL_STACK_TO_SUBCHANNEL_CALL ( callstack ) \ <nl> + ( SubchannelCall * ) ( ( ( char * ) ( call_stack ) ) - \ <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( SubchannelCall ) ) ) <nl> <nl> namespace grpc_core { <nl> <nl> RefCountedPtr < SubchannelCall > ConnectedSubchannel : : CreateCall ( <nl> size_t ConnectedSubchannel : : GetInitialCallSizeEstimate ( <nl> size_t parent_data_size ) const { <nl> size_t allocation_size = <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( SubchannelCall ) ) ; <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( SubchannelCall ) ) ; <nl> if ( parent_data_size > 0 ) { <nl> allocation_size + = <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( channel_stack_ - > call_stack_size ) + <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( channel_stack_ - > call_stack_size ) + <nl> parent_data_size ; <nl> } else { <nl> allocation_size + = channel_stack_ - > call_stack_size ; <nl> void SubchannelCall : : StartTransportStreamOpBatch ( <nl> <nl> void * SubchannelCall : : GetParentData ( ) { <nl> grpc_channel_stack * chanstk = connected_subchannel_ - > channel_stack ( ) ; <nl> - return ( char * ) this + <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( SubchannelCall ) ) + <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( chanstk - > call_stack_size ) ; <nl> + return ( char * ) this + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( SubchannelCall ) ) + <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( chanstk - > call_stack_size ) ; <nl> } <nl> <nl> grpc_call_stack * SubchannelCall : : GetCallStack ( ) { <nl> mmm a / src / core / ext / transport / chttp2 / transport / chttp2_transport . cc <nl> ppp b / src / core / ext / transport / chttp2 / transport / chttp2_transport . cc <nl> grpc_chttp2_stream : : grpc_chttp2_stream ( grpc_chttp2_transport * t , <nl> grpc_slice_buffer_init ( & frame_storage ) ; <nl> grpc_slice_buffer_init ( & unprocessed_incoming_frames_buffer ) ; <nl> grpc_slice_buffer_init ( & flow_controlled_buffer ) ; <nl> - grpc_slice_buffer_init ( & compressed_data_buffer ) ; <nl> - grpc_slice_buffer_init ( & decompressed_data_buffer ) ; <nl> <nl> GRPC_CLOSURE_INIT ( & complete_fetch_locked , : : complete_fetch_locked , this , <nl> grpc_combiner_scheduler ( t - > combiner ) ) ; <nl> grpc_chttp2_stream : : ~ grpc_chttp2_stream ( ) { <nl> <nl> grpc_slice_buffer_destroy_internal ( & unprocessed_incoming_frames_buffer ) ; <nl> grpc_slice_buffer_destroy_internal ( & frame_storage ) ; <nl> - grpc_slice_buffer_destroy_internal ( & compressed_data_buffer ) ; <nl> - grpc_slice_buffer_destroy_internal ( & decompressed_data_buffer ) ; <nl> + if ( stream_compression_method ! = GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS ) { <nl> + grpc_slice_buffer_destroy_internal ( & compressed_data_buffer ) ; <nl> + } <nl> + if ( stream_decompression_method ! = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS ) { <nl> + grpc_slice_buffer_destroy_internal ( & decompressed_data_buffer ) ; <nl> + } <nl> <nl> grpc_chttp2_list_remove_stalled_by_transport ( t , this ) ; <nl> grpc_chttp2_list_remove_stalled_by_stream ( t , this ) ; <nl> static void destroy_stream ( grpc_transport * gt , grpc_stream * gs , <nl> GPR_TIMER_SCOPE ( " destroy_stream " , 0 ) ; <nl> grpc_chttp2_transport * t = reinterpret_cast < grpc_chttp2_transport * > ( gt ) ; <nl> grpc_chttp2_stream * s = reinterpret_cast < grpc_chttp2_stream * > ( gs ) ; <nl> - <nl> - if ( s - > stream_compression_ctx ! = nullptr ) { <nl> + if ( s - > stream_compression_method ! = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS & & <nl> + s - > stream_compression_ctx ! = nullptr ) { <nl> grpc_stream_compression_context_destroy ( s - > stream_compression_ctx ) ; <nl> s - > stream_compression_ctx = nullptr ; <nl> } <nl> - if ( s - > stream_decompression_ctx ! = nullptr ) { <nl> + if ( s - > stream_decompression_method ! = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS & & <nl> + s - > stream_decompression_ctx ! = nullptr ) { <nl> grpc_stream_compression_context_destroy ( s - > stream_decompression_ctx ) ; <nl> s - > stream_decompression_ctx = nullptr ; <nl> } <nl> static void perform_stream_op_locked ( void * stream_op , <nl> true , & s - > stream_compression_method ) = = 0 ) { <nl> s - > stream_compression_method = GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS ; <nl> } <nl> - <nl> + if ( s - > stream_compression_method ! = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS ) { <nl> + s - > uncompressed_data_size = 0 ; <nl> + s - > stream_compression_ctx = nullptr ; <nl> + grpc_slice_buffer_init ( & s - > compressed_data_buffer ) ; <nl> + } <nl> s - > send_initial_metadata_finished = add_closure_barrier ( on_complete ) ; <nl> s - > send_initial_metadata = <nl> op_payload - > send_initial_metadata . send_initial_metadata ; <nl> void grpc_chttp2_maybe_complete_recv_trailing_metadata ( grpc_chttp2_transport * t , <nl> ! s - > seen_error & & s - > recv_trailing_metadata_finished ! = nullptr ) { <nl> / * Maybe some SYNC_FLUSH data is left in frame_storage . Consume them and <nl> * maybe decompress the next 5 bytes in the stream . * / <nl> - bool end_of_context ; <nl> - if ( ! s - > stream_decompression_ctx ) { <nl> - s - > stream_decompression_ctx = grpc_stream_compression_context_create ( <nl> - s - > stream_decompression_method ) ; <nl> - } <nl> - if ( ! grpc_stream_decompress ( <nl> - s - > stream_decompression_ctx , & s - > frame_storage , <nl> - & s - > unprocessed_incoming_frames_buffer , nullptr , <nl> - GRPC_HEADER_SIZE_IN_BYTES , & end_of_context ) ) { <nl> - grpc_slice_buffer_reset_and_unref_internal ( & s - > frame_storage ) ; <nl> - grpc_slice_buffer_reset_and_unref_internal ( <nl> - & s - > unprocessed_incoming_frames_buffer ) ; <nl> - s - > seen_error = true ; <nl> - } else { <nl> + if ( s - > stream_decompression_method = = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS ) { <nl> + grpc_slice_buffer_move_first ( & s - > frame_storage , <nl> + GRPC_HEADER_SIZE_IN_BYTES , <nl> + & s - > unprocessed_incoming_frames_buffer ) ; <nl> if ( s - > unprocessed_incoming_frames_buffer . length > 0 ) { <nl> s - > unprocessed_incoming_frames_decompressed = true ; <nl> pending_data = true ; <nl> } <nl> - if ( end_of_context ) { <nl> - grpc_stream_compression_context_destroy ( s - > stream_decompression_ctx ) ; <nl> - s - > stream_decompression_ctx = nullptr ; <nl> + } else { <nl> + bool end_of_context ; <nl> + if ( ! s - > stream_decompression_ctx ) { <nl> + s - > stream_decompression_ctx = grpc_stream_compression_context_create ( <nl> + s - > stream_decompression_method ) ; <nl> + } <nl> + if ( ! grpc_stream_decompress ( <nl> + s - > stream_decompression_ctx , & s - > frame_storage , <nl> + & s - > unprocessed_incoming_frames_buffer , nullptr , <nl> + GRPC_HEADER_SIZE_IN_BYTES , & end_of_context ) ) { <nl> + grpc_slice_buffer_reset_and_unref_internal ( & s - > frame_storage ) ; <nl> + grpc_slice_buffer_reset_and_unref_internal ( <nl> + & s - > unprocessed_incoming_frames_buffer ) ; <nl> + s - > seen_error = true ; <nl> + } else { <nl> + if ( s - > unprocessed_incoming_frames_buffer . length > 0 ) { <nl> + s - > unprocessed_incoming_frames_decompressed = true ; <nl> + pending_data = true ; <nl> + } <nl> + if ( end_of_context ) { <nl> + grpc_stream_compression_context_destroy ( <nl> + s - > stream_decompression_ctx ) ; <nl> + s - > stream_decompression_ctx = nullptr ; <nl> + } <nl> } <nl> } <nl> } <nl> bool Chttp2IncomingByteStream : : Next ( size_t max_size_hint , <nl> } <nl> <nl> void Chttp2IncomingByteStream : : MaybeCreateStreamDecompressionCtx ( ) { <nl> + GPR_DEBUG_ASSERT ( stream_ - > stream_decompression_method ! = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS ) ; <nl> if ( ! stream_ - > stream_decompression_ctx ) { <nl> stream_ - > stream_decompression_ctx = grpc_stream_compression_context_create ( <nl> stream_ - > stream_decompression_method ) ; <nl> grpc_error * Chttp2IncomingByteStream : : Pull ( grpc_slice * slice ) { <nl> GPR_TIMER_SCOPE ( " incoming_byte_stream_pull " , 0 ) ; <nl> grpc_error * error ; <nl> if ( stream_ - > unprocessed_incoming_frames_buffer . length > 0 ) { <nl> - if ( ! stream_ - > unprocessed_incoming_frames_decompressed ) { <nl> + if ( ! stream_ - > unprocessed_incoming_frames_decompressed & & <nl> + stream_ - > stream_decompression_method ! = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS ) { <nl> bool end_of_context ; <nl> MaybeCreateStreamDecompressionCtx ( ) ; <nl> if ( ! grpc_stream_decompress ( stream_ - > stream_decompression_ctx , <nl> mmm a / src / core / ext / transport / chttp2 / transport / hpack_parser . cc <nl> ppp b / src / core / ext / transport / chttp2 / transport / hpack_parser . cc <nl> static void parse_stream_compression_md ( grpc_chttp2_transport * t , <nl> s - > stream_decompression_method = <nl> GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS ; <nl> } <nl> + <nl> + if ( s - > stream_decompression_method ! = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS ) { <nl> + s - > stream_decompression_ctx = nullptr ; <nl> + grpc_slice_buffer_init ( & s - > decompressed_data_buffer ) ; <nl> + } <nl> } <nl> <nl> grpc_error * grpc_chttp2_header_parser_parse ( void * hpack_parser , <nl> mmm a / src / core / ext / transport / chttp2 / transport / internal . h <nl> ppp b / src / core / ext / transport / chttp2 / transport / internal . h <nl> struct grpc_chttp2_stream { <nl> <nl> grpc_slice_buffer frame_storage ; / * protected by t combiner * / <nl> <nl> - / * Accessed only by transport thread when stream - > pending_byte_stream = = false <nl> - * Accessed only by application thread when stream - > pending_byte_stream = = <nl> - * true * / <nl> - grpc_slice_buffer unprocessed_incoming_frames_buffer ; <nl> grpc_closure * on_next = nullptr ; / * protected by t combiner * / <nl> bool pending_byte_stream = false ; / * protected by t combiner * / <nl> / / cached length of buffer to be used by the transport thread in cases where <nl> struct grpc_chttp2_stream { <nl> / / application threads are allowed to modify <nl> / / unprocessed_incoming_frames_buffer <nl> size_t unprocessed_incoming_frames_buffer_cached_length = 0 ; <nl> + / * Accessed only by transport thread when stream - > pending_byte_stream = = false <nl> + * Accessed only by application thread when stream - > pending_byte_stream = = <nl> + * true * / <nl> + grpc_slice_buffer unprocessed_incoming_frames_buffer ; <nl> grpc_closure reset_byte_stream ; <nl> grpc_error * byte_stream_error = GRPC_ERROR_NONE ; / * protected by t combiner * / <nl> bool received_last_frame = false ; / * protected by t combiner * / <nl> struct grpc_chttp2_stream { <nl> / * Stream decompression method to be used . * / <nl> grpc_stream_compression_method stream_decompression_method = <nl> GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS ; <nl> - / * * Stream compression decompress context * / <nl> - grpc_stream_compression_context * stream_decompression_ctx = nullptr ; <nl> - / * * Stream compression compress context * / <nl> - grpc_stream_compression_context * stream_compression_ctx = nullptr ; <nl> <nl> - / * * Buffer storing data that is compressed but not sent * / <nl> - grpc_slice_buffer compressed_data_buffer ; <nl> - / * * Amount of uncompressed bytes sent out when compressed_data_buffer is <nl> - * emptied * / <nl> - size_t uncompressed_data_size = 0 ; <nl> - / * * Temporary buffer storing decompressed data * / <nl> - grpc_slice_buffer decompressed_data_buffer ; <nl> / * * Whether bytes stored in unprocessed_incoming_byte_stream is decompressed <nl> * / <nl> bool unprocessed_incoming_frames_decompressed = false ; <nl> struct grpc_chttp2_stream { <nl> size_t decompressed_header_bytes = 0 ; <nl> / * * Byte counter for number of bytes written * / <nl> size_t byte_counter = 0 ; <nl> + <nl> + / * * Amount of uncompressed bytes sent out when compressed_data_buffer is <nl> + * emptied * / <nl> + size_t uncompressed_data_size ; <nl> + / * * Stream compression compress context * / <nl> + grpc_stream_compression_context * stream_compression_ctx ; <nl> + / * * Buffer storing data that is compressed but not sent * / <nl> + grpc_slice_buffer compressed_data_buffer ; <nl> + <nl> + / * * Stream compression decompress context * / <nl> + grpc_stream_compression_context * stream_decompression_ctx ; <nl> + / * * Temporary buffer storing decompressed data . <nl> + * Initialized , used , and destroyed only when stream uses ( non - identity ) <nl> + * compression . <nl> + * / <nl> + grpc_slice_buffer decompressed_data_buffer ; <nl> } ; <nl> <nl> / * * Transport writing call flow : <nl> mmm a / src / core / ext / transport / chttp2 / transport / writing . cc <nl> ppp b / src / core / ext / transport / chttp2 / transport / writing . cc <nl> <nl> <nl> # include < grpc / support / log . h > <nl> <nl> + # include " src / core / lib / compression / stream_compression . h " <nl> # include " src / core / lib / debug / stats . h " <nl> # include " src / core / lib / profiling / timers . h " <nl> # include " src / core / lib / slice / slice_internal . h " <nl> static void report_stall ( grpc_chttp2_transport * t , grpc_chttp2_stream * s , <nl> " : flowed = % " PRId64 " : peer_initwin = % d : t_win = % " PRId64 <nl> " : s_win = % d : s_delta = % " PRId64 " ] " , <nl> t - > peer_string , t , s - > id , staller , s - > flow_controlled_buffer . length , <nl> - s - > compressed_data_buffer . length , s - > flow_controlled_bytes_flowed , <nl> + s - > stream_compression_method = = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS <nl> + ? 0 <nl> + : s - > compressed_data_buffer . length , <nl> + s - > flow_controlled_bytes_flowed , <nl> t - > settings [ GRPC_ACKED_SETTINGS ] <nl> [ GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE ] , <nl> t - > flow_control - > remote_window ( ) , <nl> class DataSendContext { <nl> <nl> bool AnyOutgoing ( ) const { return max_outgoing ( ) > 0 ; } <nl> <nl> + void FlushUncompressedBytes ( ) { <nl> + uint32_t send_bytes = static_cast < uint32_t > GPR_MIN ( <nl> + max_outgoing ( ) , s_ - > flow_controlled_buffer . length ) ; <nl> + is_last_frame_ = send_bytes = = s_ - > flow_controlled_buffer . length & & <nl> + s_ - > fetching_send_message = = nullptr & & <nl> + s_ - > send_trailing_metadata ! = nullptr & & <nl> + grpc_metadata_batch_is_empty ( s_ - > send_trailing_metadata ) ; <nl> + grpc_chttp2_encode_data ( s_ - > id , & s_ - > flow_controlled_buffer , send_bytes , <nl> + is_last_frame_ , & s_ - > stats . outgoing , & t_ - > outbuf ) ; <nl> + s_ - > flow_control - > SentData ( send_bytes ) ; <nl> + s_ - > sending_bytes + = send_bytes ; <nl> + } <nl> + <nl> void FlushCompressedBytes ( ) { <nl> + GPR_DEBUG_ASSERT ( s_ - > stream_compression_method ! = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS ) ; <nl> + <nl> uint32_t send_bytes = static_cast < uint32_t > GPR_MIN ( <nl> max_outgoing ( ) , s_ - > compressed_data_buffer . length ) ; <nl> bool is_last_data_frame = <nl> class DataSendContext { <nl> } <nl> <nl> void CompressMoreBytes ( ) { <nl> + GPR_DEBUG_ASSERT ( s_ - > stream_compression_method ! = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS ) ; <nl> + <nl> if ( s_ - > stream_compression_ctx = = nullptr ) { <nl> s_ - > stream_compression_ctx = <nl> grpc_stream_compression_context_create ( s_ - > stream_compression_method ) ; <nl> class StreamWriteContext { <nl> / / https : / / github . com / grpc / proposal / blob / master / A6 - client - retries . md # when - retries - are - valid <nl> if ( ! t_ - > is_client & & s_ - > fetching_send_message = = nullptr & & <nl> s_ - > flow_controlled_buffer . length = = 0 & & <nl> - s_ - > compressed_data_buffer . length = = 0 & & <nl> + compressed_data_buffer_len ( ) = = 0 & & <nl> s_ - > send_trailing_metadata ! = nullptr & & <nl> is_default_initial_metadata ( s_ - > send_initial_metadata ) ) { <nl> ConvertInitialMetadataToTrailingMetadata ( ) ; <nl> class StreamWriteContext { <nl> " send_initial_metadata_finished " ) ; <nl> } <nl> <nl> + bool compressed_data_buffer_len ( ) { <nl> + return s_ - > stream_compression_method = = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS <nl> + ? 0 <nl> + : s_ - > compressed_data_buffer . length ; <nl> + } <nl> + <nl> void FlushWindowUpdates ( ) { <nl> / * send any window updates * / <nl> const uint32_t stream_announce = s_ - > flow_control - > MaybeSendUpdate ( ) ; <nl> class StreamWriteContext { <nl> if ( ! s_ - > sent_initial_metadata ) return ; <nl> <nl> if ( s_ - > flow_controlled_buffer . length = = 0 & & <nl> - s_ - > compressed_data_buffer . length = = 0 ) { <nl> + compressed_data_buffer_len ( ) = = 0 ) { <nl> return ; / / early out : nothing to do <nl> } <nl> <nl> class StreamWriteContext { <nl> return ; / / early out : nothing to do <nl> } <nl> <nl> - while ( ( s_ - > flow_controlled_buffer . length > 0 | | <nl> - s_ - > compressed_data_buffer . length > 0 ) & & <nl> - data_send_context . max_outgoing ( ) > 0 ) { <nl> - if ( s_ - > compressed_data_buffer . length > 0 ) { <nl> - data_send_context . FlushCompressedBytes ( ) ; <nl> - } else { <nl> - data_send_context . CompressMoreBytes ( ) ; <nl> + if ( s_ - > stream_compression_method = = <nl> + GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS ) { <nl> + while ( s_ - > flow_controlled_buffer . length > 0 & & <nl> + data_send_context . max_outgoing ( ) > 0 ) { <nl> + data_send_context . FlushUncompressedBytes ( ) ; <nl> + } <nl> + } else { <nl> + while ( ( s_ - > flow_controlled_buffer . length > 0 | | <nl> + s_ - > compressed_data_buffer . length > 0 ) & & <nl> + data_send_context . max_outgoing ( ) > 0 ) { <nl> + if ( s_ - > compressed_data_buffer . length > 0 ) { <nl> + data_send_context . FlushCompressedBytes ( ) ; <nl> + } else { <nl> + data_send_context . CompressMoreBytes ( ) ; <nl> + } <nl> } <nl> } <nl> write_context_ - > ResetPingClock ( ) ; <nl> class StreamWriteContext { <nl> data_send_context . CallCallbacks ( ) ; <nl> stream_became_writable_ = true ; <nl> if ( s_ - > flow_controlled_buffer . length > 0 | | <nl> - s_ - > compressed_data_buffer . length > 0 ) { <nl> + compressed_data_buffer_len ( ) > 0 ) { <nl> GRPC_CHTTP2_STREAM_REF ( s_ , " chttp2_writing : fork " ) ; <nl> grpc_chttp2_list_add_writable_stream ( t_ , s_ ) ; <nl> } <nl> class StreamWriteContext { <nl> if ( s_ - > send_trailing_metadata = = nullptr ) return ; <nl> if ( s_ - > fetching_send_message ! = nullptr ) return ; <nl> if ( s_ - > flow_controlled_buffer . length ! = 0 ) return ; <nl> - if ( s_ - > compressed_data_buffer . length ! = 0 ) return ; <nl> + if ( compressed_data_buffer_len ( ) ! = 0 ) return ; <nl> <nl> GRPC_CHTTP2_IF_TRACING ( gpr_log ( GPR_INFO , " sending trailing_metadata " ) ) ; <nl> if ( grpc_metadata_batch_is_empty ( s_ - > send_trailing_metadata ) ) { <nl> mmm a / src / core / lib / channel / channel_stack . cc <nl> ppp b / src / core / lib / channel / channel_stack . cc <nl> grpc_core : : TraceFlag grpc_trace_channel ( false , " channel " ) ; <nl> size_t grpc_channel_stack_size ( const grpc_channel_filter * * filters , <nl> size_t filter_count ) { <nl> / * always need the header , and size for the channel elements * / <nl> - size_t size = GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( grpc_channel_stack ) ) + <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( <nl> - filter_count * sizeof ( grpc_channel_element ) ) ; <nl> + size_t size = GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( grpc_channel_stack ) ) + <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( filter_count * <nl> + sizeof ( grpc_channel_element ) ) ; <nl> size_t i ; <nl> <nl> GPR_ASSERT ( ( GPR_MAX_ALIGNMENT & ( GPR_MAX_ALIGNMENT - 1 ) ) = = 0 & & <nl> size_t grpc_channel_stack_size ( const grpc_channel_filter * * filters , <nl> <nl> / * add the size for each filter * / <nl> for ( i = 0 ; i < filter_count ; i + + ) { <nl> - size + = GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( filters [ i ] - > sizeof_channel_data ) ; <nl> + size + = GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( filters [ i ] - > sizeof_channel_data ) ; <nl> } <nl> <nl> return size ; <nl> } <nl> <nl> - # define CHANNEL_ELEMS_FROM_STACK ( stk ) \ <nl> - ( ( grpc_channel_element * ) ( ( char * ) ( stk ) + GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( \ <nl> + # define CHANNEL_ELEMS_FROM_STACK ( stk ) \ <nl> + ( ( grpc_channel_element * ) ( ( char * ) ( stk ) + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( \ <nl> sizeof ( grpc_channel_stack ) ) ) ) <nl> <nl> - # define CALL_ELEMS_FROM_STACK ( stk ) \ <nl> - ( ( grpc_call_element * ) ( ( char * ) ( stk ) + GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( \ <nl> + # define CALL_ELEMS_FROM_STACK ( stk ) \ <nl> + ( ( grpc_call_element * ) ( ( char * ) ( stk ) + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( \ <nl> sizeof ( grpc_call_stack ) ) ) ) <nl> <nl> grpc_channel_element * grpc_channel_stack_element ( <nl> grpc_error * grpc_channel_stack_init ( <nl> const grpc_channel_args * channel_args , grpc_transport * optional_transport , <nl> const char * name , grpc_channel_stack * stack ) { <nl> size_t call_size = <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( grpc_call_stack ) ) + <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( filter_count * <nl> - sizeof ( grpc_call_element ) ) ; <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( grpc_call_stack ) ) + <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( filter_count * sizeof ( grpc_call_element ) ) ; <nl> grpc_channel_element * elems ; <nl> grpc_channel_element_args args ; <nl> char * user_data ; <nl> grpc_error * grpc_channel_stack_init ( <nl> name ) ; <nl> elems = CHANNEL_ELEMS_FROM_STACK ( stack ) ; <nl> user_data = ( reinterpret_cast < char * > ( elems ) ) + <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( filter_count * <nl> - sizeof ( grpc_channel_element ) ) ; <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( filter_count * <nl> + sizeof ( grpc_channel_element ) ) ; <nl> <nl> / * init per - filter data * / <nl> grpc_error * first_error = GRPC_ERROR_NONE ; <nl> grpc_error * grpc_channel_stack_init ( <nl> } <nl> } <nl> user_data + = <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( filters [ i ] - > sizeof_channel_data ) ; <nl> - call_size + = <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( filters [ i ] - > sizeof_call_data ) ; <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( filters [ i ] - > sizeof_channel_data ) ; <nl> + call_size + = GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( filters [ i ] - > sizeof_call_data ) ; <nl> } <nl> <nl> GPR_ASSERT ( user_data > ( char * ) stack ) ; <nl> grpc_error * grpc_call_stack_init ( grpc_channel_stack * channel_stack , <nl> GRPC_STREAM_REF_INIT ( & elem_args - > call_stack - > refcount , initial_refs , destroy , <nl> destroy_arg , " CALL_STACK " ) ; <nl> call_elems = CALL_ELEMS_FROM_STACK ( elem_args - > call_stack ) ; <nl> - user_data = <nl> - ( reinterpret_cast < char * > ( call_elems ) ) + <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( count * sizeof ( grpc_call_element ) ) ; <nl> + user_data = ( reinterpret_cast < char * > ( call_elems ) ) + <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( count * sizeof ( grpc_call_element ) ) ; <nl> <nl> / * init per - filter data * / <nl> grpc_error * first_error = GRPC_ERROR_NONE ; <nl> grpc_error * grpc_call_stack_init ( grpc_channel_stack * channel_stack , <nl> call_elems [ i ] . filter = channel_elems [ i ] . filter ; <nl> call_elems [ i ] . channel_data = channel_elems [ i ] . channel_data ; <nl> call_elems [ i ] . call_data = user_data ; <nl> - user_data + = GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( <nl> - call_elems [ i ] . filter - > sizeof_call_data ) ; <nl> + user_data + = <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( call_elems [ i ] . filter - > sizeof_call_data ) ; <nl> } <nl> for ( size_t i = 0 ; i < count ; i + + ) { <nl> grpc_error * error = <nl> grpc_channel_stack * grpc_channel_stack_from_top_element ( <nl> grpc_channel_element * elem ) { <nl> return reinterpret_cast < grpc_channel_stack * > ( <nl> reinterpret_cast < char * > ( elem ) - <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( grpc_channel_stack ) ) ) ; <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( grpc_channel_stack ) ) ) ; <nl> } <nl> <nl> grpc_call_stack * grpc_call_stack_from_top_element ( grpc_call_element * elem ) { <nl> return reinterpret_cast < grpc_call_stack * > ( <nl> reinterpret_cast < char * > ( elem ) - <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( grpc_call_stack ) ) ) ; <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( grpc_call_stack ) ) ) ; <nl> } <nl> mmm a / src / core / lib / gpr / alloc . cc <nl> ppp b / src / core / lib / gpr / alloc . cc <nl> <nl> # include < grpc / support / log . h > <nl> # include < stdlib . h > <nl> # include < string . h > <nl> - # include " src / core / lib / gpr / alloc . h " <nl> # include " src / core / lib / profiling / timers . h " <nl> <nl> static void * zalloc_with_calloc ( size_t sz ) { return calloc ( sz , 1 ) ; } <nl> static void * zalloc_with_gpr_malloc ( size_t sz ) { <nl> return p ; <nl> } <nl> <nl> - # ifndef NDEBUG <nl> - static constexpr bool is_power_of_two ( size_t value ) { <nl> - / / 2 ^ N = 100000 . . . 000 <nl> - / / 2 ^ N - 1 = 011111 . . . 111 <nl> - / / ( 2 ^ N ) & & ( ( 2 ^ N ) - 1 ) ) = 0 <nl> - return ( value & ( value - 1 ) ) = = 0 ; <nl> - } <nl> - # endif <nl> - <nl> - static void * platform_malloc_aligned ( size_t size , size_t alignment ) { <nl> - # if defined ( GPR_HAS_ALIGNED_ALLOC ) <nl> - GPR_DEBUG_ASSERT ( is_power_of_two ( alignment ) ) ; <nl> - size = GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( size , alignment ) ; <nl> - void * ret = aligned_alloc ( alignment , size ) ; <nl> - GPR_ASSERT ( ret ! = nullptr ) ; <nl> - return ret ; <nl> - # elif defined ( GPR_HAS_ALIGNED_MALLOC ) <nl> - GPR_DEBUG_ASSERT ( is_power_of_two ( alignment ) ) ; <nl> - void * ret = _aligned_malloc ( size , alignment ) ; <nl> - GPR_ASSERT ( ret ! = nullptr ) ; <nl> - return ret ; <nl> - # elif defined ( GPR_HAS_POSIX_MEMALIGN ) <nl> - GPR_DEBUG_ASSERT ( is_power_of_two ( alignment ) ) ; <nl> - GPR_DEBUG_ASSERT ( alignment % sizeof ( void * ) = = 0 ) ; <nl> - void * ret = nullptr ; <nl> - GPR_ASSERT ( posix_memalign ( & ret , alignment , size ) = = 0 ) ; <nl> - return ret ; <nl> - # else <nl> - GPR_DEBUG_ASSERT ( is_power_of_two ( alignment ) ) ; <nl> - size_t extra = alignment - 1 + sizeof ( void * ) ; <nl> - void * p = gpr_malloc ( size + extra ) ; <nl> - void * * ret = ( void * * ) ( ( ( uintptr_t ) p + extra ) & ~ ( alignment - 1 ) ) ; <nl> - ret [ - 1 ] = p ; <nl> - return ( void * ) ret ; <nl> - # endif <nl> - } <nl> - <nl> - static void platform_free_aligned ( void * ptr ) { <nl> - # if defined ( GPR_HAS_ALIGNED_ALLOC ) | | defined ( GPR_HAS_POSIX_MEMALIGN ) <nl> - free ( ptr ) ; <nl> - # elif defined ( GPR_HAS_ALIGNED_MALLOC ) <nl> - _aligned_free ( ptr ) ; <nl> - # else <nl> - gpr_free ( ( static_cast < void * * > ( ptr ) ) [ - 1 ] ) ; <nl> - # endif <nl> - } <nl> - <nl> - static gpr_allocation_functions g_alloc_functions = { <nl> - malloc , zalloc_with_calloc , realloc , <nl> - free , platform_malloc_aligned , platform_free_aligned } ; <nl> + static gpr_allocation_functions g_alloc_functions = { malloc , zalloc_with_calloc , <nl> + realloc , free } ; <nl> <nl> gpr_allocation_functions gpr_get_allocation_functions ( ) { <nl> return g_alloc_functions ; <nl> void gpr_set_allocation_functions ( gpr_allocation_functions functions ) { <nl> if ( functions . zalloc_fn = = nullptr ) { <nl> functions . zalloc_fn = zalloc_with_gpr_malloc ; <nl> } <nl> - GPR_ASSERT ( ( functions . aligned_alloc_fn = = nullptr ) = = <nl> - ( functions . aligned_free_fn = = nullptr ) ) ; <nl> - if ( functions . aligned_alloc_fn = = nullptr ) { <nl> - functions . aligned_alloc_fn = platform_malloc_aligned ; <nl> - functions . aligned_free_fn = platform_free_aligned ; <nl> - } <nl> g_alloc_functions = functions ; <nl> } <nl> <nl> void * gpr_realloc ( void * p , size_t size ) { <nl> } <nl> <nl> void * gpr_malloc_aligned ( size_t size , size_t alignment ) { <nl> - GPR_TIMER_SCOPE ( " gpr_malloc_aligned " , 0 ) ; <nl> - if ( size = = 0 ) return nullptr ; <nl> - return g_alloc_functions . aligned_alloc_fn ( size , alignment ) ; <nl> + GPR_ASSERT ( ( ( alignment - 1 ) & alignment ) = = 0 ) ; / / Must be power of 2 . <nl> + size_t extra = alignment - 1 + sizeof ( void * ) ; <nl> + void * p = gpr_malloc ( size + extra ) ; <nl> + void * * ret = ( void * * ) ( ( ( uintptr_t ) p + extra ) & ~ ( alignment - 1 ) ) ; <nl> + ret [ - 1 ] = p ; <nl> + return ( void * ) ret ; <nl> } <nl> <nl> - void gpr_free_aligned ( void * ptr ) { <nl> - GPR_TIMER_SCOPE ( " gpr_free_aligned " , 0 ) ; <nl> - g_alloc_functions . aligned_free_fn ( ptr ) ; <nl> - } <nl> + void gpr_free_aligned ( void * ptr ) { gpr_free ( ( static_cast < void * * > ( ptr ) ) [ - 1 ] ) ; } <nl> mmm a / src / core / lib / gpr / alloc . h <nl> ppp b / src / core / lib / gpr / alloc . h <nl> <nl> # include < grpc / support / port_platform . h > <nl> <nl> / / / Given a size , round up to the next multiple of sizeof ( void * ) . <nl> - # define GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( x , align ) \ <nl> - ( ( ( x ) + ( align ) - 1u ) & ~ ( ( align ) - 1u ) ) <nl> - <nl> - # define GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( x ) \ <nl> - GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( ( x ) , GPR_MAX_ALIGNMENT ) <nl> - <nl> - # define GPR_ROUND_UP_TO_CACHELINE_SIZE ( x ) \ <nl> - GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( ( x ) , GPR_CACHELINE_SIZE ) <nl> + # define GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( x ) \ <nl> + ( ( ( x ) + GPR_MAX_ALIGNMENT - 1u ) & ~ ( GPR_MAX_ALIGNMENT - 1u ) ) <nl> <nl> # endif / * GRPC_CORE_LIB_GPR_ALLOC_H * / <nl> mmm a / src / core / lib / gprpp / arena . cc <nl> ppp b / src / core / lib / gprpp / arena . cc <nl> namespace { <nl> <nl> void * ArenaStorage ( size_t initial_size ) { <nl> static constexpr size_t base_size = <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( grpc_core : : Arena ) ) ; <nl> - initial_size = GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( initial_size ) ; <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( grpc_core : : Arena ) ) ; <nl> + initial_size = GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( initial_size ) ; <nl> size_t alloc_size = base_size + initial_size ; <nl> static constexpr size_t alignment = <nl> ( GPR_CACHELINE_SIZE > GPR_MAX_ALIGNMENT & & <nl> Arena * Arena : : Create ( size_t initial_size ) { <nl> Pair < Arena * , void * > Arena : : CreateWithAlloc ( size_t initial_size , <nl> size_t alloc_size ) { <nl> static constexpr size_t base_size = <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( Arena ) ) ; <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( Arena ) ) ; <nl> auto * new_arena = <nl> new ( ArenaStorage ( initial_size ) ) Arena ( initial_size , alloc_size ) ; <nl> void * first_alloc = reinterpret_cast < char * > ( new_arena ) + base_size ; <nl> void * Arena : : AllocZone ( size_t size ) { <nl> / / sizing hysteresis ( that is , most calls should have a large enough initial <nl> / / zone and will not need to grow the arena ) . <nl> static constexpr size_t zone_base_size = <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( Zone ) ) ; <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( Zone ) ) ; <nl> size_t alloc_size = zone_base_size + size ; <nl> Zone * z = new ( gpr_malloc_aligned ( alloc_size , GPR_MAX_ALIGNMENT ) ) Zone ( ) ; <nl> { <nl> mmm a / src / core / lib / gprpp / arena . h <nl> ppp b / src / core / lib / gprpp / arena . h <nl> class Arena { <nl> / / Allocate \ a size bytes from the arena . <nl> void * Alloc ( size_t size ) { <nl> static constexpr size_t base_size = <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( Arena ) ) ; <nl> - size = GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( size ) ; <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( Arena ) ) ; <nl> + size = GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( size ) ; <nl> size_t begin = total_used_ . FetchAdd ( size , MemoryOrder : : RELAXED ) ; <nl> - if ( GPR_LIKELY ( begin + size < = initial_zone_size_ ) ) { <nl> + if ( begin + size < = initial_zone_size_ ) { <nl> return reinterpret_cast < char * > ( this ) + base_size + begin ; <nl> } else { <nl> return AllocZone ( size ) ; <nl> mmm a / src / core / lib / iomgr / ev_epoll1_linux . cc <nl> ppp b / src / core / lib / iomgr / ev_epoll1_linux . cc <nl> static void fd_shutdown_internal ( grpc_fd * fd , grpc_error * why , <nl> if ( fd - > read_closure - > SetShutdown ( GRPC_ERROR_REF ( why ) ) ) { <nl> if ( ! releasing_fd ) { <nl> shutdown ( fd - > fd , SHUT_RDWR ) ; <nl> + } else { <nl> + / * we need a dummy event for earlier linux versions . * / <nl> + epoll_event dummy_event ; <nl> + if ( epoll_ctl ( g_epoll_set . epfd , EPOLL_CTL_DEL , fd - > fd , & dummy_event ) ! = <nl> + 0 ) { <nl> + gpr_log ( GPR_ERROR , " epoll_ctl failed : % s " , strerror ( errno ) ) ; <nl> + } <nl> } <nl> fd - > write_closure - > SetShutdown ( GRPC_ERROR_REF ( why ) ) ; <nl> fd - > error_closure - > SetShutdown ( GRPC_ERROR_REF ( why ) ) ; <nl> mmm a / src / core / lib / surface / call . cc <nl> ppp b / src / core / lib / surface / call . cc <nl> grpc_core : : TraceFlag grpc_compression_trace ( false , " compression " ) ; <nl> <nl> # define CALL_STACK_FROM_CALL ( call ) \ <nl> ( grpc_call_stack * ) ( ( char * ) ( call ) + \ <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( grpc_call ) ) ) <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( grpc_call ) ) ) <nl> # define CALL_FROM_CALL_STACK ( call_stack ) \ <nl> ( grpc_call * ) ( ( ( char * ) ( call_stack ) ) - \ <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( grpc_call ) ) ) <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( grpc_call ) ) ) <nl> <nl> # define CALL_ELEM_FROM_CALL ( call , idx ) \ <nl> grpc_call_stack_element ( CALL_STACK_FROM_CALL ( call ) , idx ) <nl> grpc_error * grpc_call_create ( const grpc_call_create_args * args , <nl> size_t initial_size = grpc_channel_get_call_size_estimate ( args - > channel ) ; <nl> GRPC_STATS_INC_CALL_INITIAL_SIZE ( initial_size ) ; <nl> size_t call_and_stack_size = <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( grpc_call ) ) + <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( grpc_call ) ) + <nl> channel_stack - > call_stack_size ; <nl> size_t call_alloc_size = <nl> call_and_stack_size + ( args - > parent ? sizeof ( child_call ) : 0 ) ; <nl> mmm a / src / core / lib / transport / transport . cc <nl> ppp b / src / core / lib / transport / transport . cc <nl> void grpc_transport_move_stats ( grpc_transport_stream_stats * from , <nl> } <nl> <nl> size_t grpc_transport_stream_size ( grpc_transport * transport ) { <nl> - return GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( transport - > vtable - > sizeof_stream ) ; <nl> + return GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( transport - > vtable - > sizeof_stream ) ; <nl> } <nl> <nl> void grpc_transport_destroy ( grpc_transport * transport ) { <nl> mmm a / src / csharp / Grpc . Core . Api / DeserializationContext . cs <nl> ppp b / src / csharp / Grpc . Core . Api / DeserializationContext . cs <nl> public abstract class DeserializationContext <nl> / / / Also , allocating a new buffer each time can put excessive pressure on GC , especially if <nl> / / / the payload is more than 86700 bytes large ( which means the newly allocated buffer will be placed in LOH , <nl> / / / and LOH object can only be garbage collected via a full ( " stop the world " ) GC run ) . <nl> - / / / NOTE : Deserializers are expected not to call this method more than once per received message <nl> + / / / NOTE : Deserializers are expected not to call this method ( or other payload accessor methods ) more than once per received message <nl> / / / ( as there is no practical reason for doing so ) and < c > DeserializationContext < / c > implementations are free to assume so . <nl> / / / < / summary > <nl> / / / < returns > byte array containing the entire payload . < / returns > <nl> public virtual byte [ ] PayloadAsNewBuffer ( ) <nl> { <nl> throw new NotImplementedException ( ) ; <nl> } <nl> + <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + / / / < summary > <nl> + / / / Gets the entire payload as a ReadOnlySequence . <nl> + / / / The ReadOnlySequence is only valid for the duration of the deserializer routine and the caller must not access it after the deserializer returns . <nl> + / / / Using the read only sequence is the most efficient way to access the message payload . Where possible it allows directly <nl> + / / / accessing the received payload without needing to perform any buffer copying or buffer allocations . <nl> + / / / NOTE : This method is only available in the netstandard2 . 0 build of the library . <nl> + / / / NOTE : Deserializers are expected not to call this method ( or other payload accessor methods ) more than once per received message <nl> + / / / ( as there is no practical reason for doing so ) and < c > DeserializationContext < / c > implementations are free to assume so . <nl> + / / / < / summary > <nl> + / / / < returns > read only sequence containing the entire payload . < / returns > <nl> + public virtual System . Buffers . ReadOnlySequence < byte > PayloadAsReadOnlySequence ( ) <nl> + { <nl> + throw new NotImplementedException ( ) ; <nl> + } <nl> + # endif <nl> } <nl> } <nl> mmm a / src / csharp / Grpc . Core . Api / Grpc . Core . Api . csproj <nl> ppp b / src / csharp / Grpc . Core . Api / Grpc . Core . Api . csproj <nl> <nl> < TreatWarningsAsErrors > true < / TreatWarningsAsErrors > <nl> < / PropertyGroup > <nl> <nl> + < PropertyGroup Condition = " ' $ ( TargetFramework ) ' = = ' netstandard2 . 0 ' " > <nl> + < DefineConstants > $ ( DefineConstants ) ; GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY < / DefineConstants > <nl> + < / PropertyGroup > <nl> + <nl> < Import Project = " . . \ Grpc . Core \ SourceLink . csproj . include " / > <nl> <nl> < ItemGroup > <nl> < PackageReference Include = " System . Interactive . Async " Version = " 3 . 2 . 0 " / > <nl> < / ItemGroup > <nl> <nl> + < ItemGroup Condition = " ' $ ( TargetFramework ) ' = = ' netstandard2 . 0 ' " > <nl> + < PackageReference Include = " System . Memory " Version = " 4 . 5 . 2 " / > <nl> + < / ItemGroup > <nl> + <nl> < ItemGroup Condition = " ' $ ( TargetFramework ) ' = = ' net45 ' " > <nl> < Reference Include = " System " / > <nl> < Reference Include = " Microsoft . CSharp " / > <nl> mmm a / src / csharp / Grpc . Core . Api / StatusCode . cs <nl> ppp b / src / csharp / Grpc . Core . Api / StatusCode . cs <nl> public enum StatusCode <nl> / / / < summary > <nl> / / / The service is currently unavailable . This is a most likely a <nl> / / / transient condition and may be corrected by retrying with <nl> - / / / a backoff . <nl> + / / / a backoff . Note that it is not always safe to retry <nl> + / / / non - idempotent operations . <nl> / / / < / summary > <nl> Unavailable = 14 , <nl> <nl> mmm a / src / csharp / Grpc . Core . Tests / Grpc . Core . Tests . csproj <nl> ppp b / src / csharp / Grpc . Core . Tests / Grpc . Core . Tests . csproj <nl> <nl> < TreatWarningsAsErrors > true < / TreatWarningsAsErrors > <nl> < / PropertyGroup > <nl> <nl> + < PropertyGroup Condition = " ' $ ( TargetFramework ) ' = = ' netcoreapp2 . 1 ' " > <nl> + < DefineConstants > $ ( DefineConstants ) ; GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY < / DefineConstants > <nl> + < / PropertyGroup > <nl> + <nl> < ItemGroup > <nl> < ProjectReference Include = " . . / Grpc . Core / Grpc . Core . csproj " / > <nl> < / ItemGroup > <nl> mmm a / src / csharp / Grpc . Core . Tests / Internal / AsyncCallServerTest . cs <nl> ppp b / src / csharp / Grpc . Core . Tests / Internal / AsyncCallServerTest . cs <nl> public class AsyncCallServerTest <nl> Server server ; <nl> FakeNativeCall fakeCall ; <nl> AsyncCallServer < string , string > asyncCallServer ; <nl> + FakeBufferReaderManager fakeBufferReaderManager ; <nl> <nl> [ SetUp ] <nl> public void Init ( ) <nl> public void Init ( ) <nl> Marshallers . StringMarshaller . ContextualSerializer , Marshallers . StringMarshaller . ContextualDeserializer , <nl> server ) ; <nl> asyncCallServer . InitializeForTesting ( fakeCall ) ; <nl> + fakeBufferReaderManager = new FakeBufferReaderManager ( ) ; <nl> } <nl> <nl> [ TearDown ] <nl> public void Cleanup ( ) <nl> { <nl> + fakeBufferReaderManager . Dispose ( ) ; <nl> server . ShutdownAsync ( ) . Wait ( ) ; <nl> } <nl> <nl> public void CancelNotificationAfterStartDisposesAfterPendingReadFinishes ( ) <nl> var moveNextTask = requestStream . MoveNext ( ) ; <nl> <nl> fakeCall . ReceivedCloseOnServerCallback . OnReceivedCloseOnServer ( true , cancelled : true ) ; <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , CreateNullResponse ( ) ) ; <nl> Assert . IsFalse ( moveNextTask . Result ) ; <nl> <nl> AssertFinished ( asyncCallServer , fakeCall , finishedTask ) ; <nl> public void ReadCompletionFailureClosesRequestStream ( ) <nl> / / if a read completion ' s success = = false , the request stream will silently finish <nl> / / and we rely on C core cancelling the call . <nl> var moveNextTask = requestStream . MoveNext ( ) ; <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( false , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( false , CreateNullResponse ( ) ) ; <nl> Assert . IsFalse ( moveNextTask . Result ) ; <nl> <nl> fakeCall . ReceivedCloseOnServerCallback . OnReceivedCloseOnServer ( true , cancelled : true ) ; <nl> static void AssertFinished ( AsyncCallServer < string , string > asyncCallServer , Fake <nl> Assert . IsTrue ( finishedTask . IsCompleted ) ; <nl> Assert . DoesNotThrow ( ( ) = > finishedTask . Wait ( ) ) ; <nl> } <nl> + <nl> + IBufferReader CreateNullResponse ( ) <nl> + { <nl> + return fakeBufferReaderManager . CreateNullPayloadBufferReader ( ) ; <nl> + } <nl> } <nl> } <nl> mmm a / src / csharp / Grpc . Core . Tests / Internal / AsyncCallTest . cs <nl> ppp b / src / csharp / Grpc . Core . Tests / Internal / AsyncCallTest . cs <nl> <nl> using System . Threading . Tasks ; <nl> <nl> using Grpc . Core . Internal ; <nl> + using Grpc . Core . Utils ; <nl> using NUnit . Framework ; <nl> <nl> namespace Grpc . Core . Internal . Tests <nl> public class AsyncCallTest <nl> Channel channel ; <nl> FakeNativeCall fakeCall ; <nl> AsyncCall < string , string > asyncCall ; <nl> + FakeBufferReaderManager fakeBufferReaderManager ; <nl> <nl> [ SetUp ] <nl> public void Init ( ) <nl> public void Init ( ) <nl> <nl> var callDetails = new CallInvocationDetails < string , string > ( channel , " someMethod " , null , Marshallers . StringMarshaller , Marshallers . StringMarshaller , new CallOptions ( ) ) ; <nl> asyncCall = new AsyncCall < string , string > ( callDetails , fakeCall ) ; <nl> + fakeBufferReaderManager = new FakeBufferReaderManager ( ) ; <nl> } <nl> <nl> [ TearDown ] <nl> public void Cleanup ( ) <nl> { <nl> channel . ShutdownAsync ( ) . Wait ( ) ; <nl> + fakeBufferReaderManager . Dispose ( ) ; <nl> } <nl> <nl> [ Test ] <nl> public void AsyncUnary_NonSuccessStatusCode ( ) <nl> var resultTask = asyncCall . UnaryCallAsync ( " request1 " ) ; <nl> fakeCall . UnaryResponseClientCallback . OnUnaryResponseClient ( true , <nl> CreateClientSideStatus ( StatusCode . InvalidArgument ) , <nl> - null , <nl> + CreateNullResponse ( ) , <nl> new Metadata ( ) ) ; <nl> <nl> AssertUnaryResponseError ( asyncCall , fakeCall , resultTask , StatusCode . InvalidArgument ) ; <nl> public void ClientStreaming_NoRequest_NonSuccessStatusCode ( ) <nl> var resultTask = asyncCall . ClientStreamingCallAsync ( ) ; <nl> fakeCall . UnaryResponseClientCallback . OnUnaryResponseClient ( true , <nl> CreateClientSideStatus ( StatusCode . InvalidArgument ) , <nl> - null , <nl> + CreateNullResponse ( ) , <nl> new Metadata ( ) ) ; <nl> <nl> AssertUnaryResponseError ( asyncCall , fakeCall , resultTask , StatusCode . InvalidArgument ) ; <nl> public void ClientStreaming_WriteFailureThrowsRpcException ( ) <nl> <nl> fakeCall . UnaryResponseClientCallback . OnUnaryResponseClient ( true , <nl> CreateClientSideStatus ( StatusCode . Internal ) , <nl> - null , <nl> + CreateNullResponse ( ) , <nl> new Metadata ( ) ) ; <nl> <nl> var ex = Assert . ThrowsAsync < RpcException > ( async ( ) = > await writeTask ) ; <nl> public void ClientStreaming_WriteFailureThrowsRpcException2 ( ) <nl> <nl> fakeCall . UnaryResponseClientCallback . OnUnaryResponseClient ( true , <nl> CreateClientSideStatus ( StatusCode . Internal ) , <nl> - null , <nl> + CreateNullResponse ( ) , <nl> new Metadata ( ) ) ; <nl> <nl> fakeCall . SendCompletionCallback . OnSendCompletion ( false ) ; <nl> public void ClientStreaming_WriteFailureThrowsRpcException3 ( ) <nl> <nl> fakeCall . UnaryResponseClientCallback . OnUnaryResponseClient ( true , <nl> CreateClientSideStatus ( StatusCode . Internal ) , <nl> - null , <nl> + CreateNullResponse ( ) , <nl> new Metadata ( ) ) ; <nl> <nl> var ex = Assert . ThrowsAsync < RpcException > ( async ( ) = > await writeTask ) ; <nl> public void ClientStreaming_WriteAfterCancellationRequestThrowsTaskCanceledExcep <nl> <nl> fakeCall . UnaryResponseClientCallback . OnUnaryResponseClient ( true , <nl> CreateClientSideStatus ( StatusCode . Cancelled ) , <nl> - null , <nl> + CreateNullResponse ( ) , <nl> new Metadata ( ) ) ; <nl> <nl> AssertUnaryResponseError ( asyncCall , fakeCall , resultTask , StatusCode . Cancelled ) ; <nl> public void ServerStreaming_NoResponse_Success1 ( ) <nl> fakeCall . ReceivedResponseHeadersCallback . OnReceivedResponseHeaders ( true , new Metadata ( ) ) ; <nl> Assert . AreEqual ( 0 , asyncCall . ResponseHeadersAsync . Result . Count ) ; <nl> <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , CreateNullResponse ( ) ) ; <nl> fakeCall . ReceivedStatusOnClientCallback . OnReceivedStatusOnClient ( true , new ClientSideStatus ( Status . DefaultSuccess , new Metadata ( ) ) ) ; <nl> <nl> AssertStreamingResponseSuccess ( asyncCall , fakeCall , readTask ) ; <nl> public void ServerStreaming_NoResponse_Success2 ( ) <nl> <nl> / / try alternative order of completions <nl> fakeCall . ReceivedStatusOnClientCallback . OnReceivedStatusOnClient ( true , new ClientSideStatus ( Status . DefaultSuccess , new Metadata ( ) ) ) ; <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , CreateNullResponse ( ) ) ; <nl> <nl> AssertStreamingResponseSuccess ( asyncCall , fakeCall , readTask ) ; <nl> } <nl> public void ServerStreaming_NoResponse_ReadFailure ( ) <nl> var responseStream = new ClientResponseStream < string , string > ( asyncCall ) ; <nl> var readTask = responseStream . MoveNext ( ) ; <nl> <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( false , null ) ; / / after a failed read , we rely on C core to deliver appropriate status code . <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( false , CreateNullResponse ( ) ) ; / / after a failed read , we rely on C core to deliver appropriate status code . <nl> fakeCall . ReceivedStatusOnClientCallback . OnReceivedStatusOnClient ( true , CreateClientSideStatus ( StatusCode . Internal ) ) ; <nl> <nl> AssertStreamingResponseError ( asyncCall , fakeCall , readTask , StatusCode . Internal ) ; <nl> public void ServerStreaming_MoreResponses_Success ( ) <nl> <nl> var readTask3 = responseStream . MoveNext ( ) ; <nl> fakeCall . ReceivedStatusOnClientCallback . OnReceivedStatusOnClient ( true , new ClientSideStatus ( Status . DefaultSuccess , new Metadata ( ) ) ) ; <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , CreateNullResponse ( ) ) ; <nl> <nl> AssertStreamingResponseSuccess ( asyncCall , fakeCall , readTask3 ) ; <nl> } <nl> public void DuplexStreaming_NoRequestNoResponse_Success ( ) <nl> Assert . DoesNotThrowAsync ( async ( ) = > await writeTask1 ) ; <nl> <nl> var readTask = responseStream . MoveNext ( ) ; <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , CreateNullResponse ( ) ) ; <nl> fakeCall . ReceivedStatusOnClientCallback . OnReceivedStatusOnClient ( true , new ClientSideStatus ( Status . DefaultSuccess , new Metadata ( ) ) ) ; <nl> <nl> AssertStreamingResponseSuccess ( asyncCall , fakeCall , readTask ) ; <nl> public void DuplexStreaming_WriteAfterReceivingStatusThrowsRpcException ( ) <nl> var responseStream = new ClientResponseStream < string , string > ( asyncCall ) ; <nl> <nl> var readTask = responseStream . MoveNext ( ) ; <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , CreateNullResponse ( ) ) ; <nl> fakeCall . ReceivedStatusOnClientCallback . OnReceivedStatusOnClient ( true , new ClientSideStatus ( Status . DefaultSuccess , new Metadata ( ) ) ) ; <nl> <nl> AssertStreamingResponseSuccess ( asyncCall , fakeCall , readTask ) ; <nl> public void DuplexStreaming_CompleteAfterReceivingStatusSuceeds ( ) <nl> var responseStream = new ClientResponseStream < string , string > ( asyncCall ) ; <nl> <nl> var readTask = responseStream . MoveNext ( ) ; <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , CreateNullResponse ( ) ) ; <nl> fakeCall . ReceivedStatusOnClientCallback . OnReceivedStatusOnClient ( true , new ClientSideStatus ( Status . DefaultSuccess , new Metadata ( ) ) ) ; <nl> <nl> AssertStreamingResponseSuccess ( asyncCall , fakeCall , readTask ) ; <nl> public void DuplexStreaming_WriteFailureThrowsRpcException ( ) <nl> Assert . IsFalse ( writeTask . IsCompleted ) ; <nl> <nl> var readTask = responseStream . MoveNext ( ) ; <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , CreateNullResponse ( ) ) ; <nl> fakeCall . ReceivedStatusOnClientCallback . OnReceivedStatusOnClient ( true , CreateClientSideStatus ( StatusCode . PermissionDenied ) ) ; <nl> <nl> var ex = Assert . ThrowsAsync < RpcException > ( async ( ) = > await writeTask ) ; <nl> public void DuplexStreaming_WriteFailureThrowsRpcException2 ( ) <nl> var writeTask = requestStream . WriteAsync ( " request1 " ) ; <nl> <nl> var readTask = responseStream . MoveNext ( ) ; <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , CreateNullResponse ( ) ) ; <nl> fakeCall . ReceivedStatusOnClientCallback . OnReceivedStatusOnClient ( true , CreateClientSideStatus ( StatusCode . PermissionDenied ) ) ; <nl> fakeCall . SendCompletionCallback . OnSendCompletion ( false ) ; <nl> <nl> public void DuplexStreaming_WriteAfterCancellationRequestThrowsTaskCanceledExcep <nl> Assert . ThrowsAsync ( typeof ( TaskCanceledException ) , async ( ) = > await writeTask ) ; <nl> <nl> var readTask = responseStream . MoveNext ( ) ; <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , CreateNullResponse ( ) ) ; <nl> fakeCall . ReceivedStatusOnClientCallback . OnReceivedStatusOnClient ( true , CreateClientSideStatus ( StatusCode . Cancelled ) ) ; <nl> <nl> AssertStreamingResponseError ( asyncCall , fakeCall , readTask , StatusCode . Cancelled ) ; <nl> public void DuplexStreaming_ReadAfterCancellationRequestCanSucceed ( ) <nl> Assert . AreEqual ( " response1 " , responseStream . Current ) ; <nl> <nl> var readTask2 = responseStream . MoveNext ( ) ; <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , CreateNullResponse ( ) ) ; <nl> fakeCall . ReceivedStatusOnClientCallback . OnReceivedStatusOnClient ( true , CreateClientSideStatus ( StatusCode . Cancelled ) ) ; <nl> <nl> AssertStreamingResponseError ( asyncCall , fakeCall , readTask2 , StatusCode . Cancelled ) ; <nl> public void DuplexStreaming_ReadStartedBeforeCancellationRequestCanSucceed ( ) <nl> Assert . AreEqual ( " response1 " , responseStream . Current ) ; <nl> <nl> var readTask2 = responseStream . MoveNext ( ) ; <nl> - fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , null ) ; <nl> + fakeCall . ReceivedMessageCallback . OnReceivedMessage ( true , CreateNullResponse ( ) ) ; <nl> fakeCall . ReceivedStatusOnClientCallback . OnReceivedStatusOnClient ( true , CreateClientSideStatus ( StatusCode . Cancelled ) ) ; <nl> <nl> AssertStreamingResponseError ( asyncCall , fakeCall , readTask2 , StatusCode . Cancelled ) ; <nl> ClientSideStatus CreateClientSideStatus ( StatusCode statusCode ) <nl> return new ClientSideStatus ( new Status ( statusCode , " " ) , new Metadata ( ) ) ; <nl> } <nl> <nl> - byte [ ] CreateResponsePayload ( ) <nl> + IBufferReader CreateResponsePayload ( ) <nl> + { <nl> + return fakeBufferReaderManager . CreateSingleSegmentBufferReader ( Marshallers . StringMarshaller . Serializer ( " response1 " ) ) ; <nl> + } <nl> + <nl> + IBufferReader CreateNullResponse ( ) <nl> { <nl> - return Marshallers . StringMarshaller . Serializer ( " response1 " ) ; <nl> + return fakeBufferReaderManager . CreateNullPayloadBufferReader ( ) ; <nl> } <nl> <nl> static void AssertUnaryResponseSuccess ( AsyncCall < string , string > asyncCall , FakeNativeCall fakeCall , Task < string > resultTask ) <nl> new file mode 100644 <nl> index 00000000000 . . 63baab31624 <nl> mmm / dev / null <nl> ppp b / src / csharp / Grpc . Core . Tests / Internal / DefaultDeserializationContextTest . cs <nl> <nl> + # region Copyright notice and license <nl> + <nl> + / / Copyright 2019 The gRPC Authors <nl> + / / <nl> + / / Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + / / you may not use this file except in compliance with the License . <nl> + / / You may obtain a copy of the License at <nl> + / / <nl> + / / http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + / / <nl> + / / Unless required by applicable law or agreed to in writing , software <nl> + / / distributed under the License is distributed on an " AS IS " BASIS , <nl> + / / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + / / See the License for the specific language governing permissions and <nl> + / / limitations under the License . <nl> + <nl> + # endregion <nl> + <nl> + using System ; <nl> + using System . Collections . Generic ; <nl> + using Grpc . Core ; <nl> + using Grpc . Core . Internal ; <nl> + using Grpc . Core . Utils ; <nl> + using NUnit . Framework ; <nl> + <nl> + using System . Runtime . InteropServices ; <nl> + <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + using System . Buffers ; <nl> + # endif <nl> + <nl> + namespace Grpc . Core . Internal . Tests <nl> + { <nl> + public class DefaultDeserializationContextTest <nl> + { <nl> + FakeBufferReaderManager fakeBufferReaderManager ; <nl> + <nl> + [ SetUp ] <nl> + public void Init ( ) <nl> + { <nl> + fakeBufferReaderManager = new FakeBufferReaderManager ( ) ; <nl> + } <nl> + <nl> + [ TearDown ] <nl> + public void Cleanup ( ) <nl> + { <nl> + fakeBufferReaderManager . Dispose ( ) ; <nl> + } <nl> + <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + [ TestCase ] <nl> + public void PayloadAsReadOnlySequence_ZeroSegmentPayload ( ) <nl> + { <nl> + var context = new DefaultDeserializationContext ( ) ; <nl> + context . Initialize ( fakeBufferReaderManager . CreateMultiSegmentBufferReader ( new List < byte [ ] > { } ) ) ; <nl> + <nl> + Assert . AreEqual ( 0 , context . PayloadLength ) ; <nl> + <nl> + var sequence = context . PayloadAsReadOnlySequence ( ) ; <nl> + <nl> + Assert . AreEqual ( ReadOnlySequence < byte > . Empty , sequence ) ; <nl> + Assert . IsTrue ( sequence . IsEmpty ) ; <nl> + Assert . IsTrue ( sequence . IsSingleSegment ) ; <nl> + } <nl> + <nl> + [ TestCase ( 0 ) ] <nl> + [ TestCase ( 1 ) ] <nl> + [ TestCase ( 10 ) ] <nl> + [ TestCase ( 100 ) ] <nl> + [ TestCase ( 1000 ) ] <nl> + public void PayloadAsReadOnlySequence_SingleSegmentPayload ( int segmentLength ) <nl> + { <nl> + var origBuffer = GetTestBuffer ( segmentLength ) ; <nl> + var context = new DefaultDeserializationContext ( ) ; <nl> + context . Initialize ( fakeBufferReaderManager . CreateSingleSegmentBufferReader ( origBuffer ) ) ; <nl> + <nl> + Assert . AreEqual ( origBuffer . Length , context . PayloadLength ) ; <nl> + <nl> + var sequence = context . PayloadAsReadOnlySequence ( ) ; <nl> + <nl> + Assert . AreEqual ( origBuffer . Length , sequence . Length ) ; <nl> + Assert . AreEqual ( origBuffer . Length , sequence . First . Length ) ; <nl> + Assert . IsTrue ( sequence . IsSingleSegment ) ; <nl> + CollectionAssert . AreEqual ( origBuffer , sequence . First . ToArray ( ) ) ; <nl> + } <nl> + <nl> + [ TestCase ( 0 , 5 , 10 ) ] <nl> + [ TestCase ( 1 , 1 , 1 ) ] <nl> + [ TestCase ( 10 , 100 , 1000 ) ] <nl> + [ TestCase ( 100 , 100 , 10 ) ] <nl> + [ TestCase ( 1000 , 1000 , 1000 ) ] <nl> + public void PayloadAsReadOnlySequence_MultiSegmentPayload ( int segmentLen1 , int segmentLen2 , int segmentLen3 ) <nl> + { <nl> + var origBuffer1 = GetTestBuffer ( segmentLen1 ) ; <nl> + var origBuffer2 = GetTestBuffer ( segmentLen2 ) ; <nl> + var origBuffer3 = GetTestBuffer ( segmentLen3 ) ; <nl> + int totalLen = origBuffer1 . Length + origBuffer2 . Length + origBuffer3 . Length ; <nl> + <nl> + var context = new DefaultDeserializationContext ( ) ; <nl> + context . Initialize ( fakeBufferReaderManager . CreateMultiSegmentBufferReader ( new List < byte [ ] > { origBuffer1 , origBuffer2 , origBuffer3 } ) ) ; <nl> + <nl> + Assert . AreEqual ( totalLen , context . PayloadLength ) ; <nl> + <nl> + var sequence = context . PayloadAsReadOnlySequence ( ) ; <nl> + <nl> + Assert . AreEqual ( totalLen , sequence . Length ) ; <nl> + <nl> + var segmentEnumerator = sequence . GetEnumerator ( ) ; <nl> + <nl> + Assert . IsTrue ( segmentEnumerator . MoveNext ( ) ) ; <nl> + CollectionAssert . AreEqual ( origBuffer1 , segmentEnumerator . Current . ToArray ( ) ) ; <nl> + <nl> + Assert . IsTrue ( segmentEnumerator . MoveNext ( ) ) ; <nl> + CollectionAssert . AreEqual ( origBuffer2 , segmentEnumerator . Current . ToArray ( ) ) ; <nl> + <nl> + Assert . IsTrue ( segmentEnumerator . MoveNext ( ) ) ; <nl> + CollectionAssert . AreEqual ( origBuffer3 , segmentEnumerator . Current . ToArray ( ) ) ; <nl> + <nl> + Assert . IsFalse ( segmentEnumerator . MoveNext ( ) ) ; <nl> + } <nl> + # endif <nl> + <nl> + [ TestCase ] <nl> + public void NullPayloadNotAllowed ( ) <nl> + { <nl> + var context = new DefaultDeserializationContext ( ) ; <nl> + Assert . Throws ( typeof ( InvalidOperationException ) , ( ) = > context . Initialize ( fakeBufferReaderManager . CreateNullPayloadBufferReader ( ) ) ) ; <nl> + } <nl> + <nl> + [ TestCase ] <nl> + public void PayloadAsNewByteBuffer_ZeroSegmentPayload ( ) <nl> + { <nl> + var context = new DefaultDeserializationContext ( ) ; <nl> + context . Initialize ( fakeBufferReaderManager . CreateMultiSegmentBufferReader ( new List < byte [ ] > { } ) ) ; <nl> + <nl> + Assert . AreEqual ( 0 , context . PayloadLength ) ; <nl> + <nl> + var payload = context . PayloadAsNewBuffer ( ) ; <nl> + Assert . AreEqual ( 0 , payload . Length ) ; <nl> + } <nl> + <nl> + [ TestCase ( 0 ) ] <nl> + [ TestCase ( 1 ) ] <nl> + [ TestCase ( 10 ) ] <nl> + [ TestCase ( 100 ) ] <nl> + [ TestCase ( 1000 ) ] <nl> + public void PayloadAsNewByteBuffer_SingleSegmentPayload ( int segmentLength ) <nl> + { <nl> + var origBuffer = GetTestBuffer ( segmentLength ) ; <nl> + var context = new DefaultDeserializationContext ( ) ; <nl> + context . Initialize ( fakeBufferReaderManager . CreateSingleSegmentBufferReader ( origBuffer ) ) ; <nl> + <nl> + Assert . AreEqual ( origBuffer . Length , context . PayloadLength ) ; <nl> + <nl> + var payload = context . PayloadAsNewBuffer ( ) ; <nl> + CollectionAssert . AreEqual ( origBuffer , payload ) ; <nl> + } <nl> + <nl> + [ TestCase ( 0 , 5 , 10 ) ] <nl> + [ TestCase ( 1 , 1 , 1 ) ] <nl> + [ TestCase ( 10 , 100 , 1000 ) ] <nl> + [ TestCase ( 100 , 100 , 10 ) ] <nl> + [ TestCase ( 1000 , 1000 , 1000 ) ] <nl> + public void PayloadAsNewByteBuffer_MultiSegmentPayload ( int segmentLen1 , int segmentLen2 , int segmentLen3 ) <nl> + { <nl> + var origBuffer1 = GetTestBuffer ( segmentLen1 ) ; <nl> + var origBuffer2 = GetTestBuffer ( segmentLen2 ) ; <nl> + var origBuffer3 = GetTestBuffer ( segmentLen3 ) ; <nl> + <nl> + var context = new DefaultDeserializationContext ( ) ; <nl> + context . Initialize ( fakeBufferReaderManager . CreateMultiSegmentBufferReader ( new List < byte [ ] > { origBuffer1 , origBuffer2 , origBuffer3 } ) ) ; <nl> + <nl> + var payload = context . PayloadAsNewBuffer ( ) ; <nl> + <nl> + var concatenatedOrigBuffers = new List < byte > ( ) ; <nl> + concatenatedOrigBuffers . AddRange ( origBuffer1 ) ; <nl> + concatenatedOrigBuffers . AddRange ( origBuffer2 ) ; <nl> + concatenatedOrigBuffers . AddRange ( origBuffer3 ) ; <nl> + <nl> + Assert . AreEqual ( concatenatedOrigBuffers . Count , context . PayloadLength ) ; <nl> + Assert . AreEqual ( concatenatedOrigBuffers . Count , payload . Length ) ; <nl> + CollectionAssert . AreEqual ( concatenatedOrigBuffers , payload ) ; <nl> + } <nl> + <nl> + [ TestCase ] <nl> + public void GetPayloadMultipleTimesIsIllegal ( ) <nl> + { <nl> + var origBuffer = GetTestBuffer ( 100 ) ; <nl> + var context = new DefaultDeserializationContext ( ) ; <nl> + context . Initialize ( fakeBufferReaderManager . CreateSingleSegmentBufferReader ( origBuffer ) ) ; <nl> + <nl> + Assert . AreEqual ( origBuffer . Length , context . PayloadLength ) ; <nl> + <nl> + var payload = context . PayloadAsNewBuffer ( ) ; <nl> + CollectionAssert . AreEqual ( origBuffer , payload ) ; <nl> + <nl> + / / Getting payload multiple times is illegal <nl> + Assert . Throws ( typeof ( InvalidOperationException ) , ( ) = > context . PayloadAsNewBuffer ( ) ) ; <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + Assert . Throws ( typeof ( InvalidOperationException ) , ( ) = > context . PayloadAsReadOnlySequence ( ) ) ; <nl> + # endif <nl> + } <nl> + <nl> + [ TestCase ] <nl> + public void ResetContextAndReinitialize ( ) <nl> + { <nl> + var origBuffer = GetTestBuffer ( 100 ) ; <nl> + var context = new DefaultDeserializationContext ( ) ; <nl> + context . Initialize ( fakeBufferReaderManager . CreateSingleSegmentBufferReader ( origBuffer ) ) ; <nl> + <nl> + Assert . AreEqual ( origBuffer . Length , context . PayloadLength ) ; <nl> + <nl> + / / Reset invalidates context <nl> + context . Reset ( ) ; <nl> + <nl> + Assert . AreEqual ( 0 , context . PayloadLength ) ; <nl> + Assert . Throws ( typeof ( NullReferenceException ) , ( ) = > context . PayloadAsNewBuffer ( ) ) ; <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + Assert . Throws ( typeof ( NullReferenceException ) , ( ) = > context . PayloadAsReadOnlySequence ( ) ) ; <nl> + # endif <nl> + <nl> + / / Previously reset context can be initialized again <nl> + var origBuffer2 = GetTestBuffer ( 50 ) ; <nl> + context . Initialize ( fakeBufferReaderManager . CreateSingleSegmentBufferReader ( origBuffer2 ) ) ; <nl> + <nl> + Assert . AreEqual ( origBuffer2 . Length , context . PayloadLength ) ; <nl> + CollectionAssert . AreEqual ( origBuffer2 , context . PayloadAsNewBuffer ( ) ) ; <nl> + } <nl> + <nl> + private byte [ ] GetTestBuffer ( int length ) <nl> + { <nl> + var testBuffer = new byte [ length ] ; <nl> + for ( int i = 0 ; i < testBuffer . Length ; i + + ) <nl> + { <nl> + testBuffer [ i ] = ( byte ) i ; <nl> + } <nl> + return testBuffer ; <nl> + } <nl> + } <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . d8d0c0a6354 <nl> mmm / dev / null <nl> ppp b / src / csharp / Grpc . Core . Tests / Internal / FakeBufferReaderManager . cs <nl> <nl> + # region Copyright notice and license <nl> + <nl> + / / Copyright 2018 The gRPC Authors <nl> + / / <nl> + / / Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + / / you may not use this file except in compliance with the License . <nl> + / / You may obtain a copy of the License at <nl> + / / <nl> + / / http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + / / <nl> + / / Unless required by applicable law or agreed to in writing , software <nl> + / / distributed under the License is distributed on an " AS IS " BASIS , <nl> + / / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + / / See the License for the specific language governing permissions and <nl> + / / limitations under the License . <nl> + <nl> + # endregion <nl> + <nl> + using System ; <nl> + using System . Collections . Generic ; <nl> + using System . Runtime . InteropServices ; <nl> + using System . Threading . Tasks ; <nl> + <nl> + using Grpc . Core . Internal ; <nl> + using Grpc . Core . Utils ; <nl> + <nl> + namespace Grpc . Core . Internal . Tests <nl> + { <nl> + / / Creates instances of fake IBufferReader . All created instances will become invalid once Dispose is called . <nl> + internal class FakeBufferReaderManager : IDisposable <nl> + { <nl> + List < GCHandle > pinnedHandles = new List < GCHandle > ( ) ; <nl> + bool disposed = false ; <nl> + public IBufferReader CreateSingleSegmentBufferReader ( byte [ ] data ) <nl> + { <nl> + return CreateMultiSegmentBufferReader ( new List < byte [ ] > { data } ) ; <nl> + } <nl> + <nl> + public IBufferReader CreateMultiSegmentBufferReader ( IEnumerable < byte [ ] > dataSegments ) <nl> + { <nl> + GrpcPreconditions . CheckState ( ! disposed ) ; <nl> + GrpcPreconditions . CheckNotNull ( dataSegments ) ; <nl> + var segments = new List < GCHandle > ( ) ; <nl> + foreach ( var data in dataSegments ) <nl> + { <nl> + GrpcPreconditions . CheckNotNull ( data ) ; <nl> + segments . Add ( GCHandle . Alloc ( data , GCHandleType . Pinned ) ) ; <nl> + } <nl> + pinnedHandles . AddRange ( segments ) ; / / all the allocated GCHandles will be freed on Dispose ( ) <nl> + return new FakeBufferReader ( segments ) ; <nl> + } <nl> + <nl> + public IBufferReader CreateNullPayloadBufferReader ( ) <nl> + { <nl> + GrpcPreconditions . CheckState ( ! disposed ) ; <nl> + return new FakeBufferReader ( null ) ; <nl> + } <nl> + <nl> + public void Dispose ( ) <nl> + { <nl> + if ( ! disposed ) <nl> + { <nl> + disposed = true ; <nl> + for ( int i = 0 ; i < pinnedHandles . Count ; i + + ) <nl> + { <nl> + pinnedHandles [ i ] . Free ( ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + private class FakeBufferReader : IBufferReader <nl> + { <nl> + readonly List < GCHandle > bufferSegments ; <nl> + readonly int ? totalLength ; <nl> + readonly IEnumerator < GCHandle > segmentEnumerator ; <nl> + <nl> + public FakeBufferReader ( List < GCHandle > bufferSegments ) <nl> + { <nl> + this . bufferSegments = bufferSegments ; <nl> + this . totalLength = ComputeTotalLength ( bufferSegments ) ; <nl> + this . segmentEnumerator = bufferSegments ? . GetEnumerator ( ) ; <nl> + } <nl> + <nl> + public int ? TotalLength = > totalLength ; <nl> + <nl> + public bool TryGetNextSlice ( out Slice slice ) <nl> + { <nl> + GrpcPreconditions . CheckNotNull ( bufferSegments ) ; <nl> + if ( ! segmentEnumerator . MoveNext ( ) ) <nl> + { <nl> + slice = default ( Slice ) ; <nl> + return false ; <nl> + } <nl> + <nl> + var segment = segmentEnumerator . Current ; <nl> + int sliceLen = ( ( byte [ ] ) segment . Target ) . Length ; <nl> + slice = new Slice ( segment . AddrOfPinnedObject ( ) , sliceLen ) ; <nl> + return true ; <nl> + } <nl> + <nl> + static int ? ComputeTotalLength ( List < GCHandle > bufferSegments ) <nl> + { <nl> + if ( bufferSegments = = null ) <nl> + { <nl> + return null ; <nl> + } <nl> + <nl> + int sum = 0 ; <nl> + foreach ( var segment in bufferSegments ) <nl> + { <nl> + var data = ( byte [ ] ) segment . Target ; <nl> + sum + = data . Length ; <nl> + } <nl> + return sum ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . 7c4ff652bd3 <nl> mmm / dev / null <nl> ppp b / src / csharp / Grpc . Core . Tests / Internal / FakeBufferReaderManagerTest . cs <nl> <nl> + # region Copyright notice and license <nl> + <nl> + / / Copyright 2018 The gRPC Authors <nl> + / / <nl> + / / Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + / / you may not use this file except in compliance with the License . <nl> + / / You may obtain a copy of the License at <nl> + / / <nl> + / / http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + / / <nl> + / / Unless required by applicable law or agreed to in writing , software <nl> + / / distributed under the License is distributed on an " AS IS " BASIS , <nl> + / / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + / / See the License for the specific language governing permissions and <nl> + / / limitations under the License . <nl> + <nl> + # endregion <nl> + <nl> + using System ; <nl> + using System . Collections . Generic ; <nl> + using Grpc . Core ; <nl> + using Grpc . Core . Internal ; <nl> + using Grpc . Core . Utils ; <nl> + using NUnit . Framework ; <nl> + <nl> + namespace Grpc . Core . Internal . Tests <nl> + { <nl> + public class FakeBufferReaderManagerTest <nl> + { <nl> + FakeBufferReaderManager fakeBufferReaderManager ; <nl> + <nl> + [ SetUp ] <nl> + public void Init ( ) <nl> + { <nl> + fakeBufferReaderManager = new FakeBufferReaderManager ( ) ; <nl> + } <nl> + <nl> + [ TearDown ] <nl> + public void Cleanup ( ) <nl> + { <nl> + fakeBufferReaderManager . Dispose ( ) ; <nl> + } <nl> + <nl> + [ TestCase ] <nl> + public void NullPayload ( ) <nl> + { <nl> + var fakeBufferReader = fakeBufferReaderManager . CreateNullPayloadBufferReader ( ) ; <nl> + Assert . IsFalse ( fakeBufferReader . TotalLength . HasValue ) ; <nl> + Assert . Throws ( typeof ( ArgumentNullException ) , ( ) = > fakeBufferReader . TryGetNextSlice ( out Slice slice ) ) ; <nl> + } <nl> + [ TestCase ] <nl> + public void ZeroSegmentPayload ( ) <nl> + { <nl> + var fakeBufferReader = fakeBufferReaderManager . CreateMultiSegmentBufferReader ( new List < byte [ ] > { } ) ; <nl> + Assert . AreEqual ( 0 , fakeBufferReader . TotalLength . Value ) ; <nl> + Assert . IsFalse ( fakeBufferReader . TryGetNextSlice ( out Slice slice ) ) ; <nl> + } <nl> + <nl> + [ TestCase ( 0 ) ] <nl> + [ TestCase ( 1 ) ] <nl> + [ TestCase ( 10 ) ] <nl> + [ TestCase ( 30 ) ] <nl> + [ TestCase ( 100 ) ] <nl> + [ TestCase ( 1000 ) ] <nl> + public void SingleSegmentPayload ( int bufferLen ) <nl> + { <nl> + var origBuffer = GetTestBuffer ( bufferLen ) ; <nl> + var fakeBufferReader = fakeBufferReaderManager . CreateSingleSegmentBufferReader ( origBuffer ) ; <nl> + Assert . AreEqual ( origBuffer . Length , fakeBufferReader . TotalLength . Value ) ; <nl> + <nl> + Assert . IsTrue ( fakeBufferReader . TryGetNextSlice ( out Slice slice ) ) ; <nl> + AssertSliceDataEqual ( origBuffer , slice ) ; <nl> + <nl> + Assert . IsFalse ( fakeBufferReader . TryGetNextSlice ( out Slice slice2 ) ) ; <nl> + } <nl> + <nl> + [ TestCase ( 0 , 5 , 10 ) ] <nl> + [ TestCase ( 1 , 1 , 1 ) ] <nl> + [ TestCase ( 10 , 100 , 1000 ) ] <nl> + [ TestCase ( 100 , 100 , 10 ) ] <nl> + [ TestCase ( 1000 , 1000 , 1000 ) ] <nl> + public void MultiSegmentPayload ( int segmentLen1 , int segmentLen2 , int segmentLen3 ) <nl> + { <nl> + var origBuffer1 = GetTestBuffer ( segmentLen1 ) ; <nl> + var origBuffer2 = GetTestBuffer ( segmentLen2 ) ; <nl> + var origBuffer3 = GetTestBuffer ( segmentLen3 ) ; <nl> + var fakeBufferReader = fakeBufferReaderManager . CreateMultiSegmentBufferReader ( new List < byte [ ] > { origBuffer1 , origBuffer2 , origBuffer3 } ) ; <nl> + <nl> + Assert . AreEqual ( origBuffer1 . Length + origBuffer2 . Length + origBuffer3 . Length , fakeBufferReader . TotalLength . Value ) ; <nl> + <nl> + Assert . IsTrue ( fakeBufferReader . TryGetNextSlice ( out Slice slice1 ) ) ; <nl> + AssertSliceDataEqual ( origBuffer1 , slice1 ) ; <nl> + <nl> + Assert . IsTrue ( fakeBufferReader . TryGetNextSlice ( out Slice slice2 ) ) ; <nl> + AssertSliceDataEqual ( origBuffer2 , slice2 ) ; <nl> + <nl> + Assert . IsTrue ( fakeBufferReader . TryGetNextSlice ( out Slice slice3 ) ) ; <nl> + AssertSliceDataEqual ( origBuffer3 , slice3 ) ; <nl> + <nl> + Assert . IsFalse ( fakeBufferReader . TryGetNextSlice ( out Slice slice4 ) ) ; <nl> + } <nl> + <nl> + private void AssertSliceDataEqual ( byte [ ] expected , Slice actual ) <nl> + { <nl> + var actualSliceData = new byte [ actual . Length ] ; <nl> + actual . CopyTo ( new ArraySegment < byte > ( actualSliceData ) ) ; <nl> + CollectionAssert . AreEqual ( expected , actualSliceData ) ; <nl> + } <nl> + <nl> + / / create a buffer of given size and fill it with some data <nl> + private byte [ ] GetTestBuffer ( int length ) <nl> + { <nl> + var testBuffer = new byte [ length ] ; <nl> + for ( int i = 0 ; i < testBuffer . Length ; i + + ) <nl> + { <nl> + testBuffer [ i ] = ( byte ) i ; <nl> + } <nl> + return testBuffer ; <nl> + } <nl> + } <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . 7630785aef4 <nl> mmm / dev / null <nl> ppp b / src / csharp / Grpc . Core . Tests / Internal / ReusableSliceBufferTest . cs <nl> <nl> + # region Copyright notice and license <nl> + <nl> + / / Copyright 2018 The gRPC Authors <nl> + / / <nl> + / / Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + / / you may not use this file except in compliance with the License . <nl> + / / You may obtain a copy of the License at <nl> + / / <nl> + / / http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + / / <nl> + / / Unless required by applicable law or agreed to in writing , software <nl> + / / distributed under the License is distributed on an " AS IS " BASIS , <nl> + / / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + / / See the License for the specific language governing permissions and <nl> + / / limitations under the License . <nl> + <nl> + # endregion <nl> + <nl> + using System ; <nl> + using System . Collections . Generic ; <nl> + using System . Linq ; <nl> + using Grpc . Core ; <nl> + using Grpc . Core . Internal ; <nl> + using Grpc . Core . Utils ; <nl> + using NUnit . Framework ; <nl> + <nl> + using System . Runtime . InteropServices ; <nl> + <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + using System . Buffers ; <nl> + # endif <nl> + <nl> + namespace Grpc . Core . Internal . Tests <nl> + { <nl> + / / Converts IBufferReader into instances of ReadOnlySequence < byte > <nl> + / / Objects representing the sequence segments are cached to decrease GC load . <nl> + public class ReusableSliceBufferTest <nl> + { <nl> + FakeBufferReaderManager fakeBufferReaderManager ; <nl> + <nl> + [ SetUp ] <nl> + public void Init ( ) <nl> + { <nl> + fakeBufferReaderManager = new FakeBufferReaderManager ( ) ; <nl> + } <nl> + <nl> + [ TearDown ] <nl> + public void Cleanup ( ) <nl> + { <nl> + fakeBufferReaderManager . Dispose ( ) ; <nl> + } <nl> + <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + [ TestCase ] <nl> + public void NullPayload ( ) <nl> + { <nl> + var sliceBuffer = new ReusableSliceBuffer ( ) ; <nl> + Assert . Throws ( typeof ( ArgumentNullException ) , ( ) = > sliceBuffer . PopulateFrom ( fakeBufferReaderManager . CreateNullPayloadBufferReader ( ) ) ) ; <nl> + } <nl> + <nl> + [ TestCase ] <nl> + public void ZeroSegmentPayload ( ) <nl> + { <nl> + var sliceBuffer = new ReusableSliceBuffer ( ) ; <nl> + var sequence = sliceBuffer . PopulateFrom ( fakeBufferReaderManager . CreateMultiSegmentBufferReader ( new List < byte [ ] > { } ) ) ; <nl> + <nl> + Assert . AreEqual ( ReadOnlySequence < byte > . Empty , sequence ) ; <nl> + Assert . IsTrue ( sequence . IsEmpty ) ; <nl> + Assert . IsTrue ( sequence . IsSingleSegment ) ; <nl> + } <nl> + <nl> + [ TestCase ] <nl> + public void SegmentsAreCached ( ) <nl> + { <nl> + var bufferSegments1 = Enumerable . Range ( 0 , 100 ) . Select ( ( _ ) = > GetTestBuffer ( 50 ) ) . ToList ( ) ; <nl> + var bufferSegments2 = Enumerable . Range ( 0 , 100 ) . Select ( ( _ ) = > GetTestBuffer ( 50 ) ) . ToList ( ) ; <nl> + <nl> + var sliceBuffer = new ReusableSliceBuffer ( ) ; <nl> + <nl> + var sequence1 = sliceBuffer . PopulateFrom ( fakeBufferReaderManager . CreateMultiSegmentBufferReader ( bufferSegments1 ) ) ; <nl> + var memoryManagers1 = GetMemoryManagersForSequenceSegments ( sequence1 ) ; <nl> + <nl> + sliceBuffer . Invalidate ( ) ; <nl> + <nl> + var sequence2 = sliceBuffer . PopulateFrom ( fakeBufferReaderManager . CreateMultiSegmentBufferReader ( bufferSegments2 ) ) ; <nl> + var memoryManagers2 = GetMemoryManagersForSequenceSegments ( sequence2 ) ; <nl> + <nl> + / / check memory managers are identical objects ( i . e . they ' ve been reused ) <nl> + CollectionAssert . AreEquivalent ( memoryManagers1 , memoryManagers2 ) ; <nl> + } <nl> + <nl> + [ TestCase ] <nl> + public void MultiSegmentPayload_LotsOfSegments ( ) <nl> + { <nl> + var bufferSegments = Enumerable . Range ( 0 , ReusableSliceBuffer . MaxCachedSegments + 100 ) . Select ( ( _ ) = > GetTestBuffer ( 10 ) ) . ToList ( ) ; <nl> + <nl> + var sliceBuffer = new ReusableSliceBuffer ( ) ; <nl> + var sequence = sliceBuffer . PopulateFrom ( fakeBufferReaderManager . CreateMultiSegmentBufferReader ( bufferSegments ) ) ; <nl> + <nl> + int index = 0 ; <nl> + foreach ( var memory in sequence ) <nl> + { <nl> + CollectionAssert . AreEqual ( bufferSegments [ index ] , memory . ToArray ( ) ) ; <nl> + index + + ; <nl> + } <nl> + } <nl> + <nl> + [ TestCase ] <nl> + public void InvalidateMakesSequenceUnusable ( ) <nl> + { <nl> + var origBuffer = GetTestBuffer ( 100 ) ; <nl> + <nl> + var sliceBuffer = new ReusableSliceBuffer ( ) ; <nl> + var sequence = sliceBuffer . PopulateFrom ( fakeBufferReaderManager . CreateMultiSegmentBufferReader ( new List < byte [ ] > { origBuffer } ) ) ; <nl> + <nl> + Assert . AreEqual ( origBuffer . Length , sequence . Length ) ; <nl> + <nl> + sliceBuffer . Invalidate ( ) ; <nl> + <nl> + / / Invalidate with make the returned sequence completely unusable and broken , users must not use it beyond the deserializer functions . <nl> + Assert . Throws ( typeof ( ArgumentOutOfRangeException ) , ( ) = > { var first = sequence . First ; } ) ; <nl> + } <nl> + <nl> + private List < MemoryManager < byte > > GetMemoryManagersForSequenceSegments ( ReadOnlySequence < byte > sequence ) <nl> + { <nl> + var result = new List < MemoryManager < byte > > ( ) ; <nl> + foreach ( var memory in sequence ) <nl> + { <nl> + Assert . IsTrue ( MemoryMarshal . TryGetMemoryManager ( memory , out MemoryManager < byte > memoryManager ) ) ; <nl> + result . Add ( memoryManager ) ; <nl> + } <nl> + return result ; <nl> + } <nl> + # else <nl> + [ TestCase ] <nl> + public void OnlySupportedOnNetCore ( ) <nl> + { <nl> + / / Test case needs to exist to make C # sanity test happy . <nl> + } <nl> + # endif <nl> + private byte [ ] GetTestBuffer ( int length ) <nl> + { <nl> + var testBuffer = new byte [ length ] ; <nl> + for ( int i = 0 ; i < testBuffer . Length ; i + + ) <nl> + { <nl> + testBuffer [ i ] = ( byte ) i ; <nl> + } <nl> + return testBuffer ; <nl> + } <nl> + } <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . eb090bbfa50 <nl> mmm / dev / null <nl> ppp b / src / csharp / Grpc . Core . Tests / Internal / SliceTest . cs <nl> <nl> + # region Copyright notice and license <nl> + <nl> + / / Copyright 2018 The gRPC Authors <nl> + / / <nl> + / / Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + / / you may not use this file except in compliance with the License . <nl> + / / You may obtain a copy of the License at <nl> + / / <nl> + / / http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + / / <nl> + / / Unless required by applicable law or agreed to in writing , software <nl> + / / distributed under the License is distributed on an " AS IS " BASIS , <nl> + / / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + / / See the License for the specific language governing permissions and <nl> + / / limitations under the License . <nl> + <nl> + # endregion <nl> + <nl> + using System ; <nl> + using Grpc . Core ; <nl> + using Grpc . Core . Internal ; <nl> + using Grpc . Core . Utils ; <nl> + using NUnit . Framework ; <nl> + <nl> + using System . Runtime . InteropServices ; <nl> + <nl> + namespace Grpc . Core . Internal . Tests <nl> + { <nl> + public class SliceTest <nl> + { <nl> + [ TestCase ( 0 ) ] <nl> + [ TestCase ( 1 ) ] <nl> + [ TestCase ( 10 ) ] <nl> + [ TestCase ( 100 ) ] <nl> + [ TestCase ( 1000 ) ] <nl> + public void SliceFromNativePtr_CopyToArraySegment ( int bufferLength ) <nl> + { <nl> + var origBuffer = GetTestBuffer ( bufferLength ) ; <nl> + var gcHandle = GCHandle . Alloc ( origBuffer , GCHandleType . Pinned ) ; <nl> + try <nl> + { <nl> + var slice = new Slice ( gcHandle . AddrOfPinnedObject ( ) , origBuffer . Length ) ; <nl> + Assert . AreEqual ( bufferLength , slice . Length ) ; <nl> + <nl> + var newBuffer = new byte [ bufferLength ] ; <nl> + slice . CopyTo ( new ArraySegment < byte > ( newBuffer ) ) ; <nl> + CollectionAssert . AreEqual ( origBuffer , newBuffer ) ; <nl> + } <nl> + finally <nl> + { <nl> + gcHandle . Free ( ) ; <nl> + } <nl> + } <nl> + <nl> + [ TestCase ] <nl> + public void SliceFromNativePtr_CopyToArraySegmentTooSmall ( ) <nl> + { <nl> + var origBuffer = GetTestBuffer ( 100 ) ; <nl> + var gcHandle = GCHandle . Alloc ( origBuffer , GCHandleType . Pinned ) ; <nl> + try <nl> + { <nl> + var slice = new Slice ( gcHandle . AddrOfPinnedObject ( ) , origBuffer . Length ) ; <nl> + var tooSmall = new byte [ origBuffer . Length - 1 ] ; <nl> + Assert . Catch ( typeof ( ArgumentException ) , ( ) = > slice . CopyTo ( new ArraySegment < byte > ( tooSmall ) ) ) ; <nl> + } <nl> + finally <nl> + { <nl> + gcHandle . Free ( ) ; <nl> + } <nl> + } <nl> + <nl> + / / create a buffer of given size and fill it with some data <nl> + private byte [ ] GetTestBuffer ( int length ) <nl> + { <nl> + var testBuffer = new byte [ length ] ; <nl> + for ( int i = 0 ; i < testBuffer . Length ; i + + ) <nl> + { <nl> + testBuffer [ i ] = ( byte ) i ; <nl> + } <nl> + return testBuffer ; <nl> + } <nl> + } <nl> + } <nl> mmm a / src / csharp / Grpc . Core / Grpc . Core . csproj <nl> ppp b / src / csharp / Grpc . Core / Grpc . Core . csproj <nl> <nl> < TreatWarningsAsErrors > true < / TreatWarningsAsErrors > <nl> < / PropertyGroup > <nl> <nl> + < PropertyGroup > <nl> + < AllowUnsafeBlocks > true < / AllowUnsafeBlocks > <nl> + < / PropertyGroup > <nl> + <nl> + < PropertyGroup Condition = " ' $ ( TargetFramework ) ' = = ' netstandard2 . 0 ' " > <nl> + < LangVersion > 7 . 2 < / LangVersion > <nl> + < DefineConstants > $ ( DefineConstants ) ; GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY < / DefineConstants > <nl> + < / PropertyGroup > <nl> + <nl> < ItemGroup > <nl> < Compile Include = " . . \ Grpc . Core . Api \ Version . cs " / > <nl> < / ItemGroup > <nl> mmm a / src / csharp / Grpc . Core / Internal / AsyncCall . cs <nl> ppp b / src / csharp / Grpc . Core / Internal / AsyncCall . cs <nl> public TResponse UnaryCall ( TRequest msg ) <nl> { <nl> using ( profiler . NewScope ( " AsyncCall . UnaryCall . HandleBatch " ) ) <nl> { <nl> - HandleUnaryResponse ( success , ctx . GetReceivedStatusOnClient ( ) , ctx . GetReceivedMessage ( ) , ctx . GetReceivedInitialMetadata ( ) ) ; <nl> + HandleUnaryResponse ( success , ctx . GetReceivedStatusOnClient ( ) , ctx . GetReceivedMessageReader ( ) , ctx . GetReceivedInitialMetadata ( ) ) ; <nl> } <nl> } <nl> catch ( Exception e ) <nl> private void HandleReceivedResponseHeaders ( bool success , Metadata responseHeader <nl> / / / < summary > <nl> / / / Handler for unary response completion . <nl> / / / < / summary > <nl> - private void HandleUnaryResponse ( bool success , ClientSideStatus receivedStatus , byte [ ] receivedMessage , Metadata responseHeaders ) <nl> + private void HandleUnaryResponse ( bool success , ClientSideStatus receivedStatus , IBufferReader receivedMessageReader , Metadata responseHeaders ) <nl> { <nl> / / NOTE : because this event is a result of batch containing GRPC_OP_RECV_STATUS_ON_CLIENT , <nl> / / success will be always set to true . <nl> <nl> TaskCompletionSource < object > delayedStreamingWriteTcs = null ; <nl> TResponse msg = default ( TResponse ) ; <nl> - var deserializeException = TryDeserialize ( receivedMessage , out msg ) ; <nl> + var deserializeException = TryDeserialize ( receivedMessageReader , out msg ) ; <nl> <nl> bool releasedResources ; <nl> lock ( myLock ) <nl> private void HandleFinished ( bool success , ClientSideStatus receivedStatus ) <nl> <nl> IUnaryResponseClientCallback UnaryResponseClientCallback = > this ; <nl> <nl> - void IUnaryResponseClientCallback . OnUnaryResponseClient ( bool success , ClientSideStatus receivedStatus , byte [ ] receivedMessage , Metadata responseHeaders ) <nl> + void IUnaryResponseClientCallback . OnUnaryResponseClient ( bool success , ClientSideStatus receivedStatus , IBufferReader receivedMessageReader , Metadata responseHeaders ) <nl> { <nl> - HandleUnaryResponse ( success , receivedStatus , receivedMessage , responseHeaders ) ; <nl> + HandleUnaryResponse ( success , receivedStatus , receivedMessageReader , responseHeaders ) ; <nl> } <nl> <nl> IReceivedStatusOnClientCallback ReceivedStatusOnClientCallback = > this ; <nl> mmm a / src / csharp / Grpc . Core / Internal / AsyncCallBase . cs <nl> ppp b / src / csharp / Grpc . Core / Internal / AsyncCallBase . cs <nl> protected byte [ ] UnsafeSerialize ( TWrite msg ) <nl> } <nl> } <nl> <nl> - protected Exception TryDeserialize ( byte [ ] payload , out TRead msg ) <nl> + protected Exception TryDeserialize ( IBufferReader reader , out TRead msg ) <nl> { <nl> DefaultDeserializationContext context = null ; <nl> try <nl> { <nl> - context = DefaultDeserializationContext . GetInitializedThreadLocal ( payload ) ; <nl> + context = DefaultDeserializationContext . GetInitializedThreadLocal ( reader ) ; <nl> msg = deserializer ( context ) ; <nl> return null ; <nl> } <nl> protected Exception TryDeserialize ( byte [ ] payload , out TRead msg ) <nl> finally <nl> { <nl> context ? . Reset ( ) ; <nl> - <nl> } <nl> } <nl> <nl> protected void HandleSendStatusFromServerFinished ( bool success ) <nl> / / / < summary > <nl> / / / Handles streaming read completion . <nl> / / / < / summary > <nl> - protected void HandleReadFinished ( bool success , byte [ ] receivedMessage ) <nl> + protected void HandleReadFinished ( bool success , IBufferReader receivedMessageReader ) <nl> { <nl> - / / if success = = false , received message will be null . It that case we will <nl> + / / if success = = false , the message reader will report null payload . It that case we will <nl> / / treat this completion as the last read an rely on C core to handle the failed <nl> / / read ( e . g . deliver approriate statusCode on the clientside ) . <nl> <nl> TRead msg = default ( TRead ) ; <nl> - var deserializeException = ( success & & receivedMessage ! = null ) ? TryDeserialize ( receivedMessage , out msg ) : null ; <nl> + var deserializeException = ( success & & receivedMessageReader . TotalLength . HasValue ) ? TryDeserialize ( receivedMessageReader , out msg ) : null ; <nl> <nl> TaskCompletionSource < TRead > origTcs = null ; <nl> bool releasedResources ; <nl> lock ( myLock ) <nl> { <nl> origTcs = streamingReadTcs ; <nl> - if ( receivedMessage = = null ) <nl> + if ( ! receivedMessageReader . TotalLength . HasValue ) <nl> { <nl> / / This was the last read . <nl> readingDone = true ; <nl> void ISendCompletionCallback . OnSendCompletion ( bool success ) <nl> <nl> IReceivedMessageCallback ReceivedMessageCallback = > this ; <nl> <nl> - void IReceivedMessageCallback . OnReceivedMessage ( bool success , byte [ ] receivedMessage ) <nl> + void IReceivedMessageCallback . OnReceivedMessage ( bool success , IBufferReader receivedMessageReader ) <nl> { <nl> - HandleReadFinished ( success , receivedMessage ) ; <nl> + HandleReadFinished ( success , receivedMessageReader ) ; <nl> } <nl> } <nl> } <nl> mmm a / src / csharp / Grpc . Core / Internal / BatchContextSafeHandle . cs <nl> ppp b / src / csharp / Grpc . Core / Internal / BatchContextSafeHandle . cs <nl> internal interface IOpCompletionCallback <nl> void OnComplete ( bool success ) ; <nl> } <nl> <nl> + internal interface IBufferReader <nl> + { <nl> + int ? TotalLength { get ; } <nl> + <nl> + bool TryGetNextSlice ( out Slice slice ) ; <nl> + } <nl> + <nl> / / / < summary > <nl> / / / grpcsharp_batch_context <nl> / / / < / summary > <nl> - internal class BatchContextSafeHandle : SafeHandleZeroIsInvalid , IOpCompletionCallback , IPooledObject < BatchContextSafeHandle > <nl> + internal class BatchContextSafeHandle : SafeHandleZeroIsInvalid , IOpCompletionCallback , IPooledObject < BatchContextSafeHandle > , IBufferReader <nl> { <nl> static readonly NativeMethods Native = NativeMethods . Get ( ) ; <nl> static readonly ILogger Logger = GrpcEnvironment . Logger . ForType < BatchContextSafeHandle > ( ) ; <nl> public ClientSideStatus GetReceivedStatusOnClient ( ) <nl> return new ClientSideStatus ( status , metadata ) ; <nl> } <nl> <nl> - / / Gets data of recv_message completion . <nl> - public byte [ ] GetReceivedMessage ( ) <nl> + public IBufferReader GetReceivedMessageReader ( ) <nl> { <nl> - IntPtr len = Native . grpcsharp_batch_context_recv_message_length ( this ) ; <nl> - if ( len = = new IntPtr ( - 1 ) ) <nl> - { <nl> - return null ; <nl> - } <nl> - byte [ ] data = new byte [ ( int ) len ] ; <nl> - Native . grpcsharp_batch_context_recv_message_to_buffer ( this , data , new UIntPtr ( ( ulong ) data . Length ) ) ; <nl> - return data ; <nl> + return this ; <nl> } <nl> <nl> / / Gets data of receive_close_on_server completion . <nl> void IOpCompletionCallback . OnComplete ( bool success ) <nl> } <nl> } <nl> <nl> + int ? IBufferReader . TotalLength <nl> + { <nl> + get <nl> + { <nl> + var len = Native . grpcsharp_batch_context_recv_message_length ( this ) ; <nl> + return len ! = new IntPtr ( - 1 ) ? ( int ? ) len : null ; <nl> + } <nl> + } <nl> + <nl> + bool IBufferReader . TryGetNextSlice ( out Slice slice ) <nl> + { <nl> + UIntPtr sliceLen ; <nl> + IntPtr sliceDataPtr ; <nl> + <nl> + if ( 0 = = Native . grpcsharp_batch_context_recv_message_next_slice_peek ( this , out sliceLen , out sliceDataPtr ) ) <nl> + { <nl> + slice = default ( Slice ) ; <nl> + return false ; <nl> + } <nl> + slice = new Slice ( sliceDataPtr , ( int ) sliceLen ) ; <nl> + return true ; <nl> + } <nl> + <nl> struct CompletionCallbackData <nl> { <nl> public CompletionCallbackData ( BatchCompletionDelegate callback , object state ) <nl> mmm a / src / csharp / Grpc . Core / Internal / CallSafeHandle . cs <nl> ppp b / src / csharp / Grpc . Core / Internal / CallSafeHandle . cs <nl> internal class CallSafeHandle : SafeHandleZeroIsInvalid , INativeCall <nl> / / Completion handlers are pre - allocated to avoid unneccessary delegate allocations . <nl> / / The " state " field is used to store the actual callback to invoke . <nl> static readonly BatchCompletionDelegate CompletionHandler_IUnaryResponseClientCallback = <nl> - ( success , context , state ) = > ( ( IUnaryResponseClientCallback ) state ) . OnUnaryResponseClient ( success , context . GetReceivedStatusOnClient ( ) , context . GetReceivedMessage ( ) , context . GetReceivedInitialMetadata ( ) ) ; <nl> + ( success , context , state ) = > ( ( IUnaryResponseClientCallback ) state ) . OnUnaryResponseClient ( success , context . GetReceivedStatusOnClient ( ) , context . GetReceivedMessageReader ( ) , context . GetReceivedInitialMetadata ( ) ) ; <nl> static readonly BatchCompletionDelegate CompletionHandler_IReceivedStatusOnClientCallback = <nl> ( success , context , state ) = > ( ( IReceivedStatusOnClientCallback ) state ) . OnReceivedStatusOnClient ( success , context . GetReceivedStatusOnClient ( ) ) ; <nl> static readonly BatchCompletionDelegate CompletionHandler_IReceivedMessageCallback = <nl> - ( success , context , state ) = > ( ( IReceivedMessageCallback ) state ) . OnReceivedMessage ( success , context . GetReceivedMessage ( ) ) ; <nl> + ( success , context , state ) = > ( ( IReceivedMessageCallback ) state ) . OnReceivedMessage ( success , context . GetReceivedMessageReader ( ) ) ; <nl> static readonly BatchCompletionDelegate CompletionHandler_IReceivedResponseHeadersCallback = <nl> ( success , context , state ) = > ( ( IReceivedResponseHeadersCallback ) state ) . OnReceivedResponseHeaders ( success , context . GetReceivedInitialMetadata ( ) ) ; <nl> static readonly BatchCompletionDelegate CompletionHandler_ISendCompletionCallback = <nl> mmm a / src / csharp / Grpc . Core / Internal / DefaultDeserializationContext . cs <nl> ppp b / src / csharp / Grpc . Core / Internal / DefaultDeserializationContext . cs <nl> <nl> using System ; <nl> using System . Threading ; <nl> <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + using System . Buffers ; <nl> + # endif <nl> + <nl> namespace Grpc . Core . Internal <nl> { <nl> internal class DefaultDeserializationContext : DeserializationContext <nl> internal class DefaultDeserializationContext : DeserializationContext <nl> static readonly ThreadLocal < DefaultDeserializationContext > threadLocalInstance = <nl> new ThreadLocal < DefaultDeserializationContext > ( ( ) = > new DefaultDeserializationContext ( ) , false ) ; <nl> <nl> - byte [ ] payload ; <nl> - bool alreadyCalledPayloadAsNewBuffer ; <nl> + IBufferReader bufferReader ; <nl> + int payloadLength ; <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + ReusableSliceBuffer cachedSliceBuffer = new ReusableSliceBuffer ( ) ; <nl> + # endif <nl> <nl> public DefaultDeserializationContext ( ) <nl> { <nl> Reset ( ) ; <nl> } <nl> <nl> - public override int PayloadLength = > payload . Length ; <nl> + public override int PayloadLength = > payloadLength ; <nl> <nl> public override byte [ ] PayloadAsNewBuffer ( ) <nl> { <nl> - GrpcPreconditions . CheckState ( ! alreadyCalledPayloadAsNewBuffer ) ; <nl> - alreadyCalledPayloadAsNewBuffer = true ; <nl> - return payload ; <nl> + var buffer = new byte [ payloadLength ] ; <nl> + FillContinguousBuffer ( bufferReader , buffer ) ; <nl> + return buffer ; <nl> + } <nl> + <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + public override ReadOnlySequence < byte > PayloadAsReadOnlySequence ( ) <nl> + { <nl> + var sequence = cachedSliceBuffer . PopulateFrom ( bufferReader ) ; <nl> + GrpcPreconditions . CheckState ( sequence . Length = = payloadLength ) ; <nl> + return sequence ; <nl> } <nl> + # endif <nl> <nl> - public void Initialize ( byte [ ] payload ) <nl> + public void Initialize ( IBufferReader bufferReader ) <nl> { <nl> - this . payload = GrpcPreconditions . CheckNotNull ( payload ) ; <nl> - this . alreadyCalledPayloadAsNewBuffer = false ; <nl> + this . bufferReader = GrpcPreconditions . CheckNotNull ( bufferReader ) ; <nl> + this . payloadLength = bufferReader . TotalLength . Value ; / / payload must not be null <nl> } <nl> <nl> public void Reset ( ) <nl> { <nl> - this . payload = null ; <nl> - this . alreadyCalledPayloadAsNewBuffer = true ; / / mark payload as read <nl> + this . bufferReader = null ; <nl> + this . payloadLength = 0 ; <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + this . cachedSliceBuffer . Invalidate ( ) ; <nl> + # endif <nl> } <nl> <nl> - public static DefaultDeserializationContext GetInitializedThreadLocal ( byte [ ] payload ) <nl> + public static DefaultDeserializationContext GetInitializedThreadLocal ( IBufferReader bufferReader ) <nl> { <nl> var instance = threadLocalInstance . Value ; <nl> - instance . Initialize ( payload ) ; <nl> + instance . Initialize ( bufferReader ) ; <nl> return instance ; <nl> } <nl> + <nl> + private void FillContinguousBuffer ( IBufferReader reader , byte [ ] destination ) <nl> + { <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + PayloadAsReadOnlySequence ( ) . CopyTo ( new Span < byte > ( destination ) ) ; <nl> + # else <nl> + int offset = 0 ; <nl> + while ( reader . TryGetNextSlice ( out Slice slice ) ) <nl> + { <nl> + slice . CopyTo ( new ArraySegment < byte > ( destination , offset , ( int ) slice . Length ) ) ; <nl> + offset + = ( int ) slice . Length ; <nl> + } <nl> + / / check that we filled the entire destination <nl> + GrpcPreconditions . CheckState ( offset = = payloadLength ) ; <nl> + # endif <nl> + } <nl> } <nl> } <nl> mmm a / src / csharp / Grpc . Core / Internal / INativeCall . cs <nl> ppp b / src / csharp / Grpc . Core / Internal / INativeCall . cs <nl> namespace Grpc . Core . Internal <nl> { <nl> internal interface IUnaryResponseClientCallback <nl> { <nl> - void OnUnaryResponseClient ( bool success , ClientSideStatus receivedStatus , byte [ ] receivedMessage , Metadata responseHeaders ) ; <nl> + void OnUnaryResponseClient ( bool success , ClientSideStatus receivedStatus , IBufferReader receivedMessageReader , Metadata responseHeaders ) ; <nl> } <nl> <nl> / / Received status for streaming response calls . <nl> internal interface IReceivedStatusOnClientCallback <nl> <nl> internal interface IReceivedMessageCallback <nl> { <nl> - void OnReceivedMessage ( bool success , byte [ ] receivedMessage ) ; <nl> + void OnReceivedMessage ( bool success , IBufferReader receivedMessageReader ) ; <nl> } <nl> <nl> internal interface IReceivedResponseHeadersCallback <nl> mmm a / src / csharp / Grpc . Core / Internal / NativeMethods . Generated . cs <nl> ppp b / src / csharp / Grpc . Core / Internal / NativeMethods . Generated . cs <nl> internal partial class NativeMethods <nl> public readonly Delegates . grpcsharp_batch_context_create_delegate grpcsharp_batch_context_create ; <nl> public readonly Delegates . grpcsharp_batch_context_recv_initial_metadata_delegate grpcsharp_batch_context_recv_initial_metadata ; <nl> public readonly Delegates . grpcsharp_batch_context_recv_message_length_delegate grpcsharp_batch_context_recv_message_length ; <nl> - public readonly Delegates . grpcsharp_batch_context_recv_message_to_buffer_delegate grpcsharp_batch_context_recv_message_to_buffer ; <nl> + public readonly Delegates . grpcsharp_batch_context_recv_message_next_slice_peek_delegate grpcsharp_batch_context_recv_message_next_slice_peek ; <nl> public readonly Delegates . grpcsharp_batch_context_recv_status_on_client_status_delegate grpcsharp_batch_context_recv_status_on_client_status ; <nl> public readonly Delegates . grpcsharp_batch_context_recv_status_on_client_details_delegate grpcsharp_batch_context_recv_status_on_client_details ; <nl> public readonly Delegates . grpcsharp_batch_context_recv_status_on_client_trailing_metadata_delegate grpcsharp_batch_context_recv_status_on_client_trailing_metadata ; <nl> public NativeMethods ( UnmanagedLibrary library ) <nl> this . grpcsharp_batch_context_create = GetMethodDelegate < Delegates . grpcsharp_batch_context_create_delegate > ( library ) ; <nl> this . grpcsharp_batch_context_recv_initial_metadata = GetMethodDelegate < Delegates . grpcsharp_batch_context_recv_initial_metadata_delegate > ( library ) ; <nl> this . grpcsharp_batch_context_recv_message_length = GetMethodDelegate < Delegates . grpcsharp_batch_context_recv_message_length_delegate > ( library ) ; <nl> - this . grpcsharp_batch_context_recv_message_to_buffer = GetMethodDelegate < Delegates . grpcsharp_batch_context_recv_message_to_buffer_delegate > ( library ) ; <nl> + this . grpcsharp_batch_context_recv_message_next_slice_peek = GetMethodDelegate < Delegates . grpcsharp_batch_context_recv_message_next_slice_peek_delegate > ( library ) ; <nl> this . grpcsharp_batch_context_recv_status_on_client_status = GetMethodDelegate < Delegates . grpcsharp_batch_context_recv_status_on_client_status_delegate > ( library ) ; <nl> this . grpcsharp_batch_context_recv_status_on_client_details = GetMethodDelegate < Delegates . grpcsharp_batch_context_recv_status_on_client_details_delegate > ( library ) ; <nl> this . grpcsharp_batch_context_recv_status_on_client_trailing_metadata = GetMethodDelegate < Delegates . grpcsharp_batch_context_recv_status_on_client_trailing_metadata_delegate > ( library ) ; <nl> public NativeMethods ( DllImportsFromStaticLib unusedInstance ) <nl> this . grpcsharp_batch_context_create = DllImportsFromStaticLib . grpcsharp_batch_context_create ; <nl> this . grpcsharp_batch_context_recv_initial_metadata = DllImportsFromStaticLib . grpcsharp_batch_context_recv_initial_metadata ; <nl> this . grpcsharp_batch_context_recv_message_length = DllImportsFromStaticLib . grpcsharp_batch_context_recv_message_length ; <nl> - this . grpcsharp_batch_context_recv_message_to_buffer = DllImportsFromStaticLib . grpcsharp_batch_context_recv_message_to_buffer ; <nl> + this . grpcsharp_batch_context_recv_message_next_slice_peek = DllImportsFromStaticLib . grpcsharp_batch_context_recv_message_next_slice_peek ; <nl> this . grpcsharp_batch_context_recv_status_on_client_status = DllImportsFromStaticLib . grpcsharp_batch_context_recv_status_on_client_status ; <nl> this . grpcsharp_batch_context_recv_status_on_client_details = DllImportsFromStaticLib . grpcsharp_batch_context_recv_status_on_client_details ; <nl> this . grpcsharp_batch_context_recv_status_on_client_trailing_metadata = DllImportsFromStaticLib . grpcsharp_batch_context_recv_status_on_client_trailing_metadata ; <nl> public NativeMethods ( DllImportsFromSharedLib unusedInstance ) <nl> this . grpcsharp_batch_context_create = DllImportsFromSharedLib . grpcsharp_batch_context_create ; <nl> this . grpcsharp_batch_context_recv_initial_metadata = DllImportsFromSharedLib . grpcsharp_batch_context_recv_initial_metadata ; <nl> this . grpcsharp_batch_context_recv_message_length = DllImportsFromSharedLib . grpcsharp_batch_context_recv_message_length ; <nl> - this . grpcsharp_batch_context_recv_message_to_buffer = DllImportsFromSharedLib . grpcsharp_batch_context_recv_message_to_buffer ; <nl> + this . grpcsharp_batch_context_recv_message_next_slice_peek = DllImportsFromSharedLib . grpcsharp_batch_context_recv_message_next_slice_peek ; <nl> this . grpcsharp_batch_context_recv_status_on_client_status = DllImportsFromSharedLib . grpcsharp_batch_context_recv_status_on_client_status ; <nl> this . grpcsharp_batch_context_recv_status_on_client_details = DllImportsFromSharedLib . grpcsharp_batch_context_recv_status_on_client_details ; <nl> this . grpcsharp_batch_context_recv_status_on_client_trailing_metadata = DllImportsFromSharedLib . grpcsharp_batch_context_recv_status_on_client_trailing_metadata ; <nl> public class Delegates <nl> public delegate BatchContextSafeHandle grpcsharp_batch_context_create_delegate ( ) ; <nl> public delegate IntPtr grpcsharp_batch_context_recv_initial_metadata_delegate ( BatchContextSafeHandle ctx ) ; <nl> public delegate IntPtr grpcsharp_batch_context_recv_message_length_delegate ( BatchContextSafeHandle ctx ) ; <nl> - public delegate void grpcsharp_batch_context_recv_message_to_buffer_delegate ( BatchContextSafeHandle ctx , byte [ ] buffer , UIntPtr bufferLen ) ; <nl> + public delegate int grpcsharp_batch_context_recv_message_next_slice_peek_delegate ( BatchContextSafeHandle ctx , out UIntPtr sliceLen , out IntPtr sliceDataPtr ) ; <nl> public delegate StatusCode grpcsharp_batch_context_recv_status_on_client_status_delegate ( BatchContextSafeHandle ctx ) ; <nl> public delegate IntPtr grpcsharp_batch_context_recv_status_on_client_details_delegate ( BatchContextSafeHandle ctx , out UIntPtr detailsLength ) ; <nl> public delegate IntPtr grpcsharp_batch_context_recv_status_on_client_trailing_metadata_delegate ( BatchContextSafeHandle ctx ) ; <nl> internal class DllImportsFromStaticLib <nl> public static extern IntPtr grpcsharp_batch_context_recv_message_length ( BatchContextSafeHandle ctx ) ; <nl> <nl> [ DllImport ( ImportName ) ] <nl> - public static extern void grpcsharp_batch_context_recv_message_to_buffer ( BatchContextSafeHandle ctx , byte [ ] buffer , UIntPtr bufferLen ) ; <nl> + public static extern int grpcsharp_batch_context_recv_message_next_slice_peek ( BatchContextSafeHandle ctx , out UIntPtr sliceLen , out IntPtr sliceDataPtr ) ; <nl> <nl> [ DllImport ( ImportName ) ] <nl> public static extern StatusCode grpcsharp_batch_context_recv_status_on_client_status ( BatchContextSafeHandle ctx ) ; <nl> internal class DllImportsFromSharedLib <nl> public static extern IntPtr grpcsharp_batch_context_recv_message_length ( BatchContextSafeHandle ctx ) ; <nl> <nl> [ DllImport ( ImportName ) ] <nl> - public static extern void grpcsharp_batch_context_recv_message_to_buffer ( BatchContextSafeHandle ctx , byte [ ] buffer , UIntPtr bufferLen ) ; <nl> + public static extern int grpcsharp_batch_context_recv_message_next_slice_peek ( BatchContextSafeHandle ctx , out UIntPtr sliceLen , out IntPtr sliceDataPtr ) ; <nl> <nl> [ DllImport ( ImportName ) ] <nl> public static extern StatusCode grpcsharp_batch_context_recv_status_on_client_status ( BatchContextSafeHandle ctx ) ; <nl> new file mode 100644 <nl> index 00000000000 . . 2d38509e511 <nl> mmm / dev / null <nl> ppp b / src / csharp / Grpc . Core / Internal / ReusableSliceBuffer . cs <nl> <nl> + # region Copyright notice and license <nl> + <nl> + / / Copyright 2019 The gRPC Authors <nl> + / / <nl> + / / Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + / / you may not use this file except in compliance with the License . <nl> + / / You may obtain a copy of the License at <nl> + / / <nl> + / / http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + / / <nl> + / / Unless required by applicable law or agreed to in writing , software <nl> + / / distributed under the License is distributed on an " AS IS " BASIS , <nl> + / / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + / / See the License for the specific language governing permissions and <nl> + / / limitations under the License . <nl> + <nl> + # endregion <nl> + <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + <nl> + using Grpc . Core . Utils ; <nl> + using System ; <nl> + using System . Threading ; <nl> + <nl> + using System . Buffers ; <nl> + <nl> + namespace Grpc . Core . Internal <nl> + { <nl> + internal class ReusableSliceBuffer <nl> + { <nl> + public const int MaxCachedSegments = 1024 ; / / ~ 4MB payload for 4K slices <nl> + <nl> + readonly SliceSegment [ ] cachedSegments = new SliceSegment [ MaxCachedSegments ] ; <nl> + int populatedSegmentCount ; <nl> + <nl> + public ReadOnlySequence < byte > PopulateFrom ( IBufferReader bufferReader ) <nl> + { <nl> + populatedSegmentCount = 0 ; <nl> + long offset = 0 ; <nl> + SliceSegment prevSegment = null ; <nl> + while ( bufferReader . TryGetNextSlice ( out Slice slice ) ) <nl> + { <nl> + / / Initialize cached segment if still null or just allocate a new segment if we already reached MaxCachedSegments <nl> + var current = populatedSegmentCount < cachedSegments . Length ? cachedSegments [ populatedSegmentCount ] : new SliceSegment ( ) ; <nl> + if ( current = = null ) <nl> + { <nl> + current = cachedSegments [ populatedSegmentCount ] = new SliceSegment ( ) ; <nl> + } <nl> + <nl> + current . Reset ( slice , offset ) ; <nl> + prevSegment ? . SetNext ( current ) ; <nl> + <nl> + populatedSegmentCount + + ; <nl> + offset + = slice . Length ; <nl> + prevSegment = current ; <nl> + } <nl> + <nl> + / / Not necessary for ending the ReadOnlySequence , but for making sure we <nl> + / / don ' t keep more than MaxCachedSegments alive . <nl> + prevSegment ? . SetNext ( null ) ; <nl> + <nl> + if ( populatedSegmentCount = = 0 ) <nl> + { <nl> + return ReadOnlySequence < byte > . Empty ; <nl> + } <nl> + <nl> + var firstSegment = cachedSegments [ 0 ] ; <nl> + var lastSegment = prevSegment ; <nl> + return new ReadOnlySequence < byte > ( firstSegment , 0 , lastSegment , lastSegment . Memory . Length ) ; <nl> + } <nl> + <nl> + public void Invalidate ( ) <nl> + { <nl> + if ( populatedSegmentCount = = 0 ) <nl> + { <nl> + return ; <nl> + } <nl> + var segment = cachedSegments [ 0 ] ; <nl> + while ( segment ! = null ) <nl> + { <nl> + segment . Reset ( new Slice ( IntPtr . Zero , 0 ) , 0 ) ; <nl> + var nextSegment = ( SliceSegment ) segment . Next ; <nl> + segment . SetNext ( null ) ; <nl> + segment = nextSegment ; <nl> + } <nl> + populatedSegmentCount = 0 ; <nl> + } <nl> + <nl> + / / Represents a segment in ReadOnlySequence <nl> + / / Segment is backed by Slice and the instances are reusable . <nl> + private class SliceSegment : ReadOnlySequenceSegment < byte > <nl> + { <nl> + readonly SliceMemoryManager pointerMemoryManager = new SliceMemoryManager ( ) ; <nl> + <nl> + public void Reset ( Slice slice , long runningIndex ) <nl> + { <nl> + pointerMemoryManager . Reset ( slice ) ; <nl> + Memory = pointerMemoryManager . Memory ; / / maybe not always necessary <nl> + RunningIndex = runningIndex ; <nl> + } <nl> + <nl> + public void SetNext ( ReadOnlySequenceSegment < byte > next ) <nl> + { <nl> + Next = next ; <nl> + } <nl> + } <nl> + <nl> + / / Allow creating instances of Memory < byte > from Slice . <nl> + / / Represents a chunk of native memory , but doesn ' t manage its lifetime . <nl> + / / Instances of this class are reuseable - they can be reset to point to a different memory chunk . <nl> + / / That is important to make the instances cacheable ( rather then creating new instances <nl> + / / the old ones will be reused to reduce GC pressure ) . <nl> + private class SliceMemoryManager : MemoryManager < byte > <nl> + { <nl> + private Slice slice ; <nl> + <nl> + public void Reset ( Slice slice ) <nl> + { <nl> + this . slice = slice ; <nl> + } <nl> + <nl> + public void Reset ( ) <nl> + { <nl> + Reset ( new Slice ( IntPtr . Zero , 0 ) ) ; <nl> + } <nl> + <nl> + public override Span < byte > GetSpan ( ) <nl> + { <nl> + return slice . ToSpanUnsafe ( ) ; <nl> + } <nl> + <nl> + public override MemoryHandle Pin ( int elementIndex = 0 ) <nl> + { <nl> + throw new NotSupportedException ( ) ; <nl> + } <nl> + <nl> + public override void Unpin ( ) <nl> + { <nl> + } <nl> + <nl> + protected override void Dispose ( bool disposing ) <nl> + { <nl> + / / NOP <nl> + } <nl> + } <nl> + } <nl> + } <nl> + # endif <nl> new file mode 100644 <nl> index 00000000000 . . 22eb9537951 <nl> mmm / dev / null <nl> ppp b / src / csharp / Grpc . Core / Internal / Slice . cs <nl> <nl> + # region Copyright notice and license <nl> + <nl> + / / Copyright 2019 The gRPC Authors <nl> + / / <nl> + / / Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + / / you may not use this file except in compliance with the License . <nl> + / / You may obtain a copy of the License at <nl> + / / <nl> + / / http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + / / <nl> + / / Unless required by applicable law or agreed to in writing , software <nl> + / / distributed under the License is distributed on an " AS IS " BASIS , <nl> + / / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + / / See the License for the specific language governing permissions and <nl> + / / limitations under the License . <nl> + <nl> + # endregion <nl> + <nl> + using System ; <nl> + using System . Runtime . InteropServices ; <nl> + using System . Threading ; <nl> + using Grpc . Core . Utils ; <nl> + <nl> + namespace Grpc . Core . Internal <nl> + { <nl> + / / / < summary > <nl> + / / / Slice of native memory . <nl> + / / / Rough equivalent of grpc_slice ( but doesn ' t support inlined slices , just a pointer to data and length ) <nl> + / / / < / summary > <nl> + internal struct Slice <nl> + { <nl> + private readonly IntPtr dataPtr ; <nl> + private readonly int length ; <nl> + <nl> + public Slice ( IntPtr dataPtr , int length ) <nl> + { <nl> + this . dataPtr = dataPtr ; <nl> + this . length = length ; <nl> + } <nl> + <nl> + public int Length = > length ; <nl> + <nl> + / / copies data of the slice to given span . <nl> + / / there needs to be enough space in the destination buffer <nl> + public void CopyTo ( ArraySegment < byte > destination ) <nl> + { <nl> + Marshal . Copy ( dataPtr , destination . Array , destination . Offset , length ) ; <nl> + } <nl> + <nl> + # if GRPC_CSHARP_SUPPORT_SYSTEM_MEMORY <nl> + public Span < byte > ToSpanUnsafe ( ) <nl> + { <nl> + unsafe <nl> + { <nl> + return new Span < byte > ( ( byte * ) dataPtr , length ) ; <nl> + } <nl> + } <nl> + # endif <nl> + <nl> + / / / < summary > <nl> + / / / Returns a < see cref = " System . String " / > that represents the current < see cref = " Grpc . Core . Internal . Slice " / > . <nl> + / / / < / summary > <nl> + public override string ToString ( ) <nl> + { <nl> + return string . Format ( " [ Slice : dataPtr = { 0 } , length = { 1 } ] " , dataPtr , length ) ; <nl> + } <nl> + } <nl> + } <nl> mmm a / src / csharp / Grpc . Tools / build / _protobuf / Google . Protobuf . Tools . targets <nl> ppp b / src / csharp / Grpc . Tools / build / _protobuf / Google . Protobuf . Tools . targets <nl> <nl> < ProtoRoot Condition = " ' % ( Protobuf . ProtoRoot ) ' = = ' ' " / > <nl> < CompileOutputs Condition = " ' % ( Protobuf . CompileOutputs ) ' = = ' ' " > True < / CompileOutputs > <nl> < OutputDir Condition = " ' % ( Protobuf . OutputDir ) ' = = ' ' " > $ ( Protobuf_OutputPath ) < / OutputDir > <nl> + < Generator Condition = " ' % ( Protobuf . Generator ) ' = = ' ' and ' $ ( DisableProtobufDesignTimeBuild ) ' ! = ' true ' " > MSBuild : Compile < / Generator > <nl> < / Protobuf > <nl> < / ItemDefinitionGroup > <nl> <nl> mmm a / src / csharp / ext / grpc_csharp_ext . c <nl> ppp b / src / csharp / ext / grpc_csharp_ext . c <nl> typedef struct grpcsharp_batch_context { <nl> } send_status_from_server ; <nl> grpc_metadata_array recv_initial_metadata ; <nl> grpc_byte_buffer * recv_message ; <nl> + grpc_byte_buffer_reader * recv_message_reader ; <nl> struct { <nl> grpc_metadata_array trailing_metadata ; <nl> grpc_status_code status ; <nl> grpc_slice status_details ; <nl> } recv_status_on_client ; <nl> int recv_close_on_server_cancelled ; <nl> + <nl> + / * reserve space for byte_buffer_reader * / <nl> + grpc_byte_buffer_reader reserved_recv_message_reader ; <nl> } grpcsharp_batch_context ; <nl> <nl> GPR_EXPORT grpcsharp_batch_context * GPR_CALLTYPE <nl> grpcsharp_batch_context_reset ( grpcsharp_batch_context * ctx ) { <nl> <nl> grpcsharp_metadata_array_destroy_metadata_only ( & ( ctx - > recv_initial_metadata ) ) ; <nl> <nl> + if ( ctx - > recv_message_reader ) { <nl> + grpc_byte_buffer_reader_destroy ( ctx - > recv_message_reader ) ; <nl> + } <nl> grpc_byte_buffer_destroy ( ctx - > recv_message ) ; <nl> <nl> grpcsharp_metadata_array_destroy_metadata_only ( <nl> GPR_EXPORT intptr_t GPR_CALLTYPE grpcsharp_batch_context_recv_message_length ( <nl> } <nl> <nl> / * <nl> - * Copies data from recv_message to a buffer . Fatal error occurs if <nl> - * buffer is too small . <nl> + * Gets the next slice from recv_message byte buffer . <nl> + * Returns 1 if a slice was get successfully , 0 if there are no more slices to <nl> + * read . Set slice_len to the length of the slice and the slice_data_ptr to <nl> + * point to slice ' s data . Caller must ensure that the byte buffer being read <nl> + * from stays alive as long as the data of the slice are being accessed <nl> + * ( grpc_byte_buffer_reader_peek method is used internally ) <nl> + * <nl> + * Remarks : <nl> + * Slices can only be iterated once . <nl> + * Initializes recv_message_buffer_reader if it was not initialized yet . <nl> * / <nl> - GPR_EXPORT void GPR_CALLTYPE grpcsharp_batch_context_recv_message_to_buffer ( <nl> - const grpcsharp_batch_context * ctx , char * buffer , size_t buffer_len ) { <nl> - grpc_byte_buffer_reader reader ; <nl> - grpc_slice slice ; <nl> - size_t offset = 0 ; <nl> + GPR_EXPORT int GPR_CALLTYPE <nl> + grpcsharp_batch_context_recv_message_next_slice_peek ( <nl> + grpcsharp_batch_context * ctx , size_t * slice_len , uint8_t * * slice_data_ptr ) { <nl> + * slice_len = 0 ; <nl> + * slice_data_ptr = NULL ; <nl> <nl> - GPR_ASSERT ( grpc_byte_buffer_reader_init ( & reader , ctx - > recv_message ) ) ; <nl> + if ( ! ctx - > recv_message ) { <nl> + return 0 ; <nl> + } <nl> <nl> - while ( grpc_byte_buffer_reader_next ( & reader , & slice ) ) { <nl> - size_t len = GRPC_SLICE_LENGTH ( slice ) ; <nl> - GPR_ASSERT ( offset + len < = buffer_len ) ; <nl> - memcpy ( buffer + offset , GRPC_SLICE_START_PTR ( slice ) , <nl> - GRPC_SLICE_LENGTH ( slice ) ) ; <nl> - offset + = len ; <nl> - grpc_slice_unref ( slice ) ; <nl> + if ( ! ctx - > recv_message_reader ) { <nl> + ctx - > recv_message_reader = & ctx - > reserved_recv_message_reader ; <nl> + GPR_ASSERT ( grpc_byte_buffer_reader_init ( ctx - > recv_message_reader , <nl> + ctx - > recv_message ) ) ; <nl> } <nl> <nl> - grpc_byte_buffer_reader_destroy ( & reader ) ; <nl> + grpc_slice * slice_ptr ; <nl> + if ( ! grpc_byte_buffer_reader_peek ( ctx - > recv_message_reader , & slice_ptr ) ) { <nl> + return 0 ; <nl> + } <nl> + <nl> + / * recv_message buffer must not be deleted before all the data is read * / <nl> + * slice_len = GRPC_SLICE_LENGTH ( * slice_ptr ) ; <nl> + * slice_data_ptr = GRPC_SLICE_START_PTR ( * slice_ptr ) ; <nl> + return 1 ; <nl> } <nl> <nl> GPR_EXPORT grpc_status_code GPR_CALLTYPE <nl> mmm a / src / csharp / tests . json <nl> ppp b / src / csharp / tests . json <nl> <nl> " Grpc . Core . Internal . Tests . ChannelArgsSafeHandleTest " , <nl> " Grpc . Core . Internal . Tests . CompletionQueueEventTest " , <nl> " Grpc . Core . Internal . Tests . CompletionQueueSafeHandleTest " , <nl> + " Grpc . Core . Internal . Tests . DefaultDeserializationContextTest " , <nl> " Grpc . Core . Internal . Tests . DefaultObjectPoolTest " , <nl> + " Grpc . Core . Internal . Tests . FakeBufferReaderManagerTest " , <nl> " Grpc . Core . Internal . Tests . MetadataArraySafeHandleTest " , <nl> + " Grpc . Core . Internal . Tests . ReusableSliceBufferTest " , <nl> + " Grpc . Core . Internal . Tests . SliceTest " , <nl> " Grpc . Core . Internal . Tests . TimespecTest " , <nl> " Grpc . Core . Tests . AppDomainUnloadTest " , <nl> " Grpc . Core . Tests . AuthContextTest " , <nl> mmm a / src / csharp / unitypackage / unitypackage_skeleton / Plugins / Grpc . Core / runtimes / grpc_csharp_ext_dummy_stubs . c <nl> ppp b / src / csharp / unitypackage / unitypackage_skeleton / Plugins / Grpc . Core / runtimes / grpc_csharp_ext_dummy_stubs . c <nl> void grpcsharp_batch_context_recv_message_length ( ) { <nl> fprintf ( stderr , " Should never reach here " ) ; <nl> abort ( ) ; <nl> } <nl> - void grpcsharp_batch_context_recv_message_to_buffer ( ) { <nl> + void grpcsharp_batch_context_recv_message_next_slice_peek ( ) { <nl> fprintf ( stderr , " Should never reach here " ) ; <nl> abort ( ) ; <nl> } <nl> mmm a / src / objective - c / GRPCClient / GRPCCall . h <nl> ppp b / src / objective - c / GRPCClient / GRPCCall . h <nl> typedef NS_ENUM ( NSUInteger , GRPCErrorCode ) { <nl> <nl> / * * <nl> * The server is currently unavailable . This is most likely a transient condition and may be <nl> - * corrected by retrying with a backoff . <nl> + * corrected by retrying with a backoff . Note that it is not always safe to retry <nl> + * non - idempotent operations . <nl> * / <nl> GRPCErrorCodeUnavailable = 14 , <nl> <nl> mmm a / src / ruby / lib / grpc / errors . rb <nl> ppp b / src / ruby / lib / grpc / errors . rb <nl> <nl> # limitations under the License . <nl> <nl> require_relative ' . / grpc ' <nl> - require_relative ' . / google_rpc_status_utils ' <nl> <nl> # GRPC contains the General RPC module . <nl> module GRPC <nl> def to_status <nl> # <nl> # @ return [ Google : : Rpc : : Status , nil ] <nl> def to_rpc_status <nl> + # Lazily require google_rpc_status_utils to scope <nl> + # loading protobuf_c . so to the users of this method . <nl> + require_relative ' . / google_rpc_status_utils ' <nl> status = to_status <nl> - <nl> return if status . nil ? <nl> - <nl> GoogleRpcStatusUtils . extract_google_rpc_status ( status ) <nl> rescue Google : : Protobuf : : ParseError = > parse_error <nl> GRPC . logger . warn ( ' parse error : to_rpc_status failed ' ) <nl> mmm a / templates / src / csharp / Grpc . Core / Internal / native_methods . include <nl> ppp b / templates / src / csharp / Grpc . Core / Internal / native_methods . include <nl> native_method_signatures = [ <nl> ' BatchContextSafeHandle grpcsharp_batch_context_create ( ) ' , <nl> ' IntPtr grpcsharp_batch_context_recv_initial_metadata ( BatchContextSafeHandle ctx ) ' , <nl> ' IntPtr grpcsharp_batch_context_recv_message_length ( BatchContextSafeHandle ctx ) ' , <nl> - ' void grpcsharp_batch_context_recv_message_to_buffer ( BatchContextSafeHandle ctx , byte [ ] buffer , UIntPtr bufferLen ) ' , <nl> + ' int grpcsharp_batch_context_recv_message_next_slice_peek ( BatchContextSafeHandle ctx , out UIntPtr sliceLen , out IntPtr sliceDataPtr ) ' , <nl> ' StatusCode grpcsharp_batch_context_recv_status_on_client_status ( BatchContextSafeHandle ctx ) ' , <nl> ' IntPtr grpcsharp_batch_context_recv_status_on_client_details ( BatchContextSafeHandle ctx , out UIntPtr detailsLength ) ' , <nl> ' IntPtr grpcsharp_batch_context_recv_status_on_client_trailing_metadata ( BatchContextSafeHandle ctx ) ' , <nl> mmm a / test / core / gpr / alloc_test . cc <nl> ppp b / test / core / gpr / alloc_test . cc <nl> static void fake_free ( void * addr ) { <nl> * ( static_cast < intptr_t * > ( addr ) ) = static_cast < intptr_t > ( 0xdeadd00d ) ; <nl> } <nl> <nl> - static void * fake_aligned_malloc ( size_t size , size_t alignment ) { <nl> - return ( void * ) ( size + alignment ) ; <nl> - } <nl> - <nl> - static void fake_aligned_free ( void * addr ) { <nl> - * ( static_cast < intptr_t * > ( addr ) ) = static_cast < intptr_t > ( 0xcafef00d ) ; <nl> - } <nl> - <nl> static void test_custom_allocs ( ) { <nl> const gpr_allocation_functions default_fns = gpr_get_allocation_functions ( ) ; <nl> intptr_t addr_to_free = 0 ; <nl> char * i ; <nl> - gpr_allocation_functions fns = { fake_malloc , nullptr , <nl> - fake_realloc , fake_free , <nl> - fake_aligned_malloc , fake_aligned_free } ; <nl> + gpr_allocation_functions fns = { fake_malloc , nullptr , fake_realloc , <nl> + fake_free } ; <nl> <nl> gpr_set_allocation_functions ( fns ) ; <nl> GPR_ASSERT ( ( void * ) ( size_t ) 0xdeadbeef = = gpr_malloc ( 0xdeadbeef ) ) ; <nl> static void test_custom_allocs ( ) { <nl> gpr_free ( & addr_to_free ) ; <nl> GPR_ASSERT ( addr_to_free = = ( intptr_t ) 0xdeadd00d ) ; <nl> <nl> - GPR_ASSERT ( ( void * ) ( size_t ) ( 0xdeadbeef + 64 ) = = <nl> - gpr_malloc_aligned ( 0xdeadbeef , 64 ) ) ; <nl> - gpr_free_aligned ( & addr_to_free ) ; <nl> - GPR_ASSERT ( addr_to_free = = ( intptr_t ) 0xcafef00d ) ; <nl> - <nl> / * Restore and check we don ' t get funky values and that we don ' t leak * / <nl> gpr_set_allocation_functions ( default_fns ) ; <nl> GPR_ASSERT ( ( void * ) sizeof ( * i ) ! = <nl> mmm a / test / core / util / memory_counters . cc <nl> ppp b / test / core / util / memory_counters . cc <nl> static void * guard_malloc ( size_t size ) { <nl> NO_BARRIER_FETCH_ADD ( & g_memory_counters . total_allocs_absolute , ( gpr_atm ) 1 ) ; <nl> NO_BARRIER_FETCH_ADD ( & g_memory_counters . total_allocs_relative , ( gpr_atm ) 1 ) ; <nl> void * ptr = g_old_allocs . malloc_fn ( <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( size ) ) + size ) ; <nl> + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( size ) ) + size ) ; <nl> * static_cast < size_t * > ( ptr ) = size ; <nl> - return static_cast < char * > ( ptr ) + <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( size ) ) ; <nl> + return static_cast < char * > ( ptr ) + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( size ) ) ; <nl> } <nl> <nl> static void * guard_realloc ( void * vptr , size_t size ) { <nl> static void * guard_realloc ( void * vptr , size_t size ) { <nl> guard_free ( vptr ) ; <nl> return nullptr ; <nl> } <nl> - void * ptr = static_cast < char * > ( vptr ) - <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( size ) ) ; <nl> + void * ptr = <nl> + static_cast < char * > ( vptr ) - GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( size ) ) ; <nl> NO_BARRIER_FETCH_ADD ( & g_memory_counters . total_size_absolute , ( gpr_atm ) size ) ; <nl> NO_BARRIER_FETCH_ADD ( & g_memory_counters . total_size_relative , <nl> - * static_cast < gpr_atm * > ( ptr ) ) ; <nl> NO_BARRIER_FETCH_ADD ( & g_memory_counters . total_size_relative , ( gpr_atm ) size ) ; <nl> NO_BARRIER_FETCH_ADD ( & g_memory_counters . total_allocs_absolute , ( gpr_atm ) 1 ) ; <nl> ptr = g_old_allocs . realloc_fn ( <nl> - ptr , GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( size ) ) + size ) ; <nl> + ptr , GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( size ) ) + size ) ; <nl> * static_cast < size_t * > ( ptr ) = size ; <nl> - return static_cast < char * > ( ptr ) + <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( size ) ) ; <nl> + return static_cast < char * > ( ptr ) + GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( size ) ) ; <nl> } <nl> <nl> static void guard_free ( void * vptr ) { <nl> if ( vptr = = nullptr ) return ; <nl> - void * ptr = static_cast < char * > ( vptr ) - <nl> - GPR_ROUND_UP_TO_MAX_ALIGNMENT_SIZE ( sizeof ( size_t ) ) ; <nl> + void * ptr = <nl> + static_cast < char * > ( vptr ) - GPR_ROUND_UP_TO_ALIGNMENT_SIZE ( sizeof ( size_t ) ) ; <nl> NO_BARRIER_FETCH_ADD ( & g_memory_counters . total_size_relative , <nl> - * static_cast < gpr_atm * > ( ptr ) ) ; <nl> NO_BARRIER_FETCH_ADD ( & g_memory_counters . total_allocs_relative , - ( gpr_atm ) 1 ) ; <nl> g_old_allocs . free_fn ( ptr ) ; <nl> } <nl> <nl> - / / NB : We do not specify guard_malloc_aligned / guard_free_aligned methods . Since <nl> - / / they are null , calls to gpr_malloc_aligned / gpr_free_aligned are executed as a <nl> - / / wrapper over gpr_malloc / gpr_free , which do use guard_malloc / guard_free , and <nl> - / / thus their allocations are tracked as well . <nl> - struct gpr_allocation_functions g_guard_allocs = { <nl> - guard_malloc , nullptr , guard_realloc , guard_free , nullptr , nullptr } ; <nl> + struct gpr_allocation_functions g_guard_allocs = { guard_malloc , nullptr , <nl> + guard_realloc , guard_free } ; <nl> <nl> void grpc_memory_counters_init ( ) { <nl> memset ( & g_memory_counters , 0 , sizeof ( g_memory_counters ) ) ; <nl> similarity index 85 % <nl> rename from tools / internal_ci / linux / pull_request / grpc_basictests_c_cpp_dbg . cfg <nl> rename to tools / internal_ci / linux / pull_request / grpc_basictests_csharp . cfg <nl> mmm a / tools / internal_ci / linux / pull_request / grpc_basictests_c_cpp_dbg . cfg <nl> ppp b / tools / internal_ci / linux / pull_request / grpc_basictests_csharp . cfg <nl> <nl> - # Copyright 2017 gRPC authors . <nl> + # Copyright 2019 The gRPC Authors <nl> # <nl> # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> # you may not use this file except in compliance with the License . <nl> <nl> <nl> # Location of the continuous shell script in repository . <nl> build_file : " grpc / tools / internal_ci / linux / grpc_run_tests_matrix . sh " <nl> - timeout_mins : 240 <nl> + timeout_mins : 60 <nl> action { <nl> define_artifacts { <nl> regex : " * * / * sponge_log . * " <nl> action { <nl> <nl> env_vars { <nl> key : " RUN_TESTS_FLAGS " <nl> - value : " - f basictests linux corelang dbg - - inner_jobs 16 - j 1 - - internal_ci - - max_time = 3600 " <nl> + value : " - f basictests linux csharp - - inner_jobs 16 - j 2 - - internal_ci - - max_time = 3600 " <nl> } <nl> similarity index 85 % <nl> rename from tools / internal_ci / linux / pull_request / grpc_basictests_c_cpp_opt . cfg <nl> rename to tools / internal_ci / linux / pull_request / grpc_basictests_node . cfg <nl> mmm a / tools / internal_ci / linux / pull_request / grpc_basictests_c_cpp_opt . cfg <nl> ppp b / tools / internal_ci / linux / pull_request / grpc_basictests_node . cfg <nl> <nl> - # Copyright 2017 gRPC authors . <nl> + # Copyright 2019 The gRPC Authors <nl> # <nl> # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> # you may not use this file except in compliance with the License . <nl> <nl> <nl> # Location of the continuous shell script in repository . <nl> build_file : " grpc / tools / internal_ci / linux / grpc_run_tests_matrix . sh " <nl> - timeout_mins : 240 <nl> + timeout_mins : 60 <nl> action { <nl> define_artifacts { <nl> regex : " * * / * sponge_log . * " <nl> action { <nl> <nl> env_vars { <nl> key : " RUN_TESTS_FLAGS " <nl> - value : " - f basictests linux corelang opt - - inner_jobs 16 - j 1 - - internal_ci - - max_time = 3600 " <nl> + value : " - f basictests linux grpc - node - - inner_jobs 16 - j 2 - - internal_ci - - max_time = 3600 " <nl> } <nl> new file mode 100644 <nl> index 00000000000 . . c844fcfae00 <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / linux / pull_request / grpc_basictests_php . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / linux / grpc_run_tests_matrix . sh " <nl> + timeout_mins : 60 <nl> + action { <nl> + define_artifacts { <nl> + regex : " * * / * sponge_log . * " <nl> + regex : " github / grpc / reports / * * " <nl> + } <nl> + } <nl> + <nl> + env_vars { <nl> + key : " RUN_TESTS_FLAGS " <nl> + value : " - f basictests linux php - - inner_jobs 16 - j 2 - - internal_ci - - max_time = 3600 " <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . b4e91c2a7e2 <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / linux / pull_request / grpc_basictests_python . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / linux / grpc_run_tests_matrix . sh " <nl> + timeout_mins : 60 <nl> + action { <nl> + define_artifacts { <nl> + regex : " * * / * sponge_log . * " <nl> + regex : " github / grpc / reports / * * " <nl> + } <nl> + } <nl> + <nl> + env_vars { <nl> + key : " RUN_TESTS_FLAGS " <nl> + value : " - f basictests linux python - - inner_jobs 16 - j 2 - - internal_ci - - max_time = 3600 " <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . 49d3dad592e <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / linux / pull_request / grpc_basictests_ruby . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / linux / grpc_run_tests_matrix . sh " <nl> + timeout_mins : 60 <nl> + action { <nl> + define_artifacts { <nl> + regex : " * * / * sponge_log . * " <nl> + regex : " github / grpc / reports / * * " <nl> + } <nl> + } <nl> + <nl> + env_vars { <nl> + key : " RUN_TESTS_FLAGS " <nl> + value : " - f basictests linux ruby - - inner_jobs 16 - j 2 - - internal_ci - - max_time = 3600 " <nl> + } <nl> mmm a / tools / internal_ci / macos / grpc_basictests_c_cpp . cfg <nl> ppp b / tools / internal_ci / macos / grpc_basictests_c_cpp . cfg <nl> <nl> # Location of the continuous shell script in repository . <nl> build_file : " grpc / tools / internal_ci / macos / grpc_run_tests_matrix . sh " <nl> gfile_resources : " / bigstore / grpc - testing - secrets / gcp_credentials / GrpcTesting - d0eeee2db331 . json " <nl> - timeout_mins : 60 <nl> + timeout_mins : 120 <nl> action { <nl> define_artifacts { <nl> regex : " * * / * sponge_log . * " <nl> new file mode 100644 <nl> index 00000000000 . . 00f402d389b <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / macos / pull_request / grpc_basictests_c_cpp . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / macos / grpc_run_tests_matrix . sh " <nl> + gfile_resources : " / bigstore / grpc - testing - secrets / gcp_credentials / GrpcTesting - d0eeee2db331 . json " <nl> + timeout_mins : 120 <nl> + action { <nl> + define_artifacts { <nl> + regex : " * * / * sponge_log . * " <nl> + regex : " github / grpc / reports / * * " <nl> + } <nl> + } <nl> + <nl> + env_vars { <nl> + key : " RUN_TESTS_FLAGS " <nl> + value : " - f basictests macos corelang - - internal_ci - j 1 - - inner_jobs 4 - - max_time = 3600 " <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . c9c1403693c <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / macos / pull_request / grpc_basictests_csharp . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / macos / grpc_run_tests_matrix . sh " <nl> + gfile_resources : " / bigstore / grpc - testing - secrets / gcp_credentials / GrpcTesting - d0eeee2db331 . json " <nl> + timeout_mins : 60 <nl> + action { <nl> + define_artifacts { <nl> + regex : " * * / * sponge_log . * " <nl> + regex : " github / grpc / reports / * * " <nl> + } <nl> + } <nl> + <nl> + env_vars { <nl> + key : " RUN_TESTS_FLAGS " <nl> + value : " - f basictests macos csharp - - internal_ci - j 1 - - inner_jobs 4 - - max_time = 3600 " <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . ed729ef5a91 <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / macos / pull_request / grpc_basictests_node . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / macos / grpc_run_tests_matrix . sh " <nl> + gfile_resources : " / bigstore / grpc - testing - secrets / gcp_credentials / GrpcTesting - d0eeee2db331 . json " <nl> + timeout_mins : 60 <nl> + action { <nl> + define_artifacts { <nl> + regex : " * * / * sponge_log . * " <nl> + regex : " github / grpc / reports / * * " <nl> + } <nl> + } <nl> + <nl> + env_vars { <nl> + key : " RUN_TESTS_FLAGS " <nl> + value : " - f basictests macos grpc - node - - internal_ci - j 1 - - inner_jobs 4 - - max_time = 3600 " <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . 11b17874c28 <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / macos / pull_request / grpc_basictests_php . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / macos / grpc_run_tests_matrix . sh " <nl> + gfile_resources : " / bigstore / grpc - testing - secrets / gcp_credentials / GrpcTesting - d0eeee2db331 . json " <nl> + timeout_mins : 60 <nl> + action { <nl> + define_artifacts { <nl> + regex : " * * / * sponge_log . * " <nl> + regex : " github / grpc / reports / * * " <nl> + } <nl> + } <nl> + <nl> + env_vars { <nl> + key : " RUN_TESTS_FLAGS " <nl> + value : " - f basictests macos php - - internal_ci - j 1 - - inner_jobs 4 - - max_time = 3600 " <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . c86871f80cb <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / macos / pull_request / grpc_basictests_python . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / macos / grpc_run_tests_matrix . sh " <nl> + gfile_resources : " / bigstore / grpc - testing - secrets / gcp_credentials / GrpcTesting - d0eeee2db331 . json " <nl> + timeout_mins : 60 <nl> + action { <nl> + define_artifacts { <nl> + regex : " * * / * sponge_log . * " <nl> + regex : " github / grpc / reports / * * " <nl> + } <nl> + } <nl> + <nl> + env_vars { <nl> + key : " RUN_TESTS_FLAGS " <nl> + value : " - f basictests macos python - - internal_ci - j 1 - - inner_jobs 4 - - max_time = 3600 " <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . 5729bf8f751 <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / macos / pull_request / grpc_basictests_ruby . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / macos / grpc_run_tests_matrix . sh " <nl> + gfile_resources : " / bigstore / grpc - testing - secrets / gcp_credentials / GrpcTesting - d0eeee2db331 . json " <nl> + timeout_mins : 60 <nl> + action { <nl> + define_artifacts { <nl> + regex : " * * / * sponge_log . * " <nl> + regex : " github / grpc / reports / * * " <nl> + } <nl> + } <nl> + <nl> + env_vars { <nl> + key : " RUN_TESTS_FLAGS " <nl> + value : " - f basictests macos ruby - - internal_ci - j 1 - - inner_jobs 4 - - max_time = 3600 " <nl> + } <nl> mmm a / tools / internal_ci / windows / grpc_basictests_c . cfg <nl> ppp b / tools / internal_ci / windows / grpc_basictests_c . cfg <nl> <nl> <nl> # Location of the continuous shell script in repository . <nl> build_file : " grpc / tools / internal_ci / windows / grpc_run_tests_matrix . bat " <nl> - timeout_mins : 60 <nl> + timeout_mins : 120 <nl> action { <nl> define_artifacts { <nl> regex : " * * / * sponge_log . * " <nl> new file mode 100644 <nl> index 00000000000 . . 4cedcae9a87 <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / windows / pull_request / grpc_basictests_c . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / windows / grpc_run_tests_matrix . bat " <nl> + timeout_mins : 120 <nl> + action { <nl> + define_artifacts { <nl> + regex : " * * / * sponge_log . * " <nl> + regex : " github / grpc / reports / * * " <nl> + } <nl> + } <nl> + <nl> + env_vars { <nl> + key : " RUN_TESTS_FLAGS " <nl> + value : " - f basictests windows c - j 1 - - inner_jobs 8 - - internal_ci - - max_time = 3600 " <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . e1c5af108ec <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / windows / pull_request / grpc_basictests_csharp . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / windows / grpc_run_tests_matrix . bat " <nl> + timeout_mins : 60 <nl> + action { <nl> + define_artifacts { <nl> + regex : " * * / * sponge_log . * " <nl> + regex : " github / grpc / reports / * * " <nl> + } <nl> + } <nl> + <nl> + env_vars { <nl> + key : " RUN_TESTS_FLAGS " <nl> + value : " - f basictests windows csharp - j 1 - - inner_jobs 8 - - internal_ci - - max_time = 3600 " <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . 6947e8e1b4e <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / windows / pull_request / grpc_basictests_python . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / windows / grpc_run_tests_matrix . bat " <nl> + timeout_mins : 60 <nl> + action { <nl> + define_artifacts { <nl> + regex : " * * / * sponge_log . * " <nl> + regex : " github / grpc / reports / * * " <nl> + } <nl> + } <nl> + <nl> + env_vars { <nl> + key : " RUN_TESTS_FLAGS " <nl> + value : " - f basictests windows python - j 1 - - inner_jobs 8 - - internal_ci - - max_time = 3600 " <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . f958fed33dd <nl> mmm / dev / null <nl> ppp b / tools / internal_ci / windows / pull_request / grpc_bazel_rbe_dbg . cfg <nl> <nl> + # Copyright 2019 The gRPC Authors <nl> + # <nl> + # Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + # you may not use this file except in compliance with the License . <nl> + # You may obtain a copy of the License at <nl> + # <nl> + # http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + # <nl> + # Unless required by applicable law or agreed to in writing , software <nl> + # distributed under the License is distributed on an " AS IS " BASIS , <nl> + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + # See the License for the specific language governing permissions and <nl> + # limitations under the License . <nl> + <nl> + # Config file for the internal CI ( in protobuf text format ) <nl> + <nl> + # Location of the continuous shell script in repository . <nl> + build_file : " grpc / tools / internal_ci / windows / bazel_rbe . bat " <nl> + <nl> + timeout_mins : 60 <nl> + <nl> + gfile_resources : " / bigstore / grpc - testing - secrets / gcp_credentials / GrpcTesting - d0eeee2db331 . json " <nl> + gfile_resources : " / bigstore / grpc - testing - secrets / gcp_credentials / resultstore_api_key " <nl> + gfile_resources : " / bigstore / grpc - testing - secrets / gcp_credentials / rbe - windows - credentials . json " <nl> + <nl> + bazel_setting { <nl> + # In order for Kokoro to recognize this as a bazel build and publish the bazel resultstore link , <nl> + # the bazel_setting section needs to be present and " upsalite_frontend_address " needs to be <nl> + # set . The rest of configuration from bazel_setting is unused ( we configure everything when bazel <nl> + # command is invoked ) . <nl> + upsalite_frontend_address : " https : / / source . cloud . google . com " <nl> + } <nl>
Merge remote - tracking branch ' upstream / master '
grpc/grpc
0f7f745864fc0e09b8edd7ce8967cf9c42ee3ec8
2019-05-08T00:33:44Z
mmm a / CHANGELOG . md <nl> ppp b / CHANGELOG . md <nl> <nl> * Added functions for working with base64 : ` base64Encode ` , ` base64Decode ` , ` tryBase64Decode ` . [ Alexander Krasheninnikov ] ( https : / / github . com / yandex / ClickHouse / pull / 3350 ) <nl> * Now you can use a parameter to configure the precision of the ` uniqCombined ` aggregate function ( select the number of HyperLogLog cells ) . [ # 3406 ] ( https : / / github . com / yandex / ClickHouse / pull / 3406 ) <nl> * Added the ` system . contributors ` table that contains the names of everyone who made commits in ClickHouse . [ # 3452 ] ( https : / / github . com / yandex / ClickHouse / pull / 3452 ) <nl> - * Added the ability to omit the partition for the ` ALTER TABLE . . . FREEZE ` request in order to back up all partitions at once . [ # 3514 ] ( https : / / github . com / yandex / ClickHouse / pull / 3514 ) <nl> + * Added the ability to omit the partition for the ` ALTER TABLE . . . FREEZE ` query in order to back up all partitions at once . [ # 3514 ] ( https : / / github . com / yandex / ClickHouse / pull / 3514 ) <nl> * Added ` dictGet ` and ` dictGetOrDefault ` functions that don ' t require specifying the type of return value . The type is determined automatically from the dictionary description . [ Amos Bird ] ( https : / / github . com / yandex / ClickHouse / pull / 3564 ) <nl> * Now you can specify comments for a column in the table description and change it using ` ALTER ` . [ # 3377 ] ( https : / / github . com / yandex / ClickHouse / pull / 3377 ) <nl> * Reading is supported for ` Join ` type tables with simple keys . [ Amos Bird ] ( https : / / github . com / yandex / ClickHouse / pull / 3728 ) <nl> <nl> * The ` min_merge_bytes_to_use_direct_io ` option is set to 10 GiB by default . A merge that forms large parts of tables from the MergeTree family will be performed in ` O_DIRECT ` mode , which prevents the cache resources from being cleared . [ # 3504 ] ( https : / / github . com / yandex / ClickHouse / pull / 3504 ) <nl> * Accelerated server start when there is a very large number of tables . [ # 3398 ] ( https : / / github . com / yandex / ClickHouse / pull / 3398 ) <nl> * Added a connection pool and HTTP ` Keep - Alive ` for connections between replicas . [ # 3594 ] ( https : / / github . com / yandex / ClickHouse / pull / 3594 ) <nl> - * If the request syntax is invalid , the ` 400 Bad Request ` code is returned in the ` HTTP ` interface ( 500 was returned previously ) . [ 31bc680a ] ( https : / / github . com / yandex / ClickHouse / commit / 31bc680ac5f4bb1d0360a8ba4696fa84bb47d6ab ) <nl> + * If the query syntax is invalid , the ` 400 Bad Request ` code is returned in the ` HTTP ` interface ( 500 was returned previously ) . [ 31bc680a ] ( https : / / github . com / yandex / ClickHouse / commit / 31bc680ac5f4bb1d0360a8ba4696fa84bb47d6ab ) <nl> * The ` join_default_strictness ` option is set to ` ALL ` by default for compatibility . [ 120e2cbe ] ( https : / / github . com / yandex / ClickHouse / commit / 120e2cbe2ff4fbad626c28042d9b28781c805afe ) <nl> * Removed logging to ` stderr ` from the ` re2 ` library for invalid or complex regular expressions . [ # 3723 ] ( https : / / github . com / yandex / ClickHouse / pull / 3723 ) <nl> * Added for the ` Kafka ` table engine : checks for subscriptions before beginning to read from Kafka ; the kafka_max_block_size setting for the table . [ Marek Vavruša ] ( https : / / github . com / yandex / ClickHouse / pull / 3396 ) <nl> <nl> <nl> # # # Improvements : <nl> <nl> - * Significantly reduced memory consumption for requests with ` ORDER BY ` and ` LIMIT ` . See the ` max_bytes_before_remerge_sort ` setting . [ # 3205 ] ( https : / / github . com / yandex / ClickHouse / pull / 3205 ) <nl> + * Significantly reduced memory consumption for queries with ` ORDER BY ` and ` LIMIT ` . See the ` max_bytes_before_remerge_sort ` setting . [ # 3205 ] ( https : / / github . com / yandex / ClickHouse / pull / 3205 ) <nl> * In the absence of ` JOIN ` ( ` LEFT ` , ` INNER ` , . . . ) , ` INNER JOIN ` is assumed . [ # 3147 ] ( https : / / github . com / yandex / ClickHouse / pull / 3147 ) <nl> * Qualified asterisks work correctly in queries with ` JOIN ` . [ Winter Zhang ] ( https : / / github . com / yandex / ClickHouse / pull / 3202 ) <nl> * The ` ODBC ` table engine correctly chooses the method for quoting identifiers in the SQL dialect of a remote database . [ Alexandr Krasheninnikov ] ( https : / / github . com / yandex / ClickHouse / pull / 3210 ) <nl> <nl> * If after merging data parts , the checksum for the resulting part differs from the result of the same merge in another replica , the result of the merge is deleted and the data part is downloaded from the other replica ( this is the correct behavior ) . But after downloading the data part , it couldn ' t be added to the working set because of an error that the part already exists ( because the data part was deleted with some delay after the merge ) . This led to cyclical attempts to download the same data . [ # 3194 ] ( https : / / github . com / yandex / ClickHouse / pull / 3194 ) <nl> * Fixed incorrect calculation of total memory consumption by queries ( because of incorrect calculation , the ` max_memory_usage_for_all_queries ` setting worked incorrectly and the ` MemoryTracking ` metric had an incorrect value ) . This error occurred in version 18 . 12 . 13 . [ Marek Vavruša ] ( https : / / github . com / yandex / ClickHouse / pull / 3344 ) <nl> * Fixed the functionality of ` CREATE TABLE . . . ON CLUSTER . . . AS SELECT . . . ` This error occurred in version 18 . 12 . 13 . [ # 3247 ] ( https : / / github . com / yandex / ClickHouse / pull / 3247 ) <nl> - * Fixed unnecessary preparation of data structures for ` JOIN ` s on the server that initiates the request if the ` JOIN ` is only performed on remote servers . [ # 3340 ] ( https : / / github . com / yandex / ClickHouse / pull / 3340 ) <nl> + * Fixed unnecessary preparation of data structures for ` JOIN ` s on the server that initiates the query if the ` JOIN ` is only performed on remote servers . [ # 3340 ] ( https : / / github . com / yandex / ClickHouse / pull / 3340 ) <nl> * Fixed bugs in the ` Kafka ` engine : deadlocks after exceptions when starting to read data , and locks upon completion [ Marek Vavruša ] ( https : / / github . com / yandex / ClickHouse / pull / 3215 ) . <nl> * For ` Kafka ` tables , the optional ` schema ` parameter was not passed ( the schema of the ` Cap ' n ' Proto ` format ) . [ Vojtech Splichal ] ( https : / / github . com / yandex / ClickHouse / pull / 3150 ) <nl> * If the ensemble of ZooKeeper servers has servers that accept the connection but then immediately close it instead of responding to the handshake , ClickHouse chooses to connect another server . Previously , this produced the error ` Cannot read all data . Bytes read : 0 . Bytes expected : 4 . ` and the server couldn ' t start . [ 8218cf3a ] ( https : / / github . com / yandex / ClickHouse / commit / 8218cf3a5f39a43401953769d6d12a0bb8d29da9 ) <nl> <nl> <nl> * Added the ` DECIMAL ( digits , scale ) ` data type ( ` Decimal32 ( scale ) ` , ` Decimal64 ( scale ) ` , ` Decimal128 ( scale ) ` ) . To enable it , use the setting ` allow_experimental_decimal_type ` . [ # 2846 ] ( https : / / github . com / yandex / ClickHouse / pull / 2846 ) [ # 2970 ] ( https : / / github . com / yandex / ClickHouse / pull / 2970 ) [ # 3008 ] ( https : / / github . com / yandex / ClickHouse / pull / 3008 ) [ # 3047 ] ( https : / / github . com / yandex / ClickHouse / pull / 3047 ) <nl> * New ` WITH ROLLUP ` modifier for ` GROUP BY ` ( alternative syntax : ` GROUP BY ROLLUP ( . . . ) ` ) . [ # 2948 ] ( https : / / github . com / yandex / ClickHouse / pull / 2948 ) <nl> - * In requests with JOIN , the star character expands to a list of columns in all tables , in compliance with the SQL standard . You can restore the old behavior by setting ` asterisk_left_columns_only ` to 1 on the user configuration level . [ Winter Zhang ] ( https : / / github . com / yandex / ClickHouse / pull / 2787 ) <nl> + * In queries with JOIN , the star character expands to a list of columns in all tables , in compliance with the SQL standard . You can restore the old behavior by setting ` asterisk_left_columns_only ` to 1 on the user configuration level . [ Winter Zhang ] ( https : / / github . com / yandex / ClickHouse / pull / 2787 ) <nl> * Added support for JOIN with table functions . [ Winter Zhang ] ( https : / / github . com / yandex / ClickHouse / pull / 2907 ) <nl> * Autocomplete by pressing Tab in clickhouse - client . [ Sergey Shcherbin ] ( https : / / github . com / yandex / ClickHouse / pull / 2447 ) <nl> * Ctrl + C in clickhouse - client clears a query that was entered . [ # 2877 ] ( https : / / github . com / yandex / ClickHouse / pull / 2877 ) <nl> <nl> <nl> # # # Backward incompatible changes : <nl> <nl> - * In requests with JOIN , the star character expands to a list of columns in all tables , in compliance with the SQL standard . You can restore the old behavior by setting ` asterisk_left_columns_only ` to 1 on the user configuration level . <nl> + * In queries with JOIN , the star character expands to a list of columns in all tables , in compliance with the SQL standard . You can restore the old behavior by setting ` asterisk_left_columns_only ` to 1 on the user configuration level . <nl> <nl> # # # Build changes : <nl> <nl> <nl> * Fixed an error for concurrent ` Set ` or ` Join ` . [ Amos Bird ] ( https : / / github . com / yandex / ClickHouse / pull / 2823 ) <nl> * Fixed the ` Block structure mismatch in UNION stream : different number of columns ` error that occurred for ` UNION ALL ` queries inside a sub - query if one of the ` SELECT ` queries contains duplicate column names . [ Winter Zhang ] ( https : / / github . com / yandex / ClickHouse / pull / 2094 ) <nl> * Fixed a memory leak if an exception occurred when connecting to a MySQL server . <nl> - * Fixed incorrect clickhouse - client response code in case of a request error . <nl> + * Fixed incorrect clickhouse - client response code in case of a query error . <nl> * Fixed incorrect behavior of materialized views containing DISTINCT . [ # 2795 ] ( https : / / github . com / yandex / ClickHouse / issues / 2795 ) <nl> <nl> # # # Backward incompatible changes <nl> The expression must be a chain of equalities joined by the AND operator . Each si <nl> * Fixed a problem with a very small timeout for sockets ( one second ) for reading and writing when sending and downloading replicated data , which made it impossible to download larger parts if there is a load on the network or disk ( it resulted in cyclical attempts to download parts ) . This error occurred in version 1 . 1 . 54388 . <nl> * Fixed issues when using chroot in ZooKeeper if you inserted duplicate data blocks in the table . <nl> * The ` has ` function now works correctly for an array with Nullable elements ( [ # 2115 ] ( https : / / github . com / yandex / ClickHouse / issues / 2115 ) ) . <nl> - * The ` system . tables ` table now works correctly when used in distributed queries . The ` metadata_modification_time ` and ` engine_full ` columns are now non - virtual . Fixed an error that occurred if only these columns were requested from the table . <nl> + * The ` system . tables ` table now works correctly when used in distributed queries . The ` metadata_modification_time ` and ` engine_full ` columns are now non - virtual . Fixed an error that occurred if only these columns were queried from the table . <nl> * Fixed how an empty ` TinyLog ` table works after inserting an empty data block ( [ # 2563 ] ( https : / / github . com / yandex / ClickHouse / issues / 2563 ) ) . <nl> * The ` system . zookeeper ` table works if the value of the node in ZooKeeper is NULL . <nl> <nl> The expression must be a chain of equalities joined by the AND operator . Each si <nl> * Added the ` parseDateTimeBestEffort ` , ` parseDateTimeBestEffortOrZero ` , and ` parseDateTimeBestEffortOrNull ` functions to read the DateTime from a string containing text in a wide variety of possible formats . <nl> * Data can be partially reloaded from external dictionaries during updating ( load just the records in which the value of the specified field greater than in the previous download ) ( Arsen Hakobyan ) . <nl> * Added the ` cluster ` table function . Example : ` cluster ( cluster_name , db , table ) ` . The ` remote ` table function can accept the cluster name as the first argument , if it is specified as an identifier . <nl> - * The ` remote ` and ` cluster ` table functions can be used in ` INSERT ` requests . <nl> + * The ` remote ` and ` cluster ` table functions can be used in ` INSERT ` queries . <nl> * Added the ` create_table_query ` and ` engine_full ` virtual columns to the ` system . tables ` table . The ` metadata_modification_time ` column is virtual . <nl> * Added the ` data_path ` and ` metadata_path ` columns to ` system . tables ` and ` system . databases ` tables , and added the ` path ` column to the ` system . parts ` and ` system . parts_columns ` tables . <nl> * Added additional information about merges in the ` system . part_log ` table . <nl> This release contains bug fixes for the previous release 1 . 1 . 54310 : <nl> <nl> # # # Please note when upgrading : <nl> <nl> - * There is now a higher default value for the MergeTree setting ` max_bytes_to_merge_at_max_space_in_pool ` ( the maximum total size of data parts to merge , in bytes ) : it has increased from 100 GiB to 150 GiB . This might result in large merges running after the server upgrade , which could cause an increased load on the disk subsystem . If the free space available on the server is less than twice the total amount of the merges that are running , this will cause all other merges to stop running , including merges of small data parts . As a result , INSERT requests will fail with the message " Merges are processing significantly slower than inserts . " Use the ` SELECT * FROM system . merges ` request to monitor the situation . You can also check the ` DiskSpaceReservedForMerge ` metric in the ` system . metrics ` table , or in Graphite . You don ' t need to do anything to fix this , since the issue will resolve itself once the large merges finish . If you find this unacceptable , you can restore the previous value for the ` max_bytes_to_merge_at_max_space_in_pool ` setting . To do this , go to the < merge_tree > section in config . xml , set ` < merge_tree > ` ` < max_bytes_to_merge_at_max_space_in_pool > 107374182400 < / max_bytes_to_merge_at_max_space_in_pool > ` and restart the server . <nl> + * There is now a higher default value for the MergeTree setting ` max_bytes_to_merge_at_max_space_in_pool ` ( the maximum total size of data parts to merge , in bytes ) : it has increased from 100 GiB to 150 GiB . This might result in large merges running after the server upgrade , which could cause an increased load on the disk subsystem . If the free space available on the server is less than twice the total amount of the merges that are running , this will cause all other merges to stop running , including merges of small data parts . As a result , INSERT queries will fail with the message " Merges are processing significantly slower than inserts . " Use the ` SELECT * FROM system . merges ` query to monitor the situation . You can also check the ` DiskSpaceReservedForMerge ` metric in the ` system . metrics ` table , or in Graphite . You don ' t need to do anything to fix this , since the issue will resolve itself once the large merges finish . If you find this unacceptable , you can restore the previous value for the ` max_bytes_to_merge_at_max_space_in_pool ` setting . To do this , go to the < merge_tree > section in config . xml , set ` < merge_tree > ` ` < max_bytes_to_merge_at_max_space_in_pool > 107374182400 < / max_bytes_to_merge_at_max_space_in_pool > ` and restart the server . <nl> <nl> # # ClickHouse release 1 . 1 . 54284 , 2017 - 08 - 29 <nl> <nl> This release contains bug fixes for the previous release 1 . 1 . 54276 : <nl> # # # New features : <nl> <nl> * Distributed DDL ( for example , ` CREATE TABLE ON CLUSTER ` ) <nl> - * The replicated request ` ALTER TABLE CLEAR COLUMN IN PARTITION . ` <nl> + * The replicated query ` ALTER TABLE CLEAR COLUMN IN PARTITION . ` <nl> * The engine for Dictionary tables ( access to dictionary data in the form of a table ) . <nl> * Dictionary database engine ( this type of database automatically has Dictionary tables available for all the connected external dictionaries ) . <nl> * You can check for updates to the dictionary by sending a request to the source . <nl>
Update CHANGELOG . md
ClickHouse/ClickHouse
6c84afeb0f08166657770e12e06363a901863c61
2018-12-20T19:37:47Z
mmm a / xbmc / cores / VideoPlayer / DVDDemuxers / DVDDemuxFFmpeg . cpp <nl> ppp b / xbmc / cores / VideoPlayer / DVDDemuxers / DVDDemuxFFmpeg . cpp <nl> AVDictionary * CDVDDemuxFFmpeg : : GetFFMpegOptionsFromInput ( ) <nl> { <nl> if ( value [ 0 ] = = " swfurl " | | value [ 0 ] = = " SWFPlayer " ) <nl> swfurl = value [ 1 ] ; <nl> - if ( value [ 0 ] = = " swfvfy " & & ( value [ 1 ] = = " true " | | value [ 1 ] = = " 1 " ) ) <nl> + if ( value [ 0 ] = = " swfvfy " & & ( value [ 1 ] = = " true " | | value [ 1 ] = = " 1 " ) ) <nl> swfvfy = true ; <nl> else <nl> av_dict_set ( & options , it - > second . c_str ( ) , value [ 1 ] . c_str ( ) , 0 ) ; <nl>
Merge pull request from fritsch / whitespace
xbmc/xbmc
8b194aa95875c3cb20321baf07d2e196b4c851b1
2016-11-01T10:56:14Z
mmm a / src / ruby / bin / interop / interop_client . rb <nl> ppp b / src / ruby / bin / interop / interop_client . rb <nl> def test_creds <nl> end <nl> <nl> # creates a test stub that accesses host : port securely . <nl> - def create_stub ( host , port ) <nl> + def create_stub ( host , port , is_secure ) <nl> address = " # { host } : # { port } " <nl> - stub_opts = { <nl> - : creds = > test_creds , <nl> - GRPC : : Core : : Channel : : SSL_TARGET = > ' foo . test . google . com ' <nl> - } <nl> - logger . info ( " . . . connecting securely to # { address } " ) <nl> - Grpc : : Testing : : TestService : : Stub . new ( address , * * stub_opts ) <nl> + if is_secure <nl> + stub_opts = { <nl> + : creds = > test_creds , <nl> + GRPC : : Core : : Channel : : SSL_TARGET = > ' foo . test . google . com ' <nl> + } <nl> + logger . info ( " . . . connecting securely to # { address } " ) <nl> + Grpc : : Testing : : TestService : : Stub . new ( address , * * stub_opts ) <nl> + else <nl> + logger . info ( " . . . connecting insecurely to # { address } " ) <nl> + Grpc : : Testing : : TestService : : Stub . new ( address ) <nl> + end <nl> end <nl> <nl> # produces a string of null chars ( \ 0 ) of length l . <nl> def ping_pong <nl> # validates the the command line options , returning them as a Hash . <nl> def parse_options <nl> options = { <nl> + ' secure ' = > false , <nl> ' server_host ' = > nil , <nl> ' server_port ' = > nil , <nl> ' test_case ' = > nil <nl> def parse_options <nl> " ( # { test_case_list } ) " ) do | v | <nl> options [ ' test_case ' ] = v <nl> end <nl> + opts . on ( ' - u ' , ' - - use_tls ' , ' access using test creds ' ) do | v | <nl> + options [ ' secure ' ] = v <nl> + end <nl> end . parse ! <nl> <nl> % w ( server_host server_port test_case ) . each do | arg | <nl> def parse_options <nl> <nl> def main <nl> opts = parse_options <nl> - stub = create_stub ( opts [ ' server_host ' ] , opts [ ' server_port ' ] ) <nl> + stub = create_stub ( opts [ ' server_host ' ] , opts [ ' server_port ' ] , opts [ ' secure ' ] ) <nl> NamedTests . new ( stub ) . method ( opts [ ' test_case ' ] ) . call <nl> end <nl> <nl> mmm a / src / ruby / bin / interop / interop_server . rb <nl> ppp b / src / ruby / bin / interop / interop_server . rb <nl> def half_duplex_call ( reqs ) <nl> # validates the the command line options , returning them as a Hash . <nl> def parse_options <nl> options = { <nl> - ' port ' = > nil <nl> + ' port ' = > nil , <nl> + ' secure ' = > false <nl> } <nl> OptionParser . new do | opts | <nl> opts . banner = ' Usage : - - port port ' <nl> opts . on ( ' - - port PORT ' , ' server port ' ) do | v | <nl> options [ ' port ' ] = v <nl> end <nl> + opts . on ( ' - u ' , ' - - use_tls ' , ' access using test creds ' ) do | v | <nl> + options [ ' secure ' ] = v <nl> + end <nl> + <nl> end . parse ! <nl> <nl> if options [ ' port ' ] . nil ? <nl> def parse_options <nl> def main <nl> opts = parse_options <nl> host = " 0 . 0 . 0 . 0 : # { opts [ ' port ' ] } " <nl> - s = GRPC : : RpcServer . new ( creds : test_server_creds ) <nl> - s . add_http2_port ( host , true ) <nl> - logger . info ( " . . . running securely on # { host } " ) <nl> - <nl> + if opts [ ' secure ' ] <nl> + s = GRPC : : RpcServer . new ( creds : test_server_creds ) <nl> + s . add_http2_port ( host , true ) <nl> + logger . info ( " . . . running securely on # { host } " ) <nl> + else <nl> + s = GRPC : : RpcServer . new <nl> + s . add_http2_port ( host ) <nl> + logger . info ( " . . . running insecurely on # { host } " ) <nl> + end <nl> s . handle ( TestTarget ) <nl> s . run <nl> end <nl>
Added the use_tls flag toggle connecting securely
grpc/grpc
9cae580877947652f6a3edcfd4ec1a043556f4df
2015-01-27T03:05:16Z
mmm a / googletest / scripts / gen_gtest_pred_impl . py <nl> ppp b / googletest / scripts / gen_gtest_pred_impl . py <nl> def TestsForArity ( n ) : <nl> return % ( v_sum ) s > 0 ; <nl> } <nl> <nl> - / / The following two functions are needed to circumvent a bug in <nl> - / / gcc 2 . 95 . 3 , which sometimes has problem with the above template <nl> - / / function . <nl> + / / The following two functions are needed because a compiler doesn ' t have <nl> + / / a context yet to know which template function must be instantiated . <nl> bool PredFunction % ( n ) sInt ( % ( int_vs ) s ) { <nl> return % ( v_sum ) s > 0 ; <nl> } <nl> mmm a / googletest / test / gtest_pred_impl_unittest . cc <nl> ppp b / googletest / test / gtest_pred_impl_unittest . cc <nl> <nl> / / ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE <nl> / / OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE . <nl> <nl> - / / This file is AUTOMATICALLY GENERATED on 01 / 02 / 2019 by command <nl> + / / This file is AUTOMATICALLY GENERATED on 11 / 05 / 2019 by command <nl> / / ' gen_gtest_pred_impl . py 5 ' . DO NOT EDIT BY HAND ! <nl> <nl> / / Regression test for gtest_pred_impl . h <nl> bool PredFunction1 ( T1 v1 ) { <nl> return v1 > 0 ; <nl> } <nl> <nl> - / / The following two functions are needed to circumvent a bug in <nl> - / / gcc 2 . 95 . 3 , which sometimes has problem with the above template <nl> - / / function . <nl> + / / The following two functions are needed because a compiler doesn ' t have <nl> + / / a context yet to know which template function must be instantiated . <nl> bool PredFunction1Int ( int v1 ) { <nl> return v1 > 0 ; <nl> } <nl> bool PredFunction2 ( T1 v1 , T2 v2 ) { <nl> return v1 + v2 > 0 ; <nl> } <nl> <nl> - / / The following two functions are needed to circumvent a bug in <nl> - / / gcc 2 . 95 . 3 , which sometimes has problem with the above template <nl> - / / function . <nl> + / / The following two functions are needed because a compiler doesn ' t have <nl> + / / a context yet to know which template function must be instantiated . <nl> bool PredFunction2Int ( int v1 , int v2 ) { <nl> return v1 + v2 > 0 ; <nl> } <nl> bool PredFunction3 ( T1 v1 , T2 v2 , T3 v3 ) { <nl> return v1 + v2 + v3 > 0 ; <nl> } <nl> <nl> - / / The following two functions are needed to circumvent a bug in <nl> - / / gcc 2 . 95 . 3 , which sometimes has problem with the above template <nl> - / / function . <nl> + / / The following two functions are needed because a compiler doesn ' t have <nl> + / / a context yet to know which template function must be instantiated . <nl> bool PredFunction3Int ( int v1 , int v2 , int v3 ) { <nl> return v1 + v2 + v3 > 0 ; <nl> } <nl> bool PredFunction4 ( T1 v1 , T2 v2 , T3 v3 , T4 v4 ) { <nl> return v1 + v2 + v3 + v4 > 0 ; <nl> } <nl> <nl> - / / The following two functions are needed to circumvent a bug in <nl> - / / gcc 2 . 95 . 3 , which sometimes has problem with the above template <nl> - / / function . <nl> + / / The following two functions are needed because a compiler doesn ' t have <nl> + / / a context yet to know which template function must be instantiated . <nl> bool PredFunction4Int ( int v1 , int v2 , int v3 , int v4 ) { <nl> return v1 + v2 + v3 + v4 > 0 ; <nl> } <nl> bool PredFunction5 ( T1 v1 , T2 v2 , T3 v3 , T4 v4 , T5 v5 ) { <nl> return v1 + v2 + v3 + v4 + v5 > 0 ; <nl> } <nl> <nl> - / / The following two functions are needed to circumvent a bug in <nl> - / / gcc 2 . 95 . 3 , which sometimes has problem with the above template <nl> - / / function . <nl> + / / The following two functions are needed because a compiler doesn ' t have <nl> + / / a context yet to know which template function must be instantiated . <nl> bool PredFunction5Int ( int v1 , int v2 , int v3 , int v4 , int v5 ) { <nl> return v1 + v2 + v3 + v4 + v5 > 0 ; <nl> } <nl>
Merge pull request from kuzkry : remove - workaround_g + + - incorrect - comments
google/googletest
a32a2000947300720264205e0de88eee729f6b48
2019-11-26T20:46:55Z
mmm a / core / variant / variant_internal . h <nl> ppp b / core / variant / variant_internal . h <nl> <nl> class VariantInternal { <nl> public : <nl> / / Set type . <nl> - _FORCE_INLINE_ static void initialize ( Variant * v , Variant : : Type p_type ) { v - > type = p_type ; } <nl> + _FORCE_INLINE_ static void initialize ( Variant * v , Variant : : Type p_type ) { <nl> + v - > clear ( ) ; <nl> + v - > type = p_type ; <nl> + <nl> + switch ( p_type ) { <nl> + case Variant : : AABB : <nl> + init_aabb ( v ) ; <nl> + break ; <nl> + case Variant : : TRANSFORM2D : <nl> + init_transform2d ( v ) ; <nl> + break ; <nl> + case Variant : : TRANSFORM : <nl> + init_transform ( v ) ; <nl> + break ; <nl> + case Variant : : STRING : <nl> + init_string ( v ) ; <nl> + break ; <nl> + case Variant : : STRING_NAME : <nl> + init_string_name ( v ) ; <nl> + break ; <nl> + case Variant : : NODE_PATH : <nl> + init_node_path ( v ) ; <nl> + break ; <nl> + case Variant : : CALLABLE : <nl> + init_callable ( v ) ; <nl> + break ; <nl> + case Variant : : SIGNAL : <nl> + init_signal ( v ) ; <nl> + break ; <nl> + case Variant : : DICTIONARY : <nl> + init_dictionary ( v ) ; <nl> + break ; <nl> + case Variant : : ARRAY : <nl> + init_array ( v ) ; <nl> + break ; <nl> + case Variant : : PACKED_BYTE_ARRAY : <nl> + init_byte_array ( v ) ; <nl> + break ; <nl> + case Variant : : PACKED_INT32_ARRAY : <nl> + init_int32_array ( v ) ; <nl> + break ; <nl> + case Variant : : PACKED_INT64_ARRAY : <nl> + init_int64_array ( v ) ; <nl> + break ; <nl> + case Variant : : PACKED_FLOAT32_ARRAY : <nl> + init_float32_array ( v ) ; <nl> + break ; <nl> + case Variant : : PACKED_FLOAT64_ARRAY : <nl> + init_float64_array ( v ) ; <nl> + break ; <nl> + case Variant : : PACKED_STRING_ARRAY : <nl> + init_string_array ( v ) ; <nl> + break ; <nl> + case Variant : : PACKED_VECTOR2_ARRAY : <nl> + init_vector2_array ( v ) ; <nl> + break ; <nl> + case Variant : : PACKED_VECTOR3_ARRAY : <nl> + init_vector3_array ( v ) ; <nl> + break ; <nl> + case Variant : : PACKED_COLOR_ARRAY : <nl> + init_color_array ( v ) ; <nl> + break ; <nl> + default : <nl> + break ; <nl> + } <nl> + } <nl> + <nl> + _FORCE_INLINE_ static void set_object ( Variant * v , Object * obj ) { <nl> + if ( obj ) { <nl> + v - > _get_obj ( ) . obj = obj ; <nl> + v - > _get_obj ( ) . id = obj - > get_instance_id ( ) ; <nl> + } else { <nl> + v - > _get_obj ( ) . obj = nullptr ; <nl> + v - > _get_obj ( ) . id = ObjectID ( ) ; <nl> + } <nl> + } <nl> <nl> / / Atomic types . <nl> _FORCE_INLINE_ static bool * get_bool ( Variant * v ) { return & v - > _data . _bool ; } <nl> class VariantInternal { <nl> v - > _get_obj ( ) . obj = nullptr ; <nl> v - > _get_obj ( ) . id = ObjectID ( ) ; <nl> } <nl> + <nl> + _FORCE_INLINE_ static void * get_opaque_pointer ( Variant * v ) { <nl> + switch ( v - > type ) { <nl> + case Variant : : NIL : <nl> + return nullptr ; <nl> + case Variant : : BOOL : <nl> + return get_bool ( v ) ; <nl> + case Variant : : INT : <nl> + return get_int ( v ) ; <nl> + case Variant : : FLOAT : <nl> + return get_float ( v ) ; <nl> + case Variant : : STRING : <nl> + return get_string ( v ) ; <nl> + case Variant : : VECTOR2 : <nl> + return get_vector2 ( v ) ; <nl> + case Variant : : VECTOR2I : <nl> + return get_vector2i ( v ) ; <nl> + case Variant : : VECTOR3 : <nl> + return get_vector3 ( v ) ; <nl> + case Variant : : VECTOR3I : <nl> + return get_vector3i ( v ) ; <nl> + case Variant : : RECT2 : <nl> + return get_rect2 ( v ) ; <nl> + case Variant : : RECT2I : <nl> + return get_rect2i ( v ) ; <nl> + case Variant : : TRANSFORM : <nl> + return get_transform ( v ) ; <nl> + case Variant : : TRANSFORM2D : <nl> + return get_transform2d ( v ) ; <nl> + case Variant : : QUAT : <nl> + return get_quat ( v ) ; <nl> + case Variant : : PLANE : <nl> + return get_plane ( v ) ; <nl> + case Variant : : BASIS : <nl> + return get_basis ( v ) ; <nl> + case Variant : : AABB : <nl> + return get_aabb ( v ) ; <nl> + case Variant : : COLOR : <nl> + return get_color ( v ) ; <nl> + case Variant : : STRING_NAME : <nl> + return get_string_name ( v ) ; <nl> + case Variant : : NODE_PATH : <nl> + return get_node_path ( v ) ; <nl> + case Variant : : RID : <nl> + return get_rid ( v ) ; <nl> + case Variant : : CALLABLE : <nl> + return get_callable ( v ) ; <nl> + case Variant : : SIGNAL : <nl> + return get_signal ( v ) ; <nl> + case Variant : : DICTIONARY : <nl> + return get_dictionary ( v ) ; <nl> + case Variant : : ARRAY : <nl> + return get_array ( v ) ; <nl> + case Variant : : PACKED_BYTE_ARRAY : <nl> + return get_byte_array ( v ) ; <nl> + case Variant : : PACKED_INT32_ARRAY : <nl> + return get_int32_array ( v ) ; <nl> + case Variant : : PACKED_INT64_ARRAY : <nl> + return get_int64_array ( v ) ; <nl> + case Variant : : PACKED_FLOAT32_ARRAY : <nl> + return get_float32_array ( v ) ; <nl> + case Variant : : PACKED_FLOAT64_ARRAY : <nl> + return get_float64_array ( v ) ; <nl> + case Variant : : PACKED_STRING_ARRAY : <nl> + return get_string_array ( v ) ; <nl> + case Variant : : PACKED_VECTOR2_ARRAY : <nl> + return get_vector2_array ( v ) ; <nl> + case Variant : : PACKED_VECTOR3_ARRAY : <nl> + return get_vector3_array ( v ) ; <nl> + case Variant : : PACKED_COLOR_ARRAY : <nl> + return get_color_array ( v ) ; <nl> + case Variant : : OBJECT : <nl> + return v - > _get_obj ( ) . obj ; <nl> + case Variant : : VARIANT_MAX : <nl> + ERR_FAIL_V ( nullptr ) ; <nl> + } <nl> + ERR_FAIL_V ( nullptr ) ; <nl> + } <nl> + <nl> + _FORCE_INLINE_ static const void * get_opaque_pointer ( const Variant * v ) { <nl> + switch ( v - > type ) { <nl> + case Variant : : NIL : <nl> + return nullptr ; <nl> + case Variant : : BOOL : <nl> + return get_bool ( v ) ; <nl> + case Variant : : INT : <nl> + return get_int ( v ) ; <nl> + case Variant : : FLOAT : <nl> + return get_float ( v ) ; <nl> + case Variant : : STRING : <nl> + return get_string ( v ) ; <nl> + case Variant : : VECTOR2 : <nl> + return get_vector2 ( v ) ; <nl> + case Variant : : VECTOR2I : <nl> + return get_vector2i ( v ) ; <nl> + case Variant : : VECTOR3 : <nl> + return get_vector3 ( v ) ; <nl> + case Variant : : VECTOR3I : <nl> + return get_vector3i ( v ) ; <nl> + case Variant : : RECT2 : <nl> + return get_rect2 ( v ) ; <nl> + case Variant : : RECT2I : <nl> + return get_rect2i ( v ) ; <nl> + case Variant : : TRANSFORM : <nl> + return get_transform ( v ) ; <nl> + case Variant : : TRANSFORM2D : <nl> + return get_transform2d ( v ) ; <nl> + case Variant : : QUAT : <nl> + return get_quat ( v ) ; <nl> + case Variant : : PLANE : <nl> + return get_plane ( v ) ; <nl> + case Variant : : BASIS : <nl> + return get_basis ( v ) ; <nl> + case Variant : : AABB : <nl> + return get_aabb ( v ) ; <nl> + case Variant : : COLOR : <nl> + return get_color ( v ) ; <nl> + case Variant : : STRING_NAME : <nl> + return get_string_name ( v ) ; <nl> + case Variant : : NODE_PATH : <nl> + return get_node_path ( v ) ; <nl> + case Variant : : RID : <nl> + return get_rid ( v ) ; <nl> + case Variant : : CALLABLE : <nl> + return get_callable ( v ) ; <nl> + case Variant : : SIGNAL : <nl> + return get_signal ( v ) ; <nl> + case Variant : : DICTIONARY : <nl> + return get_dictionary ( v ) ; <nl> + case Variant : : ARRAY : <nl> + return get_array ( v ) ; <nl> + case Variant : : PACKED_BYTE_ARRAY : <nl> + return get_byte_array ( v ) ; <nl> + case Variant : : PACKED_INT32_ARRAY : <nl> + return get_int32_array ( v ) ; <nl> + case Variant : : PACKED_INT64_ARRAY : <nl> + return get_int64_array ( v ) ; <nl> + case Variant : : PACKED_FLOAT32_ARRAY : <nl> + return get_float32_array ( v ) ; <nl> + case Variant : : PACKED_FLOAT64_ARRAY : <nl> + return get_float64_array ( v ) ; <nl> + case Variant : : PACKED_STRING_ARRAY : <nl> + return get_string_array ( v ) ; <nl> + case Variant : : PACKED_VECTOR2_ARRAY : <nl> + return get_vector2_array ( v ) ; <nl> + case Variant : : PACKED_VECTOR3_ARRAY : <nl> + return get_vector3_array ( v ) ; <nl> + case Variant : : PACKED_COLOR_ARRAY : <nl> + return get_color_array ( v ) ; <nl> + case Variant : : OBJECT : <nl> + return v - > _get_obj ( ) . obj ; <nl> + case Variant : : VARIANT_MAX : <nl> + ERR_FAIL_V ( nullptr ) ; <nl> + } <nl> + ERR_FAIL_V ( nullptr ) ; <nl> + } <nl> } ; <nl> <nl> template < class T > <nl> mmm a / modules / gdscript / gdscript_byte_codegen . cpp <nl> ppp b / modules / gdscript / gdscript_byte_codegen . cpp <nl> void GDScriptByteCodeGenerator : : write_start ( GDScript * p_script , const StringName <nl> } <nl> <nl> GDScriptFunction * GDScriptByteCodeGenerator : : write_end ( ) { <nl> - append ( GDScriptFunction : : OPCODE_END ) ; <nl> + append ( GDScriptFunction : : OPCODE_END , 0 ) ; <nl> <nl> if ( constant_map . size ( ) ) { <nl> function - > _constant_count = constant_map . size ( ) ; <nl> GDScriptFunction * GDScriptByteCodeGenerator : : write_end ( ) { <nl> function - > _default_arg_ptr = nullptr ; <nl> } <nl> <nl> + if ( operator_func_map . size ( ) ) { <nl> + function - > operator_funcs . resize ( operator_func_map . size ( ) ) ; <nl> + function - > _operator_funcs_count = function - > operator_funcs . size ( ) ; <nl> + function - > _operator_funcs_ptr = function - > operator_funcs . ptr ( ) ; <nl> + for ( const Map < Variant : : ValidatedOperatorEvaluator , int > : : Element * E = operator_func_map . front ( ) ; E ; E = E - > next ( ) ) { <nl> + function - > operator_funcs . write [ E - > get ( ) ] = E - > key ( ) ; <nl> + } <nl> + } else { <nl> + function - > _operator_funcs_count = 0 ; <nl> + function - > _operator_funcs_ptr = nullptr ; <nl> + } <nl> + <nl> + if ( setters_map . size ( ) ) { <nl> + function - > setters . resize ( setters_map . size ( ) ) ; <nl> + function - > _setters_count = function - > setters . size ( ) ; <nl> + function - > _setters_ptr = function - > setters . ptr ( ) ; <nl> + for ( const Map < Variant : : ValidatedSetter , int > : : Element * E = setters_map . front ( ) ; E ; E = E - > next ( ) ) { <nl> + function - > setters . write [ E - > get ( ) ] = E - > key ( ) ; <nl> + } <nl> + } else { <nl> + function - > _setters_count = 0 ; <nl> + function - > _setters_ptr = nullptr ; <nl> + } <nl> + <nl> + if ( getters_map . size ( ) ) { <nl> + function - > getters . resize ( getters_map . size ( ) ) ; <nl> + function - > _getters_count = function - > getters . size ( ) ; <nl> + function - > _getters_ptr = function - > getters . ptr ( ) ; <nl> + for ( const Map < Variant : : ValidatedGetter , int > : : Element * E = getters_map . front ( ) ; E ; E = E - > next ( ) ) { <nl> + function - > getters . write [ E - > get ( ) ] = E - > key ( ) ; <nl> + } <nl> + } else { <nl> + function - > _getters_count = 0 ; <nl> + function - > _getters_ptr = nullptr ; <nl> + } <nl> + <nl> + if ( keyed_setters_map . size ( ) ) { <nl> + function - > keyed_setters . resize ( keyed_setters_map . size ( ) ) ; <nl> + function - > _keyed_setters_count = function - > keyed_setters . size ( ) ; <nl> + function - > _keyed_setters_ptr = function - > keyed_setters . ptr ( ) ; <nl> + for ( const Map < Variant : : ValidatedKeyedSetter , int > : : Element * E = keyed_setters_map . front ( ) ; E ; E = E - > next ( ) ) { <nl> + function - > keyed_setters . write [ E - > get ( ) ] = E - > key ( ) ; <nl> + } <nl> + } else { <nl> + function - > _keyed_setters_count = 0 ; <nl> + function - > _keyed_setters_ptr = nullptr ; <nl> + } <nl> + <nl> + if ( keyed_getters_map . size ( ) ) { <nl> + function - > keyed_getters . resize ( keyed_getters_map . size ( ) ) ; <nl> + function - > _keyed_getters_count = function - > keyed_getters . size ( ) ; <nl> + function - > _keyed_getters_ptr = function - > keyed_getters . ptr ( ) ; <nl> + for ( const Map < Variant : : ValidatedKeyedGetter , int > : : Element * E = keyed_getters_map . front ( ) ; E ; E = E - > next ( ) ) { <nl> + function - > keyed_getters . write [ E - > get ( ) ] = E - > key ( ) ; <nl> + } <nl> + } else { <nl> + function - > _keyed_getters_count = 0 ; <nl> + function - > _keyed_getters_ptr = nullptr ; <nl> + } <nl> + <nl> + if ( indexed_setters_map . size ( ) ) { <nl> + function - > indexed_setters . resize ( indexed_setters_map . size ( ) ) ; <nl> + function - > _indexed_setters_count = function - > indexed_setters . size ( ) ; <nl> + function - > _indexed_setters_ptr = function - > indexed_setters . ptr ( ) ; <nl> + for ( const Map < Variant : : ValidatedIndexedSetter , int > : : Element * E = indexed_setters_map . front ( ) ; E ; E = E - > next ( ) ) { <nl> + function - > indexed_setters . write [ E - > get ( ) ] = E - > key ( ) ; <nl> + } <nl> + } else { <nl> + function - > _indexed_setters_count = 0 ; <nl> + function - > _indexed_setters_ptr = nullptr ; <nl> + } <nl> + <nl> + if ( indexed_getters_map . size ( ) ) { <nl> + function - > indexed_getters . resize ( indexed_getters_map . size ( ) ) ; <nl> + function - > _indexed_getters_count = function - > indexed_getters . size ( ) ; <nl> + function - > _indexed_getters_ptr = function - > indexed_getters . ptr ( ) ; <nl> + for ( const Map < Variant : : ValidatedIndexedGetter , int > : : Element * E = indexed_getters_map . front ( ) ; E ; E = E - > next ( ) ) { <nl> + function - > indexed_getters . write [ E - > get ( ) ] = E - > key ( ) ; <nl> + } <nl> + } else { <nl> + function - > _indexed_getters_count = 0 ; <nl> + function - > _indexed_getters_ptr = nullptr ; <nl> + } <nl> + <nl> + if ( builtin_method_map . size ( ) ) { <nl> + function - > builtin_methods . resize ( builtin_method_map . size ( ) ) ; <nl> + function - > _builtin_methods_ptr = function - > builtin_methods . ptr ( ) ; <nl> + function - > _builtin_methods_count = builtin_method_map . size ( ) ; <nl> + for ( const Map < Variant : : ValidatedBuiltInMethod , int > : : Element * E = builtin_method_map . front ( ) ; E ; E = E - > next ( ) ) { <nl> + function - > builtin_methods . write [ E - > get ( ) ] = E - > key ( ) ; <nl> + } <nl> + } else { <nl> + function - > _builtin_methods_ptr = nullptr ; <nl> + function - > _builtin_methods_count = 0 ; <nl> + } <nl> + <nl> + if ( constructors_map . size ( ) ) { <nl> + function - > constructors . resize ( constructors_map . size ( ) ) ; <nl> + function - > _constructors_ptr = function - > constructors . ptr ( ) ; <nl> + function - > _constructors_count = constructors_map . size ( ) ; <nl> + for ( const Map < Variant : : ValidatedConstructor , int > : : Element * E = constructors_map . front ( ) ; E ; E = E - > next ( ) ) { <nl> + function - > constructors . write [ E - > get ( ) ] = E - > key ( ) ; <nl> + } <nl> + } else { <nl> + function - > _constructors_ptr = nullptr ; <nl> + function - > _constructors_count = 0 ; <nl> + } <nl> + <nl> + if ( method_bind_map . size ( ) ) { <nl> + function - > methods . resize ( method_bind_map . size ( ) ) ; <nl> + function - > _methods_ptr = function - > methods . ptrw ( ) ; <nl> + function - > _methods_count = method_bind_map . size ( ) ; <nl> + for ( const Map < MethodBind * , int > : : Element * E = method_bind_map . front ( ) ; E ; E = E - > next ( ) ) { <nl> + function - > methods . write [ E - > get ( ) ] = E - > key ( ) ; <nl> + } <nl> + } else { <nl> + function - > _methods_ptr = nullptr ; <nl> + function - > _methods_count = 0 ; <nl> + } <nl> + <nl> if ( debug_stack ) { <nl> function - > stack_debug = stack_debug ; <nl> } <nl> function - > _stack_size = stack_max ; <nl> - function - > _call_size = call_max ; <nl> + function - > _instruction_args_size = instr_args_max ; <nl> + function - > _ptrcall_args_size = ptrcall_max ; <nl> <nl> ended = true ; <nl> return function ; <nl> void GDScriptByteCodeGenerator : : set_initial_line ( int p_line ) { <nl> function - > _initial_line = p_line ; <nl> } <nl> <nl> + # define HAS_BUILTIN_TYPE ( m_var ) \ <nl> + ( m_var . type . has_type & & m_var . type . kind = = GDScriptDataType : : BUILTIN ) <nl> + <nl> + # define IS_BUILTIN_TYPE ( m_var , m_type ) \ <nl> + ( m_var . type . has_type & & m_var . type . kind = = GDScriptDataType : : BUILTIN & & m_var . type . builtin_type = = m_type ) <nl> + <nl> void GDScriptByteCodeGenerator : : write_operator ( const Address & p_target , Variant : : Operator p_operator , const Address & p_left_operand , const Address & p_right_operand ) { <nl> - append ( GDScriptFunction : : OPCODE_OPERATOR ) ; <nl> - append ( p_operator ) ; <nl> + if ( HAS_BUILTIN_TYPE ( p_left_operand ) & & HAS_BUILTIN_TYPE ( p_right_operand ) ) { <nl> + / / Gather specific operator . <nl> + Variant : : ValidatedOperatorEvaluator op_func = Variant : : get_validated_operator_evaluator ( p_operator , p_left_operand . type . builtin_type , p_right_operand . type . builtin_type ) ; <nl> + <nl> + append ( GDScriptFunction : : OPCODE_OPERATOR_VALIDATED , 3 ) ; <nl> + append ( p_left_operand ) ; <nl> + append ( p_right_operand ) ; <nl> + append ( p_target ) ; <nl> + append ( op_func ) ; <nl> + return ; <nl> + } <nl> + <nl> + / / No specific types , perform variant evaluation . <nl> + append ( GDScriptFunction : : OPCODE_OPERATOR , 3 ) ; <nl> append ( p_left_operand ) ; <nl> append ( p_right_operand ) ; <nl> append ( p_target ) ; <nl> + append ( p_operator ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_type_test ( const Address & p_target , const Address & p_source , const Address & p_type ) { <nl> - append ( GDScriptFunction : : OPCODE_EXTENDS_TEST ) ; <nl> + append ( GDScriptFunction : : OPCODE_EXTENDS_TEST , 3 ) ; <nl> append ( p_source ) ; <nl> append ( p_type ) ; <nl> append ( p_target ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_type_test_builtin ( const Address & p_target , const Address & p_source , Variant : : Type p_type ) { <nl> - append ( GDScriptFunction : : OPCODE_IS_BUILTIN ) ; <nl> + append ( GDScriptFunction : : OPCODE_IS_BUILTIN , 3 ) ; <nl> append ( p_source ) ; <nl> - append ( p_type ) ; <nl> append ( p_target ) ; <nl> + append ( p_type ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_and_left_operand ( const Address & p_left_operand ) { <nl> - append ( GDScriptFunction : : OPCODE_JUMP_IF_NOT ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP_IF_NOT , 1 ) ; <nl> append ( p_left_operand ) ; <nl> logic_op_jump_pos1 . push_back ( opcodes . size ( ) ) ; <nl> append ( 0 ) ; / / Jump target , will be patched . <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_and_right_operand ( const Address & p_right_operand ) { <nl> - append ( GDScriptFunction : : OPCODE_JUMP_IF_NOT ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP_IF_NOT , 1 ) ; <nl> append ( p_right_operand ) ; <nl> logic_op_jump_pos2 . push_back ( opcodes . size ( ) ) ; <nl> append ( 0 ) ; / / Jump target , will be patched . <nl> void GDScriptByteCodeGenerator : : write_and_right_operand ( const Address & p_right_o <nl> <nl> void GDScriptByteCodeGenerator : : write_end_and ( const Address & p_target ) { <nl> / / If here means both operands are true . <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN_TRUE ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN_TRUE , 1 ) ; <nl> append ( p_target ) ; <nl> / / Jump away from the fail condition . <nl> - append ( GDScriptFunction : : OPCODE_JUMP ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP , 0 ) ; <nl> append ( opcodes . size ( ) + 3 ) ; <nl> / / Here it means one of operands is false . <nl> patch_jump ( logic_op_jump_pos1 . back ( ) - > get ( ) ) ; <nl> patch_jump ( logic_op_jump_pos2 . back ( ) - > get ( ) ) ; <nl> logic_op_jump_pos1 . pop_back ( ) ; <nl> logic_op_jump_pos2 . pop_back ( ) ; <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN_FALSE ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN_FALSE , 0 ) ; <nl> append ( p_target ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_or_left_operand ( const Address & p_left_operand ) { <nl> - append ( GDScriptFunction : : OPCODE_JUMP_IF ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP_IF , 1 ) ; <nl> append ( p_left_operand ) ; <nl> logic_op_jump_pos1 . push_back ( opcodes . size ( ) ) ; <nl> append ( 0 ) ; / / Jump target , will be patched . <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_or_right_operand ( const Address & p_right_operand ) { <nl> - append ( GDScriptFunction : : OPCODE_JUMP_IF ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP_IF , 1 ) ; <nl> append ( p_right_operand ) ; <nl> logic_op_jump_pos2 . push_back ( opcodes . size ( ) ) ; <nl> append ( 0 ) ; / / Jump target , will be patched . <nl> void GDScriptByteCodeGenerator : : write_or_right_operand ( const Address & p_right_op <nl> <nl> void GDScriptByteCodeGenerator : : write_end_or ( const Address & p_target ) { <nl> / / If here means both operands are false . <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN_FALSE ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN_FALSE , 1 ) ; <nl> append ( p_target ) ; <nl> / / Jump away from the success condition . <nl> - append ( GDScriptFunction : : OPCODE_JUMP ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP , 0 ) ; <nl> append ( opcodes . size ( ) + 3 ) ; <nl> / / Here it means one of operands is false . <nl> patch_jump ( logic_op_jump_pos1 . back ( ) - > get ( ) ) ; <nl> patch_jump ( logic_op_jump_pos2 . back ( ) - > get ( ) ) ; <nl> logic_op_jump_pos1 . pop_back ( ) ; <nl> logic_op_jump_pos2 . pop_back ( ) ; <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN_TRUE ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN_TRUE , 1 ) ; <nl> append ( p_target ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_start_ternary ( const Address & p_target ) { <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_ternary_condition ( const Address & p_condition ) { <nl> - append ( GDScriptFunction : : OPCODE_JUMP_IF_NOT ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP_IF_NOT , 1 ) ; <nl> append ( p_condition ) ; <nl> ternary_jump_fail_pos . push_back ( opcodes . size ( ) ) ; <nl> append ( 0 ) ; / / Jump target , will be patched . <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_ternary_true_expr ( const Address & p_expr ) { <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN , 2 ) ; <nl> append ( ternary_result . back ( ) - > get ( ) ) ; <nl> append ( p_expr ) ; <nl> / / Jump away from the false path . <nl> - append ( GDScriptFunction : : OPCODE_JUMP ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP , 0 ) ; <nl> ternary_jump_skip_pos . push_back ( opcodes . size ( ) ) ; <nl> append ( 0 ) ; <nl> / / Fail must jump here . <nl> void GDScriptByteCodeGenerator : : write_ternary_true_expr ( const Address & p_expr ) { <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_ternary_false_expr ( const Address & p_expr ) { <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN , 2 ) ; <nl> append ( ternary_result . back ( ) - > get ( ) ) ; <nl> append ( p_expr ) ; <nl> } <nl> void GDScriptByteCodeGenerator : : write_end_ternary ( ) { <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_set ( const Address & p_target , const Address & p_index , const Address & p_source ) { <nl> - append ( GDScriptFunction : : OPCODE_SET ) ; <nl> + if ( HAS_BUILTIN_TYPE ( p_target ) ) { <nl> + if ( IS_BUILTIN_TYPE ( p_index , Variant : : INT ) & & Variant : : get_member_validated_indexed_setter ( p_target . type . builtin_type ) ) { <nl> + / / Use indexed setter instead . <nl> + Variant : : ValidatedIndexedSetter setter = Variant : : get_member_validated_indexed_setter ( p_target . type . builtin_type ) ; <nl> + append ( GDScriptFunction : : OPCODE_SET_INDEXED_VALIDATED , 3 ) ; <nl> + append ( p_target ) ; <nl> + append ( p_index ) ; <nl> + append ( p_source ) ; <nl> + append ( setter ) ; <nl> + return ; <nl> + } else if ( Variant : : get_member_validated_keyed_setter ( p_target . type . builtin_type ) ) { <nl> + Variant : : ValidatedKeyedSetter setter = Variant : : get_member_validated_keyed_setter ( p_target . type . builtin_type ) ; <nl> + append ( GDScriptFunction : : OPCODE_SET_KEYED_VALIDATED , 3 ) ; <nl> + append ( p_target ) ; <nl> + append ( p_index ) ; <nl> + append ( p_source ) ; <nl> + append ( setter ) ; <nl> + return ; <nl> + } <nl> + } <nl> + <nl> + append ( GDScriptFunction : : OPCODE_SET_KEYED , 3 ) ; <nl> append ( p_target ) ; <nl> append ( p_index ) ; <nl> append ( p_source ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_get ( const Address & p_target , const Address & p_index , const Address & p_source ) { <nl> - append ( GDScriptFunction : : OPCODE_GET ) ; <nl> + if ( HAS_BUILTIN_TYPE ( p_source ) ) { <nl> + if ( IS_BUILTIN_TYPE ( p_index , Variant : : INT ) & & Variant : : get_member_validated_indexed_getter ( p_source . type . builtin_type ) ) { <nl> + / / Use indexed getter instead . <nl> + Variant : : ValidatedIndexedGetter getter = Variant : : get_member_validated_indexed_getter ( p_source . type . builtin_type ) ; <nl> + append ( GDScriptFunction : : OPCODE_GET_INDEXED_VALIDATED , 3 ) ; <nl> + append ( p_source ) ; <nl> + append ( p_index ) ; <nl> + append ( p_target ) ; <nl> + append ( getter ) ; <nl> + return ; <nl> + } else if ( Variant : : get_member_validated_keyed_getter ( p_source . type . builtin_type ) ) { <nl> + Variant : : ValidatedKeyedGetter getter = Variant : : get_member_validated_keyed_getter ( p_source . type . builtin_type ) ; <nl> + append ( GDScriptFunction : : OPCODE_GET_KEYED_VALIDATED , 3 ) ; <nl> + append ( p_source ) ; <nl> + append ( p_index ) ; <nl> + append ( p_target ) ; <nl> + append ( getter ) ; <nl> + return ; <nl> + } <nl> + } <nl> + append ( GDScriptFunction : : OPCODE_GET_KEYED , 3 ) ; <nl> append ( p_source ) ; <nl> append ( p_index ) ; <nl> append ( p_target ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_set_named ( const Address & p_target , const StringName & p_name , const Address & p_source ) { <nl> - append ( GDScriptFunction : : OPCODE_SET_NAMED ) ; <nl> + if ( HAS_BUILTIN_TYPE ( p_target ) & & Variant : : get_member_validated_setter ( p_target . type . builtin_type , p_name ) ) { <nl> + Variant : : ValidatedSetter setter = Variant : : get_member_validated_setter ( p_target . type . builtin_type , p_name ) ; <nl> + append ( GDScriptFunction : : OPCODE_SET_NAMED_VALIDATED , 2 ) ; <nl> + append ( p_target ) ; <nl> + append ( p_source ) ; <nl> + append ( setter ) ; <nl> + return ; <nl> + } <nl> + append ( GDScriptFunction : : OPCODE_SET_NAMED , 2 ) ; <nl> append ( p_target ) ; <nl> - append ( p_name ) ; <nl> append ( p_source ) ; <nl> + append ( p_name ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_get_named ( const Address & p_target , const StringName & p_name , const Address & p_source ) { <nl> - append ( GDScriptFunction : : OPCODE_GET_NAMED ) ; <nl> + if ( HAS_BUILTIN_TYPE ( p_source ) & & Variant : : get_member_validated_getter ( p_source . type . builtin_type , p_name ) ) { <nl> + Variant : : ValidatedGetter getter = Variant : : get_member_validated_getter ( p_source . type . builtin_type , p_name ) ; <nl> + append ( GDScriptFunction : : OPCODE_GET_NAMED_VALIDATED , 2 ) ; <nl> + append ( p_source ) ; <nl> + append ( p_target ) ; <nl> + append ( getter ) ; <nl> + return ; <nl> + } <nl> + append ( GDScriptFunction : : OPCODE_GET_NAMED , 2 ) ; <nl> append ( p_source ) ; <nl> - append ( p_name ) ; <nl> append ( p_target ) ; <nl> + append ( p_name ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_set_member ( const Address & p_value , const StringName & p_name ) { <nl> - append ( GDScriptFunction : : OPCODE_SET_MEMBER ) ; <nl> - append ( p_name ) ; <nl> + append ( GDScriptFunction : : OPCODE_SET_MEMBER , 1 ) ; <nl> append ( p_value ) ; <nl> + append ( p_name ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_get_member ( const Address & p_target , const StringName & p_name ) { <nl> - append ( GDScriptFunction : : OPCODE_GET_MEMBER ) ; <nl> - append ( p_name ) ; <nl> + append ( GDScriptFunction : : OPCODE_GET_MEMBER , 1 ) ; <nl> append ( p_target ) ; <nl> + append ( p_name ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_assign ( const Address & p_target , const Address & p_source ) { <nl> void GDScriptByteCodeGenerator : : write_assign ( const Address & p_target , const Addr <nl> / / Typed assignment . <nl> switch ( p_target . type . kind ) { <nl> case GDScriptDataType : : BUILTIN : { <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN_TYPED_BUILTIN ) ; <nl> - append ( p_target . type . builtin_type ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN_TYPED_BUILTIN , 2 ) ; <nl> append ( p_target ) ; <nl> append ( p_source ) ; <nl> + append ( p_target . type . builtin_type ) ; <nl> } break ; <nl> case GDScriptDataType : : NATIVE : { <nl> int class_idx = GDScriptLanguage : : get_singleton ( ) - > get_global_map ( ) [ p_target . type . native_type ] ; <nl> class_idx | = ( GDScriptFunction : : ADDR_TYPE_GLOBAL < < GDScriptFunction : : ADDR_BITS ) ; <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN_TYPED_NATIVE ) ; <nl> - append ( class_idx ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN_TYPED_NATIVE , 3 ) ; <nl> append ( p_target ) ; <nl> append ( p_source ) ; <nl> + append ( class_idx ) ; <nl> } break ; <nl> case GDScriptDataType : : SCRIPT : <nl> case GDScriptDataType : : GDSCRIPT : { <nl> Variant script = p_target . type . script_type ; <nl> int idx = get_constant_pos ( script ) ; <nl> + idx | = ( GDScriptFunction : : ADDR_TYPE_LOCAL_CONSTANT < < GDScriptFunction : : ADDR_BITS ) ; <nl> <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN_TYPED_SCRIPT ) ; <nl> - append ( idx ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN_TYPED_SCRIPT , 3 ) ; <nl> append ( p_target ) ; <nl> append ( p_source ) ; <nl> + append ( idx ) ; <nl> } break ; <nl> default : { <nl> ERR_PRINT ( " Compiler bug : unresolved assign . " ) ; <nl> <nl> / / Shouldn ' t get here , but fail - safe to a regular assignment <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN , 2 ) ; <nl> append ( p_target ) ; <nl> append ( p_source ) ; <nl> } <nl> void GDScriptByteCodeGenerator : : write_assign ( const Address & p_target , const Addr <nl> } else { <nl> if ( p_target . type . kind = = GDScriptDataType : : BUILTIN & & p_source . type . kind = = GDScriptDataType : : BUILTIN & & p_target . type . builtin_type ! = p_source . type . builtin_type ) { <nl> / / Need conversion . . <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN_TYPED_BUILTIN ) ; <nl> - append ( p_target . type . builtin_type ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN_TYPED_BUILTIN , 2 ) ; <nl> append ( p_target ) ; <nl> append ( p_source ) ; <nl> + append ( p_target . type . builtin_type ) ; <nl> } else { <nl> / / Either untyped assignment or already type - checked by the parser <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN , 2 ) ; <nl> append ( p_target ) ; <nl> append ( p_source ) ; <nl> } <nl> void GDScriptByteCodeGenerator : : write_assign ( const Address & p_target , const Addr <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_assign_true ( const Address & p_target ) { <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN_TRUE ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN_TRUE , 1 ) ; <nl> append ( p_target ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_assign_false ( const Address & p_target ) { <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN_FALSE ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN_FALSE , 1 ) ; <nl> append ( p_target ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_cast ( const Address & p_target , const Address & p_source , const GDScriptDataType & p_type ) { <nl> + int index = 0 ; <nl> + <nl> switch ( p_type . kind ) { <nl> case GDScriptDataType : : BUILTIN : { <nl> - append ( GDScriptFunction : : OPCODE_CAST_TO_BUILTIN ) ; <nl> - append ( p_type . builtin_type ) ; <nl> + append ( GDScriptFunction : : OPCODE_CAST_TO_BUILTIN , 2 ) ; <nl> + index = p_type . builtin_type ; <nl> } break ; <nl> case GDScriptDataType : : NATIVE : { <nl> int class_idx = GDScriptLanguage : : get_singleton ( ) - > get_global_map ( ) [ p_type . native_type ] ; <nl> class_idx | = ( GDScriptFunction : : ADDR_TYPE_GLOBAL < < GDScriptFunction : : ADDR_BITS ) ; <nl> - append ( GDScriptFunction : : OPCODE_CAST_TO_NATIVE ) ; <nl> - append ( class_idx ) ; <nl> + append ( GDScriptFunction : : OPCODE_CAST_TO_NATIVE , 3 ) ; <nl> + index = class_idx ; <nl> } break ; <nl> case GDScriptDataType : : SCRIPT : <nl> case GDScriptDataType : : GDSCRIPT : { <nl> Variant script = p_type . script_type ; <nl> int idx = get_constant_pos ( script ) ; <nl> + idx | = ( GDScriptFunction : : ADDR_TYPE_LOCAL_CONSTANT < < GDScriptFunction : : ADDR_BITS ) ; <nl> <nl> - append ( GDScriptFunction : : OPCODE_CAST_TO_SCRIPT ) ; <nl> - append ( idx ) ; <nl> + append ( GDScriptFunction : : OPCODE_CAST_TO_SCRIPT , 3 ) ; <nl> + index = idx ; <nl> } break ; <nl> default : { <nl> return ; <nl> void GDScriptByteCodeGenerator : : write_cast ( const Address & p_target , const Addres <nl> <nl> append ( p_source ) ; <nl> append ( p_target ) ; <nl> + append ( index ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_call ( const Address & p_target , const Address & p_base , const StringName & p_function_name , const Vector < Address > & p_arguments ) { <nl> - append ( p_target . mode = = Address : : NIL ? GDScriptFunction : : OPCODE_CALL : GDScriptFunction : : OPCODE_CALL_RETURN ) ; <nl> - append ( p_arguments . size ( ) ) ; <nl> - append ( p_base ) ; <nl> - append ( p_function_name ) ; <nl> + append ( p_target . mode = = Address : : NIL ? GDScriptFunction : : OPCODE_CALL : GDScriptFunction : : OPCODE_CALL_RETURN , 2 + p_arguments . size ( ) ) ; <nl> for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> append ( p_arguments [ i ] ) ; <nl> } <nl> + append ( p_base ) ; <nl> append ( p_target ) ; <nl> - alloc_call ( p_arguments . size ( ) ) ; <nl> + append ( p_arguments . size ( ) ) ; <nl> + append ( p_function_name ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_super_call ( const Address & p_target , const StringName & p_function_name , const Vector < Address > & p_arguments ) { <nl> - append ( GDScriptFunction : : OPCODE_CALL_SELF_BASE ) ; <nl> - append ( p_function_name ) ; <nl> - append ( p_arguments . size ( ) ) ; <nl> + append ( GDScriptFunction : : OPCODE_CALL_SELF_BASE , 1 + p_arguments . size ( ) ) ; <nl> for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> append ( p_arguments [ i ] ) ; <nl> } <nl> append ( p_target ) ; <nl> - alloc_call ( p_arguments . size ( ) ) ; <nl> + append ( p_arguments . size ( ) ) ; <nl> + append ( p_function_name ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_call_async ( const Address & p_target , const Address & p_base , const StringName & p_function_name , const Vector < Address > & p_arguments ) { <nl> - append ( GDScriptFunction : : OPCODE_CALL_ASYNC ) ; <nl> - append ( p_arguments . size ( ) ) ; <nl> - append ( p_base ) ; <nl> - append ( p_function_name ) ; <nl> + append ( GDScriptFunction : : OPCODE_CALL_ASYNC , 2 + p_arguments . size ( ) ) ; <nl> for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> append ( p_arguments [ i ] ) ; <nl> } <nl> + append ( p_base ) ; <nl> append ( p_target ) ; <nl> - alloc_call ( p_arguments . size ( ) ) ; <nl> + append ( p_arguments . size ( ) ) ; <nl> + append ( p_function_name ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_call_builtin ( const Address & p_target , GDScriptFunctions : : Function p_function , const Vector < Address > & p_arguments ) { <nl> - append ( GDScriptFunction : : OPCODE_CALL_BUILT_IN ) ; <nl> - append ( p_function ) ; <nl> - append ( p_arguments . size ( ) ) ; <nl> + append ( GDScriptFunction : : OPCODE_CALL_BUILT_IN , 1 + p_arguments . size ( ) ) ; <nl> for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> append ( p_arguments [ i ] ) ; <nl> } <nl> append ( p_target ) ; <nl> - alloc_call ( p_arguments . size ( ) ) ; <nl> + append ( p_arguments . size ( ) ) ; <nl> + append ( p_function ) ; <nl> } <nl> <nl> - void GDScriptByteCodeGenerator : : write_call_method_bind ( const Address & p_target , const Address & p_base , const MethodBind * p_method , const Vector < Address > & p_arguments ) { <nl> - append ( p_target . mode = = Address : : NIL ? GDScriptFunction : : OPCODE_CALL : GDScriptFunction : : OPCODE_CALL_RETURN ) ; <nl> - append ( p_arguments . size ( ) ) ; <nl> - append ( p_base ) ; <nl> - append ( p_method - > get_name ( ) ) ; <nl> + void GDScriptByteCodeGenerator : : write_call_builtin_type ( const Address & p_target , const Address & p_base , Variant : : Type p_type , const StringName & p_method , const Vector < Address > & p_arguments ) { <nl> + bool is_validated = false ; <nl> + <nl> + / / Check if all types are correct . <nl> + if ( Variant : : is_builtin_method_vararg ( p_type , p_method ) ) { <nl> + is_validated = true ; / / Vararg works fine with any argument , since they can be any type . <nl> + } else if ( p_arguments . size ( ) = = Variant : : get_builtin_method_argument_count ( p_type , p_method ) ) { <nl> + bool all_types_exact = true ; <nl> + for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> + if ( ! IS_BUILTIN_TYPE ( p_arguments [ i ] , Variant : : get_builtin_method_argument_type ( p_type , p_method , i ) ) ) { <nl> + all_types_exact = false ; <nl> + break ; <nl> + } <nl> + } <nl> + <nl> + is_validated = all_types_exact ; <nl> + } <nl> + <nl> + if ( ! is_validated ) { <nl> + / / Perform regular call . <nl> + write_call ( p_target , p_base , p_method , p_arguments ) ; <nl> + return ; <nl> + } <nl> + <nl> + append ( GDScriptFunction : : OPCODE_CALL_BUILTIN_TYPE_VALIDATED , 2 + p_arguments . size ( ) ) ; <nl> + <nl> for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> append ( p_arguments [ i ] ) ; <nl> } <nl> + append ( p_base ) ; <nl> append ( p_target ) ; <nl> - alloc_call ( p_arguments . size ( ) ) ; <nl> + append ( p_arguments . size ( ) ) ; <nl> + append ( Variant : : get_validated_builtin_method ( p_type , p_method ) ) ; <nl> } <nl> <nl> - void GDScriptByteCodeGenerator : : write_call_ptrcall ( const Address & p_target , const Address & p_base , const MethodBind * p_method , const Vector < Address > & p_arguments ) { <nl> - append ( p_target . mode = = Address : : NIL ? GDScriptFunction : : OPCODE_CALL : GDScriptFunction : : OPCODE_CALL_RETURN ) ; <nl> - append ( p_arguments . size ( ) ) ; <nl> + void GDScriptByteCodeGenerator : : write_call_method_bind ( const Address & p_target , const Address & p_base , MethodBind * p_method , const Vector < Address > & p_arguments ) { <nl> + append ( p_target . mode = = Address : : NIL ? GDScriptFunction : : OPCODE_CALL_METHOD_BIND : GDScriptFunction : : OPCODE_CALL_METHOD_BIND_RET , 2 + p_arguments . size ( ) ) ; <nl> + for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> + append ( p_arguments [ i ] ) ; <nl> + } <nl> append ( p_base ) ; <nl> - append ( p_method - > get_name ( ) ) ; <nl> + append ( p_target ) ; <nl> + append ( p_arguments . size ( ) ) ; <nl> + append ( p_method ) ; <nl> + } <nl> + <nl> + void GDScriptByteCodeGenerator : : write_call_ptrcall ( const Address & p_target , const Address & p_base , MethodBind * p_method , const Vector < Address > & p_arguments ) { <nl> + # define CASE_TYPE ( m_type ) \ <nl> + case Variant : : m_type : \ <nl> + append ( GDScriptFunction : : OPCODE_CALL_PTRCALL_ # # m_type , 2 + p_arguments . size ( ) ) ; \ <nl> + break <nl> + <nl> + bool is_ptrcall = true ; <nl> + <nl> + if ( p_method - > has_return ( ) ) { <nl> + MethodInfo info ; <nl> + ClassDB : : get_method_info ( p_method - > get_instance_class ( ) , p_method - > get_name ( ) , & info ) ; <nl> + switch ( info . return_val . type ) { <nl> + CASE_TYPE ( BOOL ) ; <nl> + CASE_TYPE ( INT ) ; <nl> + CASE_TYPE ( FLOAT ) ; <nl> + CASE_TYPE ( STRING ) ; <nl> + CASE_TYPE ( VECTOR2 ) ; <nl> + CASE_TYPE ( VECTOR2I ) ; <nl> + CASE_TYPE ( RECT2 ) ; <nl> + CASE_TYPE ( RECT2I ) ; <nl> + CASE_TYPE ( VECTOR3 ) ; <nl> + CASE_TYPE ( VECTOR3I ) ; <nl> + CASE_TYPE ( TRANSFORM2D ) ; <nl> + CASE_TYPE ( PLANE ) ; <nl> + CASE_TYPE ( AABB ) ; <nl> + CASE_TYPE ( BASIS ) ; <nl> + CASE_TYPE ( TRANSFORM ) ; <nl> + CASE_TYPE ( COLOR ) ; <nl> + CASE_TYPE ( STRING_NAME ) ; <nl> + CASE_TYPE ( NODE_PATH ) ; <nl> + CASE_TYPE ( RID ) ; <nl> + CASE_TYPE ( QUAT ) ; <nl> + CASE_TYPE ( OBJECT ) ; <nl> + CASE_TYPE ( CALLABLE ) ; <nl> + CASE_TYPE ( SIGNAL ) ; <nl> + CASE_TYPE ( DICTIONARY ) ; <nl> + CASE_TYPE ( ARRAY ) ; <nl> + CASE_TYPE ( PACKED_BYTE_ARRAY ) ; <nl> + CASE_TYPE ( PACKED_INT32_ARRAY ) ; <nl> + CASE_TYPE ( PACKED_INT64_ARRAY ) ; <nl> + CASE_TYPE ( PACKED_FLOAT32_ARRAY ) ; <nl> + CASE_TYPE ( PACKED_FLOAT64_ARRAY ) ; <nl> + CASE_TYPE ( PACKED_STRING_ARRAY ) ; <nl> + CASE_TYPE ( PACKED_VECTOR2_ARRAY ) ; <nl> + CASE_TYPE ( PACKED_VECTOR3_ARRAY ) ; <nl> + CASE_TYPE ( PACKED_COLOR_ARRAY ) ; <nl> + default : <nl> + append ( p_target . mode = = Address : : NIL ? GDScriptFunction : : OPCODE_CALL_METHOD_BIND : GDScriptFunction : : OPCODE_CALL_METHOD_BIND_RET , 2 + p_arguments . size ( ) ) ; <nl> + is_ptrcall = false ; <nl> + break ; <nl> + } <nl> + } else { <nl> + append ( GDScriptFunction : : OPCODE_CALL_PTRCALL_NO_RETURN , 2 + p_arguments . size ( ) ) ; <nl> + } <nl> + <nl> for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> append ( p_arguments [ i ] ) ; <nl> } <nl> + append ( p_base ) ; <nl> append ( p_target ) ; <nl> - alloc_call ( p_arguments . size ( ) ) ; <nl> + append ( p_arguments . size ( ) ) ; <nl> + append ( p_method ) ; <nl> + if ( is_ptrcall ) { <nl> + alloc_ptrcall ( p_arguments . size ( ) ) ; <nl> + } <nl> + <nl> + # undef CASE_TYPE <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_call_self ( const Address & p_target , const StringName & p_function_name , const Vector < Address > & p_arguments ) { <nl> - append ( p_target . mode = = Address : : NIL ? GDScriptFunction : : OPCODE_CALL : GDScriptFunction : : OPCODE_CALL_RETURN ) ; <nl> - append ( p_arguments . size ( ) ) ; <nl> - append ( GDScriptFunction : : ADDR_TYPE_SELF < < GDScriptFunction : : ADDR_BITS ) ; <nl> - append ( p_function_name ) ; <nl> + append ( p_target . mode = = Address : : NIL ? GDScriptFunction : : OPCODE_CALL : GDScriptFunction : : OPCODE_CALL_RETURN , 2 + p_arguments . size ( ) ) ; <nl> for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> append ( p_arguments [ i ] ) ; <nl> } <nl> + append ( GDScriptFunction : : ADDR_TYPE_SELF < < GDScriptFunction : : ADDR_BITS ) ; <nl> append ( p_target ) ; <nl> - alloc_call ( p_arguments . size ( ) ) ; <nl> + append ( p_arguments . size ( ) ) ; <nl> + append ( p_function_name ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_call_script_function ( const Address & p_target , const Address & p_base , const StringName & p_function_name , const Vector < Address > & p_arguments ) { <nl> - append ( p_target . mode = = Address : : NIL ? GDScriptFunction : : OPCODE_CALL : GDScriptFunction : : OPCODE_CALL_RETURN ) ; <nl> - append ( p_arguments . size ( ) ) ; <nl> - append ( p_base ) ; <nl> - append ( p_function_name ) ; <nl> + append ( p_target . mode = = Address : : NIL ? GDScriptFunction : : OPCODE_CALL : GDScriptFunction : : OPCODE_CALL_RETURN , 2 + p_arguments . size ( ) ) ; <nl> for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> append ( p_arguments [ i ] ) ; <nl> } <nl> + append ( p_base ) ; <nl> append ( p_target ) ; <nl> - alloc_call ( p_arguments . size ( ) ) ; <nl> + append ( p_arguments . size ( ) ) ; <nl> + append ( p_function_name ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_construct ( const Address & p_target , Variant : : Type p_type , const Vector < Address > & p_arguments ) { <nl> - append ( GDScriptFunction : : OPCODE_CONSTRUCT ) ; <nl> - append ( p_type ) ; <nl> - append ( p_arguments . size ( ) ) ; <nl> + / / Try to find an appropriate constructor . <nl> + bool all_have_type = true ; <nl> + Vector < Variant : : Type > arg_types ; <nl> + for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> + if ( ! HAS_BUILTIN_TYPE ( p_arguments [ i ] ) ) { <nl> + all_have_type = false ; <nl> + break ; <nl> + } <nl> + arg_types . push_back ( p_arguments [ i ] . type . builtin_type ) ; <nl> + } <nl> + if ( all_have_type ) { <nl> + int valid_constructor = - 1 ; <nl> + for ( int i = 0 ; i < Variant : : get_constructor_count ( p_type ) ; i + + ) { <nl> + if ( Variant : : get_constructor_argument_count ( p_type , i ) ! = p_arguments . size ( ) ) { <nl> + continue ; <nl> + } <nl> + int types_correct = true ; <nl> + for ( int j = 0 ; j < arg_types . size ( ) ; j + + ) { <nl> + if ( arg_types [ j ] ! = Variant : : get_constructor_argument_type ( p_type , i , j ) ) { <nl> + types_correct = false ; <nl> + break ; <nl> + } <nl> + } <nl> + if ( types_correct ) { <nl> + valid_constructor = i ; <nl> + break ; <nl> + } <nl> + } <nl> + if ( valid_constructor > = 0 ) { <nl> + append ( GDScriptFunction : : OPCODE_CONSTRUCT_VALIDATED , 1 + p_arguments . size ( ) ) ; <nl> + for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> + append ( p_arguments [ i ] ) ; <nl> + } <nl> + append ( p_target ) ; <nl> + append ( p_arguments . size ( ) ) ; <nl> + append ( Variant : : get_validated_constructor ( p_type , valid_constructor ) ) ; <nl> + return ; <nl> + } <nl> + } <nl> + <nl> + append ( GDScriptFunction : : OPCODE_CONSTRUCT , 1 + p_arguments . size ( ) ) ; <nl> for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> append ( p_arguments [ i ] ) ; <nl> } <nl> append ( p_target ) ; <nl> - alloc_call ( p_arguments . size ( ) ) ; <nl> + append ( p_arguments . size ( ) ) ; <nl> + append ( p_type ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_construct_array ( const Address & p_target , const Vector < Address > & p_arguments ) { <nl> - append ( GDScriptFunction : : OPCODE_CONSTRUCT_ARRAY ) ; <nl> - append ( p_arguments . size ( ) ) ; <nl> + append ( GDScriptFunction : : OPCODE_CONSTRUCT_ARRAY , 1 + p_arguments . size ( ) ) ; <nl> for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> append ( p_arguments [ i ] ) ; <nl> } <nl> append ( p_target ) ; <nl> + append ( p_arguments . size ( ) ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_construct_dictionary ( const Address & p_target , const Vector < Address > & p_arguments ) { <nl> - append ( GDScriptFunction : : OPCODE_CONSTRUCT_DICTIONARY ) ; <nl> - append ( p_arguments . size ( ) / 2 ) ; / / This is number of key - value pairs , so only half of actual arguments . <nl> + append ( GDScriptFunction : : OPCODE_CONSTRUCT_DICTIONARY , 1 + p_arguments . size ( ) ) ; <nl> for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> append ( p_arguments [ i ] ) ; <nl> } <nl> append ( p_target ) ; <nl> + append ( p_arguments . size ( ) / 2 ) ; / / This is number of key - value pairs , so only half of actual arguments . <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_await ( const Address & p_target , const Address & p_operand ) { <nl> - append ( GDScriptFunction : : OPCODE_AWAIT ) ; <nl> + append ( GDScriptFunction : : OPCODE_AWAIT , 1 ) ; <nl> append ( p_operand ) ; <nl> - append ( GDScriptFunction : : OPCODE_AWAIT_RESUME ) ; <nl> + append ( GDScriptFunction : : OPCODE_AWAIT_RESUME , 1 ) ; <nl> append ( p_target ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_if ( const Address & p_condition ) { <nl> - append ( GDScriptFunction : : OPCODE_JUMP_IF_NOT ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP_IF_NOT , 1 ) ; <nl> append ( p_condition ) ; <nl> if_jmp_addrs . push_back ( opcodes . size ( ) ) ; <nl> append ( 0 ) ; / / Jump destination , will be patched . <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_else ( ) { <nl> - append ( GDScriptFunction : : OPCODE_JUMP ) ; / / Jump from true if block ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP , 0 ) ; / / Jump from true if block ; <nl> int else_jmp_addr = opcodes . size ( ) ; <nl> append ( 0 ) ; / / Jump destination , will be patched . <nl> <nl> void GDScriptByteCodeGenerator : : write_for ( const Address & p_variable , const Addre <nl> current_breaks_to_patch . push_back ( List < int > ( ) ) ; <nl> <nl> / / Assign container . <nl> - append ( GDScriptFunction : : OPCODE_ASSIGN ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSIGN , 2 ) ; <nl> append ( container_pos ) ; <nl> append ( p_list ) ; <nl> <nl> + GDScriptFunction : : Opcode begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN ; <nl> + GDScriptFunction : : Opcode iterate_opcode = GDScriptFunction : : OPCODE_ITERATE ; <nl> + <nl> + if ( p_list . type . has_type ) { <nl> + if ( p_list . type . kind = = GDScriptDataType : : BUILTIN ) { <nl> + switch ( p_list . type . builtin_type ) { <nl> + case Variant : : INT : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_INT ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_INT ; <nl> + break ; <nl> + case Variant : : FLOAT : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_FLOAT ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_FLOAT ; <nl> + break ; <nl> + case Variant : : VECTOR2 : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_VECTOR2 ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_VECTOR2 ; <nl> + break ; <nl> + case Variant : : VECTOR2I : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_VECTOR2I ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_VECTOR2I ; <nl> + break ; <nl> + case Variant : : VECTOR3 : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_VECTOR3 ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_VECTOR3 ; <nl> + break ; <nl> + case Variant : : VECTOR3I : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_VECTOR3I ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_VECTOR3I ; <nl> + break ; <nl> + case Variant : : STRING : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_STRING ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_STRING ; <nl> + break ; <nl> + case Variant : : DICTIONARY : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_DICTIONARY ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_DICTIONARY ; <nl> + break ; <nl> + case Variant : : ARRAY : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_ARRAY ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_ARRAY ; <nl> + break ; <nl> + case Variant : : PACKED_BYTE_ARRAY : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_PACKED_BYTE_ARRAY ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_PACKED_BYTE_ARRAY ; <nl> + break ; <nl> + case Variant : : PACKED_INT32_ARRAY : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_PACKED_INT32_ARRAY ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_PACKED_INT32_ARRAY ; <nl> + break ; <nl> + case Variant : : PACKED_INT64_ARRAY : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_PACKED_INT64_ARRAY ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_PACKED_INT64_ARRAY ; <nl> + break ; <nl> + case Variant : : PACKED_FLOAT32_ARRAY : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_PACKED_FLOAT32_ARRAY ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_PACKED_FLOAT32_ARRAY ; <nl> + break ; <nl> + case Variant : : PACKED_FLOAT64_ARRAY : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_PACKED_FLOAT64_ARRAY ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_PACKED_FLOAT64_ARRAY ; <nl> + break ; <nl> + case Variant : : PACKED_STRING_ARRAY : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_PACKED_STRING_ARRAY ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_PACKED_STRING_ARRAY ; <nl> + break ; <nl> + case Variant : : PACKED_VECTOR2_ARRAY : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_PACKED_VECTOR2_ARRAY ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_PACKED_VECTOR2_ARRAY ; <nl> + break ; <nl> + case Variant : : PACKED_VECTOR3_ARRAY : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_PACKED_VECTOR3_ARRAY ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_PACKED_VECTOR3_ARRAY ; <nl> + break ; <nl> + case Variant : : PACKED_COLOR_ARRAY : <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_PACKED_COLOR_ARRAY ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_PACKED_COLOR_ARRAY ; <nl> + break ; <nl> + default : <nl> + break ; <nl> + } <nl> + } else { <nl> + begin_opcode = GDScriptFunction : : OPCODE_ITERATE_BEGIN_OBJECT ; <nl> + iterate_opcode = GDScriptFunction : : OPCODE_ITERATE_OBJECT ; <nl> + } <nl> + } <nl> + <nl> / / Begin loop . <nl> - append ( GDScriptFunction : : OPCODE_ITERATE_BEGIN ) ; <nl> + append ( begin_opcode , 3 ) ; <nl> append ( counter_pos ) ; <nl> append ( container_pos ) ; <nl> + append ( p_variable ) ; <nl> for_jmp_addrs . push_back ( opcodes . size ( ) ) ; <nl> append ( 0 ) ; / / End of loop address , will be patched . <nl> - append ( p_variable ) ; <nl> - append ( GDScriptFunction : : OPCODE_JUMP ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP , 0 ) ; <nl> append ( opcodes . size ( ) + 6 ) ; / / Skip over ' continue ' code . <nl> <nl> / / Next iteration . <nl> int continue_addr = opcodes . size ( ) ; <nl> continue_addrs . push_back ( continue_addr ) ; <nl> - append ( GDScriptFunction : : OPCODE_ITERATE ) ; <nl> + append ( iterate_opcode , 3 ) ; <nl> append ( counter_pos ) ; <nl> append ( container_pos ) ; <nl> + append ( p_variable ) ; <nl> for_jmp_addrs . push_back ( opcodes . size ( ) ) ; <nl> append ( 0 ) ; / / Jump destination , will be patched . <nl> - append ( p_variable ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_endfor ( ) { <nl> / / Jump back to loop check . <nl> - append ( GDScriptFunction : : OPCODE_JUMP ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP , 0 ) ; <nl> append ( continue_addrs . back ( ) - > get ( ) ) ; <nl> continue_addrs . pop_back ( ) ; <nl> <nl> void GDScriptByteCodeGenerator : : start_while_condition ( ) { <nl> <nl> void GDScriptByteCodeGenerator : : write_while ( const Address & p_condition ) { <nl> / / Condition check . <nl> - append ( GDScriptFunction : : OPCODE_JUMP_IF_NOT ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP_IF_NOT , 1 ) ; <nl> append ( p_condition ) ; <nl> while_jmp_addrs . push_back ( opcodes . size ( ) ) ; <nl> append ( 0 ) ; / / End of loop address , will be patched . <nl> void GDScriptByteCodeGenerator : : write_while ( const Address & p_condition ) { <nl> <nl> void GDScriptByteCodeGenerator : : write_endwhile ( ) { <nl> / / Jump back to loop check . <nl> - append ( GDScriptFunction : : OPCODE_JUMP ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP , 0 ) ; <nl> append ( continue_addrs . back ( ) - > get ( ) ) ; <nl> continue_addrs . pop_back ( ) ; <nl> <nl> void GDScriptByteCodeGenerator : : end_match ( ) { <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_break ( ) { <nl> - append ( GDScriptFunction : : OPCODE_JUMP ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP , 0 ) ; <nl> current_breaks_to_patch . back ( ) - > get ( ) . push_back ( opcodes . size ( ) ) ; <nl> append ( 0 ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_continue ( ) { <nl> - append ( GDScriptFunction : : OPCODE_JUMP ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP , 0 ) ; <nl> append ( continue_addrs . back ( ) - > get ( ) ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_continue_match ( ) { <nl> - append ( GDScriptFunction : : OPCODE_JUMP ) ; <nl> + append ( GDScriptFunction : : OPCODE_JUMP , 0 ) ; <nl> match_continues_to_patch . back ( ) - > get ( ) . push_back ( opcodes . size ( ) ) ; <nl> append ( 0 ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_breakpoint ( ) { <nl> - append ( GDScriptFunction : : OPCODE_BREAKPOINT ) ; <nl> + append ( GDScriptFunction : : OPCODE_BREAKPOINT , 0 ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_newline ( int p_line ) { <nl> - append ( GDScriptFunction : : OPCODE_LINE ) ; <nl> + append ( GDScriptFunction : : OPCODE_LINE , 0 ) ; <nl> append ( p_line ) ; <nl> current_line = p_line ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_return ( const Address & p_return_value ) { <nl> - append ( GDScriptFunction : : OPCODE_RETURN ) ; <nl> + append ( GDScriptFunction : : OPCODE_RETURN , 1 ) ; <nl> append ( p_return_value ) ; <nl> } <nl> <nl> void GDScriptByteCodeGenerator : : write_assert ( const Address & p_test , const Address & p_message ) { <nl> - append ( GDScriptFunction : : OPCODE_ASSERT ) ; <nl> + append ( GDScriptFunction : : OPCODE_ASSERT , 2 ) ; <nl> append ( p_test ) ; <nl> append ( p_message ) ; <nl> } <nl> mmm a / modules / gdscript / gdscript_byte_codegen . h <nl> ppp b / modules / gdscript / gdscript_byte_codegen . h <nl> <nl> <nl> # include " gdscript_codegen . h " <nl> <nl> + # include " gdscript_function . h " <nl> + <nl> class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { <nl> bool ended = false ; <nl> GDScriptFunction * function = nullptr ; <nl> class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { <nl> <nl> int current_stack_size = 0 ; <nl> int current_temporaries = 0 ; <nl> + int current_line = 0 ; <nl> + int stack_max = 0 ; <nl> + int instr_args_max = 0 ; <nl> + int ptrcall_max = 0 ; <nl> <nl> HashMap < Variant , int , VariantHasher , VariantComparator > constant_map ; <nl> Map < StringName , int > name_map ; <nl> # ifdef TOOLS_ENABLED <nl> Vector < StringName > named_globals ; <nl> # endif <nl> - int current_line = 0 ; <nl> - int stack_max = 0 ; <nl> - int call_max = 0 ; <nl> + Map < Variant : : ValidatedOperatorEvaluator , int > operator_func_map ; <nl> + Map < Variant : : ValidatedSetter , int > setters_map ; <nl> + Map < Variant : : ValidatedGetter , int > getters_map ; <nl> + Map < Variant : : ValidatedKeyedSetter , int > keyed_setters_map ; <nl> + Map < Variant : : ValidatedKeyedGetter , int > keyed_getters_map ; <nl> + Map < Variant : : ValidatedIndexedSetter , int > indexed_setters_map ; <nl> + Map < Variant : : ValidatedIndexedGetter , int > indexed_getters_map ; <nl> + Map < Variant : : ValidatedBuiltInMethod , int > builtin_method_map ; <nl> + Map < Variant : : ValidatedConstructor , int > constructors_map ; <nl> + Map < MethodBind * , int > method_bind_map ; <nl> <nl> List < int > if_jmp_addrs ; / / List since this can be nested . <nl> List < int > for_jmp_addrs ; <nl> class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { <nl> return pos ; <nl> } <nl> <nl> + int get_operation_pos ( const Variant : : ValidatedOperatorEvaluator p_operation ) { <nl> + if ( operator_func_map . has ( p_operation ) ) <nl> + return operator_func_map [ p_operation ] ; <nl> + int pos = operator_func_map . size ( ) ; <nl> + operator_func_map [ p_operation ] = pos ; <nl> + return pos ; <nl> + } <nl> + <nl> + int get_setter_pos ( const Variant : : ValidatedSetter p_setter ) { <nl> + if ( setters_map . has ( p_setter ) ) <nl> + return setters_map [ p_setter ] ; <nl> + int pos = setters_map . size ( ) ; <nl> + setters_map [ p_setter ] = pos ; <nl> + return pos ; <nl> + } <nl> + <nl> + int get_getter_pos ( const Variant : : ValidatedGetter p_getter ) { <nl> + if ( getters_map . has ( p_getter ) ) <nl> + return getters_map [ p_getter ] ; <nl> + int pos = getters_map . size ( ) ; <nl> + getters_map [ p_getter ] = pos ; <nl> + return pos ; <nl> + } <nl> + <nl> + int get_keyed_setter_pos ( const Variant : : ValidatedKeyedSetter p_keyed_setter ) { <nl> + if ( keyed_setters_map . has ( p_keyed_setter ) ) <nl> + return keyed_setters_map [ p_keyed_setter ] ; <nl> + int pos = keyed_setters_map . size ( ) ; <nl> + keyed_setters_map [ p_keyed_setter ] = pos ; <nl> + return pos ; <nl> + } <nl> + <nl> + int get_keyed_getter_pos ( const Variant : : ValidatedKeyedGetter p_keyed_getter ) { <nl> + if ( keyed_getters_map . has ( p_keyed_getter ) ) <nl> + return keyed_getters_map [ p_keyed_getter ] ; <nl> + int pos = keyed_getters_map . size ( ) ; <nl> + keyed_getters_map [ p_keyed_getter ] = pos ; <nl> + return pos ; <nl> + } <nl> + <nl> + int get_indexed_setter_pos ( const Variant : : ValidatedIndexedSetter p_indexed_setter ) { <nl> + if ( indexed_setters_map . has ( p_indexed_setter ) ) <nl> + return indexed_setters_map [ p_indexed_setter ] ; <nl> + int pos = indexed_setters_map . size ( ) ; <nl> + indexed_setters_map [ p_indexed_setter ] = pos ; <nl> + return pos ; <nl> + } <nl> + <nl> + int get_indexed_getter_pos ( const Variant : : ValidatedIndexedGetter p_indexed_getter ) { <nl> + if ( indexed_getters_map . has ( p_indexed_getter ) ) <nl> + return indexed_getters_map [ p_indexed_getter ] ; <nl> + int pos = indexed_getters_map . size ( ) ; <nl> + indexed_getters_map [ p_indexed_getter ] = pos ; <nl> + return pos ; <nl> + } <nl> + <nl> + int get_builtin_method_pos ( const Variant : : ValidatedBuiltInMethod p_method ) { <nl> + if ( builtin_method_map . has ( p_method ) ) { <nl> + return builtin_method_map [ p_method ] ; <nl> + } <nl> + int pos = builtin_method_map . size ( ) ; <nl> + builtin_method_map [ p_method ] = pos ; <nl> + return pos ; <nl> + } <nl> + <nl> + int get_constructor_pos ( const Variant : : ValidatedConstructor p_constructor ) { <nl> + if ( constructors_map . has ( p_constructor ) ) { <nl> + return constructors_map [ p_constructor ] ; <nl> + } <nl> + int pos = constructors_map . size ( ) ; <nl> + constructors_map [ p_constructor ] = pos ; <nl> + return pos ; <nl> + } <nl> + <nl> + int get_method_bind_pos ( MethodBind * p_method ) { <nl> + if ( method_bind_map . has ( p_method ) ) { <nl> + return method_bind_map [ p_method ] ; <nl> + } <nl> + int pos = method_bind_map . size ( ) ; <nl> + method_bind_map [ p_method ] = pos ; <nl> + return pos ; <nl> + } <nl> + <nl> void alloc_stack ( int p_level ) { <nl> if ( p_level > = stack_max ) <nl> stack_max = p_level + 1 ; <nl> } <nl> <nl> - void alloc_call ( int p_params ) { <nl> - if ( p_params > = call_max ) <nl> - call_max = p_params ; <nl> - } <nl> - <nl> int increase_stack ( ) { <nl> int top = current_stack_size + + ; <nl> alloc_stack ( current_stack_size ) ; <nl> return top ; <nl> } <nl> <nl> + void alloc_ptrcall ( int p_params ) { <nl> + if ( p_params > = ptrcall_max ) <nl> + ptrcall_max = p_params ; <nl> + } <nl> + <nl> int address_of ( const Address & p_address ) { <nl> switch ( p_address . mode ) { <nl> case Address : : SELF : <nl> class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { <nl> return - 1 ; / / Unreachable . <nl> } <nl> <nl> - void append ( int code ) { <nl> - opcodes . push_back ( code ) ; <nl> + void append ( GDScriptFunction : : Opcode p_code , int p_argument_count ) { <nl> + opcodes . push_back ( ( p_code & GDScriptFunction : : INSTR_MASK ) | ( p_argument_count < < GDScriptFunction : : INSTR_BITS ) ) ; <nl> + instr_args_max = MAX ( instr_args_max , p_argument_count ) ; <nl> + } <nl> + <nl> + void append ( int p_code ) { <nl> + opcodes . push_back ( p_code ) ; <nl> } <nl> <nl> void append ( const Address & p_address ) { <nl> class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { <nl> opcodes . push_back ( get_name_map_pos ( p_name ) ) ; <nl> } <nl> <nl> + void append ( const Variant : : ValidatedOperatorEvaluator p_operation ) { <nl> + opcodes . push_back ( get_operation_pos ( p_operation ) ) ; <nl> + } <nl> + <nl> + void append ( const Variant : : ValidatedSetter p_setter ) { <nl> + opcodes . push_back ( get_setter_pos ( p_setter ) ) ; <nl> + } <nl> + <nl> + void append ( const Variant : : ValidatedGetter p_getter ) { <nl> + opcodes . push_back ( get_getter_pos ( p_getter ) ) ; <nl> + } <nl> + <nl> + void append ( const Variant : : ValidatedKeyedSetter p_keyed_setter ) { <nl> + opcodes . push_back ( get_keyed_setter_pos ( p_keyed_setter ) ) ; <nl> + } <nl> + <nl> + void append ( const Variant : : ValidatedKeyedGetter p_keyed_getter ) { <nl> + opcodes . push_back ( get_keyed_getter_pos ( p_keyed_getter ) ) ; <nl> + } <nl> + <nl> + void append ( const Variant : : ValidatedIndexedSetter p_indexed_setter ) { <nl> + opcodes . push_back ( get_indexed_setter_pos ( p_indexed_setter ) ) ; <nl> + } <nl> + <nl> + void append ( const Variant : : ValidatedIndexedGetter p_indexed_getter ) { <nl> + opcodes . push_back ( get_indexed_getter_pos ( p_indexed_getter ) ) ; <nl> + } <nl> + <nl> + void append ( const Variant : : ValidatedBuiltInMethod p_method ) { <nl> + opcodes . push_back ( get_builtin_method_pos ( p_method ) ) ; <nl> + } <nl> + <nl> + void append ( const Variant : : ValidatedConstructor p_constructor ) { <nl> + opcodes . push_back ( get_constructor_pos ( p_constructor ) ) ; <nl> + } <nl> + <nl> + void append ( MethodBind * p_method ) { <nl> + opcodes . push_back ( get_method_bind_pos ( p_method ) ) ; <nl> + } <nl> + <nl> void patch_jump ( int p_address ) { <nl> opcodes . write [ p_address ] = opcodes . size ( ) ; <nl> } <nl> class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { <nl> virtual void write_super_call ( const Address & p_target , const StringName & p_function_name , const Vector < Address > & p_arguments ) override ; <nl> virtual void write_call_async ( const Address & p_target , const Address & p_base , const StringName & p_function_name , const Vector < Address > & p_arguments ) override ; <nl> virtual void write_call_builtin ( const Address & p_target , GDScriptFunctions : : Function p_function , const Vector < Address > & p_arguments ) override ; <nl> - virtual void write_call_method_bind ( const Address & p_target , const Address & p_base , const MethodBind * p_method , const Vector < Address > & p_arguments ) override ; <nl> - virtual void write_call_ptrcall ( const Address & p_target , const Address & p_base , const MethodBind * p_method , const Vector < Address > & p_arguments ) override ; <nl> + virtual void write_call_builtin_type ( const Address & p_target , const Address & p_base , Variant : : Type p_type , const StringName & p_method , const Vector < Address > & p_arguments ) override ; <nl> + virtual void write_call_method_bind ( const Address & p_target , const Address & p_base , MethodBind * p_method , const Vector < Address > & p_arguments ) override ; <nl> + virtual void write_call_ptrcall ( const Address & p_target , const Address & p_base , MethodBind * p_method , const Vector < Address > & p_arguments ) override ; <nl> virtual void write_call_self ( const Address & p_target , const StringName & p_function_name , const Vector < Address > & p_arguments ) override ; <nl> virtual void write_call_script_function ( const Address & p_target , const Address & p_base , const StringName & p_function_name , const Vector < Address > & p_arguments ) override ; <nl> virtual void write_construct ( const Address & p_target , Variant : : Type p_type , const Vector < Address > & p_arguments ) override ; <nl> mmm a / modules / gdscript / gdscript_codegen . h <nl> ppp b / modules / gdscript / gdscript_codegen . h <nl> class GDScriptCodeGenerator { <nl> virtual void write_super_call ( const Address & p_target , const StringName & p_function_name , const Vector < Address > & p_arguments ) = 0 ; <nl> virtual void write_call_async ( const Address & p_target , const Address & p_base , const StringName & p_function_name , const Vector < Address > & p_arguments ) = 0 ; <nl> virtual void write_call_builtin ( const Address & p_target , GDScriptFunctions : : Function p_function , const Vector < Address > & p_arguments ) = 0 ; <nl> - virtual void write_call_method_bind ( const Address & p_target , const Address & p_base , const MethodBind * p_method , const Vector < Address > & p_arguments ) = 0 ; <nl> - virtual void write_call_ptrcall ( const Address & p_target , const Address & p_base , const MethodBind * p_method , const Vector < Address > & p_arguments ) = 0 ; <nl> + virtual void write_call_builtin_type ( const Address & p_target , const Address & p_base , Variant : : Type p_type , const StringName & p_method , const Vector < Address > & p_arguments ) = 0 ; <nl> + virtual void write_call_method_bind ( const Address & p_target , const Address & p_base , MethodBind * p_method , const Vector < Address > & p_arguments ) = 0 ; <nl> + virtual void write_call_ptrcall ( const Address & p_target , const Address & p_base , MethodBind * p_method , const Vector < Address > & p_arguments ) = 0 ; <nl> virtual void write_call_self ( const Address & p_target , const StringName & p_function_name , const Vector < Address > & p_arguments ) = 0 ; <nl> virtual void write_call_script_function ( const Address & p_target , const Address & p_base , const StringName & p_function_name , const Vector < Address > & p_arguments ) = 0 ; <nl> virtual void write_construct ( const Address & p_target , Variant : : Type p_type , const Vector < Address > & p_arguments ) = 0 ; <nl> mmm a / modules / gdscript / gdscript_compiler . cpp <nl> ppp b / modules / gdscript / gdscript_compiler . cpp <nl> GDScriptDataType GDScriptCompiler : : _gdtype_from_datatype ( const GDScriptParser : : D <nl> return result ; <nl> } <nl> <nl> + static bool _is_exact_type ( const PropertyInfo & p_par_type , const GDScriptDataType & p_arg_type ) { <nl> + if ( ! p_arg_type . has_type ) { <nl> + return false ; <nl> + } <nl> + if ( p_par_type . type = = Variant : : NIL ) { <nl> + return false ; <nl> + } <nl> + if ( p_par_type . type = = Variant : : OBJECT ) { <nl> + if ( p_arg_type . kind = = GDScriptDataType : : BUILTIN ) { <nl> + return false ; <nl> + } <nl> + StringName class_name ; <nl> + if ( p_arg_type . kind = = GDScriptDataType : : NATIVE ) { <nl> + class_name = p_arg_type . native_type ; <nl> + } else { <nl> + class_name = p_arg_type . native_type = = StringName ( ) ? p_arg_type . script_type - > get_instance_base_type ( ) : p_arg_type . native_type ; <nl> + } <nl> + return p_par_type . class_name = = class_name | | ClassDB : : is_parent_class ( class_name , p_par_type . class_name ) ; <nl> + } else { <nl> + if ( p_arg_type . kind ! = GDScriptDataType : : BUILTIN ) { <nl> + return false ; <nl> + } <nl> + return p_par_type . type = = p_arg_type . builtin_type ; <nl> + } <nl> + } <nl> + <nl> + static bool _have_exact_arguments ( const MethodBind * p_method , const Vector < GDScriptCodeGenerator : : Address > & p_arguments ) { <nl> + if ( p_method - > get_argument_count ( ) ! = p_arguments . size ( ) ) { <nl> + / / ptrcall won ' t work with default arguments . <nl> + return false ; <nl> + } <nl> + MethodInfo info ; <nl> + ClassDB : : get_method_info ( p_method - > get_instance_class ( ) , p_method - > get_name ( ) , & info ) ; <nl> + for ( int i = 0 ; i < p_arguments . size ( ) ; i + + ) { <nl> + const PropertyInfo & prop = info . arguments [ i ] ; <nl> + if ( ! _is_exact_type ( prop , p_arguments [ i ] . type ) ) { <nl> + return false ; <nl> + } <nl> + } <nl> + return true ; <nl> + } <nl> + <nl> GDScriptCodeGenerator : : Address GDScriptCompiler : : _parse_expression ( CodeGen & codegen , Error & r_error , const GDScriptParser : : ExpressionNode * p_expression , bool p_root , bool p_initializer , const GDScriptCodeGenerator : : Address & p_index_addr ) { <nl> if ( p_expression - > is_constant ) { <nl> return codegen . add_constant ( p_expression - > reduced_value ) ; <nl> GDScriptCodeGenerator : : Address GDScriptCompiler : : _parse_expression ( CodeGen & code <nl> } else { <nl> if ( callee - > type = = GDScriptParser : : Node : : IDENTIFIER ) { <nl> / / Self function call . <nl> - if ( ( codegen . function_node & & codegen . function_node - > is_static ) | | call - > function_name = = " new " ) { <nl> + if ( ClassDB : : has_method ( codegen . script - > native - > get_name ( ) , call - > function_name ) ) { <nl> + / / Native method , use faster path . <nl> + GDScriptCodeGenerator : : Address self ; <nl> + self . mode = GDScriptCodeGenerator : : Address : : SELF ; <nl> + MethodBind * method = ClassDB : : get_method ( codegen . script - > native - > get_name ( ) , call - > function_name ) ; <nl> + <nl> + if ( _have_exact_arguments ( method , arguments ) ) { <nl> + / / Exact arguments , use ptrcall . <nl> + gen - > write_call_ptrcall ( result , self , method , arguments ) ; <nl> + } else { <nl> + / / Not exact arguments , but still can use method bind call . <nl> + gen - > write_call_method_bind ( result , self , method , arguments ) ; <nl> + } <nl> + } else if ( ( codegen . function_node & & codegen . function_node - > is_static ) | | call - > function_name = = " new " ) { <nl> GDScriptCodeGenerator : : Address self ; <nl> self . mode = GDScriptCodeGenerator : : Address : : CLASS ; <nl> gen - > write_call ( result , self , call - > function_name , arguments ) ; <nl> GDScriptCodeGenerator : : Address GDScriptCompiler : : _parse_expression ( CodeGen & code <nl> } <nl> if ( within_await ) { <nl> gen - > write_call_async ( result , base , call - > function_name , arguments ) ; <nl> + } else if ( base . type . has_type & & base . type . kind ! = GDScriptDataType : : BUILTIN ) { <nl> + / / Native method , use faster path . <nl> + StringName class_name ; <nl> + if ( base . type . kind = = GDScriptDataType : : NATIVE ) { <nl> + class_name = base . type . native_type ; <nl> + } else { <nl> + class_name = base . type . native_type = = StringName ( ) ? base . type . script_type - > get_instance_base_type ( ) : base . type . native_type ; <nl> + } <nl> + if ( ClassDB : : class_exists ( class_name ) & & ClassDB : : has_method ( class_name , call - > function_name ) ) { <nl> + MethodBind * method = ClassDB : : get_method ( class_name , call - > function_name ) ; <nl> + if ( _have_exact_arguments ( method , arguments ) ) { <nl> + / / Exact arguments , use ptrcall . <nl> + gen - > write_call_ptrcall ( result , base , method , arguments ) ; <nl> + } else { <nl> + / / Not exact arguments , but still can use method bind call . <nl> + gen - > write_call_method_bind ( result , base , method , arguments ) ; <nl> + } <nl> + } else { <nl> + gen - > write_call ( result , base , call - > function_name , arguments ) ; <nl> + } <nl> + } else if ( base . type . has_type & & base . type . kind = = GDScriptDataType : : BUILTIN ) { <nl> + gen - > write_call_builtin_type ( result , base , base . type . builtin_type , call - > function_name , arguments ) ; <nl> } else { <nl> gen - > write_call ( result , base , call - > function_name , arguments ) ; <nl> } <nl> GDScriptCodeGenerator : : Address GDScriptCompiler : : _parse_expression ( CodeGen & code <nl> GDScriptCodeGenerator : : Address result = codegen . add_temporary ( _gdtype_from_datatype ( get_node - > get_datatype ( ) ) ) ; <nl> <nl> MethodBind * get_node_method = ClassDB : : get_method ( " Node " , " get_node " ) ; <nl> - gen - > write_call_method_bind ( result , GDScriptCodeGenerator : : Address ( GDScriptCodeGenerator : : Address : : SELF ) , get_node_method , args ) ; <nl> + gen - > write_call_ptrcall ( result , GDScriptCodeGenerator : : Address ( GDScriptCodeGenerator : : Address : : SELF ) , get_node_method , args ) ; <nl> <nl> return result ; <nl> } break ; <nl> new file mode 100644 <nl> index 00000000000 . . c918251772c <nl> mmm / dev / null <nl> ppp b / modules / gdscript / gdscript_disassembler . cpp <nl> <nl> + / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> + / * gdscript_disassembler . cpp * / <nl> + / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> + / * This file is part of : * / <nl> + / * GODOT ENGINE * / <nl> + / * https : / / godotengine . org * / <nl> + / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> + / * Copyright ( c ) 2007 - 2020 Juan Linietsky , Ariel Manzur . * / <nl> + / * Copyright ( c ) 2014 - 2020 Godot Engine contributors ( cf . AUTHORS . md ) . * / <nl> + / * * / <nl> + / * Permission is hereby granted , free of charge , to any person obtaining * / <nl> + / * a copy of this software and associated documentation files ( the * / <nl> + / * " Software " ) , to deal in the Software without restriction , including * / <nl> + / * without limitation the rights to use , copy , modify , merge , publish , * / <nl> + / * distribute , sublicense , and / or sell copies of the Software , and to * / <nl> + / * permit persons to whom the Software is furnished to do so , subject to * / <nl> + / * the following conditions : * / <nl> + / * * / <nl> + / * The above copyright notice and this permission notice shall be * / <nl> + / * included in all copies or substantial portions of the Software . * / <nl> + / * * / <nl> + / * THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , * / <nl> + / * EXPRESS OR IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * / <nl> + / * MERCHANTABILITY , FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . * / <nl> + / * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * / <nl> + / * CLAIM , DAMAGES OR OTHER LIABILITY , WHETHER IN AN ACTION OF CONTRACT , * / <nl> + / * TORT OR OTHERWISE , ARISING FROM , OUT OF OR IN CONNECTION WITH THE * / <nl> + / * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE . * / <nl> + / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + <nl> + # include " gdscript_function . h " <nl> + <nl> + # include " core / string / string_builder . h " <nl> + # include " gdscript . h " <nl> + # include " gdscript_functions . h " <nl> + <nl> + static String _get_variant_string ( const Variant & p_variant ) { <nl> + String txt ; <nl> + if ( p_variant . get_type ( ) = = Variant : : STRING ) { <nl> + txt = " \ " " + String ( p_variant ) + " \ " " ; <nl> + } else if ( p_variant . get_type ( ) = = Variant : : STRING_NAME ) { <nl> + txt = " & \ " " + String ( p_variant ) + " \ " " ; <nl> + } else if ( p_variant . get_type ( ) = = Variant : : NODE_PATH ) { <nl> + txt = " ^ \ " " + String ( p_variant ) + " \ " " ; <nl> + } else if ( p_variant . get_type ( ) = = Variant : : OBJECT ) { <nl> + Object * obj = p_variant ; <nl> + if ( ! obj ) { <nl> + txt = " null " ; <nl> + } else { <nl> + GDScriptNativeClass * cls = Object : : cast_to < GDScriptNativeClass > ( obj ) ; <nl> + if ( cls ) { <nl> + txt + = cls - > get_name ( ) ; <nl> + txt + = " ( class ) " ; <nl> + } else { <nl> + txt = obj - > get_class ( ) ; <nl> + if ( obj - > get_script_instance ( ) ) { <nl> + txt + = " ( " + obj - > get_script_instance ( ) - > get_script ( ) - > get_path ( ) + " ) " ; <nl> + } <nl> + } <nl> + } <nl> + } else { <nl> + txt = p_variant ; <nl> + } <nl> + return txt ; <nl> + } <nl> + <nl> + static String _disassemble_address ( const GDScript * p_script , const GDScriptFunction & p_function , int p_address ) { <nl> + int addr = p_address & GDScriptFunction : : ADDR_MASK ; <nl> + <nl> + switch ( p_address > > GDScriptFunction : : ADDR_BITS ) { <nl> + case GDScriptFunction : : ADDR_TYPE_SELF : { <nl> + return " self " ; <nl> + } break ; <nl> + case GDScriptFunction : : ADDR_TYPE_CLASS : { <nl> + return " class " ; <nl> + } break ; <nl> + case GDScriptFunction : : ADDR_TYPE_MEMBER : { <nl> + return " member ( " + p_script - > debug_get_member_by_index ( addr ) + " ) " ; <nl> + } break ; <nl> + case GDScriptFunction : : ADDR_TYPE_CLASS_CONSTANT : { <nl> + return " class_const ( " + p_function . get_global_name ( addr ) + " ) " ; <nl> + } break ; <nl> + case GDScriptFunction : : ADDR_TYPE_LOCAL_CONSTANT : { <nl> + return " const ( " + _get_variant_string ( p_function . get_constant ( addr ) ) + " ) " ; <nl> + } break ; <nl> + case GDScriptFunction : : ADDR_TYPE_STACK : { <nl> + return " stack ( " + itos ( addr ) + " ) " ; <nl> + } break ; <nl> + case GDScriptFunction : : ADDR_TYPE_STACK_VARIABLE : { <nl> + return " var_stack ( " + itos ( addr ) + " ) " ; <nl> + } break ; <nl> + case GDScriptFunction : : ADDR_TYPE_GLOBAL : { <nl> + return " global ( " + _get_variant_string ( GDScriptLanguage : : get_singleton ( ) - > get_global_array ( ) [ addr ] ) + " ) " ; <nl> + } break ; <nl> + case GDScriptFunction : : ADDR_TYPE_NAMED_GLOBAL : { <nl> + return " named_global ( " + p_function . get_global_name ( addr ) + " ) " ; <nl> + } break ; <nl> + case GDScriptFunction : : ADDR_TYPE_NIL : { <nl> + return " nil " ; <nl> + } break ; <nl> + } <nl> + <nl> + return " < err > " ; <nl> + } <nl> + <nl> + void GDScriptFunction : : disassemble ( const Vector < String > & p_code_lines ) const { <nl> + # define DADDR ( m_ip ) ( _disassemble_address ( _script , * this , _code_ptr [ ip + m_ip ] ) ) <nl> + <nl> + for ( int ip = 0 ; ip < _code_size ; ) { <nl> + StringBuilder text ; <nl> + int incr = 0 ; <nl> + <nl> + text + = " " ; <nl> + text + = itos ( ip ) ; <nl> + text + = " : " ; <nl> + <nl> + / / This makes the compiler complain if some opcode is unchecked in the switch . <nl> + Opcode code = Opcode ( _code_ptr [ ip ] & INSTR_MASK ) ; <nl> + int instr_var_args = ( _code_ptr [ ip ] & INSTR_ARGS_MASK ) > > INSTR_BITS ; <nl> + <nl> + switch ( code ) { <nl> + case OPCODE_OPERATOR : { <nl> + int operation = _code_ptr [ ip + 4 ] ; <nl> + <nl> + text + = " operator " ; <nl> + <nl> + text + = DADDR ( 3 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " " ; <nl> + text + = Variant : : get_operator_name ( Variant : : Operator ( operation ) ) ; <nl> + text + = " " ; <nl> + text + = DADDR ( 2 ) ; <nl> + <nl> + incr + = 5 ; <nl> + } break ; <nl> + case OPCODE_OPERATOR_VALIDATED : { <nl> + text + = " validated operator " ; <nl> + <nl> + text + = DADDR ( 3 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " < operator function > " ; <nl> + text + = DADDR ( 2 ) ; <nl> + <nl> + incr + = 5 ; <nl> + } break ; <nl> + case OPCODE_EXTENDS_TEST : { <nl> + text + = " is object " ; <nl> + text + = DADDR ( 3 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " is " ; <nl> + text + = DADDR ( 2 ) ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_IS_BUILTIN : { <nl> + text + = " is builtin " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " is " ; <nl> + text + = Variant : : get_type_name ( Variant : : Type ( _code_ptr [ ip + 3 ] ) ) ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_SET_KEYED : { <nl> + text + = " set keyed " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " [ " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " ] = " ; <nl> + text + = DADDR ( 3 ) ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_SET_KEYED_VALIDATED : { <nl> + text + = " set keyed validated " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " [ " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " ] = " ; <nl> + text + = DADDR ( 3 ) ; <nl> + <nl> + incr + = 5 ; <nl> + } break ; <nl> + case OPCODE_SET_INDEXED_VALIDATED : { <nl> + text + = " set indexed validated " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " [ " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " ] = " ; <nl> + text + = DADDR ( 3 ) ; <nl> + <nl> + incr + = 5 ; <nl> + } break ; <nl> + case OPCODE_GET_KEYED : { <nl> + text + = " get keyed " ; <nl> + text + = DADDR ( 3 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " [ " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " ] " ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_GET_KEYED_VALIDATED : { <nl> + text + = " get keyed validated " ; <nl> + text + = DADDR ( 3 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " [ " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " ] " ; <nl> + <nl> + incr + = 5 ; <nl> + } break ; <nl> + case OPCODE_GET_INDEXED_VALIDATED : { <nl> + text + = " get indexed validated " ; <nl> + text + = DADDR ( 3 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " [ " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " ] " ; <nl> + <nl> + incr + = 5 ; <nl> + } break ; <nl> + case OPCODE_SET_NAMED : { <nl> + text + = " set_named " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " [ \ " " ; <nl> + text + = _global_names_ptr [ _code_ptr [ ip + 3 ] ] ; <nl> + text + = " \ " ] = " ; <nl> + text + = DADDR ( 2 ) ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_SET_NAMED_VALIDATED : { <nl> + text + = " set_named validated " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " [ \ " " ; <nl> + text + = " < unknown name > " ; <nl> + text + = " \ " ] = " ; <nl> + text + = DADDR ( 2 ) ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_GET_NAMED : { <nl> + text + = " get_named " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " [ \ " " ; <nl> + text + = _global_names_ptr [ _code_ptr [ ip + 3 ] ] ; <nl> + text + = " \ " ] " ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_GET_NAMED_VALIDATED : { <nl> + text + = " get_named validated " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " [ \ " " ; <nl> + text + = " < unknown name > " ; <nl> + text + = " \ " ] " ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_SET_MEMBER : { <nl> + text + = " set_member " ; <nl> + text + = " [ \ " " ; <nl> + text + = _global_names_ptr [ _code_ptr [ ip + 2 ] ] ; <nl> + text + = " \ " ] = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + <nl> + incr + = 3 ; <nl> + } break ; <nl> + case OPCODE_GET_MEMBER : { <nl> + text + = " get_member " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " = " ; <nl> + text + = " [ \ " " ; <nl> + text + = _global_names_ptr [ _code_ptr [ ip + 2 ] ] ; <nl> + text + = " \ " ] " ; <nl> + <nl> + incr + = 3 ; <nl> + } break ; <nl> + case OPCODE_ASSIGN : { <nl> + text + = " assign " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 2 ) ; <nl> + <nl> + incr + = 3 ; <nl> + } break ; <nl> + case OPCODE_ASSIGN_TRUE : { <nl> + text + = " assign " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " = true " ; <nl> + <nl> + incr + = 2 ; <nl> + } break ; <nl> + case OPCODE_ASSIGN_FALSE : { <nl> + text + = " assign " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " = false " ; <nl> + <nl> + incr + = 2 ; <nl> + } break ; <nl> + case OPCODE_ASSIGN_TYPED_BUILTIN : { <nl> + text + = " assign typed builtin ( " ; <nl> + text + = Variant : : get_type_name ( ( Variant : : Type ) _code_ptr [ ip + 3 ] ) ; <nl> + text + = " ) " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 2 ) ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_ASSIGN_TYPED_NATIVE : { <nl> + Variant class_name = _constants_ptr [ _code_ptr [ ip + 3 ] ] ; <nl> + GDScriptNativeClass * nc = Object : : cast_to < GDScriptNativeClass > ( class_name . operator Object * ( ) ) ; <nl> + <nl> + text + = " assign typed native ( " ; <nl> + text + = nc - > get_name ( ) . operator String ( ) ; <nl> + text + = " ) " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 2 ) ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_ASSIGN_TYPED_SCRIPT : { <nl> + Variant script = _constants_ptr [ _code_ptr [ ip + 3 ] ] ; <nl> + Script * sc = Object : : cast_to < Script > ( script . operator Object * ( ) ) ; <nl> + <nl> + text + = " assign typed script ( " ; <nl> + text + = sc - > get_path ( ) ; <nl> + text + = " ) " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 2 ) ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_CAST_TO_BUILTIN : { <nl> + text + = " cast builtin " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " as " ; <nl> + text + = Variant : : get_type_name ( Variant : : Type ( _code_ptr [ ip + 1 ] ) ) ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_CAST_TO_NATIVE : { <nl> + Variant class_name = _constants_ptr [ _code_ptr [ ip + 1 ] ] ; <nl> + GDScriptNativeClass * nc = Object : : cast_to < GDScriptNativeClass > ( class_name . operator Object * ( ) ) ; <nl> + <nl> + text + = " cast native " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " as " ; <nl> + text + = nc - > get_name ( ) ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_CAST_TO_SCRIPT : { <nl> + text + = " cast " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " = " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " as " ; <nl> + text + = DADDR ( 3 ) ; <nl> + <nl> + incr + = 4 ; <nl> + } break ; <nl> + case OPCODE_CONSTRUCT : { <nl> + Variant : : Type t = Variant : : Type ( _code_ptr [ ip + 3 + instr_var_args ] ) ; <nl> + int argc = _code_ptr [ ip + 1 + instr_var_args ] ; <nl> + <nl> + text + = " construct " ; <nl> + text + = DADDR ( 1 + argc ) ; <nl> + text + = " = " ; <nl> + <nl> + text + = Variant : : get_type_name ( t ) + " ( " ; <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + if ( i > 0 ) <nl> + text + = " , " ; <nl> + text + = DADDR ( i + 1 ) ; <nl> + } <nl> + text + = " ) " ; <nl> + <nl> + incr = 3 + instr_var_args ; <nl> + } break ; <nl> + case OPCODE_CONSTRUCT_VALIDATED : { <nl> + int argc = _code_ptr [ ip + 1 + instr_var_args ] ; <nl> + <nl> + text + = " construct validated " ; <nl> + text + = DADDR ( 1 + argc ) ; <nl> + text + = " = " ; <nl> + <nl> + text + = " < unkown type > ( " ; <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + if ( i > 0 ) <nl> + text + = " , " ; <nl> + text + = DADDR ( i + 1 ) ; <nl> + } <nl> + text + = " ) " ; <nl> + <nl> + incr = 3 + instr_var_args ; <nl> + } break ; <nl> + case OPCODE_CONSTRUCT_ARRAY : { <nl> + int argc = _code_ptr [ ip + 1 + instr_var_args ] ; <nl> + text + = " make_array " ; <nl> + text + = DADDR ( 1 + argc ) ; <nl> + text + = " = [ " ; <nl> + <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + if ( i > 0 ) <nl> + text + = " , " ; <nl> + text + = DADDR ( 1 + i ) ; <nl> + } <nl> + <nl> + text + = " ] " ; <nl> + <nl> + incr + = 3 + argc ; <nl> + } break ; <nl> + case OPCODE_CONSTRUCT_DICTIONARY : { <nl> + int argc = _code_ptr [ ip + 1 + instr_var_args ] ; <nl> + text + = " make_dict " ; <nl> + text + = DADDR ( 1 + argc * 2 ) ; <nl> + text + = " = { " ; <nl> + <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + if ( i > 0 ) <nl> + text + = " , " ; <nl> + text + = DADDR ( 1 + i * 2 + 0 ) ; <nl> + text + = " : " ; <nl> + text + = DADDR ( 1 + i * 2 + 1 ) ; <nl> + } <nl> + <nl> + text + = " } " ; <nl> + <nl> + incr + = 3 + argc * 2 ; <nl> + } break ; <nl> + case OPCODE_CALL : <nl> + case OPCODE_CALL_RETURN : <nl> + case OPCODE_CALL_ASYNC : { <nl> + bool ret = ( _code_ptr [ ip ] & INSTR_MASK ) = = OPCODE_CALL_RETURN ; <nl> + bool async = ( _code_ptr [ ip ] & INSTR_MASK ) = = OPCODE_CALL_ASYNC ; <nl> + <nl> + if ( ret ) { <nl> + text + = " call - ret " ; <nl> + } else if ( async ) { <nl> + text + = " call - async " ; <nl> + } else { <nl> + text + = " call " ; <nl> + } <nl> + <nl> + int argc = _code_ptr [ ip + 1 + instr_var_args ] ; <nl> + if ( ret | | async ) { <nl> + text + = DADDR ( 2 + argc ) + " = " ; <nl> + } <nl> + <nl> + text + = DADDR ( 1 + argc ) + " . " ; <nl> + text + = String ( _global_names_ptr [ _code_ptr [ ip + 2 + instr_var_args ] ] ) ; <nl> + text + = " ( " ; <nl> + <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + if ( i > 0 ) <nl> + text + = " , " ; <nl> + text + = DADDR ( 1 + i ) ; <nl> + } <nl> + text + = " ) " ; <nl> + <nl> + incr = 5 + argc ; <nl> + } break ; <nl> + case OPCODE_CALL_METHOD_BIND : <nl> + case OPCODE_CALL_METHOD_BIND_RET : { <nl> + bool ret = ( _code_ptr [ ip ] & INSTR_MASK ) = = OPCODE_CALL_METHOD_BIND_RET ; <nl> + <nl> + if ( ret ) { <nl> + text + = " call - method_bind - ret " ; <nl> + } else { <nl> + text + = " call - method_bind " ; <nl> + } <nl> + <nl> + MethodBind * method = _methods_ptr [ _code_ptr [ ip + 2 + instr_var_args ] ] ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 + instr_var_args ] ; <nl> + if ( ret ) { <nl> + text + = DADDR ( 2 + argc ) + " = " ; <nl> + } <nl> + <nl> + text + = DADDR ( 1 + argc ) + " . " ; <nl> + text + = method - > get_name ( ) ; <nl> + text + = " ( " ; <nl> + <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + if ( i > 0 ) <nl> + text + = " , " ; <nl> + text + = DADDR ( 1 + i ) ; <nl> + } <nl> + text + = " ) " ; <nl> + <nl> + incr = 5 + argc ; <nl> + } break ; <nl> + case OPCODE_CALL_PTRCALL_NO_RETURN : { <nl> + text + = " call - ptrcall ( no return ) " ; <nl> + <nl> + MethodBind * method = _methods_ptr [ _code_ptr [ ip + 2 + instr_var_args ] ] ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 + instr_var_args ] ; <nl> + <nl> + text + = DADDR ( 1 + argc ) + " . " ; <nl> + text + = method - > get_name ( ) ; <nl> + text + = " ( " ; <nl> + <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + if ( i > 0 ) <nl> + text + = " , " ; <nl> + text + = DADDR ( 1 + i ) ; <nl> + } <nl> + text + = " ) " ; <nl> + <nl> + incr = 5 + argc ; <nl> + } break ; <nl> + <nl> + # define DISASSEMBLE_PTRCALL ( m_type ) \ <nl> + case OPCODE_CALL_PTRCALL_ # # m_type : { \ <nl> + text + = " call - ptrcall ( return " ; \ <nl> + text + = # m_type ; \ <nl> + text + = " ) " ; \ <nl> + MethodBind * method = _methods_ptr [ _code_ptr [ ip + 2 + instr_var_args ] ] ; \ <nl> + int argc = _code_ptr [ ip + 1 + instr_var_args ] ; \ <nl> + text + = DADDR ( 2 + argc ) + " = " ; \ <nl> + text + = DADDR ( 1 + argc ) + " . " ; \ <nl> + text + = method - > get_name ( ) ; \ <nl> + text + = " ( " ; \ <nl> + for ( int i = 0 ; i < argc ; i + + ) { \ <nl> + if ( i > 0 ) \ <nl> + text + = " , " ; \ <nl> + text + = DADDR ( 1 + i ) ; \ <nl> + } \ <nl> + text + = " ) " ; \ <nl> + incr = 5 + argc ; \ <nl> + } break <nl> + <nl> + DISASSEMBLE_PTRCALL ( BOOL ) ; <nl> + DISASSEMBLE_PTRCALL ( INT ) ; <nl> + DISASSEMBLE_PTRCALL ( FLOAT ) ; <nl> + DISASSEMBLE_PTRCALL ( STRING ) ; <nl> + DISASSEMBLE_PTRCALL ( VECTOR2 ) ; <nl> + DISASSEMBLE_PTRCALL ( VECTOR2I ) ; <nl> + DISASSEMBLE_PTRCALL ( RECT2 ) ; <nl> + DISASSEMBLE_PTRCALL ( RECT2I ) ; <nl> + DISASSEMBLE_PTRCALL ( VECTOR3 ) ; <nl> + DISASSEMBLE_PTRCALL ( VECTOR3I ) ; <nl> + DISASSEMBLE_PTRCALL ( TRANSFORM2D ) ; <nl> + DISASSEMBLE_PTRCALL ( PLANE ) ; <nl> + DISASSEMBLE_PTRCALL ( AABB ) ; <nl> + DISASSEMBLE_PTRCALL ( BASIS ) ; <nl> + DISASSEMBLE_PTRCALL ( TRANSFORM ) ; <nl> + DISASSEMBLE_PTRCALL ( COLOR ) ; <nl> + DISASSEMBLE_PTRCALL ( STRING_NAME ) ; <nl> + DISASSEMBLE_PTRCALL ( NODE_PATH ) ; <nl> + DISASSEMBLE_PTRCALL ( RID ) ; <nl> + DISASSEMBLE_PTRCALL ( QUAT ) ; <nl> + DISASSEMBLE_PTRCALL ( OBJECT ) ; <nl> + DISASSEMBLE_PTRCALL ( CALLABLE ) ; <nl> + DISASSEMBLE_PTRCALL ( SIGNAL ) ; <nl> + DISASSEMBLE_PTRCALL ( DICTIONARY ) ; <nl> + DISASSEMBLE_PTRCALL ( ARRAY ) ; <nl> + DISASSEMBLE_PTRCALL ( PACKED_BYTE_ARRAY ) ; <nl> + DISASSEMBLE_PTRCALL ( PACKED_INT32_ARRAY ) ; <nl> + DISASSEMBLE_PTRCALL ( PACKED_INT64_ARRAY ) ; <nl> + DISASSEMBLE_PTRCALL ( PACKED_FLOAT32_ARRAY ) ; <nl> + DISASSEMBLE_PTRCALL ( PACKED_FLOAT64_ARRAY ) ; <nl> + DISASSEMBLE_PTRCALL ( PACKED_STRING_ARRAY ) ; <nl> + DISASSEMBLE_PTRCALL ( PACKED_VECTOR2_ARRAY ) ; <nl> + DISASSEMBLE_PTRCALL ( PACKED_VECTOR3_ARRAY ) ; <nl> + DISASSEMBLE_PTRCALL ( PACKED_COLOR_ARRAY ) ; <nl> + <nl> + case OPCODE_CALL_BUILTIN_TYPE_VALIDATED : { <nl> + int argc = _code_ptr [ ip + 1 + instr_var_args ] ; <nl> + <nl> + text + = " call - builtin - method validated " ; <nl> + <nl> + text + = DADDR ( 2 + argc ) + " = " ; <nl> + <nl> + text + = DADDR ( 1 ) + " . " ; <nl> + text + = " < unknown method > " ; <nl> + <nl> + text + = " ( " ; <nl> + <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + if ( i > 0 ) <nl> + text + = " , " ; <nl> + text + = DADDR ( 1 + i ) ; <nl> + } <nl> + text + = " ) " ; <nl> + <nl> + incr = 5 + argc ; <nl> + } break ; <nl> + case OPCODE_CALL_BUILT_IN : { <nl> + text + = " call - built - in " ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 + instr_var_args ] ; <nl> + text + = DADDR ( 1 + argc ) + " = " ; <nl> + <nl> + text + = GDScriptFunctions : : get_func_name ( GDScriptFunctions : : Function ( _code_ptr [ ip + 2 + instr_var_args ] ) ) ; <nl> + text + = " ( " ; <nl> + <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + if ( i > 0 ) <nl> + text + = " , " ; <nl> + text + = DADDR ( 1 + i ) ; <nl> + } <nl> + text + = " ) " ; <nl> + <nl> + incr = 4 + argc ; <nl> + } break ; <nl> + case OPCODE_CALL_SELF_BASE : { <nl> + text + = " call - self - base " ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 + instr_var_args ] ; <nl> + text + = DADDR ( 2 + argc ) + " = " ; <nl> + <nl> + text + = _global_names_ptr [ _code_ptr [ ip + 2 + instr_var_args ] ] ; <nl> + text + = " ( " ; <nl> + <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + if ( i > 0 ) <nl> + text + = " , " ; <nl> + text + = DADDR ( 1 + i ) ; <nl> + } <nl> + text + = " ) " ; <nl> + <nl> + incr = 4 + argc ; <nl> + } break ; <nl> + case OPCODE_AWAIT : { <nl> + text + = " await " ; <nl> + text + = DADDR ( 1 ) ; <nl> + <nl> + incr + = 2 ; <nl> + } break ; <nl> + case OPCODE_AWAIT_RESUME : { <nl> + text + = " await resume " ; <nl> + text + = DADDR ( 1 ) ; <nl> + <nl> + incr = 2 ; <nl> + } break ; <nl> + case OPCODE_JUMP : { <nl> + text + = " jump " ; <nl> + text + = itos ( _code_ptr [ ip + 1 ] ) ; <nl> + <nl> + incr = 2 ; <nl> + } break ; <nl> + case OPCODE_JUMP_IF : { <nl> + text + = " jump - if " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " to " ; <nl> + text + = itos ( _code_ptr [ ip + 2 ] ) ; <nl> + <nl> + incr = 3 ; <nl> + } break ; <nl> + case OPCODE_JUMP_IF_NOT : { <nl> + text + = " jump - if - not " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " to " ; <nl> + text + = itos ( _code_ptr [ ip + 2 ] ) ; <nl> + <nl> + incr = 3 ; <nl> + } break ; <nl> + case OPCODE_JUMP_TO_DEF_ARGUMENT : { <nl> + text + = " jump - to - default - argument " ; <nl> + <nl> + incr = 1 ; <nl> + } break ; <nl> + case OPCODE_RETURN : { <nl> + text + = " return " ; <nl> + text + = DADDR ( 1 ) ; <nl> + <nl> + incr = 2 ; <nl> + } break ; <nl> + <nl> + # define DISASSEMBLE_ITERATE ( m_type ) \ <nl> + case OPCODE_ITERATE_ # # m_type : { \ <nl> + text + = " for - loop ( typed " ; \ <nl> + text + = # m_type ; \ <nl> + text + = " ) " ; \ <nl> + text + = DADDR ( 3 ) ; \ <nl> + text + = " in " ; \ <nl> + text + = DADDR ( 2 ) ; \ <nl> + text + = " counter " ; \ <nl> + text + = DADDR ( 1 ) ; \ <nl> + text + = " end " ; \ <nl> + text + = itos ( _code_ptr [ ip + 4 ] ) ; \ <nl> + incr + = 5 ; \ <nl> + } break <nl> + <nl> + # define DISASSEMBLE_ITERATE_BEGIN ( m_type ) \ <nl> + case OPCODE_ITERATE_BEGIN_ # # m_type : { \ <nl> + text + = " for - init ( typed " ; \ <nl> + text + = # m_type ; \ <nl> + text + = " ) " ; \ <nl> + text + = DADDR ( 3 ) ; \ <nl> + text + = " in " ; \ <nl> + text + = DADDR ( 2 ) ; \ <nl> + text + = " counter " ; \ <nl> + text + = DADDR ( 1 ) ; \ <nl> + text + = " end " ; \ <nl> + text + = itos ( _code_ptr [ ip + 4 ] ) ; \ <nl> + incr + = 5 ; \ <nl> + } break <nl> + <nl> + # define DISASSEMBLE_ITERATE_TYPES ( m_macro ) \ <nl> + m_macro ( INT ) ; \ <nl> + m_macro ( FLOAT ) ; \ <nl> + m_macro ( VECTOR2 ) ; \ <nl> + m_macro ( VECTOR2I ) ; \ <nl> + m_macro ( VECTOR3 ) ; \ <nl> + m_macro ( VECTOR3I ) ; \ <nl> + m_macro ( STRING ) ; \ <nl> + m_macro ( DICTIONARY ) ; \ <nl> + m_macro ( ARRAY ) ; \ <nl> + m_macro ( PACKED_BYTE_ARRAY ) ; \ <nl> + m_macro ( PACKED_INT32_ARRAY ) ; \ <nl> + m_macro ( PACKED_INT64_ARRAY ) ; \ <nl> + m_macro ( PACKED_FLOAT32_ARRAY ) ; \ <nl> + m_macro ( PACKED_FLOAT64_ARRAY ) ; \ <nl> + m_macro ( PACKED_STRING_ARRAY ) ; \ <nl> + m_macro ( PACKED_VECTOR2_ARRAY ) ; \ <nl> + m_macro ( PACKED_VECTOR3_ARRAY ) ; \ <nl> + m_macro ( PACKED_COLOR_ARRAY ) ; \ <nl> + m_macro ( OBJECT ) <nl> + <nl> + case OPCODE_ITERATE_BEGIN : { <nl> + text + = " for - init " ; <nl> + text + = DADDR ( 3 ) ; <nl> + text + = " in " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " counter " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " end " ; <nl> + text + = itos ( _code_ptr [ ip + 4 ] ) ; <nl> + <nl> + incr + = 5 ; <nl> + } break ; <nl> + DISASSEMBLE_ITERATE_TYPES ( DISASSEMBLE_ITERATE_BEGIN ) ; <nl> + case OPCODE_ITERATE : { <nl> + text + = " for - loop " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " in " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " counter " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " end " ; <nl> + text + = itos ( _code_ptr [ ip + 4 ] ) ; <nl> + <nl> + incr + = 5 ; <nl> + } break ; <nl> + DISASSEMBLE_ITERATE_TYPES ( DISASSEMBLE_ITERATE ) ; <nl> + case OPCODE_LINE : { <nl> + int line = _code_ptr [ ip + 1 ] - 1 ; <nl> + if ( line > = 0 & & line < p_code_lines . size ( ) ) { <nl> + text + = " line " ; <nl> + text + = itos ( line + 1 ) ; <nl> + text + = " : " ; <nl> + text + = p_code_lines [ line ] ; <nl> + } else { <nl> + text + = " " ; <nl> + } <nl> + <nl> + incr + = 2 ; <nl> + } break ; <nl> + case OPCODE_ASSERT : { <nl> + text + = " assert ( " ; <nl> + text + = DADDR ( 1 ) ; <nl> + text + = " , " ; <nl> + text + = DADDR ( 2 ) ; <nl> + text + = " ) " ; <nl> + <nl> + incr + = 3 ; <nl> + } break ; <nl> + case OPCODE_BREAKPOINT : { <nl> + text + = " breakpoint " ; <nl> + <nl> + incr + = 1 ; <nl> + } break ; <nl> + case OPCODE_END : { <nl> + text + = " = = END = = " ; <nl> + <nl> + incr + = 1 ; <nl> + } break ; <nl> + } <nl> + <nl> + ip + = incr ; <nl> + if ( text . get_string_length ( ) > 0 ) { <nl> + print_line ( text . as_string ( ) ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + # endif <nl> mmm a / modules / gdscript / gdscript_function . cpp <nl> ppp b / modules / gdscript / gdscript_function . cpp <nl> <nl> <nl> # include " gdscript_function . h " <nl> <nl> - # include " core / os / os . h " <nl> # include " gdscript . h " <nl> - # include " gdscript_functions . h " <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - # include " core / string / string_builder . h " <nl> - # endif <nl> - <nl> - Variant * GDScriptFunction : : _get_variant ( int p_address , GDScriptInstance * p_instance , GDScript * p_script , Variant & self , Variant & static_ref , Variant * p_stack , String & r_error ) const { <nl> - int address = p_address & ADDR_MASK ; <nl> - <nl> - / / sequential table ( jump table generated by compiler ) <nl> - switch ( ( p_address & ADDR_TYPE_MASK ) > > ADDR_BITS ) { <nl> - case ADDR_TYPE_SELF : { <nl> - # ifdef DEBUG_ENABLED <nl> - if ( unlikely ( ! p_instance ) ) { <nl> - r_error = " Cannot access self without instance . " ; <nl> - return nullptr ; <nl> - } <nl> - # endif <nl> - return & self ; <nl> - } break ; <nl> - case ADDR_TYPE_CLASS : { <nl> - return & static_ref ; <nl> - } break ; <nl> - case ADDR_TYPE_MEMBER : { <nl> - # ifdef DEBUG_ENABLED <nl> - if ( unlikely ( ! p_instance ) ) { <nl> - r_error = " Cannot access member without instance . " ; <nl> - return nullptr ; <nl> - } <nl> - # endif <nl> - / / member indexing is O ( 1 ) <nl> - return & p_instance - > members . write [ address ] ; <nl> - } break ; <nl> - case ADDR_TYPE_CLASS_CONSTANT : { <nl> - / / todo change to index ! <nl> - GDScript * s = p_script ; <nl> - # ifdef DEBUG_ENABLED <nl> - ERR_FAIL_INDEX_V ( address , _global_names_count , nullptr ) ; <nl> - # endif <nl> - const StringName * sn = & _global_names_ptr [ address ] ; <nl> - <nl> - while ( s ) { <nl> - GDScript * o = s ; <nl> - while ( o ) { <nl> - Map < StringName , Variant > : : Element * E = o - > constants . find ( * sn ) ; <nl> - if ( E ) { <nl> - return & E - > get ( ) ; <nl> - } <nl> - o = o - > _owner ; <nl> - } <nl> - s = s - > _base ; <nl> - } <nl> - <nl> - ERR_FAIL_V_MSG ( nullptr , " GDScriptCompiler bug . " ) ; <nl> - } break ; <nl> - case ADDR_TYPE_LOCAL_CONSTANT : { <nl> - # ifdef DEBUG_ENABLED <nl> - ERR_FAIL_INDEX_V ( address , _constant_count , nullptr ) ; <nl> - # endif <nl> - return & _constants_ptr [ address ] ; <nl> - } break ; <nl> - case ADDR_TYPE_STACK : <nl> - case ADDR_TYPE_STACK_VARIABLE : { <nl> - # ifdef DEBUG_ENABLED <nl> - ERR_FAIL_INDEX_V ( address , _stack_size , nullptr ) ; <nl> - # endif <nl> - return & p_stack [ address ] ; <nl> - } break ; <nl> - case ADDR_TYPE_GLOBAL : { <nl> - # ifdef DEBUG_ENABLED <nl> - ERR_FAIL_INDEX_V ( address , GDScriptLanguage : : get_singleton ( ) - > get_global_array_size ( ) , nullptr ) ; <nl> - # endif <nl> - return & GDScriptLanguage : : get_singleton ( ) - > get_global_array ( ) [ address ] ; <nl> - } break ; <nl> - # ifdef TOOLS_ENABLED <nl> - case ADDR_TYPE_NAMED_GLOBAL : { <nl> - # ifdef DEBUG_ENABLED <nl> - ERR_FAIL_INDEX_V ( address , _global_names_count , nullptr ) ; <nl> - # endif <nl> - StringName id = _global_names_ptr [ address ] ; <nl> - <nl> - if ( GDScriptLanguage : : get_singleton ( ) - > get_named_globals_map ( ) . has ( id ) ) { <nl> - return ( Variant * ) & GDScriptLanguage : : get_singleton ( ) - > get_named_globals_map ( ) [ id ] ; <nl> - } else { <nl> - r_error = " Autoload singleton ' " + String ( id ) + " ' has been removed . " ; <nl> - return nullptr ; <nl> - } <nl> - } break ; <nl> - # endif <nl> - case ADDR_TYPE_NIL : { <nl> - return & nil ; <nl> - } break ; <nl> - } <nl> - <nl> - ERR_FAIL_V_MSG ( nullptr , " Bad code ! ( unknown addressing mode ) . " ) ; <nl> - return nullptr ; <nl> - } <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - static String _get_var_type ( const Variant * p_var ) { <nl> - String basestr ; <nl> - <nl> - if ( p_var - > get_type ( ) = = Variant : : OBJECT ) { <nl> - bool was_freed ; <nl> - Object * bobj = p_var - > get_validated_object_with_check ( was_freed ) ; <nl> - if ( ! bobj ) { <nl> - if ( was_freed ) { <nl> - basestr = " null instance " ; <nl> - } else { <nl> - basestr = " previously freed " ; <nl> - } <nl> - } else { <nl> - if ( bobj - > get_script_instance ( ) ) { <nl> - basestr = bobj - > get_class ( ) + " ( " + bobj - > get_script_instance ( ) - > get_script ( ) - > get_path ( ) . get_file ( ) + " ) " ; <nl> - } else { <nl> - basestr = bobj - > get_class ( ) ; <nl> - } <nl> - } <nl> - <nl> - } else { <nl> - basestr = Variant : : get_type_name ( p_var - > get_type ( ) ) ; <nl> - } <nl> - <nl> - return basestr ; <nl> - } <nl> - # endif / / DEBUG_ENABLED <nl> - <nl> - String GDScriptFunction : : _get_call_error ( const Callable : : CallError & p_err , const String & p_where , const Variant * * argptrs ) const { <nl> - String err_text ; <nl> - <nl> - if ( p_err . error = = Callable : : CallError : : CALL_ERROR_INVALID_ARGUMENT ) { <nl> - int errorarg = p_err . argument ; <nl> - / / Handle the Object to Object case separately as we don ' t have further class details . <nl> - # ifdef DEBUG_ENABLED <nl> - if ( p_err . expected = = Variant : : OBJECT & & argptrs [ errorarg ] - > get_type ( ) = = p_err . expected ) { <nl> - err_text = " Invalid type in " + p_where + " . The Object - derived class of argument " + itos ( errorarg + 1 ) + " ( " + _get_var_type ( argptrs [ errorarg ] ) + " ) is not a subclass of the expected argument class . " ; <nl> - } else <nl> - # endif / / DEBUG_ENABLED <nl> - { <nl> - err_text = " Invalid type in " + p_where + " . Cannot convert argument " + itos ( errorarg + 1 ) + " from " + Variant : : get_type_name ( argptrs [ errorarg ] - > get_type ( ) ) + " to " + Variant : : get_type_name ( Variant : : Type ( p_err . expected ) ) + " . " ; <nl> - } <nl> - } else if ( p_err . error = = Callable : : CallError : : CALL_ERROR_TOO_MANY_ARGUMENTS ) { <nl> - err_text = " Invalid call to " + p_where + " . Expected " + itos ( p_err . argument ) + " arguments . " ; <nl> - } else if ( p_err . error = = Callable : : CallError : : CALL_ERROR_TOO_FEW_ARGUMENTS ) { <nl> - err_text = " Invalid call to " + p_where + " . Expected " + itos ( p_err . argument ) + " arguments . " ; <nl> - } else if ( p_err . error = = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ) { <nl> - err_text = " Invalid call . Nonexistent " + p_where + " . " ; <nl> - } else if ( p_err . error = = Callable : : CallError : : CALL_ERROR_INSTANCE_IS_NULL ) { <nl> - err_text = " Attempt to call " + p_where + " on a null instance . " ; <nl> - } else { <nl> - err_text = " Bug , call error : # " + itos ( p_err . error ) ; <nl> - } <nl> - <nl> - return err_text ; <nl> - } <nl> - <nl> - # if defined ( __GNUC__ ) <nl> - # define OPCODES_TABLE \ <nl> - static const void * switch_table_ops [ ] = { \ <nl> - & & OPCODE_OPERATOR , \ <nl> - & & OPCODE_EXTENDS_TEST , \ <nl> - & & OPCODE_IS_BUILTIN , \ <nl> - & & OPCODE_SET , \ <nl> - & & OPCODE_GET , \ <nl> - & & OPCODE_SET_NAMED , \ <nl> - & & OPCODE_GET_NAMED , \ <nl> - & & OPCODE_SET_MEMBER , \ <nl> - & & OPCODE_GET_MEMBER , \ <nl> - & & OPCODE_ASSIGN , \ <nl> - & & OPCODE_ASSIGN_TRUE , \ <nl> - & & OPCODE_ASSIGN_FALSE , \ <nl> - & & OPCODE_ASSIGN_TYPED_BUILTIN , \ <nl> - & & OPCODE_ASSIGN_TYPED_NATIVE , \ <nl> - & & OPCODE_ASSIGN_TYPED_SCRIPT , \ <nl> - & & OPCODE_CAST_TO_BUILTIN , \ <nl> - & & OPCODE_CAST_TO_NATIVE , \ <nl> - & & OPCODE_CAST_TO_SCRIPT , \ <nl> - & & OPCODE_CONSTRUCT , \ <nl> - & & OPCODE_CONSTRUCT_ARRAY , \ <nl> - & & OPCODE_CONSTRUCT_DICTIONARY , \ <nl> - & & OPCODE_CALL , \ <nl> - & & OPCODE_CALL_RETURN , \ <nl> - & & OPCODE_CALL_ASYNC , \ <nl> - & & OPCODE_CALL_BUILT_IN , \ <nl> - & & OPCODE_CALL_SELF_BASE , \ <nl> - & & OPCODE_AWAIT , \ <nl> - & & OPCODE_AWAIT_RESUME , \ <nl> - & & OPCODE_JUMP , \ <nl> - & & OPCODE_JUMP_IF , \ <nl> - & & OPCODE_JUMP_IF_NOT , \ <nl> - & & OPCODE_JUMP_TO_DEF_ARGUMENT , \ <nl> - & & OPCODE_RETURN , \ <nl> - & & OPCODE_ITERATE_BEGIN , \ <nl> - & & OPCODE_ITERATE , \ <nl> - & & OPCODE_ASSERT , \ <nl> - & & OPCODE_BREAKPOINT , \ <nl> - & & OPCODE_LINE , \ <nl> - & & OPCODE_END \ <nl> - } ; \ <nl> - static_assert ( ( sizeof ( switch_table_ops ) / sizeof ( switch_table_ops [ 0 ] ) = = ( OPCODE_END + 1 ) ) , " Opcodes in jump table aren ' t the same as opcodes in enum . " ) ; <nl> - <nl> - # define OPCODE ( m_op ) \ <nl> - m_op : <nl> - # define OPCODE_WHILE ( m_test ) <nl> - # define OPCODES_END \ <nl> - OPSEXIT : <nl> - # define OPCODES_OUT \ <nl> - OPSOUT : <nl> - # define DISPATCH_OPCODE goto * switch_table_ops [ _code_ptr [ ip ] ] <nl> - # define OPCODE_SWITCH ( m_test ) DISPATCH_OPCODE ; <nl> - # define OPCODE_BREAK goto OPSEXIT <nl> - # define OPCODE_OUT goto OPSOUT <nl> - # else <nl> - # define OPCODES_TABLE <nl> - # define OPCODE ( m_op ) case m_op : <nl> - # define OPCODE_WHILE ( m_test ) while ( m_test ) <nl> - # define OPCODES_END <nl> - # define OPCODES_OUT <nl> - # define DISPATCH_OPCODE continue <nl> - # define OPCODE_SWITCH ( m_test ) switch ( m_test ) <nl> - # define OPCODE_BREAK break <nl> - # define OPCODE_OUT break <nl> - # endif <nl> - <nl> - Variant GDScriptFunction : : call ( GDScriptInstance * p_instance , const Variant * * p_args , int p_argcount , Callable : : CallError & r_err , CallState * p_state ) { <nl> - OPCODES_TABLE ; <nl> - <nl> - if ( ! _code_ptr ) { <nl> - return Variant ( ) ; <nl> - } <nl> - <nl> - r_err . error = Callable : : CallError : : CALL_OK ; <nl> - <nl> - Variant self ; <nl> - Variant static_ref ; <nl> - Variant retvalue ; <nl> - Variant * stack = nullptr ; <nl> - Variant * * call_args ; <nl> - int defarg = 0 ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - <nl> - / / GDScriptLanguage : : get_singleton ( ) - > calls + + ; <nl> - <nl> - # endif <nl> - <nl> - uint32_t alloca_size = 0 ; <nl> - GDScript * script ; <nl> - int ip = 0 ; <nl> - int line = _initial_line ; <nl> - <nl> - if ( p_state ) { <nl> - / / use existing ( supplied ) state ( awaited ) <nl> - stack = ( Variant * ) p_state - > stack . ptr ( ) ; <nl> - call_args = ( Variant * * ) & p_state - > stack . ptr ( ) [ sizeof ( Variant ) * p_state - > stack_size ] ; / / ptr ( ) to avoid bounds check <nl> - line = p_state - > line ; <nl> - ip = p_state - > ip ; <nl> - alloca_size = p_state - > stack . size ( ) ; <nl> - script = p_state - > script ; <nl> - p_instance = p_state - > instance ; <nl> - defarg = p_state - > defarg ; <nl> - self = p_state - > self ; <nl> - <nl> - } else { <nl> - if ( p_argcount ! = _argument_count ) { <nl> - if ( p_argcount > _argument_count ) { <nl> - r_err . error = Callable : : CallError : : CALL_ERROR_TOO_MANY_ARGUMENTS ; <nl> - r_err . argument = _argument_count ; <nl> - <nl> - return Variant ( ) ; <nl> - } else if ( p_argcount < _argument_count - _default_arg_count ) { <nl> - r_err . error = Callable : : CallError : : CALL_ERROR_TOO_FEW_ARGUMENTS ; <nl> - r_err . argument = _argument_count - _default_arg_count ; <nl> - return Variant ( ) ; <nl> - } else { <nl> - defarg = _argument_count - p_argcount ; <nl> - } <nl> - } <nl> - <nl> - alloca_size = sizeof ( Variant * ) * _call_size + sizeof ( Variant ) * _stack_size ; <nl> - <nl> - if ( alloca_size ) { <nl> - uint8_t * aptr = ( uint8_t * ) alloca ( alloca_size ) ; <nl> - <nl> - if ( _stack_size ) { <nl> - stack = ( Variant * ) aptr ; <nl> - for ( int i = 0 ; i < p_argcount ; i + + ) { <nl> - if ( ! argument_types [ i ] . has_type ) { <nl> - memnew_placement ( & stack [ i ] , Variant ( * p_args [ i ] ) ) ; <nl> - continue ; <nl> - } <nl> - <nl> - if ( ! argument_types [ i ] . is_type ( * p_args [ i ] , true ) ) { <nl> - r_err . error = Callable : : CallError : : CALL_ERROR_INVALID_ARGUMENT ; <nl> - r_err . argument = i ; <nl> - r_err . expected = argument_types [ i ] . kind = = GDScriptDataType : : BUILTIN ? argument_types [ i ] . builtin_type : Variant : : OBJECT ; <nl> - return Variant ( ) ; <nl> - } <nl> - if ( argument_types [ i ] . kind = = GDScriptDataType : : BUILTIN ) { <nl> - Variant arg ; <nl> - Variant : : construct ( argument_types [ i ] . builtin_type , arg , & p_args [ i ] , 1 , r_err ) ; <nl> - memnew_placement ( & stack [ i ] , Variant ( arg ) ) ; <nl> - } else { <nl> - memnew_placement ( & stack [ i ] , Variant ( * p_args [ i ] ) ) ; <nl> - } <nl> - } <nl> - for ( int i = p_argcount ; i < _stack_size ; i + + ) { <nl> - memnew_placement ( & stack [ i ] , Variant ) ; <nl> - } <nl> - } else { <nl> - stack = nullptr ; <nl> - } <nl> - <nl> - if ( _call_size ) { <nl> - call_args = ( Variant * * ) & aptr [ sizeof ( Variant ) * _stack_size ] ; <nl> - } else { <nl> - call_args = nullptr ; <nl> - } <nl> - <nl> - } else { <nl> - stack = nullptr ; <nl> - call_args = nullptr ; <nl> - } <nl> - <nl> - if ( p_instance ) { <nl> - if ( p_instance - > base_ref & & static_cast < Reference * > ( p_instance - > owner ) - > is_referenced ( ) ) { <nl> - self = REF ( static_cast < Reference * > ( p_instance - > owner ) ) ; <nl> - } else { <nl> - self = p_instance - > owner ; <nl> - } <nl> - script = p_instance - > script . ptr ( ) ; <nl> - } else { <nl> - script = _script ; <nl> - } <nl> - } <nl> - <nl> - static_ref = script ; <nl> - <nl> - String err_text ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - <nl> - if ( EngineDebugger : : is_active ( ) ) { <nl> - GDScriptLanguage : : get_singleton ( ) - > enter_function ( p_instance , this , stack , & ip , & line ) ; <nl> - } <nl> - <nl> - # define GD_ERR_BREAK ( m_cond ) \ <nl> - { \ <nl> - if ( unlikely ( m_cond ) ) { \ <nl> - _err_print_error ( FUNCTION_STR , __FILE__ , __LINE__ , " Condition ' " _STR ( m_cond ) " ' is true . Breaking . . : " ) ; \ <nl> - OPCODE_BREAK ; \ <nl> - } \ <nl> - } <nl> - <nl> - # define CHECK_SPACE ( m_space ) \ <nl> - GD_ERR_BREAK ( ( ip + m_space ) > _code_size ) <nl> - <nl> - # define GET_VARIANT_PTR ( m_v , m_code_ofs ) \ <nl> - Variant * m_v ; \ <nl> - m_v = _get_variant ( _code_ptr [ ip + m_code_ofs ] , p_instance , script , self , static_ref , stack , err_text ) ; \ <nl> - if ( unlikely ( ! m_v ) ) \ <nl> - OPCODE_BREAK ; <nl> - <nl> - # else <nl> - # define GD_ERR_BREAK ( m_cond ) <nl> - # define CHECK_SPACE ( m_space ) <nl> - # define GET_VARIANT_PTR ( m_v , m_code_ofs ) \ <nl> - Variant * m_v ; \ <nl> - m_v = _get_variant ( _code_ptr [ ip + m_code_ofs ] , p_instance , script , self , static_ref , stack , err_text ) ; <nl> - <nl> - # endif <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - <nl> - uint64_t function_start_time = 0 ; <nl> - uint64_t function_call_time = 0 ; <nl> - <nl> - if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> - function_start_time = OS : : get_singleton ( ) - > get_ticks_usec ( ) ; <nl> - function_call_time = 0 ; <nl> - profile . call_count + + ; <nl> - profile . frame_call_count + + ; <nl> - } <nl> - bool exit_ok = false ; <nl> - bool awaited = false ; <nl> - # endif <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - OPCODE_WHILE ( ip < _code_size ) { <nl> - int last_opcode = _code_ptr [ ip ] ; <nl> - # else <nl> - OPCODE_WHILE ( true ) { <nl> - # endif <nl> - <nl> - OPCODE_SWITCH ( _code_ptr [ ip ] ) { <nl> - OPCODE ( OPCODE_OPERATOR ) { <nl> - CHECK_SPACE ( 5 ) ; <nl> - <nl> - bool valid ; <nl> - Variant : : Operator op = ( Variant : : Operator ) _code_ptr [ ip + 1 ] ; <nl> - GD_ERR_BREAK ( op > = Variant : : OP_MAX ) ; <nl> - <nl> - GET_VARIANT_PTR ( a , 2 ) ; <nl> - GET_VARIANT_PTR ( b , 3 ) ; <nl> - GET_VARIANT_PTR ( dst , 4 ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - <nl> - Variant ret ; <nl> - Variant : : evaluate ( op , * a , * b , ret , valid ) ; <nl> - # else <nl> - Variant : : evaluate ( op , * a , * b , * dst , valid ) ; <nl> - # endif <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ! valid ) { <nl> - if ( ret . get_type ( ) = = Variant : : STRING ) { <nl> - / / return a string when invalid with the error <nl> - err_text = ret ; <nl> - err_text + = " in operator ' " + Variant : : get_operator_name ( op ) + " ' . " ; <nl> - } else { <nl> - err_text = " Invalid operands ' " + Variant : : get_type_name ( a - > get_type ( ) ) + " ' and ' " + Variant : : get_type_name ( b - > get_type ( ) ) + " ' in operator ' " + Variant : : get_operator_name ( op ) + " ' . " ; <nl> - } <nl> - OPCODE_BREAK ; <nl> - } <nl> - * dst = ret ; <nl> - # endif <nl> - ip + = 5 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_EXTENDS_TEST ) { <nl> - CHECK_SPACE ( 4 ) ; <nl> - <nl> - GET_VARIANT_PTR ( a , 1 ) ; <nl> - GET_VARIANT_PTR ( b , 2 ) ; <nl> - GET_VARIANT_PTR ( dst , 3 ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - if ( b - > get_type ( ) ! = Variant : : OBJECT | | b - > operator Object * ( ) = = nullptr ) { <nl> - err_text = " Right operand of ' is ' is not a class . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - <nl> - bool extends_ok = false ; <nl> - if ( a - > get_type ( ) = = Variant : : OBJECT & & a - > operator Object * ( ) ! = nullptr ) { <nl> - # ifdef DEBUG_ENABLED <nl> - bool was_freed ; <nl> - Object * obj_A = a - > get_validated_object_with_check ( was_freed ) ; <nl> - <nl> - if ( was_freed ) { <nl> - err_text = " Left operand of ' is ' is a previously freed instance . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - <nl> - Object * obj_B = b - > get_validated_object_with_check ( was_freed ) ; <nl> - <nl> - if ( was_freed ) { <nl> - err_text = " Right operand of ' is ' is a previously freed instance . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # else <nl> - <nl> - Object * obj_A = * a ; <nl> - Object * obj_B = * b ; <nl> - # endif / / DEBUG_ENABLED <nl> - <nl> - GDScript * scr_B = Object : : cast_to < GDScript > ( obj_B ) ; <nl> - <nl> - if ( scr_B ) { <nl> - / / if B is a script , the only valid condition is that A has an instance which inherits from the script <nl> - / / in other situation , this shoul return false . <nl> - <nl> - if ( obj_A - > get_script_instance ( ) & & obj_A - > get_script_instance ( ) - > get_language ( ) = = GDScriptLanguage : : get_singleton ( ) ) { <nl> - GDScript * cmp = static_cast < GDScript * > ( obj_A - > get_script_instance ( ) - > get_script ( ) . ptr ( ) ) ; <nl> - / / bool found = false ; <nl> - while ( cmp ) { <nl> - if ( cmp = = scr_B ) { <nl> - / / inherits from script , all ok <nl> - extends_ok = true ; <nl> - break ; <nl> - } <nl> - <nl> - cmp = cmp - > _base ; <nl> - } <nl> - } <nl> - <nl> - } else { <nl> - GDScriptNativeClass * nc = Object : : cast_to < GDScriptNativeClass > ( obj_B ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ! nc ) { <nl> - err_text = " Right operand of ' is ' is not a class ( type : ' " + obj_B - > get_class ( ) + " ' ) . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - extends_ok = ClassDB : : is_parent_class ( obj_A - > get_class_name ( ) , nc - > get_name ( ) ) ; <nl> - } <nl> - } <nl> - <nl> - * dst = extends_ok ; <nl> - ip + = 4 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_IS_BUILTIN ) { <nl> - CHECK_SPACE ( 4 ) ; <nl> - <nl> - GET_VARIANT_PTR ( value , 1 ) ; <nl> - Variant : : Type var_type = ( Variant : : Type ) _code_ptr [ ip + 2 ] ; <nl> - GET_VARIANT_PTR ( dst , 3 ) ; <nl> - <nl> - GD_ERR_BREAK ( var_type < 0 | | var_type > = Variant : : VARIANT_MAX ) ; <nl> - <nl> - * dst = value - > get_type ( ) = = var_type ; <nl> - ip + = 4 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_SET ) { <nl> - CHECK_SPACE ( 3 ) ; <nl> - <nl> - GET_VARIANT_PTR ( dst , 1 ) ; <nl> - GET_VARIANT_PTR ( index , 2 ) ; <nl> - GET_VARIANT_PTR ( value , 3 ) ; <nl> - <nl> - bool valid ; <nl> - dst - > set ( * index , * value , & valid ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ! valid ) { <nl> - String v = index - > operator String ( ) ; <nl> - if ( v ! = " " ) { <nl> - v = " ' " + v + " ' " ; <nl> - } else { <nl> - v = " of type ' " + _get_var_type ( index ) + " ' " ; <nl> - } <nl> - err_text = " Invalid set index " + v + " ( on base : ' " + _get_var_type ( dst ) + " ' ) with value of type ' " + _get_var_type ( value ) + " ' " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - ip + = 4 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_GET ) { <nl> - CHECK_SPACE ( 3 ) ; <nl> - <nl> - GET_VARIANT_PTR ( src , 1 ) ; <nl> - GET_VARIANT_PTR ( index , 2 ) ; <nl> - GET_VARIANT_PTR ( dst , 3 ) ; <nl> - <nl> - bool valid ; <nl> - # ifdef DEBUG_ENABLED <nl> - / / allow better error message in cases where src and dst are the same stack position <nl> - Variant ret = src - > get ( * index , & valid ) ; <nl> - # else <nl> - * dst = src - > get ( * index , & valid ) ; <nl> - <nl> - # endif <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ! valid ) { <nl> - String v = index - > operator String ( ) ; <nl> - if ( v ! = " " ) { <nl> - v = " ' " + v + " ' " ; <nl> - } else { <nl> - v = " of type ' " + _get_var_type ( index ) + " ' " ; <nl> - } <nl> - err_text = " Invalid get index " + v + " ( on base : ' " + _get_var_type ( src ) + " ' ) . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - * dst = ret ; <nl> - # endif <nl> - ip + = 4 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_SET_NAMED ) { <nl> - CHECK_SPACE ( 3 ) ; <nl> - <nl> - GET_VARIANT_PTR ( dst , 1 ) ; <nl> - GET_VARIANT_PTR ( value , 3 ) ; <nl> - <nl> - int indexname = _code_ptr [ ip + 2 ] ; <nl> - <nl> - GD_ERR_BREAK ( indexname < 0 | | indexname > = _global_names_count ) ; <nl> - const StringName * index = & _global_names_ptr [ indexname ] ; <nl> - <nl> - bool valid ; <nl> - dst - > set_named ( * index , * value , valid ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ! valid ) { <nl> - String err_type ; <nl> - err_text = " Invalid set index ' " + String ( * index ) + " ' ( on base : ' " + _get_var_type ( dst ) + " ' ) with value of type ' " + _get_var_type ( value ) + " ' . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - ip + = 4 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_GET_NAMED ) { <nl> - CHECK_SPACE ( 4 ) ; <nl> - <nl> - GET_VARIANT_PTR ( src , 1 ) ; <nl> - GET_VARIANT_PTR ( dst , 3 ) ; <nl> - <nl> - int indexname = _code_ptr [ ip + 2 ] ; <nl> - <nl> - GD_ERR_BREAK ( indexname < 0 | | indexname > = _global_names_count ) ; <nl> - const StringName * index = & _global_names_ptr [ indexname ] ; <nl> - <nl> - bool valid ; <nl> - # ifdef DEBUG_ENABLED <nl> - / / allow better error message in cases where src and dst are the same stack position <nl> - Variant ret = src - > get_named ( * index , valid ) ; <nl> - <nl> - # else <nl> - * dst = src - > get_named ( * index , valid ) ; <nl> - # endif <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ! valid ) { <nl> - if ( src - > has_method ( * index ) ) { <nl> - err_text = " Invalid get index ' " + index - > operator String ( ) + " ' ( on base : ' " + _get_var_type ( src ) + " ' ) . Did you mean ' . " + index - > operator String ( ) + " ( ) ' or funcref ( obj , \ " " + index - > operator String ( ) + " \ " ) ? " ; <nl> - } else { <nl> - err_text = " Invalid get index ' " + index - > operator String ( ) + " ' ( on base : ' " + _get_var_type ( src ) + " ' ) . " ; <nl> - } <nl> - OPCODE_BREAK ; <nl> - } <nl> - * dst = ret ; <nl> - # endif <nl> - ip + = 4 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_SET_MEMBER ) { <nl> - CHECK_SPACE ( 3 ) ; <nl> - int indexname = _code_ptr [ ip + 1 ] ; <nl> - GD_ERR_BREAK ( indexname < 0 | | indexname > = _global_names_count ) ; <nl> - const StringName * index = & _global_names_ptr [ indexname ] ; <nl> - GET_VARIANT_PTR ( src , 2 ) ; <nl> - <nl> - bool valid ; <nl> - # ifndef DEBUG_ENABLED <nl> - ClassDB : : set_property ( p_instance - > owner , * index , * src , & valid ) ; <nl> - # else <nl> - bool ok = ClassDB : : set_property ( p_instance - > owner , * index , * src , & valid ) ; <nl> - if ( ! ok ) { <nl> - err_text = " Internal error setting property : " + String ( * index ) ; <nl> - OPCODE_BREAK ; <nl> - } else if ( ! valid ) { <nl> - err_text = " Error setting property ' " + String ( * index ) + " ' with value of type " + Variant : : get_type_name ( src - > get_type ( ) ) + " . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - ip + = 3 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_GET_MEMBER ) { <nl> - CHECK_SPACE ( 3 ) ; <nl> - int indexname = _code_ptr [ ip + 1 ] ; <nl> - GD_ERR_BREAK ( indexname < 0 | | indexname > = _global_names_count ) ; <nl> - const StringName * index = & _global_names_ptr [ indexname ] ; <nl> - GET_VARIANT_PTR ( dst , 2 ) ; <nl> - <nl> - # ifndef DEBUG_ENABLED <nl> - ClassDB : : get_property ( p_instance - > owner , * index , * dst ) ; <nl> - # else <nl> - bool ok = ClassDB : : get_property ( p_instance - > owner , * index , * dst ) ; <nl> - if ( ! ok ) { <nl> - err_text = " Internal error getting property : " + String ( * index ) ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - ip + = 3 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_ASSIGN ) { <nl> - CHECK_SPACE ( 3 ) ; <nl> - GET_VARIANT_PTR ( dst , 1 ) ; <nl> - GET_VARIANT_PTR ( src , 2 ) ; <nl> - <nl> - * dst = * src ; <nl> - <nl> - ip + = 3 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_ASSIGN_TRUE ) { <nl> - CHECK_SPACE ( 2 ) ; <nl> - GET_VARIANT_PTR ( dst , 1 ) ; <nl> - <nl> - * dst = true ; <nl> - <nl> - ip + = 2 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_ASSIGN_FALSE ) { <nl> - CHECK_SPACE ( 2 ) ; <nl> - GET_VARIANT_PTR ( dst , 1 ) ; <nl> - <nl> - * dst = false ; <nl> - <nl> - ip + = 2 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_ASSIGN_TYPED_BUILTIN ) { <nl> - CHECK_SPACE ( 4 ) ; <nl> - GET_VARIANT_PTR ( dst , 2 ) ; <nl> - GET_VARIANT_PTR ( src , 3 ) ; <nl> - <nl> - Variant : : Type var_type = ( Variant : : Type ) _code_ptr [ ip + 1 ] ; <nl> - GD_ERR_BREAK ( var_type < 0 | | var_type > = Variant : : VARIANT_MAX ) ; <nl> - <nl> - if ( src - > get_type ( ) ! = var_type ) { <nl> - # ifdef DEBUG_ENABLED <nl> - if ( Variant : : can_convert_strict ( src - > get_type ( ) , var_type ) ) { <nl> - # endif / / DEBUG_ENABLED <nl> - Callable : : CallError ce ; <nl> - Variant : : construct ( var_type , * dst , const_cast < const Variant * * > ( & src ) , 1 , ce ) ; <nl> - } else { <nl> - # ifdef DEBUG_ENABLED <nl> - err_text = " Trying to assign value of type ' " + Variant : : get_type_name ( src - > get_type ( ) ) + <nl> - " ' to a variable of type ' " + Variant : : get_type_name ( var_type ) + " ' . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - } else { <nl> - # endif / / DEBUG_ENABLED <nl> - * dst = * src ; <nl> - } <nl> - <nl> - ip + = 4 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_ASSIGN_TYPED_NATIVE ) { <nl> - CHECK_SPACE ( 4 ) ; <nl> - GET_VARIANT_PTR ( dst , 2 ) ; <nl> - GET_VARIANT_PTR ( src , 3 ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - GET_VARIANT_PTR ( type , 1 ) ; <nl> - GDScriptNativeClass * nc = Object : : cast_to < GDScriptNativeClass > ( type - > operator Object * ( ) ) ; <nl> - GD_ERR_BREAK ( ! nc ) ; <nl> - if ( src - > get_type ( ) ! = Variant : : OBJECT & & src - > get_type ( ) ! = Variant : : NIL ) { <nl> - err_text = " Trying to assign value of type ' " + Variant : : get_type_name ( src - > get_type ( ) ) + <nl> - " ' to a variable of type ' " + nc - > get_name ( ) + " ' . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - Object * src_obj = src - > operator Object * ( ) ; <nl> - <nl> - if ( src_obj & & ! ClassDB : : is_parent_class ( src_obj - > get_class_name ( ) , nc - > get_name ( ) ) ) { <nl> - err_text = " Trying to assign value of type ' " + src_obj - > get_class_name ( ) + <nl> - " ' to a variable of type ' " + nc - > get_name ( ) + " ' . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif / / DEBUG_ENABLED <nl> - * dst = * src ; <nl> - <nl> - ip + = 4 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_ASSIGN_TYPED_SCRIPT ) { <nl> - CHECK_SPACE ( 4 ) ; <nl> - GET_VARIANT_PTR ( dst , 2 ) ; <nl> - GET_VARIANT_PTR ( src , 3 ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - GET_VARIANT_PTR ( type , 1 ) ; <nl> - Script * base_type = Object : : cast_to < Script > ( type - > operator Object * ( ) ) ; <nl> - <nl> - GD_ERR_BREAK ( ! base_type ) ; <nl> - <nl> - if ( src - > get_type ( ) ! = Variant : : OBJECT & & src - > get_type ( ) ! = Variant : : NIL ) { <nl> - err_text = " Trying to assign a non - object value to a variable of type ' " + base_type - > get_path ( ) . get_file ( ) + " ' . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - <nl> - if ( src - > get_type ( ) ! = Variant : : NIL & & src - > operator Object * ( ) ! = nullptr ) { <nl> - ScriptInstance * scr_inst = src - > operator Object * ( ) - > get_script_instance ( ) ; <nl> - if ( ! scr_inst ) { <nl> - err_text = " Trying to assign value of type ' " + src - > operator Object * ( ) - > get_class_name ( ) + <nl> - " ' to a variable of type ' " + base_type - > get_path ( ) . get_file ( ) + " ' . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - <nl> - Script * src_type = src - > operator Object * ( ) - > get_script_instance ( ) - > get_script ( ) . ptr ( ) ; <nl> - bool valid = false ; <nl> - <nl> - while ( src_type ) { <nl> - if ( src_type = = base_type ) { <nl> - valid = true ; <nl> - break ; <nl> - } <nl> - src_type = src_type - > get_base_script ( ) . ptr ( ) ; <nl> - } <nl> - <nl> - if ( ! valid ) { <nl> - err_text = " Trying to assign value of type ' " + src - > operator Object * ( ) - > get_script_instance ( ) - > get_script ( ) - > get_path ( ) . get_file ( ) + <nl> - " ' to a variable of type ' " + base_type - > get_path ( ) . get_file ( ) + " ' . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - } <nl> - # endif / / DEBUG_ENABLED <nl> - <nl> - * dst = * src ; <nl> - <nl> - ip + = 4 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_CAST_TO_BUILTIN ) { <nl> - CHECK_SPACE ( 4 ) ; <nl> - Variant : : Type to_type = ( Variant : : Type ) _code_ptr [ ip + 1 ] ; <nl> - GET_VARIANT_PTR ( src , 2 ) ; <nl> - GET_VARIANT_PTR ( dst , 3 ) ; <nl> - <nl> - GD_ERR_BREAK ( to_type < 0 | | to_type > = Variant : : VARIANT_MAX ) ; <nl> - <nl> - Callable : : CallError err ; <nl> - Variant : : construct ( to_type , * dst , ( const Variant * * ) & src , 1 , err ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - if ( err . error ! = Callable : : CallError : : CALL_OK ) { <nl> - err_text = " Invalid cast : could not convert value to ' " + Variant : : get_type_name ( to_type ) + " ' . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - <nl> - ip + = 4 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_CAST_TO_NATIVE ) { <nl> - CHECK_SPACE ( 4 ) ; <nl> - GET_VARIANT_PTR ( to_type , 1 ) ; <nl> - GET_VARIANT_PTR ( src , 2 ) ; <nl> - GET_VARIANT_PTR ( dst , 3 ) ; <nl> - <nl> - GDScriptNativeClass * nc = Object : : cast_to < GDScriptNativeClass > ( to_type - > operator Object * ( ) ) ; <nl> - GD_ERR_BREAK ( ! nc ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - if ( src - > get_type ( ) ! = Variant : : OBJECT & & src - > get_type ( ) ! = Variant : : NIL ) { <nl> - err_text = " Invalid cast : can ' t convert a non - object value to an object type . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - Object * src_obj = src - > operator Object * ( ) ; <nl> - <nl> - if ( src_obj & & ! ClassDB : : is_parent_class ( src_obj - > get_class_name ( ) , nc - > get_name ( ) ) ) { <nl> - * dst = Variant ( ) ; / / invalid cast , assign NULL <nl> - } else { <nl> - * dst = * src ; <nl> - } <nl> - <nl> - ip + = 4 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_CAST_TO_SCRIPT ) { <nl> - CHECK_SPACE ( 4 ) ; <nl> - GET_VARIANT_PTR ( to_type , 1 ) ; <nl> - GET_VARIANT_PTR ( src , 2 ) ; <nl> - GET_VARIANT_PTR ( dst , 3 ) ; <nl> - <nl> - Script * base_type = Object : : cast_to < Script > ( to_type - > operator Object * ( ) ) ; <nl> - <nl> - GD_ERR_BREAK ( ! base_type ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - if ( src - > get_type ( ) ! = Variant : : OBJECT & & src - > get_type ( ) ! = Variant : : NIL ) { <nl> - err_text = " Trying to assign a non - object value to a variable of type ' " + base_type - > get_path ( ) . get_file ( ) + " ' . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - <nl> - bool valid = false ; <nl> - <nl> - if ( src - > get_type ( ) ! = Variant : : NIL & & src - > operator Object * ( ) ! = nullptr ) { <nl> - ScriptInstance * scr_inst = src - > operator Object * ( ) - > get_script_instance ( ) ; <nl> - <nl> - if ( scr_inst ) { <nl> - Script * src_type = src - > operator Object * ( ) - > get_script_instance ( ) - > get_script ( ) . ptr ( ) ; <nl> - <nl> - while ( src_type ) { <nl> - if ( src_type = = base_type ) { <nl> - valid = true ; <nl> - break ; <nl> - } <nl> - src_type = src_type - > get_base_script ( ) . ptr ( ) ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - if ( valid ) { <nl> - * dst = * src ; / / Valid cast , copy the source object <nl> - } else { <nl> - * dst = Variant ( ) ; / / invalid cast , assign NULL <nl> - } <nl> - <nl> - ip + = 4 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_CONSTRUCT ) { <nl> - CHECK_SPACE ( 2 ) ; <nl> - Variant : : Type t = Variant : : Type ( _code_ptr [ ip + 1 ] ) ; <nl> - int argc = _code_ptr [ ip + 2 ] ; <nl> - CHECK_SPACE ( argc + 2 ) ; <nl> - Variant * * argptrs = call_args ; <nl> - for ( int i = 0 ; i < argc ; i + + ) { <nl> - GET_VARIANT_PTR ( v , 3 + i ) ; <nl> - argptrs [ i ] = v ; <nl> - } <nl> - <nl> - GET_VARIANT_PTR ( dst , 3 + argc ) ; <nl> - Callable : : CallError err ; <nl> - Variant : : construct ( t , * dst , ( const Variant * * ) argptrs , argc , err ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - if ( err . error ! = Callable : : CallError : : CALL_OK ) { <nl> - err_text = _get_call_error ( err , " ' " + Variant : : get_type_name ( t ) + " ' constructor " , ( const Variant * * ) argptrs ) ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - <nl> - ip + = 4 + argc ; <nl> - / / construct a basic type <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_CONSTRUCT_ARRAY ) { <nl> - CHECK_SPACE ( 1 ) ; <nl> - int argc = _code_ptr [ ip + 1 ] ; <nl> - Array array ; / / arrays are always shared <nl> - array . resize ( argc ) ; <nl> - CHECK_SPACE ( argc + 2 ) ; <nl> - <nl> - for ( int i = 0 ; i < argc ; i + + ) { <nl> - GET_VARIANT_PTR ( v , 2 + i ) ; <nl> - array [ i ] = * v ; <nl> - } <nl> - <nl> - GET_VARIANT_PTR ( dst , 2 + argc ) ; <nl> - <nl> - * dst = array ; <nl> - <nl> - ip + = 3 + argc ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_CONSTRUCT_DICTIONARY ) { <nl> - CHECK_SPACE ( 1 ) ; <nl> - int argc = _code_ptr [ ip + 1 ] ; <nl> - Dictionary dict ; / / arrays are always shared <nl> - <nl> - CHECK_SPACE ( argc * 2 + 2 ) ; <nl> - <nl> - for ( int i = 0 ; i < argc ; i + + ) { <nl> - GET_VARIANT_PTR ( k , 2 + i * 2 + 0 ) ; <nl> - GET_VARIANT_PTR ( v , 2 + i * 2 + 1 ) ; <nl> - dict [ * k ] = * v ; <nl> - } <nl> - <nl> - GET_VARIANT_PTR ( dst , 2 + argc * 2 ) ; <nl> - <nl> - * dst = dict ; <nl> - <nl> - ip + = 3 + argc * 2 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_CALL_ASYNC ) <nl> - OPCODE ( OPCODE_CALL_RETURN ) <nl> - OPCODE ( OPCODE_CALL ) { <nl> - CHECK_SPACE ( 4 ) ; <nl> - bool call_ret = _code_ptr [ ip ] ! = OPCODE_CALL ; <nl> - # ifdef DEBUG_ENABLED <nl> - bool call_async = _code_ptr [ ip ] = = OPCODE_CALL_ASYNC ; <nl> - # endif <nl> - <nl> - int argc = _code_ptr [ ip + 1 ] ; <nl> - GET_VARIANT_PTR ( base , 2 ) ; <nl> - int nameg = _code_ptr [ ip + 3 ] ; <nl> - <nl> - GD_ERR_BREAK ( nameg < 0 | | nameg > = _global_names_count ) ; <nl> - const StringName * methodname = & _global_names_ptr [ nameg ] ; <nl> - <nl> - GD_ERR_BREAK ( argc < 0 ) ; <nl> - ip + = 4 ; <nl> - CHECK_SPACE ( argc + 1 ) ; <nl> - Variant * * argptrs = call_args ; <nl> - <nl> - for ( int i = 0 ; i < argc ; i + + ) { <nl> - GET_VARIANT_PTR ( v , i ) ; <nl> - argptrs [ i ] = v ; <nl> - } <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - uint64_t call_time = 0 ; <nl> - <nl> - if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> - call_time = OS : : get_singleton ( ) - > get_ticks_usec ( ) ; <nl> - } <nl> - <nl> - # endif <nl> - Callable : : CallError err ; <nl> - if ( call_ret ) { <nl> - GET_VARIANT_PTR ( ret , argc ) ; <nl> - base - > call ( * methodname , ( const Variant * * ) argptrs , argc , * ret , err ) ; <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ! call_async & & ret - > get_type ( ) = = Variant : : OBJECT ) { <nl> - / / Check if getting a function state without await . <nl> - bool was_freed = false ; <nl> - Object * obj = ret - > get_validated_object_with_check ( was_freed ) ; <nl> - <nl> - if ( was_freed ) { <nl> - err_text = " Got a freed object as a result of the call . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - if ( obj & & obj - > is_class_ptr ( GDScriptFunctionState : : get_class_ptr_static ( ) ) ) { <nl> - err_text = R " ( Trying to call an async function without " await " . ) " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - } <nl> - # endif <nl> - } else { <nl> - Variant ret ; <nl> - base - > call ( * methodname , ( const Variant * * ) argptrs , argc , ret , err ) ; <nl> - } <nl> - # ifdef DEBUG_ENABLED <nl> - if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> - function_call_time + = OS : : get_singleton ( ) - > get_ticks_usec ( ) - call_time ; <nl> - } <nl> - <nl> - if ( err . error ! = Callable : : CallError : : CALL_OK ) { <nl> - String methodstr = * methodname ; <nl> - String basestr = _get_var_type ( base ) ; <nl> - <nl> - if ( methodstr = = " call " ) { <nl> - if ( argc > = 1 ) { <nl> - methodstr = String ( * argptrs [ 0 ] ) + " ( via call ) " ; <nl> - if ( err . error = = Callable : : CallError : : CALL_ERROR_INVALID_ARGUMENT ) { <nl> - err . argument + = 1 ; <nl> - } <nl> - } <nl> - } else if ( methodstr = = " free " ) { <nl> - if ( err . error = = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ) { <nl> - if ( base - > is_ref ( ) ) { <nl> - err_text = " Attempted to free a reference . " ; <nl> - OPCODE_BREAK ; <nl> - } else if ( base - > get_type ( ) = = Variant : : OBJECT ) { <nl> - err_text = " Attempted to free a locked object ( calling or emitting ) . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - } <nl> - } else if ( methodstr = = " call_recursive " & & basestr = = " TreeItem " ) { <nl> - if ( argc > = 1 ) { <nl> - methodstr = String ( * argptrs [ 0 ] ) + " ( via TreeItem . call_recursive ) " ; <nl> - if ( err . error = = Callable : : CallError : : CALL_ERROR_INVALID_ARGUMENT ) { <nl> - err . argument + = 1 ; <nl> - } <nl> - } <nl> - } <nl> - err_text = _get_call_error ( err , " function ' " + methodstr + " ' in base ' " + basestr + " ' " , ( const Variant * * ) argptrs ) ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - <nl> - / / _call_func ( nullptr , base , * methodname , ip , argc , p_instance , stack ) ; <nl> - ip + = argc + 1 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_CALL_BUILT_IN ) { <nl> - CHECK_SPACE ( 4 ) ; <nl> - <nl> - GDScriptFunctions : : Function func = GDScriptFunctions : : Function ( _code_ptr [ ip + 1 ] ) ; <nl> - int argc = _code_ptr [ ip + 2 ] ; <nl> - GD_ERR_BREAK ( argc < 0 ) ; <nl> - <nl> - ip + = 3 ; <nl> - CHECK_SPACE ( argc + 1 ) ; <nl> - Variant * * argptrs = call_args ; <nl> - <nl> - for ( int i = 0 ; i < argc ; i + + ) { <nl> - GET_VARIANT_PTR ( v , i ) ; <nl> - argptrs [ i ] = v ; <nl> - } <nl> - <nl> - GET_VARIANT_PTR ( dst , argc ) ; <nl> - <nl> - Callable : : CallError err ; <nl> - <nl> - GDScriptFunctions : : call ( func , ( const Variant * * ) argptrs , argc , * dst , err ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - if ( err . error ! = Callable : : CallError : : CALL_OK ) { <nl> - String methodstr = GDScriptFunctions : : get_func_name ( func ) ; <nl> - if ( dst - > get_type ( ) = = Variant : : STRING ) { <nl> - / / call provided error string <nl> - err_text = " Error calling built - in function ' " + methodstr + " ' : " + String ( * dst ) ; <nl> - } else { <nl> - err_text = _get_call_error ( err , " built - in function ' " + methodstr + " ' " , ( const Variant * * ) argptrs ) ; <nl> - } <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - ip + = argc + 1 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_CALL_SELF_BASE ) { <nl> - CHECK_SPACE ( 2 ) ; <nl> - int self_fun = _code_ptr [ ip + 1 ] ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - if ( self_fun < 0 | | self_fun > = _global_names_count ) { <nl> - err_text = " compiler bug , function name not found " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - const StringName * methodname = & _global_names_ptr [ self_fun ] ; <nl> - <nl> - int argc = _code_ptr [ ip + 2 ] ; <nl> - <nl> - CHECK_SPACE ( 2 + argc + 1 ) ; <nl> - <nl> - Variant * * argptrs = call_args ; <nl> - <nl> - for ( int i = 0 ; i < argc ; i + + ) { <nl> - GET_VARIANT_PTR ( v , i + 3 ) ; <nl> - argptrs [ i ] = v ; <nl> - } <nl> - <nl> - GET_VARIANT_PTR ( dst , argc + 3 ) ; <nl> - <nl> - const GDScript * gds = _script ; <nl> - <nl> - const Map < StringName , GDScriptFunction * > : : Element * E = nullptr ; <nl> - while ( gds - > base . ptr ( ) ) { <nl> - gds = gds - > base . ptr ( ) ; <nl> - E = gds - > member_functions . find ( * methodname ) ; <nl> - if ( E ) { <nl> - break ; <nl> - } <nl> - } <nl> - <nl> - Callable : : CallError err ; <nl> - <nl> - if ( E ) { <nl> - * dst = E - > get ( ) - > call ( p_instance , ( const Variant * * ) argptrs , argc , err ) ; <nl> - } else if ( gds - > native . ptr ( ) ) { <nl> - if ( * methodname ! = GDScriptLanguage : : get_singleton ( ) - > strings . _init ) { <nl> - MethodBind * mb = ClassDB : : get_method ( gds - > native - > get_name ( ) , * methodname ) ; <nl> - if ( ! mb ) { <nl> - err . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ; <nl> - } else { <nl> - * dst = mb - > call ( p_instance - > owner , ( const Variant * * ) argptrs , argc , err ) ; <nl> - } <nl> - } else { <nl> - err . error = Callable : : CallError : : CALL_OK ; <nl> - } <nl> - } else { <nl> - if ( * methodname ! = GDScriptLanguage : : get_singleton ( ) - > strings . _init ) { <nl> - err . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ; <nl> - } else { <nl> - err . error = Callable : : CallError : : CALL_OK ; <nl> - } <nl> - } <nl> - <nl> - if ( err . error ! = Callable : : CallError : : CALL_OK ) { <nl> - String methodstr = * methodname ; <nl> - err_text = _get_call_error ( err , " function ' " + methodstr + " ' " , ( const Variant * * ) argptrs ) ; <nl> - <nl> - OPCODE_BREAK ; <nl> - } <nl> - <nl> - ip + = 4 + argc ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_AWAIT ) { <nl> - CHECK_SPACE ( 2 ) ; <nl> - <nl> - / / do the oneshot connect <nl> - GET_VARIANT_PTR ( argobj , 1 ) ; <nl> - <nl> - Signal sig ; <nl> - bool is_signal = true ; <nl> - <nl> - { <nl> - Variant result = * argobj ; <nl> - <nl> - if ( argobj - > get_type ( ) = = Variant : : OBJECT ) { <nl> - bool was_freed = false ; <nl> - Object * obj = argobj - > get_validated_object_with_check ( was_freed ) ; <nl> - <nl> - if ( was_freed ) { <nl> - err_text = " Trying to await on a freed object . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - <nl> - / / Is this even possible to be null at this point ? <nl> - if ( obj ) { <nl> - if ( obj - > is_class_ptr ( GDScriptFunctionState : : get_class_ptr_static ( ) ) ) { <nl> - static StringName completed = _scs_create ( " completed " ) ; <nl> - result = Signal ( obj , completed ) ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - if ( result . get_type ( ) ! = Variant : : SIGNAL ) { <nl> - ip + = 4 ; / / Skip OPCODE_AWAIT_RESUME and its data . <nl> - / / The stack pointer should be the same , so we don ' t need to set a return value . <nl> - is_signal = false ; <nl> - } else { <nl> - sig = result ; <nl> - } <nl> - } <nl> - <nl> - if ( is_signal ) { <nl> - Ref < GDScriptFunctionState > gdfs = memnew ( GDScriptFunctionState ) ; <nl> - gdfs - > function = this ; <nl> - <nl> - gdfs - > state . stack . resize ( alloca_size ) ; <nl> - / / copy variant stack <nl> - for ( int i = 0 ; i < _stack_size ; i + + ) { <nl> - memnew_placement ( & gdfs - > state . stack . write [ sizeof ( Variant ) * i ] , Variant ( stack [ i ] ) ) ; <nl> - } <nl> - gdfs - > state . stack_size = _stack_size ; <nl> - gdfs - > state . self = self ; <nl> - gdfs - > state . alloca_size = alloca_size ; <nl> - gdfs - > state . ip = ip + 2 ; <nl> - gdfs - > state . line = line ; <nl> - gdfs - > state . script = _script ; <nl> - { <nl> - MutexLock lock ( GDScriptLanguage : : get_singleton ( ) - > lock ) ; <nl> - _script - > pending_func_states . add ( & gdfs - > scripts_list ) ; <nl> - if ( p_instance ) { <nl> - gdfs - > state . instance = p_instance ; <nl> - p_instance - > pending_func_states . add ( & gdfs - > instances_list ) ; <nl> - } else { <nl> - gdfs - > state . instance = nullptr ; <nl> - } <nl> - } <nl> - # ifdef DEBUG_ENABLED <nl> - gdfs - > state . function_name = name ; <nl> - gdfs - > state . script_path = _script - > get_path ( ) ; <nl> - # endif <nl> - gdfs - > state . defarg = defarg ; <nl> - gdfs - > function = this ; <nl> - <nl> - retvalue = gdfs ; <nl> - <nl> - Error err = sig . connect ( Callable ( gdfs . ptr ( ) , " _signal_callback " ) , varray ( gdfs ) , Object : : CONNECT_ONESHOT ) ; <nl> - if ( err ! = OK ) { <nl> - err_text = " Error connecting to signal : " + sig . get_name ( ) + " during await . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - exit_ok = true ; <nl> - awaited = true ; <nl> - # endif <nl> - OPCODE_BREAK ; <nl> - } <nl> - } <nl> - DISPATCH_OPCODE ; / / Needed for synchronous calls ( when result is immediately available ) . <nl> - <nl> - OPCODE ( OPCODE_AWAIT_RESUME ) { <nl> - CHECK_SPACE ( 2 ) ; <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ! p_state ) { <nl> - err_text = ( " Invalid Resume ( bug ? ) " ) ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - GET_VARIANT_PTR ( result , 1 ) ; <nl> - * result = p_state - > result ; <nl> - ip + = 2 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_JUMP ) { <nl> - CHECK_SPACE ( 2 ) ; <nl> - int to = _code_ptr [ ip + 1 ] ; <nl> - <nl> - GD_ERR_BREAK ( to < 0 | | to > _code_size ) ; <nl> - ip = to ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_JUMP_IF ) { <nl> - CHECK_SPACE ( 3 ) ; <nl> - <nl> - GET_VARIANT_PTR ( test , 1 ) ; <nl> - <nl> - bool result = test - > booleanize ( ) ; <nl> - <nl> - if ( result ) { <nl> - int to = _code_ptr [ ip + 2 ] ; <nl> - GD_ERR_BREAK ( to < 0 | | to > _code_size ) ; <nl> - ip = to ; <nl> - } else { <nl> - ip + = 3 ; <nl> - } <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_JUMP_IF_NOT ) { <nl> - CHECK_SPACE ( 3 ) ; <nl> - <nl> - GET_VARIANT_PTR ( test , 1 ) ; <nl> - <nl> - bool result = test - > booleanize ( ) ; <nl> - <nl> - if ( ! result ) { <nl> - int to = _code_ptr [ ip + 2 ] ; <nl> - GD_ERR_BREAK ( to < 0 | | to > _code_size ) ; <nl> - ip = to ; <nl> - } else { <nl> - ip + = 3 ; <nl> - } <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_JUMP_TO_DEF_ARGUMENT ) { <nl> - CHECK_SPACE ( 2 ) ; <nl> - ip = _default_arg_ptr [ defarg ] ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_RETURN ) { <nl> - CHECK_SPACE ( 2 ) ; <nl> - GET_VARIANT_PTR ( r , 1 ) ; <nl> - retvalue = * r ; <nl> - # ifdef DEBUG_ENABLED <nl> - exit_ok = true ; <nl> - # endif <nl> - OPCODE_BREAK ; <nl> - } <nl> - <nl> - OPCODE ( OPCODE_ITERATE_BEGIN ) { <nl> - CHECK_SPACE ( 8 ) ; / / space for this a regular iterate <nl> - <nl> - GET_VARIANT_PTR ( counter , 1 ) ; <nl> - GET_VARIANT_PTR ( container , 2 ) ; <nl> - <nl> - bool valid ; <nl> - if ( ! container - > iter_init ( * counter , valid ) ) { <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ! valid ) { <nl> - err_text = " Unable to iterate on object of type ' " + Variant : : get_type_name ( container - > get_type ( ) ) + " ' . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - int jumpto = _code_ptr [ ip + 3 ] ; <nl> - GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> - ip = jumpto ; <nl> - } else { <nl> - GET_VARIANT_PTR ( iterator , 4 ) ; <nl> - <nl> - * iterator = container - > iter_get ( * counter , valid ) ; <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ! valid ) { <nl> - err_text = " Unable to obtain iterator object of type ' " + Variant : : get_type_name ( container - > get_type ( ) ) + " ' . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - ip + = 5 ; / / skip regular iterate which is always next <nl> - } <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_ITERATE ) { <nl> - CHECK_SPACE ( 4 ) ; <nl> - <nl> - GET_VARIANT_PTR ( counter , 1 ) ; <nl> - GET_VARIANT_PTR ( container , 2 ) ; <nl> - <nl> - bool valid ; <nl> - if ( ! container - > iter_next ( * counter , valid ) ) { <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ! valid ) { <nl> - err_text = " Unable to iterate on object of type ' " + Variant : : get_type_name ( container - > get_type ( ) ) + " ' ( type changed since first iteration ? ) . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - int jumpto = _code_ptr [ ip + 3 ] ; <nl> - GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> - ip = jumpto ; <nl> - } else { <nl> - GET_VARIANT_PTR ( iterator , 4 ) ; <nl> - <nl> - * iterator = container - > iter_get ( * counter , valid ) ; <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ! valid ) { <nl> - err_text = " Unable to obtain iterator object of type ' " + Variant : : get_type_name ( container - > get_type ( ) ) + " ' ( but was obtained on first iteration ? ) . " ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - ip + = 5 ; / / loop again <nl> - } <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_ASSERT ) { <nl> - CHECK_SPACE ( 3 ) ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - GET_VARIANT_PTR ( test , 1 ) ; <nl> - bool result = test - > booleanize ( ) ; <nl> - <nl> - if ( ! result ) { <nl> - String message_str ; <nl> - if ( _code_ptr [ ip + 2 ] ! = 0 ) { <nl> - GET_VARIANT_PTR ( message , 2 ) ; <nl> - message_str = * message ; <nl> - } <nl> - if ( message_str . empty ( ) ) { <nl> - err_text = " Assertion failed . " ; <nl> - } else { <nl> - err_text = " Assertion failed : " + message_str ; <nl> - } <nl> - OPCODE_BREAK ; <nl> - } <nl> - <nl> - # endif <nl> - ip + = 3 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_BREAKPOINT ) { <nl> - # ifdef DEBUG_ENABLED <nl> - if ( EngineDebugger : : is_active ( ) ) { <nl> - GDScriptLanguage : : get_singleton ( ) - > debug_break ( " Breakpoint Statement " , true ) ; <nl> - } <nl> - # endif <nl> - ip + = 1 ; <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_LINE ) { <nl> - CHECK_SPACE ( 2 ) ; <nl> - <nl> - line = _code_ptr [ ip + 1 ] ; <nl> - ip + = 2 ; <nl> - <nl> - if ( EngineDebugger : : is_active ( ) ) { <nl> - / / line <nl> - bool do_break = false ; <nl> - <nl> - if ( EngineDebugger : : get_script_debugger ( ) - > get_lines_left ( ) > 0 ) { <nl> - if ( EngineDebugger : : get_script_debugger ( ) - > get_depth ( ) < = 0 ) { <nl> - EngineDebugger : : get_script_debugger ( ) - > set_lines_left ( EngineDebugger : : get_script_debugger ( ) - > get_lines_left ( ) - 1 ) ; <nl> - } <nl> - if ( EngineDebugger : : get_script_debugger ( ) - > get_lines_left ( ) < = 0 ) { <nl> - do_break = true ; <nl> - } <nl> - } <nl> - <nl> - if ( EngineDebugger : : get_script_debugger ( ) - > is_breakpoint ( line , source ) ) { <nl> - do_break = true ; <nl> - } <nl> - <nl> - if ( do_break ) { <nl> - GDScriptLanguage : : get_singleton ( ) - > debug_break ( " Breakpoint " , true ) ; <nl> - } <nl> - <nl> - EngineDebugger : : get_singleton ( ) - > line_poll ( ) ; <nl> - } <nl> - } <nl> - DISPATCH_OPCODE ; <nl> - <nl> - OPCODE ( OPCODE_END ) { <nl> - # ifdef DEBUG_ENABLED <nl> - exit_ok = true ; <nl> - # endif <nl> - OPCODE_BREAK ; <nl> - } <nl> - <nl> - # if 0 / / Enable for debugging . <nl> - default : { <nl> - err_text = " Illegal opcode " + itos ( _code_ptr [ ip ] ) + " at address " + itos ( ip ) ; <nl> - OPCODE_BREAK ; <nl> - } <nl> - # endif <nl> - } <nl> - <nl> - OPCODES_END <nl> - # ifdef DEBUG_ENABLED <nl> - if ( exit_ok ) { <nl> - OPCODE_OUT ; <nl> - } <nl> - / / error <nl> - / / function , file , line , error , explanation <nl> - String err_file ; <nl> - if ( p_instance & & ObjectDB : : get_instance ( p_instance - > owner_id ) ! = nullptr & & p_instance - > script - > is_valid ( ) & & p_instance - > script - > path ! = " " ) { <nl> - err_file = p_instance - > script - > path ; <nl> - } else if ( script ) { <nl> - err_file = script - > path ; <nl> - } <nl> - if ( err_file = = " " ) { <nl> - err_file = " < built - in > " ; <nl> - } <nl> - String err_func = name ; <nl> - if ( p_instance & & ObjectDB : : get_instance ( p_instance - > owner_id ) ! = nullptr & & p_instance - > script - > is_valid ( ) & & p_instance - > script - > name ! = " " ) { <nl> - err_func = p_instance - > script - > name + " . " + err_func ; <nl> - } <nl> - int err_line = line ; <nl> - if ( err_text = = " " ) { <nl> - err_text = " Internal Script Error ! - opcode # " + itos ( last_opcode ) + " ( report please ) . " ; <nl> - } <nl> - <nl> - if ( ! GDScriptLanguage : : get_singleton ( ) - > debug_break ( err_text , false ) ) { <nl> - / / debugger break did not happen <nl> - <nl> - _err_print_error ( err_func . utf8 ( ) . get_data ( ) , err_file . utf8 ( ) . get_data ( ) , err_line , err_text . utf8 ( ) . get_data ( ) , ERR_HANDLER_SCRIPT ) ; <nl> - } <nl> - <nl> - # endif <nl> - OPCODE_OUT ; <nl> - } <nl> - <nl> - OPCODES_OUT <nl> - # ifdef DEBUG_ENABLED <nl> - if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> - uint64_t time_taken = OS : : get_singleton ( ) - > get_ticks_usec ( ) - function_start_time ; <nl> - profile . total_time + = time_taken ; <nl> - profile . self_time + = time_taken - function_call_time ; <nl> - profile . frame_total_time + = time_taken ; <nl> - profile . frame_self_time + = time_taken - function_call_time ; <nl> - GDScriptLanguage : : get_singleton ( ) - > script_frame_time + = time_taken - function_call_time ; <nl> - } <nl> - <nl> - / / Check if this is the last time the function is resuming from await <nl> - / / Will be true if never awaited as well <nl> - / / When it ' s the last resume it will postpone the exit from stack , <nl> - / / so the debugger knows which function triggered the resume of the next function ( if any ) <nl> - if ( ! p_state | | awaited ) { <nl> - if ( EngineDebugger : : is_active ( ) ) { <nl> - GDScriptLanguage : : get_singleton ( ) - > exit_function ( ) ; <nl> - } <nl> - # endif <nl> - <nl> - if ( _stack_size ) { <nl> - / / free stack <nl> - for ( int i = 0 ; i < _stack_size ; i + + ) { <nl> - stack [ i ] . ~ Variant ( ) ; <nl> - } <nl> - } <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - } <nl> - # endif <nl> - <nl> - return retvalue ; <nl> - } <nl> <nl> const int * GDScriptFunction : : get_code ( ) const { <nl> return _code_ptr ; <nl> void GDScriptFunction : : debug_get_stack_member_state ( int p_line , List < Pair < String <nl> } <nl> } <nl> <nl> - GDScriptFunction : : GDScriptFunction ( ) : <nl> - function_list ( this ) { <nl> - _stack_size = 0 ; <nl> - _call_size = 0 ; <nl> - rpc_mode = MultiplayerAPI : : RPC_MODE_DISABLED ; <nl> + GDScriptFunction : : GDScriptFunction ( ) { <nl> name = " < anonymous > " ; <nl> # ifdef DEBUG_ENABLED <nl> - _func_cname = nullptr ; <nl> - <nl> { <nl> MutexLock lock ( GDScriptLanguage : : get_singleton ( ) - > lock ) ; <nl> - <nl> GDScriptLanguage : : get_singleton ( ) - > function_list . add ( & function_list ) ; <nl> } <nl> - <nl> - profile . call_count = 0 ; <nl> - profile . self_time = 0 ; <nl> - profile . total_time = 0 ; <nl> - profile . frame_call_count = 0 ; <nl> - profile . frame_self_time = 0 ; <nl> - profile . frame_total_time = 0 ; <nl> - profile . last_frame_call_count = 0 ; <nl> - profile . last_frame_self_time = 0 ; <nl> - profile . last_frame_total_time = 0 ; <nl> - <nl> # endif <nl> } <nl> <nl> GDScriptFunctionState : : ~ GDScriptFunctionState ( ) { <nl> instances_list . remove_from_list ( ) ; <nl> } <nl> } <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - static String _get_variant_string ( const Variant & p_variant ) { <nl> - String txt ; <nl> - if ( p_variant . get_type ( ) = = Variant : : STRING ) { <nl> - txt = " \ " " + String ( p_variant ) + " \ " " ; <nl> - } else if ( p_variant . get_type ( ) = = Variant : : STRING_NAME ) { <nl> - txt = " & \ " " + String ( p_variant ) + " \ " " ; <nl> - } else if ( p_variant . get_type ( ) = = Variant : : NODE_PATH ) { <nl> - txt = " ^ \ " " + String ( p_variant ) + " \ " " ; <nl> - } else if ( p_variant . get_type ( ) = = Variant : : OBJECT ) { <nl> - Object * obj = p_variant ; <nl> - if ( ! obj ) { <nl> - txt = " null " ; <nl> - } else { <nl> - GDScriptNativeClass * cls = Object : : cast_to < GDScriptNativeClass > ( obj ) ; <nl> - if ( cls ) { <nl> - txt + = cls - > get_name ( ) ; <nl> - txt + = " ( class ) " ; <nl> - } else { <nl> - txt = obj - > get_class ( ) ; <nl> - if ( obj - > get_script_instance ( ) ) { <nl> - txt + = " ( " + obj - > get_script_instance ( ) - > get_script ( ) - > get_path ( ) + " ) " ; <nl> - } <nl> - } <nl> - } <nl> - } else { <nl> - txt = p_variant ; <nl> - } <nl> - return txt ; <nl> - } <nl> - <nl> - static String _disassemble_address ( const GDScript * p_script , const GDScriptFunction & p_function , int p_address ) { <nl> - int addr = p_address & GDScriptFunction : : ADDR_MASK ; <nl> - <nl> - switch ( p_address > > GDScriptFunction : : ADDR_BITS ) { <nl> - case GDScriptFunction : : ADDR_TYPE_SELF : { <nl> - return " self " ; <nl> - } break ; <nl> - case GDScriptFunction : : ADDR_TYPE_CLASS : { <nl> - return " class " ; <nl> - } break ; <nl> - case GDScriptFunction : : ADDR_TYPE_MEMBER : { <nl> - return " member ( " + p_script - > debug_get_member_by_index ( addr ) + " ) " ; <nl> - } break ; <nl> - case GDScriptFunction : : ADDR_TYPE_CLASS_CONSTANT : { <nl> - return " class_const ( " + p_function . get_global_name ( addr ) + " ) " ; <nl> - } break ; <nl> - case GDScriptFunction : : ADDR_TYPE_LOCAL_CONSTANT : { <nl> - return " const ( " + _get_variant_string ( p_function . get_constant ( addr ) ) + " ) " ; <nl> - } break ; <nl> - case GDScriptFunction : : ADDR_TYPE_STACK : { <nl> - return " stack ( " + itos ( addr ) + " ) " ; <nl> - } break ; <nl> - case GDScriptFunction : : ADDR_TYPE_STACK_VARIABLE : { <nl> - return " var_stack ( " + itos ( addr ) + " ) " ; <nl> - } break ; <nl> - case GDScriptFunction : : ADDR_TYPE_GLOBAL : { <nl> - return " global ( " + _get_variant_string ( GDScriptLanguage : : get_singleton ( ) - > get_global_array ( ) [ addr ] ) + " ) " ; <nl> - } break ; <nl> - case GDScriptFunction : : ADDR_TYPE_NAMED_GLOBAL : { <nl> - return " named_global ( " + p_function . get_global_name ( addr ) + " ) " ; <nl> - } break ; <nl> - case GDScriptFunction : : ADDR_TYPE_NIL : { <nl> - return " nil " ; <nl> - } break ; <nl> - } <nl> - <nl> - return " < err > " ; <nl> - } <nl> - <nl> - void GDScriptFunction : : disassemble ( const Vector < String > & p_code_lines ) const { <nl> - # define DADDR ( m_ip ) ( _disassemble_address ( _script , * this , _code_ptr [ ip + m_ip ] ) ) <nl> - <nl> - for ( int ip = 0 ; ip < _code_size ; ) { <nl> - StringBuilder text ; <nl> - int incr = 0 ; <nl> - <nl> - text + = " " ; <nl> - text + = itos ( ip ) ; <nl> - text + = " : " ; <nl> - <nl> - / / This makes the compiler complain if some opcode is unchecked in the switch . <nl> - Opcode code = Opcode ( _code_ptr [ ip ] ) ; <nl> - <nl> - switch ( code ) { <nl> - case OPCODE_OPERATOR : { <nl> - int operation = _code_ptr [ ip + 1 ] ; <nl> - <nl> - text + = " operator " ; <nl> - <nl> - text + = DADDR ( 4 ) ; <nl> - text + = " = " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " " ; <nl> - text + = Variant : : get_operator_name ( Variant : : Operator ( operation ) ) ; <nl> - text + = " " ; <nl> - text + = DADDR ( 3 ) ; <nl> - <nl> - incr + = 5 ; <nl> - } break ; <nl> - case OPCODE_EXTENDS_TEST : { <nl> - text + = " is object " ; <nl> - text + = DADDR ( 3 ) ; <nl> - text + = " = " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " is " ; <nl> - text + = DADDR ( 2 ) ; <nl> - <nl> - incr + = 4 ; <nl> - } break ; <nl> - case OPCODE_IS_BUILTIN : { <nl> - text + = " is builtin " ; <nl> - text + = DADDR ( 3 ) ; <nl> - text + = " = " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " is " ; <nl> - text + = Variant : : get_type_name ( Variant : : Type ( _code_ptr [ ip + 2 ] ) ) ; <nl> - <nl> - incr + = 4 ; <nl> - } break ; <nl> - case OPCODE_SET : { <nl> - text + = " set " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " [ " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " ] = " ; <nl> - text + = DADDR ( 3 ) ; <nl> - <nl> - incr + = 4 ; <nl> - } break ; <nl> - case OPCODE_GET : { <nl> - text + = " get " ; <nl> - text + = DADDR ( 3 ) ; <nl> - text + = " = " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " [ " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " ] " ; <nl> - <nl> - incr + = 4 ; <nl> - } break ; <nl> - case OPCODE_SET_NAMED : { <nl> - text + = " set_named " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " [ \ " " ; <nl> - text + = _global_names_ptr [ _code_ptr [ ip + 2 ] ] ; <nl> - text + = " \ " ] = " ; <nl> - text + = DADDR ( 3 ) ; <nl> - <nl> - incr + = 4 ; <nl> - } break ; <nl> - case OPCODE_GET_NAMED : { <nl> - text + = " get_named " ; <nl> - text + = DADDR ( 3 ) ; <nl> - text + = " = " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " [ \ " " ; <nl> - text + = _global_names_ptr [ _code_ptr [ ip + 2 ] ] ; <nl> - text + = " \ " ] " ; <nl> - <nl> - incr + = 4 ; <nl> - } break ; <nl> - case OPCODE_SET_MEMBER : { <nl> - text + = " set_member " ; <nl> - text + = " [ \ " " ; <nl> - text + = _global_names_ptr [ _code_ptr [ ip + 1 ] ] ; <nl> - text + = " \ " ] = " ; <nl> - text + = DADDR ( 2 ) ; <nl> - <nl> - incr + = 3 ; <nl> - } break ; <nl> - case OPCODE_GET_MEMBER : { <nl> - text + = " get_member " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " = " ; <nl> - text + = " [ \ " " ; <nl> - text + = _global_names_ptr [ _code_ptr [ ip + 1 ] ] ; <nl> - text + = " \ " ] " ; <nl> - <nl> - incr + = 3 ; <nl> - } break ; <nl> - case OPCODE_ASSIGN : { <nl> - text + = " assign " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " = " ; <nl> - text + = DADDR ( 2 ) ; <nl> - <nl> - incr + = 3 ; <nl> - } break ; <nl> - case OPCODE_ASSIGN_TRUE : { <nl> - text + = " assign " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " = true " ; <nl> - <nl> - incr + = 2 ; <nl> - } break ; <nl> - case OPCODE_ASSIGN_FALSE : { <nl> - text + = " assign " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " = false " ; <nl> - <nl> - incr + = 2 ; <nl> - } break ; <nl> - case OPCODE_ASSIGN_TYPED_BUILTIN : { <nl> - text + = " assign typed builtin ( " ; <nl> - text + = Variant : : get_type_name ( ( Variant : : Type ) _code_ptr [ ip + 1 ] ) ; <nl> - text + = " ) " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " = " ; <nl> - text + = DADDR ( 3 ) ; <nl> - <nl> - incr + = 4 ; <nl> - } break ; <nl> - case OPCODE_ASSIGN_TYPED_NATIVE : { <nl> - Variant class_name = _constants_ptr [ _code_ptr [ ip + 1 ] ] ; <nl> - GDScriptNativeClass * nc = Object : : cast_to < GDScriptNativeClass > ( class_name . operator Object * ( ) ) ; <nl> - <nl> - text + = " assign typed native ( " ; <nl> - text + = nc - > get_name ( ) . operator String ( ) ; <nl> - text + = " ) " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " = " ; <nl> - text + = DADDR ( 3 ) ; <nl> - <nl> - incr + = 4 ; <nl> - } break ; <nl> - case OPCODE_ASSIGN_TYPED_SCRIPT : { <nl> - Variant script = _constants_ptr [ _code_ptr [ ip + 1 ] ] ; <nl> - Script * sc = Object : : cast_to < Script > ( script . operator Object * ( ) ) ; <nl> - <nl> - text + = " assign typed script ( " ; <nl> - text + = sc - > get_path ( ) ; <nl> - text + = " ) " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " = " ; <nl> - text + = DADDR ( 3 ) ; <nl> - <nl> - incr + = 4 ; <nl> - } break ; <nl> - case OPCODE_CAST_TO_BUILTIN : { <nl> - text + = " cast builtin " ; <nl> - text + = DADDR ( 3 ) ; <nl> - text + = " = " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " as " ; <nl> - text + = Variant : : get_type_name ( Variant : : Type ( _code_ptr [ ip + 1 ] ) ) ; <nl> - <nl> - incr + = 4 ; <nl> - } break ; <nl> - case OPCODE_CAST_TO_NATIVE : { <nl> - Variant class_name = _constants_ptr [ _code_ptr [ ip + 1 ] ] ; <nl> - GDScriptNativeClass * nc = Object : : cast_to < GDScriptNativeClass > ( class_name . operator Object * ( ) ) ; <nl> - <nl> - text + = " cast native " ; <nl> - text + = DADDR ( 3 ) ; <nl> - text + = " = " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " as " ; <nl> - text + = nc - > get_name ( ) ; <nl> - <nl> - incr + = 4 ; <nl> - } break ; <nl> - case OPCODE_CAST_TO_SCRIPT : { <nl> - text + = " cast " ; <nl> - text + = DADDR ( 3 ) ; <nl> - text + = " = " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " as " ; <nl> - text + = DADDR ( 1 ) ; <nl> - <nl> - incr + = 4 ; <nl> - } break ; <nl> - case OPCODE_CONSTRUCT : { <nl> - Variant : : Type t = Variant : : Type ( _code_ptr [ ip + 1 ] ) ; <nl> - int argc = _code_ptr [ ip + 2 ] ; <nl> - <nl> - text + = " construct " ; <nl> - text + = DADDR ( 3 + argc ) ; <nl> - text + = " = " ; <nl> - <nl> - text + = Variant : : get_type_name ( t ) + " ( " ; <nl> - for ( int i = 0 ; i < argc ; i + + ) { <nl> - if ( i > 0 ) <nl> - text + = " , " ; <nl> - text + = DADDR ( i + 3 ) ; <nl> - } <nl> - text + = " ) " ; <nl> - <nl> - incr = 4 + argc ; <nl> - } break ; <nl> - case OPCODE_CONSTRUCT_ARRAY : { <nl> - int argc = _code_ptr [ ip + 1 ] ; <nl> - text + = " make_array " ; <nl> - text + = DADDR ( 2 + argc ) ; <nl> - text + = " = [ " ; <nl> - <nl> - for ( int i = 0 ; i < argc ; i + + ) { <nl> - if ( i > 0 ) <nl> - text + = " , " ; <nl> - text + = DADDR ( 2 + i ) ; <nl> - } <nl> - <nl> - text + = " ] " ; <nl> - <nl> - incr + = 3 + argc ; <nl> - } break ; <nl> - case OPCODE_CONSTRUCT_DICTIONARY : { <nl> - int argc = _code_ptr [ ip + 1 ] ; <nl> - text + = " make_dict " ; <nl> - text + = DADDR ( 2 + argc * 2 ) ; <nl> - text + = " = { " ; <nl> - <nl> - for ( int i = 0 ; i < argc ; i + + ) { <nl> - if ( i > 0 ) <nl> - text + = " , " ; <nl> - text + = DADDR ( 2 + i * 2 + 0 ) ; <nl> - text + = " : " ; <nl> - text + = DADDR ( 2 + i * 2 + 1 ) ; <nl> - } <nl> - <nl> - text + = " } " ; <nl> - <nl> - incr + = 3 + argc * 2 ; <nl> - } break ; <nl> - case OPCODE_CALL : <nl> - case OPCODE_CALL_RETURN : <nl> - case OPCODE_CALL_ASYNC : { <nl> - bool ret = _code_ptr [ ip ] = = OPCODE_CALL_RETURN ; <nl> - bool async = _code_ptr [ ip ] = = OPCODE_CALL_ASYNC ; <nl> - <nl> - if ( ret ) { <nl> - text + = " call - ret " ; <nl> - } else if ( async ) { <nl> - text + = " call - async " ; <nl> - } else { <nl> - text + = " call " ; <nl> - } <nl> - <nl> - int argc = _code_ptr [ ip + 1 ] ; <nl> - if ( ret | | async ) { <nl> - text + = DADDR ( 4 + argc ) + " = " ; <nl> - } <nl> - <nl> - text + = DADDR ( 2 ) + " . " ; <nl> - text + = String ( _global_names_ptr [ _code_ptr [ ip + 3 ] ] ) ; <nl> - text + = " ( " ; <nl> - <nl> - for ( int i = 0 ; i < argc ; i + + ) { <nl> - if ( i > 0 ) <nl> - text + = " , " ; <nl> - text + = DADDR ( 4 + i ) ; <nl> - } <nl> - text + = " ) " ; <nl> - <nl> - incr = 5 + argc ; <nl> - } break ; <nl> - case OPCODE_CALL_BUILT_IN : { <nl> - text + = " call - built - in " ; <nl> - <nl> - int argc = _code_ptr [ ip + 2 ] ; <nl> - text + = DADDR ( 3 + argc ) + " = " ; <nl> - <nl> - text + = GDScriptFunctions : : get_func_name ( GDScriptFunctions : : Function ( _code_ptr [ ip + 1 ] ) ) ; <nl> - text + = " ( " ; <nl> - <nl> - for ( int i = 0 ; i < argc ; i + + ) { <nl> - if ( i > 0 ) <nl> - text + = " , " ; <nl> - text + = DADDR ( 3 + i ) ; <nl> - } <nl> - text + = " ) " ; <nl> - <nl> - incr = 4 + argc ; <nl> - } break ; <nl> - case OPCODE_CALL_SELF_BASE : { <nl> - text + = " call - self - base " ; <nl> - <nl> - int argc = _code_ptr [ ip + 2 ] ; <nl> - text + = DADDR ( 3 + argc ) + " = " ; <nl> - <nl> - text + = _global_names_ptr [ _code_ptr [ ip + 1 ] ] ; <nl> - text + = " ( " ; <nl> - <nl> - for ( int i = 0 ; i < argc ; i + + ) { <nl> - if ( i > 0 ) <nl> - text + = " , " ; <nl> - text + = DADDR ( 3 + i ) ; <nl> - } <nl> - text + = " ) " ; <nl> - <nl> - incr = 4 + argc ; <nl> - } break ; <nl> - case OPCODE_AWAIT : { <nl> - text + = " await " ; <nl> - text + = DADDR ( 1 ) ; <nl> - <nl> - incr + = 2 ; <nl> - } break ; <nl> - case OPCODE_AWAIT_RESUME : { <nl> - text + = " await resume " ; <nl> - text + = DADDR ( 1 ) ; <nl> - <nl> - incr = 2 ; <nl> - } break ; <nl> - case OPCODE_JUMP : { <nl> - text + = " jump " ; <nl> - text + = itos ( _code_ptr [ ip + 1 ] ) ; <nl> - <nl> - incr = 2 ; <nl> - } break ; <nl> - case OPCODE_JUMP_IF : { <nl> - text + = " jump - if " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " to " ; <nl> - text + = itos ( _code_ptr [ ip + 2 ] ) ; <nl> - <nl> - incr = 3 ; <nl> - } break ; <nl> - case OPCODE_JUMP_IF_NOT : { <nl> - text + = " jump - if - not " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " to " ; <nl> - text + = itos ( _code_ptr [ ip + 2 ] ) ; <nl> - <nl> - incr = 3 ; <nl> - } break ; <nl> - case OPCODE_JUMP_TO_DEF_ARGUMENT : { <nl> - text + = " jump - to - default - argument " ; <nl> - <nl> - incr = 1 ; <nl> - } break ; <nl> - case OPCODE_RETURN : { <nl> - text + = " return " ; <nl> - text + = DADDR ( 1 ) ; <nl> - <nl> - incr = 2 ; <nl> - } break ; <nl> - case OPCODE_ITERATE_BEGIN : { <nl> - text + = " for - init " ; <nl> - text + = DADDR ( 4 ) ; <nl> - text + = " in " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " counter " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " end " ; <nl> - text + = itos ( _code_ptr [ ip + 3 ] ) ; <nl> - <nl> - incr + = 5 ; <nl> - } break ; <nl> - case OPCODE_ITERATE : { <nl> - text + = " for - loop " ; <nl> - text + = DADDR ( 4 ) ; <nl> - text + = " in " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " counter " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " end " ; <nl> - text + = itos ( _code_ptr [ ip + 3 ] ) ; <nl> - <nl> - incr + = 5 ; <nl> - } break ; <nl> - case OPCODE_LINE : { <nl> - int line = _code_ptr [ ip + 1 ] - 1 ; <nl> - if ( line > = 0 & & line < p_code_lines . size ( ) ) { <nl> - text + = " line " ; <nl> - text + = itos ( line + 1 ) ; <nl> - text + = " : " ; <nl> - text + = p_code_lines [ line ] ; <nl> - } else { <nl> - text + = " " ; <nl> - } <nl> - <nl> - incr + = 2 ; <nl> - } break ; <nl> - case OPCODE_ASSERT : { <nl> - text + = " assert ( " ; <nl> - text + = DADDR ( 1 ) ; <nl> - text + = " , " ; <nl> - text + = DADDR ( 2 ) ; <nl> - text + = " ) " ; <nl> - <nl> - incr + = 3 ; <nl> - } break ; <nl> - case OPCODE_BREAKPOINT : { <nl> - text + = " breakpoint " ; <nl> - <nl> - incr + = 1 ; <nl> - } break ; <nl> - case OPCODE_END : { <nl> - text + = " = = END = = " ; <nl> - <nl> - incr + = 1 ; <nl> - } break ; <nl> - } <nl> - <nl> - ip + = incr ; <nl> - if ( text . get_string_length ( ) > 0 ) { <nl> - print_line ( text . as_string ( ) ) ; <nl> - } <nl> - } <nl> - } <nl> - # endif <nl> mmm a / modules / gdscript / gdscript_function . h <nl> ppp b / modules / gdscript / gdscript_function . h <nl> class GDScriptFunction { <nl> public : <nl> enum Opcode { <nl> OPCODE_OPERATOR , <nl> + OPCODE_OPERATOR_VALIDATED , <nl> OPCODE_EXTENDS_TEST , <nl> OPCODE_IS_BUILTIN , <nl> - OPCODE_SET , <nl> - OPCODE_GET , <nl> + OPCODE_SET_KEYED , <nl> + OPCODE_SET_KEYED_VALIDATED , <nl> + OPCODE_SET_INDEXED_VALIDATED , <nl> + OPCODE_GET_KEYED , <nl> + OPCODE_GET_KEYED_VALIDATED , <nl> + OPCODE_GET_INDEXED_VALIDATED , <nl> OPCODE_SET_NAMED , <nl> + OPCODE_SET_NAMED_VALIDATED , <nl> OPCODE_GET_NAMED , <nl> + OPCODE_GET_NAMED_VALIDATED , <nl> OPCODE_SET_MEMBER , <nl> OPCODE_GET_MEMBER , <nl> OPCODE_ASSIGN , <nl> class GDScriptFunction { <nl> OPCODE_CAST_TO_BUILTIN , <nl> OPCODE_CAST_TO_NATIVE , <nl> OPCODE_CAST_TO_SCRIPT , <nl> - OPCODE_CONSTRUCT , / / only for basic types ! ! <nl> + OPCODE_CONSTRUCT , / / Only for basic types ! <nl> + OPCODE_CONSTRUCT_VALIDATED , / / Only for basic types ! <nl> OPCODE_CONSTRUCT_ARRAY , <nl> OPCODE_CONSTRUCT_DICTIONARY , <nl> OPCODE_CALL , <nl> OPCODE_CALL_RETURN , <nl> OPCODE_CALL_ASYNC , <nl> OPCODE_CALL_BUILT_IN , <nl> + OPCODE_CALL_BUILTIN_TYPE_VALIDATED , <nl> OPCODE_CALL_SELF_BASE , <nl> + OPCODE_CALL_METHOD_BIND , <nl> + OPCODE_CALL_METHOD_BIND_RET , <nl> + / / ptrcall have one instruction per return type . <nl> + OPCODE_CALL_PTRCALL_NO_RETURN , <nl> + OPCODE_CALL_PTRCALL_BOOL , <nl> + OPCODE_CALL_PTRCALL_INT , <nl> + OPCODE_CALL_PTRCALL_FLOAT , <nl> + OPCODE_CALL_PTRCALL_STRING , <nl> + OPCODE_CALL_PTRCALL_VECTOR2 , <nl> + OPCODE_CALL_PTRCALL_VECTOR2I , <nl> + OPCODE_CALL_PTRCALL_RECT2 , <nl> + OPCODE_CALL_PTRCALL_RECT2I , <nl> + OPCODE_CALL_PTRCALL_VECTOR3 , <nl> + OPCODE_CALL_PTRCALL_VECTOR3I , <nl> + OPCODE_CALL_PTRCALL_TRANSFORM2D , <nl> + OPCODE_CALL_PTRCALL_PLANE , <nl> + OPCODE_CALL_PTRCALL_QUAT , <nl> + OPCODE_CALL_PTRCALL_AABB , <nl> + OPCODE_CALL_PTRCALL_BASIS , <nl> + OPCODE_CALL_PTRCALL_TRANSFORM , <nl> + OPCODE_CALL_PTRCALL_COLOR , <nl> + OPCODE_CALL_PTRCALL_STRING_NAME , <nl> + OPCODE_CALL_PTRCALL_NODE_PATH , <nl> + OPCODE_CALL_PTRCALL_RID , <nl> + OPCODE_CALL_PTRCALL_OBJECT , <nl> + OPCODE_CALL_PTRCALL_CALLABLE , <nl> + OPCODE_CALL_PTRCALL_SIGNAL , <nl> + OPCODE_CALL_PTRCALL_DICTIONARY , <nl> + OPCODE_CALL_PTRCALL_ARRAY , <nl> + OPCODE_CALL_PTRCALL_PACKED_BYTE_ARRAY , <nl> + OPCODE_CALL_PTRCALL_PACKED_INT32_ARRAY , <nl> + OPCODE_CALL_PTRCALL_PACKED_INT64_ARRAY , <nl> + OPCODE_CALL_PTRCALL_PACKED_FLOAT32_ARRAY , <nl> + OPCODE_CALL_PTRCALL_PACKED_FLOAT64_ARRAY , <nl> + OPCODE_CALL_PTRCALL_PACKED_STRING_ARRAY , <nl> + OPCODE_CALL_PTRCALL_PACKED_VECTOR2_ARRAY , <nl> + OPCODE_CALL_PTRCALL_PACKED_VECTOR3_ARRAY , <nl> + OPCODE_CALL_PTRCALL_PACKED_COLOR_ARRAY , <nl> OPCODE_AWAIT , <nl> OPCODE_AWAIT_RESUME , <nl> OPCODE_JUMP , <nl> class GDScriptFunction { <nl> OPCODE_JUMP_TO_DEF_ARGUMENT , <nl> OPCODE_RETURN , <nl> OPCODE_ITERATE_BEGIN , <nl> + OPCODE_ITERATE_BEGIN_INT , <nl> + OPCODE_ITERATE_BEGIN_FLOAT , <nl> + OPCODE_ITERATE_BEGIN_VECTOR2 , <nl> + OPCODE_ITERATE_BEGIN_VECTOR2I , <nl> + OPCODE_ITERATE_BEGIN_VECTOR3 , <nl> + OPCODE_ITERATE_BEGIN_VECTOR3I , <nl> + OPCODE_ITERATE_BEGIN_STRING , <nl> + OPCODE_ITERATE_BEGIN_DICTIONARY , <nl> + OPCODE_ITERATE_BEGIN_ARRAY , <nl> + OPCODE_ITERATE_BEGIN_PACKED_BYTE_ARRAY , <nl> + OPCODE_ITERATE_BEGIN_PACKED_INT32_ARRAY , <nl> + OPCODE_ITERATE_BEGIN_PACKED_INT64_ARRAY , <nl> + OPCODE_ITERATE_BEGIN_PACKED_FLOAT32_ARRAY , <nl> + OPCODE_ITERATE_BEGIN_PACKED_FLOAT64_ARRAY , <nl> + OPCODE_ITERATE_BEGIN_PACKED_STRING_ARRAY , <nl> + OPCODE_ITERATE_BEGIN_PACKED_VECTOR2_ARRAY , <nl> + OPCODE_ITERATE_BEGIN_PACKED_VECTOR3_ARRAY , <nl> + OPCODE_ITERATE_BEGIN_PACKED_COLOR_ARRAY , <nl> + OPCODE_ITERATE_BEGIN_OBJECT , <nl> OPCODE_ITERATE , <nl> + OPCODE_ITERATE_INT , <nl> + OPCODE_ITERATE_FLOAT , <nl> + OPCODE_ITERATE_VECTOR2 , <nl> + OPCODE_ITERATE_VECTOR2I , <nl> + OPCODE_ITERATE_VECTOR3 , <nl> + OPCODE_ITERATE_VECTOR3I , <nl> + OPCODE_ITERATE_STRING , <nl> + OPCODE_ITERATE_DICTIONARY , <nl> + OPCODE_ITERATE_ARRAY , <nl> + OPCODE_ITERATE_PACKED_BYTE_ARRAY , <nl> + OPCODE_ITERATE_PACKED_INT32_ARRAY , <nl> + OPCODE_ITERATE_PACKED_INT64_ARRAY , <nl> + OPCODE_ITERATE_PACKED_FLOAT32_ARRAY , <nl> + OPCODE_ITERATE_PACKED_FLOAT64_ARRAY , <nl> + OPCODE_ITERATE_PACKED_STRING_ARRAY , <nl> + OPCODE_ITERATE_PACKED_VECTOR2_ARRAY , <nl> + OPCODE_ITERATE_PACKED_VECTOR3_ARRAY , <nl> + OPCODE_ITERATE_PACKED_COLOR_ARRAY , <nl> + OPCODE_ITERATE_OBJECT , <nl> OPCODE_ASSERT , <nl> OPCODE_BREAKPOINT , <nl> OPCODE_LINE , <nl> class GDScriptFunction { <nl> ADDR_TYPE_NIL = 9 <nl> } ; <nl> <nl> + enum Instruction { <nl> + INSTR_BITS = 20 , <nl> + INSTR_MASK = ( ( 1 < < INSTR_BITS ) - 1 ) , <nl> + INSTR_ARGS_MASK = ~ INSTR_MASK , <nl> + } ; <nl> + <nl> struct StackDebug { <nl> int line ; <nl> int pos ; <nl> class GDScriptFunction { <nl> StringName source ; <nl> <nl> mutable Variant nil ; <nl> - mutable Variant * _constants_ptr ; <nl> - int _constant_count ; <nl> - const StringName * _global_names_ptr ; <nl> - int _global_names_count ; <nl> - const int * _default_arg_ptr ; <nl> - int _default_arg_count ; <nl> - const int * _code_ptr ; <nl> - int _code_size ; <nl> - int _argument_count ; <nl> - int _stack_size ; <nl> - int _call_size ; <nl> - int _initial_line ; <nl> - bool _static ; <nl> - MultiplayerAPI : : RPCMode rpc_mode ; <nl> - <nl> - GDScript * _script ; <nl> + mutable Variant * _constants_ptr = nullptr ; <nl> + int _constant_count = 0 ; <nl> + const StringName * _global_names_ptr = nullptr ; <nl> + int _global_names_count = 0 ; <nl> + const int * _default_arg_ptr = nullptr ; <nl> + int _default_arg_count = 0 ; <nl> + int _operator_funcs_count = 0 ; <nl> + const Variant : : ValidatedOperatorEvaluator * _operator_funcs_ptr = nullptr ; <nl> + int _setters_count = 0 ; <nl> + const Variant : : ValidatedSetter * _setters_ptr = nullptr ; <nl> + int _getters_count = 0 ; <nl> + const Variant : : ValidatedGetter * _getters_ptr = nullptr ; <nl> + int _keyed_setters_count = 0 ; <nl> + const Variant : : ValidatedKeyedSetter * _keyed_setters_ptr = nullptr ; <nl> + int _keyed_getters_count = 0 ; <nl> + const Variant : : ValidatedKeyedGetter * _keyed_getters_ptr = nullptr ; <nl> + int _indexed_setters_count = 0 ; <nl> + const Variant : : ValidatedIndexedSetter * _indexed_setters_ptr = nullptr ; <nl> + int _indexed_getters_count = 0 ; <nl> + const Variant : : ValidatedIndexedGetter * _indexed_getters_ptr = nullptr ; <nl> + int _builtin_methods_count = 0 ; <nl> + const Variant : : ValidatedBuiltInMethod * _builtin_methods_ptr = nullptr ; <nl> + int _constructors_count = 0 ; <nl> + const Variant : : ValidatedConstructor * _constructors_ptr = nullptr ; <nl> + int _methods_count = 0 ; <nl> + MethodBind * * _methods_ptr = nullptr ; <nl> + const int * _code_ptr = nullptr ; <nl> + int _code_size = 0 ; <nl> + int _argument_count = 0 ; <nl> + int _stack_size = 0 ; <nl> + int _instruction_args_size = 0 ; <nl> + int _ptrcall_args_size = 0 ; <nl> + <nl> + int _initial_line = 0 ; <nl> + bool _static = false ; <nl> + MultiplayerAPI : : RPCMode rpc_mode = MultiplayerAPI : : RPC_MODE_DISABLED ; <nl> + <nl> + GDScript * _script = nullptr ; <nl> <nl> StringName name ; <nl> Vector < Variant > constants ; <nl> Vector < StringName > global_names ; <nl> Vector < int > default_arguments ; <nl> + Vector < Variant : : ValidatedOperatorEvaluator > operator_funcs ; <nl> + Vector < Variant : : ValidatedSetter > setters ; <nl> + Vector < Variant : : ValidatedGetter > getters ; <nl> + Vector < Variant : : ValidatedKeyedSetter > keyed_setters ; <nl> + Vector < Variant : : ValidatedKeyedGetter > keyed_getters ; <nl> + Vector < Variant : : ValidatedIndexedSetter > indexed_setters ; <nl> + Vector < Variant : : ValidatedIndexedGetter > indexed_getters ; <nl> + Vector < Variant : : ValidatedBuiltInMethod > builtin_methods ; <nl> + Vector < Variant : : ValidatedConstructor > constructors ; <nl> + Vector < MethodBind * > methods ; <nl> Vector < int > code ; <nl> Vector < GDScriptDataType > argument_types ; <nl> GDScriptDataType return_type ; <nl> class GDScriptFunction { <nl> <nl> friend class GDScriptLanguage ; <nl> <nl> - SelfList < GDScriptFunction > function_list ; <nl> + SelfList < GDScriptFunction > function_list { this } ; <nl> # ifdef DEBUG_ENABLED <nl> CharString func_cname ; <nl> - const char * _func_cname ; <nl> + const char * _func_cname = nullptr ; <nl> <nl> struct Profile { <nl> StringName signature ; <nl> - uint64_t call_count ; <nl> - uint64_t self_time ; <nl> - uint64_t total_time ; <nl> - uint64_t frame_call_count ; <nl> - uint64_t frame_self_time ; <nl> - uint64_t frame_total_time ; <nl> - uint64_t last_frame_call_count ; <nl> - uint64_t last_frame_self_time ; <nl> - uint64_t last_frame_total_time ; <nl> + uint64_t call_count = 0 ; <nl> + uint64_t self_time = 0 ; <nl> + uint64_t total_time = 0 ; <nl> + uint64_t frame_call_count = 0 ; <nl> + uint64_t frame_self_time = 0 ; <nl> + uint64_t frame_total_time = 0 ; <nl> + uint64_t last_frame_call_count = 0 ; <nl> + uint64_t last_frame_self_time = 0 ; <nl> + uint64_t last_frame_total_time = 0 ; <nl> } profile ; <nl> <nl> # endif <nl> new file mode 100644 <nl> index 00000000000 . . 7c8bfcd944a <nl> mmm / dev / null <nl> ppp b / modules / gdscript / gdscript_vm . cpp <nl> <nl> + / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> + / * gdscript_vm . cpp * / <nl> + / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> + / * This file is part of : * / <nl> + / * GODOT ENGINE * / <nl> + / * https : / / godotengine . org * / <nl> + / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> + / * Copyright ( c ) 2007 - 2020 Juan Linietsky , Ariel Manzur . * / <nl> + / * Copyright ( c ) 2014 - 2020 Godot Engine contributors ( cf . AUTHORS . md ) . * / <nl> + / * * / <nl> + / * Permission is hereby granted , free of charge , to any person obtaining * / <nl> + / * a copy of this software and associated documentation files ( the * / <nl> + / * " Software " ) , to deal in the Software without restriction , including * / <nl> + / * without limitation the rights to use , copy , modify , merge , publish , * / <nl> + / * distribute , sublicense , and / or sell copies of the Software , and to * / <nl> + / * permit persons to whom the Software is furnished to do so , subject to * / <nl> + / * the following conditions : * / <nl> + / * * / <nl> + / * The above copyright notice and this permission notice shall be * / <nl> + / * included in all copies or substantial portions of the Software . * / <nl> + / * * / <nl> + / * THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , * / <nl> + / * EXPRESS OR IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * / <nl> + / * MERCHANTABILITY , FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . * / <nl> + / * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * / <nl> + / * CLAIM , DAMAGES OR OTHER LIABILITY , WHETHER IN AN ACTION OF CONTRACT , * / <nl> + / * TORT OR OTHERWISE , ARISING FROM , OUT OF OR IN CONNECTION WITH THE * / <nl> + / * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE . * / <nl> + / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> + <nl> + # include " gdscript_function . h " <nl> + <nl> + # include " core / core_string_names . h " <nl> + # include " core / os / os . h " <nl> + # include " gdscript . h " <nl> + # include " gdscript_functions . h " <nl> + <nl> + Variant * GDScriptFunction : : _get_variant ( int p_address , GDScriptInstance * p_instance , GDScript * p_script , Variant & self , Variant & static_ref , Variant * p_stack , String & r_error ) const { <nl> + int address = p_address & ADDR_MASK ; <nl> + <nl> + / / sequential table ( jump table generated by compiler ) <nl> + switch ( ( p_address & ADDR_TYPE_MASK ) > > ADDR_BITS ) { <nl> + case ADDR_TYPE_SELF : { <nl> + # ifdef DEBUG_ENABLED <nl> + if ( unlikely ( ! p_instance ) ) { <nl> + r_error = " Cannot access self without instance . " ; <nl> + return nullptr ; <nl> + } <nl> + # endif <nl> + return & self ; <nl> + } break ; <nl> + case ADDR_TYPE_CLASS : { <nl> + return & static_ref ; <nl> + } break ; <nl> + case ADDR_TYPE_MEMBER : { <nl> + # ifdef DEBUG_ENABLED <nl> + if ( unlikely ( ! p_instance ) ) { <nl> + r_error = " Cannot access member without instance . " ; <nl> + return nullptr ; <nl> + } <nl> + # endif <nl> + / / member indexing is O ( 1 ) <nl> + return & p_instance - > members . write [ address ] ; <nl> + } break ; <nl> + case ADDR_TYPE_CLASS_CONSTANT : { <nl> + / / todo change to index ! <nl> + GDScript * s = p_script ; <nl> + # ifdef DEBUG_ENABLED <nl> + ERR_FAIL_INDEX_V ( address , _global_names_count , nullptr ) ; <nl> + # endif <nl> + const StringName * sn = & _global_names_ptr [ address ] ; <nl> + <nl> + while ( s ) { <nl> + GDScript * o = s ; <nl> + while ( o ) { <nl> + Map < StringName , Variant > : : Element * E = o - > constants . find ( * sn ) ; <nl> + if ( E ) { <nl> + return & E - > get ( ) ; <nl> + } <nl> + o = o - > _owner ; <nl> + } <nl> + s = s - > _base ; <nl> + } <nl> + <nl> + ERR_FAIL_V_MSG ( nullptr , " GDScriptCompiler bug . " ) ; <nl> + } break ; <nl> + case ADDR_TYPE_LOCAL_CONSTANT : { <nl> + # ifdef DEBUG_ENABLED <nl> + ERR_FAIL_INDEX_V ( address , _constant_count , nullptr ) ; <nl> + # endif <nl> + return & _constants_ptr [ address ] ; <nl> + } break ; <nl> + case ADDR_TYPE_STACK : <nl> + case ADDR_TYPE_STACK_VARIABLE : { <nl> + # ifdef DEBUG_ENABLED <nl> + ERR_FAIL_INDEX_V ( address , _stack_size , nullptr ) ; <nl> + # endif <nl> + return & p_stack [ address ] ; <nl> + } break ; <nl> + case ADDR_TYPE_GLOBAL : { <nl> + # ifdef DEBUG_ENABLED <nl> + ERR_FAIL_INDEX_V ( address , GDScriptLanguage : : get_singleton ( ) - > get_global_array_size ( ) , nullptr ) ; <nl> + # endif <nl> + return & GDScriptLanguage : : get_singleton ( ) - > get_global_array ( ) [ address ] ; <nl> + } break ; <nl> + # ifdef TOOLS_ENABLED <nl> + case ADDR_TYPE_NAMED_GLOBAL : { <nl> + # ifdef DEBUG_ENABLED <nl> + ERR_FAIL_INDEX_V ( address , _global_names_count , nullptr ) ; <nl> + # endif <nl> + StringName id = _global_names_ptr [ address ] ; <nl> + <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > get_named_globals_map ( ) . has ( id ) ) { <nl> + return ( Variant * ) & GDScriptLanguage : : get_singleton ( ) - > get_named_globals_map ( ) [ id ] ; <nl> + } else { <nl> + r_error = " Autoload singleton ' " + String ( id ) + " ' has been removed . " ; <nl> + return nullptr ; <nl> + } <nl> + } break ; <nl> + # endif <nl> + case ADDR_TYPE_NIL : { <nl> + return & nil ; <nl> + } break ; <nl> + } <nl> + <nl> + ERR_FAIL_V_MSG ( nullptr , " Bad code ! ( unknown addressing mode ) . " ) ; <nl> + return nullptr ; <nl> + } <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + static String _get_var_type ( const Variant * p_var ) { <nl> + String basestr ; <nl> + <nl> + if ( p_var - > get_type ( ) = = Variant : : OBJECT ) { <nl> + bool was_freed ; <nl> + Object * bobj = p_var - > get_validated_object_with_check ( was_freed ) ; <nl> + if ( ! bobj ) { <nl> + if ( was_freed ) { <nl> + basestr = " null instance " ; <nl> + } else { <nl> + basestr = " previously freed " ; <nl> + } <nl> + } else { <nl> + if ( bobj - > get_script_instance ( ) ) { <nl> + basestr = bobj - > get_class ( ) + " ( " + bobj - > get_script_instance ( ) - > get_script ( ) - > get_path ( ) . get_file ( ) + " ) " ; <nl> + } else { <nl> + basestr = bobj - > get_class ( ) ; <nl> + } <nl> + } <nl> + <nl> + } else { <nl> + basestr = Variant : : get_type_name ( p_var - > get_type ( ) ) ; <nl> + } <nl> + <nl> + return basestr ; <nl> + } <nl> + # endif / / DEBUG_ENABLED <nl> + <nl> + String GDScriptFunction : : _get_call_error ( const Callable : : CallError & p_err , const String & p_where , const Variant * * argptrs ) const { <nl> + String err_text ; <nl> + <nl> + if ( p_err . error = = Callable : : CallError : : CALL_ERROR_INVALID_ARGUMENT ) { <nl> + int errorarg = p_err . argument ; <nl> + / / Handle the Object to Object case separately as we don ' t have further class details . <nl> + # ifdef DEBUG_ENABLED <nl> + if ( p_err . expected = = Variant : : OBJECT & & argptrs [ errorarg ] - > get_type ( ) = = p_err . expected ) { <nl> + err_text = " Invalid type in " + p_where + " . The Object - derived class of argument " + itos ( errorarg + 1 ) + " ( " + _get_var_type ( argptrs [ errorarg ] ) + " ) is not a subclass of the expected argument class . " ; <nl> + } else <nl> + # endif / / DEBUG_ENABLED <nl> + { <nl> + err_text = " Invalid type in " + p_where + " . Cannot convert argument " + itos ( errorarg + 1 ) + " from " + Variant : : get_type_name ( argptrs [ errorarg ] - > get_type ( ) ) + " to " + Variant : : get_type_name ( Variant : : Type ( p_err . expected ) ) + " . " ; <nl> + } <nl> + } else if ( p_err . error = = Callable : : CallError : : CALL_ERROR_TOO_MANY_ARGUMENTS ) { <nl> + err_text = " Invalid call to " + p_where + " . Expected " + itos ( p_err . argument ) + " arguments . " ; <nl> + } else if ( p_err . error = = Callable : : CallError : : CALL_ERROR_TOO_FEW_ARGUMENTS ) { <nl> + err_text = " Invalid call to " + p_where + " . Expected " + itos ( p_err . argument ) + " arguments . " ; <nl> + } else if ( p_err . error = = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ) { <nl> + err_text = " Invalid call . Nonexistent " + p_where + " . " ; <nl> + } else if ( p_err . error = = Callable : : CallError : : CALL_ERROR_INSTANCE_IS_NULL ) { <nl> + err_text = " Attempt to call " + p_where + " on a null instance . " ; <nl> + } else { <nl> + err_text = " Bug , call error : # " + itos ( p_err . error ) ; <nl> + } <nl> + <nl> + return err_text ; <nl> + } <nl> + <nl> + # if defined ( __GNUC__ ) <nl> + # define OPCODES_TABLE \ <nl> + static const void * switch_table_ops [ ] = { \ <nl> + & & OPCODE_OPERATOR , \ <nl> + & & OPCODE_OPERATOR_VALIDATED , \ <nl> + & & OPCODE_EXTENDS_TEST , \ <nl> + & & OPCODE_IS_BUILTIN , \ <nl> + & & OPCODE_SET_KEYED , \ <nl> + & & OPCODE_SET_KEYED_VALIDATED , \ <nl> + & & OPCODE_SET_INDEXED_VALIDATED , \ <nl> + & & OPCODE_GET_KEYED , \ <nl> + & & OPCODE_GET_KEYED_VALIDATED , \ <nl> + & & OPCODE_GET_INDEXED_VALIDATED , \ <nl> + & & OPCODE_SET_NAMED , \ <nl> + & & OPCODE_SET_NAMED_VALIDATED , \ <nl> + & & OPCODE_GET_NAMED , \ <nl> + & & OPCODE_GET_NAMED_VALIDATED , \ <nl> + & & OPCODE_SET_MEMBER , \ <nl> + & & OPCODE_GET_MEMBER , \ <nl> + & & OPCODE_ASSIGN , \ <nl> + & & OPCODE_ASSIGN_TRUE , \ <nl> + & & OPCODE_ASSIGN_FALSE , \ <nl> + & & OPCODE_ASSIGN_TYPED_BUILTIN , \ <nl> + & & OPCODE_ASSIGN_TYPED_NATIVE , \ <nl> + & & OPCODE_ASSIGN_TYPED_SCRIPT , \ <nl> + & & OPCODE_CAST_TO_BUILTIN , \ <nl> + & & OPCODE_CAST_TO_NATIVE , \ <nl> + & & OPCODE_CAST_TO_SCRIPT , \ <nl> + & & OPCODE_CONSTRUCT , \ <nl> + & & OPCODE_CONSTRUCT_VALIDATED , \ <nl> + & & OPCODE_CONSTRUCT_ARRAY , \ <nl> + & & OPCODE_CONSTRUCT_DICTIONARY , \ <nl> + & & OPCODE_CALL , \ <nl> + & & OPCODE_CALL_RETURN , \ <nl> + & & OPCODE_CALL_ASYNC , \ <nl> + & & OPCODE_CALL_BUILT_IN , \ <nl> + & & OPCODE_CALL_BUILTIN_TYPE_VALIDATED , \ <nl> + & & OPCODE_CALL_SELF_BASE , \ <nl> + & & OPCODE_CALL_METHOD_BIND , \ <nl> + & & OPCODE_CALL_METHOD_BIND_RET , \ <nl> + & & OPCODE_CALL_PTRCALL_NO_RETURN , \ <nl> + & & OPCODE_CALL_PTRCALL_BOOL , \ <nl> + & & OPCODE_CALL_PTRCALL_INT , \ <nl> + & & OPCODE_CALL_PTRCALL_FLOAT , \ <nl> + & & OPCODE_CALL_PTRCALL_STRING , \ <nl> + & & OPCODE_CALL_PTRCALL_VECTOR2 , \ <nl> + & & OPCODE_CALL_PTRCALL_VECTOR2I , \ <nl> + & & OPCODE_CALL_PTRCALL_RECT2 , \ <nl> + & & OPCODE_CALL_PTRCALL_RECT2I , \ <nl> + & & OPCODE_CALL_PTRCALL_VECTOR3 , \ <nl> + & & OPCODE_CALL_PTRCALL_VECTOR3I , \ <nl> + & & OPCODE_CALL_PTRCALL_TRANSFORM2D , \ <nl> + & & OPCODE_CALL_PTRCALL_PLANE , \ <nl> + & & OPCODE_CALL_PTRCALL_QUAT , \ <nl> + & & OPCODE_CALL_PTRCALL_AABB , \ <nl> + & & OPCODE_CALL_PTRCALL_BASIS , \ <nl> + & & OPCODE_CALL_PTRCALL_TRANSFORM , \ <nl> + & & OPCODE_CALL_PTRCALL_COLOR , \ <nl> + & & OPCODE_CALL_PTRCALL_STRING_NAME , \ <nl> + & & OPCODE_CALL_PTRCALL_NODE_PATH , \ <nl> + & & OPCODE_CALL_PTRCALL_RID , \ <nl> + & & OPCODE_CALL_PTRCALL_OBJECT , \ <nl> + & & OPCODE_CALL_PTRCALL_CALLABLE , \ <nl> + & & OPCODE_CALL_PTRCALL_SIGNAL , \ <nl> + & & OPCODE_CALL_PTRCALL_DICTIONARY , \ <nl> + & & OPCODE_CALL_PTRCALL_ARRAY , \ <nl> + & & OPCODE_CALL_PTRCALL_PACKED_BYTE_ARRAY , \ <nl> + & & OPCODE_CALL_PTRCALL_PACKED_INT32_ARRAY , \ <nl> + & & OPCODE_CALL_PTRCALL_PACKED_INT64_ARRAY , \ <nl> + & & OPCODE_CALL_PTRCALL_PACKED_FLOAT32_ARRAY , \ <nl> + & & OPCODE_CALL_PTRCALL_PACKED_FLOAT64_ARRAY , \ <nl> + & & OPCODE_CALL_PTRCALL_PACKED_STRING_ARRAY , \ <nl> + & & OPCODE_CALL_PTRCALL_PACKED_VECTOR2_ARRAY , \ <nl> + & & OPCODE_CALL_PTRCALL_PACKED_VECTOR3_ARRAY , \ <nl> + & & OPCODE_CALL_PTRCALL_PACKED_COLOR_ARRAY , \ <nl> + & & OPCODE_AWAIT , \ <nl> + & & OPCODE_AWAIT_RESUME , \ <nl> + & & OPCODE_JUMP , \ <nl> + & & OPCODE_JUMP_IF , \ <nl> + & & OPCODE_JUMP_IF_NOT , \ <nl> + & & OPCODE_JUMP_TO_DEF_ARGUMENT , \ <nl> + & & OPCODE_RETURN , \ <nl> + & & OPCODE_ITERATE_BEGIN , \ <nl> + & & OPCODE_ITERATE_BEGIN_INT , \ <nl> + & & OPCODE_ITERATE_BEGIN_FLOAT , \ <nl> + & & OPCODE_ITERATE_BEGIN_VECTOR2 , \ <nl> + & & OPCODE_ITERATE_BEGIN_VECTOR2I , \ <nl> + & & OPCODE_ITERATE_BEGIN_VECTOR3 , \ <nl> + & & OPCODE_ITERATE_BEGIN_VECTOR3I , \ <nl> + & & OPCODE_ITERATE_BEGIN_STRING , \ <nl> + & & OPCODE_ITERATE_BEGIN_DICTIONARY , \ <nl> + & & OPCODE_ITERATE_BEGIN_ARRAY , \ <nl> + & & OPCODE_ITERATE_BEGIN_PACKED_BYTE_ARRAY , \ <nl> + & & OPCODE_ITERATE_BEGIN_PACKED_INT32_ARRAY , \ <nl> + & & OPCODE_ITERATE_BEGIN_PACKED_INT64_ARRAY , \ <nl> + & & OPCODE_ITERATE_BEGIN_PACKED_FLOAT32_ARRAY , \ <nl> + & & OPCODE_ITERATE_BEGIN_PACKED_FLOAT64_ARRAY , \ <nl> + & & OPCODE_ITERATE_BEGIN_PACKED_STRING_ARRAY , \ <nl> + & & OPCODE_ITERATE_BEGIN_PACKED_VECTOR2_ARRAY , \ <nl> + & & OPCODE_ITERATE_BEGIN_PACKED_VECTOR3_ARRAY , \ <nl> + & & OPCODE_ITERATE_BEGIN_PACKED_COLOR_ARRAY , \ <nl> + & & OPCODE_ITERATE_BEGIN_OBJECT , \ <nl> + & & OPCODE_ITERATE , \ <nl> + & & OPCODE_ITERATE_INT , \ <nl> + & & OPCODE_ITERATE_FLOAT , \ <nl> + & & OPCODE_ITERATE_VECTOR2 , \ <nl> + & & OPCODE_ITERATE_VECTOR2I , \ <nl> + & & OPCODE_ITERATE_VECTOR3 , \ <nl> + & & OPCODE_ITERATE_VECTOR3I , \ <nl> + & & OPCODE_ITERATE_STRING , \ <nl> + & & OPCODE_ITERATE_DICTIONARY , \ <nl> + & & OPCODE_ITERATE_ARRAY , \ <nl> + & & OPCODE_ITERATE_PACKED_BYTE_ARRAY , \ <nl> + & & OPCODE_ITERATE_PACKED_INT32_ARRAY , \ <nl> + & & OPCODE_ITERATE_PACKED_INT64_ARRAY , \ <nl> + & & OPCODE_ITERATE_PACKED_FLOAT32_ARRAY , \ <nl> + & & OPCODE_ITERATE_PACKED_FLOAT64_ARRAY , \ <nl> + & & OPCODE_ITERATE_PACKED_STRING_ARRAY , \ <nl> + & & OPCODE_ITERATE_PACKED_VECTOR2_ARRAY , \ <nl> + & & OPCODE_ITERATE_PACKED_VECTOR3_ARRAY , \ <nl> + & & OPCODE_ITERATE_PACKED_COLOR_ARRAY , \ <nl> + & & OPCODE_ITERATE_OBJECT , \ <nl> + & & OPCODE_ASSERT , \ <nl> + & & OPCODE_BREAKPOINT , \ <nl> + & & OPCODE_LINE , \ <nl> + & & OPCODE_END \ <nl> + } ; \ <nl> + static_assert ( ( sizeof ( switch_table_ops ) / sizeof ( switch_table_ops [ 0 ] ) = = ( OPCODE_END + 1 ) ) , " Opcodes in jump table aren ' t the same as opcodes in enum . " ) ; <nl> + <nl> + # define OPCODE ( m_op ) \ <nl> + m_op : <nl> + # define OPCODE_WHILE ( m_test ) \ <nl> + OPSWHILE : <nl> + # define OPCODES_END \ <nl> + OPSEXIT : <nl> + # define OPCODES_OUT \ <nl> + OPSOUT : <nl> + # define DISPATCH_OPCODE goto OPSWHILE <nl> + # define OPCODE_SWITCH ( m_test ) goto * switch_table_ops [ m_test ] ; <nl> + # define OPCODE_BREAK goto OPSEXIT <nl> + # define OPCODE_OUT goto OPSOUT <nl> + # else <nl> + # define OPCODES_TABLE <nl> + # define OPCODE ( m_op ) case m_op : <nl> + # define OPCODE_WHILE ( m_test ) while ( m_test ) <nl> + # define OPCODES_END <nl> + # define OPCODES_OUT <nl> + # define DISPATCH_OPCODE continue <nl> + # define OPCODE_SWITCH ( m_test ) switch ( m_test ) <nl> + # define OPCODE_BREAK break <nl> + # define OPCODE_OUT break <nl> + # endif <nl> + <nl> + / / Helpers for VariantInternal methods in macros . <nl> + # define OP_GET_BOOL get_bool <nl> + # define OP_GET_INT get_int <nl> + # define OP_GET_FLOAT get_float <nl> + # define OP_GET_VECTOR2 get_vector2 <nl> + # define OP_GET_VECTOR2I get_vector2i <nl> + # define OP_GET_VECTOR3 get_vector3 <nl> + # define OP_GET_VECTOR3I get_vector3i <nl> + # define OP_GET_RECT2 get_rect2 <nl> + # define OP_GET_RECT2I get_rect2i <nl> + # define OP_GET_QUAT get_quat <nl> + # define OP_GET_COLOR get_color <nl> + # define OP_GET_STRING get_string <nl> + # define OP_GET_STRING_NAME get_string_name <nl> + # define OP_GET_NODE_PATH get_node_path <nl> + # define OP_GET_CALLABLE get_callable <nl> + # define OP_GET_SIGNAL get_signal <nl> + # define OP_GET_ARRAY get_array <nl> + # define OP_GET_DICTIONARY get_dictionary <nl> + # define OP_GET_PACKED_BYTE_ARRAY get_byte_array <nl> + # define OP_GET_PACKED_INT32_ARRAY get_int32_array <nl> + # define OP_GET_PACKED_INT64_ARRAY get_int64_array <nl> + # define OP_GET_PACKED_FLOAT32_ARRAY get_float32_array <nl> + # define OP_GET_PACKED_FLOAT64_ARRAY get_float64_array <nl> + # define OP_GET_PACKED_STRING_ARRAY get_string_array <nl> + # define OP_GET_PACKED_VECTOR2_ARRAY get_vector2_array <nl> + # define OP_GET_PACKED_VECTOR3_ARRAY get_vector3_array <nl> + # define OP_GET_PACKED_COLOR_ARRAY get_color_array <nl> + # define OP_GET_TRANSFORM get_transform <nl> + # define OP_GET_TRANSFORM2D get_transform2d <nl> + # define OP_GET_PLANE get_plane <nl> + # define OP_GET_AABB get_aabb <nl> + # define OP_GET_BASIS get_basis <nl> + # define OP_GET_RID get_rid <nl> + <nl> + Variant GDScriptFunction : : call ( GDScriptInstance * p_instance , const Variant * * p_args , int p_argcount , Callable : : CallError & r_err , CallState * p_state ) { <nl> + OPCODES_TABLE ; <nl> + <nl> + if ( ! _code_ptr ) { <nl> + return Variant ( ) ; <nl> + } <nl> + <nl> + r_err . error = Callable : : CallError : : CALL_OK ; <nl> + <nl> + Variant self ; <nl> + Variant static_ref ; <nl> + Variant retvalue ; <nl> + Variant * stack = nullptr ; <nl> + Variant * * instruction_args ; <nl> + const void * * call_args_ptr = nullptr ; <nl> + int defarg = 0 ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + <nl> + / / GDScriptLanguage : : get_singleton ( ) - > calls + + ; <nl> + <nl> + # endif <nl> + <nl> + uint32_t alloca_size = 0 ; <nl> + GDScript * script ; <nl> + int ip = 0 ; <nl> + int line = _initial_line ; <nl> + <nl> + if ( p_state ) { <nl> + / / use existing ( supplied ) state ( awaited ) <nl> + stack = ( Variant * ) p_state - > stack . ptr ( ) ; <nl> + instruction_args = ( Variant * * ) & p_state - > stack . ptr ( ) [ sizeof ( Variant ) * p_state - > stack_size ] ; / / ptr ( ) to avoid bounds check <nl> + line = p_state - > line ; <nl> + ip = p_state - > ip ; <nl> + alloca_size = p_state - > stack . size ( ) ; <nl> + script = p_state - > script ; <nl> + p_instance = p_state - > instance ; <nl> + defarg = p_state - > defarg ; <nl> + self = p_state - > self ; <nl> + <nl> + } else { <nl> + if ( p_argcount ! = _argument_count ) { <nl> + if ( p_argcount > _argument_count ) { <nl> + r_err . error = Callable : : CallError : : CALL_ERROR_TOO_MANY_ARGUMENTS ; <nl> + r_err . argument = _argument_count ; <nl> + <nl> + return Variant ( ) ; <nl> + } else if ( p_argcount < _argument_count - _default_arg_count ) { <nl> + r_err . error = Callable : : CallError : : CALL_ERROR_TOO_FEW_ARGUMENTS ; <nl> + r_err . argument = _argument_count - _default_arg_count ; <nl> + return Variant ( ) ; <nl> + } else { <nl> + defarg = _argument_count - p_argcount ; <nl> + } <nl> + } <nl> + <nl> + alloca_size = sizeof ( Variant * ) * _instruction_args_size + sizeof ( Variant ) * _stack_size ; <nl> + <nl> + if ( alloca_size ) { <nl> + uint8_t * aptr = ( uint8_t * ) alloca ( alloca_size ) ; <nl> + <nl> + if ( _stack_size ) { <nl> + stack = ( Variant * ) aptr ; <nl> + for ( int i = 0 ; i < p_argcount ; i + + ) { <nl> + if ( ! argument_types [ i ] . has_type ) { <nl> + memnew_placement ( & stack [ i ] , Variant ( * p_args [ i ] ) ) ; <nl> + continue ; <nl> + } <nl> + <nl> + if ( ! argument_types [ i ] . is_type ( * p_args [ i ] , true ) ) { <nl> + r_err . error = Callable : : CallError : : CALL_ERROR_INVALID_ARGUMENT ; <nl> + r_err . argument = i ; <nl> + r_err . expected = argument_types [ i ] . kind = = GDScriptDataType : : BUILTIN ? argument_types [ i ] . builtin_type : Variant : : OBJECT ; <nl> + return Variant ( ) ; <nl> + } <nl> + if ( argument_types [ i ] . kind = = GDScriptDataType : : BUILTIN ) { <nl> + Variant arg ; <nl> + Variant : : construct ( argument_types [ i ] . builtin_type , arg , & p_args [ i ] , 1 , r_err ) ; <nl> + memnew_placement ( & stack [ i ] , Variant ( arg ) ) ; <nl> + } else { <nl> + memnew_placement ( & stack [ i ] , Variant ( * p_args [ i ] ) ) ; <nl> + } <nl> + } <nl> + for ( int i = p_argcount ; i < _stack_size ; i + + ) { <nl> + memnew_placement ( & stack [ i ] , Variant ) ; <nl> + } <nl> + } else { <nl> + stack = nullptr ; <nl> + } <nl> + <nl> + if ( _instruction_args_size ) { <nl> + instruction_args = ( Variant * * ) & aptr [ sizeof ( Variant ) * _stack_size ] ; <nl> + } else { <nl> + instruction_args = nullptr ; <nl> + } <nl> + <nl> + } else { <nl> + stack = nullptr ; <nl> + instruction_args = nullptr ; <nl> + } <nl> + <nl> + if ( p_instance ) { <nl> + if ( p_instance - > base_ref & & static_cast < Reference * > ( p_instance - > owner ) - > is_referenced ( ) ) { <nl> + self = REF ( static_cast < Reference * > ( p_instance - > owner ) ) ; <nl> + } else { <nl> + self = p_instance - > owner ; <nl> + } <nl> + script = p_instance - > script . ptr ( ) ; <nl> + } else { <nl> + script = _script ; <nl> + } <nl> + } <nl> + if ( _ptrcall_args_size ) { <nl> + call_args_ptr = ( const void * * ) alloca ( _ptrcall_args_size * sizeof ( void * ) ) ; <nl> + } else { <nl> + call_args_ptr = nullptr ; <nl> + } <nl> + <nl> + static_ref = script ; <nl> + <nl> + String err_text ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + <nl> + if ( EngineDebugger : : is_active ( ) ) { <nl> + GDScriptLanguage : : get_singleton ( ) - > enter_function ( p_instance , this , stack , & ip , & line ) ; <nl> + } <nl> + <nl> + # define GD_ERR_BREAK ( m_cond ) \ <nl> + { \ <nl> + if ( unlikely ( m_cond ) ) { \ <nl> + _err_print_error ( FUNCTION_STR , __FILE__ , __LINE__ , " Condition ' " _STR ( m_cond ) " ' is true . Breaking . . : " ) ; \ <nl> + OPCODE_BREAK ; \ <nl> + } \ <nl> + } <nl> + <nl> + # define CHECK_SPACE ( m_space ) \ <nl> + GD_ERR_BREAK ( ( ip + m_space ) > _code_size ) <nl> + <nl> + # define GET_VARIANT_PTR ( m_v , m_code_ofs ) \ <nl> + Variant * m_v ; \ <nl> + m_v = _get_variant ( _code_ptr [ ip + m_code_ofs ] , p_instance , script , self , static_ref , stack , err_text ) ; \ <nl> + if ( unlikely ( ! m_v ) ) \ <nl> + OPCODE_BREAK ; <nl> + <nl> + # else <nl> + # define GD_ERR_BREAK ( m_cond ) <nl> + # define CHECK_SPACE ( m_space ) <nl> + # define GET_VARIANT_PTR ( m_v , m_code_ofs ) \ <nl> + Variant * m_v ; \ <nl> + m_v = _get_variant ( _code_ptr [ ip + m_code_ofs ] , p_instance , script , self , static_ref , stack , err_text ) ; <nl> + <nl> + # endif <nl> + <nl> + # define GET_INSTRUCTION_ARG ( m_v , m_idx ) \ <nl> + Variant * m_v = instruction_args [ m_idx ] <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + <nl> + uint64_t function_start_time = 0 ; <nl> + uint64_t function_call_time = 0 ; <nl> + <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> + function_start_time = OS : : get_singleton ( ) - > get_ticks_usec ( ) ; <nl> + function_call_time = 0 ; <nl> + profile . call_count + + ; <nl> + profile . frame_call_count + + ; <nl> + } <nl> + bool exit_ok = false ; <nl> + bool awaited = false ; <nl> + # endif <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + OPCODE_WHILE ( ip < _code_size ) { <nl> + int last_opcode = _code_ptr [ ip ] ; <nl> + # else <nl> + OPCODE_WHILE ( true ) { <nl> + # endif <nl> + / / Load arguments for the instruction before each instruction . <nl> + int instr_arg_count = ( ( _code_ptr [ ip ] ) & INSTR_ARGS_MASK ) > > INSTR_BITS ; <nl> + for ( int i = 0 ; i < instr_arg_count ; i + + ) { <nl> + GET_VARIANT_PTR ( v , i + 1 ) ; <nl> + instruction_args [ i ] = v ; <nl> + } <nl> + <nl> + OPCODE_SWITCH ( _code_ptr [ ip ] & INSTR_MASK ) { <nl> + OPCODE ( OPCODE_OPERATOR ) { <nl> + CHECK_SPACE ( 5 ) ; <nl> + <nl> + bool valid ; <nl> + Variant : : Operator op = ( Variant : : Operator ) _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( op > = Variant : : OP_MAX ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( a , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( b , 1 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 2 ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + <nl> + Variant ret ; <nl> + Variant : : evaluate ( op , * a , * b , ret , valid ) ; <nl> + # else <nl> + Variant : : evaluate ( op , * a , * b , * dst , valid ) ; <nl> + # endif <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! valid ) { <nl> + if ( ret . get_type ( ) = = Variant : : STRING ) { <nl> + / / return a string when invalid with the error <nl> + err_text = ret ; <nl> + err_text + = " in operator ' " + Variant : : get_operator_name ( op ) + " ' . " ; <nl> + } else { <nl> + err_text = " Invalid operands ' " + Variant : : get_type_name ( a - > get_type ( ) ) + " ' and ' " + Variant : : get_type_name ( b - > get_type ( ) ) + " ' in operator ' " + Variant : : get_operator_name ( op ) + " ' . " ; <nl> + } <nl> + OPCODE_BREAK ; <nl> + } <nl> + * dst = ret ; <nl> + # endif <nl> + ip + = 5 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_OPERATOR_VALIDATED ) { <nl> + CHECK_SPACE ( 5 ) ; <nl> + <nl> + int operator_idx = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( operator_idx < 0 | | operator_idx > = _operator_funcs_count ) ; <nl> + Variant : : ValidatedOperatorEvaluator operator_func = _operator_funcs_ptr [ operator_idx ] ; <nl> + <nl> + GET_INSTRUCTION_ARG ( a , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( b , 1 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 2 ) ; <nl> + <nl> + operator_func ( a , b , dst ) ; <nl> + <nl> + ip + = 5 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_EXTENDS_TEST ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( a , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( b , 1 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 2 ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( b - > get_type ( ) ! = Variant : : OBJECT | | b - > operator Object * ( ) = = nullptr ) { <nl> + err_text = " Right operand of ' is ' is not a class . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + <nl> + bool extends_ok = false ; <nl> + if ( a - > get_type ( ) = = Variant : : OBJECT & & a - > operator Object * ( ) ! = nullptr ) { <nl> + # ifdef DEBUG_ENABLED <nl> + bool was_freed ; <nl> + Object * obj_A = a - > get_validated_object_with_check ( was_freed ) ; <nl> + <nl> + if ( was_freed ) { <nl> + err_text = " Left operand of ' is ' is a previously freed instance . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + <nl> + Object * obj_B = b - > get_validated_object_with_check ( was_freed ) ; <nl> + <nl> + if ( was_freed ) { <nl> + err_text = " Right operand of ' is ' is a previously freed instance . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # else <nl> + <nl> + Object * obj_A = * a ; <nl> + Object * obj_B = * b ; <nl> + # endif / / DEBUG_ENABLED <nl> + <nl> + GDScript * scr_B = Object : : cast_to < GDScript > ( obj_B ) ; <nl> + <nl> + if ( scr_B ) { <nl> + / / if B is a script , the only valid condition is that A has an instance which inherits from the script <nl> + / / in other situation , this shoul return false . <nl> + <nl> + if ( obj_A - > get_script_instance ( ) & & obj_A - > get_script_instance ( ) - > get_language ( ) = = GDScriptLanguage : : get_singleton ( ) ) { <nl> + GDScript * cmp = static_cast < GDScript * > ( obj_A - > get_script_instance ( ) - > get_script ( ) . ptr ( ) ) ; <nl> + / / bool found = false ; <nl> + while ( cmp ) { <nl> + if ( cmp = = scr_B ) { <nl> + / / inherits from script , all ok <nl> + extends_ok = true ; <nl> + break ; <nl> + } <nl> + <nl> + cmp = cmp - > _base ; <nl> + } <nl> + } <nl> + <nl> + } else { <nl> + GDScriptNativeClass * nc = Object : : cast_to < GDScriptNativeClass > ( obj_B ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! nc ) { <nl> + err_text = " Right operand of ' is ' is not a class ( type : ' " + obj_B - > get_class ( ) + " ' ) . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + extends_ok = ClassDB : : is_parent_class ( obj_A - > get_class_name ( ) , nc - > get_name ( ) ) ; <nl> + } <nl> + } <nl> + <nl> + * dst = extends_ok ; <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_IS_BUILTIN ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( value , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 1 ) ; <nl> + Variant : : Type var_type = ( Variant : : Type ) _code_ptr [ ip + 3 ] ; <nl> + <nl> + GD_ERR_BREAK ( var_type < 0 | | var_type > = Variant : : VARIANT_MAX ) ; <nl> + <nl> + * dst = value - > get_type ( ) = = var_type ; <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_SET_KEYED ) { <nl> + CHECK_SPACE ( 3 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( dst , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( index , 1 ) ; <nl> + GET_INSTRUCTION_ARG ( value , 2 ) ; <nl> + <nl> + bool valid ; <nl> + dst - > set ( * index , * value , & valid ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! valid ) { <nl> + String v = index - > operator String ( ) ; <nl> + if ( v ! = " " ) { <nl> + v = " ' " + v + " ' " ; <nl> + } else { <nl> + v = " of type ' " + _get_var_type ( index ) + " ' " ; <nl> + } <nl> + err_text = " Invalid set index " + v + " ( on base : ' " + _get_var_type ( dst ) + " ' ) with value of type ' " + _get_var_type ( value ) + " ' " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_SET_KEYED_VALIDATED ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( dst , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( index , 1 ) ; <nl> + GET_INSTRUCTION_ARG ( value , 2 ) ; <nl> + <nl> + int index_setter = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( index_setter < 0 | | index_setter > = _keyed_setters_count ) ; <nl> + const Variant : : ValidatedKeyedSetter setter = _keyed_setters_ptr [ index_setter ] ; <nl> + <nl> + bool valid ; <nl> + setter ( dst , index , value , valid ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! valid ) { <nl> + String v = index - > operator String ( ) ; <nl> + if ( v ! = " " ) { <nl> + v = " ' " + v + " ' " ; <nl> + } else { <nl> + v = " of type ' " + _get_var_type ( index ) + " ' " ; <nl> + } <nl> + err_text = " Invalid set index " + v + " ( on base : ' " + _get_var_type ( dst ) + " ' ) with value of type ' " + _get_var_type ( value ) + " ' " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + ip + = 5 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_SET_INDEXED_VALIDATED ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( dst , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( index , 1 ) ; <nl> + GET_INSTRUCTION_ARG ( value , 2 ) ; <nl> + <nl> + int index_setter = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( index_setter < 0 | | index_setter > = _indexed_setters_count ) ; <nl> + const Variant : : ValidatedIndexedSetter setter = _indexed_setters_ptr [ index_setter ] ; <nl> + <nl> + int64_t int_index = * VariantInternal : : get_int ( index ) ; <nl> + <nl> + bool oob ; <nl> + setter ( dst , int_index , value , oob ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( oob ) { <nl> + String v = index - > operator String ( ) ; <nl> + if ( v ! = " " ) { <nl> + v = " ' " + v + " ' " ; <nl> + } else { <nl> + v = " of type ' " + _get_var_type ( index ) + " ' " ; <nl> + } <nl> + err_text = " Out of bounds set index " + v + " ( on base : ' " + _get_var_type ( dst ) + " ' ) " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + ip + = 5 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_GET_KEYED ) { <nl> + CHECK_SPACE ( 3 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( src , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( index , 1 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 2 ) ; <nl> + <nl> + bool valid ; <nl> + # ifdef DEBUG_ENABLED <nl> + / / Allow better error message in cases where src and dst are the same stack position . <nl> + Variant ret = src - > get ( * index , & valid ) ; <nl> + # else <nl> + * dst = src - > get ( * index , & valid ) ; <nl> + <nl> + # endif <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! valid ) { <nl> + String v = index - > operator String ( ) ; <nl> + if ( v ! = " " ) { <nl> + v = " ' " + v + " ' " ; <nl> + } else { <nl> + v = " of type ' " + _get_var_type ( index ) + " ' " ; <nl> + } <nl> + err_text = " Invalid get index " + v + " ( on base : ' " + _get_var_type ( src ) + " ' ) . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + * dst = ret ; <nl> + # endif <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_GET_KEYED_VALIDATED ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( src , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( key , 1 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 2 ) ; <nl> + <nl> + int index_getter = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( index_getter < 0 | | index_getter > = _keyed_getters_count ) ; <nl> + const Variant : : ValidatedKeyedGetter getter = _keyed_getters_ptr [ index_getter ] ; <nl> + <nl> + bool valid ; <nl> + # ifdef DEBUG_ENABLED <nl> + / / Allow better error message in cases where src and dst are the same stack position . <nl> + Variant ret ; <nl> + getter ( src , key , & ret , valid ) ; <nl> + # else <nl> + getter ( src , key , dst , valid ) ; <nl> + # endif <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! valid ) { <nl> + String v = key - > operator String ( ) ; <nl> + if ( v ! = " " ) { <nl> + v = " ' " + v + " ' " ; <nl> + } else { <nl> + v = " of type ' " + _get_var_type ( key ) + " ' " ; <nl> + } <nl> + err_text = " Invalid get index " + v + " ( on base : ' " + _get_var_type ( src ) + " ' ) . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + * dst = ret ; <nl> + # endif <nl> + ip + = 5 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_GET_INDEXED_VALIDATED ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( src , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( index , 1 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 2 ) ; <nl> + <nl> + int index_getter = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( index_getter < 0 | | index_getter > = _indexed_getters_count ) ; <nl> + const Variant : : ValidatedIndexedGetter getter = _indexed_getters_ptr [ index_getter ] ; <nl> + <nl> + int64_t int_index = * VariantInternal : : get_int ( index ) ; <nl> + <nl> + bool oob ; <nl> + getter ( src , int_index , dst , oob ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( oob ) { <nl> + String v = index - > operator String ( ) ; <nl> + if ( v ! = " " ) { <nl> + v = " ' " + v + " ' " ; <nl> + } else { <nl> + v = " of type ' " + _get_var_type ( index ) + " ' " ; <nl> + } <nl> + err_text = " Out of bounds get index " + v + " ( on base : ' " + _get_var_type ( src ) + " ' ) " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + ip + = 5 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_SET_NAMED ) { <nl> + CHECK_SPACE ( 3 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( dst , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( value , 1 ) ; <nl> + <nl> + int indexname = _code_ptr [ ip + 3 ] ; <nl> + <nl> + GD_ERR_BREAK ( indexname < 0 | | indexname > = _global_names_count ) ; <nl> + const StringName * index = & _global_names_ptr [ indexname ] ; <nl> + <nl> + bool valid ; <nl> + dst - > set_named ( * index , * value , valid ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! valid ) { <nl> + String err_type ; <nl> + err_text = " Invalid set index ' " + String ( * index ) + " ' ( on base : ' " + _get_var_type ( dst ) + " ' ) with value of type ' " + _get_var_type ( value ) + " ' . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_SET_NAMED_VALIDATED ) { <nl> + CHECK_SPACE ( 3 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( dst , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( value , 1 ) ; <nl> + <nl> + int index_setter = _code_ptr [ ip + 3 ] ; <nl> + GD_ERR_BREAK ( index_setter < 0 | | index_setter > = _setters_count ) ; <nl> + const Variant : : ValidatedSetter setter = _setters_ptr [ index_setter ] ; <nl> + <nl> + setter ( dst , value ) ; <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_GET_NAMED ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( src , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 1 ) ; <nl> + <nl> + int indexname = _code_ptr [ ip + 3 ] ; <nl> + <nl> + GD_ERR_BREAK ( indexname < 0 | | indexname > = _global_names_count ) ; <nl> + const StringName * index = & _global_names_ptr [ indexname ] ; <nl> + <nl> + bool valid ; <nl> + # ifdef DEBUG_ENABLED <nl> + / / allow better error message in cases where src and dst are the same stack position <nl> + Variant ret = src - > get_named ( * index , valid ) ; <nl> + <nl> + # else <nl> + * dst = src - > get_named ( * index , valid ) ; <nl> + # endif <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! valid ) { <nl> + if ( src - > has_method ( * index ) ) { <nl> + err_text = " Invalid get index ' " + index - > operator String ( ) + " ' ( on base : ' " + _get_var_type ( src ) + " ' ) . Did you mean ' . " + index - > operator String ( ) + " ( ) ' or funcref ( obj , \ " " + index - > operator String ( ) + " \ " ) ? " ; <nl> + } else { <nl> + err_text = " Invalid get index ' " + index - > operator String ( ) + " ' ( on base : ' " + _get_var_type ( src ) + " ' ) . " ; <nl> + } <nl> + OPCODE_BREAK ; <nl> + } <nl> + * dst = ret ; <nl> + # endif <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_GET_NAMED_VALIDATED ) { <nl> + CHECK_SPACE ( 3 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( src , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 1 ) ; <nl> + <nl> + int index_getter = _code_ptr [ ip + 3 ] ; <nl> + GD_ERR_BREAK ( index_getter < 0 | | index_getter > = _getters_count ) ; <nl> + const Variant : : ValidatedGetter getter = _getters_ptr [ index_getter ] ; <nl> + <nl> + getter ( src , dst ) ; <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_SET_MEMBER ) { <nl> + CHECK_SPACE ( 3 ) ; <nl> + GET_INSTRUCTION_ARG ( src , 0 ) ; <nl> + int indexname = _code_ptr [ ip + 2 ] ; <nl> + GD_ERR_BREAK ( indexname < 0 | | indexname > = _global_names_count ) ; <nl> + const StringName * index = & _global_names_ptr [ indexname ] ; <nl> + <nl> + bool valid ; <nl> + # ifndef DEBUG_ENABLED <nl> + ClassDB : : set_property ( p_instance - > owner , * index , * src , & valid ) ; <nl> + # else <nl> + bool ok = ClassDB : : set_property ( p_instance - > owner , * index , * src , & valid ) ; <nl> + if ( ! ok ) { <nl> + err_text = " Internal error setting property : " + String ( * index ) ; <nl> + OPCODE_BREAK ; <nl> + } else if ( ! valid ) { <nl> + err_text = " Error setting property ' " + String ( * index ) + " ' with value of type " + Variant : : get_type_name ( src - > get_type ( ) ) + " . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_GET_MEMBER ) { <nl> + CHECK_SPACE ( 3 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 0 ) ; <nl> + int indexname = _code_ptr [ ip + 2 ] ; <nl> + GD_ERR_BREAK ( indexname < 0 | | indexname > = _global_names_count ) ; <nl> + const StringName * index = & _global_names_ptr [ indexname ] ; <nl> + # ifndef DEBUG_ENABLED <nl> + ClassDB : : get_property ( p_instance - > owner , * index , * dst ) ; <nl> + # else <nl> + bool ok = ClassDB : : get_property ( p_instance - > owner , * index , * dst ) ; <nl> + if ( ! ok ) { <nl> + err_text = " Internal error getting property : " + String ( * index ) ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ASSIGN ) { <nl> + CHECK_SPACE ( 3 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( src , 1 ) ; <nl> + <nl> + * dst = * src ; <nl> + <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ASSIGN_TRUE ) { <nl> + CHECK_SPACE ( 2 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 0 ) ; <nl> + <nl> + * dst = true ; <nl> + <nl> + ip + = 2 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ASSIGN_FALSE ) { <nl> + CHECK_SPACE ( 2 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 0 ) ; <nl> + <nl> + * dst = false ; <nl> + <nl> + ip + = 2 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ASSIGN_TYPED_BUILTIN ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( src , 1 ) ; <nl> + <nl> + Variant : : Type var_type = ( Variant : : Type ) _code_ptr [ ip + 3 ] ; <nl> + GD_ERR_BREAK ( var_type < 0 | | var_type > = Variant : : VARIANT_MAX ) ; <nl> + <nl> + if ( src - > get_type ( ) ! = var_type ) { <nl> + # ifdef DEBUG_ENABLED <nl> + if ( Variant : : can_convert_strict ( src - > get_type ( ) , var_type ) ) { <nl> + # endif / / DEBUG_ENABLED <nl> + Callable : : CallError ce ; <nl> + Variant : : construct ( var_type , * dst , const_cast < const Variant * * > ( & src ) , 1 , ce ) ; <nl> + } else { <nl> + # ifdef DEBUG_ENABLED <nl> + err_text = " Trying to assign value of type ' " + Variant : : get_type_name ( src - > get_type ( ) ) + <nl> + " ' to a variable of type ' " + Variant : : get_type_name ( var_type ) + " ' . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + } else { <nl> + # endif / / DEBUG_ENABLED <nl> + * dst = * src ; <nl> + } <nl> + <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ASSIGN_TYPED_NATIVE ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( src , 1 ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + GET_INSTRUCTION_ARG ( type , 2 ) ; <nl> + GDScriptNativeClass * nc = Object : : cast_to < GDScriptNativeClass > ( type - > operator Object * ( ) ) ; <nl> + GD_ERR_BREAK ( ! nc ) ; <nl> + if ( src - > get_type ( ) ! = Variant : : OBJECT & & src - > get_type ( ) ! = Variant : : NIL ) { <nl> + err_text = " Trying to assign value of type ' " + Variant : : get_type_name ( src - > get_type ( ) ) + <nl> + " ' to a variable of type ' " + nc - > get_name ( ) + " ' . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + Object * src_obj = src - > operator Object * ( ) ; <nl> + <nl> + if ( src_obj & & ! ClassDB : : is_parent_class ( src_obj - > get_class_name ( ) , nc - > get_name ( ) ) ) { <nl> + err_text = " Trying to assign value of type ' " + src_obj - > get_class_name ( ) + <nl> + " ' to a variable of type ' " + nc - > get_name ( ) + " ' . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif / / DEBUG_ENABLED <nl> + * dst = * src ; <nl> + <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ASSIGN_TYPED_SCRIPT ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( src , 1 ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + GET_INSTRUCTION_ARG ( type , 2 ) ; <nl> + Script * base_type = Object : : cast_to < Script > ( type - > operator Object * ( ) ) ; <nl> + <nl> + GD_ERR_BREAK ( ! base_type ) ; <nl> + <nl> + if ( src - > get_type ( ) ! = Variant : : OBJECT & & src - > get_type ( ) ! = Variant : : NIL ) { <nl> + err_text = " Trying to assign a non - object value to a variable of type ' " + base_type - > get_path ( ) . get_file ( ) + " ' . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + <nl> + if ( src - > get_type ( ) ! = Variant : : NIL & & src - > operator Object * ( ) ! = nullptr ) { <nl> + ScriptInstance * scr_inst = src - > operator Object * ( ) - > get_script_instance ( ) ; <nl> + if ( ! scr_inst ) { <nl> + err_text = " Trying to assign value of type ' " + src - > operator Object * ( ) - > get_class_name ( ) + <nl> + " ' to a variable of type ' " + base_type - > get_path ( ) . get_file ( ) + " ' . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + <nl> + Script * src_type = src - > operator Object * ( ) - > get_script_instance ( ) - > get_script ( ) . ptr ( ) ; <nl> + bool valid = false ; <nl> + <nl> + while ( src_type ) { <nl> + if ( src_type = = base_type ) { <nl> + valid = true ; <nl> + break ; <nl> + } <nl> + src_type = src_type - > get_base_script ( ) . ptr ( ) ; <nl> + } <nl> + <nl> + if ( ! valid ) { <nl> + err_text = " Trying to assign value of type ' " + src - > operator Object * ( ) - > get_script_instance ( ) - > get_script ( ) - > get_path ( ) . get_file ( ) + <nl> + " ' to a variable of type ' " + base_type - > get_path ( ) . get_file ( ) + " ' . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + } <nl> + # endif / / DEBUG_ENABLED <nl> + <nl> + * dst = * src ; <nl> + <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_CAST_TO_BUILTIN ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + GET_INSTRUCTION_ARG ( src , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 1 ) ; <nl> + Variant : : Type to_type = ( Variant : : Type ) _code_ptr [ ip + 3 ] ; <nl> + <nl> + GD_ERR_BREAK ( to_type < 0 | | to_type > = Variant : : VARIANT_MAX ) ; <nl> + <nl> + Callable : : CallError err ; <nl> + Variant : : construct ( to_type , * dst , ( const Variant * * ) & src , 1 , err ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( err . error ! = Callable : : CallError : : CALL_OK ) { <nl> + err_text = " Invalid cast : could not convert value to ' " + Variant : : get_type_name ( to_type ) + " ' . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_CAST_TO_NATIVE ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + GET_INSTRUCTION_ARG ( src , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 1 ) ; <nl> + GET_INSTRUCTION_ARG ( to_type , 2 ) ; <nl> + <nl> + GDScriptNativeClass * nc = Object : : cast_to < GDScriptNativeClass > ( to_type - > operator Object * ( ) ) ; <nl> + GD_ERR_BREAK ( ! nc ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( src - > get_type ( ) ! = Variant : : OBJECT & & src - > get_type ( ) ! = Variant : : NIL ) { <nl> + err_text = " Invalid cast : can ' t convert a non - object value to an object type . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + Object * src_obj = src - > operator Object * ( ) ; <nl> + <nl> + if ( src_obj & & ! ClassDB : : is_parent_class ( src_obj - > get_class_name ( ) , nc - > get_name ( ) ) ) { <nl> + * dst = Variant ( ) ; / / invalid cast , assign NULL <nl> + } else { <nl> + * dst = * src ; <nl> + } <nl> + <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_CAST_TO_SCRIPT ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + GET_INSTRUCTION_ARG ( src , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( dst , 1 ) ; <nl> + GET_INSTRUCTION_ARG ( to_type , 2 ) ; <nl> + <nl> + Script * base_type = Object : : cast_to < Script > ( to_type - > operator Object * ( ) ) ; <nl> + <nl> + GD_ERR_BREAK ( ! base_type ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( src - > get_type ( ) ! = Variant : : OBJECT & & src - > get_type ( ) ! = Variant : : NIL ) { <nl> + err_text = " Trying to assign a non - object value to a variable of type ' " + base_type - > get_path ( ) . get_file ( ) + " ' . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + <nl> + bool valid = false ; <nl> + <nl> + if ( src - > get_type ( ) ! = Variant : : NIL & & src - > operator Object * ( ) ! = nullptr ) { <nl> + ScriptInstance * scr_inst = src - > operator Object * ( ) - > get_script_instance ( ) ; <nl> + <nl> + if ( scr_inst ) { <nl> + Script * src_type = src - > operator Object * ( ) - > get_script_instance ( ) - > get_script ( ) . ptr ( ) ; <nl> + <nl> + while ( src_type ) { <nl> + if ( src_type = = base_type ) { <nl> + valid = true ; <nl> + break ; <nl> + } <nl> + src_type = src_type - > get_base_script ( ) . ptr ( ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + if ( valid ) { <nl> + * dst = * src ; / / Valid cast , copy the source object <nl> + } else { <nl> + * dst = Variant ( ) ; / / invalid cast , assign NULL <nl> + } <nl> + <nl> + ip + = 4 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_CONSTRUCT ) { <nl> + CHECK_SPACE ( 2 + instr_arg_count ) ; <nl> + <nl> + ip + = instr_arg_count ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 ] ; <nl> + <nl> + Variant : : Type t = Variant : : Type ( _code_ptr [ ip + 2 ] ) ; <nl> + Variant * * argptrs = instruction_args ; <nl> + <nl> + GET_INSTRUCTION_ARG ( dst , argc ) ; <nl> + <nl> + Callable : : CallError err ; <nl> + Variant : : construct ( t , * dst , ( const Variant * * ) argptrs , argc , err ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( err . error ! = Callable : : CallError : : CALL_OK ) { <nl> + err_text = _get_call_error ( err , " ' " + Variant : : get_type_name ( t ) + " ' constructor " , ( const Variant * * ) argptrs ) ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_CONSTRUCT_VALIDATED ) { <nl> + CHECK_SPACE ( 2 + instr_arg_count ) ; <nl> + <nl> + ip + = instr_arg_count ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 ] ; <nl> + <nl> + int constructor_idx = _code_ptr [ ip + 2 ] ; <nl> + GD_ERR_BREAK ( constructor_idx < 0 | | constructor_idx > = _constructors_count ) ; <nl> + Variant : : ValidatedConstructor constructor = _constructors_ptr [ constructor_idx ] ; <nl> + <nl> + Variant * * argptrs = instruction_args ; <nl> + <nl> + GET_INSTRUCTION_ARG ( dst , argc ) ; <nl> + <nl> + constructor ( * dst , ( const Variant * * ) argptrs ) ; <nl> + <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_CONSTRUCT_ARRAY ) { <nl> + CHECK_SPACE ( 1 + instr_arg_count ) ; <nl> + ip + = instr_arg_count ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 ] ; <nl> + Array array ; <nl> + array . resize ( argc ) ; <nl> + <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + array [ i ] = * ( instruction_args [ i ] ) ; <nl> + } <nl> + <nl> + GET_INSTRUCTION_ARG ( dst , argc ) ; <nl> + <nl> + * dst = array ; <nl> + <nl> + ip + = 2 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_CONSTRUCT_DICTIONARY ) { <nl> + CHECK_SPACE ( 2 + instr_arg_count ) ; <nl> + <nl> + ip + = instr_arg_count ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 ] ; <nl> + Dictionary dict ; <nl> + <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + GET_INSTRUCTION_ARG ( k , i * 2 + 0 ) ; <nl> + GET_INSTRUCTION_ARG ( v , i * 2 + 1 ) ; <nl> + dict [ * k ] = * v ; <nl> + } <nl> + <nl> + GET_INSTRUCTION_ARG ( dst , argc * 2 ) ; <nl> + <nl> + * dst = dict ; <nl> + <nl> + ip + = 2 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_CALL_ASYNC ) <nl> + OPCODE ( OPCODE_CALL_RETURN ) <nl> + OPCODE ( OPCODE_CALL ) { <nl> + CHECK_SPACE ( 3 + instr_arg_count ) ; <nl> + bool call_ret = ( _code_ptr [ ip ] & INSTR_MASK ) ! = OPCODE_CALL ; <nl> + # ifdef DEBUG_ENABLED <nl> + bool call_async = ( _code_ptr [ ip ] & INSTR_MASK ) = = OPCODE_CALL_ASYNC ; <nl> + # endif <nl> + <nl> + ip + = instr_arg_count ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 ] ; <nl> + GD_ERR_BREAK ( argc < 0 ) ; <nl> + <nl> + int methodname_idx = _code_ptr [ ip + 2 ] ; <nl> + GD_ERR_BREAK ( methodname_idx < 0 | | methodname_idx > = _global_names_count ) ; <nl> + const StringName * methodname = & _global_names_ptr [ methodname_idx ] ; <nl> + <nl> + GET_INSTRUCTION_ARG ( base , argc ) ; <nl> + Variant * * argptrs = instruction_args ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + uint64_t call_time = 0 ; <nl> + <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> + call_time = OS : : get_singleton ( ) - > get_ticks_usec ( ) ; <nl> + } <nl> + <nl> + # endif <nl> + Callable : : CallError err ; <nl> + if ( call_ret ) { <nl> + GET_INSTRUCTION_ARG ( ret , argc + 1 ) ; <nl> + base - > call ( * methodname , ( const Variant * * ) argptrs , argc , * ret , err ) ; <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! call_async & & ret - > get_type ( ) = = Variant : : OBJECT ) { <nl> + / / Check if getting a function state without await . <nl> + bool was_freed = false ; <nl> + Object * obj = ret - > get_validated_object_with_check ( was_freed ) ; <nl> + <nl> + if ( was_freed ) { <nl> + err_text = " Got a freed object as a result of the call . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + if ( obj & & obj - > is_class_ptr ( GDScriptFunctionState : : get_class_ptr_static ( ) ) ) { <nl> + err_text = R " ( Trying to call an async function without " await " . ) " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + } <nl> + # endif <nl> + } else { <nl> + Variant ret ; <nl> + base - > call ( * methodname , ( const Variant * * ) argptrs , argc , ret , err ) ; <nl> + } <nl> + # ifdef DEBUG_ENABLED <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> + function_call_time + = OS : : get_singleton ( ) - > get_ticks_usec ( ) - call_time ; <nl> + } <nl> + <nl> + if ( err . error ! = Callable : : CallError : : CALL_OK ) { <nl> + String methodstr = * methodname ; <nl> + String basestr = _get_var_type ( base ) ; <nl> + <nl> + if ( methodstr = = " call " ) { <nl> + if ( argc > = 1 ) { <nl> + methodstr = String ( * argptrs [ 0 ] ) + " ( via call ) " ; <nl> + if ( err . error = = Callable : : CallError : : CALL_ERROR_INVALID_ARGUMENT ) { <nl> + err . argument + = 1 ; <nl> + } <nl> + } <nl> + } else if ( methodstr = = " free " ) { <nl> + if ( err . error = = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ) { <nl> + if ( base - > is_ref ( ) ) { <nl> + err_text = " Attempted to free a reference . " ; <nl> + OPCODE_BREAK ; <nl> + } else if ( base - > get_type ( ) = = Variant : : OBJECT ) { <nl> + err_text = " Attempted to free a locked object ( calling or emitting ) . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + } <nl> + } else if ( methodstr = = " call_recursive " & & basestr = = " TreeItem " ) { <nl> + if ( argc > = 1 ) { <nl> + methodstr = String ( * argptrs [ 0 ] ) + " ( via TreeItem . call_recursive ) " ; <nl> + if ( err . error = = Callable : : CallError : : CALL_ERROR_INVALID_ARGUMENT ) { <nl> + err . argument + = 1 ; <nl> + } <nl> + } <nl> + } <nl> + err_text = _get_call_error ( err , " function ' " + methodstr + " ' in base ' " + basestr + " ' " , ( const Variant * * ) argptrs ) ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_CALL_METHOD_BIND ) <nl> + OPCODE ( OPCODE_CALL_METHOD_BIND_RET ) { <nl> + CHECK_SPACE ( 3 + instr_arg_count ) ; <nl> + bool call_ret = ( _code_ptr [ ip ] & INSTR_MASK ) = = OPCODE_CALL_METHOD_BIND_RET ; <nl> + <nl> + ip + = instr_arg_count ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 ] ; <nl> + GD_ERR_BREAK ( argc < 0 ) ; <nl> + GD_ERR_BREAK ( _code_ptr [ ip + 2 ] < 0 | | _code_ptr [ ip + 2 ] > = _methods_count ) ; <nl> + MethodBind * method = _methods_ptr [ _code_ptr [ ip + 2 ] ] ; <nl> + <nl> + GET_INSTRUCTION_ARG ( base , argc ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + bool freed = false ; <nl> + Object * base_obj = base - > get_validated_object_with_check ( freed ) ; <nl> + if ( freed ) { <nl> + err_text = " Trying to call a function on a previously freed instance . " ; <nl> + OPCODE_BREAK ; <nl> + } else if ( ! base_obj ) { <nl> + err_text = " Trying to call a function on a null value . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # else <nl> + Object * base_obj = base - > operator Object * ( ) ; <nl> + # endif <nl> + Variant * * argptrs = instruction_args ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + uint64_t call_time = 0 ; <nl> + <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> + call_time = OS : : get_singleton ( ) - > get_ticks_usec ( ) ; <nl> + } <nl> + # endif <nl> + <nl> + Callable : : CallError err ; <nl> + if ( call_ret ) { <nl> + GET_INSTRUCTION_ARG ( ret , argc + 1 ) ; <nl> + * ret = method - > call ( base_obj , ( const Variant * * ) argptrs , argc , err ) ; <nl> + } else { <nl> + method - > call ( base_obj , ( const Variant * * ) argptrs , argc , err ) ; <nl> + } <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> + function_call_time + = OS : : get_singleton ( ) - > get_ticks_usec ( ) - call_time ; <nl> + } <nl> + <nl> + if ( err . error ! = Callable : : CallError : : CALL_OK ) { <nl> + String methodstr = method - > get_name ( ) ; <nl> + String basestr = _get_var_type ( base ) ; <nl> + <nl> + if ( methodstr = = " call " ) { <nl> + if ( argc > = 1 ) { <nl> + methodstr = String ( * argptrs [ 0 ] ) + " ( via call ) " ; <nl> + if ( err . error = = Callable : : CallError : : CALL_ERROR_INVALID_ARGUMENT ) { <nl> + err . argument + = 1 ; <nl> + } <nl> + } <nl> + } else if ( methodstr = = " free " ) { <nl> + if ( err . error = = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ) { <nl> + if ( base - > is_ref ( ) ) { <nl> + err_text = " Attempted to free a reference . " ; <nl> + OPCODE_BREAK ; <nl> + } else if ( base - > get_type ( ) = = Variant : : OBJECT ) { <nl> + err_text = " Attempted to free a locked object ( calling or emitting ) . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + } <nl> + } <nl> + err_text = _get_call_error ( err , " function ' " + methodstr + " ' in base ' " + basestr + " ' " , ( const Variant * * ) argptrs ) ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + # define OPCODE_CALL_PTR ( m_type ) \ <nl> + OPCODE ( OPCODE_CALL_PTRCALL_ # # m_type ) { \ <nl> + CHECK_SPACE ( 3 + instr_arg_count ) ; \ <nl> + ip + = instr_arg_count ; \ <nl> + int argc = _code_ptr [ ip + 1 ] ; \ <nl> + GD_ERR_BREAK ( argc < 0 ) ; \ <nl> + GET_INSTRUCTION_ARG ( base , argc ) ; \ <nl> + GD_ERR_BREAK ( _code_ptr [ ip + 2 ] < 0 | | _code_ptr [ ip + 2 ] > = _methods_count ) ; \ <nl> + MethodBind * method = _methods_ptr [ _code_ptr [ ip + 2 ] ] ; \ <nl> + bool freed = false ; \ <nl> + Object * base_obj = base - > get_validated_object_with_check ( freed ) ; \ <nl> + if ( freed ) { \ <nl> + err_text = " Trying to call a function on a previously freed instance . " ; \ <nl> + OPCODE_BREAK ; \ <nl> + } else if ( ! base_obj ) { \ <nl> + err_text = " Trying to call a function on a null value . " ; \ <nl> + OPCODE_BREAK ; \ <nl> + } \ <nl> + const void * * argptrs = call_args_ptr ; \ <nl> + for ( int i = 0 ; i < argc ; i + + ) { \ <nl> + GET_INSTRUCTION_ARG ( v , i ) ; \ <nl> + argptrs [ i ] = VariantInternal : : get_opaque_pointer ( ( const Variant * ) v ) ; \ <nl> + } \ <nl> + uint64_t call_time = 0 ; \ <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { \ <nl> + call_time = OS : : get_singleton ( ) - > get_ticks_usec ( ) ; \ <nl> + } \ <nl> + GET_INSTRUCTION_ARG ( ret , argc + 1 ) ; \ <nl> + VariantInternal : : initialize ( ret , Variant : : m_type ) ; \ <nl> + void * ret_opaque = VariantInternal : : OP_GET_ # # m_type ( ret ) ; \ <nl> + method - > ptrcall ( base_obj , argptrs , ret_opaque ) ; \ <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { \ <nl> + function_call_time + = OS : : get_singleton ( ) - > get_ticks_usec ( ) - call_time ; \ <nl> + } \ <nl> + ip + = 3 ; \ <nl> + } \ <nl> + DISPATCH_OPCODE <nl> + # else <nl> + # define OPCODE_CALL_PTR ( m_type ) \ <nl> + OPCODE ( OPCODE_CALL_PTRCALL_ # # m_type ) { \ <nl> + CHECK_SPACE ( 3 + instr_arg_count ) ; \ <nl> + int argc = _code_ptr [ ip + 1 ] ; \ <nl> + GET_INSTRUCTION_ARG ( base , argc ) ; \ <nl> + MethodBind * method = _methods_ptr [ _code_ptr [ ip + 2 ] ] ; \ <nl> + Object * base_obj = * VariantInternal : : get_object ( base ) ; \ <nl> + const void * * argptrs = call_args_ptr ; \ <nl> + for ( int i = 0 ; i < argc ; i + + ) { \ <nl> + GET_INSTRUCTION_ARG ( v , i ) ; \ <nl> + argptrs [ i ] = VariantInternal : : get_opaque_pointer ( ( const Variant * ) v ) ; \ <nl> + } \ <nl> + GET_INSTRUCTION_ARG ( ret , argc + 1 ) ; \ <nl> + VariantInternal : : initialize ( ret , Variant : : m_type ) ; \ <nl> + void * ret_opaque = VariantInternal : : OP_GET_ # # m_type ( ret ) ; \ <nl> + method - > ptrcall ( base_obj , argptrs , ret_opaque ) ; \ <nl> + ip + = 3 ; \ <nl> + } \ <nl> + DISPATCH_OPCODE <nl> + # endif <nl> + <nl> + OPCODE_CALL_PTR ( BOOL ) ; <nl> + OPCODE_CALL_PTR ( INT ) ; <nl> + OPCODE_CALL_PTR ( FLOAT ) ; <nl> + OPCODE_CALL_PTR ( STRING ) ; <nl> + OPCODE_CALL_PTR ( VECTOR2 ) ; <nl> + OPCODE_CALL_PTR ( VECTOR2I ) ; <nl> + OPCODE_CALL_PTR ( RECT2 ) ; <nl> + OPCODE_CALL_PTR ( RECT2I ) ; <nl> + OPCODE_CALL_PTR ( VECTOR3 ) ; <nl> + OPCODE_CALL_PTR ( VECTOR3I ) ; <nl> + OPCODE_CALL_PTR ( TRANSFORM2D ) ; <nl> + OPCODE_CALL_PTR ( PLANE ) ; <nl> + OPCODE_CALL_PTR ( QUAT ) ; <nl> + OPCODE_CALL_PTR ( AABB ) ; <nl> + OPCODE_CALL_PTR ( BASIS ) ; <nl> + OPCODE_CALL_PTR ( TRANSFORM ) ; <nl> + OPCODE_CALL_PTR ( COLOR ) ; <nl> + OPCODE_CALL_PTR ( STRING_NAME ) ; <nl> + OPCODE_CALL_PTR ( NODE_PATH ) ; <nl> + OPCODE_CALL_PTR ( RID ) ; <nl> + OPCODE_CALL_PTR ( CALLABLE ) ; <nl> + OPCODE_CALL_PTR ( SIGNAL ) ; <nl> + OPCODE_CALL_PTR ( DICTIONARY ) ; <nl> + OPCODE_CALL_PTR ( ARRAY ) ; <nl> + OPCODE_CALL_PTR ( PACKED_BYTE_ARRAY ) ; <nl> + OPCODE_CALL_PTR ( PACKED_INT32_ARRAY ) ; <nl> + OPCODE_CALL_PTR ( PACKED_INT64_ARRAY ) ; <nl> + OPCODE_CALL_PTR ( PACKED_FLOAT32_ARRAY ) ; <nl> + OPCODE_CALL_PTR ( PACKED_FLOAT64_ARRAY ) ; <nl> + OPCODE_CALL_PTR ( PACKED_STRING_ARRAY ) ; <nl> + OPCODE_CALL_PTR ( PACKED_VECTOR2_ARRAY ) ; <nl> + OPCODE_CALL_PTR ( PACKED_VECTOR3_ARRAY ) ; <nl> + OPCODE_CALL_PTR ( PACKED_COLOR_ARRAY ) ; <nl> + OPCODE ( OPCODE_CALL_PTRCALL_OBJECT ) { <nl> + CHECK_SPACE ( 3 + instr_arg_count ) ; <nl> + <nl> + ip + = instr_arg_count ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 ] ; <nl> + GD_ERR_BREAK ( argc < 0 ) ; <nl> + <nl> + GD_ERR_BREAK ( _code_ptr [ ip + 2 ] < 0 | | _code_ptr [ ip + 2 ] > = _methods_count ) ; <nl> + MethodBind * method = _methods_ptr [ _code_ptr [ ip + 2 ] ] ; <nl> + <nl> + GET_INSTRUCTION_ARG ( base , argc ) ; <nl> + # ifdef DEBUG_ENABLED <nl> + bool freed = false ; <nl> + Object * base_obj = base - > get_validated_object_with_check ( freed ) ; <nl> + if ( freed ) { <nl> + err_text = " Trying to call a function on a previously freed instance . " ; <nl> + OPCODE_BREAK ; <nl> + } else if ( ! base_obj ) { <nl> + err_text = " Trying to call a function on a null value . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # else <nl> + Object * base_obj = * VariantInternal : : get_object ( base ) ; <nl> + # endif <nl> + <nl> + const void * * argptrs = call_args_ptr ; <nl> + <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + GET_INSTRUCTION_ARG ( v , i ) ; <nl> + argptrs [ i ] = VariantInternal : : get_opaque_pointer ( ( const Variant * ) v ) ; <nl> + } <nl> + # ifdef DEBUG_ENABLED <nl> + uint64_t call_time = 0 ; <nl> + <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> + call_time = OS : : get_singleton ( ) - > get_ticks_usec ( ) ; <nl> + } <nl> + # endif <nl> + <nl> + GET_INSTRUCTION_ARG ( ret , argc + 1 ) ; <nl> + VariantInternal : : initialize ( ret , Variant : : OBJECT ) ; <nl> + Object * * ret_opaque = VariantInternal : : get_object ( ret ) ; <nl> + method - > ptrcall ( base_obj , argptrs , ret_opaque ) ; <nl> + VariantInternal : : set_object ( ret , * ret_opaque ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> + function_call_time + = OS : : get_singleton ( ) - > get_ticks_usec ( ) - call_time ; <nl> + } <nl> + # endif <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + OPCODE ( OPCODE_CALL_PTRCALL_NO_RETURN ) { <nl> + CHECK_SPACE ( 3 + instr_arg_count ) ; <nl> + <nl> + ip + = instr_arg_count ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 ] ; <nl> + GD_ERR_BREAK ( argc < 0 ) ; <nl> + <nl> + GD_ERR_BREAK ( _code_ptr [ ip + 2 ] < 0 | | _code_ptr [ ip + 2 ] > = _methods_count ) ; <nl> + MethodBind * method = _methods_ptr [ _code_ptr [ ip + 2 ] ] ; <nl> + <nl> + GET_INSTRUCTION_ARG ( base , argc ) ; <nl> + # ifdef DEBUG_ENABLED <nl> + bool freed = false ; <nl> + Object * base_obj = base - > get_validated_object_with_check ( freed ) ; <nl> + if ( freed ) { <nl> + err_text = " Trying to call a function on a previously freed instance . " ; <nl> + OPCODE_BREAK ; <nl> + } else if ( ! base_obj ) { <nl> + err_text = " Trying to call a function on a null value . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # else <nl> + Object * base_obj = * VariantInternal : : get_object ( base ) ; <nl> + # endif <nl> + const void * * argptrs = call_args_ptr ; <nl> + <nl> + for ( int i = 0 ; i < argc ; i + + ) { <nl> + GET_INSTRUCTION_ARG ( v , i ) ; <nl> + argptrs [ i ] = VariantInternal : : get_opaque_pointer ( ( const Variant * ) v ) ; <nl> + } <nl> + # ifdef DEBUG_ENABLED <nl> + uint64_t call_time = 0 ; <nl> + <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> + call_time = OS : : get_singleton ( ) - > get_ticks_usec ( ) ; <nl> + } <nl> + # endif <nl> + <nl> + GET_INSTRUCTION_ARG ( ret , argc + 1 ) ; <nl> + VariantInternal : : initialize ( ret , Variant : : NIL ) ; <nl> + method - > ptrcall ( base_obj , argptrs , nullptr ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> + function_call_time + = OS : : get_singleton ( ) - > get_ticks_usec ( ) - call_time ; <nl> + } <nl> + # endif <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_CALL_BUILTIN_TYPE_VALIDATED ) { <nl> + CHECK_SPACE ( 3 + instr_arg_count ) ; <nl> + <nl> + ip + = instr_arg_count ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 ] ; <nl> + GD_ERR_BREAK ( argc < 0 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( base , argc ) ; <nl> + <nl> + GD_ERR_BREAK ( _code_ptr [ ip + 2 ] < 0 | | _code_ptr [ ip + 2 ] > = _builtin_methods_count ) ; <nl> + Variant : : ValidatedBuiltInMethod method = _builtin_methods_ptr [ _code_ptr [ ip + 2 ] ] ; <nl> + Variant * * argptrs = instruction_args ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + uint64_t call_time = 0 ; <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> + call_time = OS : : get_singleton ( ) - > get_ticks_usec ( ) ; <nl> + } <nl> + # endif <nl> + <nl> + GET_INSTRUCTION_ARG ( ret , argc + 1 ) ; <nl> + method ( base , ( const Variant * * ) argptrs , argc , ret ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> + function_call_time + = OS : : get_singleton ( ) - > get_ticks_usec ( ) - call_time ; <nl> + } <nl> + # endif <nl> + <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_CALL_BUILT_IN ) { <nl> + CHECK_SPACE ( 3 + instr_arg_count ) ; <nl> + <nl> + ip + = instr_arg_count ; <nl> + <nl> + int argc = _code_ptr [ ip + 1 ] ; <nl> + GD_ERR_BREAK ( argc < 0 ) ; <nl> + <nl> + GDScriptFunctions : : Function func = GDScriptFunctions : : Function ( _code_ptr [ ip + 2 ] ) ; <nl> + Variant * * argptrs = instruction_args ; <nl> + <nl> + GET_INSTRUCTION_ARG ( dst , argc ) ; <nl> + <nl> + Callable : : CallError err ; <nl> + GDScriptFunctions : : call ( func , ( const Variant * * ) argptrs , argc , * dst , err ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( err . error ! = Callable : : CallError : : CALL_OK ) { <nl> + String methodstr = GDScriptFunctions : : get_func_name ( func ) ; <nl> + if ( dst - > get_type ( ) = = Variant : : STRING ) { <nl> + / / call provided error string <nl> + err_text = " Error calling built - in function ' " + methodstr + " ' : " + String ( * dst ) ; <nl> + } else { <nl> + err_text = _get_call_error ( err , " built - in function ' " + methodstr + " ' " , ( const Variant * * ) argptrs ) ; <nl> + } <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_CALL_SELF_BASE ) { <nl> + CHECK_SPACE ( 3 + instr_arg_count ) ; <nl> + <nl> + ip + = instr_arg_count ; <nl> + <nl> + int self_fun = _code_ptr [ ip + 1 ] ; <nl> + # ifdef DEBUG_ENABLED <nl> + if ( self_fun < 0 | | self_fun > = _global_names_count ) { <nl> + err_text = " compiler bug , function name not found " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + const StringName * methodname = & _global_names_ptr [ self_fun ] ; <nl> + <nl> + int argc = _code_ptr [ ip + 2 ] ; <nl> + GD_ERR_BREAK ( argc < 0 ) ; <nl> + <nl> + Variant * * argptrs = instruction_args ; <nl> + <nl> + GET_INSTRUCTION_ARG ( dst , argc ) ; <nl> + <nl> + const GDScript * gds = _script ; <nl> + <nl> + const Map < StringName , GDScriptFunction * > : : Element * E = nullptr ; <nl> + while ( gds - > base . ptr ( ) ) { <nl> + gds = gds - > base . ptr ( ) ; <nl> + E = gds - > member_functions . find ( * methodname ) ; <nl> + if ( E ) { <nl> + break ; <nl> + } <nl> + } <nl> + <nl> + Callable : : CallError err ; <nl> + <nl> + if ( E ) { <nl> + * dst = E - > get ( ) - > call ( p_instance , ( const Variant * * ) argptrs , argc , err ) ; <nl> + } else if ( gds - > native . ptr ( ) ) { <nl> + if ( * methodname ! = GDScriptLanguage : : get_singleton ( ) - > strings . _init ) { <nl> + MethodBind * mb = ClassDB : : get_method ( gds - > native - > get_name ( ) , * methodname ) ; <nl> + if ( ! mb ) { <nl> + err . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ; <nl> + } else { <nl> + * dst = mb - > call ( p_instance - > owner , ( const Variant * * ) argptrs , argc , err ) ; <nl> + } <nl> + } else { <nl> + err . error = Callable : : CallError : : CALL_OK ; <nl> + } <nl> + } else { <nl> + if ( * methodname ! = GDScriptLanguage : : get_singleton ( ) - > strings . _init ) { <nl> + err . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ; <nl> + } else { <nl> + err . error = Callable : : CallError : : CALL_OK ; <nl> + } <nl> + } <nl> + <nl> + if ( err . error ! = Callable : : CallError : : CALL_OK ) { <nl> + String methodstr = * methodname ; <nl> + err_text = _get_call_error ( err , " function ' " + methodstr + " ' " , ( const Variant * * ) argptrs ) ; <nl> + <nl> + OPCODE_BREAK ; <nl> + } <nl> + <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_AWAIT ) { <nl> + CHECK_SPACE ( 2 ) ; <nl> + <nl> + / / Do the oneshot connect . <nl> + GET_INSTRUCTION_ARG ( argobj , 0 ) ; <nl> + <nl> + Signal sig ; <nl> + bool is_signal = true ; <nl> + <nl> + { <nl> + Variant result = * argobj ; <nl> + <nl> + if ( argobj - > get_type ( ) = = Variant : : OBJECT ) { <nl> + bool was_freed = false ; <nl> + Object * obj = argobj - > get_validated_object_with_check ( was_freed ) ; <nl> + <nl> + if ( was_freed ) { <nl> + err_text = " Trying to await on a freed object . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + <nl> + / / Is this even possible to be null at this point ? <nl> + if ( obj ) { <nl> + if ( obj - > is_class_ptr ( GDScriptFunctionState : : get_class_ptr_static ( ) ) ) { <nl> + static StringName completed = _scs_create ( " completed " ) ; <nl> + result = Signal ( obj , completed ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + if ( result . get_type ( ) ! = Variant : : SIGNAL ) { <nl> + ip + = 4 ; / / Skip OPCODE_AWAIT_RESUME and its data . <nl> + / / The stack pointer should be the same , so we don ' t need to set a return value . <nl> + is_signal = false ; <nl> + } else { <nl> + sig = result ; <nl> + } <nl> + } <nl> + <nl> + if ( is_signal ) { <nl> + Ref < GDScriptFunctionState > gdfs = memnew ( GDScriptFunctionState ) ; <nl> + gdfs - > function = this ; <nl> + <nl> + gdfs - > state . stack . resize ( alloca_size ) ; <nl> + / / copy variant stack <nl> + for ( int i = 0 ; i < _stack_size ; i + + ) { <nl> + memnew_placement ( & gdfs - > state . stack . write [ sizeof ( Variant ) * i ] , Variant ( stack [ i ] ) ) ; <nl> + } <nl> + gdfs - > state . stack_size = _stack_size ; <nl> + gdfs - > state . self = self ; <nl> + gdfs - > state . alloca_size = alloca_size ; <nl> + gdfs - > state . ip = ip + 2 ; <nl> + gdfs - > state . line = line ; <nl> + gdfs - > state . script = _script ; <nl> + { <nl> + MutexLock lock ( GDScriptLanguage : : get_singleton ( ) - > lock ) ; <nl> + _script - > pending_func_states . add ( & gdfs - > scripts_list ) ; <nl> + if ( p_instance ) { <nl> + gdfs - > state . instance = p_instance ; <nl> + p_instance - > pending_func_states . add ( & gdfs - > instances_list ) ; <nl> + } else { <nl> + gdfs - > state . instance = nullptr ; <nl> + } <nl> + } <nl> + # ifdef DEBUG_ENABLED <nl> + gdfs - > state . function_name = name ; <nl> + gdfs - > state . script_path = _script - > get_path ( ) ; <nl> + # endif <nl> + gdfs - > state . defarg = defarg ; <nl> + gdfs - > function = this ; <nl> + <nl> + retvalue = gdfs ; <nl> + <nl> + Error err = sig . connect ( Callable ( gdfs . ptr ( ) , " _signal_callback " ) , varray ( gdfs ) , Object : : CONNECT_ONESHOT ) ; <nl> + if ( err ! = OK ) { <nl> + err_text = " Error connecting to signal : " + sig . get_name ( ) + " during await . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + exit_ok = true ; <nl> + awaited = true ; <nl> + # endif <nl> + OPCODE_BREAK ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; / / Needed for synchronous calls ( when result is immediately available ) . <nl> + <nl> + OPCODE ( OPCODE_AWAIT_RESUME ) { <nl> + CHECK_SPACE ( 2 ) ; <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! p_state ) { <nl> + err_text = ( " Invalid Resume ( bug ? ) " ) ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + GET_INSTRUCTION_ARG ( result , 0 ) ; <nl> + * result = p_state - > result ; <nl> + ip + = 2 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_JUMP ) { <nl> + CHECK_SPACE ( 2 ) ; <nl> + int to = _code_ptr [ ip + 1 ] ; <nl> + <nl> + GD_ERR_BREAK ( to < 0 | | to > _code_size ) ; <nl> + ip = to ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_JUMP_IF ) { <nl> + CHECK_SPACE ( 3 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( test , 0 ) ; <nl> + <nl> + bool result = test - > booleanize ( ) ; <nl> + <nl> + if ( result ) { <nl> + int to = _code_ptr [ ip + 2 ] ; <nl> + GD_ERR_BREAK ( to < 0 | | to > _code_size ) ; <nl> + ip = to ; <nl> + } else { <nl> + ip + = 3 ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_JUMP_IF_NOT ) { <nl> + CHECK_SPACE ( 3 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( test , 0 ) ; <nl> + <nl> + bool result = test - > booleanize ( ) ; <nl> + <nl> + if ( ! result ) { <nl> + int to = _code_ptr [ ip + 2 ] ; <nl> + GD_ERR_BREAK ( to < 0 | | to > _code_size ) ; <nl> + ip = to ; <nl> + } else { <nl> + ip + = 3 ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_JUMP_TO_DEF_ARGUMENT ) { <nl> + CHECK_SPACE ( 2 ) ; <nl> + ip = _default_arg_ptr [ defarg ] ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_RETURN ) { <nl> + CHECK_SPACE ( 2 ) ; <nl> + GET_INSTRUCTION_ARG ( r , 0 ) ; <nl> + retvalue = * r ; <nl> + # ifdef DEBUG_ENABLED <nl> + exit_ok = true ; <nl> + # endif <nl> + OPCODE_BREAK ; <nl> + } <nl> + <nl> + OPCODE ( OPCODE_ITERATE_BEGIN ) { <nl> + CHECK_SPACE ( 8 ) ; / / Space for this and a regular iterate . <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + bool valid ; <nl> + if ( ! container - > iter_init ( * counter , valid ) ) { <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! valid ) { <nl> + err_text = " Unable to iterate on object of type ' " + Variant : : get_type_name ( container - > get_type ( ) ) + " ' . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + <nl> + * iterator = container - > iter_get ( * counter , valid ) ; <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! valid ) { <nl> + err_text = " Unable to obtain iterator object of type ' " + Variant : : get_type_name ( container - > get_type ( ) ) + " ' . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + ip + = 5 ; / / Skip regular iterate which is always next . <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_BEGIN_INT ) { <nl> + CHECK_SPACE ( 8 ) ; / / Check space for iterate instruction too . <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + int64_t size = * VariantInternal : : get_int ( container ) ; <nl> + <nl> + VariantInternal : : initialize ( counter , Variant : : INT ) ; <nl> + * VariantInternal : : get_int ( counter ) = 0 ; <nl> + <nl> + if ( size > 0 ) { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + VariantInternal : : initialize ( iterator , Variant : : INT ) ; <nl> + * VariantInternal : : get_int ( iterator ) = 0 ; <nl> + <nl> + / / Skip regular iterate . <nl> + ip + = 5 ; <nl> + } else { <nl> + / / Jump to end of loop . <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_BEGIN_FLOAT ) { <nl> + CHECK_SPACE ( 8 ) ; / / Check space for iterate instruction too . <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + double size = * VariantInternal : : get_float ( container ) ; <nl> + <nl> + VariantInternal : : initialize ( counter , Variant : : FLOAT ) ; <nl> + * VariantInternal : : get_float ( counter ) = 0 . 0 ; <nl> + <nl> + if ( size > 0 ) { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + VariantInternal : : initialize ( iterator , Variant : : FLOAT ) ; <nl> + * VariantInternal : : get_float ( iterator ) = 0 ; <nl> + <nl> + / / Skip regular iterate . <nl> + ip + = 5 ; <nl> + } else { <nl> + / / Jump to end of loop . <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_BEGIN_VECTOR2 ) { <nl> + CHECK_SPACE ( 8 ) ; / / Check space for iterate instruction too . <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + Vector2 * bounds = VariantInternal : : get_vector2 ( container ) ; <nl> + <nl> + VariantInternal : : initialize ( counter , Variant : : FLOAT ) ; <nl> + * VariantInternal : : get_float ( counter ) = bounds - > x ; <nl> + <nl> + if ( bounds - > x < bounds - > y ) { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + VariantInternal : : initialize ( iterator , Variant : : FLOAT ) ; <nl> + * VariantInternal : : get_float ( iterator ) = bounds - > x ; <nl> + <nl> + / / Skip regular iterate . <nl> + ip + = 5 ; <nl> + } else { <nl> + / / Jump to end of loop . <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_BEGIN_VECTOR2I ) { <nl> + CHECK_SPACE ( 8 ) ; / / Check space for iterate instruction too . <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + Vector2i * bounds = VariantInternal : : get_vector2i ( container ) ; <nl> + <nl> + VariantInternal : : initialize ( counter , Variant : : FLOAT ) ; <nl> + * VariantInternal : : get_int ( counter ) = bounds - > x ; <nl> + <nl> + if ( bounds - > x < bounds - > y ) { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + VariantInternal : : initialize ( iterator , Variant : : INT ) ; <nl> + * VariantInternal : : get_int ( iterator ) = bounds - > x ; <nl> + <nl> + / / Skip regular iterate . <nl> + ip + = 5 ; <nl> + } else { <nl> + / / Jump to end of loop . <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_BEGIN_VECTOR3 ) { <nl> + CHECK_SPACE ( 8 ) ; / / Check space for iterate instruction too . <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + Vector3 * bounds = VariantInternal : : get_vector3 ( container ) ; <nl> + double from = bounds - > x ; <nl> + double to = bounds - > y ; <nl> + double step = bounds - > z ; <nl> + <nl> + VariantInternal : : initialize ( counter , Variant : : FLOAT ) ; <nl> + * VariantInternal : : get_float ( counter ) = from ; <nl> + <nl> + bool do_continue = from = = to ? false : ( from < to ? step > 0 : step < 0 ) ; <nl> + <nl> + if ( do_continue ) { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + VariantInternal : : initialize ( iterator , Variant : : FLOAT ) ; <nl> + * VariantInternal : : get_float ( iterator ) = from ; <nl> + <nl> + / / Skip regular iterate . <nl> + ip + = 5 ; <nl> + } else { <nl> + / / Jump to end of loop . <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_BEGIN_VECTOR3I ) { <nl> + CHECK_SPACE ( 8 ) ; / / Check space for iterate instruction too . <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + Vector3i * bounds = VariantInternal : : get_vector3i ( container ) ; <nl> + int64_t from = bounds - > x ; <nl> + int64_t to = bounds - > y ; <nl> + int64_t step = bounds - > z ; <nl> + <nl> + VariantInternal : : initialize ( counter , Variant : : INT ) ; <nl> + * VariantInternal : : get_int ( counter ) = from ; <nl> + <nl> + bool do_continue = from = = to ? false : ( from < to ? step > 0 : step < 0 ) ; <nl> + <nl> + if ( do_continue ) { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + VariantInternal : : initialize ( iterator , Variant : : INT ) ; <nl> + * VariantInternal : : get_int ( iterator ) = from ; <nl> + <nl> + / / Skip regular iterate . <nl> + ip + = 5 ; <nl> + } else { <nl> + / / Jump to end of loop . <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_BEGIN_STRING ) { <nl> + CHECK_SPACE ( 8 ) ; / / Check space for iterate instruction too . <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + String * str = VariantInternal : : get_string ( container ) ; <nl> + <nl> + VariantInternal : : initialize ( counter , Variant : : INT ) ; <nl> + * VariantInternal : : get_int ( counter ) = 0 ; <nl> + <nl> + if ( ! str - > empty ( ) ) { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + VariantInternal : : initialize ( iterator , Variant : : STRING ) ; <nl> + * VariantInternal : : get_string ( iterator ) = str - > substr ( 0 , 1 ) ; <nl> + <nl> + / / Skip regular iterate . <nl> + ip + = 5 ; <nl> + } else { <nl> + / / Jump to end of loop . <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_BEGIN_DICTIONARY ) { <nl> + CHECK_SPACE ( 8 ) ; / / Check space for iterate instruction too . <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + Dictionary * dict = VariantInternal : : get_dictionary ( container ) ; <nl> + const Variant * next = dict - > next ( nullptr ) ; <nl> + * counter = * next ; <nl> + <nl> + if ( ! dict - > empty ( ) ) { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * iterator = * next ; <nl> + <nl> + / / Skip regular iterate . <nl> + ip + = 5 ; <nl> + } else { <nl> + / / Jump to end of loop . <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_BEGIN_ARRAY ) { <nl> + CHECK_SPACE ( 8 ) ; / / Check space for iterate instruction too . <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + Array * array = VariantInternal : : get_array ( container ) ; <nl> + <nl> + VariantInternal : : initialize ( counter , Variant : : INT ) ; <nl> + * VariantInternal : : get_int ( counter ) = 0 ; <nl> + <nl> + if ( ! array - > empty ( ) ) { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * iterator = array - > get ( 0 ) ; <nl> + <nl> + / / Skip regular iterate . <nl> + ip + = 5 ; <nl> + } else { <nl> + / / Jump to end of loop . <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + # define OPCODE_ITERATE_BEGIN_PACKED_ARRAY ( m_var_type , m_elem_type , m_get_func , m_var_ret_type , m_ret_type , m_ret_get_func ) \ <nl> + OPCODE ( OPCODE_ITERATE_BEGIN_PACKED_ # # m_var_type # # _ARRAY ) { \ <nl> + CHECK_SPACE ( 8 ) ; \ <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; \ <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; \ <nl> + Vector < m_elem_type > * array = VariantInternal : : m_get_func ( container ) ; \ <nl> + VariantInternal : : initialize ( counter , Variant : : INT ) ; \ <nl> + * VariantInternal : : get_int ( counter ) = 0 ; \ <nl> + if ( ! array - > empty ( ) ) { \ <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; \ <nl> + VariantInternal : : initialize ( iterator , Variant : : m_var_ret_type ) ; \ <nl> + m_ret_type * it = VariantInternal : : m_ret_get_func ( iterator ) ; \ <nl> + * it = array - > get ( 0 ) ; \ <nl> + ip + = 5 ; \ <nl> + } else { \ <nl> + int jumpto = _code_ptr [ ip + 4 ] ; \ <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; \ <nl> + ip = jumpto ; \ <nl> + } \ <nl> + } \ <nl> + DISPATCH_OPCODE <nl> + <nl> + OPCODE_ITERATE_BEGIN_PACKED_ARRAY ( BYTE , uint8_t , get_byte_array , INT , int64_t , get_int ) ; <nl> + OPCODE_ITERATE_BEGIN_PACKED_ARRAY ( INT32 , int32_t , get_int32_array , INT , int64_t , get_int ) ; <nl> + OPCODE_ITERATE_BEGIN_PACKED_ARRAY ( INT64 , int64_t , get_int64_array , INT , int64_t , get_int ) ; <nl> + OPCODE_ITERATE_BEGIN_PACKED_ARRAY ( FLOAT32 , float , get_float32_array , FLOAT , double , get_float ) ; <nl> + OPCODE_ITERATE_BEGIN_PACKED_ARRAY ( FLOAT64 , double , get_float64_array , FLOAT , double , get_float ) ; <nl> + OPCODE_ITERATE_BEGIN_PACKED_ARRAY ( STRING , String , get_string_array , STRING , String , get_string ) ; <nl> + OPCODE_ITERATE_BEGIN_PACKED_ARRAY ( VECTOR2 , Vector2 , get_vector2_array , VECTOR2 , Vector2 , get_vector2 ) ; <nl> + OPCODE_ITERATE_BEGIN_PACKED_ARRAY ( VECTOR3 , Vector3 , get_vector3_array , VECTOR3 , Vector3 , get_vector3 ) ; <nl> + OPCODE_ITERATE_BEGIN_PACKED_ARRAY ( COLOR , Color , get_color_array , COLOR , Color , get_color ) ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_BEGIN_OBJECT ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + bool freed = false ; <nl> + Object * obj = container - > get_validated_object_with_check ( freed ) ; <nl> + if ( freed ) { <nl> + err_text = " Trying to iterate on a previously freed object . " ; <nl> + OPCODE_BREAK ; <nl> + } else if ( ! obj ) { <nl> + err_text = " Trying to iterate on a null value . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # else <nl> + Object * obj = * VariantInternal : : get_object ( container ) ; <nl> + # endif <nl> + Array ref ; <nl> + ref . push_back ( * counter ) ; <nl> + Variant vref ; <nl> + VariantInternal : : initialize ( & vref , Variant : : ARRAY ) ; <nl> + * VariantInternal : : get_array ( & vref ) = ref ; <nl> + <nl> + Variant * * args = instruction_args ; / / Overriding an instruction argument , but we don ' t need access to that anymore . <nl> + args [ 0 ] = & vref ; <nl> + <nl> + Callable : : CallError ce ; <nl> + Variant has_next = obj - > call ( CoreStringNames : : get_singleton ( ) - > _iter_init , ( const Variant * * ) args , 1 , ce ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ce . error ! = Callable : : CallError : : CALL_OK ) { <nl> + err_text = vformat ( R " ( There was an error calling " _iter_next " on iterator object of type % s . ) " , * container ) ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + if ( ! has_next . booleanize ( ) ) { <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * iterator = obj - > call ( CoreStringNames : : get_singleton ( ) - > _iter_get , ( const Variant * * ) args , 1 , ce ) ; <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ce . error ! = Callable : : CallError : : CALL_OK ) { <nl> + err_text = vformat ( R " ( There was an error calling " _iter_get " on iterator object of type % s . ) " , * container ) ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + <nl> + ip + = 5 ; / / Loop again . <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + bool valid ; <nl> + if ( ! container - > iter_next ( * counter , valid ) ) { <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! valid ) { <nl> + err_text = " Unable to iterate on object of type ' " + Variant : : get_type_name ( container - > get_type ( ) ) + " ' ( type changed since first iteration ? ) . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + <nl> + * iterator = container - > iter_get ( * counter , valid ) ; <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ! valid ) { <nl> + err_text = " Unable to obtain iterator object of type ' " + Variant : : get_type_name ( container - > get_type ( ) ) + " ' ( but was obtained on first iteration ? ) . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + ip + = 5 ; / / loop again <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_INT ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + int64_t size = * VariantInternal : : get_int ( container ) ; <nl> + int64_t * count = VariantInternal : : get_int ( counter ) ; <nl> + <nl> + ( * count ) + + ; <nl> + <nl> + if ( * count > = size ) { <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * VariantInternal : : get_int ( iterator ) = * count ; <nl> + <nl> + ip + = 5 ; / / Loop again . <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_FLOAT ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + double size = * VariantInternal : : get_float ( container ) ; <nl> + double * count = VariantInternal : : get_float ( counter ) ; <nl> + <nl> + ( * count ) + + ; <nl> + <nl> + if ( * count > = size ) { <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * VariantInternal : : get_float ( iterator ) = * count ; <nl> + <nl> + ip + = 5 ; / / Loop again . <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_VECTOR2 ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + const Vector2 * bounds = VariantInternal : : get_vector2 ( ( const Variant * ) container ) ; <nl> + double * count = VariantInternal : : get_float ( counter ) ; <nl> + <nl> + ( * count ) + + ; <nl> + <nl> + if ( * count > = bounds - > y ) { <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * VariantInternal : : get_float ( iterator ) = * count ; <nl> + <nl> + ip + = 5 ; / / Loop again . <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_VECTOR2I ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + const Vector2i * bounds = VariantInternal : : get_vector2i ( ( const Variant * ) container ) ; <nl> + int64_t * count = VariantInternal : : get_int ( counter ) ; <nl> + <nl> + ( * count ) + + ; <nl> + <nl> + if ( * count > = bounds - > y ) { <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * VariantInternal : : get_int ( iterator ) = * count ; <nl> + <nl> + ip + = 5 ; / / Loop again . <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_VECTOR3 ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + const Vector3 * bounds = VariantInternal : : get_vector3 ( ( const Variant * ) container ) ; <nl> + double * count = VariantInternal : : get_float ( counter ) ; <nl> + <nl> + * count + = bounds - > z ; <nl> + <nl> + if ( ( bounds - > z < 0 & & * count < = bounds - > y ) | | ( bounds - > z > 0 & & * count > = bounds - > y ) ) { <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * VariantInternal : : get_float ( iterator ) = * count ; <nl> + <nl> + ip + = 5 ; / / Loop again . <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_VECTOR3I ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + const Vector3i * bounds = VariantInternal : : get_vector3i ( ( const Variant * ) container ) ; <nl> + int64_t * count = VariantInternal : : get_int ( counter ) ; <nl> + <nl> + * count + = bounds - > z ; <nl> + <nl> + if ( ( bounds - > z < 0 & & * count < = bounds - > y ) | | ( bounds - > z > 0 & & * count > = bounds - > y ) ) { <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * VariantInternal : : get_int ( iterator ) = * count ; <nl> + <nl> + ip + = 5 ; / / Loop again . <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_STRING ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + const String * str = VariantInternal : : get_string ( ( const Variant * ) container ) ; <nl> + int64_t * idx = VariantInternal : : get_int ( counter ) ; <nl> + ( * idx ) + + ; <nl> + <nl> + if ( * idx > = str - > length ( ) ) { <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * VariantInternal : : get_string ( iterator ) = str - > substr ( * idx , 1 ) ; <nl> + <nl> + ip + = 5 ; / / Loop again . <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_DICTIONARY ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + const Dictionary * dict = VariantInternal : : get_dictionary ( ( const Variant * ) container ) ; <nl> + const Variant * next = dict - > next ( counter ) ; <nl> + <nl> + if ( ! next ) { <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * counter = * next ; <nl> + * iterator = * next ; <nl> + <nl> + ip + = 5 ; / / Loop again . <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_ARRAY ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + const Array * array = VariantInternal : : get_array ( ( const Variant * ) container ) ; <nl> + int64_t * idx = VariantInternal : : get_int ( counter ) ; <nl> + ( * idx ) + + ; <nl> + <nl> + if ( * idx > = array - > size ( ) ) { <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * iterator = array - > get ( * idx ) ; <nl> + <nl> + ip + = 5 ; / / Loop again . <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + # define OPCODE_ITERATE_PACKED_ARRAY ( m_var_type , m_elem_type , m_get_func , m_ret_get_func ) \ <nl> + OPCODE ( OPCODE_ITERATE_PACKED_ # # m_var_type # # _ARRAY ) { \ <nl> + CHECK_SPACE ( 4 ) ; \ <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; \ <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; \ <nl> + const Vector < m_elem_type > * array = VariantInternal : : m_get_func ( ( const Variant * ) container ) ; \ <nl> + int64_t * idx = VariantInternal : : get_int ( counter ) ; \ <nl> + ( * idx ) + + ; \ <nl> + if ( * idx > = array - > size ( ) ) { \ <nl> + int jumpto = _code_ptr [ ip + 4 ] ; \ <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; \ <nl> + ip = jumpto ; \ <nl> + } else { \ <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; \ <nl> + * VariantInternal : : m_ret_get_func ( iterator ) = array - > get ( * idx ) ; \ <nl> + ip + = 5 ; \ <nl> + } \ <nl> + } \ <nl> + DISPATCH_OPCODE <nl> + <nl> + OPCODE_ITERATE_PACKED_ARRAY ( BYTE , uint8_t , get_byte_array , get_int ) ; <nl> + OPCODE_ITERATE_PACKED_ARRAY ( INT32 , int32_t , get_int32_array , get_int ) ; <nl> + OPCODE_ITERATE_PACKED_ARRAY ( INT64 , int64_t , get_int64_array , get_int ) ; <nl> + OPCODE_ITERATE_PACKED_ARRAY ( FLOAT32 , float , get_float32_array , get_float ) ; <nl> + OPCODE_ITERATE_PACKED_ARRAY ( FLOAT64 , double , get_float64_array , get_float ) ; <nl> + OPCODE_ITERATE_PACKED_ARRAY ( STRING , String , get_string_array , get_string ) ; <nl> + OPCODE_ITERATE_PACKED_ARRAY ( VECTOR2 , Vector2 , get_vector2_array , get_vector2 ) ; <nl> + OPCODE_ITERATE_PACKED_ARRAY ( VECTOR3 , Vector3 , get_vector3_array , get_vector3 ) ; <nl> + OPCODE_ITERATE_PACKED_ARRAY ( COLOR , Color , get_color_array , get_color ) ; <nl> + <nl> + OPCODE ( OPCODE_ITERATE_OBJECT ) { <nl> + CHECK_SPACE ( 4 ) ; <nl> + <nl> + GET_INSTRUCTION_ARG ( counter , 0 ) ; <nl> + GET_INSTRUCTION_ARG ( container , 1 ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + bool freed = false ; <nl> + Object * obj = container - > get_validated_object_with_check ( freed ) ; <nl> + if ( freed ) { <nl> + err_text = " Trying to iterate on a previously freed object . " ; <nl> + OPCODE_BREAK ; <nl> + } else if ( ! obj ) { <nl> + err_text = " Trying to iterate on a null value . " ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # else <nl> + Object * obj = * VariantInternal : : get_object ( container ) ; <nl> + # endif <nl> + Array ref ; <nl> + ref . push_back ( * counter ) ; <nl> + Variant vref ; <nl> + VariantInternal : : initialize ( & vref , Variant : : ARRAY ) ; <nl> + * VariantInternal : : get_array ( & vref ) = ref ; <nl> + <nl> + Variant * * args = instruction_args ; / / Overriding an instruction argument , but we don ' t need access to that anymore . <nl> + args [ 0 ] = & vref ; <nl> + <nl> + Callable : : CallError ce ; <nl> + Variant has_next = obj - > call ( CoreStringNames : : get_singleton ( ) - > _iter_next , ( const Variant * * ) args , 1 , ce ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ce . error ! = Callable : : CallError : : CALL_OK ) { <nl> + err_text = vformat ( R " ( There was an error calling " _iter_next " on iterator object of type % s . ) " , * container ) ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + if ( ! has_next . booleanize ( ) ) { <nl> + int jumpto = _code_ptr [ ip + 4 ] ; <nl> + GD_ERR_BREAK ( jumpto < 0 | | jumpto > _code_size ) ; <nl> + ip = jumpto ; <nl> + } else { <nl> + GET_INSTRUCTION_ARG ( iterator , 2 ) ; <nl> + * iterator = obj - > call ( CoreStringNames : : get_singleton ( ) - > _iter_get , ( const Variant * * ) args , 1 , ce ) ; <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ce . error ! = Callable : : CallError : : CALL_OK ) { <nl> + err_text = vformat ( R " ( There was an error calling " _iter_get " on iterator object of type % s . ) " , * container ) ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + <nl> + ip + = 5 ; / / Loop again . <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_ASSERT ) { <nl> + CHECK_SPACE ( 3 ) ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + GET_INSTRUCTION_ARG ( test , 0 ) ; <nl> + bool result = test - > booleanize ( ) ; <nl> + <nl> + if ( ! result ) { <nl> + String message_str ; <nl> + if ( _code_ptr [ ip + 2 ] ! = 0 ) { <nl> + GET_INSTRUCTION_ARG ( message , 1 ) ; <nl> + message_str = * message ; <nl> + } <nl> + if ( message_str . empty ( ) ) { <nl> + err_text = " Assertion failed . " ; <nl> + } else { <nl> + err_text = " Assertion failed : " + message_str ; <nl> + } <nl> + OPCODE_BREAK ; <nl> + } <nl> + <nl> + # endif <nl> + ip + = 3 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_BREAKPOINT ) { <nl> + # ifdef DEBUG_ENABLED <nl> + if ( EngineDebugger : : is_active ( ) ) { <nl> + GDScriptLanguage : : get_singleton ( ) - > debug_break ( " Breakpoint Statement " , true ) ; <nl> + } <nl> + # endif <nl> + ip + = 1 ; <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_LINE ) { <nl> + CHECK_SPACE ( 2 ) ; <nl> + <nl> + line = _code_ptr [ ip + 1 ] ; <nl> + ip + = 2 ; <nl> + <nl> + if ( EngineDebugger : : is_active ( ) ) { <nl> + / / line <nl> + bool do_break = false ; <nl> + <nl> + if ( EngineDebugger : : get_script_debugger ( ) - > get_lines_left ( ) > 0 ) { <nl> + if ( EngineDebugger : : get_script_debugger ( ) - > get_depth ( ) < = 0 ) { <nl> + EngineDebugger : : get_script_debugger ( ) - > set_lines_left ( EngineDebugger : : get_script_debugger ( ) - > get_lines_left ( ) - 1 ) ; <nl> + } <nl> + if ( EngineDebugger : : get_script_debugger ( ) - > get_lines_left ( ) < = 0 ) { <nl> + do_break = true ; <nl> + } <nl> + } <nl> + <nl> + if ( EngineDebugger : : get_script_debugger ( ) - > is_breakpoint ( line , source ) ) { <nl> + do_break = true ; <nl> + } <nl> + <nl> + if ( do_break ) { <nl> + GDScriptLanguage : : get_singleton ( ) - > debug_break ( " Breakpoint " , true ) ; <nl> + } <nl> + <nl> + EngineDebugger : : get_singleton ( ) - > line_poll ( ) ; <nl> + } <nl> + } <nl> + DISPATCH_OPCODE ; <nl> + <nl> + OPCODE ( OPCODE_END ) { <nl> + # ifdef DEBUG_ENABLED <nl> + exit_ok = true ; <nl> + # endif <nl> + OPCODE_BREAK ; <nl> + } <nl> + <nl> + # if 0 / / Enable for debugging . <nl> + default : { <nl> + err_text = " Illegal opcode " + itos ( _code_ptr [ ip ] ) + " at address " + itos ( ip ) ; <nl> + OPCODE_BREAK ; <nl> + } <nl> + # endif <nl> + } <nl> + <nl> + OPCODES_END <nl> + # ifdef DEBUG_ENABLED <nl> + if ( exit_ok ) { <nl> + OPCODE_OUT ; <nl> + } <nl> + / / error <nl> + / / function , file , line , error , explanation <nl> + String err_file ; <nl> + if ( p_instance & & ObjectDB : : get_instance ( p_instance - > owner_id ) ! = nullptr & & p_instance - > script - > is_valid ( ) & & p_instance - > script - > path ! = " " ) { <nl> + err_file = p_instance - > script - > path ; <nl> + } else if ( script ) { <nl> + err_file = script - > path ; <nl> + } <nl> + if ( err_file = = " " ) { <nl> + err_file = " < built - in > " ; <nl> + } <nl> + String err_func = name ; <nl> + if ( p_instance & & ObjectDB : : get_instance ( p_instance - > owner_id ) ! = nullptr & & p_instance - > script - > is_valid ( ) & & p_instance - > script - > name ! = " " ) { <nl> + err_func = p_instance - > script - > name + " . " + err_func ; <nl> + } <nl> + int err_line = line ; <nl> + if ( err_text = = " " ) { <nl> + err_text = " Internal Script Error ! - opcode # " + itos ( last_opcode ) + " ( report please ) . " ; <nl> + } <nl> + <nl> + if ( ! GDScriptLanguage : : get_singleton ( ) - > debug_break ( err_text , false ) ) { <nl> + / / debugger break did not happen <nl> + <nl> + _err_print_error ( err_func . utf8 ( ) . get_data ( ) , err_file . utf8 ( ) . get_data ( ) , err_line , err_text . utf8 ( ) . get_data ( ) , ERR_HANDLER_SCRIPT ) ; <nl> + } <nl> + <nl> + # endif <nl> + OPCODE_OUT ; <nl> + } <nl> + <nl> + OPCODES_OUT <nl> + # ifdef DEBUG_ENABLED <nl> + if ( GDScriptLanguage : : get_singleton ( ) - > profiling ) { <nl> + uint64_t time_taken = OS : : get_singleton ( ) - > get_ticks_usec ( ) - function_start_time ; <nl> + profile . total_time + = time_taken ; <nl> + profile . self_time + = time_taken - function_call_time ; <nl> + profile . frame_total_time + = time_taken ; <nl> + profile . frame_self_time + = time_taken - function_call_time ; <nl> + GDScriptLanguage : : get_singleton ( ) - > script_frame_time + = time_taken - function_call_time ; <nl> + } <nl> + <nl> + / / Check if this is the last time the function is resuming from await <nl> + / / Will be true if never awaited as well <nl> + / / When it ' s the last resume it will postpone the exit from stack , <nl> + / / so the debugger knows which function triggered the resume of the next function ( if any ) <nl> + if ( ! p_state | | awaited ) { <nl> + if ( EngineDebugger : : is_active ( ) ) { <nl> + GDScriptLanguage : : get_singleton ( ) - > exit_function ( ) ; <nl> + } <nl> + # endif <nl> + <nl> + if ( _stack_size ) { <nl> + / / free stack <nl> + for ( int i = 0 ; i < _stack_size ; i + + ) { <nl> + stack [ i ] . ~ Variant ( ) ; <nl> + } <nl> + } <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + } <nl> + # endif <nl> + <nl> + return retvalue ; <nl> + } <nl>
Merge pull request from vnen / gdscript - typed - vm - 2
godotengine/godot
4ed42bfc299c8b4e5f21217f18d9d0157f0bf1c4
2020-11-23T08:59:20Z
mmm a / docs / LangRef . html <nl> ppp b / docs / LangRef . html <nl> < h4 id = " stdlib - short - circuit - logical " > Short Circuiting Logical Operators < / h4 > <nl> From highest to lowest : < / p > <nl> <nl> < pre class = " stdlib " > <nl> - " exponentiative : " < < , > > , * * <nl> + " exponentiative : " < < , > > <nl> " multiplicative : " * , / , % , & <nl> " additive : " + , - , | , ^ <nl> " comparative : " = = , ! = , < , < = , > = , > <nl> mmm a / utils / buildbot - release - notes . txt <nl> ppp b / utils / buildbot - release - notes . txt <nl> <nl> } <nl> <nl> * Operator precedence has been simplified : <nl> - " exponentiative : " < < , > > , * * <nl> + " exponentiative : " < < , > > <nl> " multiplicative : " * , / , % , & <nl> " additive : " + , - , | , ^ <nl> " comparative : " = = , ! = , < , < = , > = , > <nl>
Copy and paste error : we do not have a * * operator
apple/swift
942b490342acad4639cbe50a2ecb4a1cccc5f0c9
2013-12-04T23:46:51Z
mmm a / libraries / ESP8266HTTPClient / src / ESP8266HTTPClient . cpp <nl> ppp b / libraries / ESP8266HTTPClient / src / ESP8266HTTPClient . cpp <nl> int HTTPClient : : sendRequest ( const char * type , Stream * stream , size_t size ) { <nl> <nl> / / write it to Stream <nl> int w = _tcp - > write ( ( const uint8_t * ) buff , c ) ; <nl> + bytesWritten + = w ; <nl> if ( w ! = c ) { <nl> DEBUG_HTTPCLIENT ( " [ HTTP - Client ] [ sendRequest ] short write asked for % d but got % d \ n " , c , w ) ; <nl> break ; <nl> } <nl> - bytesWritten + = c ; <nl> <nl> if ( len > 0 ) { <nl> len - = c ; <nl> int HTTPClient : : writeToStream ( Stream * stream ) { <nl> <nl> / / write it to Stream <nl> int w = stream - > write ( buff , c ) ; <nl> + bytesWritten + = w ; <nl> if ( w ! = c ) { <nl> DEBUG_HTTPCLIENT ( " [ HTTP - Client ] [ writeToStream ] short write asked for % d but got % d \ n " , c , w ) ; <nl> break ; <nl> } <nl> - bytesWritten + = c ; <nl> <nl> if ( len > 0 ) { <nl> len - = c ; <nl>
Merge pull request from gtalusan / bytesWritten_accounting
esp8266/Arduino
caa2443f22663e233894059a424529c77e17eafd
2015-12-23T17:30:15Z
new file mode 100644 <nl> index 0000000000 . . 1066356856 <nl> mmm / dev / null <nl> ppp b / vnpy / gateway / okexo / __init__ . py <nl> @ @ - 0 , 0 + 1 @ @ <nl> + from . okexo_gateway import OkexoGateway <nl>
Create __init__ . py
vnpy/vnpy
d775ebdc4e5f18999e86702f15497bb36d466960
2020-02-18T02:30:51Z
mmm a / folly / test / JsonOtherTest . cpp <nl> ppp b / folly / test / JsonOtherTest . cpp <nl> <nl> <nl> # include < folly / Benchmark . h > <nl> # include < folly / Conv . h > <nl> - # include < folly / FileUtil . h > <nl> # include < folly / Range . h > <nl> # include < folly / portability / GFlags . h > <nl> # include < folly / portability / GTest . h > <nl> constexpr folly : : StringPiece kLargeAsciiStringWithSpecialChars = <nl> " < script > foo % @ bar . com < / script > " ; <nl> <nl> TEST ( Json , StripComments ) { <nl> - const std : : string kTestDir = " folly / test / " ; <nl> - const std : : string kTestFile = " json_test_data / commented . json " ; <nl> - const std : : string kTestExpected = " json_test_data / commented . json . exp " ; <nl> - <nl> - std : : string testStr ; <nl> - std : : string expectedStr ; <nl> - if ( ! folly : : readFile ( kTestFile . data ( ) , testStr ) & & <nl> - ! folly : : readFile ( ( kTestDir + kTestFile ) . data ( ) , testStr ) ) { <nl> - FAIL ( ) < < " can not read test file " < < kTestFile ; <nl> - } <nl> - if ( ! folly : : readFile ( kTestExpected . data ( ) , expectedStr ) & & <nl> - ! folly : : readFile ( ( kTestDir + kTestExpected ) . data ( ) , expectedStr ) ) { <nl> - FAIL ( ) < < " can not read test file " < < kTestExpected ; <nl> - } <nl> + auto testStr = folly : : stripLeftMargin ( R " JSON ( <nl> + { <nl> + / / comment <nl> + " test " : " foo " , / / comment <nl> + " test2 " : " foo / / bar " , / / more comments <nl> + / * <nl> + " test3 " : " baz " <nl> + * / <nl> + " test4 " : " foo / * bar " , / * comment * / <nl> + " te / / " : " foo " , <nl> + " te / * " : " bar " , <nl> + " \ \ \ " " : " \ \ " / * comment * / <nl> + } <nl> + ) JSON " ) ; <nl> + auto expectedStr = folly : : stripLeftMargin ( R " JSON ( <nl> + { <nl> + " test " : " foo " , " test2 " : " foo / / bar " , <nl> + " test4 " : " foo / * bar " , <nl> + " te / / " : " foo " , <nl> + " te / * " : " bar " , <nl> + " \ \ \ " " : " \ \ " <nl> + } <nl> + ) JSON " ) ; <nl> + <nl> EXPECT_EQ ( expectedStr , folly : : json : : stripComments ( testStr ) ) ; <nl> } <nl> <nl> deleted file mode 100644 <nl> index 80632cb64b2 . . 00000000000 <nl> mmm a / folly / test / json_test_data / commented . json <nl> ppp / dev / null <nl> <nl> - { <nl> - / / comment <nl> - " test " : " foo " , / / comment <nl> - " test2 " : " foo / / bar " , / / more comments <nl> - / * <nl> - " test3 " : " baz " <nl> - * / <nl> - " test4 " : " foo / * bar " , / * comment * / <nl> - " te / / " : " foo " , <nl> - " te / * " : " bar " , <nl> - " \ \ \ " " : " \ \ " / * comment * / <nl> - } <nl> deleted file mode 100644 <nl> index 0c8482fdd2b . . 00000000000 <nl> mmm a / folly / test / json_test_data / commented . json . exp <nl> ppp / dev / null <nl> <nl> - { <nl> - " test " : " foo " , " test2 " : " foo / / bar " , <nl> - " test4 " : " foo / * bar " , <nl> - " te / / " : " foo " , <nl> - " te / * " : " bar " , <nl> - " \ \ \ " " : " \ \ " <nl> - } <nl>
No need to load test files at runtime in json test
facebook/folly
d3f8fa39189a7fe0be74be86c53a54194cadb7f7
2019-09-26T23:19:41Z
mmm a / test / integration / static_cluster . py <nl> ppp b / test / integration / static_cluster . py <nl> <nl> op = OptParser ( ) <nl> op [ " workload " ] = PositionalArg ( ) <nl> op [ " num - nodes " ] = IntFlag ( " - - num - nodes " , 3 ) <nl> + op [ " timeout " ] = IntFlag ( " - - timeout " , 600 ) <nl> opts = op . parse ( sys . argv ) <nl> <nl> cluster = http_admin . Cluster ( ) <nl> <nl> <nl> port = cluster . compute_port ( namespace , next ( cluster . machines . iterkeys ( ) ) ) <nl> <nl> - time . sleep ( 5 ) <nl> + wait_time = 5 <nl> + print " Waiting % d seconds for cluster to configure itself . . . " % wait_time <nl> + time . sleep ( wait_time ) <nl> <nl> command_line = opts [ " workload " ] <nl> new_environ = os . environ . copy ( ) <nl> <nl> <nl> print " Running % r with HOST = % r and PORT = % r . . . " % ( command_line , new_environ [ " HOST " ] , new_environ [ " PORT " ] ) <nl> start_time = time . time ( ) <nl> - try : <nl> - subprocess . check_call ( command_line , shell = True , env = new_environ ) <nl> - except subprocess . CalledProcessError : <nl> - end_time = time . time ( ) <nl> - print " Failed ( % d seconds ) " % ( end_time - start_time ) <nl> - sys . exit ( 1 ) <nl> - else : <nl> - end_time = time . time ( ) <nl> - print " Done ( % d seconds ) " % ( end_time - start_time ) <nl> + subp = subprocess . Popen ( command_line , shell = True , env = new_environ ) <nl> + while time . time ( ) < start_time + opts [ " timeout " ] : <nl> + if subp . poll ( ) is None : <nl> + time . sleep ( 1 ) <nl> + elif subp . poll ( ) = = 0 : <nl> + print " Done ( % d seconds ) " % ( end_time - start_time ) <nl> + sys . exit ( 0 ) <nl> + else : <nl> + print " Failed ( % d seconds ) " % ( end_time - start_time ) <nl> + sys . exit ( 1 ) <nl> + print " Timed out " <nl> + subp . terminate ( ) <nl> + sys . exit ( 1 ) <nl>
Add timeouts to static_cluster . py .
rethinkdb/rethinkdb
2f7192d4ec7dfc9e5cde4cb53d3af077851112ff
2012-03-30T20:10:17Z
mmm a / tensorflow / docs_src / community / index . md <nl> ppp b / tensorflow / docs_src / community / index . md <nl> with content from the TensorFlow team and the best articles from the community . <nl> <nl> # # # YouTube <nl> <nl> - Our [ YouTube Channel ] ( http : / / youtube . com / tensorflow / ) focuses on machine learing <nl> + Our [ YouTube Channel ] ( http : / / youtube . com / tensorflow / ) focuses on machine learning <nl> and AI with TensorFlow . On it we have a number of new shows , including : <nl> <nl> - TensorFlow Meets : meet with community contributors to learn and share what they ' re doing <nl> mmm a / tensorflow / docs_src / deploy / s3 . md <nl> ppp b / tensorflow / docs_src / deploy / s3 . md <nl> AWS_SECRET_ACCESS_KEY = XXXXX <nl> AWS_REGION = us - east - 1 # Region for the S3 bucket , this is not always needed . Default is us - east - 1 . <nl> S3_ENDPOINT = s3 . us - east - 1 . amazonaws . com # The S3 API Endpoint to connect to . This is specified in a HOST : PORT format . <nl> S3_USE_HTTPS = 1 # Whether or not to use HTTPS . Disable with 0 . <nl> - S3_VERIFY_SSL = 1 # If HTTPS is used , conterols if SSL should be enabled . Disable with 0 . <nl> + S3_VERIFY_SSL = 1 # If HTTPS is used , controls if SSL should be enabled . Disable with 0 . <nl> ` ` ` <nl> <nl> # # Usage <nl> mmm a / tensorflow / docs_src / extend / adding_an_op . md <nl> ppp b / tensorflow / docs_src / extend / adding_an_op . md <nl> define an attr with constraints , you can use the following ` < attr - type - expr > ` s : <nl> ` ` ` <nl> <nl> Lists can be combined with other lists and single types . The following <nl> - op allows attr ` t ` to be any of the numberic types , or the bool type : <nl> + op allows attr ` t ` to be any of the numeric types , or the bool type : <nl> <nl> ` ` ` c + + <nl> REGISTER_OP ( " NumberOrBooleanType " ) <nl> mmm a / tensorflow / docs_src / extend / index . md <nl> ppp b / tensorflow / docs_src / extend / index . md <nl> TensorFlow : <nl> <nl> Python is currently the only language supported by TensorFlow ' s API stability <nl> promises . However , TensorFlow also provides functionality in C + + , Go , Java and <nl> - [ JavaScript ] ( https : / / js . tensorflow . org ) ( incuding <nl> + [ JavaScript ] ( https : / / js . tensorflow . org ) ( including <nl> [ Node . js ] ( https : / / github . com / tensorflow / tfjs - node ) ) , <nl> plus community support for [ Haskell ] ( https : / / github . com / tensorflow / haskell ) and <nl> [ Rust ] ( https : / / github . com / tensorflow / rust ) . If you ' d like to create or <nl> mmm a / tensorflow / docs_src / guide / debugger . md <nl> ppp b / tensorflow / docs_src / guide / debugger . md <nl> hooks = [ tf_debug . DumpingDebugHook ( " / shared / storage / location / tfdbg_dumps_1 " ) ] <nl> <nl> Then this ` hook ` can be used in the same way as the ` LocalCLIDebugHook ` examples <nl> described earlier in this document . <nl> - As the training , evalution or prediction happens with ` Estimator ` , <nl> + As the training , evaluation or prediction happens with ` Estimator ` , <nl> tfdbg creates directories having the following name pattern : <nl> ` / shared / storage / location / tfdbg_dumps_1 / run_ < epoch_timestamp_microsec > _ < uuid > ` . <nl> Each directory corresponds to a ` Session . run ( ) ` call that underlies <nl> sess . run ( b ) <nl> <nl> * * A * * : The reason why you see no data dumped is because every node in the <nl> executed TensorFlow graph is constant - folded by the TensorFlow runtime . <nl> - In this exapmle , ` a ` is a constant tensor ; therefore , the fetched <nl> + In this example , ` a ` is a constant tensor ; therefore , the fetched <nl> tensor ` b ` is effectively also a constant tensor . TensorFlow ' s graph <nl> optimization folds the graph that contains ` a ` and ` b ` into a single <nl> node to speed up future runs of the graph , which is why ` tfdbg ` does <nl> mmm a / tensorflow / docs_src / performance / xla / operation_semantics . md <nl> ppp b / tensorflow / docs_src / performance / xla / operation_semantics . md <nl> Alltoall is a collective operation that sends data from all cores to all cores . <nl> It has two phases : <nl> <nl> 1 . the scatter phase . On each core , the operand is split into ` split_count ` <nl> - number of blocks along the ` split_dimensions ` , and the blocks are scatterd <nl> + number of blocks along the ` split_dimensions ` , and the blocks are scattered <nl> to all cores , e . g . , the ith block is send to the ith core . <nl> 2 . the gather phase . Each core concatenates the received blocks along the <nl> ` concat_dimension ` . <nl>
Merge pull request from brettkoonce : docs_src_sp
tensorflow/tensorflow
84fe668df5d79643cc431c075fe18cec908eb81f
2018-08-10T19:57:36Z
mmm a / core / io / stream_peer_ssl . cpp <nl> ppp b / core / io / stream_peer_ssl . cpp <nl> bool StreamPeerSSL : : is_available ( ) { <nl> return available ; <nl> } <nl> <nl> + void StreamPeerSSL : : set_blocking_handshake_enabled ( bool p_enabled ) { <nl> + blocking_handshake = p_enabled ; <nl> + } <nl> + <nl> + bool StreamPeerSSL : : is_blocking_handshake_enabled ( ) const { <nl> + return blocking_handshake ; <nl> + } <nl> + <nl> PoolByteArray StreamPeerSSL : : get_project_cert_array ( ) { <nl> <nl> PoolByteArray out ; <nl> PoolByteArray StreamPeerSSL : : get_project_cert_array ( ) { <nl> void StreamPeerSSL : : _bind_methods ( ) { <nl> <nl> ClassDB : : bind_method ( D_METHOD ( " poll " ) , & StreamPeerSSL : : poll ) ; <nl> - ClassDB : : bind_method ( D_METHOD ( " accept_stream " , " stream " ) , & StreamPeerSSL : : accept_stream ) ; <nl> + ClassDB : : bind_method ( D_METHOD ( " accept_stream " ) , & StreamPeerSSL : : accept_stream ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " connect_to_stream " , " stream " , " validate_certs " , " for_hostname " ) , & StreamPeerSSL : : connect_to_stream , DEFVAL ( false ) , DEFVAL ( String ( ) ) ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " get_status " ) , & StreamPeerSSL : : get_status ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " disconnect_from_stream " ) , & StreamPeerSSL : : disconnect_from_stream ) ; <nl> + ClassDB : : bind_method ( D_METHOD ( " set_blocking_handshake_enabled " , " enabled " ) , & StreamPeerSSL : : set_blocking_handshake_enabled ) ; <nl> + ClassDB : : bind_method ( D_METHOD ( " is_blocking_handshake_enabled " ) , & StreamPeerSSL : : is_blocking_handshake_enabled ) ; <nl> + <nl> + ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " blocking_handshake " ) , " set_blocking_handshake_enabled " , " is_blocking_handshake_enabled " ) ; <nl> <nl> BIND_ENUM_CONSTANT ( STATUS_DISCONNECTED ) ; <nl> BIND_ENUM_CONSTANT ( STATUS_CONNECTED ) ; <nl> - BIND_ENUM_CONSTANT ( STATUS_ERROR_NO_CERTIFICATE ) ; <nl> + BIND_ENUM_CONSTANT ( STATUS_ERROR ) ; <nl> BIND_ENUM_CONSTANT ( STATUS_ERROR_HOSTNAME_MISMATCH ) ; <nl> } <nl> <nl> StreamPeerSSL : : StreamPeerSSL ( ) { <nl> + blocking_handshake = true ; <nl> } <nl> mmm a / core / io / stream_peer_ssl . h <nl> ppp b / core / io / stream_peer_ssl . h <nl> class StreamPeerSSL : public StreamPeer { <nl> friend class Main ; <nl> static bool initialize_certs ; <nl> <nl> + bool blocking_handshake ; <nl> + <nl> public : <nl> enum Status { <nl> STATUS_DISCONNECTED , <nl> + STATUS_HANDSHAKING , <nl> STATUS_CONNECTED , <nl> - STATUS_ERROR_NO_CERTIFICATE , <nl> + STATUS_ERROR , <nl> STATUS_ERROR_HOSTNAME_MISMATCH <nl> } ; <nl> <nl> + void set_blocking_handshake_enabled ( bool p_enabled ) ; <nl> + bool is_blocking_handshake_enabled ( ) const ; <nl> + <nl> virtual void poll ( ) = 0 ; <nl> virtual Error accept_stream ( Ref < StreamPeer > p_base ) = 0 ; <nl> virtual Error connect_to_stream ( Ref < StreamPeer > p_base , bool p_validate_certs = false , const String & p_for_hostname = String ( ) ) = 0 ; <nl> mmm a / modules / mbedtls / stream_peer_mbed_tls . cpp <nl> ppp b / modules / mbedtls / stream_peer_mbed_tls . cpp <nl> <nl> / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> <nl> # include " stream_peer_mbed_tls . h " <nl> + # include " mbedtls / platform_util . h " <nl> + # include " os / file_access . h " <nl> <nl> static void my_debug ( void * ctx , int level , <nl> const char * file , int line , <nl> int StreamPeerMbedTLS : : bio_recv ( void * ctx , unsigned char * buf , size_t len ) { <nl> return got ; <nl> } <nl> <nl> + void StreamPeerMbedTLS : : _cleanup ( ) { <nl> + <nl> + mbedtls_ssl_free ( & ssl ) ; <nl> + mbedtls_ssl_config_free ( & conf ) ; <nl> + mbedtls_ctr_drbg_free ( & ctr_drbg ) ; <nl> + mbedtls_entropy_free ( & entropy ) ; <nl> + <nl> + base = Ref < StreamPeer > ( ) ; <nl> + status = STATUS_DISCONNECTED ; <nl> + } <nl> + <nl> + Error StreamPeerMbedTLS : : _do_handshake ( ) { <nl> + int ret = 0 ; <nl> + while ( ( ret = mbedtls_ssl_handshake ( & ssl ) ) ! = 0 ) { <nl> + if ( ret ! = MBEDTLS_ERR_SSL_WANT_READ & & ret ! = MBEDTLS_ERR_SSL_WANT_WRITE ) { <nl> + ERR_PRINTS ( " TLS handshake error : " + itos ( ret ) ) ; <nl> + _print_error ( ret ) ; <nl> + disconnect_from_stream ( ) ; <nl> + status = STATUS_ERROR ; <nl> + return FAILED ; <nl> + } else if ( ! blocking_handshake ) { <nl> + / / Will retry via poll later <nl> + return OK ; <nl> + } <nl> + } <nl> + <nl> + status = STATUS_CONNECTED ; <nl> + return OK ; <nl> + } <nl> + <nl> Error StreamPeerMbedTLS : : connect_to_stream ( Ref < StreamPeer > p_base , bool p_validate_certs , const String & p_for_hostname ) { <nl> <nl> base = p_base ; <nl> Error StreamPeerMbedTLS : : connect_to_stream ( Ref < StreamPeer > p_base , bool p_valida <nl> ret = mbedtls_ctr_drbg_seed ( & ctr_drbg , mbedtls_entropy_func , & entropy , NULL , 0 ) ; <nl> if ( ret ! = 0 ) { <nl> ERR_PRINTS ( " failed \ n ! mbedtls_ctr_drbg_seed returned an error " + itos ( ret ) ) ; <nl> + _cleanup ( ) ; <nl> return FAILED ; <nl> } <nl> <nl> Error StreamPeerMbedTLS : : connect_to_stream ( Ref < StreamPeer > p_base , bool p_valida <nl> <nl> mbedtls_ssl_set_bio ( & ssl , this , bio_send , bio_recv , NULL ) ; <nl> <nl> - while ( ( ret = mbedtls_ssl_handshake ( & ssl ) ) ! = 0 ) { <nl> - if ( ret ! = MBEDTLS_ERR_SSL_WANT_READ & & ret ! = MBEDTLS_ERR_SSL_WANT_WRITE ) { <nl> - ERR_PRINTS ( " TLS handshake error : " + itos ( ret ) ) ; <nl> - _print_error ( ret ) ; <nl> - status = STATUS_ERROR_HOSTNAME_MISMATCH ; <nl> - return FAILED ; <nl> - } <nl> - } <nl> + status = STATUS_HANDSHAKING ; <nl> <nl> - connected = true ; <nl> - status = STATUS_CONNECTED ; <nl> + if ( ( ret = _do_handshake ( ) ) ! = OK ) { <nl> + status = STATUS_ERROR_HOSTNAME_MISMATCH ; <nl> + return FAILED ; <nl> + } <nl> <nl> return OK ; <nl> } <nl> <nl> Error StreamPeerMbedTLS : : accept_stream ( Ref < StreamPeer > p_base ) { <nl> <nl> - return ERR_UNAVAILABLE ; <nl> + return OK ; <nl> } <nl> <nl> Error StreamPeerMbedTLS : : put_data ( const uint8_t * p_data , int p_bytes ) { <nl> <nl> - ERR_FAIL_COND_V ( ! connected , ERR_UNCONFIGURED ) ; <nl> + ERR_FAIL_COND_V ( status ! = STATUS_CONNECTED , ERR_UNCONFIGURED ) ; <nl> <nl> Error err ; <nl> int sent = 0 ; <nl> Error StreamPeerMbedTLS : : put_data ( const uint8_t * p_data , int p_bytes ) { <nl> <nl> Error StreamPeerMbedTLS : : put_partial_data ( const uint8_t * p_data , int p_bytes , int & r_sent ) { <nl> <nl> - ERR_FAIL_COND_V ( ! connected , ERR_UNCONFIGURED ) ; <nl> + ERR_FAIL_COND_V ( status ! = STATUS_CONNECTED , ERR_UNCONFIGURED ) ; <nl> <nl> r_sent = 0 ; <nl> <nl> Error StreamPeerMbedTLS : : put_partial_data ( const uint8_t * p_data , int p_bytes , in <nl> <nl> Error StreamPeerMbedTLS : : get_data ( uint8_t * p_buffer , int p_bytes ) { <nl> <nl> - ERR_FAIL_COND_V ( ! connected , ERR_UNCONFIGURED ) ; <nl> + ERR_FAIL_COND_V ( status ! = STATUS_CONNECTED , ERR_UNCONFIGURED ) ; <nl> <nl> Error err ; <nl> <nl> Error StreamPeerMbedTLS : : get_data ( uint8_t * p_buffer , int p_bytes ) { <nl> <nl> Error StreamPeerMbedTLS : : get_partial_data ( uint8_t * p_buffer , int p_bytes , int & r_received ) { <nl> <nl> - ERR_FAIL_COND_V ( ! connected , ERR_UNCONFIGURED ) ; <nl> + ERR_FAIL_COND_V ( status ! = STATUS_CONNECTED , ERR_UNCONFIGURED ) ; <nl> <nl> r_received = 0 ; <nl> <nl> Error StreamPeerMbedTLS : : get_partial_data ( uint8_t * p_buffer , int p_bytes , int & r <nl> <nl> void StreamPeerMbedTLS : : poll ( ) { <nl> <nl> - ERR_FAIL_COND ( ! connected ) ; <nl> + ERR_FAIL_COND ( status ! = STATUS_CONNECTED & & status ! = STATUS_HANDSHAKING ) ; <nl> ERR_FAIL_COND ( ! base . is_valid ( ) ) ; <nl> <nl> + if ( status = = STATUS_HANDSHAKING ) { <nl> + _do_handshake ( ) ; <nl> + return ; <nl> + } <nl> + <nl> int ret = mbedtls_ssl_read ( & ssl , NULL , 0 ) ; <nl> <nl> if ( ret < 0 & & ret ! = MBEDTLS_ERR_SSL_WANT_READ & & ret ! = MBEDTLS_ERR_SSL_WANT_WRITE ) { <nl> _print_error ( ret ) ; <nl> disconnect_from_stream ( ) ; <nl> - return ; <nl> } <nl> } <nl> <nl> int StreamPeerMbedTLS : : get_available_bytes ( ) const { <nl> <nl> - ERR_FAIL_COND_V ( ! connected , 0 ) ; <nl> + ERR_FAIL_COND_V ( status ! = STATUS_CONNECTED , 0 ) ; <nl> <nl> return mbedtls_ssl_get_bytes_avail ( & ssl ) ; <nl> } <nl> StreamPeerMbedTLS : : StreamPeerMbedTLS ( ) { <nl> <nl> - connected = false ; <nl> status = STATUS_DISCONNECTED ; <nl> } <nl> <nl> StreamPeerMbedTLS : : ~ StreamPeerMbedTLS ( ) { <nl> <nl> void StreamPeerMbedTLS : : disconnect_from_stream ( ) { <nl> <nl> - if ( ! connected ) <nl> + if ( status ! = STATUS_CONNECTED & & status ! = STATUS_HANDSHAKING ) <nl> return ; <nl> <nl> - mbedtls_ssl_free ( & ssl ) ; <nl> - mbedtls_ssl_config_free ( & conf ) ; <nl> - mbedtls_ctr_drbg_free ( & ctr_drbg ) ; <nl> - mbedtls_entropy_free ( & entropy ) ; <nl> - <nl> - base = Ref < StreamPeer > ( ) ; <nl> - connected = false ; <nl> - status = STATUS_DISCONNECTED ; <nl> + _cleanup ( ) ; <nl> } <nl> <nl> StreamPeerMbedTLS : : Status StreamPeerMbedTLS : : get_status ( ) const { <nl> mmm a / modules / mbedtls / stream_peer_mbed_tls . h <nl> ppp b / modules / mbedtls / stream_peer_mbed_tls . h <nl> class StreamPeerMbedTLS : public StreamPeerSSL { <nl> Status status ; <nl> String hostname ; <nl> <nl> - bool connected ; <nl> - <nl> Ref < StreamPeer > base ; <nl> <nl> static StreamPeerSSL * _create_func ( ) ; <nl> class StreamPeerMbedTLS : public StreamPeerSSL { <nl> <nl> static int bio_recv ( void * ctx , unsigned char * buf , size_t len ) ; <nl> static int bio_send ( void * ctx , const unsigned char * buf , size_t len ) ; <nl> + void _cleanup ( ) ; <nl> <nl> protected : <nl> static mbedtls_x509_crt cacert ; <nl> + <nl> mbedtls_entropy_context entropy ; <nl> mbedtls_ctr_drbg_context ctr_drbg ; <nl> mbedtls_ssl_context ssl ; <nl> class StreamPeerMbedTLS : public StreamPeerSSL { <nl> <nl> static void _bind_methods ( ) ; <nl> <nl> + Error _do_handshake ( ) ; <nl> + <nl> public : <nl> virtual void poll ( ) ; <nl> virtual Error accept_stream ( Ref < StreamPeer > p_base ) ; <nl>
Implement non blocking - handshake for StreamPeerSSL
godotengine/godot
99d0b7ba14ee98a6a712c5cbb65af4fd37f2cf56
2018-07-16T11:08:17Z
mmm a / src / SimpleRandomizer . cc <nl> ppp b / src / SimpleRandomizer . cc <nl> void SimpleRandomizer : : getRandomBytes ( unsigned char * buf , size_t len ) <nl> if ( rv < - 1 ) { <nl> A2_LOG_ERROR ( fmt ( " Failed to produce randomness : % d " , errno ) ) ; <nl> } <nl> + / / getrandom is not supposed to fail , ever , so , we want to assert here . <nl> assert ( rv > = 0 & & ( size_t ) rv = = len ) ; <nl> return ; <nl> } <nl> mmm a / src / getrandom_linux . c <nl> ppp b / src / getrandom_linux . c <nl> <nl> int getrandom_linux ( void * buf , size_t buflen ) { <nl> int rv = 0 ; <nl> uint8_t * p = buf ; <nl> + <nl> + / * Loop while we did not fully retrieve what the user asked for . <nl> + * This may happen in particular when a call was EINTRupted . <nl> + * / <nl> while ( buflen ) { <nl> int read ; <nl> # ifdef HAVE_GETRANDOM <nl> + / * libc already has support * / <nl> read = getrandom ( p , buflen , 0 ) ; <nl> # else / / HAVE_GETRANDOM <nl> + / * libc has no support , make the syscall ourselves * / <nl> read = syscall ( SYS_getrandom , p , buflen , 0 ) ; <nl> - / * Some libc impl . might mess this up * / <nl> + / * Some libc impl . might mess - ERESTART up * / <nl> if ( read = = - EINTR | | read = = - ERESTART ) { <nl> + / * ERESTART , like EINTR , should restart the call , later , so handle both <nl> + * the same way . <nl> + * / <nl> errno = EINTR ; <nl> read = - 1 ; <nl> } <nl> + / * Some other non - interrupted error happened , put error code into errno and <nl> + * switch read to - 1 ( return value ) . <nl> + * / <nl> if ( read < - 1 ) { <nl> errno = - read ; <nl> read = - 1 ; <nl> int getrandom_linux ( void * buf , size_t buflen ) { <nl> # endif / / HAVE_GETRANDOM <nl> if ( read < 0 ) { <nl> if ( errno = = EINTR ) { <nl> + / * Restart call * / <nl> continue ; <nl> } <nl> + / * Call failed , return - 1 , errno should be set up correctly at this <nl> + * point . <nl> + * / <nl> return - 1 ; <nl> } <nl> + / * We got some more randomness * / <nl> p + = read ; <nl> rv + = read ; <nl> buflen - = read ; <nl> } <nl> + <nl> return rv ; <nl> } <nl>
Comment getrandom code a bit
aria2/aria2
c248d456d194532098747055dd75a28118d77521
2015-03-18T00:46:26Z
mmm a / tensorflow / compiler / tf2xla / tf2xla . cc <nl> ppp b / tensorflow / compiler / tf2xla / tf2xla . cc <nl> Status ConvertVarHandlesToAotVarHandles ( GraphDef * graph_def ) { <nl> const auto & it = node . attr ( ) . find ( " allowed_devices " ) ; <nl> if ( it ! = node . attr ( ) . end ( ) ) { <nl> if ( ! it - > second . list ( ) . s ( ) . empty ( ) ) { <nl> - / / TODO ( b / 149512838 ) : Support non - empty allowed devices . <nl> return errors : : InvalidArgument ( <nl> " VarHandleOp with non - empty allowed devices is not supported . " ) ; <nl> } <nl>
Remove an obsolete TODO since allowed_device has been deprecated .
tensorflow/tensorflow
44aa25ec4609778fae9ce4e4a157c0df095f2362
2020-08-20T22:54:51Z
mmm a / base / common / sleep . cpp <nl> ppp b / base / common / sleep . cpp <nl> void sleepForNanoseconds ( uint64_t nanoseconds ) <nl> # if defined ( OS_DARWIN ) <nl> / / https : / / developer . apple . com / library / archive / technotes / tn2169 / _index . html <nl> / / https : / / dshil . github . io / blog / missed - os - x - clock - guide / <nl> - static mach_timebase_info_data_t timebase_info = { 0 } ; <nl> + static mach_timebase_info_data_t timebase_info { } ; <nl> if ( timebase_info . denom = = 0 ) <nl> mach_timebase_info ( & timebase_info ) ; <nl> <nl>
Fix build
ClickHouse/ClickHouse
3b97b4118880da5bb34639a766768383396651ce
2020-05-10T19:28:40Z
mmm a / include / tesseract / genericvector . h <nl> ppp b / include / tesseract / genericvector . h <nl> class GenericVector : public std : : vector < T > { <nl> std : : function < bool ( const T & , const T & ) > compare_cb_ ; <nl> } ; <nl> <nl> - # if defined ( _MSC_VER ) <nl> - / / msvc stl does not have : : data ( ) in vector < bool > , <nl> - / / so we add custom specialization <nl> + # if defined ( _MSC_VER ) | | defined ( __APPLE__ ) <nl> + / / MSVC stl does not have : : data ( ) in vector < bool > , <nl> + / / so we add custom specialization . <nl> + / / On Apple there are also errors when using std : : vector < bool > , <nl> + / / so we replace it with vector < int > as a workaround . <nl> template < > <nl> - class GenericVector < bool > : public std : : vector < bool > { } ; <nl> + class GenericVector < bool > : public std : : vector < int > { } ; <nl> # endif <nl> <nl> / / The default FileReader loads the whole file into the vector of char , <nl>
Another msvc / macos fix attempt .
tesseract-ocr/tesseract
b2b2d021678fe925b3cc31aa57590111da662bac
2020-12-26T12:09:03Z
mmm a / src / debug . cc <nl> ppp b / src / debug . cc <nl> void BreakLocationIterator : : SetDebugBreakAtIC ( ) { <nl> / / is set the patching performed by the runtime system will take place in <nl> / / the code copy and will therefore have no effect on the running code <nl> / / keeping it from using the inlined code . <nl> - if ( code - > is_keyed_load_stub ( ) ) KeyedLoadIC : : ClearInlinedVersion ( pc ( ) ) ; <nl> - if ( code - > is_keyed_store_stub ( ) ) KeyedStoreIC : : ClearInlinedVersion ( pc ( ) ) ; <nl> + if ( code - > is_keyed_load_stub ( ) ) { <nl> + KeyedLoadIC : : ClearInlinedVersion ( pc ( ) ) ; <nl> + } else if ( code - > is_keyed_store_stub ( ) ) { <nl> + KeyedStoreIC : : ClearInlinedVersion ( pc ( ) ) ; <nl> + } else if ( code - > is_load_stub ( ) ) { <nl> + LoadIC : : ClearInlinedVersion ( pc ( ) ) ; <nl> + } <nl> } <nl> } <nl> <nl> mmm a / src / ic . cc <nl> ppp b / src / ic . cc <nl> Object * LoadIC : : Load ( State state , Handle < Object > object , Handle < String > name ) { <nl> # ifdef DEBUG <nl> if ( FLAG_trace_ic ) PrintF ( " [ LoadIC : + # length / string ] \ n " ) ; <nl> # endif <nl> + Map * map = HeapObject : : cast ( * object ) - > map ( ) ; <nl> + if ( object - > IsString ( ) ) { <nl> + const int offset = String : : kLengthOffset ; <nl> + PatchInlinedLoad ( address ( ) , map , offset ) ; <nl> + } <nl> + <nl> Code * target = NULL ; <nl> target = Builtins : : builtin ( Builtins : : LoadIC_StringLength ) ; <nl> set_target ( target ) ; <nl> - StubCache : : Set ( * name , HeapObject : : cast ( * object ) - > map ( ) , target ) ; <nl> + StubCache : : Set ( * name , map , target ) ; <nl> return Smi : : FromInt ( String : : cast ( * object ) - > length ( ) ) ; <nl> } <nl> <nl> Object * LoadIC : : Load ( State state , Handle < Object > object , Handle < String > name ) { <nl> # ifdef DEBUG <nl> if ( FLAG_trace_ic ) PrintF ( " [ LoadIC : + # length / array ] \ n " ) ; <nl> # endif <nl> + Map * map = HeapObject : : cast ( * object ) - > map ( ) ; <nl> + const int offset = JSArray : : kLengthOffset ; <nl> + PatchInlinedLoad ( address ( ) , map , offset ) ; <nl> + <nl> Code * target = Builtins : : builtin ( Builtins : : LoadIC_ArrayLength ) ; <nl> set_target ( target ) ; <nl> - StubCache : : Set ( * name , HeapObject : : cast ( * object ) - > map ( ) , target ) ; <nl> + StubCache : : Set ( * name , map , target ) ; <nl> return JSArray : : cast ( * object ) - > length ( ) ; <nl> } <nl> <nl> mmm a / src / ic . h <nl> ppp b / src / ic . h <nl> class LoadIC : public IC { <nl> static void GenerateStringLength ( MacroAssembler * masm ) ; <nl> static void GenerateFunctionPrototype ( MacroAssembler * masm ) ; <nl> <nl> + / / Clear the use of the inlined version . <nl> + static void ClearInlinedVersion ( Address address ) ; <nl> + <nl> / / The offset from the inlined patch site to the start of the <nl> / / inlined load instruction . It is architecture - dependent , and not <nl> / / used on ARM . <nl> class LoadIC : public IC { <nl> <nl> static void Clear ( Address address , Code * target ) ; <nl> <nl> - / / Clear the use of the inlined version . <nl> - static void ClearInlinedVersion ( Address address ) ; <nl> - <nl> static bool PatchInlinedLoad ( Address address , Object * map , int index ) ; <nl> <nl> friend class IC ; <nl> mmm a / test / cctest / test - debug . cc <nl> ppp b / test / cctest / test - debug . cc <nl> TEST ( DebugStepKeyedStoreLoop ) { <nl> } <nl> <nl> <nl> + / / Test of the stepping mechanism for named load in a loop . <nl> + TEST ( DebugStepNamedLoadLoop ) { <nl> + v8 : : HandleScope scope ; <nl> + DebugLocalContext env ; <nl> + <nl> + / / Create a function for testing stepping of named load . <nl> + v8 : : Local < v8 : : Function > foo = CompileFunction ( <nl> + & env , <nl> + " function foo ( ) { \ n " <nl> + " var a = [ ] ; \ n " <nl> + " var s = \ " \ " ; \ n " <nl> + " for ( var i = 0 ; i < 10 ; i + + ) { \ n " <nl> + " var v = new V ( i , i + 1 ) ; \ n " <nl> + " v . y ; \ n " <nl> + " a . length ; \ n " / / Special case : array length . <nl> + " s . length ; \ n " / / Special case : string length . <nl> + " } \ n " <nl> + " } \ n " <nl> + " function V ( x , y ) { \ n " <nl> + " this . x = x ; \ n " <nl> + " this . y = y ; \ n " <nl> + " } \ n " , <nl> + " foo " ) ; <nl> + <nl> + / / Call function without any break points to ensure inlining is in place . <nl> + foo - > Call ( env - > Global ( ) , 0 , NULL ) ; <nl> + <nl> + / / Register a debug event listener which steps and counts . <nl> + v8 : : Debug : : SetDebugEventListener ( DebugEventStep ) ; <nl> + <nl> + / / Setup break point and step through the function . <nl> + SetBreakPoint ( foo , 4 ) ; <nl> + step_action = StepNext ; <nl> + break_point_hit_count = 0 ; <nl> + foo - > Call ( env - > Global ( ) , 0 , NULL ) ; <nl> + <nl> + / / With stepping all break locations are hit . <nl> + CHECK_EQ ( 41 , break_point_hit_count ) ; <nl> + <nl> + v8 : : Debug : : SetDebugEventListener ( NULL ) ; <nl> + CheckDebuggerUnloaded ( ) ; <nl> + } <nl> + <nl> + <nl> / / Test the stepping mechanism with different ICs . <nl> TEST ( DebugStepLinearMixedICs ) { <nl> v8 : : HandleScope scope ; <nl>
Inlined load of string . length and array . length .
v8/v8
eaa95c523bb09ab9d396a04a0ba1778dcf1d012b
2010-05-06T10:50:22Z
mmm a / folly / File . cpp <nl> ppp b / folly / File . cpp <nl> File & File : : operator = ( File & & other ) { <nl> } <nl> <nl> File : : ~ File ( ) { <nl> - closeNoThrow ( ) ; / / ignore error <nl> + auto fd = fd_ ; <nl> + if ( ! closeNoThrow ( ) ) { / / ignore most errors <nl> + DCHECK_NE ( errno , EBADF ) < < " closing fd " < < fd < < " , it may already " <nl> + < < " have been closed . Another time , this might close the wrong FD . " ; <nl> + } <nl> } <nl> <nl> / * static * / File File : : temporary ( ) { <nl>
Destructor DCHECKs for EBADF
facebook/folly
ec3c8f790fc7e8d870d518211e124830c4bdf1d3
2015-05-12T00:02:34Z
mmm a / contracts / eosio . system / producers_election . hpp <nl> ppp b / contracts / eosio . system / producers_election . hpp <nl> namespace eosiosystem { <nl> EOSLIB_SERIALIZE ( unstake_request , ( id ) ( account ) ( amount ) ( refund_time ) ) <nl> } ; <nl> <nl> - typedef eosio : : multi_index < N ( unstakerequests ) , unstake_request , <nl> + typedef eosio : : multi_index < N ( unstakereqs ) , unstake_request , <nl> indexed_by < N ( bytime ) , const_mem_fun < unstake_request , uint64_t , & unstake_request : : rt > > <nl> > unstake_requests_table ; <nl> <nl>
table name fix
EOSIO/eos
e21cb1d32a0f56edc624a2e4558e7fd4f926918a
2018-02-22T23:51:16Z
mmm a / benchmark / single - source / DictionarySwap . swift <nl> ppp b / benchmark / single - source / DictionarySwap . swift <nl> <nl> / / rdar : / / problem / 19804127 <nl> import TestsUtils <nl> <nl> + let size = 100 <nl> + let numberMap = Dictionary ( uniqueKeysWithValues : zip ( 1 . . . size , 1 . . . size ) ) <nl> + let boxedNums = ( 1 . . . size ) . lazy . map { Box ( $ 0 ) } <nl> + let boxedNumMap = Dictionary ( uniqueKeysWithValues : zip ( boxedNums , boxedNums ) ) <nl> + <nl> let t : [ BenchmarkCategory ] = [ . validation , . api , . Dictionary ] <nl> <nl> public let DictionarySwap = [ <nl> BenchmarkInfo ( name : " DictionarySwap " , <nl> - runFunction : run_DictionarySwap , tags : t , legacyFactor : 4 ) , <nl> + runFunction : { <nl> + var dict = numberMap <nl> + var swapped = false <nl> + for _ in 1 . . . $ 0 * 2500 { <nl> + ( dict [ 25 ] , dict [ 75 ] ) = ( dict [ 75 ] ! , dict [ 25 ] ! ) <nl> + swapped = ! swapped <nl> + CheckResults ( swappedCorrectly ( swapped , dict [ 25 ] ! , dict [ 75 ] ! ) ) <nl> + } } , tags : t , legacyFactor : 4 ) , <nl> BenchmarkInfo ( name : " DictionarySwapOfObjects " , <nl> - runFunction : run_DictionarySwapOfObjects , tags : t , legacyFactor : 40 ) , <nl> + runFunction : { <nl> + var dict = boxedNumMap <nl> + var swapped = false <nl> + for _ in 1 . . . $ 0 * 250 { <nl> + let b1 = Box ( 25 ) <nl> + let b2 = Box ( 75 ) <nl> + ( dict [ b1 ] , dict [ b2 ] ) = ( dict [ b2 ] ! , dict [ b1 ] ! ) <nl> + swapped = ! swapped <nl> + CheckResults ( swappedCorrectly ( swapped , <nl> + dict [ Box ( 25 ) ] ! . value , dict [ Box ( 75 ) ] ! . value ) ) <nl> + } } , tags : t , legacyFactor : 40 ) , <nl> BenchmarkInfo ( name : " DictionarySwapAt " , <nl> - runFunction : run_DictionarySwapAt , tags : t , legacyFactor : 4 ) , <nl> + runFunction : { <nl> + var dict = numberMap <nl> + var swapped = false <nl> + for _ in 1 . . . $ 0 * 2500 { <nl> + let i25 = dict . index ( forKey : 25 ) ! <nl> + let i75 = dict . index ( forKey : 75 ) ! <nl> + dict . values . swapAt ( i25 , i75 ) <nl> + swapped = ! swapped <nl> + CheckResults ( swappedCorrectly ( swapped , dict [ 25 ] ! , dict [ 75 ] ! ) ) <nl> + } } , tags : t , legacyFactor : 4 ) , <nl> BenchmarkInfo ( name : " DictionarySwapAtOfObjects " , <nl> - runFunction : run_DictionarySwapAtOfObjects , tags : t , legacyFactor : 40 ) , <nl> - ] <nl> - <nl> - @ inline ( never ) <nl> - public func run_DictionarySwap ( _ N : Int ) { <nl> - let size = 100 <nl> - var dict = [ Int : Int ] ( minimumCapacity : size ) <nl> - <nl> - / / Fill dictionary <nl> - for i in 1 . . . size { <nl> - dict [ i ] = i <nl> - } <nl> - CheckResults ( dict . count = = size ) <nl> - <nl> - var swapped = false <nl> - for _ in 1 . . . 2500 * N { <nl> - ( dict [ 25 ] , dict [ 75 ] ) = ( dict [ 75 ] ! , dict [ 25 ] ! ) <nl> + runFunction : { <nl> + var dict = boxedNumMap <nl> + var swapped = false <nl> + for _ in 1 . . . $ 0 * 250 { <nl> + let i25 = dict . index ( forKey : Box ( 25 ) ) ! <nl> + let i75 = dict . index ( forKey : Box ( 75 ) ) ! <nl> + dict . values . swapAt ( i25 , i75 ) <nl> swapped = ! swapped <nl> - if ! swappedCorrectly ( swapped , dict [ 25 ] ! , dict [ 75 ] ! ) { <nl> - break <nl> - } <nl> - } <nl> - <nl> - CheckResults ( swappedCorrectly ( swapped , dict [ 25 ] ! , dict [ 75 ] ! ) ) <nl> - } <nl> - <nl> - @ inline ( never ) <nl> - public func run_DictionarySwapAt ( _ N : Int ) { <nl> - let size = 100 <nl> - var dict = [ Int : Int ] ( minimumCapacity : size ) <nl> - <nl> - / / Fill dictionary <nl> - for i in 1 . . . size { <nl> - dict [ i ] = i <nl> - } <nl> - CheckResults ( dict . count = = size ) <nl> - <nl> - var swapped = false <nl> - for _ in 1 . . . 2500 * N { <nl> - let i25 = dict . index ( forKey : 25 ) ! <nl> - let i75 = dict . index ( forKey : 75 ) ! <nl> - <nl> - dict . values . swapAt ( i25 , i75 ) <nl> - swapped = ! swapped <nl> - if ! swappedCorrectly ( swapped , dict [ 25 ] ! , dict [ 75 ] ! ) { <nl> - break <nl> - } <nl> - } <nl> - <nl> - CheckResults ( swappedCorrectly ( swapped , dict [ 25 ] ! , dict [ 75 ] ! ) ) <nl> - } <nl> + CheckResults ( swappedCorrectly ( swapped , <nl> + dict [ Box ( 25 ) ] ! . value , dict [ Box ( 75 ) ] ! . value ) ) <nl> + } } , tags : t , legacyFactor : 40 ) , <nl> + ] <nl> <nl> / / Return true if correctly swapped , false otherwise <nl> func swappedCorrectly ( _ swapped : Bool , _ p25 : Int , _ p75 : Int ) - > Bool { <nl> class Box < T : Hashable > : Hashable { <nl> return lhs . value = = rhs . value <nl> } <nl> } <nl> - <nl> - @ inline ( never ) <nl> - public func run_DictionarySwapOfObjects ( _ N : Int ) { <nl> - let size = 100 <nl> - var dict = Dictionary < Box < Int > , Box < Int > > ( minimumCapacity : size ) <nl> - <nl> - / / Fill dictionary <nl> - for i in 1 . . . size { <nl> - dict [ Box ( i ) ] = Box ( i ) <nl> - } <nl> - CheckResults ( dict . count = = size ) <nl> - <nl> - var swapped = false <nl> - for _ in 1 . . . 250 * N { <nl> - let b1 = Box ( 25 ) <nl> - let b2 = Box ( 75 ) <nl> - ( dict [ b1 ] , dict [ b2 ] ) = ( dict [ b2 ] ! , dict [ b1 ] ! ) <nl> - swapped = ! swapped <nl> - if ! swappedCorrectly ( swapped , dict [ Box ( 25 ) ] ! . value , dict [ Box ( 75 ) ] ! . value ) { <nl> - break <nl> - } <nl> - } <nl> - <nl> - CheckResults ( swappedCorrectly ( swapped , dict [ Box ( 25 ) ] ! . value , dict [ Box ( 75 ) ] ! . value ) ) <nl> - } <nl> - <nl> - @ inline ( never ) <nl> - public func run_DictionarySwapAtOfObjects ( _ N : Int ) { <nl> - let size = 100 <nl> - var dict = [ Box < Int > : Box < Int > ] ( minimumCapacity : size ) <nl> - <nl> - / / Fill dictionary <nl> - for i in 1 . . . size { <nl> - dict [ Box ( i ) ] = Box ( i ) <nl> - } <nl> - CheckResults ( dict . count = = size ) <nl> - <nl> - var swapped = false <nl> - for _ in 1 . . . 250 * N { <nl> - let b25 = Box ( 25 ) <nl> - let b75 = Box ( 75 ) <nl> - let i25 = dict . index ( forKey : b25 ) ! <nl> - let i75 = dict . index ( forKey : b75 ) ! <nl> - <nl> - dict . values . swapAt ( i25 , i75 ) <nl> - swapped = ! swapped <nl> - if ! swappedCorrectly ( swapped , dict [ Box ( 25 ) ] ! . value , dict [ Box ( 75 ) ] ! . value ) { <nl> - break <nl> - } <nl> - } <nl> - <nl> - CheckResults ( swappedCorrectly ( swapped , dict [ Box ( 25 ) ] ! . value , dict [ Box ( 75 ) ] ! . value ) ) <nl> - } <nl>
[ benchmark ] DictionarySwap Setup Overhead
apple/swift
aa977ad3f60e2692c5a187f13013de630d7dbaa3
2019-02-19T22:50:50Z
mmm a / include / swift / AST / Module . h <nl> ppp b / include / swift / AST / Module . h <nl> <nl> # include " llvm / ADT / STLExtras . h " <nl> # include " llvm / ADT / TinyPtrVector . h " <nl> # include " llvm / Support / ErrorHandling . h " <nl> + # include " llvm / Support / MD5 . h " <nl> <nl> namespace clang { <nl> class Module ; <nl> class SourceFile final : public FileUnit { <nl> / / / The source location of the main class . <nl> SourceLoc MainClassDiagLoc ; <nl> <nl> + / / / A hash of all interface - contributing tokens that have been lexed for <nl> + / / / this source file so far . <nl> + llvm : : MD5 InterfaceHash ; <nl> + <nl> / / / \ brief The ID for the memory buffer containing this file ' s source . <nl> / / / <nl> / / / May be - 1 , to indicate no association with a buffer . <nl> class SourceFile final : public FileUnit { <nl> <nl> / / / Set the root refinement context for the file . <nl> void setTypeRefinementContext ( TypeRefinementContext * TRC ) ; <nl> + <nl> + void recordInterfaceToken ( StringRef token ) { <nl> + assert ( ! token . empty ( ) ) ; <nl> + InterfaceHash . update ( token ) ; <nl> + / / Add null byte to separate tokens . <nl> + uint8_t a [ 1 ] = { 0 } ; <nl> + InterfaceHash . update ( a ) ; <nl> + } <nl> + <nl> + void getInterfaceHash ( llvm : : SmallString < 32 > & str ) { <nl> + llvm : : MD5 : : MD5Result result ; <nl> + InterfaceHash . final ( result ) ; <nl> + llvm : : MD5 : : stringifyResult ( result , str ) ; <nl> + } <nl> + <nl> + void dumpInterfaceHash ( llvm : : raw_ostream & out ) { <nl> + llvm : : SmallString < 32 > str ; <nl> + getInterfaceHash ( str ) ; <nl> + out < < str < < ' \ n ' ; <nl> + } <nl> } ; <nl> <nl> <nl> mmm a / include / swift / Frontend / FrontendOptions . h <nl> ppp b / include / swift / Frontend / FrontendOptions . h <nl> class FrontendOptions { <nl> NoneAction , / / / < No specific action <nl> Parse , / / / < Parse and type - check only <nl> DumpParse , / / / < Parse only and dump AST <nl> + DumpInterfaceHash , / / / < Parse and dump the interface token hash . <nl> DumpAST , / / / < Parse , type - check , and dump AST <nl> PrintAST , / / / < Parse , type - check , and pretty - print AST <nl> <nl> mmm a / include / swift / Option / FrontendOptions . td <nl> ppp b / include / swift / Option / FrontendOptions . td <nl> def external_pass_pipeline_filename : Separate < [ " - " ] , " external - pass - pipeline - fi <nl> HelpText < " Use the pass pipeline defined by < pass_pipeline_file > " > , <nl> MetaVarName < " < pass_pipeline_file > " > ; <nl> <nl> + def dump_interface_hash : Flag < [ " - " ] , " dump - interface - hash " > , <nl> + HelpText < " Parse input file ( s ) and dump interface token hash ( es ) " > , <nl> + ModeOpt ; <nl> + <nl> } / / end let Flags = [ FrontendOption , NoDriverOption , HelpHidden ] <nl> mmm a / include / swift / Parse / Parser . h <nl> ppp b / include / swift / Parse / Parser . h <nl> class Parser { <nl> ASTContext & Context ; <nl> CodeCompletionCallbacks * CodeCompletion = nullptr ; <nl> std : : vector < std : : pair < SourceLoc , std : : vector < VarDecl * > > > AnonClosureVars ; <nl> + <nl> + bool IsParsingInterfaceTokens = false ; <nl> <nl> / / / DisabledVars is a list of variables for whom local name lookup is <nl> / / / disabled . This is used when parsing a PatternBindingDecl to reject self <nl> mmm a / lib / Driver / Driver . cpp <nl> ppp b / lib / Driver / Driver . cpp <nl> void Driver : : buildOutputInfo ( const ToolChain & TC , const DerivedArgList & Args , <nl> case options : : OPT_dump_ast : <nl> case options : : OPT_print_ast : <nl> case options : : OPT_dump_type_refinement_contexts : <nl> + case options : : OPT_dump_interface_hash : <nl> OI . CompilerOutputType = types : : TY_Nothing ; <nl> break ; <nl> <nl> mmm a / lib / Frontend / CompilerInvocation . cpp <nl> ppp b / lib / Frontend / CompilerInvocation . cpp <nl> static bool ParseFrontendArgs ( FrontendOptions & Opts , ArgList & Args , <nl> Action = FrontendOptions : : DumpAST ; <nl> } else if ( Opt . matches ( OPT_dump_type_refinement_contexts ) ) { <nl> Action = FrontendOptions : : DumpTypeRefinementContexts ; <nl> + } else if ( Opt . matches ( OPT_dump_interface_hash ) ) { <nl> + Action = FrontendOptions : : DumpInterfaceHash ; <nl> } else if ( Opt . matches ( OPT_print_ast ) ) { <nl> Action = FrontendOptions : : PrintAST ; <nl> } else if ( Opt . matches ( OPT_repl ) | | <nl> static bool ParseFrontendArgs ( FrontendOptions & Opts , ArgList & Args , <nl> <nl> case FrontendOptions : : Parse : <nl> case FrontendOptions : : DumpParse : <nl> + case FrontendOptions : : DumpInterfaceHash : <nl> case FrontendOptions : : DumpAST : <nl> case FrontendOptions : : PrintAST : <nl> case FrontendOptions : : DumpTypeRefinementContexts : <nl> static bool ParseFrontendArgs ( FrontendOptions & Opts , ArgList & Args , <nl> switch ( Opts . RequestedAction ) { <nl> case FrontendOptions : : NoneAction : <nl> case FrontendOptions : : DumpParse : <nl> + case FrontendOptions : : DumpInterfaceHash : <nl> case FrontendOptions : : DumpAST : <nl> case FrontendOptions : : PrintAST : <nl> case FrontendOptions : : DumpTypeRefinementContexts : <nl> static bool ParseFrontendArgs ( FrontendOptions & Opts , ArgList & Args , <nl> switch ( Opts . RequestedAction ) { <nl> case FrontendOptions : : NoneAction : <nl> case FrontendOptions : : DumpParse : <nl> + case FrontendOptions : : DumpInterfaceHash : <nl> case FrontendOptions : : DumpAST : <nl> case FrontendOptions : : PrintAST : <nl> case FrontendOptions : : DumpTypeRefinementContexts : <nl> static bool ParseFrontendArgs ( FrontendOptions & Opts , ArgList & Args , <nl> case FrontendOptions : : NoneAction : <nl> case FrontendOptions : : Parse : <nl> case FrontendOptions : : DumpParse : <nl> + case FrontendOptions : : DumpInterfaceHash : <nl> case FrontendOptions : : DumpAST : <nl> case FrontendOptions : : PrintAST : <nl> case FrontendOptions : : DumpTypeRefinementContexts : <nl> mmm a / lib / Frontend / FrontendOptions . cpp <nl> ppp b / lib / Frontend / FrontendOptions . cpp <nl> bool FrontendOptions : : actionHasOutput ( ) const { <nl> case Parse : <nl> case DumpParse : <nl> case DumpAST : <nl> + case DumpInterfaceHash : <nl> case PrintAST : <nl> case DumpTypeRefinementContexts : <nl> return false ; <nl> bool FrontendOptions : : actionIsImmediate ( ) const { <nl> case Parse : <nl> case DumpParse : <nl> case DumpAST : <nl> + case DumpInterfaceHash : <nl> case PrintAST : <nl> case DumpTypeRefinementContexts : <nl> case EmitSILGen : <nl> mmm a / lib / Parse / ParseDecl . cpp <nl> ppp b / lib / Parse / ParseDecl . cpp <nl> bool Parser : : parseGetSetImpl ( ParseDeclOptions Flags , Pattern * Indices , <nl> <nl> / / Parse the body . <nl> SmallVector < ASTNode , 16 > Entries ; <nl> - if ( ! isDelayedParsingEnabled ( ) ) <nl> - parseBraceItems ( Entries ) ; <nl> - else <nl> - consumeGetSetBody ( TheDecl , LBLoc ) ; <nl> + { <nl> + llvm : : SaveAndRestore < bool > T ( IsParsingInterfaceTokens , false ) ; <nl> + if ( ! isDelayedParsingEnabled ( ) ) <nl> + parseBraceItems ( Entries ) ; <nl> + else <nl> + consumeGetSetBody ( TheDecl , LBLoc ) ; <nl> + } <nl> <nl> SourceLoc RBLoc ; <nl> if ( ! isImplicitGet ) { <nl> Parser : : parseDeclFunc ( SourceLoc StaticLoc , StaticSpellingKind StaticSpelling , <nl> <nl> / / Check to see if we have a " { " to start a brace statement . <nl> if ( Tok . is ( tok : : l_brace ) ) { <nl> + / / Record the curly braces but nothing inside . <nl> + SF . recordInterfaceToken ( " { " ) ; <nl> + SF . recordInterfaceToken ( " } " ) ; <nl> + llvm : : SaveAndRestore < bool > T ( IsParsingInterfaceTokens , false ) ; <nl> + <nl> if ( Flags . contains ( PD_InProtocol ) ) { <nl> diagnose ( Tok , diag : : protocol_method_with_body ) ; <nl> skipUntilDeclRBrace ( ) ; <nl> Parser : : parseDeclInit ( ParseDeclOptions Flags , DeclAttributes & Attributes ) { <nl> <nl> / / ' { ' <nl> if ( Tok . is ( tok : : l_brace ) ) { <nl> - <nl> + / / Record the curly braces but nothing inside . <nl> + SF . recordInterfaceToken ( " { " ) ; <nl> + SF . recordInterfaceToken ( " } " ) ; <nl> + llvm : : SaveAndRestore < bool > T ( IsParsingInterfaceTokens , false ) ; <nl> + <nl> if ( Flags . contains ( PD_InProtocol ) ) { <nl> diagnose ( Tok , diag : : protocol_init_with_body ) ; <nl> skipUntilDeclRBrace ( ) ; <nl> parseDeclDeinit ( ParseDeclOptions Flags , DeclAttributes & Attributes ) { <nl> <nl> / / Parse the body . <nl> if ( Tok . is ( tok : : l_brace ) ) { <nl> + / / Record the curly braces but nothing inside . <nl> + SF . recordInterfaceToken ( " { " ) ; <nl> + SF . recordInterfaceToken ( " } " ) ; <nl> + llvm : : SaveAndRestore < bool > T ( IsParsingInterfaceTokens , false ) ; <nl> + <nl> ParseFunctionBody CC ( * this , DD ) ; <nl> if ( ! isDelayedParsingEnabled ( ) ) { <nl> ParserResult < BraceStmt > Body = parseBraceItemList ( diag : : invalid_diagnostic ) ; <nl> mmm a / lib / Parse / Parser . cpp <nl> ppp b / lib / Parse / Parser . cpp <nl> bool swift : : parseIntoSourceFile ( SourceFile & SF , <nl> Parser P ( BufferID , SF , SIL , PersistentState ) ; <nl> PrettyStackTraceParser StackTrace ( P ) ; <nl> <nl> + llvm : : SaveAndRestore < bool > S ( P . IsParsingInterfaceTokens , true ) ; <nl> + <nl> if ( DelayedParseCB ) <nl> P . setDelayedParsingCallbacks ( DelayedParseCB ) ; <nl> <nl> const Token & Parser : : peekToken ( ) { <nl> SourceLoc Parser : : consumeToken ( ) { <nl> SourceLoc Loc = Tok . getLoc ( ) ; <nl> assert ( Tok . isNot ( tok : : eof ) & & " Lexing past eof ! " ) ; <nl> + <nl> + if ( IsParsingInterfaceTokens & & ! Tok . getText ( ) . empty ( ) ) { <nl> + SF . recordInterfaceToken ( Tok . getText ( ) ) ; <nl> + } <nl> + <nl> L - > lex ( Tok ) ; <nl> PreviousLoc = Loc ; <nl> return Loc ; <nl> new file mode 100644 <nl> index 000000000000 . . c70f34a306ea <nl> mmm / dev / null <nl> ppp b / test / InterfaceHash / added_function . swift <nl> <nl> + / / RUN : mkdir - p % t <nl> + / / RUN : % S / . . / . . / utils / split_file . py - o % t % s <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / a . swift 2 > % t / a . hash <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / b . swift 2 > % t / b . hash <nl> + / / RUN : not cmp % t / a . hash % t / b . hash <nl> + <nl> + / / BEGIN a . swift <nl> + func f ( ) { } <nl> + <nl> + / / BEGIN b . swift <nl> + func f ( ) { } <nl> + func g ( ) { } <nl> new file mode 100644 <nl> index 000000000000 . . 65799ff38c2a <nl> mmm / dev / null <nl> ppp b / test / InterfaceHash / added_method . swift <nl> <nl> + / / RUN : mkdir - p % t <nl> + / / RUN : % S / . . / . . / utils / split_file . py - o % t % s <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / a . swift 2 > % t / a . hash <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / b . swift 2 > % t / b . hash <nl> + / / RUN : not cmp % t / a . hash % t / b . hash <nl> + <nl> + / / BEGIN a . swift <nl> + class C { <nl> + func f2 ( ) - > Int { <nl> + return 0 <nl> + } <nl> + } <nl> + <nl> + / / BEGIN b . swift <nl> + class C { <nl> + func f2 ( ) - > Int { <nl> + return 0 <nl> + } <nl> + <nl> + func f3 ( ) - > Int { <nl> + return 1 <nl> + } <nl> + } <nl> new file mode 100644 <nl> index 000000000000 . . c4325901c21b <nl> mmm / dev / null <nl> ppp b / test / InterfaceHash / changed_var_name . swift <nl> <nl> + / / RUN : mkdir - p % t <nl> + / / RUN : % S / . . / . . / utils / split_file . py - o % t % s <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / a . swift 2 > % t / a . hash <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / b . swift 2 > % t / b . hash <nl> + / / RUN : not cmp % t / a . hash % t / b . hash <nl> + <nl> + / / BEGIN a . swift <nl> + var x : Int <nl> + <nl> + / / BEGIN b . swift <nl> + var y : Int <nl> new file mode 100644 <nl> index 000000000000 . . 33ca0ad04c72 <nl> mmm / dev / null <nl> ppp b / test / InterfaceHash / changed_var_type . swift <nl> <nl> + / / RUN : mkdir - p % t <nl> + / / RUN : % S / . . / . . / utils / split_file . py - o % t % s <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / a . swift 2 > % t / a . hash <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / b . swift 2 > % t / b . hash <nl> + / / RUN : not cmp % t / a . hash % t / b . hash <nl> + <nl> + / / BEGIN a . swift <nl> + var x : Int <nl> + <nl> + / / BEGIN b . swift <nl> + var x : Float <nl> new file mode 100644 <nl> index 000000000000 . . a9d69bcdbd43 <nl> mmm / dev / null <nl> ppp b / test / InterfaceHash / edited_function_body . swift <nl> <nl> + / / RUN : mkdir - p % t <nl> + / / RUN : % S / . . / . . / utils / split_file . py - o % t % s <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / a . swift 2 > % t / a . hash <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / b . swift 2 > % t / b . hash <nl> + / / RUN : cmp % t / a . hash % t / b . hash <nl> + <nl> + / / BEGIN a . swift <nl> + func f ( ) - > Int { <nl> + return 0 <nl> + } <nl> + <nl> + / / BEGIN b . swift <nl> + func f ( ) - > Int { <nl> + return 1 <nl> + } <nl> new file mode 100644 <nl> index 000000000000 . . 7c6ec3391e05 <nl> mmm / dev / null <nl> ppp b / test / InterfaceHash / edited_method_body . swift <nl> <nl> + / / RUN : mkdir - p % t <nl> + / / RUN : % S / . . / . . / utils / split_file . py - o % t % s <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / a . swift 2 > % t / a . hash <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / b . swift 2 > % t / b . hash <nl> + / / RUN : cmp % t / a . hash % t / b . hash <nl> + <nl> + / / BEGIN a . swift <nl> + class C { <nl> + func f2 ( ) - > Int { <nl> + return 0 <nl> + } <nl> + } <nl> + <nl> + / / BEGIN b . swift <nl> + class C { <nl> + func f2 ( ) - > Int { <nl> + return 1 <nl> + } <nl> + } <nl> new file mode 100644 <nl> index 000000000000 . . 89b0cdb74a59 <nl> mmm / dev / null <nl> ppp b / test / InterfaceHash / edited_property_getter . swift <nl> <nl> + / / RUN : mkdir - p % t <nl> + / / RUN : % S / . . / . . / utils / split_file . py - o % t % s <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / a . swift 2 > % t / a . hash <nl> + / / RUN : % target - swift - frontend - dump - interface - hash % t / b . swift 2 > % t / b . hash <nl> + / / RUN : cmp % t / a . hash % t / b . hash <nl> + <nl> + / / BEGIN a . swift <nl> + class C { <nl> + var p : Int { <nl> + return 0 <nl> + } <nl> + } <nl> + <nl> + / / BEGIN b . swift <nl> + class C { <nl> + var p : Int { <nl> + let x = 1 <nl> + return x <nl> + } <nl> + } <nl> mmm a / tools / driver / frontend_main . cpp <nl> ppp b / tools / driver / frontend_main . cpp <nl> static bool emitReferenceDependencies ( DiagnosticEngine & diags , <nl> out < < " - \ " " < < llvm : : yaml : : escape ( entry ) < < " \ " \ n " ; <nl> } <nl> <nl> + llvm : : SmallString < 32 > interfaceHash ; <nl> + SF - > getInterfaceHash ( interfaceHash ) ; <nl> + out < < " interface - hash : \ " " < < interfaceHash < < " \ " \ n " ; <nl> + <nl> return false ; <nl> } <nl> <nl> static bool performCompile ( CompilerInstance & Instance , <nl> if ( shouldTrackReferences ) <nl> Instance . setReferencedNameTracker ( & nameTracker ) ; <nl> <nl> - if ( Action = = FrontendOptions : : DumpParse ) <nl> + if ( Action = = FrontendOptions : : DumpParse | | <nl> + Action = = FrontendOptions : : DumpInterfaceHash ) <nl> Instance . performParseOnly ( ) ; <nl> else <nl> Instance . performSema ( ) ; <nl> static bool performCompile ( CompilerInstance & Instance , <nl> if ( Action = = FrontendOptions : : DumpParse | | <nl> Action = = FrontendOptions : : DumpAST | | <nl> Action = = FrontendOptions : : PrintAST | | <nl> - Action = = FrontendOptions : : DumpTypeRefinementContexts ) { <nl> + Action = = FrontendOptions : : DumpTypeRefinementContexts | | <nl> + Action = = FrontendOptions : : DumpInterfaceHash ) { <nl> SourceFile * SF = PrimarySourceFile ; <nl> if ( ! SF ) { <nl> SourceFileKind Kind = Invocation . getSourceFileKind ( ) ; <nl> static bool performCompile ( CompilerInstance & Instance , <nl> SF - > print ( llvm : : outs ( ) , PrintOptions : : printEverything ( ) ) ; <nl> else if ( Action = = FrontendOptions : : DumpTypeRefinementContexts ) <nl> SF - > getTypeRefinementContext ( ) - > dump ( llvm : : errs ( ) , Context . SourceMgr ) ; <nl> + else if ( Action = = FrontendOptions : : DumpInterfaceHash ) <nl> + SF - > dumpInterfaceHash ( llvm : : errs ( ) ) ; <nl> else <nl> SF - > dump ( ) ; <nl> return false ; <nl> new file mode 100755 <nl> index 000000000000 . . f0d499f78f49 <nl> mmm / dev / null <nl> ppp b / utils / split_file . py <nl> <nl> + # ! / usr / bin / env python <nl> + <nl> + " " " <nl> + split_file . py [ - o < dir > ] < path > <nl> + <nl> + Take the file at < path > and write it to multiple files , switching to a new file <nl> + every time an annotation of the form " / / BEGIN file1 . swift " is encountered . If <nl> + < dir > is specified , place the files in < dir > ; otherwise , put them in the <nl> + current directory . <nl> + " " " <nl> + <nl> + import os <nl> + import sys <nl> + import re <nl> + import getopt <nl> + <nl> + def usage ( ) : <nl> + sys . stderr . write ( __doc__ . strip ( ) + " \ n " ) <nl> + sys . exit ( 1 ) <nl> + <nl> + fp_out = None <nl> + dest_dir = ' . ' <nl> + <nl> + try : <nl> + opts , args = getopt . getopt ( sys . argv [ 1 : ] , ' o : h ' ) <nl> + for ( opt , arg ) in opts : <nl> + if opt = = ' - o ' : <nl> + dest_dir = arg <nl> + elif opt = = ' - h ' : <nl> + usage ( ) <nl> + except getopt . GetoptError : <nl> + usage ( ) <nl> + <nl> + if len ( args ) ! = 1 : <nl> + usage ( ) <nl> + fp_in = open ( args [ 0 ] , ' r ' ) <nl> + <nl> + for line in fp_in : <nl> + m = re . match ( r ' ^ / / \ s * BEGIN \ s + ( [ ^ \ s ] + ) \ s * $ ' , line ) <nl> + if m : <nl> + if fp_out : <nl> + fp_out . close ( ) <nl> + fp_out = open ( os . path . join ( dest_dir , m . group ( 1 ) ) , ' w ' ) <nl> + elif fp_out : <nl> + fp_out . write ( line ) <nl> + <nl> + fp_in . close ( ) <nl> + if fp_out : <nl> + fp_out . close ( ) <nl>
Add " interface hash " for improved incremental builds .
apple/swift
fbb8d3f9a8c94c209ae6cfdc2ced8fafbd9513ab
2015-07-22T00:13:54Z
mmm a / admin / static / js / codemirror / codemirror . css <nl> ppp b / admin / static / js / codemirror / codemirror . css <nl> <nl> . CodeMirror { <nl> / * Set height , width , borders , and global font properties here * / <nl> font - family : monospace ; <nl> - margin : 0px 0px 7px 0px ; <nl> + height : 300px ; <nl> } <nl> . CodeMirror - scroll { <nl> / * Set scrolling behaviour here * / <nl> overflow : auto ; <nl> - height : auto ; <nl> - min - height : 70px ; <nl> } <nl> <nl> / * PADDING * / <nl> <nl> <nl> . CodeMirror div . CodeMirror - cursor { <nl> border - left : 1px solid black ; <nl> + z - index : 3 ; <nl> } <nl> / * Shown when moving in bi - directional text * / <nl> . CodeMirror div . CodeMirror - secondarycursor { <nl> <nl> . CodeMirror . cm - keymap - fat - cursor div . CodeMirror - cursor { <nl> width : auto ; <nl> border : 0 ; <nl> - background : transparent ; <nl> - background : rgba ( 0 , 200 , 0 , . 4 ) ; <nl> - filter : progid : DXImageTransform . Microsoft . gradient ( startColorstr = # 6600c800 , endColorstr = # 4c00c800 ) ; <nl> - } <nl> - / * Kludge to turn off filter in ie9 + , which also accepts rgba * / <nl> - . CodeMirror . cm - keymap - fat - cursor div . CodeMirror - cursor : not ( # nonsense_id ) { <nl> - filter : progid : DXImageTransform . Microsoft . gradient ( enabled = false ) ; <nl> + background : # 7e7 ; <nl> + z - index : 1 ; <nl> } <nl> / * Can style cursor different in overwrite ( non - insert ) mode * / <nl> . CodeMirror div . CodeMirror - cursor . CodeMirror - overwrite { } <nl> <nl> + . cm - tab { display : inline - block ; } <nl> + <nl> / * DEFAULT THEME * / <nl> <nl> . cm - s - default . cm - keyword { color : # 708 ; } <nl> <nl> . cm - positive { color : # 292 ; } <nl> . cm - header , . cm - strong { font - weight : bold ; } <nl> . cm - em { font - style : italic ; } <nl> - . cm - emstrong { font - style : italic ; font - weight : bold ; } <nl> . cm - link { text - decoration : underline ; } <nl> <nl> . cm - invalidchar { color : # f00 ; } <nl> div . CodeMirror span . CodeMirror - nonmatchingbracket { color : # f22 ; } <nl> line - height : 1 ; <nl> position : relative ; <nl> overflow : hidden ; <nl> + background : white ; <nl> + color : black ; <nl> } <nl> <nl> . CodeMirror - scroll { <nl> div . CodeMirror span . CodeMirror - nonmatchingbracket { color : # f22 ; } <nl> <nl> . CodeMirror - gutters { <nl> position : absolute ; left : 0 ; top : 0 ; <nl> - min - height : 70px ; <nl> + height : 100 % ; <nl> + padding - bottom : 30px ; <nl> z - index : 3 ; <nl> - background : # f1f1f1 ; <nl> } <nl> . CodeMirror - gutter { <nl> height : 100 % ; <nl> + padding - bottom : 30px ; <nl> + margin - bottom : - 32px ; <nl> display : inline - block ; <nl> / * Hack to make IE7 behave * / <nl> * zoom : 1 ; <nl> div . CodeMirror span . CodeMirror - nonmatchingbracket { color : # f22 ; } <nl> position : absolute ; <nl> cursor : default ; <nl> z - index : 4 ; <nl> - height : 100 % ; <nl> } <nl> <nl> . CodeMirror - lines { <nl> div . CodeMirror span . CodeMirror - nonmatchingbracket { color : # f22 ; } <nl> } <nl> . CodeMirror pre { <nl> / * Reset some styles that the rest of the page might have set * / <nl> - - moz - border - radius : 0 ; - webkit - border - radius : 0 ; - o - border - radius : 0 ; border - radius : 0 ; <nl> + - moz - border - radius : 0 ; - webkit - border - radius : 0 ; border - radius : 0 ; <nl> border - width : 0 ; <nl> background : transparent ; <nl> font - family : inherit ; <nl> div . CodeMirror span . CodeMirror - nonmatchingbracket { color : # f22 ; } <nl> overflow : auto ; <nl> } <nl> <nl> + . CodeMirror - widget { <nl> + display : inline - block ; <nl> + } <nl> + <nl> . CodeMirror - wrap . CodeMirror - scroll { <nl> overflow - x : hidden ; <nl> } <nl> mmm a / admin / static / js / codemirror / codemirror . js <nl> ppp b / admin / static / js / codemirror / codemirror . js <nl> <nl> - / / CodeMirror version 3 . 02 <nl> + / / CodeMirror version 3 . 11 <nl> / / <nl> / / CodeMirror is the only global var we claim <nl> window . CodeMirror = ( function ( ) { <nl> window . CodeMirror = ( function ( ) { <nl> if ( opera_version ) opera_version = Number ( opera_version [ 1 ] ) ; <nl> / / Some browsers use the wrong event properties to signal cmd / ctrl on OS X <nl> var flipCtrlCmd = mac & & ( qtwebkit | | opera & & ( opera_version = = null | | opera_version < 12 . 11 ) ) ; <nl> + var captureMiddleClick = gecko | | ( ie & & ! ie_lt9 ) ; <nl> <nl> / / Optimize some code when these features are not used <nl> var sawReadOnlySpans = false , sawCollapsedSpans = false ; <nl> window . CodeMirror = ( function ( ) { <nl> <nl> function CodeMirror ( place , options ) { <nl> if ( ! ( this instanceof CodeMirror ) ) return new CodeMirror ( place , options ) ; <nl> - <nl> + <nl> this . options = options = options | | { } ; <nl> / / Determine effective options based on given values and defaults . <nl> for ( var opt in defaults ) if ( ! options . hasOwnProperty ( opt ) & & defaults . hasOwnProperty ( opt ) ) <nl> options [ opt ] = defaults [ opt ] ; <nl> setGuttersForLineNumbers ( options ) ; <nl> <nl> - var display = this . display = makeDisplay ( place ) ; <nl> + var docStart = typeof options . value = = " string " ? 0 : options . value . first ; <nl> + var display = this . display = makeDisplay ( place , docStart ) ; <nl> display . wrapper . CodeMirror = this ; <nl> updateGutters ( this ) ; <nl> if ( options . autofocus & & ! mobile ) focusInput ( this ) ; <nl> <nl> - this . view = makeView ( new BranchChunk ( [ new LeafChunk ( [ makeLine ( " " , null , textHeight ( display ) ) ] ) ] ) ) ; <nl> - this . nextOpId = 0 ; <nl> - loadMode ( this ) ; <nl> + this . state = { keyMaps : [ ] , <nl> + overlays : [ ] , <nl> + modeGen : 0 , <nl> + overwrite : false , focused : false , <nl> + suppressEdits : false , pasteIncoming : false , <nl> + draggingText : false , <nl> + highlight : new Delayed ( ) } ; <nl> + <nl> themeChanged ( this ) ; <nl> if ( options . lineWrapping ) <nl> this . display . wrapper . className + = " CodeMirror - wrap " ; <nl> <nl> - / / Initialize the content . <nl> - this . setValue ( options . value | | " " ) ; <nl> + var doc = options . value ; <nl> + if ( typeof doc = = " string " ) doc = new Doc ( options . value , options . mode ) ; <nl> + operation ( this , attachDoc ) ( this , doc ) ; <nl> + <nl> / / Override magic textarea content restore that IE sometimes does <nl> / / on our hidden textarea on reload <nl> if ( ie ) setTimeout ( bind ( resetInput , this , true ) , 20 ) ; <nl> - this . view . history = makeHistory ( ) ; <nl> <nl> registerEventHandlers ( this ) ; <nl> / / IE throws unspecified error in certain cases , when <nl> window . CodeMirror = ( function ( ) { <nl> <nl> / / DISPLAY CONSTRUCTOR <nl> <nl> - function makeDisplay ( place ) { <nl> + function makeDisplay ( place , docStart ) { <nl> var d = { } ; <nl> + <nl> var input = d . input = elt ( " textarea " , null , null , " position : absolute ; padding : 0 ; width : 1px ; height : 1em ; outline : none ; " ) ; <nl> if ( webkit ) input . style . width = " 1000px " ; <nl> else input . setAttribute ( " wrap " , " off " ) ; <nl> + / / if border : 0 ; - - iOS fails to open keyboard ( issue # 1287 ) <nl> + if ( ios ) input . style . border = " 1px solid black " ; <nl> input . setAttribute ( " autocorrect " , " off " ) ; input . setAttribute ( " autocapitalize " , " off " ) ; <nl> + <nl> / / Wraps and hides input textarea <nl> d . inputDiv = elt ( " div " , [ input ] , null , " overflow : hidden ; position : relative ; width : 3px ; height : 0px ; " ) ; <nl> / / The actual fake scrollbars . <nl> window . CodeMirror = ( function ( ) { <nl> / / Set to the height of the text , causes scrolling <nl> d . sizer = elt ( " div " , [ d . mover ] , " CodeMirror - sizer " ) ; <nl> / / D is needed because behavior of elts with overflow : auto and padding is inconsistent across browsers <nl> - d . heightForcer = elt ( " div " , " \ u00a0 " , null , " position : absolute ; height : " + scrollerCutOff + " px " ) ; <nl> + d . heightForcer = elt ( " div " , null , null , " position : absolute ; height : " + scrollerCutOff + " px ; width : 1px ; " ) ; <nl> / / Will contain the gutters , if any <nl> d . gutters = elt ( " div " , null , " CodeMirror - gutters " ) ; <nl> d . lineGutter = null ; <nl> window . CodeMirror = ( function ( ) { <nl> else if ( ie_lt8 ) d . scrollbarH . style . minWidth = d . scrollbarV . style . minWidth = " 18px " ; <nl> <nl> / / Current visible range ( may be bigger than the view window ) . <nl> - d . viewOffset = d . showingFrom = d . showingTo = d . lastSizeC = 0 ; <nl> + d . viewOffset = d . lastSizeC = 0 ; <nl> + d . showingFrom = d . showingTo = docStart ; <nl> <nl> / / Used to only resize the line number gutter when necessary ( when <nl> / / the amount of lines crosses a boundary that makes its width change ) <nl> window . CodeMirror = ( function ( ) { <nl> / / string instead of the ( large ) selection . <nl> d . inaccurateSelection = false ; <nl> <nl> - / / Used to adjust overwrite behaviour when a paste has been <nl> - / / detected <nl> - d . pasteIncoming = false ; <nl> + / / Tracks the maximum line length so that the horizontal scrollbar <nl> + / / can be kept static when scrolling . <nl> + d . maxLine = null ; <nl> + d . maxLineLength = 0 ; <nl> + d . maxLineChanged = false ; <nl> <nl> / / Used for measuring wheel scrolling granularity <nl> d . wheelDX = d . wheelDY = d . wheelStartX = d . wheelStartY = null ; <nl> - <nl> - return d ; <nl> - } <nl> - <nl> - / / VIEW CONSTRUCTOR <nl> <nl> - function makeView ( doc ) { <nl> - var selPos = { line : 0 , ch : 0 } ; <nl> - return { <nl> - doc : doc , <nl> - / / frontier is the point up to which the content has been parsed , <nl> - frontier : 0 , highlight : new Delayed ( ) , <nl> - sel : { from : selPos , to : selPos , head : selPos , anchor : selPos , shift : false , extend : false } , <nl> - scrollTop : 0 , scrollLeft : 0 , <nl> - overwrite : false , focused : false , <nl> - / / Tracks the maximum line length so that <nl> - / / the horizontal scrollbar can be kept <nl> - / / static when scrolling . <nl> - maxLine : getLine ( doc , 0 ) , <nl> - maxLineLength : 0 , <nl> - maxLineChanged : false , <nl> - suppressEdits : false , <nl> - goalColumn : null , <nl> - cantEdit : false , <nl> - keyMaps : [ ] , <nl> - overlays : [ ] , <nl> - modeGen : 0 <nl> - } ; <nl> + return d ; <nl> } <nl> <nl> / / STATE UPDATES <nl> window . CodeMirror = ( function ( ) { <nl> / / Used to get the editor into a consistent state again when options change . <nl> <nl> function loadMode ( cm ) { <nl> - var doc = cm . view . doc ; <nl> - cm . view . mode = CodeMirror . getMode ( cm . options , cm . options . mode ) ; <nl> - doc . iter ( 0 , doc . size , function ( line ) { <nl> + cm . doc . mode = CodeMirror . getMode ( cm . options , cm . doc . modeOption ) ; <nl> + cm . doc . iter ( function ( line ) { <nl> if ( line . stateAfter ) line . stateAfter = null ; <nl> if ( line . styles ) line . styles = null ; <nl> } ) ; <nl> - cm . view . frontier = 0 ; <nl> + cm . doc . frontier = cm . doc . first ; <nl> startWorker ( cm , 100 ) ; <nl> - cm . view . modeGen + + ; <nl> - if ( cm . curOp ) regChange ( cm , 0 , doc . size ) ; <nl> + cm . state . modeGen + + ; <nl> + if ( cm . curOp ) regChange ( cm ) ; <nl> } <nl> <nl> function wrappingChanged ( cm ) { <nl> - var doc = cm . view . doc , th = textHeight ( cm . display ) ; <nl> if ( cm . options . lineWrapping ) { <nl> cm . display . wrapper . className + = " CodeMirror - wrap " ; <nl> - var perLine = cm . display . scroller . clientWidth / charWidth ( cm . display ) - 3 ; <nl> - doc . iter ( 0 , doc . size , function ( line ) { <nl> - if ( line . height = = 0 ) return ; <nl> - var guess = Math . ceil ( line . text . length / perLine ) | | 1 ; <nl> - if ( guess ! = 1 ) updateLineHeight ( line , guess * th ) ; <nl> - } ) ; <nl> cm . display . sizer . style . minWidth = " " ; <nl> } else { <nl> cm . display . wrapper . className = cm . display . wrapper . className . replace ( " CodeMirror - wrap " , " " ) ; <nl> - computeMaxLength ( cm . view ) ; <nl> - doc . iter ( 0 , doc . size , function ( line ) { <nl> - if ( line . height ! = 0 ) updateLineHeight ( line , th ) ; <nl> - } ) ; <nl> + computeMaxLength ( cm ) ; <nl> } <nl> - regChange ( cm , 0 , doc . size ) ; <nl> + estimateLineHeights ( cm ) ; <nl> + regChange ( cm ) ; <nl> clearCaches ( cm ) ; <nl> - setTimeout ( function ( ) { updateScrollbars ( cm . display , cm . view . doc . height ) ; } , 100 ) ; <nl> + setTimeout ( function ( ) { updateScrollbars ( cm . display , cm . doc . height ) ; } , 100 ) ; <nl> + } <nl> + <nl> + function estimateHeight ( cm ) { <nl> + var th = textHeight ( cm . display ) , wrapping = cm . options . lineWrapping ; <nl> + var perLine = wrapping & & Math . max ( 5 , cm . display . scroller . clientWidth / charWidth ( cm . display ) - 3 ) ; <nl> + return function ( line ) { <nl> + if ( lineIsHidden ( cm . doc , line ) ) <nl> + return 0 ; <nl> + else if ( wrapping ) <nl> + return ( Math . ceil ( line . text . length / perLine ) | | 1 ) * th ; <nl> + else <nl> + return th ; <nl> + } ; <nl> + } <nl> + <nl> + function estimateLineHeights ( cm ) { <nl> + var doc = cm . doc , est = estimateHeight ( cm ) ; <nl> + doc . iter ( function ( line ) { <nl> + var estHeight = est ( line ) ; <nl> + if ( estHeight ! = line . height ) updateLineHeight ( line , estHeight ) ; <nl> + } ) ; <nl> } <nl> <nl> function keyMapChanged ( cm ) { <nl> window . CodeMirror = ( function ( ) { <nl> <nl> function guttersChanged ( cm ) { <nl> updateGutters ( cm ) ; <nl> - updateDisplay ( cm , true ) ; <nl> + regChange ( cm ) ; <nl> } <nl> <nl> function updateGutters ( cm ) { <nl> window . CodeMirror = ( function ( ) { <nl> return len ; <nl> } <nl> <nl> - function computeMaxLength ( view ) { <nl> - view . maxLine = getLine ( view . doc , 0 ) ; <nl> - view . maxLineLength = lineLength ( view . doc , view . maxLine ) ; <nl> - view . maxLineChanged = true ; <nl> - view . doc . iter ( 1 , view . doc . size , function ( line ) { <nl> - var len = lineLength ( view . doc , line ) ; <nl> - if ( len > view . maxLineLength ) { <nl> - view . maxLineLength = len ; <nl> - view . maxLine = line ; <nl> + function computeMaxLength ( cm ) { <nl> + var d = cm . display , doc = cm . doc ; <nl> + d . maxLine = getLine ( doc , doc . first ) ; <nl> + d . maxLineLength = lineLength ( doc , d . maxLine ) ; <nl> + d . maxLineChanged = true ; <nl> + doc . iter ( function ( line ) { <nl> + var len = lineLength ( doc , line ) ; <nl> + if ( len > d . maxLineLength ) { <nl> + d . maxLineLength = len ; <nl> + d . maxLine = line ; <nl> } <nl> } ) ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> / / Re - synchronize the fake scrollbars with the actual size of the <nl> / / content . Optionally force a scrollTop . <nl> function updateScrollbars ( d / * display * / , docHeight ) { <nl> - var totalHeight = docHeight + 2 * paddingTop ( d ) ; <nl> + var totalHeight = docHeight + paddingVert ( d ) ; <nl> d . sizer . style . minHeight = d . heightForcer . style . top = totalHeight + " px " ; <nl> var scrollHeight = Math . max ( totalHeight , d . scroller . scrollHeight ) ; <nl> var needsH = d . scroller . scrollWidth > d . scroller . clientWidth ; <nl> window . CodeMirror = ( function ( ) { <nl> if ( needsV ) { <nl> d . scrollbarV . style . display = " block " ; <nl> d . scrollbarV . style . bottom = needsH ? scrollbarWidth ( d . measure ) + " px " : " 0 " ; <nl> - d . scrollbarV . firstChild . style . height = <nl> + d . scrollbarV . firstChild . style . height = <nl> ( scrollHeight - d . scroller . clientHeight + d . scrollbarV . clientHeight ) + " px " ; <nl> } else d . scrollbarV . style . display = " " ; <nl> if ( needsH ) { <nl> window . CodeMirror = ( function ( ) { <nl> function alignHorizontally ( cm ) { <nl> var display = cm . display ; <nl> if ( ! display . alignWidgets & & ( ! display . gutters . firstChild | | ! cm . options . fixedGutter ) ) return ; <nl> - var comp = compensateForHScroll ( display ) - display . scroller . scrollLeft + cm . view . scrollLeft ; <nl> + var comp = compensateForHScroll ( display ) - display . scroller . scrollLeft + cm . doc . scrollLeft ; <nl> var gutterW = display . gutters . offsetWidth , l = comp + " px " ; <nl> for ( var n = display . lineDiv . firstChild ; n ; n = n . nextSibling ) if ( n . alignable ) { <nl> for ( var i = 0 , a = n . alignable ; i < a . length ; + + i ) a [ i ] . style . left = l ; <nl> window . CodeMirror = ( function ( ) { <nl> <nl> function maybeUpdateLineNumberWidth ( cm ) { <nl> if ( ! cm . options . lineNumbers ) return false ; <nl> - var doc = cm . view . doc , last = lineNumberFor ( cm . options , doc . size - 1 ) , display = cm . display ; <nl> + var doc = cm . doc , last = lineNumberFor ( cm . options , doc . first + doc . size - 1 ) , display = cm . display ; <nl> if ( last . length ! = display . lineNumChars ) { <nl> var test = display . measure . appendChild ( elt ( " div " , [ elt ( " div " , last ) ] , <nl> " CodeMirror - linenumber CodeMirror - gutter - elt " ) ) ; <nl> window . CodeMirror = ( function ( ) { <nl> return String ( options . lineNumberFormatter ( i + options . firstLineNumber ) ) ; <nl> } <nl> function compensateForHScroll ( display ) { <nl> - return display . scroller . getBoundingClientRect ( ) . left - display . sizer . getBoundingClientRect ( ) . left ; <nl> + return getRect ( display . scroller ) . left - getRect ( display . sizer ) . left ; <nl> } <nl> <nl> / / DISPLAY DRAWING <nl> window . CodeMirror = ( function ( ) { <nl> var oldFrom = cm . display . showingFrom , oldTo = cm . display . showingTo ; <nl> var updated = updateDisplayInner ( cm , changes , viewPort ) ; <nl> if ( updated ) { <nl> - signalLater ( cm , cm , " update " , cm ) ; <nl> + signalLater ( cm , " update " , cm ) ; <nl> if ( cm . display . showingFrom ! = oldFrom | | cm . display . showingTo ! = oldTo ) <nl> - signalLater ( cm , cm , " viewportChange " , cm , cm . display . showingFrom , cm . display . showingTo ) ; <nl> + signalLater ( cm , " viewportChange " , cm , cm . display . showingFrom , cm . display . showingTo ) ; <nl> } <nl> updateSelection ( cm ) ; <nl> - updateScrollbars ( cm . display , cm . view . doc . height ) ; <nl> + updateScrollbars ( cm . display , cm . doc . height ) ; <nl> <nl> return updated ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> / / determine which DOM updates have to be made , and makes the <nl> / / updates . <nl> function updateDisplayInner ( cm , changes , viewPort ) { <nl> - var display = cm . display , doc = cm . view . doc ; <nl> + var display = cm . display , doc = cm . doc ; <nl> if ( ! display . wrapper . clientWidth ) { <nl> - display . showingFrom = display . showingTo = display . viewOffset = 0 ; <nl> + display . showingFrom = display . showingTo = doc . first ; <nl> + display . viewOffset = 0 ; <nl> return ; <nl> } <nl> <nl> window . CodeMirror = ( function ( ) { <nl> / / to render instead of the current scrollbar position . <nl> var visible = visibleLines ( display , doc , viewPort ) ; <nl> / / Bail out if the visible area is already rendered and nothing changed . <nl> - if ( changes ! = = true & & changes . length = = 0 & & <nl> + if ( changes . length = = 0 & & <nl> visible . from > display . showingFrom & & visible . to < display . showingTo ) <nl> return ; <nl> <nl> - if ( changes & & maybeUpdateLineNumberWidth ( cm ) ) <nl> - changes = true ; <nl> + if ( maybeUpdateLineNumberWidth ( cm ) ) <nl> + changes = [ { from : doc . first , to : doc . first + doc . size } ] ; <nl> var gutterW = display . sizer . style . marginLeft = display . gutters . offsetWidth + " px " ; <nl> display . scrollbarH . style . left = cm . options . fixedGutter ? gutterW : " 0 " ; <nl> <nl> - / / When merged lines are present , the line that needs to be <nl> - / / redrawn might not be the one that was changed . <nl> - if ( changes ! = = true & & sawCollapsedSpans ) <nl> - for ( var i = 0 ; i < changes . length ; + + i ) { <nl> - var ch = changes [ i ] , merged ; <nl> - while ( merged = collapsedSpanAtStart ( getLine ( doc , ch . from ) ) ) { <nl> - var from = merged . find ( ) . from . line ; <nl> - if ( ch . diff ) ch . diff - = ch . from - from ; <nl> - ch . from = from ; <nl> - } <nl> - } <nl> - <nl> / / Used to determine which lines need their line numbers updated <nl> - var positionsChangedFrom = changes = = = true ? 0 : Infinity ; <nl> - if ( cm . options . lineNumbers & & changes & & changes ! = = true ) <nl> + var positionsChangedFrom = Infinity ; <nl> + if ( cm . options . lineNumbers ) <nl> for ( var i = 0 ; i < changes . length ; + + i ) <nl> if ( changes [ i ] . diff ) { positionsChangedFrom = changes [ i ] . from ; break ; } <nl> <nl> - var from = Math . max ( visible . from - cm . options . viewportMargin , 0 ) ; <nl> - var to = Math . min ( doc . size , visible . to + cm . options . viewportMargin ) ; <nl> - if ( display . showingFrom < from & & from - display . showingFrom < 20 ) from = display . showingFrom ; <nl> - if ( display . showingTo > to & & display . showingTo - to < 20 ) to = Math . min ( doc . size , display . showingTo ) ; <nl> + var end = doc . first + doc . size ; <nl> + var from = Math . max ( visible . from - cm . options . viewportMargin , doc . first ) ; <nl> + var to = Math . min ( end , visible . to + cm . options . viewportMargin ) ; <nl> + if ( display . showingFrom < from & & from - display . showingFrom < 20 ) from = Math . max ( doc . first , display . showingFrom ) ; <nl> + if ( display . showingTo > to & & display . showingTo - to < 20 ) to = Math . min ( end , display . showingTo ) ; <nl> if ( sawCollapsedSpans ) { <nl> from = lineNo ( visualLine ( doc , getLine ( doc , from ) ) ) ; <nl> - while ( to < doc . size & & lineIsHidden ( getLine ( doc , to ) ) ) + + to ; <nl> + while ( to < end & & lineIsHidden ( doc , getLine ( doc , to ) ) ) + + to ; <nl> } <nl> <nl> / / Create a range of theoretically intact lines , and punch holes <nl> / / in that using the change info . <nl> - var intact = changes = = = true ? [ ] : <nl> - computeIntact ( [ { from : display . showingFrom , to : display . showingTo } ] , changes ) ; <nl> + var intact = [ { from : Math . max ( display . showingFrom , doc . first ) , <nl> + to : Math . min ( display . showingTo , end ) } ] ; <nl> + if ( intact [ 0 ] . from > = intact [ 0 ] . to ) intact = [ ] ; <nl> + else intact = computeIntact ( intact , changes ) ; <nl> + / / When merged lines are present , we might have to reduce the <nl> + / / intact ranges because changes in continued fragments of the <nl> + / / intact lines do require the lines to be redrawn . <nl> + if ( sawCollapsedSpans ) <nl> + for ( var i = 0 ; i < intact . length ; + + i ) { <nl> + var range = intact [ i ] , merged ; <nl> + while ( merged = collapsedSpanAtEnd ( getLine ( doc , range . to - 1 ) ) ) { <nl> + var newTo = merged . find ( ) . from . line ; <nl> + if ( newTo > range . from ) range . to = newTo ; <nl> + else { intact . splice ( i - - , 1 ) ; break ; } <nl> + } <nl> + } <nl> + <nl> / / Clip off the parts that won ' t be visible <nl> var intactLines = 0 ; <nl> for ( var i = 0 ; i < intact . length ; + + i ) { <nl> window . CodeMirror = ( function ( ) { <nl> if ( range . from > = range . to ) intact . splice ( i - - , 1 ) ; <nl> else intactLines + = range . to - range . from ; <nl> } <nl> - if ( intactLines = = to - from & & from = = display . showingFrom & & to = = display . showingTo ) <nl> + if ( intactLines = = to - from & & from = = display . showingFrom & & to = = display . showingTo ) { <nl> + updateViewOffset ( cm ) ; <nl> return ; <nl> + } <nl> intact . sort ( function ( a , b ) { return a . from - b . from ; } ) ; <nl> <nl> var focused = document . activeElement ; <nl> window . CodeMirror = ( function ( ) { <nl> height = bot - prevBottom ; <nl> prevBottom = bot ; <nl> } else { <nl> - var box = node . getBoundingClientRect ( ) ; <nl> + var box = getRect ( node ) ; <nl> height = box . bottom - box . top ; <nl> } <nl> var diff = node . lineObj . height - height ; <nl> window . CodeMirror = ( function ( ) { <nl> widgets [ i ] . height = widgets [ i ] . node . offsetHeight ; <nl> } <nl> } <nl> - display . viewOffset = heightAtLine ( cm , getLine ( doc , from ) ) ; <nl> - / / Position the mover div to align with the current virtual scroll position <nl> - display . mover . style . top = display . viewOffset + " px " ; <nl> + updateViewOffset ( cm ) ; <nl> <nl> - if ( visibleLines ( display , doc , viewPort ) . to > = to ) <nl> + if ( visibleLines ( display , doc , viewPort ) . to > to ) <nl> updateDisplayInner ( cm , [ ] , viewPort ) ; <nl> return true ; <nl> } <nl> <nl> + function updateViewOffset ( cm ) { <nl> + var off = cm . display . viewOffset = heightAtLine ( cm , getLine ( cm . doc , cm . display . showingFrom ) ) ; <nl> + / / Position the mover div to align with the current virtual scroll position <nl> + cm . display . mover . style . top = off + " px " ; <nl> + } <nl> + <nl> function computeIntact ( intact , changes ) { <nl> for ( var i = 0 , l = changes . length | | 0 ; i < l ; + + i ) { <nl> var change = changes [ i ] , intact2 = [ ] , diff = change . diff | | 0 ; <nl> window . CodeMirror = ( function ( ) { <nl> return next ; <nl> } <nl> <nl> - var nextIntact = intact . shift ( ) , lineNo = from ; <nl> - cm . view . doc . iter ( from , to , function ( line ) { <nl> - if ( nextIntact & & nextIntact . to = = lineNo ) nextIntact = intact . shift ( ) ; <nl> - if ( lineIsHidden ( line ) ) { <nl> + var nextIntact = intact . shift ( ) , lineN = from ; <nl> + cm . doc . iter ( from , to , function ( line ) { <nl> + if ( nextIntact & & nextIntact . to = = lineN ) nextIntact = intact . shift ( ) ; <nl> + if ( lineIsHidden ( cm . doc , line ) ) { <nl> if ( line . height ! = 0 ) updateLineHeight ( line , 0 ) ; <nl> if ( line . widgets & & cur . previousSibling ) for ( var i = 0 ; i < line . widgets . length ; + + i ) <nl> if ( line . widgets [ i ] . showIfHidden ) { <nl> var prev = cur . previousSibling ; <nl> - if ( prev . nodeType = = " pre " ) { <nl> + if ( / pre / i . test ( prev . nodeName ) ) { <nl> var wrap = elt ( " div " , null , null , " position : relative " ) ; <nl> prev . parentNode . replaceChild ( wrap , prev ) ; <nl> wrap . appendChild ( prev ) ; <nl> prev = wrap ; <nl> } <nl> - prev . appendChild ( buildLineWidget ( line . widgets [ i ] , prev , dims ) ) ; <nl> + var wnode = prev . appendChild ( elt ( " div " , [ line . widgets [ i ] . node ] , " CodeMirror - linewidget " ) ) ; <nl> + positionLineWidget ( line . widgets [ i ] , wnode , prev , dims ) ; <nl> } <nl> - } else if ( nextIntact & & nextIntact . from < = lineNo & & nextIntact . to > lineNo ) { <nl> + } else if ( nextIntact & & nextIntact . from < = lineN & & nextIntact . to > lineN ) { <nl> / / This line is intact . Skip to the actual node . Update its <nl> / / line number if needed . <nl> while ( cur . lineObj ! = line ) cur = rm ( cur ) ; <nl> - if ( lineNumbers & & updateNumbersFrom < = lineNo & & cur . lineNumber ) <nl> - setTextContent ( cur . lineNumber , lineNumberFor ( cm . options , lineNo ) ) ; <nl> + if ( lineNumbers & & updateNumbersFrom < = lineN & & cur . lineNumber ) <nl> + setTextContent ( cur . lineNumber , lineNumberFor ( cm . options , lineN ) ) ; <nl> cur = cur . nextSibling ; <nl> } else { <nl> + / / For lines with widgets , make an attempt to find and reuse <nl> + / / the existing element , so that widgets aren ' t needlessly <nl> + / / removed and re - inserted into the dom <nl> + if ( line . widgets ) for ( var j = 0 , search = cur , reuse ; search & & j < 20 ; + + j , search = search . nextSibling ) <nl> + if ( search . lineObj = = line & & / div / i . test ( search . nodeName ) ) { reuse = search ; break ; } <nl> / / This line needs to be generated . <nl> - var lineNode = buildLineElement ( cm , line , lineNo , dims ) ; <nl> - container . insertBefore ( lineNode , cur ) ; <nl> + var lineNode = buildLineElement ( cm , line , lineN , dims , reuse ) ; <nl> + if ( lineNode ! = reuse ) { <nl> + container . insertBefore ( lineNode , cur ) ; <nl> + } else { <nl> + while ( cur ! = reuse ) cur = rm ( cur ) ; <nl> + cur = cur . nextSibling ; <nl> + } <nl> + <nl> lineNode . lineObj = line ; <nl> } <nl> - + + lineNo ; <nl> + + + lineN ; <nl> } ) ; <nl> while ( cur ) cur = rm ( cur ) ; <nl> } <nl> <nl> - function buildLineElement ( cm , line , lineNo , dims ) { <nl> + function buildLineElement ( cm , line , lineNo , dims , reuse ) { <nl> var lineElement = lineContent ( cm , line ) ; <nl> - var markers = line . gutterMarkers , display = cm . display ; <nl> - <nl> - if ( ! cm . options . lineNumbers & & ! markers & & ! line . bgClass & & ! line . wrapClass & & <nl> - ( ! line . widgets | | ! line . widgets . length ) ) return lineElement ; <nl> - <nl> - / / Lines with gutter elements or a background class need <nl> - / / to be wrapped again , and have the extra elements added <nl> - / / to the wrapper div <nl> - <nl> - var wrap = elt ( " div " , null , line . wrapClass , " position : relative " ) ; <nl> + var markers = line . gutterMarkers , display = cm . display , wrap ; <nl> + <nl> + if ( ! cm . options . lineNumbers & & ! markers & & ! line . bgClass & & ! line . wrapClass & & ! line . widgets ) <nl> + return lineElement ; <nl> + <nl> + / / Lines with gutter elements , widgets or a background class need <nl> + / / to be wrapped again , and have the extra elements added to the <nl> + / / wrapper div <nl> + <nl> + if ( reuse ) { <nl> + reuse . alignable = null ; <nl> + var isOk = true , widgetsSeen = 0 ; <nl> + for ( var n = reuse . firstChild , next ; n ; n = next ) { <nl> + next = n . nextSibling ; <nl> + if ( ! / \ bCodeMirror - linewidget \ b / . test ( n . className ) ) { <nl> + reuse . removeChild ( n ) ; <nl> + } else { <nl> + for ( var i = 0 , first = true ; i < line . widgets . length ; + + i ) { <nl> + var widget = line . widgets [ i ] , isFirst = false ; <nl> + if ( ! widget . above ) { isFirst = first ; first = false ; } <nl> + if ( widget . node = = n . firstChild ) { <nl> + positionLineWidget ( widget , n , reuse , dims ) ; <nl> + + + widgetsSeen ; <nl> + if ( isFirst ) reuse . insertBefore ( lineElement , n ) ; <nl> + break ; <nl> + } <nl> + } <nl> + if ( i = = line . widgets . length ) { isOk = false ; break ; } <nl> + } <nl> + } <nl> + if ( isOk & & widgetsSeen = = line . widgets . length ) { <nl> + wrap = reuse ; <nl> + reuse . className = line . wrapClass | | " " ; <nl> + } <nl> + } <nl> + if ( ! wrap ) { <nl> + wrap = elt ( " div " , null , line . wrapClass , " position : relative " ) ; <nl> + wrap . appendChild ( lineElement ) ; <nl> + } <nl> + / / Kludge to make sure the styled element lies behind the selection ( by z - index ) <nl> + if ( line . bgClass ) <nl> + wrap . insertBefore ( elt ( " div " , null , line . bgClass + " CodeMirror - linebackground " ) , wrap . firstChild ) ; <nl> if ( cm . options . lineNumbers | | markers ) { <nl> - var gutterWrap = wrap . appendChild ( elt ( " div " , null , null , " position : absolute ; left : " + <nl> - ( cm . options . fixedGutter ? dims . fixedPos : - dims . gutterTotalWidth ) + " px " ) ) ; <nl> - if ( cm . options . fixedGutter ) wrap . alignable = [ gutterWrap ] ; <nl> + var gutterWrap = wrap . insertBefore ( elt ( " div " , null , null , " position : absolute ; left : " + <nl> + ( cm . options . fixedGutter ? dims . fixedPos : - dims . gutterTotalWidth ) + " px " ) , <nl> + wrap . firstChild ) ; <nl> + if ( cm . options . fixedGutter ) ( wrap . alignable | | ( wrap . alignable = [ ] ) ) . push ( gutterWrap ) ; <nl> if ( cm . options . lineNumbers & & ( ! markers | | ! markers [ " CodeMirror - linenumbers " ] ) ) <nl> wrap . lineNumber = gutterWrap . appendChild ( <nl> elt ( " div " , lineNumberFor ( cm . options , lineNo ) , <nl> window . CodeMirror = ( function ( ) { <nl> dims . gutterLeft [ id ] + " px ; width : " + dims . gutterWidth [ id ] + " px " ) ) ; <nl> } <nl> } <nl> - / / Kludge to make sure the styled element lies behind the selection ( by z - index ) <nl> - if ( line . bgClass ) <nl> - wrap . appendChild ( elt ( " div " , " \ u00a0 " , line . bgClass + " CodeMirror - linebackground " ) ) ; <nl> - wrap . appendChild ( lineElement ) ; <nl> - if ( line . widgets ) for ( var i = 0 , ws = line . widgets ; i < ws . length ; + + i ) { <nl> - var widget = ws [ i ] , node = buildLineWidget ( widget , wrap , dims ) ; <nl> + if ( ie_lt8 ) wrap . style . zIndex = 2 ; <nl> + if ( line . widgets & & wrap ! = reuse ) for ( var i = 0 , ws = line . widgets ; i < ws . length ; + + i ) { <nl> + var widget = ws [ i ] , node = elt ( " div " , [ widget . node ] , " CodeMirror - linewidget " ) ; <nl> + positionLineWidget ( widget , node , wrap , dims ) ; <nl> if ( widget . above ) <nl> wrap . insertBefore ( node , cm . options . lineNumbers & & line . height ! = 0 ? gutterWrap : lineElement ) ; <nl> else <nl> wrap . appendChild ( node ) ; <nl> + signalLater ( widget , " redraw " ) ; <nl> } <nl> - if ( ie_lt8 ) wrap . style . zIndex = 2 ; <nl> return wrap ; <nl> } <nl> <nl> - function buildLineWidget ( widget , wrap , dims ) { <nl> - var node = elt ( " div " , [ widget . node ] , " CodeMirror - linewidget " ) ; <nl> - node . widget = widget ; <nl> + function positionLineWidget ( widget , node , wrap , dims ) { <nl> if ( widget . noHScroll ) { <nl> ( wrap . alignable | | ( wrap . alignable = [ ] ) ) . push ( node ) ; <nl> var width = dims . wrapperWidth ; <nl> window . CodeMirror = ( function ( ) { <nl> node . style . position = " relative " ; <nl> if ( ! widget . noHScroll ) node . style . marginLeft = - dims . gutterTotalWidth + " px " ; <nl> } <nl> - return node ; <nl> } <nl> <nl> / / SELECTION / CURSOR <nl> <nl> function updateSelection ( cm ) { <nl> var display = cm . display ; <nl> - var collapsed = posEq ( cm . view . sel . from , cm . view . sel . to ) ; <nl> + var collapsed = posEq ( cm . doc . sel . from , cm . doc . sel . to ) ; <nl> if ( collapsed | | cm . options . showCursorWhenSelecting ) <nl> updateSelectionCursor ( cm ) ; <nl> else <nl> window . CodeMirror = ( function ( ) { <nl> display . selectionDiv . style . display = " none " ; <nl> <nl> / / Move the hidden textarea near the cursor to prevent scrolling artifacts <nl> - var headPos = cursorCoords ( cm , cm . view . sel . head , " div " ) ; <nl> - var wrapOff = display . wrapper . getBoundingClientRect ( ) , lineOff = display . lineDiv . getBoundingClientRect ( ) ; <nl> + var headPos = cursorCoords ( cm , cm . doc . sel . head , " div " ) ; <nl> + var wrapOff = getRect ( display . wrapper ) , lineOff = getRect ( display . lineDiv ) ; <nl> display . inputDiv . style . top = Math . max ( 0 , Math . min ( display . wrapper . clientHeight - 10 , <nl> headPos . top + lineOff . top - wrapOff . top ) ) + " px " ; <nl> display . inputDiv . style . left = Math . max ( 0 , Math . min ( display . wrapper . clientWidth - 10 , <nl> window . CodeMirror = ( function ( ) { <nl> <nl> / / No selection , plain cursor <nl> function updateSelectionCursor ( cm ) { <nl> - var display = cm . display , pos = cursorCoords ( cm , cm . view . sel . head , " div " ) ; <nl> + var display = cm . display , pos = cursorCoords ( cm , cm . doc . sel . head , " div " ) ; <nl> display . cursor . style . left = pos . left + " px " ; <nl> display . cursor . style . top = pos . top + " px " ; <nl> display . cursor . style . height = Math . max ( 0 , pos . bottom - pos . top ) * cm . options . cursorHeight + " px " ; <nl> window . CodeMirror = ( function ( ) { <nl> <nl> / / Highlight selection <nl> function updateSelectionRange ( cm ) { <nl> - var display = cm . display , doc = cm . view . doc , sel = cm . view . sel ; <nl> + var display = cm . display , doc = cm . doc , sel = cm . doc . sel ; <nl> var fragment = document . createDocumentFragment ( ) ; <nl> var clientWidth = display . lineSpace . offsetWidth , pl = paddingLeft ( cm . display ) ; <nl> <nl> window . CodeMirror = ( function ( ) { <nl> var lineObj = getLine ( doc , line ) ; <nl> var lineLen = lineObj . text . length , rVal = retTop ? Infinity : - Infinity ; <nl> function coords ( ch ) { <nl> - return charCoords ( cm , { line : line , ch : ch } , " div " , lineObj ) ; <nl> + return charCoords ( cm , Pos ( line , ch ) , " div " , lineObj ) ; <nl> } <nl> <nl> iterateBidiSections ( getOrder ( lineObj ) , fromArg | | 0 , toArg = = null ? lineLen : toArg , function ( from , to , dir ) { <nl> window . CodeMirror = ( function ( ) { <nl> / / HIGHLIGHT WORKER <nl> <nl> function startWorker ( cm , time ) { <nl> - if ( cm . view . mode . startState & & cm . view . frontier < cm . display . showingTo ) <nl> - cm . view . highlight . set ( time , bind ( highlightWorker , cm ) ) ; <nl> + if ( cm . doc . mode . startState & & cm . doc . frontier < cm . display . showingTo ) <nl> + cm . state . highlight . set ( time , bind ( highlightWorker , cm ) ) ; <nl> } <nl> <nl> function highlightWorker ( cm ) { <nl> - var view = cm . view , doc = view . doc ; <nl> - if ( view . frontier > = cm . display . showingTo ) return ; <nl> + var doc = cm . doc ; <nl> + if ( doc . frontier < doc . first ) doc . frontier = doc . first ; <nl> + if ( doc . frontier > = cm . display . showingTo ) return ; <nl> var end = + new Date + cm . options . workTime ; <nl> - var state = copyState ( view . mode , getStateBefore ( cm , view . frontier ) ) ; <nl> + var state = copyState ( doc . mode , getStateBefore ( cm , doc . frontier ) ) ; <nl> var changed = [ ] , prevChange ; <nl> - doc . iter ( view . frontier , Math . min ( doc . size , cm . display . showingTo + 500 ) , function ( line ) { <nl> - if ( view . frontier > = cm . display . showingFrom ) { / / Visible <nl> + doc . iter ( doc . frontier , Math . min ( doc . first + doc . size , cm . display . showingTo + 500 ) , function ( line ) { <nl> + if ( doc . frontier > = cm . display . showingFrom ) { / / Visible <nl> var oldStyles = line . styles ; <nl> line . styles = highlightLine ( cm , line , state ) ; <nl> var ischange = ! oldStyles | | oldStyles . length ! = line . styles . length ; <nl> - for ( var i = 0 ; ! ischange & & i < oldStyles . length ; + + i ) <nl> - ischange = oldStyles [ i ] ! = line . styles [ i ] ; <nl> + for ( var i = 0 ; ! ischange & & i < oldStyles . length ; + + i ) ischange = oldStyles [ i ] ! = line . styles [ i ] ; <nl> if ( ischange ) { <nl> - if ( prevChange & & prevChange . end = = view . frontier ) prevChange . end + + ; <nl> - else changed . push ( prevChange = { start : view . frontier , end : view . frontier + 1 } ) ; <nl> + if ( prevChange & & prevChange . end = = doc . frontier ) prevChange . end + + ; <nl> + else changed . push ( prevChange = { start : doc . frontier , end : doc . frontier + 1 } ) ; <nl> } <nl> - line . stateAfter = copyState ( view . mode , state ) ; <nl> + line . stateAfter = copyState ( doc . mode , state ) ; <nl> } else { <nl> processLine ( cm , line , state ) ; <nl> - line . stateAfter = view . frontier % 5 = = 0 ? copyState ( view . mode , state ) : null ; <nl> + line . stateAfter = doc . frontier % 5 = = 0 ? copyState ( doc . mode , state ) : null ; <nl> } <nl> - + + view . frontier ; <nl> + + + doc . frontier ; <nl> if ( + new Date > end ) { <nl> startWorker ( cm , cm . options . workDelay ) ; <nl> return true ; <nl> window . CodeMirror = ( function ( ) { <nl> / / smallest indentation , which tends to need the least context to <nl> / / parse correctly . <nl> function findStartLine ( cm , n ) { <nl> - var minindent , minline , doc = cm . view . doc ; <nl> + var minindent , minline , doc = cm . doc ; <nl> for ( var search = n , lim = n - 100 ; search > lim ; - - search ) { <nl> - if ( search = = 0 ) return 0 ; <nl> - var line = getLine ( doc , search - 1 ) ; <nl> + if ( search < = doc . first ) return doc . first ; <nl> + var line = getLine ( doc , search - 1 ) ; <nl> if ( line . stateAfter ) return search ; <nl> var indented = countColumn ( line . text , null , cm . options . tabSize ) ; <nl> if ( minline = = null | | minindent > indented ) { <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> <nl> function getStateBefore ( cm , n ) { <nl> - var view = cm . view ; <nl> - if ( ! view . mode . startState ) return true ; <nl> - var pos = findStartLine ( cm , n ) , state = pos & & getLine ( view . doc , pos - 1 ) . stateAfter ; <nl> - if ( ! state ) state = startState ( view . mode ) ; <nl> - else state = copyState ( view . mode , state ) ; <nl> - view . doc . iter ( pos , n , function ( line ) { <nl> + var doc = cm . doc , display = cm . display ; <nl> + if ( ! doc . mode . startState ) return true ; <nl> + var pos = findStartLine ( cm , n ) , state = pos > doc . first & & getLine ( doc , pos - 1 ) . stateAfter ; <nl> + if ( ! state ) state = startState ( doc . mode ) ; <nl> + else state = copyState ( doc . mode , state ) ; <nl> + doc . iter ( pos , n , function ( line ) { <nl> processLine ( cm , line , state ) ; <nl> - var save = pos = = n - 1 | | pos % 5 = = 0 | | pos > = view . showingFrom & & pos < view . showingTo ; <nl> - line . stateAfter = save ? copyState ( view . mode , state ) : null ; <nl> + var save = pos = = n - 1 | | pos % 5 = = 0 | | pos > = display . showingFrom & & pos < display . showingTo ; <nl> + line . stateAfter = save ? copyState ( doc . mode , state ) : null ; <nl> + + pos ; <nl> } ) ; <nl> return state ; <nl> } <nl> <nl> / / POSITION MEASUREMENT <nl> - <nl> + <nl> function paddingTop ( display ) { return display . lineSpace . offsetTop ; } <nl> + function paddingVert ( display ) { return display . mover . offsetHeight - display . lineSpace . offsetHeight ; } <nl> function paddingLeft ( display ) { <nl> - var e = removeChildrenAndAdd ( display . measure , elt ( " pre " ) ) . appendChild ( elt ( " span " , " x " ) ) ; <nl> + var e = removeChildrenAndAdd ( display . measure , elt ( " pre " , null , null , " text - align : left " ) ) . appendChild ( elt ( " span " , " x " ) ) ; <nl> return e . offsetLeft ; <nl> } <nl> <nl> function measureChar ( cm , line , ch , data ) { <nl> var dir = - 1 ; <nl> data = data | | measureLine ( cm , line ) ; <nl> - <nl> + <nl> for ( var pos = ch ; ; pos + = dir ) { <nl> var r = data [ pos ] ; <nl> if ( r ) break ; <nl> window . CodeMirror = ( function ( ) { <nl> top : r . top , bottom : r . bottom } ; <nl> } <nl> <nl> - function measureLine ( cm , line ) { <nl> - / / First look in the cache <nl> - var display = cm . display , cache = cm . display . measureLineCache ; <nl> + function findCachedMeasurement ( cm , line ) { <nl> + var cache = cm . display . measureLineCache ; <nl> for ( var i = 0 ; i < cache . length ; + + i ) { <nl> var memo = cache [ i ] ; <nl> if ( memo . text = = line . text & & memo . markedSpans = = line . markedSpans & & <nl> - display . scroller . clientWidth = = memo . width ) <nl> + cm . display . scroller . clientWidth = = memo . width & & <nl> + memo . classes = = line . textClass + " | " + line . bgClass + " | " + line . wrapClass ) <nl> return memo . measure ; <nl> } <nl> - <nl> - var measure = measureLineInner ( cm , line ) ; <nl> - / / Store result in the cache <nl> - var memo = { text : line . text , width : display . scroller . clientWidth , <nl> - markedSpans : line . markedSpans , measure : measure } ; <nl> - if ( cache . length = = 16 ) cache [ + + display . measureLineCachePos % 16 ] = memo ; <nl> - else cache . push ( memo ) ; <nl> + } <nl> + <nl> + function measureLine ( cm , line ) { <nl> + / / First look in the cache <nl> + var measure = findCachedMeasurement ( cm , line ) ; <nl> + if ( ! measure ) { <nl> + / / Failing that , recompute and store result in cache <nl> + measure = measureLineInner ( cm , line ) ; <nl> + var cache = cm . display . measureLineCache ; <nl> + var memo = { text : line . text , width : cm . display . scroller . clientWidth , <nl> + markedSpans : line . markedSpans , measure : measure , <nl> + classes : line . textClass + " | " + line . bgClass + " | " + line . wrapClass } ; <nl> + if ( cache . length = = 16 ) cache [ + + cm . display . measureLineCachePos % 16 ] = memo ; <nl> + else cache . push ( memo ) ; <nl> + } <nl> return measure ; <nl> } <nl> <nl> window . CodeMirror = ( function ( ) { <nl> <nl> removeChildrenAndAdd ( display . measure , pre ) ; <nl> <nl> - var outer = display . lineDiv . getBoundingClientRect ( ) ; <nl> + var outer = getRect ( display . lineDiv ) ; <nl> var vranges = [ ] , data = emptyArray ( line . text . length ) , maxBot = pre . offsetHeight ; <nl> + / / Work around an IE7 / 8 bug where it will sometimes have randomly <nl> + / / replaced our pre with a clone at this point . <nl> + if ( ie_lt9 & & display . measure . first ! = pre ) <nl> + removeChildrenAndAdd ( display . measure , pre ) ; <nl> + <nl> for ( var i = 0 , cur ; i < measure . length ; + + i ) if ( cur = measure [ i ] ) { <nl> - var size = cur . getBoundingClientRect ( ) ; <nl> + var size = getRect ( cur ) ; <nl> var top = Math . max ( 0 , size . top - outer . top ) , bot = Math . min ( size . bottom - outer . top , maxBot ) ; <nl> for ( var j = 0 ; j < vranges . length ; j + = 2 ) { <nl> var rtop = vranges [ j ] , rbot = vranges [ j + 1 ] ; <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> } <nl> if ( j = = vranges . length ) vranges . push ( top , bot ) ; <nl> - data [ i ] = { left : size . left - outer . left , right : size . right - outer . left , top : j } ; <nl> + var right = size . right ; <nl> + if ( cur . measureRight ) right = getRect ( cur . measureRight ) . left ; <nl> + data [ i ] = { left : size . left - outer . left , right : right - outer . left , top : j } ; <nl> } <nl> for ( var i = 0 , cur ; i < data . length ; + + i ) if ( cur = data [ i ] ) { <nl> var vr = cur . top ; <nl> cur . top = vranges [ vr ] ; cur . bottom = vranges [ vr + 1 ] ; <nl> } <nl> + <nl> return data ; <nl> } <nl> <nl> + function measureLineWidth ( cm , line ) { <nl> + var hasBadSpan = false ; <nl> + if ( line . markedSpans ) for ( var i = 0 ; i < line . markedSpans ; + + i ) { <nl> + var sp = line . markedSpans [ i ] ; <nl> + if ( sp . collapsed & & ( sp . to = = null | | sp . to = = line . text . length ) ) hasBadSpan = true ; <nl> + } <nl> + var cached = ! hasBadSpan & & findCachedMeasurement ( cm , line ) ; <nl> + if ( cached ) return measureChar ( cm , line , line . text . length , cached ) . right ; <nl> + <nl> + var pre = lineContent ( cm , line ) ; <nl> + var end = pre . appendChild ( zeroWidthElement ( cm . display . measure ) ) ; <nl> + removeChildrenAndAdd ( cm . display . measure , pre ) ; <nl> + return getRect ( end ) . right - getRect ( cm . display . lineDiv ) . left ; <nl> + } <nl> + <nl> function clearCaches ( cm ) { <nl> cm . display . measureLineCache . length = cm . display . measureLineCachePos = 0 ; <nl> cm . display . cachedCharWidth = cm . display . cachedTextHeight = null ; <nl> - cm . view . maxLineChanged = true ; <nl> + cm . display . maxLineChanged = true ; <nl> + cm . display . lineNumChars = null ; <nl> } <nl> <nl> / / Context is one of " line " , " div " ( display . lineDiv ) , " local " / null ( editor ) , or " page " <nl> window . CodeMirror = ( function ( ) { <nl> var yOff = heightAtLine ( cm , lineObj ) ; <nl> if ( context ! = " local " ) yOff - = cm . display . viewOffset ; <nl> if ( context = = " page " ) { <nl> - var lOff = cm . display . lineSpace . getBoundingClientRect ( ) ; <nl> + var lOff = getRect ( cm . display . lineSpace ) ; <nl> yOff + = lOff . top + ( window . pageYOffset | | ( document . documentElement | | document . body ) . scrollTop ) ; <nl> var xOff = lOff . left + ( window . pageXOffset | | ( document . documentElement | | document . body ) . scrollLeft ) ; <nl> rect . left + = xOff ; rect . right + = xOff ; <nl> window . CodeMirror = ( function ( ) { <nl> return rect ; <nl> } <nl> <nl> + / / Context may be " window " , " page " , " div " , or " local " / null <nl> + / / Result is in local coords <nl> + function fromCoordSystem ( cm , coords , context ) { <nl> + if ( context = = " div " ) return coords ; <nl> + var left = coords . left , top = coords . top ; <nl> + if ( context = = " page " ) { <nl> + left - = window . pageXOffset | | ( document . documentElement | | document . body ) . scrollLeft ; <nl> + top - = window . pageYOffset | | ( document . documentElement | | document . body ) . scrollTop ; <nl> + } <nl> + var lineSpaceBox = getRect ( cm . display . lineSpace ) ; <nl> + left - = lineSpaceBox . left ; <nl> + top - = lineSpaceBox . top ; <nl> + if ( context = = " local " | | ! context ) { <nl> + var editorBox = getRect ( cm . display . wrapper ) ; <nl> + left - = editorBox . left ; <nl> + top - = editorBox . top ; <nl> + } <nl> + return { left : left , top : top } ; <nl> + } <nl> + <nl> function charCoords ( cm , pos , context , lineObj ) { <nl> - if ( ! lineObj ) lineObj = getLine ( cm . view . doc , pos . line ) ; <nl> + if ( ! lineObj ) lineObj = getLine ( cm . doc , pos . line ) ; <nl> return intoCoordSystem ( cm , lineObj , measureChar ( cm , lineObj , pos . ch ) , context ) ; <nl> } <nl> <nl> function cursorCoords ( cm , pos , context , lineObj , measurement ) { <nl> - lineObj = lineObj | | getLine ( cm . view . doc , pos . line ) ; <nl> + lineObj = lineObj | | getLine ( cm . doc , pos . line ) ; <nl> if ( ! measurement ) measurement = measureLine ( cm , lineObj ) ; <nl> function get ( ch , right ) { <nl> var m = measureChar ( cm , lineObj , ch , measurement ) ; <nl> window . CodeMirror = ( function ( ) { <nl> if ( part . from < ch & & part . to > ch ) return get ( ch , rtl ) ; <nl> var left = rtl ? part . to : part . from , right = rtl ? part . from : part . to ; <nl> if ( left = = ch ) { <nl> - / / Opera and IE return bogus offsets and widths for edges <nl> - / / where the direction flips , but only for the side with the <nl> - / / lower level . So we try to use the side with the higher <nl> - / / level . <nl> + / / IE returns bogus offsets and widths for edges where the <nl> + / / direction flips , but only for the side with the lower <nl> + / / level . So we try to use the side with the higher level . <nl> if ( i & & part . level < ( nb = order [ i - 1 ] ) . level ) here = get ( nb . level % 2 ? nb . from : nb . to - 1 , true ) ; <nl> else here = get ( rtl & & part . from ! = part . to ? ch - 1 : ch ) ; <nl> if ( rtl = = linedir ) main = here ; else other = here ; <nl> window . CodeMirror = ( function ( ) { <nl> return main ; <nl> } <nl> <nl> + function PosMaybeOutside ( line , ch , outside ) { <nl> + var pos = new Pos ( line , ch ) ; <nl> + if ( outside ) pos . outside = true ; <nl> + return pos ; <nl> + } <nl> + <nl> / / Coords must be lineSpace - local <nl> function coordsChar ( cm , x , y ) { <nl> - var doc = cm . view . doc ; <nl> + var doc = cm . doc ; <nl> y + = cm . display . viewOffset ; <nl> - if ( y < 0 ) return { line : 0 , ch : 0 , outside : true } ; <nl> - var lineNo = lineAtHeight ( doc , y ) ; <nl> - if ( lineNo > = doc . size ) return { line : doc . size - 1 , ch : getLine ( doc , doc . size - 1 ) . text . length } ; <nl> + if ( y < 0 ) return PosMaybeOutside ( doc . first , 0 , true ) ; <nl> + var lineNo = lineAtHeight ( doc , y ) , last = doc . first + doc . size - 1 ; <nl> + if ( lineNo > last ) <nl> + return PosMaybeOutside ( doc . first + doc . size - 1 , getLine ( doc , last ) . text . length , true ) ; <nl> if ( x < 0 ) x = 0 ; <nl> <nl> for ( ; ; ) { <nl> window . CodeMirror = ( function ( ) { <nl> <nl> function coordsCharInner ( cm , lineObj , lineNo , x , y ) { <nl> var innerOff = y - heightAtLine ( cm , lineObj ) ; <nl> - var wrongLine = false , cWidth = cm . display . wrapper . clientWidth ; <nl> + var wrongLine = false , adjust = 2 * cm . display . wrapper . clientWidth ; <nl> var measurement = measureLine ( cm , lineObj ) ; <nl> <nl> function getX ( ch ) { <nl> - var sp = cursorCoords ( cm , { line : lineNo , ch : ch } , " line " , <nl> + var sp = cursorCoords ( cm , Pos ( lineNo , ch ) , " line " , <nl> lineObj , measurement ) ; <nl> wrongLine = true ; <nl> - if ( innerOff > sp . bottom ) return Math . max ( 0 , sp . left - cWidth ) ; <nl> - else if ( innerOff < sp . top ) return sp . left + cWidth ; <nl> + if ( innerOff > sp . bottom ) return sp . left - adjust ; <nl> + else if ( innerOff < sp . top ) return sp . left + adjust ; <nl> else wrongLine = false ; <nl> return sp . left ; <nl> } <nl> <nl> var bidi = getOrder ( lineObj ) , dist = lineObj . text . length ; <nl> var from = lineLeft ( lineObj ) , to = lineRight ( lineObj ) ; <nl> - var fromX = paddingLeft ( cm . display ) , toX = getX ( to ) ; <nl> + var fromX = getX ( from ) , fromOutside = wrongLine , toX = getX ( to ) , toOutside = wrongLine ; <nl> <nl> - if ( x > toX ) return { line : lineNo , ch : to , outside : wrongLine } ; <nl> + if ( x > toX ) return PosMaybeOutside ( lineNo , to , toOutside ) ; <nl> / / Do a binary search between these bounds . <nl> for ( ; ; ) { <nl> if ( bidi ? to = = from | | to = = moveVisually ( lineObj , from , 1 ) : to - from < = 1 ) { <nl> var after = x - fromX < toX - x , ch = after ? from : to ; <nl> while ( isExtendingChar . test ( lineObj . text . charAt ( ch ) ) ) + + ch ; <nl> - return { line : lineNo , ch : ch , after : after , outside : wrongLine } ; <nl> + var pos = PosMaybeOutside ( lineNo , ch , after ? fromOutside : toOutside ) ; <nl> + pos . after = after ; <nl> + return pos ; <nl> } <nl> var step = Math . ceil ( dist / 2 ) , middle = from + step ; <nl> if ( bidi ) { <nl> window . CodeMirror = ( function ( ) { <nl> for ( var i = 0 ; i < step ; + + i ) middle = moveVisually ( lineObj , middle , 1 ) ; <nl> } <nl> var middleX = getX ( middle ) ; <nl> - if ( middleX > x ) { to = middle ; toX = middleX ; if ( wrongLine ) toX + = 1000 ; dist - = step ; } <nl> - else { from = middle ; fromX = middleX ; dist = step ; } <nl> + if ( middleX > x ) { to = middle ; toX = middleX ; if ( toOutside = wrongLine ) toX + = 1000 ; dist - = step ; } <nl> + else { from = middle ; fromX = middleX ; fromOutside = wrongLine ; dist = step ; } <nl> } <nl> } <nl> <nl> window . CodeMirror = ( function ( ) { <nl> / / be awkward , slow , and error - prone ) , but instead updates are <nl> / / batched and then all combined and executed at once . <nl> <nl> + var nextOpId = 0 ; <nl> function startOperation ( cm ) { <nl> - if ( cm . curOp ) + + cm . curOp . depth ; <nl> - else cm . curOp = { <nl> - / / Nested operations delay update until the outermost one <nl> - / / finishes . <nl> - depth : 1 , <nl> + cm . curOp = { <nl> / / An array of ranges of lines that have to be updated . See <nl> / / updateDisplay . <nl> changes : [ ] , <nl> - delayedCallbacks : [ ] , <nl> updateInput : null , <nl> userSelChange : null , <nl> textChanged : null , <nl> selectionChanged : false , <nl> updateMaxLine : false , <nl> - id : + + cm . nextOpId <nl> + updateScrollPos : false , <nl> + id : + + nextOpId <nl> } ; <nl> + if ( ! delayedCallbackDepth + + ) delayedCallbacks = [ ] ; <nl> } <nl> <nl> function endOperation ( cm ) { <nl> - var op = cm . curOp ; <nl> - if ( - - op . depth ) return ; <nl> + var op = cm . curOp , doc = cm . doc , display = cm . display ; <nl> cm . curOp = null ; <nl> - var view = cm . view , display = cm . display ; <nl> - if ( op . updateMaxLine ) computeMaxLength ( view ) ; <nl> - if ( view . maxLineChanged & & ! cm . options . lineWrapping ) { <nl> - var width = measureChar ( cm , view . maxLine , view . maxLine . text . length ) . right ; <nl> - display . sizer . style . minWidth = ( width + 3 + scrollerCutOff ) + " px " ; <nl> - view . maxLineChanged = false ; <nl> + <nl> + if ( op . updateMaxLine ) computeMaxLength ( cm ) ; <nl> + if ( display . maxLineChanged & & ! cm . options . lineWrapping ) { <nl> + var width = measureLineWidth ( cm , display . maxLine ) ; <nl> + display . sizer . style . minWidth = Math . max ( 0 , width + 3 + scrollerCutOff ) + " px " ; <nl> + display . maxLineChanged = false ; <nl> var maxScrollLeft = Math . max ( 0 , display . sizer . offsetLeft + display . sizer . offsetWidth - display . scroller . clientWidth ) ; <nl> - if ( maxScrollLeft < view . scrollLeft ) <nl> + if ( maxScrollLeft < doc . scrollLeft & & ! op . updateScrollPos ) <nl> setScrollLeft ( cm , Math . min ( display . scroller . scrollLeft , maxScrollLeft ) , true ) ; <nl> } <nl> var newScrollPos , updated ; <nl> - if ( op . selectionChanged ) { <nl> - var coords = cursorCoords ( cm , view . sel . head ) ; <nl> + if ( op . updateScrollPos ) { <nl> + newScrollPos = op . updateScrollPos ; <nl> + } else if ( op . selectionChanged & & display . scroller . clientHeight ) { / / don ' t rescroll if not visible <nl> + var coords = cursorCoords ( cm , doc . sel . head ) ; <nl> newScrollPos = calculateScrollPos ( cm , coords . left , coords . top , coords . left , coords . bottom ) ; <nl> } <nl> - if ( op . changes . length | | newScrollPos & & newScrollPos . scrollTop ! = null ) <nl> + if ( op . changes . length | | newScrollPos & & newScrollPos . scrollTop ! = null ) { <nl> updated = updateDisplay ( cm , op . changes , newScrollPos & & newScrollPos . scrollTop ) ; <nl> + if ( cm . display . scroller . offsetHeight ) cm . doc . scrollTop = cm . display . scroller . scrollTop ; <nl> + } <nl> if ( ! updated & & op . selectionChanged ) updateSelection ( cm ) ; <nl> - if ( newScrollPos ) scrollCursorIntoView ( cm ) ; <nl> + if ( op . updateScrollPos ) { <nl> + display . scroller . scrollTop = display . scrollbarV . scrollTop = doc . scrollTop = newScrollPos . scrollTop ; <nl> + display . scroller . scrollLeft = display . scrollbarH . scrollLeft = doc . scrollLeft = newScrollPos . scrollLeft ; <nl> + alignHorizontally ( cm ) ; <nl> + } else if ( newScrollPos ) { <nl> + scrollCursorIntoView ( cm ) ; <nl> + } <nl> if ( op . selectionChanged ) restartBlink ( cm ) ; <nl> <nl> - if ( view . focused & & op . updateInput ) <nl> + if ( cm . state . focused & & op . updateInput ) <nl> resetInput ( cm , op . userSelChange ) ; <nl> <nl> + var hidden = op . maybeHiddenMarkers , unhidden = op . maybeUnhiddenMarkers ; <nl> + if ( hidden ) for ( var i = 0 ; i < hidden . length ; + + i ) <nl> + if ( ! hidden [ i ] . lines . length ) signal ( hidden [ i ] , " hide " ) ; <nl> + if ( unhidden ) for ( var i = 0 ; i < unhidden . length ; + + i ) <nl> + if ( unhidden [ i ] . lines . length ) signal ( unhidden [ i ] , " unhide " ) ; <nl> + <nl> + var delayed ; <nl> + if ( ! - - delayedCallbackDepth ) { <nl> + delayed = delayedCallbacks ; <nl> + delayedCallbacks = null ; <nl> + } <nl> if ( op . textChanged ) <nl> signal ( cm , " change " , cm , op . textChanged ) ; <nl> if ( op . selectionChanged ) signal ( cm , " cursorActivity " , cm ) ; <nl> - for ( var i = 0 ; i < op . delayedCallbacks . length ; + + i ) op . delayedCallbacks [ i ] ( cm ) ; <nl> + if ( delayed ) for ( var i = 0 ; i < delayed . length ; + + i ) delayed [ i ] ( ) ; <nl> } <nl> <nl> / / Wraps a function in an operation . Returns the wrapped function . <nl> function operation ( cm1 , f ) { <nl> return function ( ) { <nl> - var cm = cm1 | | this ; <nl> - startOperation ( cm ) ; <nl> - try { var result = f . apply ( cm , arguments ) ; } <nl> - finally { endOperation ( cm ) ; } <nl> + var cm = cm1 | | this , withOp = ! cm . curOp ; <nl> + if ( withOp ) startOperation ( cm ) ; <nl> + try { var result = f . apply ( cm , arguments ) ; } <nl> + finally { if ( withOp ) endOperation ( cm ) ; } <nl> + return result ; <nl> + } ; <nl> + } <nl> + function docOperation ( f ) { <nl> + return function ( ) { <nl> + var withOp = this . cm & & ! this . cm . curOp , result ; <nl> + if ( withOp ) startOperation ( this . cm ) ; <nl> + try { result = f . apply ( this , arguments ) ; } <nl> + finally { if ( withOp ) endOperation ( this . cm ) ; } <nl> return result ; <nl> } ; <nl> } <nl> + function runInOp ( cm , f ) { <nl> + var withOp = ! cm . curOp , result ; <nl> + if ( withOp ) startOperation ( cm ) ; <nl> + try { result = f ( ) ; } <nl> + finally { if ( withOp ) endOperation ( cm ) ; } <nl> + return result ; <nl> + } <nl> <nl> function regChange ( cm , from , to , lendiff ) { <nl> + if ( from = = null ) from = cm . doc . first ; <nl> + if ( to = = null ) to = cm . doc . first + cm . doc . size ; <nl> cm . curOp . changes . push ( { from : from , to : to , diff : lendiff } ) ; <nl> } <nl> <nl> / / INPUT HANDLING <nl> <nl> function slowPoll ( cm ) { <nl> - if ( cm . view . pollingFast ) return ; <nl> + if ( cm . display . pollingFast ) return ; <nl> cm . display . poll . set ( cm . options . pollInterval , function ( ) { <nl> readInput ( cm ) ; <nl> - if ( cm . view . focused ) slowPoll ( cm ) ; <nl> + if ( cm . state . focused ) slowPoll ( cm ) ; <nl> } ) ; <nl> } <nl> <nl> window . CodeMirror = ( function ( ) { <nl> / / events that indicate IME taking place , but these are not widely <nl> / / supported or compatible enough yet to rely on . ) <nl> function readInput ( cm ) { <nl> - var input = cm . display . input , prevInput = cm . display . prevInput , view = cm . view , sel = view . sel ; <nl> - if ( ! view . focused | | hasSelection ( input ) | | isReadOnly ( cm ) ) return false ; <nl> + var input = cm . display . input , prevInput = cm . display . prevInput , doc = cm . doc , sel = doc . sel ; <nl> + if ( ! cm . state . focused | | hasSelection ( input ) | | isReadOnly ( cm ) ) return false ; <nl> var text = input . value ; <nl> if ( text = = prevInput & & posEq ( sel . from , sel . to ) ) return false ; <nl> - startOperation ( cm ) ; <nl> - view . sel . shift = false ; <nl> + / / IE enjoys randomly deselecting our input ' s text when <nl> + / / re - focusing . If the selection is gone but the cursor is at the <nl> + / / start of the input , that ' s probably what happened . <nl> + if ( ie & & text & & input . selectionStart = = = 0 ) { <nl> + resetInput ( cm , true ) ; <nl> + return false ; <nl> + } <nl> + var withOp = ! cm . curOp ; <nl> + if ( withOp ) startOperation ( cm ) ; <nl> + sel . shift = false ; <nl> var same = 0 , l = Math . min ( prevInput . length , text . length ) ; <nl> while ( same < l & & prevInput [ same ] = = text [ same ] ) + + same ; <nl> var from = sel . from , to = sel . to ; <nl> if ( same < prevInput . length ) <nl> - from = { line : from . line , ch : from . ch - ( prevInput . length - same ) } ; <nl> - else if ( view . overwrite & & posEq ( from , to ) & & ! cm . display . pasteIncoming ) <nl> - to = { line : to . line , ch : Math . min ( getLine ( cm . view . doc , to . line ) . text . length , to . ch + ( text . length - same ) ) } ; <nl> + from = Pos ( from . line , from . ch - ( prevInput . length - same ) ) ; <nl> + else if ( cm . state . overwrite & & posEq ( from , to ) & & ! cm . state . pasteIncoming ) <nl> + to = Pos ( to . line , Math . min ( getLine ( doc , to . line ) . text . length , to . ch + ( text . length - same ) ) ) ; <nl> var updateInput = cm . curOp . updateInput ; <nl> - updateDoc ( cm , from , to , splitLines ( text . slice ( same ) ) , " end " , <nl> - cm . display . pasteIncoming ? " paste " : " input " , { from : from , to : to } ) ; <nl> + makeChange ( cm . doc , { from : from , to : to , text : splitLines ( text . slice ( same ) ) , <nl> + origin : cm . state . pasteIncoming ? " paste " : " + input " } , " end " ) ; <nl> + <nl> cm . curOp . updateInput = updateInput ; <nl> - if ( text . length > 1000 ) input . value = cm . display . prevInput = " " ; <nl> + if ( text . length > 1000 | | text . indexOf ( " \ n " ) > - 1 ) input . value = cm . display . prevInput = " " ; <nl> else cm . display . prevInput = text ; <nl> - endOperation ( cm ) ; <nl> - cm . display . pasteIncoming = false ; <nl> + if ( withOp ) endOperation ( cm ) ; <nl> + cm . state . pasteIncoming = false ; <nl> return true ; <nl> } <nl> <nl> function resetInput ( cm , user ) { <nl> - var view = cm . view , minimal , selected ; <nl> - if ( ! posEq ( view . sel . from , view . sel . to ) ) { <nl> + var minimal , selected , doc = cm . doc ; <nl> + if ( ! posEq ( doc . sel . from , doc . sel . to ) ) { <nl> cm . display . prevInput = " " ; <nl> minimal = hasCopyEvent & & <nl> - ( view . sel . to . line - view . sel . from . line > 100 | | ( selected = cm . getSelection ( ) ) . length > 1000 ) ; <nl> + ( doc . sel . to . line - doc . sel . from . line > 100 | | ( selected = cm . getSelection ( ) ) . length > 1000 ) ; <nl> if ( minimal ) cm . display . input . value = " - " ; <nl> else cm . display . input . value = selected | | cm . getSelection ( ) ; <nl> - if ( view . focused ) selectInput ( cm . display . input ) ; <nl> + if ( cm . state . focused ) selectInput ( cm . display . input ) ; <nl> } else if ( user ) cm . display . prevInput = cm . display . input . value = " " ; <nl> cm . display . inaccurateSelection = minimal ; <nl> } <nl> <nl> function focusInput ( cm ) { <nl> - if ( cm . options . readOnly ! = " nocursor " & & ( ie | | document . activeElement ! = cm . display . input ) ) <nl> + if ( cm . options . readOnly ! = " nocursor " & & ( ! mobile | | document . activeElement ! = cm . display . input ) ) <nl> cm . display . input . focus ( ) ; <nl> } <nl> <nl> function isReadOnly ( cm ) { <nl> - return cm . options . readOnly | | cm . view . cantEdit ; <nl> + return cm . options . readOnly | | cm . doc . cantEdit ; <nl> } <nl> <nl> / / EVENT HANDLERS <nl> window . CodeMirror = ( function ( ) { <nl> / / Gecko browsers fire contextmenu * after * opening the menu , at <nl> / / which point we can ' t mess with it anymore . Context menu is <nl> / / handled in onMouseDown for Gecko . <nl> - if ( ! gecko ) on ( d . scroller , " contextmenu " , function ( e ) { onContextMenu ( cm , e ) ; } ) ; <nl> + if ( ! captureMiddleClick ) on ( d . scroller , " contextmenu " , function ( e ) { onContextMenu ( cm , e ) ; } ) ; <nl> <nl> on ( d . scroller , " scroll " , function ( ) { <nl> - setScrollTop ( cm , d . scroller . scrollTop ) ; <nl> - setScrollLeft ( cm , d . scroller . scrollLeft , true ) ; <nl> - signal ( cm , " scroll " , cm ) ; <nl> + if ( d . scroller . clientHeight ) { <nl> + setScrollTop ( cm , d . scroller . scrollTop ) ; <nl> + setScrollLeft ( cm , d . scroller . scrollLeft , true ) ; <nl> + signal ( cm , " scroll " , cm ) ; <nl> + } <nl> } ) ; <nl> on ( d . scrollbarV , " scroll " , function ( ) { <nl> - setScrollTop ( cm , d . scrollbarV . scrollTop ) ; <nl> + if ( d . scroller . clientHeight ) setScrollTop ( cm , d . scrollbarV . scrollTop ) ; <nl> } ) ; <nl> on ( d . scrollbarH , " scroll " , function ( ) { <nl> - setScrollLeft ( cm , d . scrollbarH . scrollLeft ) ; <nl> + if ( d . scroller . clientHeight ) setScrollLeft ( cm , d . scrollbarH . scrollLeft ) ; <nl> } ) ; <nl> <nl> on ( d . scroller , " mousewheel " , function ( e ) { onScrollWheel ( cm , e ) ; } ) ; <nl> on ( d . scroller , " DOMMouseScroll " , function ( e ) { onScrollWheel ( cm , e ) ; } ) ; <nl> <nl> - function reFocus ( ) { if ( cm . view . focused ) setTimeout ( bind ( focusInput , cm ) , 0 ) ; } <nl> + function reFocus ( ) { if ( cm . state . focused ) setTimeout ( bind ( focusInput , cm ) , 0 ) ; } <nl> on ( d . scrollbarH , " mousedown " , reFocus ) ; <nl> on ( d . scrollbarV , " mousedown " , reFocus ) ; <nl> / / Prevent wrapper from ever scrolling <nl> on ( d . wrapper , " scroll " , function ( ) { d . wrapper . scrollTop = d . wrapper . scrollLeft = 0 ; } ) ; <nl> <nl> - if ( ! window . registered ) window . registered = 0 ; <nl> - + + window . registered ; <nl> function onResize ( ) { <nl> / / Might be a text scaling operation , clear size caches . <nl> d . cachedCharWidth = d . cachedTextHeight = null ; <nl> clearCaches ( cm ) ; <nl> - updateDisplay ( cm , true ) ; <nl> + runInOp ( cm , bind ( regChange , cm ) ) ; <nl> } <nl> on ( window , " resize " , onResize ) ; <nl> / / Above handler holds on to the editor and its data structures . <nl> / / Here we poll to unregister it when the editor is no longer in <nl> / / the document , so that it can be garbage - collected . <nl> - setTimeout ( function unregister ( ) { <nl> + function unregister ( ) { <nl> for ( var p = d . wrapper . parentNode ; p & & p ! = document . body ; p = p . parentNode ) { } <nl> if ( p ) setTimeout ( unregister , 5000 ) ; <nl> - else { - - window . registered ; off ( window , " resize " , onResize ) ; } <nl> - } , 5000 ) ; <nl> + else off ( window , " resize " , onResize ) ; <nl> + } <nl> + setTimeout ( unregister , 5000 ) ; <nl> <nl> on ( d . input , " keyup " , operation ( cm , function ( e ) { <nl> if ( cm . options . onKeyEvent & & cm . options . onKeyEvent ( cm , addStop ( e ) ) ) return ; <nl> - if ( e_prop ( e , " keyCode " ) = = 16 ) cm . view . sel . shift = false ; <nl> + if ( e . keyCode = = 16 ) cm . doc . sel . shift = false ; <nl> } ) ) ; <nl> on ( d . input , " input " , bind ( fastPoll , cm ) ) ; <nl> on ( d . input , " keydown " , operation ( cm , onKeyDown ) ) ; <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> on ( d . scroller , " paste " , function ( e ) { <nl> if ( eventInWidget ( d , e ) ) return ; <nl> - focusInput ( cm ) ; <nl> + focusInput ( cm ) ; <nl> fastPoll ( cm ) ; <nl> } ) ; <nl> on ( d . input , " paste " , function ( ) { <nl> - d . pasteIncoming = true ; <nl> + cm . state . pasteIncoming = true ; <nl> fastPoll ( cm ) ; <nl> } ) ; <nl> <nl> window . CodeMirror = ( function ( ) { <nl> target = = display . scrollbarV | | target = = display . scrollbarV . firstChild | | <nl> target = = display . scrollbarFiller ) return null ; <nl> } <nl> - var x , y , space = display . lineSpace . getBoundingClientRect ( ) ; <nl> + var x , y , space = getRect ( display . lineSpace ) ; <nl> / / Fails unpredictably on IE [ 67 ] when mouse is dragged around quickly . <nl> try { x = e . clientX ; y = e . clientY ; } catch ( e ) { return null ; } <nl> return coordsChar ( cm , x - space . left , y - space . top ) ; <nl> window . CodeMirror = ( function ( ) { <nl> <nl> var lastClick , lastDoubleClick ; <nl> function onMouseDown ( e ) { <nl> - var cm = this , display = cm . display , view = cm . view , sel = view . sel , doc = view . doc ; <nl> - sel . shift = e_prop ( e , " shiftKey " ) ; <nl> + var cm = this , display = cm . display , doc = cm . doc , sel = doc . sel ; <nl> + sel . shift = e . shiftKey ; <nl> <nl> if ( eventInWidget ( display , e ) ) { <nl> if ( ! webkit ) { <nl> window . CodeMirror = ( function ( ) { <nl> <nl> switch ( e_button ( e ) ) { <nl> case 3 : <nl> - if ( gecko ) onContextMenu . call ( cm , cm , e ) ; <nl> + if ( captureMiddleClick ) onContextMenu . call ( cm , cm , e ) ; <nl> return ; <nl> case 2 : <nl> - if ( start ) extendSelection ( cm , start ) ; <nl> + if ( start ) extendSelection ( cm . doc , start ) ; <nl> setTimeout ( bind ( focusInput , cm ) , 20 ) ; <nl> e_preventDefault ( e ) ; <nl> return ; <nl> window . CodeMirror = ( function ( ) { <nl> / / selection . <nl> if ( ! start ) { if ( e_target ( e ) = = display . scroller ) e_preventDefault ( e ) ; return ; } <nl> <nl> - if ( ! view . focused ) onFocus ( cm ) ; <nl> + if ( ! cm . state . focused ) onFocus ( cm ) ; <nl> <nl> var now = + new Date , type = " single " ; <nl> if ( lastDoubleClick & & lastDoubleClick . time > now - 400 & & posEq ( lastDoubleClick . pos , start ) ) { <nl> window . CodeMirror = ( function ( ) { <nl> lastDoubleClick = { time : now , pos : start } ; <nl> e_preventDefault ( e ) ; <nl> var word = findWordAt ( getLine ( doc , start . line ) . text , start ) ; <nl> - extendSelection ( cm , word . from , word . to ) ; <nl> + extendSelection ( cm . doc , word . from , word . to ) ; <nl> } else { lastClick = { time : now , pos : start } ; } <nl> <nl> var last = start ; <nl> window . CodeMirror = ( function ( ) { <nl> ! posLess ( start , sel . from ) & & ! posLess ( sel . to , start ) & & type = = " single " ) { <nl> var dragEnd = operation ( cm , function ( e2 ) { <nl> if ( webkit ) display . scroller . draggable = false ; <nl> - view . draggingText = false ; <nl> + cm . state . draggingText = false ; <nl> off ( document , " mouseup " , dragEnd ) ; <nl> off ( display . scroller , " drop " , dragEnd ) ; <nl> if ( Math . abs ( e . clientX - e2 . clientX ) + Math . abs ( e . clientY - e2 . clientY ) < 10 ) { <nl> e_preventDefault ( e2 ) ; <nl> - extendSelection ( cm , start ) ; <nl> + extendSelection ( cm . doc , start ) ; <nl> focusInput ( cm ) ; <nl> } <nl> } ) ; <nl> / / Let the drag handler handle this . <nl> if ( webkit ) display . scroller . draggable = true ; <nl> - view . draggingText = dragEnd ; <nl> + cm . state . draggingText = dragEnd ; <nl> / / IE ' s approach to draggable <nl> if ( display . scroller . dragDrop ) display . scroller . dragDrop ( ) ; <nl> on ( document , " mouseup " , dragEnd ) ; <nl> window . CodeMirror = ( function ( ) { <nl> return ; <nl> } <nl> e_preventDefault ( e ) ; <nl> - if ( type = = " single " ) extendSelection ( cm , clipPos ( doc , start ) ) ; <nl> + if ( type = = " single " ) extendSelection ( cm . doc , clipPos ( doc , start ) ) ; <nl> <nl> var startstart = sel . from , startend = sel . to ; <nl> <nl> function doSelect ( cur ) { <nl> if ( type = = " single " ) { <nl> - extendSelection ( cm , clipPos ( doc , start ) , cur ) ; <nl> + extendSelection ( cm . doc , clipPos ( doc , start ) , cur ) ; <nl> return ; <nl> } <nl> <nl> window . CodeMirror = ( function ( ) { <nl> startend = clipPos ( doc , startend ) ; <nl> if ( type = = " double " ) { <nl> var word = findWordAt ( getLine ( doc , cur . line ) . text , cur ) ; <nl> - if ( posLess ( cur , startstart ) ) extendSelection ( cm , word . from , startend ) ; <nl> - else extendSelection ( cm , startstart , word . to ) ; <nl> + if ( posLess ( cur , startstart ) ) extendSelection ( cm . doc , word . from , startend ) ; <nl> + else extendSelection ( cm . doc , startstart , word . to ) ; <nl> } else if ( type = = " triple " ) { <nl> - if ( posLess ( cur , startstart ) ) extendSelection ( cm , startend , clipPos ( doc , { line : cur . line , ch : 0 } ) ) ; <nl> - else extendSelection ( cm , startstart , clipPos ( doc , { line : cur . line + 1 , ch : 0 } ) ) ; <nl> + if ( posLess ( cur , startstart ) ) extendSelection ( cm . doc , startend , clipPos ( doc , Pos ( cur . line , 0 ) ) ) ; <nl> + else extendSelection ( cm . doc , startstart , clipPos ( doc , Pos ( cur . line + 1 , 0 ) ) ) ; <nl> } <nl> } <nl> <nl> - var editorSize = display . wrapper . getBoundingClientRect ( ) ; <nl> + var editorSize = getRect ( display . wrapper ) ; <nl> / / Used to ensure timeout re - tries don ' t fire when another extend <nl> / / happened in the meantime ( clearTimeout isn ' t reliable - - at <nl> / / least on Chrome , the timeouts still happen even when cleared , <nl> window . CodeMirror = ( function ( ) { <nl> var cur = posFromMouse ( cm , e , true ) ; <nl> if ( ! cur ) return ; <nl> if ( ! posEq ( cur , last ) ) { <nl> - if ( ! view . focused ) onFocus ( cm ) ; <nl> + if ( ! cm . state . focused ) onFocus ( cm ) ; <nl> last = cur ; <nl> doSelect ( cur ) ; <nl> var visible = visibleLines ( display , doc ) ; <nl> window . CodeMirror = ( function ( ) { <nl> reader . onload = function ( ) { <nl> text [ i ] = reader . result ; <nl> if ( + + read = = n ) { <nl> - pos = clipPos ( cm . view . doc , pos ) ; <nl> - operation ( cm , function ( ) { <nl> - var end = replaceRange ( cm , text . join ( " " ) , pos , pos , " paste " ) ; <nl> - setSelection ( cm , pos , end ) ; <nl> - } ) ( ) ; <nl> + pos = clipPos ( cm . doc , pos ) ; <nl> + makeChange ( cm . doc , { from : pos , to : pos , text : splitLines ( text . join ( " \ n " ) ) , origin : " paste " } , " around " ) ; <nl> } <nl> } ; <nl> reader . readAsText ( file ) ; <nl> window . CodeMirror = ( function ( ) { <nl> for ( var i = 0 ; i < n ; + + i ) loadFile ( files [ i ] , i ) ; <nl> } else { <nl> / / Don ' t do a replace if the drop happened inside of the selected text . <nl> - if ( cm . view . draggingText & & ! ( posLess ( pos , cm . view . sel . from ) | | posLess ( cm . view . sel . to , pos ) ) ) { <nl> - cm . view . draggingText ( e ) ; <nl> + if ( cm . state . draggingText & & ! ( posLess ( pos , cm . doc . sel . from ) | | posLess ( cm . doc . sel . to , pos ) ) ) { <nl> + cm . state . draggingText ( e ) ; <nl> / / Ensure the editor is re - focused <nl> setTimeout ( bind ( focusInput , cm ) , 20 ) ; <nl> return ; <nl> window . CodeMirror = ( function ( ) { <nl> try { <nl> var text = e . dataTransfer . getData ( " Text " ) ; <nl> if ( text ) { <nl> - var curFrom = cm . view . sel . from , curTo = cm . view . sel . to ; <nl> - setSelection ( cm , pos , pos ) ; <nl> - if ( cm . view . draggingText ) replaceRange ( cm , " " , curFrom , curTo , " paste " ) ; <nl> + var curFrom = cm . doc . sel . from , curTo = cm . doc . sel . to ; <nl> + setSelection ( cm . doc , pos , pos ) ; <nl> + if ( cm . state . draggingText ) replaceRange ( cm . doc , " " , curFrom , curTo , " paste " ) ; <nl> cm . replaceSelection ( text , null , " paste " ) ; <nl> focusInput ( cm ) ; <nl> onFocus ( cm ) ; <nl> window . CodeMirror = ( function ( ) { <nl> try { var mX = e . clientX , mY = e . clientY ; } <nl> catch ( e ) { return false ; } <nl> <nl> - if ( mX > = Math . floor ( display . gutters . getBoundingClientRect ( ) . right ) ) return false ; <nl> + if ( mX > = Math . floor ( getRect ( display . gutters ) . right ) ) return false ; <nl> e_preventDefault ( e ) ; <nl> if ( ! hasHandler ( cm , " gutterClick " ) ) return true ; <nl> <nl> - var lineBox = display . lineDiv . getBoundingClientRect ( ) ; <nl> + var lineBox = getRect ( display . lineDiv ) ; <nl> if ( mY > lineBox . bottom ) return true ; <nl> mY - = lineBox . top - display . viewOffset ; <nl> <nl> for ( var i = 0 ; i < cm . options . gutters . length ; + + i ) { <nl> var g = display . gutters . childNodes [ i ] ; <nl> - if ( g & & g . getBoundingClientRect ( ) . right > = mX ) { <nl> - var line = lineAtHeight ( cm . view . doc , mY ) ; <nl> + if ( g & & getRect ( g ) . right > = mX ) { <nl> + var line = lineAtHeight ( cm . doc , mY ) ; <nl> var gutter = cm . options . gutters [ i ] ; <nl> - signalLater ( cm , cm , " gutterClick " , cm , line , gutter , e ) ; <nl> + signalLater ( cm , " gutterClick " , cm , line , gutter , e ) ; <nl> break ; <nl> } <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> <nl> function onDragStart ( cm , e ) { <nl> if ( eventInWidget ( cm . display , e ) ) return ; <nl> - <nl> + <nl> var txt = cm . getSelection ( ) ; <nl> e . dataTransfer . setData ( " Text " , txt ) ; <nl> <nl> / / Use dummy image instead of default browsers image . <nl> / / Recent Safari ( ~ 6 . 0 . 2 ) have a tendency to segfault when this happens , so we don ' t do it there . <nl> - if ( e . dataTransfer . setDragImage & & ! safari ) { <nl> + if ( e . dataTransfer . setDragImage ) { <nl> var img = elt ( " img " , null , null , " position : fixed ; left : 0 ; top : 0 ; " ) ; <nl> if ( opera ) { <nl> img . width = img . height = 1 ; <nl> window . CodeMirror = ( function ( ) { <nl> / / Force a relayout , or Opera won ' t use our image for some obscure reason <nl> img . _top = img . offsetTop ; <nl> } <nl> + if ( safari ) { <nl> + if ( cm . display . dragImg ) { <nl> + img = cm . display . dragImg ; <nl> + } else { <nl> + cm . display . dragImg = img ; <nl> + img . src = " data : image / gif ; base64 , R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw = = " ; <nl> + cm . display . wrapper . appendChild ( img ) ; <nl> + } <nl> + } <nl> e . dataTransfer . setDragImage ( img , 0 , 0 ) ; <nl> if ( opera ) img . parentNode . removeChild ( img ) ; <nl> } <nl> } <nl> <nl> function setScrollTop ( cm , val ) { <nl> - if ( Math . abs ( cm . view . scrollTop - val ) < 2 ) return ; <nl> - cm . view . scrollTop = val ; <nl> + if ( Math . abs ( cm . doc . scrollTop - val ) < 2 ) return ; <nl> + cm . doc . scrollTop = val ; <nl> if ( ! gecko ) updateDisplay ( cm , [ ] , val ) ; <nl> if ( cm . display . scroller . scrollTop ! = val ) cm . display . scroller . scrollTop = val ; <nl> if ( cm . display . scrollbarV . scrollTop ! = val ) cm . display . scrollbarV . scrollTop = val ; <nl> if ( gecko ) updateDisplay ( cm , [ ] ) ; <nl> } <nl> function setScrollLeft ( cm , val , isScroller ) { <nl> - if ( isScroller ? val = = cm . view . scrollLeft : Math . abs ( cm . view . scrollLeft - val ) < 2 ) return ; <nl> + if ( isScroller ? val = = cm . doc . scrollLeft : Math . abs ( cm . doc . scrollLeft - val ) < 2 ) return ; <nl> val = Math . min ( val , cm . display . scroller . scrollWidth - cm . display . scroller . clientWidth ) ; <nl> - cm . view . scrollLeft = val ; <nl> + cm . doc . scrollLeft = val ; <nl> alignHorizontally ( cm ) ; <nl> if ( cm . display . scroller . scrollLeft ! = val ) cm . display . scroller . scrollLeft = val ; <nl> if ( cm . display . scrollbarH . scrollLeft ! = val ) cm . display . scrollbarH . scrollLeft = val ; <nl> window . CodeMirror = ( function ( ) { <nl> <nl> if ( dy & & wheelPixelsPerUnit ! = null ) { <nl> var pixels = dy * wheelPixelsPerUnit ; <nl> - var top = cm . view . scrollTop , bot = top + display . wrapper . clientHeight ; <nl> + var top = cm . doc . scrollTop , bot = top + display . wrapper . clientHeight ; <nl> if ( pixels < 0 ) top = Math . max ( 0 , top + pixels - 50 ) ; <nl> - else bot = Math . min ( cm . view . doc . height , bot + pixels + 50 ) ; <nl> + else bot = Math . min ( cm . doc . height , bot + pixels + 50 ) ; <nl> updateDisplay ( cm , [ ] , { top : top , bottom : bot } ) ; <nl> } <nl> <nl> window . CodeMirror = ( function ( ) { <nl> / / Ensure previous input has been read , so that the handler sees a <nl> / / consistent view of the document <nl> if ( cm . display . pollingFast & & readInput ( cm ) ) cm . display . pollingFast = false ; <nl> - var view = cm . view , prevShift = view . sel . shift ; <nl> + var doc = cm . doc , prevShift = doc . sel . shift , done = false ; <nl> try { <nl> - if ( isReadOnly ( cm ) ) view . suppressEdits = true ; <nl> - if ( dropShift ) view . sel . shift = false ; <nl> - bound ( cm ) ; <nl> - } catch ( e ) { <nl> - if ( e ! = Pass ) throw e ; <nl> - return false ; <nl> + if ( isReadOnly ( cm ) ) cm . state . suppressEdits = true ; <nl> + if ( dropShift ) doc . sel . shift = false ; <nl> + done = bound ( cm ) ! = Pass ; <nl> } finally { <nl> - view . sel . shift = prevShift ; <nl> - view . suppressEdits = false ; <nl> + doc . sel . shift = prevShift ; <nl> + cm . state . suppressEdits = false ; <nl> } <nl> - return true ; <nl> + return done ; <nl> } <nl> <nl> function allKeyMaps ( cm ) { <nl> - var maps = cm . view . keyMaps . slice ( 0 ) ; <nl> + var maps = cm . state . keyMaps . slice ( 0 ) ; <nl> + if ( cm . options . extraKeys ) maps . push ( cm . options . extraKeys ) ; <nl> maps . push ( cm . options . keyMap ) ; <nl> - if ( cm . options . extraKeys ) maps . unshift ( cm . options . extraKeys ) ; <nl> return maps ; <nl> } <nl> <nl> window . CodeMirror = ( function ( ) { <nl> cm . options . keyMap = ( next . call ? next . call ( null , cm ) : next ) ; <nl> } , 50 ) ; <nl> <nl> - var name = keyNames [ e_prop ( e , " keyCode " ) ] , handled = false ; <nl> - if ( name = = null | | e . altGraphKey ) return false ; <nl> - if ( e_prop ( e , " altKey " ) ) name = " Alt - " + name ; <nl> - if ( e_prop ( e , flipCtrlCmd ? " metaKey " : " ctrlKey " ) ) name = " Ctrl - " + name ; <nl> - if ( e_prop ( e , flipCtrlCmd ? " ctrlKey " : " metaKey " ) ) name = " Cmd - " + name ; <nl> - <nl> - var stopped = false ; <nl> - function stop ( ) { stopped = true ; } <nl> + var name = keyName ( e , true ) , handled = false ; <nl> + if ( ! name ) return false ; <nl> var keymaps = allKeyMaps ( cm ) ; <nl> <nl> - if ( e_prop ( e , " shiftKey " ) ) { <nl> - handled = lookupKey ( " Shift - " + name , keymaps , <nl> - function ( b ) { return doHandleBinding ( cm , b , true ) ; } , stop ) <nl> - | | lookupKey ( name , keymaps , function ( b ) { <nl> - if ( typeof b = = " string " & & / ^ go [ A - Z ] / . test ( b ) ) return doHandleBinding ( cm , b ) ; <nl> - } , stop ) ; <nl> + if ( e . shiftKey ) { <nl> + / / First try to resolve full name ( including ' Shift - ' ) . Failing <nl> + / / that , see if there is a cursor - motion command ( starting with <nl> + / / ' go ' ) bound to the keyname without ' Shift - ' . <nl> + handled = lookupKey ( " Shift - " + name , keymaps , function ( b ) { return doHandleBinding ( cm , b , true ) ; } ) <nl> + | | lookupKey ( name , keymaps , function ( b ) { <nl> + if ( typeof b = = " string " & & / ^ go [ A - Z ] / . test ( b ) ) return doHandleBinding ( cm , b ) ; <nl> + } ) ; <nl> } else { <nl> - handled = lookupKey ( name , keymaps , <nl> - function ( b ) { return doHandleBinding ( cm , b ) ; } , stop ) ; <nl> + handled = lookupKey ( name , keymaps , function ( b ) { return doHandleBinding ( cm , b ) ; } ) ; <nl> } <nl> - if ( stopped ) handled = false ; <nl> + if ( handled = = " stop " ) handled = false ; <nl> + <nl> if ( handled ) { <nl> e_preventDefault ( e ) ; <nl> restartBlink ( cm ) ; <nl> window . CodeMirror = ( function ( ) { <nl> var lastStoppedKey = null ; <nl> function onKeyDown ( e ) { <nl> var cm = this ; <nl> - if ( ! cm . view . focused ) onFocus ( cm ) ; <nl> + if ( ! cm . state . focused ) onFocus ( cm ) ; <nl> if ( ie & & e . keyCode = = 27 ) { e . returnValue = false ; } <nl> if ( cm . options . onKeyEvent & & cm . options . onKeyEvent ( cm , addStop ( e ) ) ) return ; <nl> - var code = e_prop ( e , " keyCode " ) ; <nl> + var code = e . keyCode ; <nl> / / IE does strange things with escape . <nl> - cm . view . sel . shift = code = = 16 | | e_prop ( e , " shiftKey " ) ; <nl> + cm . doc . sel . shift = code = = 16 | | e . shiftKey ; <nl> / / First give onKeyEvent option a chance to handle this . <nl> var handled = handleKeyBinding ( cm , e ) ; <nl> if ( opera ) { <nl> lastStoppedKey = handled ? code : null ; <nl> / / Opera has no cut event . . . we try to at least catch the key combo <nl> - if ( ! handled & & code = = 88 & & ! hasCopyEvent & & e_prop ( e , mac ? " metaKey " : " ctrlKey " ) ) <nl> + if ( ! handled & & code = = 88 & & ! hasCopyEvent & & ( mac ? e . metaKey : e . ctrlKey ) ) <nl> cm . replaceSelection ( " " ) ; <nl> } <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> function onKeyPress ( e ) { <nl> var cm = this ; <nl> if ( cm . options . onKeyEvent & & cm . options . onKeyEvent ( cm , addStop ( e ) ) ) return ; <nl> - var keyCode = e_prop ( e , " keyCode " ) , charCode = e_prop ( e , " charCode " ) ; <nl> + var keyCode = e . keyCode , charCode = e . charCode ; <nl> if ( opera & & keyCode = = lastStoppedKey ) { lastStoppedKey = null ; e_preventDefault ( e ) ; return ; } <nl> if ( ( ( opera & & ( ! e . which | | e . which < 10 ) ) | | khtml ) & & handleKeyBinding ( cm , e ) ) return ; <nl> var ch = String . fromCharCode ( charCode = = null ? keyCode : charCode ) ; <nl> - if ( this . options . electricChars & & this . view . mode . electricChars & & <nl> + if ( this . options . electricChars & & this . doc . mode . electricChars & & <nl> this . options . smartIndent & & ! isReadOnly ( this ) & & <nl> - this . view . mode . electricChars . indexOf ( ch ) > - 1 ) <nl> - setTimeout ( operation ( cm , function ( ) { indentLine ( cm , cm . view . sel . to . line , " smart " ) ; } ) , 75 ) ; <nl> + this . doc . mode . electricChars . indexOf ( ch ) > - 1 ) <nl> + setTimeout ( operation ( cm , function ( ) { indentLine ( cm , cm . doc . sel . to . line , " smart " ) ; } ) , 75 ) ; <nl> if ( handleCharBinding ( cm , e , ch ) ) return ; <nl> fastPoll ( cm ) ; <nl> } <nl> <nl> function onFocus ( cm ) { <nl> if ( cm . options . readOnly = = " nocursor " ) return ; <nl> - if ( ! cm . view . focused ) { <nl> + if ( ! cm . state . focused ) { <nl> signal ( cm , " focus " , cm ) ; <nl> - cm . view . focused = true ; <nl> - if ( cm . display . scroller . className . search ( / \ bCodeMirror - focused \ b / ) = = - 1 ) <nl> - cm . display . scroller . className + = " CodeMirror - focused " ; <nl> + cm . state . focused = true ; <nl> + if ( cm . display . wrapper . className . search ( / \ bCodeMirror - focused \ b / ) = = - 1 ) <nl> + cm . display . wrapper . className + = " CodeMirror - focused " ; <nl> resetInput ( cm , true ) ; <nl> } <nl> slowPoll ( cm ) ; <nl> restartBlink ( cm ) ; <nl> } <nl> function onBlur ( cm ) { <nl> - if ( cm . view . focused ) { <nl> + if ( cm . state . focused ) { <nl> signal ( cm , " blur " , cm ) ; <nl> - cm . view . focused = false ; <nl> - cm . display . scroller . className = cm . display . scroller . className . replace ( " CodeMirror - focused " , " " ) ; <nl> + cm . state . focused = false ; <nl> + cm . display . wrapper . className = cm . display . wrapper . className . replace ( " CodeMirror - focused " , " " ) ; <nl> } <nl> clearInterval ( cm . display . blinker ) ; <nl> - setTimeout ( function ( ) { if ( ! cm . view . focused ) cm . view . sel . shift = false ; } , 150 ) ; <nl> + setTimeout ( function ( ) { if ( ! cm . state . focused ) cm . doc . sel . shift = false ; } , 150 ) ; <nl> } <nl> <nl> var detectingSelectAll ; <nl> function onContextMenu ( cm , e ) { <nl> - var display = cm . display ; <nl> + var display = cm . display , sel = cm . doc . sel ; <nl> if ( eventInWidget ( display , e ) ) return ; <nl> - <nl> - var sel = cm . view . sel ; <nl> + <nl> var pos = posFromMouse ( cm , e ) , scrollPos = display . scroller . scrollTop ; <nl> if ( ! pos | | opera ) return ; / / Opera is difficult . <nl> if ( posEq ( sel . from , sel . to ) | | posLess ( pos , sel . from ) | | ! posLess ( pos , sel . to ) ) <nl> - operation ( cm , setSelection ) ( cm , pos , pos ) ; <nl> + operation ( cm , setSelection ) ( cm . doc , pos , pos ) ; <nl> <nl> var oldCSS = display . input . style . cssText ; <nl> display . inputDiv . style . position = " absolute " ; <nl> display . input . style . cssText = " position : fixed ; width : 30px ; height : 30px ; top : " + ( e . clientY - 5 ) + <nl> " px ; left : " + ( e . clientX - 5 ) + " px ; z - index : 1000 ; background : white ; outline : none ; " + <nl> - " border - width : 0 ; outline : none ; overflow : hidden ; opacity : . 05 ; filter : alpha ( opacity = 5 ) ; " ; <nl> + " border - width : 0 ; outline : none ; overflow : hidden ; opacity : . 05 ; - ms - opacity : . 05 ; filter : alpha ( opacity = 5 ) ; " ; <nl> focusInput ( cm ) ; <nl> resetInput ( cm , true ) ; <nl> / / Adds " Select all " to context menu in FF <nl> window . CodeMirror = ( function ( ) { <nl> if ( ie_lt9 ) display . scrollbarV . scrollTop = display . scroller . scrollTop = scrollPos ; <nl> slowPoll ( cm ) ; <nl> <nl> - / / Try to detect the user choosing select - all <nl> - if ( display . input . selectionStart ! = null ) { <nl> + / / Try to detect the user choosing select - all <nl> + if ( display . input . selectionStart ! = null & & ( ! ie | | ie_lt9 ) ) { <nl> clearTimeout ( detectingSelectAll ) ; <nl> var extval = display . input . value = " " + ( posEq ( sel . from , sel . to ) ? " " : display . input . value ) , i = 0 ; <nl> display . prevInput = " " ; <nl> display . input . selectionStart = 1 ; display . input . selectionEnd = extval . length ; <nl> - detectingSelectAll = setTimeout ( function poll ( ) { <nl> + var poll = function ( ) { <nl> if ( display . prevInput = = " " & & display . input . selectionStart = = 0 ) <nl> operation ( cm , commands . selectAll ) ( cm ) ; <nl> else if ( i + + < 10 ) detectingSelectAll = setTimeout ( poll , 500 ) ; <nl> else resetInput ( cm ) ; <nl> - } , 200 ) ; <nl> + } ; <nl> + detectingSelectAll = setTimeout ( poll , 200 ) ; <nl> } <nl> } <nl> <nl> - if ( gecko ) { <nl> + if ( captureMiddleClick ) { <nl> e_stop ( e ) ; <nl> - on ( window , " mouseup " , function mouseup ( ) { <nl> + var mouseup = function ( ) { <nl> off ( window , " mouseup " , mouseup ) ; <nl> setTimeout ( rehide , 20 ) ; <nl> - } ) ; <nl> + } ; <nl> + on ( window , " mouseup " , mouseup ) ; <nl> } else { <nl> setTimeout ( rehide , 50 ) ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> <nl> / / UPDATING <nl> <nl> - / / Replace the range from from to to by the strings in newText . <nl> - / / Afterwards , set the selection to selFrom , selTo . <nl> - function updateDoc ( cm , from , to , newText , selUpdate , origin ) { <nl> + function changeEnd ( change ) { <nl> + return Pos ( change . from . line + change . text . length - 1 , <nl> + lst ( change . text ) . length + ( change . text . length = = 1 ? change . from . ch : 0 ) ) ; <nl> + } <nl> + <nl> + / / Make sure a position will be valid after the given change . <nl> + function clipPostChange ( doc , change , pos ) { <nl> + if ( ! posLess ( change . from , pos ) ) return clipPos ( doc , pos ) ; <nl> + var diff = ( change . text . length - 1 ) - ( change . to . line - change . from . line ) ; <nl> + if ( pos . line > change . to . line + diff ) { <nl> + var preLine = pos . line - diff , lastLine = doc . first + doc . size - 1 ; <nl> + if ( preLine > lastLine ) return Pos ( lastLine , getLine ( doc , lastLine ) . text . length ) ; <nl> + return clipToLen ( pos , getLine ( doc , preLine ) . text . length ) ; <nl> + } <nl> + if ( pos . line = = change . to . line + diff ) <nl> + return clipToLen ( pos , lst ( change . text ) . length + ( change . text . length = = 1 ? change . from . ch : 0 ) + <nl> + getLine ( doc , change . to . line ) . text . length - change . to . ch ) ; <nl> + var inside = pos . line - change . from . line ; <nl> + return clipToLen ( pos , change . text [ inside ] . length + ( inside ? 0 : change . from . ch ) ) ; <nl> + } <nl> + <nl> + / / Hint can be null | " end " | " start " | " around " | { anchor , head } <nl> + function computeSelAfterChange ( doc , change , hint ) { <nl> + if ( hint & & typeof hint = = " object " ) / / Assumed to be { anchor , head } object <nl> + return { anchor : clipPostChange ( doc , change , hint . anchor ) , <nl> + head : clipPostChange ( doc , change , hint . head ) } ; <nl> + <nl> + if ( hint = = " start " ) return { anchor : change . from , head : change . from } ; <nl> + <nl> + var end = changeEnd ( change ) ; <nl> + if ( hint = = " around " ) return { anchor : change . from , head : end } ; <nl> + if ( hint = = " end " ) return { anchor : end , head : end } ; <nl> + <nl> + / / hint is null , leave the selection alone as much as possible <nl> + var adjustPos = function ( pos ) { <nl> + if ( posLess ( pos , change . from ) ) return pos ; <nl> + if ( ! posLess ( change . to , pos ) ) return end ; <nl> + <nl> + var line = pos . line + change . text . length - ( change . to . line - change . from . line ) - 1 , ch = pos . ch ; <nl> + if ( pos . line = = change . to . line ) ch + = end . ch - change . to . ch ; <nl> + return Pos ( line , ch ) ; <nl> + } ; <nl> + return { anchor : adjustPos ( doc . sel . anchor ) , head : adjustPos ( doc . sel . head ) } ; <nl> + } <nl> + <nl> + function filterChange ( doc , change ) { <nl> + var obj = { <nl> + canceled : false , <nl> + from : change . from , <nl> + to : change . to , <nl> + text : change . text , <nl> + origin : change . origin , <nl> + update : function ( from , to , text , origin ) { <nl> + if ( from ) this . from = clipPos ( doc , from ) ; <nl> + if ( to ) this . to = clipPos ( doc , to ) ; <nl> + if ( text ) this . text = text ; <nl> + if ( origin ! = = undefined ) this . origin = origin ; <nl> + } , <nl> + cancel : function ( ) { this . canceled = true ; } <nl> + } ; <nl> + signal ( doc , " beforeChange " , doc , obj ) ; <nl> + if ( doc . cm ) signal ( doc . cm , " beforeChange " , doc . cm , obj ) ; <nl> + <nl> + if ( obj . canceled ) return null ; <nl> + return { from : obj . from , to : obj . to , text : obj . text , origin : obj . origin } ; <nl> + } <nl> + <nl> + / / Replace the range from from to to by the strings in replacement . <nl> + / / change is a { from , to , text [ , origin ] } object <nl> + function makeChange ( doc , change , selUpdate , ignoreReadOnly ) { <nl> + if ( doc . cm ) { <nl> + if ( ! doc . cm . curOp ) return operation ( doc . cm , makeChange ) ( doc , change , selUpdate , ignoreReadOnly ) ; <nl> + if ( doc . cm . state . suppressEdits ) return ; <nl> + } <nl> + <nl> + if ( hasHandler ( doc , " beforeChange " ) | | doc . cm & & hasHandler ( doc . cm , " beforeChange " ) ) { <nl> + change = filterChange ( doc , change ) ; <nl> + if ( ! change ) return ; <nl> + } <nl> + <nl> / / Possibly split or suppress the update based on the presence <nl> / / of read - only spans in its range . <nl> - var split = sawReadOnlySpans & & <nl> - removeReadOnlyRanges ( cm . view . doc , from , to ) ; <nl> + var split = sawReadOnlySpans & & ! ignoreReadOnly & & removeReadOnlyRanges ( doc , change . from , change . to ) ; <nl> if ( split ) { <nl> for ( var i = split . length - 1 ; i > = 1 ; - - i ) <nl> - updateDocInner ( cm , split [ i ] . from , split [ i ] . to , [ " " ] , origin ) ; <nl> + makeChangeNoReadonly ( doc , { from : split [ i ] . from , to : split [ i ] . to , text : [ " " ] } ) ; <nl> if ( split . length ) <nl> - return updateDocInner ( cm , split [ 0 ] . from , split [ 0 ] . to , newText , selUpdate , origin ) ; <nl> + makeChangeNoReadonly ( doc , { from : split [ 0 ] . from , to : split [ 0 ] . to , text : change . text } , selUpdate ) ; <nl> } else { <nl> - return updateDocInner ( cm , from , to , newText , selUpdate , origin ) ; <nl> + makeChangeNoReadonly ( doc , change , selUpdate ) ; <nl> } <nl> } <nl> <nl> - function updateDocInner ( cm , from , to , newText , selUpdate , origin ) { <nl> - if ( cm . view . suppressEdits ) return ; <nl> + function makeChangeNoReadonly ( doc , change , selUpdate ) { <nl> + var selAfter = computeSelAfterChange ( doc , change , selUpdate ) ; <nl> + addToHistory ( doc , change , selAfter , doc . cm ? doc . cm . curOp . id : NaN ) ; <nl> <nl> - var view = cm . view , doc = view . doc , old = [ ] ; <nl> - doc . iter ( from . line , to . line + 1 , function ( line ) { <nl> - old . push ( newHL ( line . text , line . markedSpans ) ) ; <nl> + makeChangeSingleDoc ( doc , change , selAfter , stretchSpansOverChange ( doc , change ) ) ; <nl> + var rebased = [ ] ; <nl> + <nl> + linkedDocs ( doc , function ( doc , sharedHist ) { <nl> + if ( ! sharedHist & & indexOf ( rebased , doc . history ) = = - 1 ) { <nl> + rebaseHist ( doc . history , change ) ; <nl> + rebased . push ( doc . history ) ; <nl> + } <nl> + makeChangeSingleDoc ( doc , change , null , stretchSpansOverChange ( doc , change ) ) ; <nl> } ) ; <nl> - var startSelFrom = view . sel . from , startSelTo = view . sel . to ; <nl> - var lines = updateMarkedSpans ( hlSpans ( old [ 0 ] ) , hlSpans ( lst ( old ) ) , from . ch , to . ch , newText ) ; <nl> - var retval = updateDocNoUndo ( cm , from , to , lines , selUpdate , origin ) ; <nl> - if ( view . history ) addChange ( cm , from . line , newText . length , old , origin , <nl> - startSelFrom , startSelTo , view . sel . from , view . sel . to ) ; <nl> - return retval ; <nl> - } <nl> - <nl> - function unredoHelper ( cm , type ) { <nl> - var doc = cm . view . doc , hist = cm . view . history ; <nl> - var set = ( type = = " undo " ? hist . done : hist . undone ) . pop ( ) ; <nl> - if ( ! set ) return ; <nl> - var anti = { events : [ ] , fromBefore : set . fromAfter , toBefore : set . toAfter , <nl> - fromAfter : set . fromBefore , toAfter : set . toBefore } ; <nl> - for ( var i = set . events . length - 1 ; i > = 0 ; i - = 1 ) { <nl> - hist . dirtyCounter + = type = = " undo " ? - 1 : 1 ; <nl> - var change = set . events [ i ] ; <nl> - var replaced = [ ] , end = change . start + change . added ; <nl> - doc . iter ( change . start , end , function ( line ) { replaced . push ( newHL ( line . text , line . markedSpans ) ) ; } ) ; <nl> - anti . events . push ( { start : change . start , added : change . old . length , old : replaced } ) ; <nl> - var selPos = i ? null : { from : set . fromBefore , to : set . toBefore } ; <nl> - updateDocNoUndo ( cm , { line : change . start , ch : 0 } , { line : end - 1 , ch : getLine ( doc , end - 1 ) . text . length } , <nl> - change . old , selPos , type ) ; <nl> - } <nl> + } <nl> + <nl> + function makeChangeFromHistory ( doc , type ) { <nl> + if ( doc . cm & & doc . cm . state . suppressEdits ) return ; <nl> + <nl> + var hist = doc . history ; <nl> + var event = ( type = = " undo " ? hist . done : hist . undone ) . pop ( ) ; <nl> + if ( ! event ) return ; <nl> + hist . dirtyCounter + = type = = " undo " ? - 1 : 1 ; <nl> + <nl> + var anti = { changes : [ ] , anchorBefore : event . anchorAfter , headBefore : event . headAfter , <nl> + anchorAfter : event . anchorBefore , headAfter : event . headBefore } ; <nl> ( type = = " undo " ? hist . undone : hist . done ) . push ( anti ) ; <nl> + <nl> + for ( var i = event . changes . length - 1 ; i > = 0 ; - - i ) { <nl> + var change = event . changes [ i ] ; <nl> + change . origin = type ; <nl> + anti . changes . push ( historyChangeFromChange ( doc , change ) ) ; <nl> + <nl> + var after = i ? computeSelAfterChange ( doc , change , null ) <nl> + : { anchor : event . anchorBefore , head : event . headBefore } ; <nl> + makeChangeSingleDoc ( doc , change , after , mergeOldSpans ( doc , change ) ) ; <nl> + var rebased = [ ] ; <nl> + <nl> + linkedDocs ( doc , function ( doc , sharedHist ) { <nl> + if ( ! sharedHist & & indexOf ( rebased , doc . history ) = = - 1 ) { <nl> + rebaseHist ( doc . history , change ) ; <nl> + rebased . push ( doc . history ) ; <nl> + } <nl> + makeChangeSingleDoc ( doc , change , null , mergeOldSpans ( doc , change ) ) ; <nl> + } ) ; <nl> + } <nl> + } <nl> + <nl> + function shiftDoc ( doc , distance ) { <nl> + function shiftPos ( pos ) { return Pos ( pos . line + distance , pos . ch ) ; } <nl> + doc . first + = distance ; <nl> + if ( doc . cm ) regChange ( doc . cm , doc . first , doc . first , distance ) ; <nl> + doc . sel . head = shiftPos ( doc . sel . head ) ; doc . sel . anchor = shiftPos ( doc . sel . anchor ) ; <nl> + doc . sel . from = shiftPos ( doc . sel . from ) ; doc . sel . to = shiftPos ( doc . sel . to ) ; <nl> + } <nl> + <nl> + function makeChangeSingleDoc ( doc , change , selAfter , spans ) { <nl> + if ( doc . cm & & ! doc . cm . curOp ) <nl> + return operation ( doc . cm , makeChangeSingleDoc ) ( doc , change , selAfter , spans ) ; <nl> + <nl> + if ( change . to . line < doc . first ) { <nl> + shiftDoc ( doc , change . text . length - 1 - ( change . to . line - change . from . line ) ) ; <nl> + return ; <nl> + } <nl> + if ( change . from . line > doc . lastLine ( ) ) return ; <nl> + <nl> + / / Clip the change to the size of this doc <nl> + if ( change . from . line < doc . first ) { <nl> + var shift = change . text . length - 1 - ( doc . first - change . from . line ) ; <nl> + shiftDoc ( doc , shift ) ; <nl> + change = { from : Pos ( doc . first , 0 ) , to : Pos ( change . to . line + shift , change . to . ch ) , <nl> + text : [ lst ( change . text ) ] , origin : change . origin } ; <nl> + } <nl> + var last = doc . lastLine ( ) ; <nl> + if ( change . to . line > last ) { <nl> + change = { from : change . from , to : Pos ( last , getLine ( doc , last ) . text . length ) , <nl> + text : [ change . text [ 0 ] ] , origin : change . origin } ; <nl> + } <nl> + <nl> + change . removed = getBetween ( doc , change . from , change . to ) ; <nl> + <nl> + if ( ! selAfter ) selAfter = computeSelAfterChange ( doc , change , null ) ; <nl> + if ( doc . cm ) makeChangeSingleDocInEditor ( doc . cm , change , spans , selAfter ) ; <nl> + else updateDoc ( doc , change , spans , selAfter ) ; <nl> } <nl> <nl> - function updateDocNoUndo ( cm , from , to , lines , selUpdate , origin ) { <nl> - var view = cm . view , doc = view . doc , display = cm . display ; <nl> - if ( view . suppressEdits ) return ; <nl> + function makeChangeSingleDocInEditor ( cm , change , spans , selAfter ) { <nl> + var doc = cm . doc , display = cm . display , from = change . from , to = change . to ; <nl> <nl> - var nlines = to . line - from . line , firstLine = getLine ( doc , from . line ) , lastLine = getLine ( doc , to . line ) ; <nl> var recomputeMaxLength = false , checkWidthStart = from . line ; <nl> if ( ! cm . options . lineWrapping ) { <nl> - checkWidthStart = lineNo ( visualLine ( doc , firstLine ) ) ; <nl> + checkWidthStart = lineNo ( visualLine ( doc , getLine ( doc , from . line ) ) ) ; <nl> doc . iter ( checkWidthStart , to . line + 1 , function ( line ) { <nl> - if ( line = = view . maxLine ) { <nl> + if ( line = = display . maxLine ) { <nl> recomputeMaxLength = true ; <nl> return true ; <nl> } <nl> } ) ; <nl> } <nl> <nl> - var lastHL = lst ( lines ) , th = textHeight ( display ) ; <nl> - <nl> - / / First adjust the line structure <nl> - if ( from . ch = = 0 & & to . ch = = 0 & & hlText ( lastHL ) = = " " ) { <nl> - / / This is a whole - line replace . Treated specially to make <nl> - / / sure line objects move the way they are supposed to . <nl> - var added = [ ] ; <nl> - for ( var i = 0 , e = lines . length - 1 ; i < e ; + + i ) <nl> - added . push ( makeLine ( hlText ( lines [ i ] ) , hlSpans ( lines [ i ] ) , th ) ) ; <nl> - updateLine ( cm , lastLine , lastLine . text , hlSpans ( lastHL ) ) ; <nl> - if ( nlines ) doc . remove ( from . line , nlines , cm ) ; <nl> - if ( added . length ) doc . insert ( from . line , added ) ; <nl> - } else if ( firstLine = = lastLine ) { <nl> - if ( lines . length = = 1 ) { <nl> - updateLine ( cm , firstLine , firstLine . text . slice ( 0 , from . ch ) + hlText ( lines [ 0 ] ) + <nl> - firstLine . text . slice ( to . ch ) , hlSpans ( lines [ 0 ] ) ) ; <nl> - } else { <nl> - for ( var added = [ ] , i = 1 , e = lines . length - 1 ; i < e ; + + i ) <nl> - added . push ( makeLine ( hlText ( lines [ i ] ) , hlSpans ( lines [ i ] ) , th ) ) ; <nl> - added . push ( makeLine ( hlText ( lastHL ) + firstLine . text . slice ( to . ch ) , hlSpans ( lastHL ) , th ) ) ; <nl> - updateLine ( cm , firstLine , firstLine . text . slice ( 0 , from . ch ) + hlText ( lines [ 0 ] ) , hlSpans ( lines [ 0 ] ) ) ; <nl> - doc . insert ( from . line + 1 , added ) ; <nl> - } <nl> - } else if ( lines . length = = 1 ) { <nl> - updateLine ( cm , firstLine , firstLine . text . slice ( 0 , from . ch ) + hlText ( lines [ 0 ] ) + <nl> - lastLine . text . slice ( to . ch ) , hlSpans ( lines [ 0 ] ) ) ; <nl> - doc . remove ( from . line + 1 , nlines , cm ) ; <nl> - } else { <nl> - var added = [ ] ; <nl> - updateLine ( cm , firstLine , firstLine . text . slice ( 0 , from . ch ) + hlText ( lines [ 0 ] ) , hlSpans ( lines [ 0 ] ) ) ; <nl> - updateLine ( cm , lastLine , hlText ( lastHL ) + lastLine . text . slice ( to . ch ) , hlSpans ( lastHL ) ) ; <nl> - for ( var i = 1 , e = lines . length - 1 ; i < e ; + + i ) <nl> - added . push ( makeLine ( hlText ( lines [ i ] ) , hlSpans ( lines [ i ] ) , th ) ) ; <nl> - if ( nlines > 1 ) doc . remove ( from . line + 1 , nlines - 1 , cm ) ; <nl> - doc . insert ( from . line + 1 , added ) ; <nl> - } <nl> + updateDoc ( doc , change , spans , selAfter , estimateHeight ( cm ) ) ; <nl> <nl> - if ( cm . options . lineWrapping ) { <nl> - var perLine = Math . max ( 5 , display . scroller . clientWidth / charWidth ( display ) - 3 ) ; <nl> - doc . iter ( from . line , from . line + lines . length , function ( line ) { <nl> - if ( line . height = = 0 ) return ; <nl> - var guess = ( Math . ceil ( line . text . length / perLine ) | | 1 ) * th ; <nl> - if ( guess ! = line . height ) updateLineHeight ( line , guess ) ; <nl> - } ) ; <nl> - } else { <nl> - doc . iter ( checkWidthStart , from . line + lines . length , function ( line ) { <nl> + if ( ! cm . options . lineWrapping ) { <nl> + doc . iter ( checkWidthStart , from . line + change . text . length , function ( line ) { <nl> var len = lineLength ( doc , line ) ; <nl> - if ( len > view . maxLineLength ) { <nl> - view . maxLine = line ; <nl> - view . maxLineLength = len ; <nl> - view . maxLineChanged = true ; <nl> + if ( len > display . maxLineLength ) { <nl> + display . maxLine = line ; <nl> + display . maxLineLength = len ; <nl> + display . maxLineChanged = true ; <nl> recomputeMaxLength = false ; <nl> } <nl> } ) ; <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> <nl> / / Adjust frontier , schedule worker <nl> - view . frontier = Math . min ( view . frontier , from . line ) ; <nl> + doc . frontier = Math . min ( doc . frontier , from . line ) ; <nl> startWorker ( cm , 400 ) ; <nl> <nl> - var lendiff = lines . length - nlines - 1 ; <nl> + var lendiff = change . text . length - ( to . line - from . line ) - 1 ; <nl> / / Remember that these lines changed , for updating the display <nl> regChange ( cm , from . line , to . line + 1 , lendiff ) ; <nl> + <nl> if ( hasHandler ( cm , " change " ) ) { <nl> - / / Normalize lines to contain only strings , since that ' s what <nl> - / / the change event handler expects <nl> - for ( var i = 0 ; i < lines . length ; + + i ) <nl> - if ( typeof lines [ i ] ! = " string " ) lines [ i ] = lines [ i ] . text ; <nl> - var changeObj = { from : from , to : to , text : lines , origin : origin } ; <nl> + var changeObj = { from : from , to : to , <nl> + text : change . text , <nl> + removed : change . removed , <nl> + origin : change . origin } ; <nl> if ( cm . curOp . textChanged ) { <nl> for ( var cur = cm . curOp . textChanged ; cur . next ; cur = cur . next ) { } <nl> cur . next = changeObj ; <nl> } else cm . curOp . textChanged = changeObj ; <nl> } <nl> - <nl> - / / Update the selection <nl> - var newSelFrom , newSelTo , end = { line : from . line + lines . length - 1 , <nl> - ch : hlText ( lastHL ) . length + ( lines . length = = 1 ? from . ch : 0 ) } ; <nl> - if ( selUpdate & & typeof selUpdate ! = " string " ) { <nl> - if ( selUpdate . from ) { newSelFrom = selUpdate . from ; newSelTo = selUpdate . to ; } <nl> - else newSelFrom = newSelTo = selUpdate ; <nl> - } else if ( selUpdate = = " end " ) { <nl> - newSelFrom = newSelTo = end ; <nl> - } else if ( selUpdate = = " start " ) { <nl> - newSelFrom = newSelTo = from ; <nl> - } else if ( selUpdate = = " around " ) { <nl> - newSelFrom = from ; newSelTo = end ; <nl> - } else { <nl> - var adjustPos = function ( pos ) { <nl> - if ( posLess ( pos , from ) ) return pos ; <nl> - if ( ! posLess ( to , pos ) ) return end ; <nl> - var line = pos . line + lendiff ; <nl> - var ch = pos . ch ; <nl> - if ( pos . line = = to . line ) <nl> - ch + = hlText ( lastHL ) . length - ( to . ch - ( to . line = = from . line ? from . ch : 0 ) ) ; <nl> - return { line : line , ch : ch } ; <nl> - } ; <nl> - newSelFrom = adjustPos ( view . sel . from ) ; <nl> - newSelTo = adjustPos ( view . sel . to ) ; <nl> - } <nl> - setSelection ( cm , newSelFrom , newSelTo , null , true ) ; <nl> - return end ; <nl> } <nl> <nl> - function replaceRange ( cm , code , from , to , origin ) { <nl> + function replaceRange ( doc , code , from , to , origin ) { <nl> if ( ! to ) to = from ; <nl> if ( posLess ( to , from ) ) { var tmp = to ; to = from ; from = tmp ; } <nl> - return updateDoc ( cm , from , to , splitLines ( code ) , null , origin ) ; <nl> + if ( typeof code = = " string " ) code = splitLines ( code ) ; <nl> + makeChange ( doc , { from : from , to : to , text : code , origin : origin } , null ) ; <nl> } <nl> <nl> - / / SELECTION <nl> + / / POSITION OBJECT <nl> + <nl> + function Pos ( line , ch ) { <nl> + if ( ! ( this instanceof Pos ) ) return new Pos ( line , ch ) ; <nl> + this . line = line ; this . ch = ch ; <nl> + } <nl> + CodeMirror . Pos = Pos ; <nl> <nl> function posEq ( a , b ) { return a . line = = b . line & & a . ch = = b . ch ; } <nl> function posLess ( a , b ) { return a . line < b . line | | ( a . line = = b . line & & a . ch < b . ch ) ; } <nl> - function copyPos ( x ) { return { line : x . line , ch : x . ch } ; } <nl> + function copyPos ( x ) { return Pos ( x . line , x . ch ) ; } <nl> + <nl> + / / SELECTION <nl> <nl> - function clipLine ( doc , n ) { return Math . max ( 0 , Math . min ( n , doc . size - 1 ) ) ; } <nl> + function clipLine ( doc , n ) { return Math . max ( doc . first , Math . min ( n , doc . first + doc . size - 1 ) ) ; } <nl> function clipPos ( doc , pos ) { <nl> - if ( pos . line < 0 ) return { line : 0 , ch : 0 } ; <nl> - if ( pos . line > = doc . size ) return { line : doc . size - 1 , ch : getLine ( doc , doc . size - 1 ) . text . length } ; <nl> - var ch = pos . ch , linelen = getLine ( doc , pos . line ) . text . length ; <nl> - if ( ch = = null | | ch > linelen ) return { line : pos . line , ch : linelen } ; <nl> - else if ( ch < 0 ) return { line : pos . line , ch : 0 } ; <nl> + if ( pos . line < doc . first ) return Pos ( doc . first , 0 ) ; <nl> + var last = doc . first + doc . size - 1 ; <nl> + if ( pos . line > last ) return Pos ( last , getLine ( doc , last ) . text . length ) ; <nl> + return clipToLen ( pos , getLine ( doc , pos . line ) . text . length ) ; <nl> + } <nl> + function clipToLen ( pos , linelen ) { <nl> + var ch = pos . ch ; <nl> + if ( ch = = null | | ch > linelen ) return Pos ( pos . line , linelen ) ; <nl> + else if ( ch < 0 ) return Pos ( pos . line , 0 ) ; <nl> else return pos ; <nl> } <nl> - function isLine ( doc , l ) { return l > = 0 & & l < doc . size ; } <nl> + function isLine ( doc , l ) { return l > = doc . first & & l < doc . first + doc . size ; } <nl> <nl> / / If shift is held , this will move the selection anchor . Otherwise , <nl> / / it ' ll set the whole selection . <nl> - function extendSelection ( cm , pos , other , bias ) { <nl> - var sel = cm . view . sel ; <nl> - if ( sel . shift | | sel . extend ) { <nl> - var anchor = sel . anchor ; <nl> + function extendSelection ( doc , pos , other , bias ) { <nl> + if ( doc . sel . shift | | doc . sel . extend ) { <nl> + var anchor = doc . sel . anchor ; <nl> if ( other ) { <nl> var posBefore = posLess ( pos , anchor ) ; <nl> if ( posBefore ! = posLess ( other , anchor ) ) { <nl> window . CodeMirror = ( function ( ) { <nl> pos = other ; <nl> } <nl> } <nl> - setSelection ( cm , anchor , pos , bias ) ; <nl> + setSelection ( doc , anchor , pos , bias ) ; <nl> } else { <nl> - setSelection ( cm , pos , other | | pos , bias ) ; <nl> + setSelection ( doc , pos , other | | pos , bias ) ; <nl> } <nl> - cm . curOp . userSelChange = true ; <nl> + if ( doc . cm ) doc . cm . curOp . userSelChange = true ; <nl> + } <nl> + <nl> + function filterSelectionChange ( doc , anchor , head ) { <nl> + var obj = { anchor : anchor , head : head } ; <nl> + signal ( doc , " beforeSelectionChange " , doc , obj ) ; <nl> + if ( doc . cm ) signal ( doc . cm , " beforeSelectionChange " , doc . cm , obj ) ; <nl> + obj . anchor = clipPos ( doc , obj . anchor ) ; obj . head = clipPos ( doc , obj . head ) ; <nl> + return obj ; <nl> } <nl> <nl> / / Update the selection . Last two args are only used by <nl> / / updateDoc , since they have to be expressed in the line <nl> / / numbers before the update . <nl> - function setSelection ( cm , anchor , head , bias , checkAtomic ) { <nl> - cm . view . goalColumn = null ; <nl> - var sel = cm . view . sel ; <nl> + function setSelection ( doc , anchor , head , bias , checkAtomic ) { <nl> + if ( ! checkAtomic & & hasHandler ( doc , " beforeSelectionChange " ) | | doc . cm & & hasHandler ( doc . cm , " beforeSelectionChange " ) ) { <nl> + var filtered = filterSelectionChange ( doc , anchor , head ) ; <nl> + head = filtered . head ; <nl> + anchor = filtered . anchor ; <nl> + } <nl> + <nl> + var sel = doc . sel ; <nl> + sel . goalColumn = null ; <nl> / / Skip over atomic spans . <nl> if ( checkAtomic | | ! posEq ( anchor , sel . anchor ) ) <nl> - anchor = skipAtomic ( cm , anchor , bias , checkAtomic ! = " push " ) ; <nl> + anchor = skipAtomic ( doc , anchor , bias , checkAtomic ! = " push " ) ; <nl> if ( checkAtomic | | ! posEq ( head , sel . head ) ) <nl> - head = skipAtomic ( cm , head , bias , checkAtomic ! = " push " ) ; <nl> + head = skipAtomic ( doc , head , bias , checkAtomic ! = " push " ) ; <nl> <nl> if ( posEq ( sel . anchor , anchor ) & & posEq ( sel . head , head ) ) return ; <nl> <nl> window . CodeMirror = ( function ( ) { <nl> sel . from = inv ? head : anchor ; <nl> sel . to = inv ? anchor : head ; <nl> <nl> - cm . curOp . updateInput = true ; <nl> - cm . curOp . selectionChanged = true ; <nl> + if ( doc . cm ) <nl> + doc . cm . curOp . updateInput = doc . cm . curOp . selectionChanged = true ; <nl> + <nl> + signalLater ( doc , " cursorActivity " , doc ) ; <nl> } <nl> <nl> function reCheckSelection ( cm ) { <nl> - setSelection ( cm , cm . view . sel . from , cm . view . sel . to , null , " push " ) ; <nl> + setSelection ( cm . doc , cm . doc . sel . from , cm . doc . sel . to , null , " push " ) ; <nl> } <nl> <nl> - function skipAtomic ( cm , pos , bias , mayClear ) { <nl> - var doc = cm . view . doc , flipped = false , curPos = pos ; <nl> + function skipAtomic ( doc , pos , bias , mayClear ) { <nl> + var flipped = false , curPos = pos ; <nl> var dir = bias | | 1 ; <nl> - cm . view . cantEdit = false ; <nl> + doc . cantEdit = false ; <nl> search : for ( ; ; ) { <nl> - var line = getLine ( doc , curPos . line ) , toClear ; <nl> + var line = getLine ( doc , curPos . line ) ; <nl> if ( line . markedSpans ) { <nl> for ( var i = 0 ; i < line . markedSpans . length ; + + i ) { <nl> var sp = line . markedSpans [ i ] , m = sp . marker ; <nl> if ( ( sp . from = = null | | ( m . inclusiveLeft ? sp . from < = curPos . ch : sp . from < curPos . ch ) ) & & <nl> ( sp . to = = null | | ( m . inclusiveRight ? sp . to > = curPos . ch : sp . to > curPos . ch ) ) ) { <nl> - if ( mayClear & & m . clearOnEnter ) { <nl> - ( toClear | | ( toClear = [ ] ) ) . push ( m ) ; <nl> - continue ; <nl> - } else if ( ! m . atomic ) continue ; <nl> + if ( mayClear ) { <nl> + signal ( m , " beforeCursorEnter " ) ; <nl> + if ( m . explicitlyCleared ) { <nl> + if ( ! line . markedSpans ) break ; <nl> + else { - - i ; continue ; } <nl> + } <nl> + } <nl> + if ( ! m . atomic ) continue ; <nl> var newPos = m . find ( ) [ dir < 0 ? " from " : " to " ] ; <nl> if ( posEq ( newPos , curPos ) ) { <nl> newPos . ch + = dir ; <nl> if ( newPos . ch < 0 ) { <nl> - if ( newPos . line ) newPos = clipPos ( doc , { line : newPos . line - 1 } ) ; <nl> + if ( newPos . line > doc . first ) newPos = clipPos ( doc , Pos ( newPos . line - 1 ) ) ; <nl> else newPos = null ; <nl> } else if ( newPos . ch > line . text . length ) { <nl> - if ( newPos . line < doc . size - 1 ) newPos = { line : newPos . line + 1 , ch : 0 } ; <nl> + if ( newPos . line < doc . first + doc . size - 1 ) newPos = Pos ( newPos . line + 1 , 0 ) ; <nl> else newPos = null ; <nl> } <nl> if ( ! newPos ) { <nl> if ( flipped ) { <nl> / / Driven in a corner - - no valid cursor position found at all <nl> / / - - try again * with * clearing , if we didn ' t already <nl> - if ( ! mayClear ) return skipAtomic ( cm , pos , bias , true ) ; <nl> + if ( ! mayClear ) return skipAtomic ( doc , pos , bias , true ) ; <nl> / / Otherwise , turn off editing until further notice , and return the start of the doc <nl> - cm . view . cantEdit = true ; <nl> - return { line : 0 , ch : 0 } ; <nl> + doc . cantEdit = true ; <nl> + return Pos ( doc . first , 0 ) ; <nl> } <nl> flipped = true ; newPos = pos ; dir = - dir ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> continue search ; <nl> } <nl> } <nl> - if ( toClear ) for ( var i = 0 ; i < toClear . length ; + + i ) toClear [ i ] . clear ( ) ; <nl> } <nl> return curPos ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> / / SCROLLING <nl> <nl> function scrollCursorIntoView ( cm ) { <nl> - var view = cm . view ; <nl> - var coords = scrollPosIntoView ( cm , view . sel . head ) ; <nl> - if ( ! view . focused ) return ; <nl> - var display = cm . display , box = display . sizer . getBoundingClientRect ( ) , doScroll = null ; <nl> - if ( coords . top + box . top < 0 ) doScroll = true ; <nl> - else if ( coords . bottom + box . top > ( window . innerHeight | | document . documentElement . clientHeight ) ) doScroll = false ; <nl> + var coords = scrollPosIntoView ( cm , cm . doc . sel . head ) ; <nl> + if ( ! cm . state . focused ) return ; <nl> + var display = cm . display , box = getRect ( display . sizer ) , doScroll = null , pTop = paddingTop ( cm . display ) ; <nl> + if ( coords . top + pTop + box . top < 0 ) doScroll = true ; <nl> + else if ( coords . bottom + pTop + box . top > ( window . innerHeight | | document . documentElement . clientHeight ) ) doScroll = false ; <nl> if ( doScroll ! = null & & ! phantom ) { <nl> var hidden = display . cursor . style . display = = " none " ; <nl> if ( hidden ) { <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> } <nl> <nl> - function scrollPosIntoView ( cm , pos ) { <nl> + function scrollPosIntoView ( cm , pos , margin ) { <nl> + if ( margin = = null ) margin = 0 ; <nl> for ( ; ; ) { <nl> var changed = false , coords = cursorCoords ( cm , pos ) ; <nl> - var scrollPos = calculateScrollPos ( cm , coords . left , coords . top , coords . left , coords . bottom ) ; <nl> - var startTop = cm . view . scrollTop , startLeft = cm . view . scrollLeft ; <nl> + var scrollPos = calculateScrollPos ( cm , coords . left , coords . top - margin , coords . left , coords . bottom + margin ) ; <nl> + var startTop = cm . doc . scrollTop , startLeft = cm . doc . scrollLeft ; <nl> if ( scrollPos . scrollTop ! = null ) { <nl> setScrollTop ( cm , scrollPos . scrollTop ) ; <nl> - if ( Math . abs ( cm . view . scrollTop - startTop ) > 1 ) changed = true ; <nl> + if ( Math . abs ( cm . doc . scrollTop - startTop ) > 1 ) changed = true ; <nl> } <nl> if ( scrollPos . scrollLeft ! = null ) { <nl> setScrollLeft ( cm , scrollPos . scrollLeft ) ; <nl> - if ( Math . abs ( cm . view . scrollLeft - startLeft ) > 1 ) changed = true ; <nl> + if ( Math . abs ( cm . doc . scrollLeft - startLeft ) > 1 ) changed = true ; <nl> } <nl> if ( ! changed ) return coords ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> var display = cm . display , pt = paddingTop ( display ) ; <nl> y1 + = pt ; y2 + = pt ; <nl> var screen = display . scroller . clientHeight - scrollerCutOff , screentop = display . scroller . scrollTop , result = { } ; <nl> - var docBottom = cm . view . doc . height + 2 * pt ; <nl> + var docBottom = cm . doc . height + paddingVert ( display ) ; <nl> var atTop = y1 < pt + 10 , atBottom = y2 + pt > docBottom - 10 ; <nl> if ( y1 < screentop ) result . scrollTop = atTop ? 0 : Math . max ( 0 , y1 ) ; <nl> else if ( y2 > screentop + screen ) result . scrollTop = ( atBottom ? docBottom : y2 ) - screen ; <nl> window . CodeMirror = ( function ( ) { <nl> return result ; <nl> } <nl> <nl> + function updateScrollPos ( cm , left , top ) { <nl> + cm . curOp . updateScrollPos = { scrollLeft : left , scrollTop : top } ; <nl> + } <nl> + <nl> + function addToScrollPos ( cm , left , top ) { <nl> + var pos = cm . curOp . updateScrollPos | | ( cm . curOp . updateScrollPos = { scrollLeft : cm . doc . scrollLeft , scrollTop : cm . doc . scrollTop } ) ; <nl> + var scroll = cm . display . scroller ; <nl> + pos . scrollTop = Math . max ( 0 , Math . min ( scroll . scrollHeight - scroll . clientHeight , pos . scrollTop + top ) ) ; <nl> + pos . scrollLeft = Math . max ( 0 , Math . min ( scroll . scrollWidth - scroll . clientWidth , pos . scrollLeft + left ) ) ; <nl> + } <nl> + <nl> / / API UTILITIES <nl> <nl> function indentLine ( cm , n , how , aggressive ) { <nl> - var doc = cm . view . doc ; <nl> + var doc = cm . doc ; <nl> if ( ! how ) how = " add " ; <nl> if ( how = = " smart " ) { <nl> - if ( ! cm . view . mode . indent ) how = " prev " ; <nl> + if ( ! cm . doc . mode . indent ) how = " prev " ; <nl> else var state = getStateBefore ( cm , n ) ; <nl> } <nl> <nl> window . CodeMirror = ( function ( ) { <nl> var line = getLine ( doc , n ) , curSpace = countColumn ( line . text , null , tabSize ) ; <nl> var curSpaceString = line . text . match ( / ^ \ s * / ) [ 0 ] , indentation ; <nl> if ( how = = " smart " ) { <nl> - indentation = cm . view . mode . indent ( state , line . text . slice ( curSpaceString . length ) , line . text ) ; <nl> + indentation = cm . doc . mode . indent ( state , line . text . slice ( curSpaceString . length ) , line . text ) ; <nl> if ( indentation = = Pass ) { <nl> if ( ! aggressive ) return ; <nl> how = " prev " ; <nl> } <nl> } <nl> if ( how = = " prev " ) { <nl> - if ( n ) indentation = countColumn ( getLine ( doc , n - 1 ) . text , null , tabSize ) ; <nl> + if ( n > doc . first ) indentation = countColumn ( getLine ( doc , n - 1 ) . text , null , tabSize ) ; <nl> else indentation = 0 ; <nl> + } else if ( how = = " add " ) { <nl> + indentation = curSpace + cm . options . indentUnit ; <nl> + } else if ( how = = " subtract " ) { <nl> + indentation = curSpace - cm . options . indentUnit ; <nl> } <nl> - else if ( how = = " add " ) indentation = curSpace + cm . options . indentUnit ; <nl> - else if ( how = = " subtract " ) indentation = curSpace - cm . options . indentUnit ; <nl> indentation = Math . max ( 0 , indentation ) ; <nl> <nl> var indentString = " " , pos = 0 ; <nl> window . CodeMirror = ( function ( ) { <nl> if ( pos < indentation ) indentString + = spaceStr ( indentation - pos ) ; <nl> <nl> if ( indentString ! = curSpaceString ) <nl> - replaceRange ( cm , indentString , { line : n , ch : 0 } , { line : n , ch : curSpaceString . length } , " input " ) ; <nl> + replaceRange ( cm . doc , indentString , Pos ( n , 0 ) , Pos ( n , curSpaceString . length ) , " + input " ) ; <nl> line . stateAfter = null ; <nl> } <nl> <nl> function changeLine ( cm , handle , op ) { <nl> - var no = handle , line = handle , doc = cm . view . doc ; <nl> + var no = handle , line = handle , doc = cm . doc ; <nl> if ( typeof handle = = " number " ) line = getLine ( doc , clipLine ( doc , handle ) ) ; <nl> else no = lineNo ( handle ) ; <nl> if ( no = = null ) return null ; <nl> window . CodeMirror = ( function ( ) { <nl> return line ; <nl> } <nl> <nl> - function findPosH ( cm , dir , unit , visually ) { <nl> - var doc = cm . view . doc , end = cm . view . sel . head , line = end . line , ch = end . ch ; <nl> + function findPosH ( doc , pos , dir , unit , visually ) { <nl> + var line = pos . line , ch = pos . ch ; <nl> var lineObj = getLine ( doc , line ) ; <nl> + var possible = true ; <nl> function findNextLine ( ) { <nl> var l = line + dir ; <nl> - if ( l < 0 | | l = = doc . size ) return false ; <nl> + if ( l < doc . first | | l > = doc . first + doc . size ) return ( possible = false ) ; <nl> line = l ; <nl> return lineObj = getLine ( doc , l ) ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> if ( ! boundToLine & & findNextLine ( ) ) { <nl> if ( visually ) ch = ( dir < 0 ? lineRight : lineLeft ) ( lineObj ) ; <nl> else ch = dir < 0 ? lineObj . text . length : 0 ; <nl> - } else return false ; <nl> + } else return ( possible = false ) ; <nl> } else ch = next ; <nl> return true ; <nl> } <nl> + <nl> if ( unit = = " char " ) moveOnce ( ) ; <nl> else if ( unit = = " column " ) moveOnce ( true ) ; <nl> - else if ( unit = = " word " ) { <nl> - var sawWord = false ; <nl> - for ( ; ; ) { <nl> - if ( dir < 0 ) if ( ! moveOnce ( ) ) break ; <nl> - if ( isWordChar ( lineObj . text . charAt ( ch ) ) ) sawWord = true ; <nl> - else if ( sawWord ) { if ( dir < 0 ) { dir = 1 ; moveOnce ( ) ; } break ; } <nl> - if ( dir > 0 ) if ( ! moveOnce ( ) ) break ; <nl> + else if ( unit = = " word " | | unit = = " group " ) { <nl> + var sawType = null , group = unit = = " group " ; <nl> + for ( var first = true ; ; first = false ) { <nl> + if ( dir < 0 & & ! moveOnce ( ! first ) ) break ; <nl> + var cur = lineObj . text . charAt ( ch ) | | " \ n " ; <nl> + var type = isWordChar ( cur ) ? " w " <nl> + : ! group ? null <nl> + : / \ s / . test ( cur ) ? null <nl> + : " p " ; <nl> + if ( sawType & & sawType ! = type ) { <nl> + if ( dir < 0 ) { dir = 1 ; moveOnce ( ) ; } <nl> + break ; <nl> + } <nl> + if ( type ) sawType = type ; <nl> + if ( dir > 0 & & ! moveOnce ( ! first ) ) break ; <nl> } <nl> } <nl> - return skipAtomic ( cm , { line : line , ch : ch } , dir , true ) ; <nl> + var result = skipAtomic ( doc , Pos ( line , ch ) , dir , true ) ; <nl> + if ( ! possible ) result . hitSide = true ; <nl> + return result ; <nl> + } <nl> + <nl> + function findPosV ( cm , pos , dir , unit ) { <nl> + var doc = cm . doc , x = pos . left , y ; <nl> + if ( unit = = " page " ) { <nl> + var pageSize = Math . min ( cm . display . wrapper . clientHeight , window . innerHeight | | document . documentElement . clientHeight ) ; <nl> + y = pos . top + dir * ( pageSize - ( dir < 0 ? 1 . 5 : . 5 ) * textHeight ( cm . display ) ) ; <nl> + } else if ( unit = = " line " ) { <nl> + y = dir > 0 ? pos . bottom + 3 : pos . top - 3 ; <nl> + } <nl> + for ( ; ; ) { <nl> + var target = coordsChar ( cm , x , y ) ; <nl> + if ( ! target . outside ) break ; <nl> + if ( dir < 0 ? y < = 0 : y > = doc . height ) { target . hitSide = true ; break ; } <nl> + y + = dir * 5 ; <nl> + } <nl> + return target ; <nl> } <nl> <nl> function findWordAt ( line , pos ) { <nl> window . CodeMirror = ( function ( ) { <nl> if ( line ) { <nl> if ( pos . after = = = false | | end = = line . length ) - - start ; else + + end ; <nl> var startChar = line . charAt ( start ) ; <nl> - var check = isWordChar ( startChar ) ? isWordChar : <nl> - / \ s / . test ( startChar ) ? function ( ch ) { return / \ s / . test ( ch ) ; } : <nl> - function ( ch ) { return ! / \ s / . test ( ch ) & & ! isWordChar ( ch ) ; } ; <nl> + var check = isWordChar ( startChar ) ? isWordChar <nl> + : / \ s / . test ( startChar ) ? function ( ch ) { return / \ s / . test ( ch ) ; } <nl> + : function ( ch ) { return ! / \ s / . test ( ch ) & & ! isWordChar ( ch ) ; } ; <nl> while ( start > 0 & & check ( line . charAt ( start - 1 ) ) ) - - start ; <nl> while ( end < line . length & & check ( line . charAt ( end ) ) ) + + end ; <nl> } <nl> - return { from : { line : pos . line , ch : start } , to : { line : pos . line , ch : end } } ; <nl> + return { from : Pos ( pos . line , start ) , to : Pos ( pos . line , end ) } ; <nl> } <nl> <nl> function selectLine ( cm , line ) { <nl> - extendSelection ( cm , { line : line , ch : 0 } , clipPos ( cm . view . doc , { line : line + 1 , ch : 0 } ) ) ; <nl> + extendSelection ( cm . doc , Pos ( line , 0 ) , clipPos ( cm . doc , Pos ( line + 1 , 0 ) ) ) ; <nl> } <nl> <nl> / / PROTOTYPE <nl> window . CodeMirror = ( function ( ) { <nl> / / ' wrap f in an operation , performed on its ` this ` parameter ' <nl> <nl> CodeMirror . prototype = { <nl> - getValue : function ( lineSep ) { <nl> - var text = [ ] , doc = this . view . doc ; <nl> - doc . iter ( 0 , doc . size , function ( line ) { text . push ( line . text ) ; } ) ; <nl> - return text . join ( lineSep | | " \ n " ) ; <nl> - } , <nl> - <nl> - setValue : operation ( null , function ( code ) { <nl> - var doc = this . view . doc , top = { line : 0 , ch : 0 } , lastLen = getLine ( doc , doc . size - 1 ) . text . length ; <nl> - updateDocInner ( this , top , { line : doc . size - 1 , ch : lastLen } , splitLines ( code ) , top , top , " setValue " ) ; <nl> - } ) , <nl> - <nl> - getSelection : function ( lineSep ) { return this . getRange ( this . view . sel . from , this . view . sel . to , lineSep ) ; } , <nl> - <nl> - replaceSelection : operation ( null , function ( code , collapse , origin ) { <nl> - var sel = this . view . sel ; <nl> - updateDoc ( this , sel . from , sel . to , splitLines ( code ) , collapse | | " around " , origin ) ; <nl> - } ) , <nl> - <nl> focus : function ( ) { window . focus ( ) ; focusInput ( this ) ; onFocus ( this ) ; fastPoll ( this ) ; } , <nl> <nl> setOption : function ( option , value ) { <nl> window . CodeMirror = ( function ( ) { <nl> } , <nl> <nl> getOption : function ( option ) { return this . options [ option ] ; } , <nl> + getDoc : function ( ) { return this . doc ; } , <nl> <nl> - getMode : function ( ) { return this . view . mode ; } , <nl> - <nl> - addKeyMap : function ( map ) { <nl> - this . view . keyMaps . push ( map ) ; <nl> + addKeyMap : function ( map , bottom ) { <nl> + this . state . keyMaps [ bottom ? " push " : " unshift " ] ( map ) ; <nl> } , <nl> - <nl> removeKeyMap : function ( map ) { <nl> - var maps = this . view . keyMaps ; <nl> + var maps = this . state . keyMaps ; <nl> for ( var i = 0 ; i < maps . length ; + + i ) <nl> if ( ( typeof map = = " string " ? maps [ i ] . name : maps [ i ] ) = = map ) { <nl> maps . splice ( i , 1 ) ; <nl> window . CodeMirror = ( function ( ) { <nl> addOverlay : operation ( null , function ( spec , options ) { <nl> var mode = spec . token ? spec : CodeMirror . getMode ( this . options , spec ) ; <nl> if ( mode . startState ) throw new Error ( " Overlays may not be stateful . " ) ; <nl> - this . view . overlays . push ( { mode : mode , modeSpec : spec , opaque : options & & options . opaque } ) ; <nl> - this . view . modeGen + + ; <nl> - regChange ( this , 0 , this . view . doc . size ) ; <nl> + this . state . overlays . push ( { mode : mode , modeSpec : spec , opaque : options & & options . opaque } ) ; <nl> + this . state . modeGen + + ; <nl> + regChange ( this ) ; <nl> } ) , <nl> removeOverlay : operation ( null , function ( spec ) { <nl> - var overlays = this . view . overlays ; <nl> + var overlays = this . state . overlays ; <nl> for ( var i = 0 ; i < overlays . length ; + + i ) { <nl> if ( overlays [ i ] . modeSpec = = spec ) { <nl> overlays . splice ( i , 1 ) ; <nl> - this . view . modeGen + + ; <nl> - regChange ( this , 0 , this . view . doc . size ) ; <nl> + this . state . modeGen + + ; <nl> + regChange ( this ) ; <nl> return ; <nl> } <nl> } <nl> } ) , <nl> <nl> - undo : operation ( null , function ( ) { unredoHelper ( this , " undo " ) ; } ) , <nl> - redo : operation ( null , function ( ) { unredoHelper ( this , " redo " ) ; } ) , <nl> - <nl> indentLine : operation ( null , function ( n , dir , aggressive ) { <nl> if ( typeof dir ! = " string " ) { <nl> if ( dir = = null ) dir = this . options . smartIndent ? " smart " : " prev " ; <nl> else dir = dir ? " add " : " subtract " ; <nl> } <nl> - if ( isLine ( this . view . doc , n ) ) indentLine ( this , n , dir , aggressive ) ; <nl> + if ( isLine ( this . doc , n ) ) indentLine ( this , n , dir , aggressive ) ; <nl> } ) , <nl> - <nl> indentSelection : operation ( null , function ( how ) { <nl> - var sel = this . view . sel ; <nl> + var sel = this . doc . sel ; <nl> if ( posEq ( sel . from , sel . to ) ) return indentLine ( this , sel . from . line , how ) ; <nl> var e = sel . to . line - ( sel . to . ch ? 0 : 1 ) ; <nl> for ( var i = sel . from . line ; i < = e ; + + i ) indentLine ( this , i , how ) ; <nl> } ) , <nl> <nl> - historySize : function ( ) { <nl> - var hist = this . view . history ; <nl> - return { undo : hist . done . length , redo : hist . undone . length } ; <nl> - } , <nl> - <nl> - clearHistory : function ( ) { this . view . history = makeHistory ( ) ; } , <nl> - <nl> - markClean : function ( ) { <nl> - this . view . history . dirtyCounter = 0 ; <nl> - this . view . history . lastOp = this . view . history . lastOrigin = null ; <nl> - } , <nl> - <nl> - isClean : function ( ) { return this . view . history . dirtyCounter = = 0 ; } , <nl> - <nl> - getHistory : function ( ) { <nl> - var hist = this . view . history ; <nl> - function cp ( arr ) { <nl> - for ( var i = 0 , nw = [ ] , nwelt ; i < arr . length ; + + i ) { <nl> - var set = arr [ i ] ; <nl> - nw . push ( { events : nwelt = [ ] , fromBefore : set . fromBefore , toBefore : set . toBefore , <nl> - fromAfter : set . fromAfter , toAfter : set . toAfter } ) ; <nl> - for ( var j = 0 , elt = set . events ; j < elt . length ; + + j ) { <nl> - var old = [ ] , cur = elt [ j ] ; <nl> - nwelt . push ( { start : cur . start , added : cur . added , old : old } ) ; <nl> - for ( var k = 0 ; k < cur . old . length ; + + k ) old . push ( hlText ( cur . old [ k ] ) ) ; <nl> - } <nl> - } <nl> - return nw ; <nl> - } <nl> - return { done : cp ( hist . done ) , undone : cp ( hist . undone ) } ; <nl> - } , <nl> - <nl> - setHistory : function ( histData ) { <nl> - var hist = this . view . history = makeHistory ( ) ; <nl> - hist . done = histData . done ; <nl> - hist . undone = histData . undone ; <nl> - } , <nl> - <nl> / / Fetch the parser token for a given character . Useful for hacks <nl> / / that want to inspect the mode state ( say , for completion ) . <nl> getTokenAt : function ( pos ) { <nl> - var doc = this . view . doc ; <nl> + var doc = this . doc ; <nl> pos = clipPos ( doc , pos ) ; <nl> - var state = getStateBefore ( this , pos . line ) , mode = this . view . mode ; <nl> + var state = getStateBefore ( this , pos . line ) , mode = this . doc . mode ; <nl> var line = getLine ( doc , pos . line ) ; <nl> var stream = new StringStream ( line . text , this . options . tabSize ) ; <nl> while ( stream . pos < pos . ch & & ! stream . eol ( ) ) { <nl> window . CodeMirror = ( function ( ) { <nl> } , <nl> <nl> getStateAfter : function ( line ) { <nl> - var doc = this . view . doc ; <nl> - line = clipLine ( doc , line = = null ? doc . size - 1 : line ) ; <nl> + var doc = this . doc ; <nl> + line = clipLine ( doc , line = = null ? doc . first + doc . size - 1 : line ) ; <nl> return getStateBefore ( this , line + 1 ) ; <nl> } , <nl> <nl> cursorCoords : function ( start , mode ) { <nl> - var pos , sel = this . view . sel ; <nl> + var pos , sel = this . doc . sel ; <nl> if ( start = = null ) pos = sel . head ; <nl> - else if ( typeof start = = " object " ) pos = clipPos ( this . view . doc , start ) ; <nl> + else if ( typeof start = = " object " ) pos = clipPos ( this . doc , start ) ; <nl> else pos = start ? sel . from : sel . to ; <nl> return cursorCoords ( this , pos , mode | | " page " ) ; <nl> } , <nl> <nl> charCoords : function ( pos , mode ) { <nl> - return charCoords ( this , clipPos ( this . view . doc , pos ) , mode | | " page " ) ; <nl> + return charCoords ( this , clipPos ( this . doc , pos ) , mode | | " page " ) ; <nl> } , <nl> <nl> - coordsChar : function ( coords ) { <nl> - var off = this . display . lineSpace . getBoundingClientRect ( ) ; <nl> - return coordsChar ( this , coords . left - off . left , coords . top - off . top ) ; <nl> + coordsChar : function ( coords , mode ) { <nl> + coords = fromCoordSystem ( this , coords , mode | | " page " ) ; <nl> + return coordsChar ( this , coords . left , coords . top ) ; <nl> } , <nl> <nl> defaultTextHeight : function ( ) { return textHeight ( this . display ) ; } , <nl> - <nl> - markText : operation ( null , function ( from , to , options ) { <nl> - return markText ( this , clipPos ( this . view . doc , from ) , clipPos ( this . view . doc , to ) , <nl> - options , " range " ) ; <nl> - } ) , <nl> - <nl> - setBookmark : operation ( null , function ( pos , widget ) { <nl> - pos = clipPos ( this . view . doc , pos ) ; <nl> - return markText ( this , pos , pos , widget ? { replacedWith : widget } : { } , " bookmark " ) ; <nl> - } ) , <nl> - <nl> - findMarksAt : function ( pos ) { <nl> - var doc = this . view . doc ; <nl> - pos = clipPos ( doc , pos ) ; <nl> - var markers = [ ] , spans = getLine ( doc , pos . line ) . markedSpans ; <nl> - if ( spans ) for ( var i = 0 ; i < spans . length ; + + i ) { <nl> - var span = spans [ i ] ; <nl> - if ( ( span . from = = null | | span . from < = pos . ch ) & & <nl> - ( span . to = = null | | span . to > = pos . ch ) ) <nl> - markers . push ( span . marker ) ; <nl> - } <nl> - return markers ; <nl> - } , <nl> + defaultCharWidth : function ( ) { return charWidth ( this . display ) ; } , <nl> <nl> setGutterMarker : operation ( null , function ( line , gutterID , value ) { <nl> return changeLine ( this , line , function ( line ) { <nl> window . CodeMirror = ( function ( ) { <nl> } ) , <nl> <nl> clearGutter : operation ( null , function ( gutterID ) { <nl> - var i = 0 , cm = this , doc = cm . view . doc ; <nl> - doc . iter ( 0 , doc . size , function ( line ) { <nl> + var cm = this , doc = cm . doc , i = doc . first ; <nl> + doc . iter ( function ( line ) { <nl> if ( line . gutterMarkers & & line . gutterMarkers [ gutterID ] ) { <nl> line . gutterMarkers [ gutterID ] = null ; <nl> regChange ( cm , i , i + 1 ) ; <nl> window . CodeMirror = ( function ( ) { <nl> <nl> lineInfo : function ( line ) { <nl> if ( typeof line = = " number " ) { <nl> - if ( ! isLine ( this . view . doc , line ) ) return null ; <nl> + if ( ! isLine ( this . doc , line ) ) return null ; <nl> var n = line ; <nl> - line = getLine ( this . view . doc , line ) ; <nl> + line = getLine ( this . doc , line ) ; <nl> if ( ! line ) return null ; <nl> } else { <nl> var n = lineNo ( line ) ; <nl> window . CodeMirror = ( function ( ) { <nl> <nl> addWidget : function ( pos , node , scroll , vert , horiz ) { <nl> var display = this . display ; <nl> - pos = cursorCoords ( this , clipPos ( this . view . doc , pos ) ) ; <nl> - var top = pos . top , left = pos . left ; <nl> + pos = cursorCoords ( this , clipPos ( this . doc , pos ) ) ; <nl> + var top = pos . bottom , left = pos . left ; <nl> node . style . position = " absolute " ; <nl> display . sizer . appendChild ( node ) ; <nl> - if ( vert = = " over " ) top = pos . top ; <nl> - else if ( vert = = " near " ) { <nl> - var vspace = Math . max ( display . wrapper . clientHeight , this . view . doc . height ) , <nl> + if ( vert = = " over " ) { <nl> + top = pos . top ; <nl> + } else if ( vert = = " above " | | vert = = " near " ) { <nl> + var vspace = Math . max ( display . wrapper . clientHeight , this . doc . height ) , <nl> hspace = Math . max ( display . sizer . clientWidth , display . lineSpace . clientWidth ) ; <nl> - if ( pos . bottom + node . offsetHeight > vspace & & pos . top > node . offsetHeight ) <nl> + / / Default to positioning above ( if specified and possible ) ; otherwise default to positioning below <nl> + if ( ( vert = = ' above ' | | pos . bottom + node . offsetHeight > vspace ) & & pos . top > node . offsetHeight ) <nl> top = pos . top - node . offsetHeight ; <nl> + else if ( pos . bottom + node . offsetHeight < = vspace ) <nl> + top = pos . bottom ; <nl> if ( left + node . offsetWidth > hspace ) <nl> left = hspace - node . offsetWidth ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> scrollIntoView ( this , left , top , left + node . offsetWidth , top + node . offsetHeight ) ; <nl> } , <nl> <nl> - lineCount : function ( ) { return this . view . doc . size ; } , <nl> + triggerOnKeyDown : operation ( null , onKeyDown ) , <nl> <nl> - clipPos : function ( pos ) { return clipPos ( this . view . doc , pos ) ; } , <nl> + execCommand : function ( cmd ) { return commands [ cmd ] ( this ) ; } , <nl> <nl> - getCursor : function ( start ) { <nl> - var sel = this . view . sel , pos ; <nl> - if ( start = = null | | start = = " head " ) pos = sel . head ; <nl> - else if ( start = = " anchor " ) pos = sel . anchor ; <nl> - else if ( start = = " end " | | start = = = false ) pos = sel . to ; <nl> - else pos = sel . from ; <nl> - return copyPos ( pos ) ; <nl> + findPosH : function ( from , amount , unit , visually ) { <nl> + var dir = 1 ; <nl> + if ( amount < 0 ) { dir = - 1 ; amount = - amount ; } <nl> + for ( var i = 0 , cur = clipPos ( this . doc , from ) ; i < amount ; + + i ) { <nl> + cur = findPosH ( this . doc , cur , dir , unit , visually ) ; <nl> + if ( cur . hitSide ) break ; <nl> + } <nl> + return cur ; <nl> } , <nl> <nl> - somethingSelected : function ( ) { return ! posEq ( this . view . sel . from , this . view . sel . to ) ; } , <nl> - <nl> - setCursor : operation ( null , function ( line , ch , extend ) { <nl> - var pos = clipPos ( this . view . doc , typeof line = = " number " ? { line : line , ch : ch | | 0 } : line ) ; <nl> - if ( extend ) extendSelection ( this , pos ) ; <nl> - else setSelection ( this , pos , pos ) ; <nl> + moveH : operation ( null , function ( dir , unit ) { <nl> + var sel = this . doc . sel , pos ; <nl> + if ( sel . shift | | sel . extend | | posEq ( sel . from , sel . to ) ) <nl> + pos = findPosH ( this . doc , sel . head , dir , unit , this . options . rtlMoveVisually ) ; <nl> + else <nl> + pos = dir < 0 ? sel . from : sel . to ; <nl> + extendSelection ( this . doc , pos , pos , dir ) ; <nl> } ) , <nl> <nl> - setSelection : operation ( null , function ( anchor , head ) { <nl> - var doc = this . view . doc ; <nl> - setSelection ( this , clipPos ( doc , anchor ) , clipPos ( doc , head | | anchor ) ) ; <nl> + deleteH : operation ( null , function ( dir , unit ) { <nl> + var sel = this . doc . sel ; <nl> + if ( ! posEq ( sel . from , sel . to ) ) replaceRange ( this . doc , " " , sel . from , sel . to , " + delete " ) ; <nl> + else replaceRange ( this . doc , " " , sel . from , findPosH ( this . doc , sel . head , dir , unit , false ) , " + delete " ) ; <nl> + this . curOp . userSelChange = true ; <nl> } ) , <nl> <nl> - extendSelection : operation ( null , function ( from , to ) { <nl> - var doc = this . view . doc ; <nl> - extendSelection ( this , clipPos ( doc , from ) , to & & clipPos ( doc , to ) ) ; <nl> - } ) , <nl> - <nl> - setExtending : function ( val ) { this . view . sel . extend = val ; } , <nl> - <nl> - getLine : function ( line ) { var l = this . getLineHandle ( line ) ; return l & & l . text ; } , <nl> - <nl> - getLineHandle : function ( line ) { <nl> - var doc = this . view . doc ; <nl> - if ( isLine ( doc , line ) ) return getLine ( doc , line ) ; <nl> - } , <nl> - <nl> - getLineNumber : function ( line ) { return lineNo ( line ) ; } , <nl> - <nl> - setLine : operation ( null , function ( line , text ) { <nl> - if ( isLine ( this . view . doc , line ) ) <nl> - replaceRange ( this , text , { line : line , ch : 0 } , { line : line , ch : getLine ( this . view . doc , line ) . text . length } ) ; <nl> - } ) , <nl> - <nl> - removeLine : operation ( null , function ( line ) { <nl> - if ( isLine ( this . view . doc , line ) ) <nl> - replaceRange ( this , " " , { line : line , ch : 0 } , clipPos ( this . view . doc , { line : line + 1 , ch : 0 } ) ) ; <nl> - } ) , <nl> - <nl> - replaceRange : operation ( null , function ( code , from , to ) { <nl> - var doc = this . view . doc ; <nl> - from = clipPos ( doc , from ) ; <nl> - to = to ? clipPos ( doc , to ) : from ; <nl> - return replaceRange ( this , code , from , to ) ; <nl> - } ) , <nl> - <nl> - getRange : function ( from , to , lineSep ) { <nl> - var doc = this . view . doc ; <nl> - from = clipPos ( doc , from ) ; to = clipPos ( doc , to ) ; <nl> - var l1 = from . line , l2 = to . line ; <nl> - if ( l1 = = l2 ) return getLine ( doc , l1 ) . text . slice ( from . ch , to . ch ) ; <nl> - var code = [ getLine ( doc , l1 ) . text . slice ( from . ch ) ] ; <nl> - doc . iter ( l1 + 1 , l2 , function ( line ) { code . push ( line . text ) ; } ) ; <nl> - code . push ( getLine ( doc , l2 ) . text . slice ( 0 , to . ch ) ) ; <nl> - return code . join ( lineSep | | " \ n " ) ; <nl> + findPosV : function ( from , amount , unit , goalColumn ) { <nl> + var dir = 1 , x = goalColumn ; <nl> + if ( amount < 0 ) { dir = - 1 ; amount = - amount ; } <nl> + for ( var i = 0 , cur = clipPos ( this . doc , from ) ; i < amount ; + + i ) { <nl> + var coords = cursorCoords ( this , cur , " div " ) ; <nl> + if ( x = = null ) x = coords . left ; <nl> + else coords . left = x ; <nl> + cur = findPosV ( this , coords , dir , unit ) ; <nl> + if ( cur . hitSide ) break ; <nl> + } <nl> + return cur ; <nl> } , <nl> <nl> - triggerOnKeyDown : operation ( null , onKeyDown ) , <nl> - <nl> - execCommand : function ( cmd ) { return commands [ cmd ] ( this ) ; } , <nl> - <nl> - / / Stuff used by commands , probably not much use to outside code . <nl> - moveH : operation ( null , function ( dir , unit ) { <nl> - var sel = this . view . sel , pos = dir < 0 ? sel . from : sel . to ; <nl> - if ( sel . shift | | sel . extend | | posEq ( sel . from , sel . to ) ) <nl> - pos = findPosH ( this , dir , unit , this . options . rtlMoveVisually ) ; <nl> - extendSelection ( this , pos , pos , dir ) ; <nl> - } ) , <nl> - <nl> - deleteH : operation ( null , function ( dir , unit ) { <nl> - var sel = this . view . sel ; <nl> - if ( ! posEq ( sel . from , sel . to ) ) replaceRange ( this , " " , sel . from , sel . to , " delete " ) ; <nl> - else replaceRange ( this , " " , sel . from , findPosH ( this , dir , unit , false ) , " delete " ) ; <nl> - this . curOp . userSelChange = true ; <nl> - } ) , <nl> - <nl> moveV : operation ( null , function ( dir , unit ) { <nl> - var view = this . view , doc = view . doc , display = this . display ; <nl> - var cur = view . sel . head , pos = cursorCoords ( this , cur , " div " ) ; <nl> - var x = pos . left , y ; <nl> - if ( view . goalColumn ! = null ) x = view . goalColumn ; <nl> - if ( unit = = " page " ) { <nl> - var pageSize = Math . min ( display . wrapper . clientHeight , window . innerHeight | | document . documentElement . clientHeight ) ; <nl> - y = pos . top + dir * pageSize ; <nl> - } else if ( unit = = " line " ) { <nl> - y = dir > 0 ? pos . bottom + 3 : pos . top - 3 ; <nl> - } <nl> - do { <nl> - var target = coordsChar ( this , x , y ) ; <nl> - y + = dir * 5 ; <nl> - } while ( target . outside & & ( dir < 0 ? y > 0 : y < doc . height ) ) ; <nl> - <nl> - if ( unit = = " page " ) display . scrollbarV . scrollTop + = charCoords ( this , target , " div " ) . top - pos . top ; <nl> - extendSelection ( this , target , target , dir ) ; <nl> - view . goalColumn = x ; <nl> + var sel = this . doc . sel ; <nl> + var pos = cursorCoords ( this , sel . head , " div " ) ; <nl> + if ( sel . goalColumn ! = null ) pos . left = sel . goalColumn ; <nl> + var target = findPosV ( this , pos , dir , unit ) ; <nl> + <nl> + if ( unit = = " page " ) addToScrollPos ( this , 0 , charCoords ( this , target , " div " ) . top - pos . top ) ; <nl> + extendSelection ( this . doc , target , target , dir ) ; <nl> + sel . goalColumn = pos . left ; <nl> } ) , <nl> <nl> toggleOverwrite : function ( ) { <nl> - if ( this . view . overwrite = ! this . view . overwrite ) <nl> + if ( this . state . overwrite = ! this . state . overwrite ) <nl> this . display . cursor . className + = " CodeMirror - overwrite " ; <nl> else <nl> this . display . cursor . className = this . display . cursor . className . replace ( " CodeMirror - overwrite " , " " ) ; <nl> } , <nl> + hasFocus : function ( ) { return this . state . focused ; } , <nl> <nl> - posFromIndex : function ( off ) { <nl> - var lineNo = 0 , ch , doc = this . view . doc ; <nl> - doc . iter ( 0 , doc . size , function ( line ) { <nl> - var sz = line . text . length + 1 ; <nl> - if ( sz > off ) { ch = off ; return true ; } <nl> - off - = sz ; <nl> - + + lineNo ; <nl> - } ) ; <nl> - return clipPos ( doc , { line : lineNo , ch : ch } ) ; <nl> - } , <nl> - indexFromPos : function ( coords ) { <nl> - coords = clipPos ( this . view . doc , coords ) ; <nl> - var index = coords . ch ; <nl> - this . view . doc . iter ( 0 , coords . line , function ( line ) { <nl> - index + = line . text . length + 1 ; <nl> - } ) ; <nl> - return index ; <nl> - } , <nl> - <nl> - scrollTo : function ( x , y ) { <nl> - if ( x ! = null ) this . display . scrollbarH . scrollLeft = this . display . scroller . scrollLeft = x ; <nl> - if ( y ! = null ) this . display . scrollbarV . scrollTop = this . display . scroller . scrollTop = y ; <nl> - updateDisplay ( this , [ ] ) ; <nl> - } , <nl> + scrollTo : operation ( null , function ( x , y ) { <nl> + updateScrollPos ( this , x , y ) ; <nl> + } ) , <nl> getScrollInfo : function ( ) { <nl> var scroller = this . display . scroller , co = scrollerCutOff ; <nl> return { left : scroller . scrollLeft , top : scroller . scrollTop , <nl> window . CodeMirror = ( function ( ) { <nl> clientHeight : scroller . clientHeight - co , clientWidth : scroller . clientWidth - co } ; <nl> } , <nl> <nl> - scrollIntoView : function ( pos ) { <nl> - if ( typeof pos = = " number " ) pos = { line : pos , ch : 0 } ; <nl> + scrollIntoView : function ( pos , margin ) { <nl> + if ( typeof pos = = " number " ) pos = Pos ( pos , 0 ) ; <nl> if ( ! pos | | pos . line ! = null ) { <nl> - pos = pos ? clipPos ( this . view . doc , pos ) : this . view . sel . head ; <nl> - scrollPosIntoView ( this , pos ) ; <nl> + pos = pos ? clipPos ( this . doc , pos ) : this . doc . sel . head ; <nl> + scrollPosIntoView ( this , pos , margin ) ; <nl> } else { <nl> - scrollIntoView ( this , pos . left , pos . top , pos . right , pos . bottom ) ; <nl> + scrollIntoView ( this , pos . left , pos . top - margin , pos . right , pos . bottom + margin ) ; <nl> } <nl> } , <nl> <nl> window . CodeMirror = ( function ( ) { <nl> on : function ( type , f ) { on ( this , type , f ) ; } , <nl> off : function ( type , f ) { off ( this , type , f ) ; } , <nl> <nl> - operation : function ( f ) { return operation ( this , f ) ( ) ; } , <nl> + operation : function ( f ) { return runInOp ( this , f ) ; } , <nl> <nl> - refresh : function ( ) { <nl> + refresh : operation ( null , function ( ) { <nl> clearCaches ( this ) ; <nl> - var sTop = this . view . scrollTop , sLeft = this . view . scrollLeft ; <nl> - if ( this . display . scroller . scrollHeight > sTop ) <nl> - this . display . scrollbarV . scrollTop = this . display . scroller . scrollTop = sTop ; <nl> - if ( this . display . scroller . scrollWidth > sLeft ) <nl> - this . display . scrollbarH . scrollLeft = this . display . scroller . scrollLeft = sLeft ; <nl> - updateDisplay ( this , true ) ; <nl> - } , <nl> + updateScrollPos ( this , this . doc . scrollLeft , this . doc . scrollTop ) ; <nl> + regChange ( this ) ; <nl> + } ) , <nl> + <nl> + swapDoc : operation ( null , function ( doc ) { <nl> + var old = this . doc ; <nl> + old . cm = null ; <nl> + attachDoc ( this , doc ) ; <nl> + clearCaches ( this ) ; <nl> + updateScrollPos ( this , doc . scrollLeft , doc . scrollTop ) ; <nl> + return old ; <nl> + } ) , <nl> <nl> getInputField : function ( ) { return this . display . input ; } , <nl> getWrapperElement : function ( ) { return this . display . wrapper ; } , <nl> window . CodeMirror = ( function ( ) { <nl> <nl> / / These two are , on init , called from the constructor because they <nl> / / have to be initialized before the editor can start at all . <nl> - option ( " value " , " " , function ( cm , val ) { cm . setValue ( val ) ; } , true ) ; <nl> - option ( " mode " , null , loadMode , true ) ; <nl> + option ( " value " , " " , function ( cm , val ) { <nl> + cm . setValue ( val ) ; <nl> + } , true ) ; <nl> + option ( " mode " , null , function ( cm , val ) { <nl> + cm . doc . modeOption = val ; <nl> + loadMode ( cm ) ; <nl> + } , true ) ; <nl> <nl> option ( " indentUnit " , 2 , loadMode , true ) ; <nl> option ( " indentWithTabs " , false ) ; <nl> window . CodeMirror = ( function ( ) { <nl> option ( " tabSize " , 4 , function ( cm ) { <nl> loadMode ( cm ) ; <nl> clearCaches ( cm ) ; <nl> - updateDisplay ( cm , true ) ; <nl> + regChange ( cm ) ; <nl> } , true ) ; <nl> option ( " electricChars " , true ) ; <nl> option ( " rtlMoveVisually " , ! windows ) ; <nl> window . CodeMirror = ( function ( ) { <nl> option ( " firstLineNumber " , 1 , guttersChanged , true ) ; <nl> option ( " lineNumberFormatter " , function ( integer ) { return integer ; } , guttersChanged , true ) ; <nl> option ( " showCursorWhenSelecting " , false , updateSelection , true ) ; <nl> - <nl> + <nl> option ( " readOnly " , false , function ( cm , val ) { <nl> if ( val = = " nocursor " ) { onBlur ( cm ) ; cm . display . input . blur ( ) ; } <nl> else if ( ! val ) resetInput ( cm , true ) ; <nl> window . CodeMirror = ( function ( ) { <nl> option ( " workDelay " , 100 ) ; <nl> option ( " flattenSpans " , true ) ; <nl> option ( " pollInterval " , 100 ) ; <nl> - option ( " undoDepth " , 40 ) ; <nl> + option ( " undoDepth " , 40 , function ( cm , val ) { cm . doc . history . undoDepth = val ; } ) ; <nl> option ( " viewportMargin " , 10 , function ( cm ) { cm . refresh ( ) ; } , true ) ; <nl> <nl> option ( " tabindex " , null , function ( cm , val ) { <nl> window . CodeMirror = ( function ( ) { <nl> var modeExtensions = CodeMirror . modeExtensions = { } ; <nl> CodeMirror . extendMode = function ( mode , properties ) { <nl> var exts = modeExtensions . hasOwnProperty ( mode ) ? modeExtensions [ mode ] : ( modeExtensions [ mode ] = { } ) ; <nl> - for ( var prop in properties ) if ( properties . hasOwnProperty ( prop ) ) <nl> - exts [ prop ] = properties [ prop ] ; <nl> + copyObj ( properties , exts ) ; <nl> } ; <nl> <nl> / / EXTENSIONS <nl> window . CodeMirror = ( function ( ) { <nl> / / STANDARD COMMANDS <nl> <nl> var commands = CodeMirror . commands = { <nl> - selectAll : function ( cm ) { cm . setSelection ( { line : 0 , ch : 0 } , { line : cm . lineCount ( ) - 1 } ) ; } , <nl> + selectAll : function ( cm ) { cm . setSelection ( Pos ( cm . firstLine ( ) , 0 ) , Pos ( cm . lastLine ( ) ) ) ; } , <nl> killLine : function ( cm ) { <nl> var from = cm . getCursor ( true ) , to = cm . getCursor ( false ) , sel = ! posEq ( from , to ) ; <nl> if ( ! sel & & cm . getLine ( from . line ) . length = = from . ch ) <nl> - cm . replaceRange ( " " , from , { line : from . line + 1 , ch : 0 } , " delete " ) ; <nl> - else cm . replaceRange ( " " , from , sel ? to : { line : from . line } , " delete " ) ; <nl> + cm . replaceRange ( " " , from , Pos ( from . line + 1 , 0 ) , " + delete " ) ; <nl> + else cm . replaceRange ( " " , from , sel ? to : Pos ( from . line ) , " + delete " ) ; <nl> } , <nl> deleteLine : function ( cm ) { <nl> var l = cm . getCursor ( ) . line ; <nl> - cm . replaceRange ( " " , { line : l , ch : 0 } , { line : l } , " delete " ) ; <nl> + cm . replaceRange ( " " , Pos ( l , 0 ) , Pos ( l ) , " + delete " ) ; <nl> } , <nl> undo : function ( cm ) { cm . undo ( ) ; } , <nl> redo : function ( cm ) { cm . redo ( ) ; } , <nl> - goDocStart : function ( cm ) { cm . extendSelection ( { line : 0 , ch : 0 } ) ; } , <nl> - goDocEnd : function ( cm ) { cm . extendSelection ( { line : cm . lineCount ( ) - 1 } ) ; } , <nl> + goDocStart : function ( cm ) { cm . extendSelection ( Pos ( cm . firstLine ( ) , 0 ) ) ; } , <nl> + goDocEnd : function ( cm ) { cm . extendSelection ( Pos ( cm . lastLine ( ) ) ) ; } , <nl> goLineStart : function ( cm ) { <nl> cm . extendSelection ( lineStart ( cm , cm . getCursor ( ) . line ) ) ; <nl> } , <nl> window . CodeMirror = ( function ( ) { <nl> if ( ! order | | order [ 0 ] . level = = 0 ) { <nl> var firstNonWS = Math . max ( 0 , line . text . search ( / \ S / ) ) ; <nl> var inWS = cur . line = = start . line & & cur . ch < = firstNonWS & & cur . ch ; <nl> - cm . extendSelection ( { line : start . line , ch : inWS ? 0 : firstNonWS } ) ; <nl> + cm . extendSelection ( Pos ( start . line , inWS ? 0 : firstNonWS ) ) ; <nl> } else cm . extendSelection ( start ) ; <nl> } , <nl> goLineEnd : function ( cm ) { <nl> cm . extendSelection ( lineEnd ( cm , cm . getCursor ( ) . line ) ) ; <nl> } , <nl> + goLineRight : function ( cm ) { <nl> + var top = cm . charCoords ( cm . getCursor ( ) , " div " ) . top + 5 ; <nl> + cm . extendSelection ( cm . coordsChar ( { left : cm . display . lineDiv . offsetWidth + 100 , top : top } , " div " ) ) ; <nl> + } , <nl> + goLineLeft : function ( cm ) { <nl> + var top = cm . charCoords ( cm . getCursor ( ) , " div " ) . top + 5 ; <nl> + cm . extendSelection ( cm . coordsChar ( { left : 0 , top : top } , " div " ) ) ; <nl> + } , <nl> goLineUp : function ( cm ) { cm . moveV ( - 1 , " line " ) ; } , <nl> goLineDown : function ( cm ) { cm . moveV ( 1 , " line " ) ; } , <nl> goPageUp : function ( cm ) { cm . moveV ( - 1 , " page " ) ; } , <nl> window . CodeMirror = ( function ( ) { <nl> goColumnLeft : function ( cm ) { cm . moveH ( - 1 , " column " ) ; } , <nl> goColumnRight : function ( cm ) { cm . moveH ( 1 , " column " ) ; } , <nl> goWordLeft : function ( cm ) { cm . moveH ( - 1 , " word " ) ; } , <nl> + goGroupRight : function ( cm ) { cm . moveH ( 1 , " group " ) ; } , <nl> + goGroupLeft : function ( cm ) { cm . moveH ( - 1 , " group " ) ; } , <nl> goWordRight : function ( cm ) { cm . moveH ( 1 , " word " ) ; } , <nl> delCharBefore : function ( cm ) { cm . deleteH ( - 1 , " char " ) ; } , <nl> delCharAfter : function ( cm ) { cm . deleteH ( 1 , " char " ) ; } , <nl> delWordBefore : function ( cm ) { cm . deleteH ( - 1 , " word " ) ; } , <nl> delWordAfter : function ( cm ) { cm . deleteH ( 1 , " word " ) ; } , <nl> + delGroupBefore : function ( cm ) { cm . deleteH ( - 1 , " group " ) ; } , <nl> + delGroupAfter : function ( cm ) { cm . deleteH ( 1 , " group " ) ; } , <nl> indentAuto : function ( cm ) { cm . indentSelection ( " smart " ) ; } , <nl> indentMore : function ( cm ) { cm . indentSelection ( " add " ) ; } , <nl> indentLess : function ( cm ) { cm . indentSelection ( " subtract " ) ; } , <nl> - insertTab : function ( cm ) { cm . replaceSelection ( " \ t " , " end " , " input " ) ; } , <nl> + insertTab : function ( cm ) { cm . replaceSelection ( " \ t " , " end " , " + input " ) ; } , <nl> defaultTab : function ( cm ) { <nl> if ( cm . somethingSelected ( ) ) cm . indentSelection ( " add " ) ; <nl> - else cm . replaceSelection ( " \ t " , " end " , " input " ) ; <nl> + else cm . replaceSelection ( " \ t " , " end " , " + input " ) ; <nl> } , <nl> transposeChars : function ( cm ) { <nl> var cur = cm . getCursor ( ) , line = cm . getLine ( cur . line ) ; <nl> if ( cur . ch > 0 & & cur . ch < line . length - 1 ) <nl> cm . replaceRange ( line . charAt ( cur . ch ) + line . charAt ( cur . ch - 1 ) , <nl> - { line : cur . line , ch : cur . ch - 1 } , { line : cur . line , ch : cur . ch + 1 } ) ; <nl> + Pos ( cur . line , cur . ch - 1 ) , Pos ( cur . line , cur . ch + 1 ) ) ; <nl> } , <nl> newlineAndIndent : function ( cm ) { <nl> operation ( cm , function ( ) { <nl> - cm . replaceSelection ( " \ n " , " end " , " input " ) ; <nl> + cm . replaceSelection ( " \ n " , " end " , " + input " ) ; <nl> cm . indentLine ( cm . getCursor ( ) . line , null , true ) ; <nl> } ) ( ) ; <nl> } , <nl> window . CodeMirror = ( function ( ) { <nl> keyMap . pcDefault = { <nl> " Ctrl - A " : " selectAll " , " Ctrl - D " : " deleteLine " , " Ctrl - Z " : " undo " , " Shift - Ctrl - Z " : " redo " , " Ctrl - Y " : " redo " , <nl> " Ctrl - Home " : " goDocStart " , " Alt - Up " : " goDocStart " , " Ctrl - End " : " goDocEnd " , " Ctrl - Down " : " goDocEnd " , <nl> - " Ctrl - Left " : " goWordLeft " , " Ctrl - Right " : " goWordRight " , " Alt - Left " : " goLineStart " , " Alt - Right " : " goLineEnd " , <nl> - " Ctrl - Backspace " : " delWordBefore " , " Ctrl - Delete " : " delWordAfter " , " Ctrl - S " : " save " , " Ctrl - F " : " find " , <nl> + " Ctrl - Left " : " goGroupLeft " , " Ctrl - Right " : " goGroupRight " , " Alt - Left " : " goLineStart " , " Alt - Right " : " goLineEnd " , <nl> + " Ctrl - Backspace " : " delGroupBefore " , " Ctrl - Delete " : " delGroupAfter " , " Ctrl - S " : " save " , " Ctrl - F " : " find " , <nl> " Ctrl - G " : " findNext " , " Shift - Ctrl - G " : " findPrev " , " Shift - Ctrl - F " : " replace " , " Shift - Ctrl - R " : " replaceAll " , <nl> " Ctrl - [ " : " indentLess " , " Ctrl - ] " : " indentMore " , <nl> fallthrough : " basic " <nl> } ; <nl> keyMap . macDefault = { <nl> " Cmd - A " : " selectAll " , " Cmd - D " : " deleteLine " , " Cmd - Z " : " undo " , " Shift - Cmd - Z " : " redo " , " Cmd - Y " : " redo " , <nl> - " Cmd - Up " : " goDocStart " , " Cmd - End " : " goDocEnd " , " Cmd - Down " : " goDocEnd " , " Alt - Left " : " goWordLeft " , <nl> - " Alt - Right " : " goWordRight " , " Cmd - Left " : " goLineStart " , " Cmd - Right " : " goLineEnd " , " Alt - Backspace " : " delWordBefore " , <nl> - " Ctrl - Alt - Backspace " : " delWordAfter " , " Alt - Delete " : " delWordAfter " , " Cmd - S " : " save " , " Cmd - F " : " find " , <nl> + " Cmd - Up " : " goDocStart " , " Cmd - End " : " goDocEnd " , " Cmd - Down " : " goDocEnd " , " Alt - Left " : " goGroupLeft " , <nl> + " Alt - Right " : " goGroupRight " , " Cmd - Left " : " goLineStart " , " Cmd - Right " : " goLineEnd " , " Alt - Backspace " : " delGroupBefore " , <nl> + " Ctrl - Alt - Backspace " : " delGroupAfter " , " Alt - Delete " : " delGroupAfter " , " Cmd - S " : " save " , " Cmd - F " : " find " , <nl> " Cmd - G " : " findNext " , " Shift - Cmd - G " : " findPrev " , " Cmd - Alt - F " : " replace " , " Shift - Cmd - Alt - F " : " replaceAll " , <nl> " Cmd - [ " : " indentLess " , " Cmd - ] " : " indentMore " , <nl> fallthrough : [ " basic " , " emacsy " ] <nl> window . CodeMirror = ( function ( ) { <nl> else return val ; <nl> } <nl> <nl> - function lookupKey ( name , maps , handle , stop ) { <nl> + function lookupKey ( name , maps , handle ) { <nl> function lookup ( map ) { <nl> map = getKeyMap ( map ) ; <nl> var found = map [ name ] ; <nl> - if ( found = = = false ) { <nl> - if ( stop ) stop ( ) ; <nl> - return true ; <nl> - } <nl> + if ( found = = = false ) return " stop " ; <nl> if ( found ! = null & & handle ( found ) ) return true ; <nl> - if ( map . nofallthrough ) { <nl> - if ( stop ) stop ( ) ; <nl> - return true ; <nl> - } <nl> + if ( map . nofallthrough ) return " stop " ; <nl> + <nl> var fallthrough = map . fallthrough ; <nl> if ( fallthrough = = null ) return false ; <nl> if ( Object . prototype . toString . call ( fallthrough ) ! = " [ object Array ] " ) <nl> return lookup ( fallthrough ) ; <nl> for ( var i = 0 , e = fallthrough . length ; i < e ; + + i ) { <nl> - if ( lookup ( fallthrough [ i ] ) ) return true ; <nl> + var done = lookup ( fallthrough [ i ] ) ; <nl> + if ( done ) return done ; <nl> } <nl> return false ; <nl> } <nl> <nl> - for ( var i = 0 ; i < maps . length ; + + i ) <nl> - if ( lookup ( maps [ i ] ) ) return true ; <nl> + for ( var i = 0 ; i < maps . length ; + + i ) { <nl> + var done = lookup ( maps [ i ] ) ; <nl> + if ( done ) return done ; <nl> + } <nl> } <nl> function isModifierKey ( event ) { <nl> - var name = keyNames [ e_prop ( event , " keyCode " ) ] ; <nl> + var name = keyNames [ event . keyCode ] ; <nl> return name = = " Ctrl " | | name = = " Alt " | | name = = " Shift " | | name = = " Mod " ; <nl> } <nl> + function keyName ( event , noShift ) { <nl> + var name = keyNames [ event . keyCode ] ; <nl> + if ( name = = null | | event . altGraphKey ) return false ; <nl> + if ( event . altKey ) name = " Alt - " + name ; <nl> + if ( flipCtrlCmd ? event . metaKey : event . ctrlKey ) name = " Ctrl - " + name ; <nl> + if ( flipCtrlCmd ? event . ctrlKey : event . metaKey ) name = " Cmd - " + name ; <nl> + if ( ! noShift & & event . shiftKey ) name = " Shift - " + name ; <nl> + return name ; <nl> + } <nl> + CodeMirror . lookupKey = lookupKey ; <nl> CodeMirror . isModifierKey = isModifierKey ; <nl> + CodeMirror . keyName = keyName ; <nl> <nl> / / FROMTEXTAREA <nl> <nl> window . CodeMirror = ( function ( ) { <nl> options . value = textarea . value ; <nl> if ( ! options . tabindex & & textarea . tabindex ) <nl> options . tabindex = textarea . tabindex ; <nl> + if ( ! options . placeholder & & textarea . placeholder ) <nl> + options . placeholder = textarea . placeholder ; <nl> / / Set autofocus to true if this textarea is focused , or if it has <nl> / / autofocus and no other element is focused . <nl> if ( options . autofocus = = null ) { <nl> window . CodeMirror = ( function ( ) { <nl> <nl> function save ( ) { textarea . value = cm . getValue ( ) ; } <nl> if ( textarea . form ) { <nl> - / / Deplorable hack to make the submit method do the right thing . <nl> on ( textarea . form , " submit " , save ) ; <nl> - var form = textarea . form , realSubmit = form . submit ; <nl> - try { <nl> - form . submit = function wrappedSubmit ( ) { <nl> - save ( ) ; <nl> - form . submit = realSubmit ; <nl> - form . submit ( ) ; <nl> - form . submit = wrappedSubmit ; <nl> - } ; <nl> - } catch ( e ) { } <nl> + / / Deplorable hack to make the submit method do the right thing . <nl> + if ( ! options . leaveSubmitMethodAlone ) { <nl> + var form = textarea . form , realSubmit = form . submit ; <nl> + try { <nl> + var wrappedSubmit = form . submit = function ( ) { <nl> + save ( ) ; <nl> + form . submit = realSubmit ; <nl> + form . submit ( ) ; <nl> + form . submit = wrappedSubmit ; <nl> + } ; <nl> + } catch ( e ) { } <nl> + } <nl> } <nl> <nl> textarea . style . display = " none " ; <nl> window . CodeMirror = ( function ( ) { <nl> this . pos = this . start = 0 ; <nl> this . string = string ; <nl> this . tabSize = tabSize | | 8 ; <nl> + this . lastColumnPos = this . lastColumnValue = 0 ; <nl> } <nl> <nl> StringStream . prototype = { <nl> window . CodeMirror = ( function ( ) { <nl> if ( found > - 1 ) { this . pos = found ; return true ; } <nl> } , <nl> backUp : function ( n ) { this . pos - = n ; } , <nl> - column : function ( ) { return countColumn ( this . string , this . start , this . tabSize ) ; } , <nl> + column : function ( ) { <nl> + if ( this . lastColumnPos < this . start ) { <nl> + this . lastColumnValue = countColumn ( this . string , this . start , this . tabSize , this . lastColumnPos , this . lastColumnValue ) ; <nl> + this . lastColumnPos = this . start ; <nl> + } <nl> + return this . lastColumnValue ; <nl> + } , <nl> indentation : function ( ) { return countColumn ( this . string , null , this . tabSize ) ; } , <nl> match : function ( pattern , consume , caseInsensitive ) { <nl> if ( typeof pattern = = " string " ) { <nl> var cased = function ( str ) { return caseInsensitive ? str . toLowerCase ( ) : str ; } ; <nl> - if ( cased ( this . string ) . indexOf ( cased ( pattern ) , this . pos ) = = this . pos ) { <nl> + var substr = this . string . substr ( this . pos , pattern . length ) ; <nl> + if ( cased ( substr ) = = cased ( pattern ) ) { <nl> if ( consume ! = = false ) this . pos + = pattern . length ; <nl> return true ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> <nl> / / TEXTMARKERS <nl> <nl> - function TextMarker ( cm , type ) { <nl> + function TextMarker ( doc , type ) { <nl> this . lines = [ ] ; <nl> this . type = type ; <nl> - this . cm = cm ; <nl> + this . doc = doc ; <nl> } <nl> CodeMirror . TextMarker = TextMarker ; <nl> <nl> TextMarker . prototype . clear = function ( ) { <nl> if ( this . explicitlyCleared ) return ; <nl> - startOperation ( this . cm ) ; <nl> - var view = this . cm . view , min = null , max = null ; <nl> + var cm = this . doc . cm , withOp = cm & & ! cm . curOp ; <nl> + if ( withOp ) startOperation ( cm ) ; <nl> + var min = null , max = null ; <nl> for ( var i = 0 ; i < this . lines . length ; + + i ) { <nl> var line = this . lines [ i ] ; <nl> var span = getMarkedSpanFor ( line . markedSpans , this ) ; <nl> window . CodeMirror = ( function ( ) { <nl> line . markedSpans = removeMarkedSpan ( line . markedSpans , span ) ; <nl> if ( span . from ! = null ) <nl> min = lineNo ( line ) ; <nl> - else if ( this . collapsed & & ! lineIsHidden ( line ) ) <nl> - updateLineHeight ( line , textHeight ( this . cm . display ) ) ; <nl> - } <nl> - if ( this . collapsed & & ! this . cm . options . lineWrapping ) for ( var i = 0 ; i < this . lines . length ; + + i ) { <nl> - var visual = visualLine ( view . doc , this . lines [ i ] ) , len = lineLength ( view . doc , visual ) ; <nl> - if ( len > view . maxLineLength ) { <nl> - view . maxLine = visual ; <nl> - view . maxLineLength = len ; <nl> - view . maxLineChanged = true ; <nl> + else if ( this . collapsed & & ! lineIsHidden ( this . doc , line ) & & cm ) <nl> + updateLineHeight ( line , textHeight ( cm . display ) ) ; <nl> + } <nl> + if ( cm & & this . collapsed & & ! cm . options . lineWrapping ) for ( var i = 0 ; i < this . lines . length ; + + i ) { <nl> + var visual = visualLine ( cm . doc , this . lines [ i ] ) , len = lineLength ( cm . doc , visual ) ; <nl> + if ( len > cm . display . maxLineLength ) { <nl> + cm . display . maxLine = visual ; <nl> + cm . display . maxLineLength = len ; <nl> + cm . display . maxLineChanged = true ; <nl> } <nl> } <nl> <nl> - if ( min ! = null ) regChange ( this . cm , min , max + 1 ) ; <nl> + if ( min ! = null & & cm ) regChange ( cm , min , max + 1 ) ; <nl> this . lines . length = 0 ; <nl> this . explicitlyCleared = true ; <nl> - if ( this . collapsed & & this . cm . view . cantEdit ) { <nl> - this . cm . view . cantEdit = false ; <nl> - reCheckSelection ( this . cm ) ; <nl> + if ( this . collapsed & & this . doc . cantEdit ) { <nl> + this . doc . cantEdit = false ; <nl> + if ( cm ) reCheckSelection ( cm ) ; <nl> } <nl> - endOperation ( this . cm ) ; <nl> - signalLater ( this . cm , this , " clear " ) ; <nl> + if ( withOp ) endOperation ( cm ) ; <nl> + signalLater ( this , " clear " ) ; <nl> } ; <nl> <nl> TextMarker . prototype . find = function ( ) { <nl> window . CodeMirror = ( function ( ) { <nl> var span = getMarkedSpanFor ( line . markedSpans , this ) ; <nl> if ( span . from ! = null | | span . to ! = null ) { <nl> var found = lineNo ( line ) ; <nl> - if ( span . from ! = null ) from = { line : found , ch : span . from } ; <nl> - if ( span . to ! = null ) to = { line : found , ch : span . to } ; <nl> + if ( span . from ! = null ) from = Pos ( found , span . from ) ; <nl> + if ( span . to ! = null ) to = Pos ( found , span . to ) ; <nl> } <nl> } <nl> if ( this . type = = " bookmark " ) return from ; <nl> window . CodeMirror = ( function ( ) { <nl> inclusiveLeft : this . inclusiveLeft , inclusiveRight : this . inclusiveRight , <nl> atomic : this . atomic , <nl> collapsed : this . collapsed , <nl> - clearOnEnter : this . clearOnEnter , <nl> replacedWith : copyWidget ? repl & & repl . cloneNode ( true ) : repl , <nl> readOnly : this . readOnly , <nl> startStyle : this . startStyle , endStyle : this . endStyle } ; <nl> } ; <nl> <nl> - function markText ( cm , from , to , options , type ) { <nl> - var doc = cm . view . doc ; <nl> - var marker = new TextMarker ( cm , type ) ; <nl> + TextMarker . prototype . attachLine = function ( line ) { <nl> + if ( ! this . lines . length & & this . doc . cm ) { <nl> + var op = this . doc . cm . curOp ; <nl> + if ( ! op . maybeHiddenMarkers | | indexOf ( op . maybeHiddenMarkers , this ) = = - 1 ) <nl> + ( op . maybeUnhiddenMarkers | | ( op . maybeUnhiddenMarkers = [ ] ) ) . push ( this ) ; <nl> + } <nl> + this . lines . push ( line ) ; <nl> + } ; <nl> + TextMarker . prototype . detachLine = function ( line ) { <nl> + this . lines . splice ( indexOf ( this . lines , line ) , 1 ) ; <nl> + if ( ! this . lines . length & & this . doc . cm ) { <nl> + var op = this . doc . cm . curOp ; <nl> + ( op . maybeHiddenMarkers | | ( op . maybeHiddenMarkers = [ ] ) ) . push ( this ) ; <nl> + } <nl> + } ; <nl> + <nl> + function markText ( doc , from , to , options , type ) { <nl> + if ( options & & options . shared ) return markTextShared ( doc , from , to , options , type ) ; <nl> + if ( doc . cm & & ! doc . cm . curOp ) return operation ( doc . cm , markText ) ( doc , from , to , options , type ) ; <nl> + <nl> + var marker = new TextMarker ( doc , type ) ; <nl> if ( type = = " range " & & ! posLess ( from , to ) ) return marker ; <nl> - if ( options ) for ( var opt in options ) if ( options . hasOwnProperty ( opt ) ) <nl> - marker [ opt ] = options [ opt ] ; <nl> + if ( options ) copyObj ( options , marker ) ; <nl> if ( marker . replacedWith ) { <nl> marker . collapsed = true ; <nl> marker . replacedWith = elt ( " span " , [ marker . replacedWith ] , " CodeMirror - widget " ) ; <nl> } <nl> if ( marker . collapsed ) sawCollapsedSpans = true ; <nl> <nl> - var curLine = from . line , size = 0 , collapsedAtStart , collapsedAtEnd ; <nl> + var curLine = from . line , size = 0 , collapsedAtStart , collapsedAtEnd , cm = doc . cm , updateMaxLine ; <nl> doc . iter ( curLine , to . line + 1 , function ( line ) { <nl> - if ( marker . collapsed & & ! cm . options . lineWrapping & & visualLine ( doc , line ) = = cm . view . maxLine ) <nl> - cm . curOp . updateMaxLine = true ; <nl> + if ( cm & & marker . collapsed & & ! cm . options . lineWrapping & & visualLine ( doc , line ) = = cm . display . maxLine ) <nl> + updateMaxLine = true ; <nl> var span = { from : null , to : null , marker : marker } ; <nl> size + = line . text . length ; <nl> if ( curLine = = from . line ) { span . from = from . ch ; size - = from . ch ; } <nl> window . CodeMirror = ( function ( ) { <nl> + + curLine ; <nl> } ) ; <nl> if ( marker . collapsed ) doc . iter ( from . line , to . line + 1 , function ( line ) { <nl> - if ( lineIsHidden ( line ) ) updateLineHeight ( line , 0 ) ; <nl> + if ( lineIsHidden ( doc , line ) ) updateLineHeight ( line , 0 ) ; <nl> } ) ; <nl> <nl> + if ( marker . clearOnEnter ) on ( marker , " beforeCursorEnter " , function ( ) { marker . clear ( ) ; } ) ; <nl> + <nl> if ( marker . readOnly ) { <nl> sawReadOnlySpans = true ; <nl> - if ( cm . view . history . done . length | | cm . view . history . undone . length ) <nl> - cm . clearHistory ( ) ; <nl> + if ( doc . history . done . length | | doc . history . undone . length ) <nl> + doc . clearHistory ( ) ; <nl> } <nl> if ( marker . collapsed ) { <nl> if ( collapsedAtStart ! = collapsedAtEnd ) <nl> window . CodeMirror = ( function ( ) { <nl> marker . size = size ; <nl> marker . atomic = true ; <nl> } <nl> - if ( marker . className | | marker . startStyle | | marker . endStyle | | marker . collapsed ) <nl> - regChange ( cm , from . line , to . line + 1 ) ; <nl> - if ( marker . atomic ) reCheckSelection ( cm ) ; <nl> + if ( cm ) { <nl> + if ( updateMaxLine ) cm . curOp . updateMaxLine = true ; <nl> + if ( marker . className | | marker . startStyle | | marker . endStyle | | marker . collapsed ) <nl> + regChange ( cm , from . line , to . line + 1 ) ; <nl> + if ( marker . atomic ) reCheckSelection ( cm ) ; <nl> + } <nl> return marker ; <nl> } <nl> <nl> + / / SHARED TEXTMARKERS <nl> + <nl> + function SharedTextMarker ( markers , primary ) { <nl> + this . markers = markers ; <nl> + this . primary = primary ; <nl> + for ( var i = 0 , me = this ; i < markers . length ; + + i ) { <nl> + markers [ i ] . parent = this ; <nl> + on ( markers [ i ] , " clear " , function ( ) { me . clear ( ) ; } ) ; <nl> + } <nl> + } <nl> + CodeMirror . SharedTextMarker = SharedTextMarker ; <nl> + <nl> + SharedTextMarker . prototype . clear = function ( ) { <nl> + if ( this . explicitlyCleared ) return ; <nl> + this . explicitlyCleared = true ; <nl> + for ( var i = 0 ; i < this . markers . length ; + + i ) <nl> + this . markers [ i ] . clear ( ) ; <nl> + signalLater ( this , " clear " ) ; <nl> + } ; <nl> + SharedTextMarker . prototype . find = function ( ) { <nl> + return this . primary . find ( ) ; <nl> + } ; <nl> + SharedTextMarker . prototype . getOptions = function ( copyWidget ) { <nl> + var inner = this . primary . getOptions ( copyWidget ) ; <nl> + inner . shared = true ; <nl> + return inner ; <nl> + } ; <nl> + <nl> + function markTextShared ( doc , from , to , options , type ) { <nl> + options = copyObj ( options ) ; <nl> + options . shared = false ; <nl> + var markers = [ markText ( doc , from , to , options , type ) ] , primary = markers [ 0 ] ; <nl> + var widget = options . replacedWith ; <nl> + linkedDocs ( doc , function ( doc ) { <nl> + if ( widget ) options . replacedWith = widget . cloneNode ( true ) ; <nl> + markers . push ( markText ( doc , clipPos ( doc , from ) , clipPos ( doc , to ) , options , type ) ) ; <nl> + for ( var i = 0 ; i < doc . linked . length ; + + i ) <nl> + if ( doc . linked [ i ] . isParent ) return ; <nl> + primary = lst ( markers ) ; <nl> + } ) ; <nl> + return new SharedTextMarker ( markers , primary ) ; <nl> + } <nl> + <nl> / / TEXTMARKER SPANS <nl> <nl> function getMarkedSpanFor ( spans , marker ) { <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> function addMarkedSpan ( line , span ) { <nl> line . markedSpans = line . markedSpans ? line . markedSpans . concat ( [ span ] ) : [ span ] ; <nl> - span . marker . lines . push ( line ) ; <nl> + span . marker . attachLine ( line ) ; <nl> } <nl> <nl> - function markedSpansBefore ( old , startCh ) { <nl> + function markedSpansBefore ( old , startCh , isInsert ) { <nl> if ( old ) for ( var i = 0 , nw ; i < old . length ; + + i ) { <nl> var span = old [ i ] , marker = span . marker ; <nl> var startsBefore = span . from = = null | | ( marker . inclusiveLeft ? span . from < = startCh : span . from < startCh ) ; <nl> - if ( startsBefore | | marker . type = = " bookmark " & & span . from = = startCh ) { <nl> + if ( startsBefore | | marker . type = = " bookmark " & & span . from = = startCh & & ( ! isInsert | | ! span . marker . insertLeft ) ) { <nl> var endsAfter = span . to = = null | | ( marker . inclusiveRight ? span . to > = startCh : span . to > startCh ) ; <nl> ( nw | | ( nw = [ ] ) ) . push ( { from : span . from , <nl> to : endsAfter ? null : span . to , <nl> window . CodeMirror = ( function ( ) { <nl> return nw ; <nl> } <nl> <nl> - function markedSpansAfter ( old , startCh , endCh ) { <nl> + function markedSpansAfter ( old , endCh , isInsert ) { <nl> if ( old ) for ( var i = 0 , nw ; i < old . length ; + + i ) { <nl> var span = old [ i ] , marker = span . marker ; <nl> var endsAfter = span . to = = null | | ( marker . inclusiveRight ? span . to > = endCh : span . to > endCh ) ; <nl> - if ( endsAfter | | marker . type = = " bookmark " & & span . from = = endCh & & span . from ! = startCh ) { <nl> + if ( endsAfter | | marker . type = = " bookmark " & & span . from = = endCh & & ( ! isInsert | | span . marker . insertLeft ) ) { <nl> var startsBefore = span . from = = null | | ( marker . inclusiveLeft ? span . from < = endCh : span . from < endCh ) ; <nl> ( nw | | ( nw = [ ] ) ) . push ( { from : startsBefore ? null : span . from - endCh , <nl> to : span . to = = null ? null : span . to - endCh , <nl> window . CodeMirror = ( function ( ) { <nl> return nw ; <nl> } <nl> <nl> - function updateMarkedSpans ( oldFirst , oldLast , startCh , endCh , newText ) { <nl> - if ( ! oldFirst & & ! oldLast ) return newText ; <nl> + function stretchSpansOverChange ( doc , change ) { <nl> + var oldFirst = isLine ( doc , change . from . line ) & & getLine ( doc , change . from . line ) . markedSpans ; <nl> + var oldLast = isLine ( doc , change . to . line ) & & getLine ( doc , change . to . line ) . markedSpans ; <nl> + if ( ! oldFirst & & ! oldLast ) return null ; <nl> + <nl> + var startCh = change . from . ch , endCh = change . to . ch , isInsert = posEq ( change . from , change . to ) ; <nl> / / Get the spans that ' stick out ' on both sides <nl> - var first = markedSpansBefore ( oldFirst , startCh ) ; <nl> - var last = markedSpansAfter ( oldLast , startCh , endCh ) ; <nl> + var first = markedSpansBefore ( oldFirst , startCh , isInsert ) ; <nl> + var last = markedSpansAfter ( oldLast , endCh , isInsert ) ; <nl> <nl> / / Next , merge those two ends <nl> - var sameLine = newText . length = = 1 , offset = lst ( newText ) . length + ( sameLine ? startCh : 0 ) ; <nl> + var sameLine = change . text . length = = 1 , offset = lst ( change . text ) . length + ( sameLine ? startCh : 0 ) ; <nl> if ( first ) { <nl> / / Fix up . to properties of first <nl> for ( var i = 0 ; i < first . length ; + + i ) { <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> } <nl> <nl> - var newMarkers = [ newHL ( newText [ 0 ] , first ) ] ; <nl> + var newMarkers = [ first ] ; <nl> if ( ! sameLine ) { <nl> / / Fill gap with whole - line - spans <nl> - var gap = newText . length - 2 , gapMarkers ; <nl> + var gap = change . text . length - 2 , gapMarkers ; <nl> if ( gap > 0 & & first ) <nl> for ( var i = 0 ; i < first . length ; + + i ) <nl> if ( first [ i ] . to = = null ) <nl> ( gapMarkers | | ( gapMarkers = [ ] ) ) . push ( { from : null , to : null , marker : first [ i ] . marker } ) ; <nl> for ( var i = 0 ; i < gap ; + + i ) <nl> - newMarkers . push ( newHL ( newText [ i + 1 ] , gapMarkers ) ) ; <nl> - newMarkers . push ( newHL ( lst ( newText ) , last ) ) ; <nl> + newMarkers . push ( gapMarkers ) ; <nl> + newMarkers . push ( last ) ; <nl> } <nl> return newMarkers ; <nl> } <nl> <nl> + function mergeOldSpans ( doc , change ) { <nl> + var old = getOldSpans ( doc , change ) ; <nl> + var stretched = stretchSpansOverChange ( doc , change ) ; <nl> + if ( ! old ) return stretched ; <nl> + if ( ! stretched ) return old ; <nl> + <nl> + for ( var i = 0 ; i < old . length ; + + i ) { <nl> + var oldCur = old [ i ] , stretchCur = stretched [ i ] ; <nl> + if ( oldCur & & stretchCur ) { <nl> + spans : for ( var j = 0 ; j < stretchCur . length ; + + j ) { <nl> + var span = stretchCur [ j ] ; <nl> + for ( var k = 0 ; k < oldCur . length ; + + k ) <nl> + if ( oldCur [ k ] . marker = = span . marker ) continue spans ; <nl> + oldCur . push ( span ) ; <nl> + } <nl> + } else if ( stretchCur ) { <nl> + old [ i ] = stretchCur ; <nl> + } <nl> + } <nl> + return old ; <nl> + } <nl> + <nl> function removeReadOnlyRanges ( doc , from , to ) { <nl> var markers = null ; <nl> doc . iter ( from . line , to . line + 1 , function ( line ) { <nl> window . CodeMirror = ( function ( ) { <nl> if ( ! markers ) return null ; <nl> var parts = [ { from : from , to : to } ] ; <nl> for ( var i = 0 ; i < markers . length ; + + i ) { <nl> - var m = markers [ i ] . find ( ) ; <nl> + var mk = markers [ i ] , m = mk . find ( ) ; <nl> for ( var j = 0 ; j < parts . length ; + + j ) { <nl> var p = parts [ j ] ; <nl> - if ( ! posLess ( m . from , p . to ) | | posLess ( m . to , p . from ) ) continue ; <nl> + if ( posLess ( p . to , m . from ) | | posLess ( m . to , p . from ) ) continue ; <nl> var newParts = [ j , 1 ] ; <nl> - if ( posLess ( p . from , m . from ) ) newParts . push ( { from : p . from , to : m . from } ) ; <nl> - if ( posLess ( m . to , p . to ) ) newParts . push ( { from : m . to , to : p . to } ) ; <nl> + if ( posLess ( p . from , m . from ) | | ! mk . inclusiveLeft & & posEq ( p . from , m . from ) ) <nl> + newParts . push ( { from : p . from , to : m . from } ) ; <nl> + if ( posLess ( m . to , p . to ) | | ! mk . inclusiveRight & & posEq ( p . to , m . to ) ) <nl> + newParts . push ( { from : m . to , to : p . to } ) ; <nl> parts . splice . apply ( parts , newParts ) ; <nl> j + = newParts . length - 1 ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> return line ; <nl> } <nl> <nl> - function lineIsHidden ( line ) { <nl> + function lineIsHidden ( doc , line ) { <nl> var sps = sawCollapsedSpans & & line . markedSpans ; <nl> if ( sps ) for ( var sp , i = 0 ; i < sps . length ; + + i ) { <nl> sp = sps [ i ] ; <nl> if ( ! sp . marker . collapsed ) continue ; <nl> if ( sp . from = = null ) return true ; <nl> - if ( sp . from = = 0 & & sp . marker . inclusiveLeft & & lineIsHiddenInner ( line , sp ) ) <nl> + if ( sp . from = = 0 & & sp . marker . inclusiveLeft & & lineIsHiddenInner ( doc , line , sp ) ) <nl> return true ; <nl> } <nl> } <nl> - function lineIsHiddenInner ( line , span ) { <nl> + function lineIsHiddenInner ( doc , line , span ) { <nl> if ( span . to = = null ) { <nl> - var end = span . marker . find ( ) . to , endLine = getLine ( lineDoc ( line ) , end . line ) ; <nl> - return lineIsHiddenInner ( endLine , getMarkedSpanFor ( endLine . markedSpans , span . marker ) ) ; <nl> + var end = span . marker . find ( ) . to , endLine = getLine ( doc , end . line ) ; <nl> + return lineIsHiddenInner ( doc , endLine , getMarkedSpanFor ( endLine . markedSpans , span . marker ) ) ; <nl> } <nl> if ( span . marker . inclusiveRight & & span . to = = line . text . length ) <nl> return true ; <nl> window . CodeMirror = ( function ( ) { <nl> sp = line . markedSpans [ i ] ; <nl> if ( sp . marker . collapsed & & sp . from = = span . to & & <nl> ( sp . marker . inclusiveLeft | | span . marker . inclusiveRight ) & & <nl> - lineIsHiddenInner ( line , sp ) ) return true ; <nl> + lineIsHiddenInner ( doc , line , sp ) ) return true ; <nl> } <nl> } <nl> <nl> - / / hl stands for history - line , a data structure that can be either a <nl> - / / string ( line without markers ) or a { text , markedSpans } object . <nl> - function hlText ( val ) { return typeof val = = " string " ? val : val . text ; } <nl> - function hlSpans ( val ) { <nl> - if ( typeof val = = " string " ) return null ; <nl> - var spans = val . markedSpans , out = null ; <nl> - for ( var i = 0 ; i < spans . length ; + + i ) { <nl> - if ( spans [ i ] . marker . explicitlyCleared ) { if ( ! out ) out = spans . slice ( 0 , i ) ; } <nl> - else if ( out ) out . push ( spans [ i ] ) ; <nl> - } <nl> - return ! out ? spans : out . length ? out : null ; <nl> - } <nl> - function newHL ( text , spans ) { return spans ? { text : text , markedSpans : spans } : text ; } <nl> - <nl> function detachMarkedSpans ( line ) { <nl> var spans = line . markedSpans ; <nl> if ( ! spans ) return ; <nl> - for ( var i = 0 ; i < spans . length ; + + i ) { <nl> - var lines = spans [ i ] . marker . lines ; <nl> - var ix = indexOf ( lines , line ) ; <nl> - lines . splice ( ix , 1 ) ; <nl> - } <nl> + for ( var i = 0 ; i < spans . length ; + + i ) <nl> + spans [ i ] . marker . detachLine ( line ) ; <nl> line . markedSpans = null ; <nl> } <nl> <nl> function attachMarkedSpans ( line , spans ) { <nl> if ( ! spans ) return ; <nl> for ( var i = 0 ; i < spans . length ; + + i ) <nl> - spans [ i ] . marker . lines . push ( line ) ; <nl> + spans [ i ] . marker . attachLine ( line ) ; <nl> line . markedSpans = spans ; <nl> } <nl> <nl> window . CodeMirror = ( function ( ) { <nl> } ; <nl> function widgetOperation ( f ) { <nl> return function ( ) { <nl> - startOperation ( this . cm ) ; <nl> + var withOp = ! this . cm . curOp ; <nl> + if ( withOp ) startOperation ( this . cm ) ; <nl> try { var result = f . apply ( this , arguments ) ; } <nl> - finally { endOperation ( this . cm ) ; } <nl> + finally { if ( withOp ) endOperation ( this . cm ) ; } <nl> return result ; <nl> } ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> var ws = this . line . widgets , no = lineNo ( this . line ) ; <nl> if ( no = = null | | ! ws ) return ; <nl> for ( var i = 0 ; i < ws . length ; + + i ) if ( ws [ i ] = = this ) ws . splice ( i - - , 1 ) ; <nl> + if ( ! ws . length ) this . line . widgets = null ; <nl> updateLineHeight ( this . line , Math . max ( 0 , this . line . height - widgetHeight ( this ) ) ) ; <nl> regChange ( this . cm , no , no + 1 ) ; <nl> } ) ; <nl> window . CodeMirror = ( function ( ) { <nl> changeLine ( cm , handle , function ( line ) { <nl> ( line . widgets | | ( line . widgets = [ ] ) ) . push ( widget ) ; <nl> widget . line = line ; <nl> - if ( ! lineIsHidden ( line ) | | widget . showIfHidden ) { <nl> + if ( ! lineIsHidden ( cm . doc , line ) | | widget . showIfHidden ) { <nl> var aboveVisible = heightAtLine ( cm , line ) < cm . display . scroller . scrollTop ; <nl> updateLineHeight ( line , line . height + widgetHeight ( widget ) ) ; <nl> - if ( aboveVisible ) <nl> - setTimeout ( function ( ) { cm . display . scroller . scrollTop + = widget . height ; } ) ; <nl> + if ( aboveVisible ) addToScrollPos ( cm , 0 , widget . height ) ; <nl> } <nl> return true ; <nl> } ) ; <nl> window . CodeMirror = ( function ( ) { <nl> <nl> / / Line objects . These hold state related to a line , including <nl> / / highlighting info ( the styles array ) . <nl> - function makeLine ( text , markedSpans , height ) { <nl> - var line = { text : text , height : height } ; <nl> + function makeLine ( text , markedSpans , estimateHeight ) { <nl> + var line = { text : text } ; <nl> attachMarkedSpans ( line , markedSpans ) ; <nl> - if ( lineIsHidden ( line ) ) line . height = 0 ; <nl> + line . height = estimateHeight ? estimateHeight ( line ) : 1 ; <nl> return line ; <nl> } <nl> <nl> - function updateLine ( cm , line , text , markedSpans ) { <nl> + function updateLine ( line , text , markedSpans , estimateHeight ) { <nl> line . text = text ; <nl> if ( line . stateAfter ) line . stateAfter = null ; <nl> if ( line . styles ) line . styles = null ; <nl> if ( line . order ! = null ) line . order = null ; <nl> detachMarkedSpans ( line ) ; <nl> attachMarkedSpans ( line , markedSpans ) ; <nl> - if ( lineIsHidden ( line ) ) line . height = 0 ; <nl> - else if ( ! line . height ) line . height = textHeight ( cm . display ) ; <nl> - signalLater ( cm , line , " change " ) ; <nl> + var estHeight = estimateHeight ? estimateHeight ( line ) : 1 ; <nl> + if ( estHeight ! = line . height ) updateLineHeight ( line , estHeight ) ; <nl> } <nl> <nl> function cleanUpLine ( line ) { <nl> window . CodeMirror = ( function ( ) { <nl> / / array , which contains alternating fragments of text and CSS <nl> / / classes . <nl> function runMode ( cm , text , mode , state , f ) { <nl> - var flattenSpans = cm . options . flattenSpans ; <nl> + var flattenSpans = mode . flattenSpans ; <nl> + if ( flattenSpans = = null ) flattenSpans = cm . options . flattenSpans ; <nl> var curText = " " , curStyle = null ; <nl> var stream = new StringStream ( text , cm . options . tabSize ) ; <nl> if ( text = = " " & & mode . blankLine ) mode . blankLine ( state ) ; <nl> window . CodeMirror = ( function ( ) { <nl> function highlightLine ( cm , line , state ) { <nl> / / A styles array always starts with a number identifying the <nl> / / mode / overlays that it is based on ( for easy invalidation ) . <nl> - var st = [ cm . view . modeGen ] ; <nl> + var st = [ cm . state . modeGen ] ; <nl> / / Compute the base array of styles <nl> - runMode ( cm , line . text , cm . view . mode , state , function ( txt , style ) { st . push ( txt , style ) ; } ) ; <nl> + runMode ( cm , line . text , cm . doc . mode , state , function ( txt , style ) { st . push ( txt , style ) ; } ) ; <nl> <nl> / / Run overlays , adjust style array . <nl> - for ( var o = 0 ; o < cm . view . overlays . length ; + + o ) { <nl> - var overlay = cm . view . overlays [ o ] , i = 1 ; <nl> + for ( var o = 0 ; o < cm . state . overlays . length ; + + o ) { <nl> + var overlay = cm . state . overlays [ o ] , i = 1 ; <nl> runMode ( cm , line . text , overlay . mode , true , function ( txt , style ) { <nl> var start = i , len = txt . length ; <nl> / / Ensure there ' s a token end at the current position , and that i points at it <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> <nl> function getLineStyles ( cm , line ) { <nl> - if ( ! line . styles | | line . styles [ 0 ] ! = cm . view . modeGen ) <nl> + if ( ! line . styles | | line . styles [ 0 ] ! = cm . state . modeGen ) <nl> line . styles = highlightLine ( cm , line , line . stateAfter = getStateBefore ( cm , lineNo ( line ) ) ) ; <nl> return line . styles ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> / / Lightweight form of highlight - - proceed over this line and <nl> / / update state , but don ' t save a style array . <nl> function processLine ( cm , line , state ) { <nl> - var mode = cm . view . mode ; <nl> + var mode = cm . doc . mode ; <nl> var stream = new StringStream ( line . text , cm . options . tabSize ) ; <nl> if ( line . text = = " " & & mode . blankLine ) mode . blankLine ( state ) ; <nl> while ( ! stream . eol ( ) & & stream . pos < = 5000 ) { <nl> window . CodeMirror = ( function ( ) { <nl> var merged , line = realLine , lineBefore , sawBefore , simple = true ; <nl> while ( merged = collapsedSpanAtStart ( line ) ) { <nl> simple = false ; <nl> - line = getLine ( cm . view . doc , merged . find ( ) . from . line ) ; <nl> + line = getLine ( cm . doc , merged . find ( ) . from . line ) ; <nl> if ( ! lineBefore ) lineBefore = line ; <nl> } <nl> <nl> window . CodeMirror = ( function ( ) { <nl> builder . measure = line = = realLine & & measure ; <nl> builder . pos = 0 ; <nl> builder . addToken = builder . measure ? buildTokenMeasure : buildToken ; <nl> + if ( ( ie | | webkit ) & & cm . getOption ( " lineWrapping " ) ) <nl> + builder . addToken = buildTokenSplitSpaces ( builder . addToken ) ; <nl> if ( measure & & sawBefore & & line ! = realLine & & ! builder . addedOne ) { <nl> measure [ 0 ] = builder . pre . appendChild ( zeroWidthElement ( cm . display . measure ) ) ; <nl> builder . addedOne = true ; <nl> window . CodeMirror = ( function ( ) { <nl> var next = insertLineContent ( line , builder , getLineStyles ( cm , line ) ) ; <nl> sawBefore = line = = lineBefore ; <nl> if ( next ) { <nl> - line = getLine ( cm . view . doc , next . to . line ) ; <nl> + line = getLine ( cm . doc , next . to . line ) ; <nl> simple = false ; <nl> } <nl> } while ( next ) ; <nl> <nl> if ( measure & & ! builder . addedOne ) <nl> measure [ 0 ] = builder . pre . appendChild ( simple ? elt ( " span " , " \ u00a0 " ) : zeroWidthElement ( cm . display . measure ) ) ; <nl> - if ( ! builder . pre . firstChild & & ! lineIsHidden ( realLine ) ) <nl> + if ( ! builder . pre . firstChild & & ! lineIsHidden ( cm . doc , realLine ) ) <nl> builder . pre . appendChild ( document . createTextNode ( " \ u00a0 " ) ) ; <nl> <nl> + var order ; <nl> + / / Work around problem with the reported dimensions of single - char <nl> + / / direction spans on IE ( issue # 1129 ) . See also the comment in <nl> + / / cursorCoords . <nl> + if ( measure & & ie & & ( order = getOrder ( line ) ) ) { <nl> + var l = order . length - 1 ; <nl> + if ( order [ l ] . from = = order [ l ] . to ) - - l ; <nl> + var last = order [ l ] , prev = order [ l - 1 ] ; <nl> + if ( last . from + 1 = = last . to & & prev & & last . level < prev . level ) { <nl> + var span = measure [ builder . pos - 1 ] ; <nl> + if ( span ) span . parentNode . insertBefore ( span . measureRight = zeroWidthElement ( cm . display . measure ) , <nl> + span . nextSibling ) ; <nl> + } <nl> + } <nl> + <nl> + signal ( cm , " renderLine " , cm , realLine , builder . pre ) ; <nl> return builder . pre ; <nl> } <nl> <nl> - var tokenSpecialChars = / [ \ t \ u0000 - \ u0019 \ u200b \ u2028 \ u2029 \ uFEFF ] / g ; <nl> + var tokenSpecialChars = / [ \ t \ u0000 - \ u0019 \ u00ad \ u200b \ u2028 \ u2029 \ uFEFF ] / g ; <nl> function buildToken ( builder , text , style , startStyle , endStyle ) { <nl> if ( ! text ) return ; <nl> if ( ! tokenSpecialChars . test ( text ) ) { <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> <nl> function buildTokenMeasure ( builder , text , style , startStyle , endStyle ) { <nl> + var wrapping = builder . cm . options . lineWrapping ; <nl> for ( var i = 0 ; i < text . length ; + + i ) { <nl> - if ( i & & i < text . length & & <nl> - builder . cm . options . lineWrapping & & <nl> - spanAffectsWrapping . test ( text . slice ( i - 1 , i + 1 ) ) ) <nl> + var ch = text . charAt ( i ) , start = i = = 0 ; <nl> + if ( ch > = " \ ud800 " & & ch < " \ udbff " & & i < text . length - 1 ) { <nl> + ch = text . slice ( i , i + 2 ) ; <nl> + + + i ; <nl> + } else if ( i & & wrapping & & <nl> + spanAffectsWrapping . test ( text . slice ( i - 1 , i + 1 ) ) ) { <nl> builder . pre . appendChild ( elt ( " wbr " ) ) ; <nl> - builder . measure [ builder . pos + + ] = <nl> - buildToken ( builder , text . charAt ( i ) , style , <nl> - i = = 0 & & startStyle , i = = text . length - 1 & & endStyle ) ; <nl> + } <nl> + var span = builder . measure [ builder . pos ] = <nl> + buildToken ( builder , ch , style , <nl> + start & & startStyle , i = = text . length - 1 & & endStyle ) ; <nl> + / / In IE single - space nodes wrap differently than spaces <nl> + / / embedded in larger text nodes , except when set to <nl> + / / white - space : normal ( issue # 1268 ) . <nl> + if ( ie & & wrapping & & ch = = " " & & i & & ! / \ s / . test ( text . charAt ( i - 1 ) ) & & <nl> + i < text . length - 1 & & ! / \ s / . test ( text . charAt ( i + 1 ) ) ) <nl> + span . style . whiteSpace = " normal " ; <nl> + builder . pos + = ch . length ; <nl> } <nl> if ( text . length ) builder . addedOne = true ; <nl> } <nl> <nl> + function buildTokenSplitSpaces ( inner ) { <nl> + function split ( old ) { <nl> + var out = " " ; <nl> + for ( var i = 0 ; i < old . length - 2 ; + + i ) out + = i % 2 ? " " : " \ u00a0 " ; <nl> + out + = " " ; <nl> + return out ; <nl> + } <nl> + return function ( builder , text , style , startStyle , endStyle ) { <nl> + return inner ( builder , text . replace ( / { 3 , } / , split ) , style , startStyle , endStyle ) ; <nl> + } ; <nl> + } <nl> + <nl> function buildCollapsedSpan ( builder , size , widget ) { <nl> if ( widget ) { <nl> if ( ! builder . display ) widget = widget . cloneNode ( true ) ; <nl> window . CodeMirror = ( function ( ) { <nl> var end = pos + text . length ; <nl> if ( ! collapsed ) { <nl> var tokenText = end > upto ? text . slice ( 0 , upto - pos ) : text ; <nl> - builder . addToken ( builder , tokenText , style + spanStyle , <nl> + builder . addToken ( builder , tokenText , style ? style + spanStyle : spanStyle , <nl> spanStartStyle , pos + tokenText . length = = nextChange ? spanEndStyle : " " ) ; <nl> } <nl> if ( end > = upto ) { text = text . slice ( upto - pos ) ; pos = upto ; break ; } <nl> window . CodeMirror = ( function ( ) { <nl> <nl> / / DOCUMENT DATA STRUCTURE <nl> <nl> + function updateDoc ( doc , change , markedSpans , selAfter , estimateHeight ) { <nl> + function spansFor ( n ) { return markedSpans ? markedSpans [ n ] : null ; } <nl> + function update ( line , text , spans ) { <nl> + updateLine ( line , text , spans , estimateHeight ) ; <nl> + signalLater ( line , " change " , line , change ) ; <nl> + } <nl> + <nl> + var from = change . from , to = change . to , text = change . text ; <nl> + var firstLine = getLine ( doc , from . line ) , lastLine = getLine ( doc , to . line ) ; <nl> + var lastText = lst ( text ) , lastSpans = spansFor ( text . length - 1 ) , nlines = to . line - from . line ; <nl> + <nl> + / / First adjust the line structure <nl> + if ( from . ch = = 0 & & to . ch = = 0 & & lastText = = " " ) { <nl> + / / This is a whole - line replace . Treated specially to make <nl> + / / sure line objects move the way they are supposed to . <nl> + for ( var i = 0 , e = text . length - 1 , added = [ ] ; i < e ; + + i ) <nl> + added . push ( makeLine ( text [ i ] , spansFor ( i ) , estimateHeight ) ) ; <nl> + update ( lastLine , lastLine . text , lastSpans ) ; <nl> + if ( nlines ) doc . remove ( from . line , nlines ) ; <nl> + if ( added . length ) doc . insert ( from . line , added ) ; <nl> + } else if ( firstLine = = lastLine ) { <nl> + if ( text . length = = 1 ) { <nl> + update ( firstLine , firstLine . text . slice ( 0 , from . ch ) + lastText + firstLine . text . slice ( to . ch ) , lastSpans ) ; <nl> + } else { <nl> + for ( var added = [ ] , i = 1 , e = text . length - 1 ; i < e ; + + i ) <nl> + added . push ( makeLine ( text [ i ] , spansFor ( i ) , estimateHeight ) ) ; <nl> + added . push ( makeLine ( lastText + firstLine . text . slice ( to . ch ) , lastSpans , estimateHeight ) ) ; <nl> + update ( firstLine , firstLine . text . slice ( 0 , from . ch ) + text [ 0 ] , spansFor ( 0 ) ) ; <nl> + doc . insert ( from . line + 1 , added ) ; <nl> + } <nl> + } else if ( text . length = = 1 ) { <nl> + update ( firstLine , firstLine . text . slice ( 0 , from . ch ) + text [ 0 ] + lastLine . text . slice ( to . ch ) , spansFor ( 0 ) ) ; <nl> + doc . remove ( from . line + 1 , nlines ) ; <nl> + } else { <nl> + update ( firstLine , firstLine . text . slice ( 0 , from . ch ) + text [ 0 ] , spansFor ( 0 ) ) ; <nl> + update ( lastLine , lastText + lastLine . text . slice ( to . ch ) , lastSpans ) ; <nl> + for ( var i = 1 , e = text . length - 1 , added = [ ] ; i < e ; + + i ) <nl> + added . push ( makeLine ( text [ i ] , spansFor ( i ) , estimateHeight ) ) ; <nl> + if ( nlines > 1 ) doc . remove ( from . line + 1 , nlines - 1 ) ; <nl> + doc . insert ( from . line + 1 , added ) ; <nl> + } <nl> + <nl> + signalLater ( doc , " change " , doc , change ) ; <nl> + setSelection ( doc , selAfter . anchor , selAfter . head , null , true ) ; <nl> + } <nl> + <nl> function LeafChunk ( lines ) { <nl> this . lines = lines ; <nl> this . parent = null ; <nl> window . CodeMirror = ( function ( ) { <nl> <nl> LeafChunk . prototype = { <nl> chunkSize : function ( ) { return this . lines . length ; } , <nl> - remove : function ( at , n , cm ) { <nl> + removeInner : function ( at , n ) { <nl> for ( var i = at , e = at + n ; i < e ; + + i ) { <nl> var line = this . lines [ i ] ; <nl> this . height - = line . height ; <nl> cleanUpLine ( line ) ; <nl> - signalLater ( cm , line , " delete " ) ; <nl> + signalLater ( line , " delete " ) ; <nl> } <nl> this . lines . splice ( at , n ) ; <nl> } , <nl> collapse : function ( lines ) { <nl> lines . splice . apply ( lines , [ lines . length , 0 ] . concat ( this . lines ) ) ; <nl> } , <nl> - insertHeight : function ( at , lines , height ) { <nl> + insertInner : function ( at , lines , height ) { <nl> this . height + = height ; <nl> this . lines = this . lines . slice ( 0 , at ) . concat ( lines ) . concat ( this . lines . slice ( at ) ) ; <nl> for ( var i = 0 , e = lines . length ; i < e ; + + i ) lines [ i ] . parent = this ; <nl> window . CodeMirror = ( function ( ) { <nl> <nl> BranchChunk . prototype = { <nl> chunkSize : function ( ) { return this . size ; } , <nl> - remove : function ( at , n , callbacks ) { <nl> + removeInner : function ( at , n ) { <nl> this . size - = n ; <nl> for ( var i = 0 ; i < this . children . length ; + + i ) { <nl> var child = this . children [ i ] , sz = child . chunkSize ( ) ; <nl> if ( at < sz ) { <nl> var rm = Math . min ( n , sz - at ) , oldHeight = child . height ; <nl> - child . remove ( at , rm , callbacks ) ; <nl> + child . removeInner ( at , rm ) ; <nl> this . height - = oldHeight - child . height ; <nl> if ( sz = = rm ) { this . children . splice ( i - - , 1 ) ; child . parent = null ; } <nl> if ( ( n - = rm ) = = 0 ) break ; <nl> window . CodeMirror = ( function ( ) { <nl> collapse : function ( lines ) { <nl> for ( var i = 0 , e = this . children . length ; i < e ; + + i ) this . children [ i ] . collapse ( lines ) ; <nl> } , <nl> - insert : function ( at , lines ) { <nl> - var height = 0 ; <nl> - for ( var i = 0 , e = lines . length ; i < e ; + + i ) height + = lines [ i ] . height ; <nl> - this . insertHeight ( at , lines , height ) ; <nl> - } , <nl> - insertHeight : function ( at , lines , height ) { <nl> + insertInner : function ( at , lines , height ) { <nl> this . size + = lines . length ; <nl> this . height + = height ; <nl> for ( var i = 0 , e = this . children . length ; i < e ; + + i ) { <nl> var child = this . children [ i ] , sz = child . chunkSize ( ) ; <nl> if ( at < = sz ) { <nl> - child . insertHeight ( at , lines , height ) ; <nl> + child . insertInner ( at , lines , height ) ; <nl> if ( child . lines & & child . lines . length > 50 ) { <nl> while ( child . lines . length > 50 ) { <nl> var spilled = child . lines . splice ( child . lines . length - 25 , 25 ) ; <nl> window . CodeMirror = ( function ( ) { <nl> } while ( me . children . length > 10 ) ; <nl> me . parent . maybeSpill ( ) ; <nl> } , <nl> - iter : function ( from , to , op ) { this . iterN ( from , to - from , op ) ; } , <nl> iterN : function ( at , n , op ) { <nl> for ( var i = 0 , e = this . children . length ; i < e ; + + i ) { <nl> var child = this . children [ i ] , sz = child . chunkSize ( ) ; <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> } ; <nl> <nl> + var nextDocId = 0 ; <nl> + var Doc = CodeMirror . Doc = function ( text , mode , firstLine ) { <nl> + if ( ! ( this instanceof Doc ) ) return new Doc ( text , mode , firstLine ) ; <nl> + if ( firstLine = = null ) firstLine = 0 ; <nl> + <nl> + BranchChunk . call ( this , [ new LeafChunk ( [ makeLine ( " " , null ) ] ) ] ) ; <nl> + this . first = firstLine ; <nl> + this . scrollTop = this . scrollLeft = 0 ; <nl> + this . cantEdit = false ; <nl> + this . history = makeHistory ( ) ; <nl> + this . frontier = firstLine ; <nl> + var start = Pos ( firstLine , 0 ) ; <nl> + this . sel = { from : start , to : start , head : start , anchor : start , shift : false , extend : false , goalColumn : null } ; <nl> + this . id = + + nextDocId ; <nl> + this . modeOption = mode ; <nl> + <nl> + if ( typeof text = = " string " ) text = splitLines ( text ) ; <nl> + updateDoc ( this , { from : start , to : start , text : text } , null , { head : start , anchor : start } ) ; <nl> + } ; <nl> + <nl> + Doc . prototype = createObj ( BranchChunk . prototype , { <nl> + iter : function ( from , to , op ) { <nl> + if ( op ) this . iterN ( from - this . first , to - from , op ) ; <nl> + else this . iterN ( this . first , this . first + this . size , from ) ; <nl> + } , <nl> + <nl> + insert : function ( at , lines ) { <nl> + var height = 0 ; <nl> + for ( var i = 0 , e = lines . length ; i < e ; + + i ) height + = lines [ i ] . height ; <nl> + this . insertInner ( at - this . first , lines , height ) ; <nl> + } , <nl> + remove : function ( at , n ) { this . removeInner ( at - this . first , n ) ; } , <nl> + <nl> + getValue : function ( lineSep ) { <nl> + var lines = getLines ( this , this . first , this . first + this . size ) ; <nl> + if ( lineSep = = = false ) return lines ; <nl> + return lines . join ( lineSep | | " \ n " ) ; <nl> + } , <nl> + setValue : function ( code ) { <nl> + var top = Pos ( this . first , 0 ) , last = this . first + this . size - 1 ; <nl> + makeChange ( this , { from : top , to : Pos ( last , getLine ( this , last ) . text . length ) , <nl> + text : splitLines ( code ) , origin : " setValue " } , <nl> + { head : top , anchor : top } , true ) ; <nl> + } , <nl> + replaceRange : function ( code , from , to , origin ) { <nl> + from = clipPos ( this , from ) ; <nl> + to = to ? clipPos ( this , to ) : from ; <nl> + replaceRange ( this , code , from , to , origin ) ; <nl> + } , <nl> + getRange : function ( from , to , lineSep ) { <nl> + var lines = getBetween ( this , clipPos ( this , from ) , clipPos ( this , to ) ) ; <nl> + if ( lineSep = = = false ) return lines ; <nl> + return lines . join ( lineSep | | " \ n " ) ; <nl> + } , <nl> + <nl> + getLine : function ( line ) { var l = this . getLineHandle ( line ) ; return l & & l . text ; } , <nl> + setLine : function ( line , text ) { <nl> + if ( isLine ( this , line ) ) <nl> + replaceRange ( this , text , Pos ( line , 0 ) , clipPos ( this , Pos ( line ) ) ) ; <nl> + } , <nl> + removeLine : function ( line ) { <nl> + if ( isLine ( this , line ) ) <nl> + replaceRange ( this , " " , Pos ( line , 0 ) , clipPos ( this , Pos ( line + 1 , 0 ) ) ) ; <nl> + } , <nl> + <nl> + getLineHandle : function ( line ) { if ( isLine ( this , line ) ) return getLine ( this , line ) ; } , <nl> + getLineNumber : function ( line ) { return lineNo ( line ) ; } , <nl> + <nl> + lineCount : function ( ) { return this . size ; } , <nl> + firstLine : function ( ) { return this . first ; } , <nl> + lastLine : function ( ) { return this . first + this . size - 1 ; } , <nl> + <nl> + clipPos : function ( pos ) { return clipPos ( this , pos ) ; } , <nl> + <nl> + getCursor : function ( start ) { <nl> + var sel = this . sel , pos ; <nl> + if ( start = = null | | start = = " head " ) pos = sel . head ; <nl> + else if ( start = = " anchor " ) pos = sel . anchor ; <nl> + else if ( start = = " end " | | start = = = false ) pos = sel . to ; <nl> + else pos = sel . from ; <nl> + return copyPos ( pos ) ; <nl> + } , <nl> + somethingSelected : function ( ) { return ! posEq ( this . sel . head , this . sel . anchor ) ; } , <nl> + <nl> + setCursor : docOperation ( function ( line , ch , extend ) { <nl> + var pos = clipPos ( this , typeof line = = " number " ? Pos ( line , ch | | 0 ) : line ) ; <nl> + if ( extend ) extendSelection ( this , pos ) ; <nl> + else setSelection ( this , pos , pos ) ; <nl> + } ) , <nl> + setSelection : docOperation ( function ( anchor , head ) { <nl> + setSelection ( this , clipPos ( this , anchor ) , clipPos ( this , head | | anchor ) ) ; <nl> + } ) , <nl> + extendSelection : docOperation ( function ( from , to ) { <nl> + extendSelection ( this , clipPos ( this , from ) , to & & clipPos ( this , to ) ) ; <nl> + } ) , <nl> + <nl> + getSelection : function ( lineSep ) { return this . getRange ( this . sel . from , this . sel . to , lineSep ) ; } , <nl> + replaceSelection : function ( code , collapse , origin ) { <nl> + makeChange ( this , { from : this . sel . from , to : this . sel . to , text : splitLines ( code ) , origin : origin } , collapse | | " around " ) ; <nl> + } , <nl> + undo : docOperation ( function ( ) { makeChangeFromHistory ( this , " undo " ) ; } ) , <nl> + redo : docOperation ( function ( ) { makeChangeFromHistory ( this , " redo " ) ; } ) , <nl> + <nl> + setExtending : function ( val ) { this . sel . extend = val ; } , <nl> + <nl> + historySize : function ( ) { <nl> + var hist = this . history ; <nl> + return { undo : hist . done . length , redo : hist . undone . length } ; <nl> + } , <nl> + clearHistory : function ( ) { this . history = makeHistory ( ) ; } , <nl> + <nl> + markClean : function ( ) { <nl> + this . history . dirtyCounter = 0 ; <nl> + this . history . lastOp = this . history . lastOrigin = null ; <nl> + } , <nl> + isClean : function ( ) { return this . history . dirtyCounter = = 0 ; } , <nl> + <nl> + getHistory : function ( ) { <nl> + return { done : copyHistoryArray ( this . history . done ) , <nl> + undone : copyHistoryArray ( this . history . undone ) } ; <nl> + } , <nl> + setHistory : function ( histData ) { <nl> + var hist = this . history = makeHistory ( ) ; <nl> + hist . done = histData . done . slice ( 0 ) ; <nl> + hist . undone = histData . undone . slice ( 0 ) ; <nl> + } , <nl> + <nl> + markText : function ( from , to , options ) { <nl> + return markText ( this , clipPos ( this , from ) , clipPos ( this , to ) , options , " range " ) ; <nl> + } , <nl> + setBookmark : function ( pos , options ) { <nl> + var realOpts = { replacedWith : options & & ( options . nodeType = = null ? options . widget : options ) , <nl> + insertLeft : options & & options . insertLeft } ; <nl> + pos = clipPos ( this , pos ) ; <nl> + return markText ( this , pos , pos , realOpts , " bookmark " ) ; <nl> + } , <nl> + findMarksAt : function ( pos ) { <nl> + pos = clipPos ( this , pos ) ; <nl> + var markers = [ ] , spans = getLine ( this , pos . line ) . markedSpans ; <nl> + if ( spans ) for ( var i = 0 ; i < spans . length ; + + i ) { <nl> + var span = spans [ i ] ; <nl> + if ( ( span . from = = null | | span . from < = pos . ch ) & & <nl> + ( span . to = = null | | span . to > = pos . ch ) ) <nl> + markers . push ( span . marker . parent | | span . marker ) ; <nl> + } <nl> + return markers ; <nl> + } , <nl> + getAllMarks : function ( ) { <nl> + var markers = [ ] ; <nl> + this . iter ( function ( line ) { <nl> + var sps = line . markedSpans ; <nl> + if ( sps ) for ( var i = 0 ; i < sps . length ; + + i ) <nl> + if ( sps [ i ] . from ! = null ) markers . push ( sps [ i ] . marker ) ; <nl> + } ) ; <nl> + return markers ; <nl> + } , <nl> + <nl> + posFromIndex : function ( off ) { <nl> + var ch , lineNo = this . first ; <nl> + this . iter ( function ( line ) { <nl> + var sz = line . text . length + 1 ; <nl> + if ( sz > off ) { ch = off ; return true ; } <nl> + off - = sz ; <nl> + + + lineNo ; <nl> + } ) ; <nl> + return clipPos ( this , Pos ( lineNo , ch ) ) ; <nl> + } , <nl> + indexFromPos : function ( coords ) { <nl> + coords = clipPos ( this , coords ) ; <nl> + var index = coords . ch ; <nl> + if ( coords . line < this . first | | coords . ch < 0 ) return 0 ; <nl> + this . iter ( this . first , coords . line , function ( line ) { <nl> + index + = line . text . length + 1 ; <nl> + } ) ; <nl> + return index ; <nl> + } , <nl> + <nl> + copy : function ( copyHistory ) { <nl> + var doc = new Doc ( getLines ( this , this . first , this . first + this . size ) , this . modeOption , this . first ) ; <nl> + doc . scrollTop = this . scrollTop ; doc . scrollLeft = this . scrollLeft ; <nl> + doc . sel = { from : this . sel . from , to : this . sel . to , head : this . sel . head , anchor : this . sel . anchor , <nl> + shift : this . sel . shift , extend : false , goalColumn : this . sel . goalColumn } ; <nl> + if ( copyHistory ) { <nl> + doc . history . undoDepth = this . history . undoDepth ; <nl> + doc . setHistory ( this . getHistory ( ) ) ; <nl> + } <nl> + return doc ; <nl> + } , <nl> + <nl> + linkedDoc : function ( options ) { <nl> + if ( ! options ) options = { } ; <nl> + var from = this . first , to = this . first + this . size ; <nl> + if ( options . from ! = null & & options . from > from ) from = options . from ; <nl> + if ( options . to ! = null & & options . to < to ) to = options . to ; <nl> + var copy = new Doc ( getLines ( this , from , to ) , options . mode | | this . modeOption , from ) ; <nl> + if ( options . sharedHist ) copy . history = this . history ; <nl> + ( this . linked | | ( this . linked = [ ] ) ) . push ( { doc : copy , sharedHist : options . sharedHist } ) ; <nl> + copy . linked = [ { doc : this , isParent : true , sharedHist : options . sharedHist } ] ; <nl> + return copy ; <nl> + } , <nl> + unlinkDoc : function ( other ) { <nl> + if ( other instanceof CodeMirror ) other = other . doc ; <nl> + if ( this . linked ) for ( var i = 0 ; i < this . linked . length ; + + i ) { <nl> + var link = this . linked [ i ] ; <nl> + if ( link . doc ! = other ) continue ; <nl> + this . linked . splice ( i , 1 ) ; <nl> + other . unlinkDoc ( this ) ; <nl> + break ; <nl> + } <nl> + / / If the histories were shared , split them again <nl> + if ( other . history = = this . history ) { <nl> + var splitIds = [ other . id ] ; <nl> + linkedDocs ( other , function ( doc ) { splitIds . push ( doc . id ) ; } , true ) ; <nl> + other . history = makeHistory ( ) ; <nl> + other . history . done = copyHistoryArray ( this . history . done , splitIds ) ; <nl> + other . history . undone = copyHistoryArray ( this . history . undone , splitIds ) ; <nl> + } <nl> + } , <nl> + iterLinkedDocs : function ( f ) { linkedDocs ( this , f ) ; } , <nl> + <nl> + getMode : function ( ) { return this . mode ; } , <nl> + getEditor : function ( ) { return this . cm ; } <nl> + } ) ; <nl> + <nl> + Doc . prototype . eachLine = Doc . prototype . iter ; <nl> + <nl> + / / The Doc methods that should be available on CodeMirror instances <nl> + var dontDelegate = " iter insert remove copy getEditor " . split ( " " ) ; <nl> + for ( var prop in Doc . prototype ) if ( Doc . prototype . hasOwnProperty ( prop ) & & indexOf ( dontDelegate , prop ) < 0 ) <nl> + CodeMirror . prototype [ prop ] = ( function ( method ) { <nl> + return function ( ) { return method . apply ( this . doc , arguments ) ; } ; <nl> + } ) ( Doc . prototype [ prop ] ) ; <nl> + <nl> + function linkedDocs ( doc , f , sharedHistOnly ) { <nl> + function propagate ( doc , skip , sharedHist ) { <nl> + if ( doc . linked ) for ( var i = 0 ; i < doc . linked . length ; + + i ) { <nl> + var rel = doc . linked [ i ] ; <nl> + if ( rel . doc = = skip ) continue ; <nl> + var shared = sharedHist & & rel . sharedHist ; <nl> + if ( sharedHistOnly & & ! shared ) continue ; <nl> + f ( rel . doc , shared ) ; <nl> + propagate ( rel . doc , doc , shared ) ; <nl> + } <nl> + } <nl> + propagate ( doc , null , true ) ; <nl> + } <nl> + <nl> + function attachDoc ( cm , doc ) { <nl> + if ( doc . cm ) throw new Error ( " This document is already in use . " ) ; <nl> + cm . doc = doc ; <nl> + doc . cm = cm ; <nl> + estimateLineHeights ( cm ) ; <nl> + loadMode ( cm ) ; <nl> + if ( ! cm . options . lineWrapping ) computeMaxLength ( cm ) ; <nl> + cm . options . mode = doc . modeOption ; <nl> + regChange ( cm ) ; <nl> + } <nl> + <nl> / / LINE UTILITIES <nl> <nl> function getLine ( chunk , n ) { <nl> + n - = chunk . first ; <nl> while ( ! chunk . lines ) { <nl> for ( var i = 0 ; ; + + i ) { <nl> var child = chunk . children [ i ] , sz = child . chunkSize ( ) ; <nl> window . CodeMirror = ( function ( ) { <nl> return chunk . lines [ n ] ; <nl> } <nl> <nl> + function getBetween ( doc , start , end ) { <nl> + var out = [ ] , n = start . line ; <nl> + doc . iter ( start . line , end . line + 1 , function ( line ) { <nl> + var text = line . text ; <nl> + if ( n = = end . line ) text = text . slice ( 0 , end . ch ) ; <nl> + if ( n = = start . line ) text = text . slice ( start . ch ) ; <nl> + out . push ( text ) ; <nl> + + + n ; <nl> + } ) ; <nl> + return out ; <nl> + } <nl> + function getLines ( doc , from , to ) { <nl> + var out = [ ] ; <nl> + doc . iter ( from , to , function ( line ) { out . push ( line . text ) ; } ) ; <nl> + return out ; <nl> + } <nl> + <nl> function updateLineHeight ( line , height ) { <nl> var diff = height - line . height ; <nl> for ( var n = line ; n ; n = n . parent ) n . height + = diff ; <nl> window . CodeMirror = ( function ( ) { <nl> no + = chunk . children [ i ] . chunkSize ( ) ; <nl> } <nl> } <nl> - return no ; <nl> - } <nl> - <nl> - function lineDoc ( line ) { <nl> - for ( var d = line . parent ; d . parent ; d = d . parent ) { } <nl> - return d ; <nl> + return no + cur . first ; <nl> } <nl> <nl> function lineAtHeight ( chunk , h ) { <nl> - var n = 0 ; <nl> + var n = chunk . first ; <nl> outer : do { <nl> for ( var i = 0 , e = chunk . children . length ; i < e ; + + i ) { <nl> var child = chunk . children [ i ] , ch = child . height ; <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> <nl> function heightAtLine ( cm , lineObj ) { <nl> - lineObj = visualLine ( cm . view . doc , lineObj ) ; <nl> + lineObj = visualLine ( cm . doc , lineObj ) ; <nl> <nl> var h = 0 , chunk = lineObj . parent ; <nl> for ( var i = 0 ; i < chunk . lines . length ; + + i ) { <nl> window . CodeMirror = ( function ( ) { <nl> / / Arrays of history events . Doing something adds an event to <nl> / / done and clears undo . Undoing moves events from done to <nl> / / undone , redoing moves them in the other direction . <nl> - done : [ ] , undone : [ ] , <nl> + done : [ ] , undone : [ ] , undoDepth : Infinity , <nl> / / Used to track when changes can be merged into a single undo <nl> / / event <nl> lastTime : 0 , lastOp : null , lastOrigin : null , <nl> window . CodeMirror = ( function ( ) { <nl> } ; <nl> } <nl> <nl> - function addChange ( cm , start , added , old , origin , fromBefore , toBefore , fromAfter , toAfter ) { <nl> - var history = cm . view . history ; <nl> - history . undone . length = 0 ; <nl> - var time = + new Date , cur = lst ( history . done ) ; <nl> - <nl> + function attachLocalSpans ( doc , change , from , to ) { <nl> + var existing = change [ " spans_ " + doc . id ] , n = 0 ; <nl> + doc . iter ( Math . max ( doc . first , from ) , Math . min ( doc . first + doc . size , to ) , function ( line ) { <nl> + if ( line . markedSpans ) <nl> + ( existing | | ( existing = change [ " spans_ " + doc . id ] = { } ) ) [ n ] = line . markedSpans ; <nl> + + + n ; <nl> + } ) ; <nl> + } <nl> + <nl> + function historyChangeFromChange ( doc , change ) { <nl> + var histChange = { from : change . from , to : changeEnd ( change ) , text : getBetween ( doc , change . from , change . to ) } ; <nl> + attachLocalSpans ( doc , histChange , change . from . line , change . to . line + 1 ) ; <nl> + linkedDocs ( doc , function ( doc ) { attachLocalSpans ( doc , histChange , change . from . line , change . to . line + 1 ) ; } , true ) ; <nl> + return histChange ; <nl> + } <nl> + <nl> + function addToHistory ( doc , change , selAfter , opId ) { <nl> + var hist = doc . history ; <nl> + hist . undone . length = 0 ; <nl> + var time = + new Date , cur = lst ( hist . done ) ; <nl> + <nl> if ( cur & & <nl> - ( history . lastOp = = cm . curOp . id | | <nl> - history . lastOrigin = = origin & & ( origin = = " input " | | origin = = " delete " ) & & <nl> - history . lastTime > time - 600 ) ) { <nl> + ( hist . lastOp = = opId | | <nl> + hist . lastOrigin = = change . origin & & change . origin & & <nl> + ( ( change . origin . charAt ( 0 ) = = " + " & & hist . lastTime > time - 600 ) | | change . origin . charAt ( 0 ) = = " * " ) ) ) { <nl> / / Merge this change into the last event <nl> - var last = lst ( cur . events ) ; <nl> - if ( last . start > start + old . length | | last . start + last . added < start ) { <nl> - / / Doesn ' t intersect with last sub - event , add new sub - event <nl> - cur . events . push ( { start : start , added : added , old : old } ) ; <nl> + var last = lst ( cur . changes ) ; <nl> + if ( posEq ( change . from , change . to ) & & posEq ( change . from , last . to ) ) { <nl> + / / Optimized case for simple insertion - - don ' t want to add <nl> + / / new changesets for every character typed <nl> + last . to = changeEnd ( change ) ; <nl> } else { <nl> - / / Patch up the last sub - event <nl> - var startBefore = Math . max ( 0 , last . start - start ) , <nl> - endAfter = Math . max ( 0 , ( start + old . length ) - ( last . start + last . added ) ) ; <nl> - for ( var i = startBefore ; i > 0 ; - - i ) last . old . unshift ( old [ i - 1 ] ) ; <nl> - for ( var i = endAfter ; i > 0 ; - - i ) last . old . push ( old [ old . length - i ] ) ; <nl> - if ( startBefore ) last . start = start ; <nl> - last . added + = added - ( old . length - startBefore - endAfter ) ; <nl> + / / Add new sub - event <nl> + cur . changes . push ( historyChangeFromChange ( doc , change ) ) ; <nl> } <nl> - cur . fromAfter = fromAfter ; cur . toAfter = toAfter ; <nl> + cur . anchorAfter = selAfter . anchor ; cur . headAfter = selAfter . head ; <nl> } else { <nl> / / Can not be merged , start a new event . <nl> - cur = { events : [ { start : start , added : added , old : old } ] , <nl> - fromBefore : fromBefore , toBefore : toBefore , fromAfter : fromAfter , toAfter : toAfter } ; <nl> - history . done . push ( cur ) ; <nl> - while ( history . done . length > cm . options . undoDepth ) <nl> - history . done . shift ( ) ; <nl> - if ( history . dirtyCounter < 0 ) <nl> - / / The user has made a change after undoing past the last clean state . <nl> - / / We can never get back to a clean state now until markClean ( ) is called . <nl> - history . dirtyCounter = NaN ; <nl> + cur = { changes : [ historyChangeFromChange ( doc , change ) ] , <nl> + anchorBefore : doc . sel . anchor , headBefore : doc . sel . head , <nl> + anchorAfter : selAfter . anchor , headAfter : selAfter . head } ; <nl> + hist . done . push ( cur ) ; <nl> + while ( hist . done . length > hist . undoDepth ) <nl> + hist . done . shift ( ) ; <nl> + if ( hist . dirtyCounter < 0 ) <nl> + / / The user has made a change after undoing past the last clean state . <nl> + / / We can never get back to a clean state now until markClean ( ) is called . <nl> + hist . dirtyCounter = NaN ; <nl> else <nl> - history . dirtyCounter + + ; <nl> + hist . dirtyCounter + + ; <nl> } <nl> - history . lastTime = time ; <nl> - history . lastOp = cm . curOp . id ; <nl> - history . lastOrigin = origin ; <nl> + hist . lastTime = time ; <nl> + hist . lastOp = opId ; <nl> + hist . lastOrigin = change . origin ; <nl> + } <nl> + <nl> + function removeClearedSpans ( spans ) { <nl> + if ( ! spans ) return null ; <nl> + for ( var i = 0 , out ; i < spans . length ; + + i ) { <nl> + if ( spans [ i ] . marker . explicitlyCleared ) { if ( ! out ) out = spans . slice ( 0 , i ) ; } <nl> + else if ( out ) out . push ( spans [ i ] ) ; <nl> + } <nl> + return ! out ? spans : out . length ? out : null ; <nl> + } <nl> + <nl> + function getOldSpans ( doc , change ) { <nl> + var found = change [ " spans_ " + doc . id ] ; <nl> + if ( ! found ) return null ; <nl> + for ( var i = 0 , nw = [ ] ; i < change . text . length ; + + i ) <nl> + nw . push ( removeClearedSpans ( found [ i ] ) ) ; <nl> + return nw ; <nl> + } <nl> + <nl> + / / Used both to provide a JSON - safe object in . getHistory , and , when <nl> + / / detaching a document , to split the history in two <nl> + function copyHistoryArray ( events , newGroup ) { <nl> + for ( var i = 0 , copy = [ ] ; i < events . length ; + + i ) { <nl> + var event = events [ i ] , changes = event . changes , newChanges = [ ] ; <nl> + copy . push ( { changes : newChanges , anchorBefore : event . anchorBefore , headBefore : event . headBefore , <nl> + anchorAfter : event . anchorAfter , headAfter : event . headAfter } ) ; <nl> + for ( var j = 0 ; j < changes . length ; + + j ) { <nl> + var change = changes [ j ] , m ; <nl> + newChanges . push ( { from : change . from , to : change . to , text : change . text } ) ; <nl> + if ( newGroup ) for ( var prop in change ) if ( m = prop . match ( / ^ spans_ ( \ d + ) $ / ) ) { <nl> + if ( indexOf ( newGroup , Number ( m [ 1 ] ) ) > - 1 ) { <nl> + lst ( newChanges ) [ prop ] = change [ prop ] ; <nl> + delete change [ prop ] ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> + return copy ; <nl> + } <nl> + <nl> + / / Rebasing / resetting history to deal with externally - sourced changes <nl> + <nl> + function rebaseHistSel ( pos , from , to , diff ) { <nl> + if ( to < pos . line ) { <nl> + pos . line + = diff ; <nl> + } else if ( from < pos . line ) { <nl> + pos . line = from ; <nl> + pos . ch = 0 ; <nl> + } <nl> + } <nl> + <nl> + / / Tries to rebase an array of history events given a change in the <nl> + / / document . If the change touches the same lines as the event , the <nl> + / / event , and everything ' behind ' it , is discarded . If the change is <nl> + / / before the event , the event ' s positions are updated . Uses a <nl> + / / copy - on - write scheme for the positions , to avoid having to <nl> + / / reallocate them all on every rebase , but also avoid problems with <nl> + / / shared position objects being unsafely updated . <nl> + function rebaseHistArray ( array , from , to , diff ) { <nl> + for ( var i = 0 ; i < array . length ; + + i ) { <nl> + var sub = array [ i ] , ok = true ; <nl> + for ( var j = 0 ; j < sub . changes . length ; + + j ) { <nl> + var cur = sub . changes [ j ] ; <nl> + if ( ! sub . copied ) { cur . from = copyPos ( cur . from ) ; cur . to = copyPos ( cur . to ) ; } <nl> + if ( to < cur . from . line ) { <nl> + cur . from . line + = diff ; <nl> + cur . to . line + = diff ; <nl> + } else if ( from < = cur . to . line ) { <nl> + ok = false ; <nl> + break ; <nl> + } <nl> + } <nl> + if ( ! sub . copied ) { <nl> + sub . anchorBefore = copyPos ( sub . anchorBefore ) ; sub . headBefore = copyPos ( sub . headBefore ) ; <nl> + sub . anchorAfter = copyPos ( sub . anchorAfter ) ; sub . readAfter = copyPos ( sub . headAfter ) ; <nl> + sub . copied = true ; <nl> + } <nl> + if ( ! ok ) { <nl> + array . splice ( 0 , i + 1 ) ; <nl> + i = 0 ; <nl> + } else { <nl> + rebaseHistSel ( sub . anchorBefore ) ; rebaseHistSel ( sub . headBefore ) ; <nl> + rebaseHistSel ( sub . anchorAfter ) ; rebaseHistSel ( sub . headAfter ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + function rebaseHist ( hist , change ) { <nl> + var from = change . from . line , to = change . to . line , diff = change . text . length - ( to - from ) - 1 ; <nl> + rebaseHistArray ( hist . done , from , to , diff ) ; <nl> + rebaseHistArray ( hist . undone , from , to , diff ) ; <nl> } <nl> <nl> / / EVENT OPERATORS <nl> window . CodeMirror = ( function ( ) { <nl> return b ; <nl> } <nl> <nl> - / / Allow 3rd - party code to override event properties by adding an override <nl> - / / object to an event object . <nl> - function e_prop ( e , prop ) { <nl> - var overridden = e . override & & e . override . hasOwnProperty ( prop ) ; <nl> - return overridden ? e . override [ prop ] : e [ prop ] ; <nl> - } <nl> - <nl> / / EVENT HANDLING <nl> <nl> function on ( emitter , type , f ) { <nl> window . CodeMirror = ( function ( ) { <nl> for ( var i = 0 ; i < arr . length ; + + i ) arr [ i ] . apply ( null , args ) ; <nl> } <nl> <nl> - function signalLater ( cm , emitter , type / * , values . . . * / ) { <nl> + var delayedCallbacks , delayedCallbackDepth = 0 ; <nl> + function signalLater ( emitter , type / * , values . . . * / ) { <nl> var arr = emitter . _handlers & & emitter . _handlers [ type ] ; <nl> if ( ! arr ) return ; <nl> - var args = Array . prototype . slice . call ( arguments , 3 ) , flist = cm . curOp & & cm . curOp . delayedCallbacks ; <nl> + var args = Array . prototype . slice . call ( arguments , 2 ) ; <nl> + if ( ! delayedCallbacks ) { <nl> + + + delayedCallbackDepth ; <nl> + delayedCallbacks = [ ] ; <nl> + setTimeout ( fireDelayed , 0 ) ; <nl> + } <nl> function bnd ( f ) { return function ( ) { f . apply ( null , args ) ; } ; } ; <nl> for ( var i = 0 ; i < arr . length ; + + i ) <nl> - if ( flist ) flist . push ( bnd ( arr [ i ] ) ) ; <nl> - else arr [ i ] . apply ( null , args ) ; <nl> + delayedCallbacks . push ( bnd ( arr [ i ] ) ) ; <nl> + } <nl> + <nl> + function fireDelayed ( ) { <nl> + - - delayedCallbackDepth ; <nl> + var delayed = delayedCallbacks ; <nl> + delayedCallbacks = null ; <nl> + for ( var i = 0 ; i < delayed . length ; + + i ) delayed [ i ] ( ) ; <nl> } <nl> <nl> function hasHandler ( emitter , type ) { <nl> window . CodeMirror = ( function ( ) { <nl> <nl> / / Counts the column offset in a string , taking tabs into account . <nl> / / Used mostly to find indentation . <nl> - function countColumn ( string , end , tabSize ) { <nl> + function countColumn ( string , end , tabSize , startIndex , startValue ) { <nl> if ( end = = null ) { <nl> end = string . search ( / [ ^ \ s \ u00a0 ] / ) ; <nl> if ( end = = - 1 ) end = string . length ; <nl> } <nl> - for ( var i = 0 , n = 0 ; i < end ; + + i ) { <nl> + for ( var i = startIndex | | 0 , n = startValue | | 0 ; i < end ; + + i ) { <nl> if ( string . charAt ( i ) = = " \ t " ) n + = tabSize - ( n % tabSize ) ; <nl> else + + n ; <nl> } <nl> window . CodeMirror = ( function ( ) { <nl> return - 1 ; <nl> } <nl> <nl> + function createObj ( base , props ) { <nl> + function Obj ( ) { } <nl> + Obj . prototype = base ; <nl> + var inst = new Obj ( ) ; <nl> + if ( props ) copyObj ( props , inst ) ; <nl> + return inst ; <nl> + } <nl> + <nl> + function copyObj ( obj , target ) { <nl> + if ( ! target ) target = { } ; <nl> + for ( var prop in obj ) if ( obj . hasOwnProperty ( prop ) ) target [ prop ] = obj [ prop ] ; <nl> + return target ; <nl> + } <nl> + <nl> function emptyArray ( size ) { <nl> for ( var a = [ ] , i = 0 ; i < size ; + + i ) a . push ( undefined ) ; <nl> return a ; <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> <nl> function isEmpty ( obj ) { <nl> - var c = 0 ; <nl> - for ( var n in obj ) if ( obj . hasOwnProperty ( n ) & & obj [ n ] ) + + c ; <nl> - return ! c ; <nl> + for ( var n in obj ) if ( obj . hasOwnProperty ( n ) & & obj [ n ] ) return false ; <nl> + return true ; <nl> } <nl> <nl> - var isExtendingChar = / [ \ u0300 - \ u036F \ u0483 - \ u0487 \ u0488 - \ u0489 \ u0591 - \ u05BD \ u05BF \ u05C1 - \ u05C2 \ u05C4 - \ u05C5 \ u05C7 \ u0610 - \ u061A \ u064B - \ u065F \ u0670 \ u06D6 - \ u06DC \ u06DF - \ u06E4 \ u06E7 - \ u06E8 \ u06EA - \ u06ED \ uA66F \ uA670 - \ uA672 \ uA674 - \ uA67D \ uA69F ] / ; <nl> + var isExtendingChar = / [ \ u0300 - \ u036F \ u0483 - \ u0487 \ u0488 - \ u0489 \ u0591 - \ u05BD \ u05BF \ u05C1 - \ u05C2 \ u05C4 - \ u05C5 \ u05C7 \ u0610 - \ u061A \ u064B - \ u065F \ u0670 \ u06D6 - \ u06DC \ u06DF - \ u06E4 \ u06E7 - \ u06E8 \ u06EA - \ u06ED \ uA66F \ uA670 - \ uA672 \ uA674 - \ uA67D \ uA69F \ udc00 - \ udfff ] / ; <nl> <nl> / / DOM UTILITIES <nl> <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> <nl> function removeChildren ( e ) { <nl> - / / IE will break all parent - child relations in subnodes when setting innerHTML <nl> - if ( ! ie ) e . innerHTML = " " ; <nl> - else while ( e . firstChild ) e . removeChild ( e . firstChild ) ; <nl> + for ( var count = e . childNodes . length ; count > 0 ; - - count ) <nl> + e . removeChild ( e . firstChild ) ; <nl> return e ; <nl> } <nl> <nl> window . CodeMirror = ( function ( ) { <nl> } else e . textContent = str ; <nl> } <nl> <nl> + function getRect ( node ) { <nl> + return node . getBoundingClientRect ( ) ; <nl> + } <nl> + CodeMirror . replaceGetRect = function ( f ) { getRect = f ; } ; <nl> + <nl> / / FEATURE DETECTION <nl> <nl> / / Detect drag - and - drop <nl> window . CodeMirror = ( function ( ) { <nl> / / various browsers . <nl> var spanAffectsWrapping = / ^ $ / ; / / Won ' t match any two - character string <nl> if ( gecko ) spanAffectsWrapping = / $ ' / ; <nl> - else if ( safari ) spanAffectsWrapping = / \ - [ ^ \ - ? ] | \ ? [ ^ ! ' \ " \ ) , . \ - \ / : ; \ ? \ ] \ } ] / ; <nl> - else if ( chrome ) spanAffectsWrapping = / \ - [ ^ \ - \ . ? ] | \ ? [ ^ \ - \ . ? \ ] \ } : ; ! ' \ " \ ) , \ / ] | [ \ . ! \ " # & % \ ) * + , : ; = > \ ] | \ } ~ ] [ \ ( \ { \ [ < ] | \ $ ' / ; <nl> + else if ( safari & & ! / Version \ / ( [ 6 - 9 ] | \ d \ d ) \ b / . test ( navigator . userAgent ) ) spanAffectsWrapping = / \ - [ ^ \ - ? ] | \ ? [ ^ ! ' \ " \ ) , . \ - \ / : ; \ ? \ ] \ } ] / ; <nl> + else if ( webkit ) spanAffectsWrapping = / [ ~ ! # % & * ) = + } \ ] | \ " \ . > , : ; ] [ ( { [ < ] | - [ ^ \ - ? \ . ] | \ ? [ \ w ~ ` @ # $ % \ ^ & * ( _ = + { [ | > < ] / ; <nl> <nl> var knownScrollbarWidth ; <nl> function scrollbarWidth ( measure ) { <nl> window . CodeMirror = ( function ( ) { <nl> } <nl> <nl> function lineStart ( cm , lineN ) { <nl> - var line = getLine ( cm . view . doc , lineN ) ; <nl> - var visual = visualLine ( cm . view . doc , line ) ; <nl> + var line = getLine ( cm . doc , lineN ) ; <nl> + var visual = visualLine ( cm . doc , line ) ; <nl> if ( visual ! = line ) lineN = lineNo ( visual ) ; <nl> var order = getOrder ( visual ) ; <nl> var ch = ! order ? 0 : order [ 0 ] . level % 2 ? lineRight ( visual ) : lineLeft ( visual ) ; <nl> - return { line : lineN , ch : ch } ; <nl> + return Pos ( lineN , ch ) ; <nl> } <nl> - function lineEnd ( cm , lineNo ) { <nl> + function lineEnd ( cm , lineN ) { <nl> var merged , line ; <nl> - while ( merged = collapsedSpanAtEnd ( line = getLine ( cm . view . doc , lineNo ) ) ) <nl> - lineNo = merged . find ( ) . to . line ; <nl> + while ( merged = collapsedSpanAtEnd ( line = getLine ( cm . doc , lineN ) ) ) <nl> + lineN = merged . find ( ) . to . line ; <nl> var order = getOrder ( line ) ; <nl> var ch = ! order ? line . text . length : order [ 0 ] . level % 2 ? lineLeft ( line ) : lineRight ( line ) ; <nl> - return { line : lineNo , ch : ch } ; <nl> + return Pos ( lineN , ch ) ; <nl> } <nl> <nl> / / This is somewhat involved . It is needed in order to move <nl> window . CodeMirror = ( function ( ) { <nl> / / Browsers seem to always treat the boundaries of block elements as being L . <nl> var outerType = " L " ; <nl> <nl> - return function charOrdering ( str ) { <nl> + return function ( str ) { <nl> if ( ! bidiRE . test ( str ) ) return false ; <nl> var len = str . length , types = [ ] ; <nl> for ( var i = 0 , type ; i < len ; + + i ) <nl> window . CodeMirror = ( function ( ) { <nl> <nl> / / THE END <nl> <nl> - CodeMirror . version = " 3 . 02 " ; <nl> + CodeMirror . version = " 3 . 11 " ; <nl> <nl> return CodeMirror ; <nl> } ) ( ) ; <nl> mmm a / admin / static / js / codemirror / matchbrackets . js <nl> ppp b / admin / static / js / codemirror / matchbrackets . js <nl> <nl> ( function ( ) { <nl> + var ie_lt8 = / MSIE \ d / . test ( navigator . userAgent ) & & <nl> + ( document . documentMode = = null | | document . documentMode < 8 ) ; <nl> + <nl> + var Pos = CodeMirror . Pos ; <nl> + / / Disable brace matching in long lines , since it ' ll cause hugely slow updates <nl> + var maxLineLen = 1000 ; <nl> + <nl> var matching = { " ( " : " ) > " , " ) " : " ( < " , " [ " : " ] > " , " ] " : " [ < " , " { " : " } > " , " } " : " { < " } ; <nl> function findMatchingBracket ( cm ) { <nl> var cur = cm . getCursor ( ) , line = cm . getLineHandle ( cur . line ) , pos = cur . ch - 1 ; <nl> var match = ( pos > = 0 & & matching [ line . text . charAt ( pos ) ] ) | | matching [ line . text . charAt ( + + pos ) ] ; <nl> if ( ! match ) return null ; <nl> var forward = match . charAt ( 1 ) = = " > " , d = forward ? 1 : - 1 ; <nl> - var style = cm . getTokenAt ( { line : cur . line , ch : pos + 1 } ) . type ; <nl> + var style = cm . getTokenAt ( Pos ( cur . line , pos + 1 ) ) . type ; <nl> <nl> var stack = [ line . text . charAt ( pos ) ] , re = / [ ( ) { } [ \ ] ] / ; <nl> function scan ( line , lineNo , start ) { <nl> <nl> if ( start ! = null ) pos = start + d ; <nl> for ( ; pos ! = end ; pos + = d ) { <nl> var ch = line . text . charAt ( pos ) ; <nl> - if ( re . test ( ch ) & & cm . getTokenAt ( { line : lineNo , ch : pos + 1 } ) . type = = style ) { <nl> + if ( re . test ( ch ) & & cm . getTokenAt ( Pos ( lineNo , pos + 1 ) ) . type = = style ) { <nl> var match = matching [ ch ] ; <nl> if ( match . charAt ( 1 ) = = " > " = = forward ) stack . push ( ch ) ; <nl> else if ( stack . pop ( ) ! = match . charAt ( 0 ) ) return { pos : pos , match : false } ; <nl> <nl> else found = scan ( cm . getLineHandle ( i ) , i ) ; <nl> if ( found ) break ; <nl> } <nl> - return { from : { line : cur . line , ch : pos } , to : found & & { line : i , ch : found . pos } , match : found & & found . match } ; <nl> + return { from : Pos ( cur . line , pos ) , to : found & & Pos ( i , found . pos ) , match : found & & found . match } ; <nl> } <nl> <nl> function matchBrackets ( cm , autoclear ) { <nl> var found = findMatchingBracket ( cm ) ; <nl> - if ( ! found ) return ; <nl> + if ( ! found | | cm . getLine ( found . from . line ) . length > maxLineLen | | <nl> + found . to & & cm . getLine ( found . to . line ) . length > maxLineLen ) <nl> + return ; <nl> + <nl> var style = found . match ? " CodeMirror - matchingbracket " : " CodeMirror - nonmatchingbracket " ; <nl> - var one = cm . markText ( found . from , { line : found . from . line , ch : found . from . ch + 1 } , <nl> - { className : style } ) ; <nl> - var two = found . to & & cm . markText ( found . to , { line : found . to . line , ch : found . to . ch + 1 } , <nl> - { className : style } ) ; <nl> + var one = cm . markText ( found . from , Pos ( found . from . line , found . from . ch + 1 ) , { className : style } ) ; <nl> + var two = found . to & & cm . markText ( found . to , Pos ( found . to . line , found . to . ch + 1 ) , { className : style } ) ; <nl> + / / Kludge to work around the IE bug from issue # 1193 , where text <nl> + / / input stops going to the textare whever this fires . <nl> + if ( ie_lt8 & & cm . state . focused ) cm . display . input . focus ( ) ; <nl> var clear = function ( ) { <nl> cm . operation ( function ( ) { one . clear ( ) ; two & & two . clear ( ) ; } ) ; <nl> } ; <nl>
Update codemirror
rethinkdb/rethinkdb
c525ce2f9ccc7a27265782147b8826916ee2b868
2013-03-29T21:51:54Z
mmm a / dlib / svm / structural_svm_object_detection_problem . h <nl> ppp b / dlib / svm / structural_svm_object_detection_problem . h <nl> namespace dlib <nl> / / detections we will consider . We do this purely for computational reasons <nl> / / since otherwise we can end up wasting large amounts of time on certain <nl> / / pathological cases during optimization which ultimately do not influence the <nl> - / / result . Therefore , we for the separation oracle to only consider the <nl> + / / result . Therefore , we force the separation oracle to only consider the <nl> / / max_num_dets strongest detections . <nl> max_num_dets = 0 ; <nl> for ( unsigned long i = 0 ; i < truth_object_detections . size ( ) ; + + i ) <nl>
fixed grammar in comment
davisking/dlib
088ab2e1a0744815eea79e511211714ba4398be8
2013-10-16T23:15:26Z
mmm a / src / test / fuzz / deserialize . cpp <nl> ppp b / src / test / fuzz / deserialize . cpp <nl> void test_one_input ( const std : : vector < uint8_t > & buffer ) <nl> AssertEqualAfterSerializeDeserialize ( s ) ; <nl> } <nl> AssertEqualAfterSerializeDeserialize ( s , INIT_PROTO_VERSION | ADDRV2_FORMAT ) ; <nl> + CService s1 ; <nl> + DeserializeFromFuzzingInput ( buffer , s1 , INIT_PROTO_VERSION ) ; <nl> + AssertEqualAfterSerializeDeserialize ( s1 , INIT_PROTO_VERSION ) ; <nl> + assert ( s1 . IsAddrV1Compatible ( ) ) ; <nl> + CService s2 ; <nl> + DeserializeFromFuzzingInput ( buffer , s2 , INIT_PROTO_VERSION | ADDRV2_FORMAT ) ; <nl> + AssertEqualAfterSerializeDeserialize ( s2 , INIT_PROTO_VERSION | ADDRV2_FORMAT ) ; <nl> # elif MESSAGEHEADER_DESERIALIZE <nl> CMessageHeader mh ; <nl> DeserializeFromFuzzingInput ( buffer , mh ) ; <nl>
fuzz : Assert roundtrip equality for both addrv1 and addrv2 versions of CService
bitcoin/bitcoin
79b8f8d5749fc676d9eeca0296172b7cdbbf2238
2020-11-09T15:29:15Z
mmm a / src / mongo / db / repl / rs_rollback . cpp <nl> ppp b / src / mongo / db / repl / rs_rollback . cpp <nl> namespace mongo { <nl> <nl> class rsfatal : public std : : exception { <nl> public : <nl> - virtual const char * what ( ) const throw ( ) { return " replica set fatal exception " ; } <nl> + rsfatal ( const char * m = " replica set fatal exception " ) { <nl> + msg = m ; <nl> + } <nl> + virtual const char * what ( ) const throw ( ) { return msg ; } <nl> + private : <nl> + const char * msg ; <nl> } ; <nl> <nl> struct DocID { <nl> namespace mongo { <nl> log ( ) < < " replSet info rollback diff in end of log times : " < < diff < < " seconds " < < rsLog ; <nl> if ( diff > 1800 ) { <nl> log ( ) < < " replSet rollback too long a time period for a rollback . " < < rsLog ; <nl> - throw " error not willing to roll back more than 30 minutes of data " ; <nl> + throw rsfatal ( " rollback error : not willing to roll back more than 30 minutes of data " ) ; <nl> } <nl> } <nl> <nl> namespace mongo { <nl> sethbmsg ( string ( " rollback 2 error " ) + p ) ; <nl> return 10 ; <nl> } <nl> - catch ( rsfatal & ) { <nl> + catch ( rsfatal & e ) { <nl> + sethbmsg ( string ( e . what ( ) ) ) ; <nl> _fatal ( ) ; <nl> return 2 ; <nl> } <nl> mmm a / src / mongo / db / repl / rs_sync . cpp <nl> ppp b / src / mongo / db / repl / rs_sync . cpp <nl> namespace replset { <nl> lock rsLock ( this ) ; <nl> Lock : : GlobalWrite writeLock ; <nl> <nl> - / / make sure we ' re not primary , secondary , or fatal already <nl> - if ( box . getState ( ) . primary ( ) | | box . getState ( ) . secondary ( ) | | box . getState ( ) . fatal ( ) ) { <nl> + / / make sure we ' re not primary , secondary , rollback , or fatal already <nl> + if ( box . getState ( ) . primary ( ) | | box . getState ( ) . secondary ( ) | | <nl> + box . getState ( ) . rollback ( ) | | box . getState ( ) . fatal ( ) ) { <nl> return false ; <nl> } <nl> <nl>
SERVER - 9481 Fixes fluctuating between ROLLBACK and SECONDARY when ROLLBACK is impossible
mongodb/mongo
e3097872b5837e31179702f1009a976656f8af76
2013-06-12T15:37:41Z
mmm a / tensorflow / python / ops / lookup_ops . py <nl> ppp b / tensorflow / python / ops / lookup_ops . py <nl> def initialize ( self ) : <nl> def initializer ( self ) : <nl> return self . _init_op <nl> <nl> + @ property <nl> + @ deprecated ( " 2018 - 12 - 15 " , " Use ` initializer ` instead . " ) <nl> + def init ( self ) : <nl> + return self . initializer <nl> + <nl> @ property <nl> def default_value ( self ) : <nl> " " " The default value of the table . " " " <nl> def initializer ( self ) : <nl> with ops . name_scope ( None , " init " ) : <nl> return control_flow_ops . no_op ( ) <nl> <nl> + @ property <nl> + @ deprecated ( " 2018 - 12 - 15 " , " Use ` initializer ` instead . " ) <nl> + def init ( self ) : <nl> + return self . initializer <nl> + <nl> @ property <nl> def resource_handle ( self ) : <nl> if self . _table is not None : <nl>
Keeping the init ( ) method on InitializableLookupTableBase intact but adding a deprecation notice instead .
tensorflow/tensorflow
6dc0f05f84d7a6e03856f9d83fa39d5126052820
2018-11-05T18:49:58Z
mmm a / include / swift / AST / DiagnosticsClangImporter . def <nl> ppp b / include / swift / AST / DiagnosticsClangImporter . def <nl> WARNING ( clang_vfs_overlay_is_ignored , none , <nl> # undef NOTE <nl> # undef WARNING <nl> # undef ERROR <nl> + # undef REMARK <nl> # endif <nl>
Merge pull request from vguerra / SR - 10915
apple/swift
896d53da554662cdda364f7235535c50d45e6fa1
2019-06-19T20:24:59Z
new file mode 100644 <nl> index 000000000000 . . 00b6216af7c8 <nl> mmm / dev / null <nl> ppp b / utils / benchmark / Ackermann . cpp <nl> <nl> + / / - * - mode : c + + - * - <nl> + / / $ Id : ackermann . g + + , v 1 . 3 2001 / 06 / 20 03 : 20 : 02 doug Exp $ <nl> + / / http : / / www . bagley . org / ~ doug / shootout / <nl> + <nl> + # include < iostream > <nl> + # include < stdlib . h > <nl> + <nl> + using namespace std ; <nl> + <nl> + int Ack ( int M , int N ) { <nl> + if ( M = = 0 ) return ( N + 1 ) ; <nl> + if ( N = = 0 ) return ( Ack ( M - 1 , 1 ) ) ; <nl> + return ( Ack ( M - 1 , Ack ( M , ( N - 1 ) ) ) ) ; <nl> + } <nl> + <nl> + int main ( int argc , char * argv [ ] ) { <nl> + int n = 13 ; <nl> + <nl> + cout < < " Ack ( 3 , " < < n < < " ) : " < < Ack ( 3 , n ) < < endl ; <nl> + return ( 0 ) ; <nl> + } <nl> new file mode 100644 <nl> index 000000000000 . . a4a998c276d0 <nl> mmm / dev / null <nl> ppp b / utils / benchmark / ObjInst . cpp <nl> <nl> + class Toggle { <nl> + public : <nl> + bool state = true ; <nl> + Toggle ( bool start_state ) { <nl> + state = start_state ; <nl> + } <nl> + <nl> + bool value ( ) { <nl> + return state ; <nl> + } <nl> + <nl> + Toggle * activate ( ) { <nl> + state = ! state ; <nl> + return this ; <nl> + } <nl> + } ; <nl> + <nl> + class NthToggle : Toggle { <nl> + public : <nl> + int count_max ; <nl> + int counter ; <nl> + <nl> + NthToggle ( bool start_state , int max_counter ) : Toggle ( start_state ) { <nl> + count_max = max_counter ; <nl> + counter = 0 ; <nl> + } <nl> + NthToggle * activate ( ) { <nl> + counter + = 1 ; <nl> + if ( counter > = count_max ) { <nl> + state = ! state ; <nl> + counter = 0 ; <nl> + } <nl> + return this ; <nl> + } <nl> + } ; <nl> + <nl> + int main ( ) { <nl> + int n = 100000000 ; <nl> + <nl> + Toggle * toggle1 = new Toggle ( true ) ; <nl> + / / for ( int i = 0 ; i < 5 ; i + + ) { <nl> + / / Console . WriteLine ( ( toggle1 . activate ( ) . value ( ) ) ? " true " : " false " ) ; <nl> + / / } <nl> + <nl> + for ( int i = 0 ; i < n ; i + + ) { <nl> + Toggle * toggle = new Toggle ( true ) ; <nl> + delete toggle ; <nl> + } <nl> + / / Console . WriteLine ( ) ; <nl> + <nl> + <nl> + / / NthToggle ntoggle1 = new NthToggle ( true , 3 ) ; <nl> + / / for ( int i = 0 ; i < 8 ; i + + ) { <nl> + / / Console . WriteLine ( ( ntoggle1 . activate ( ) . value ( ) ) ? " true " : " false " ) ; <nl> + / / } <nl> + for ( int i = 0 ; i < n ; i + + ) { <nl> + NthToggle * toggle = new NthToggle ( true , 3 ) ; <nl> + delete toggle ; <nl> + } <nl> + return ( 0 ) ; <nl> + } <nl> new file mode 100644 <nl> index 000000000000 . . 1018ba785338 <nl> mmm / dev / null <nl> ppp b / utils / benchmark / RC4 . cpp <nl> <nl> + # include < vector > <nl> + # include < iostream > <nl> + <nl> + struct RC4 { <nl> + std : : vector < uint8_t > State ; <nl> + int I ; <nl> + int J ; <nl> + <nl> + RC4 ( ) { I = 0 ; J = 0 ; } <nl> + <nl> + void initialize ( std : : vector < uint8_t > & Key ) { <nl> + State . clear ( ) ; <nl> + for ( int i = 0 ; i < 256 ; i + + ) <nl> + State . push_back ( i ) ; <nl> + <nl> + int j = 0 ; <nl> + for ( int i = 0 ; i < 256 ; i + + ) { <nl> + uint8_t K = Key [ i % Key . size ( ) ] ; <nl> + uint8_t S = State [ i ] ; <nl> + j = ( j + S + K ) % 256 ; <nl> + swapByIndex ( i , j ) ; <nl> + } <nl> + } <nl> + <nl> + void swapByIndex ( int x , int y ) { <nl> + uint8_t T1 = State [ x ] ; <nl> + uint8_t T2 = State [ y ] ; <nl> + State [ x ] = T2 ; <nl> + State [ y ] = T1 ; <nl> + } <nl> + <nl> + uint8_t next ( ) { <nl> + I = ( I + 1 ) % 256 ; <nl> + J = ( J + State [ I ] ) % 256 ; <nl> + swapByIndex ( I , J ) ; <nl> + return State [ ( State [ I ] + State [ J ] ) & 0xFF ] ; <nl> + } <nl> + <nl> + void encrypt ( std : : vector < uint8_t > & Data ) { <nl> + int cnt = Data . size ( ) ; <nl> + for ( int i = 0 ; i < cnt ; i + + ) <nl> + Data [ i ] = Data [ i ] ^ next ( ) ; <nl> + } <nl> + } ; <nl> + <nl> + void benchRC4 ( int messageLen , int iterations , bool validate ) { <nl> + char * Secret = " This is my secret message " ; <nl> + char * Key = " This is my key " ; <nl> + <nl> + std : : vector < uint8_t > SecretData ( & Secret [ 0 ] , & Secret [ strlen ( Secret ) ] ) ; <nl> + std : : vector < uint8_t > KeyData ( & Key [ 0 ] , & Key [ strlen ( Key ) ] ) ; <nl> + <nl> + std : : vector < uint8_t > LongData ( messageLen , 0 ) ; <nl> + <nl> + std : : cout < < " Generating data . . . " < < std : : endl ; <nl> + <nl> + for ( int i = 0 ; i < messageLen ; i + + ) <nl> + LongData [ i ] = SecretData [ i % SecretData . size ( ) ] ; <nl> + <nl> + RC4 Enc ; <nl> + RC4 Dec ; <nl> + Enc . initialize ( KeyData ) ; <nl> + Dec . initialize ( KeyData ) ; <nl> + <nl> + std : : cout < < " Starting benchmark . . . " < < std : : endl ; <nl> + for ( int i = 0 ; i < iterations ; i + + ) { <nl> + Enc . encrypt ( LongData ) ; <nl> + Dec . encrypt ( LongData ) ; <nl> + } <nl> + <nl> + if ( validate ) { <nl> + std : : cout < < " Validating . . . " < < std : : endl ; <nl> + for ( int i = 0 ; i < messageLen ; i + + ) <nl> + if ( LongData [ i ] ! = SecretData [ i % SecretData . size ( ) ] ) { <nl> + std : : cout < < " Error at " < < i < < " ! ! ! " < < std : : endl ; <nl> + } <nl> + } <nl> + std : : cout < < " done " < < std : : endl ; <nl> + } <nl> + <nl> + int main ( ) { <nl> + benchRC4 ( 5000 , 2000 , false ) ; <nl> + } <nl>
Add the CPP reference files for our benchmarkes .
apple/swift
a68a5f7f5153ae333514a5c2e5a34da3fc697e5e
2014-01-17T21:56:51Z
mmm a / hphp / hhbbc / bc . h <nl> ppp b / hphp / hhbbc / bc . h <nl> <nl> # include < utility > <nl> # include < type_traits > <nl> <nl> - # include < boost / mpl / has_xxx . hpp > <nl> # include < algorithm > <nl> <nl> # include < folly / Hash . h > <nl> template < class T > Bytecode bc_with_loc ( int32_t loc , const T & t ) { <nl> * boost : : apply_visitor or match ( ) . <nl> * <nl> * The ` v ' argument should be a function object that accepts a call <nl> - * operator for all the bc : : Foo types , with a nested member typedef <nl> - * called result_type that indicates the return type of the call . <nl> + * operator for all the bc : : Foo types . Its result type should be <nl> + * independent of bytecode , but may vary with constness . <nl> * / <nl> template < class Visit > <nl> - typename Visit : : result_type visit ( Bytecode & b , Visit v ) { <nl> + auto visit ( Bytecode & b , Visit v ) { <nl> # define O ( opcode , . . . ) case Op : : opcode : return v ( b . opcode ) ; <nl> switch ( b . op ) { OPCODES } <nl> # undef O <nl> typename Visit : : result_type visit ( Bytecode & b , Visit v ) { <nl> } <nl> <nl> template < class Visit > <nl> - typename Visit : : result_type visit ( const Bytecode & b , Visit v ) { <nl> + auto visit ( const Bytecode & b , Visit v ) { <nl> # define O ( opcode , . . . ) case Op : : opcode : return v ( b . opcode ) ; <nl> switch ( b . op ) { OPCODES } <nl> # undef O <nl> typename Visit : : result_type visit ( const Bytecode & b , Visit v ) { <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> <nl> - BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF ( has_car , has_car_flag , false ) ; <nl> - BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF ( has_caw , has_caw_flag , false ) ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - <nl> - struct ReadClsRefSlotVisitor : boost : : static_visitor < ClsRefSlotId > { <nl> + struct ReadClsRefSlotVisitor { <nl> ReadClsRefSlotVisitor ( ) { } <nl> <nl> - template < class T > <nl> - typename std : : enable_if < ! has_car < T > : : value , ClsRefSlotId > : : type <nl> - operator ( ) ( T const & / * t * / ) const { <nl> - return NoClsRefSlotId ; <nl> + template < typename T > <nl> + auto fun ( T & , int ) const { return NoClsRefSlotId ; } <nl> + <nl> + template < typename T > <nl> + auto fun ( T & t , bool ) const - > decltype ( typename T : : has_car_flag { } , t . slot ) { <nl> + return t . slot ; <nl> } <nl> <nl> - template < class T > <nl> - typename std : : enable_if < has_car < T > : : value , ClsRefSlotId > : : type <nl> - operator ( ) ( T const & t ) const { return t . slot ; } <nl> + template < typename T > <nl> + ClsRefSlotId operator ( ) ( T & t ) const { return fun ( t , true ) ; } <nl> } ; <nl> <nl> - struct WriteClsRefSlotVisitor : boost : : static_visitor < ClsRefSlotId > { <nl> - template < class T > <nl> - typename std : : enable_if < ! has_caw < T > : : value , ClsRefSlotId > : : type <nl> - operator ( ) ( T const & / * t * / ) const { <nl> - return NoClsRefSlotId ; <nl> + struct WriteClsRefSlotVisitor { <nl> + template < typename T > <nl> + auto fun ( T & , int ) const { return NoClsRefSlotId ; } <nl> + <nl> + template < typename T > <nl> + auto fun ( T & t , bool ) const - > decltype ( typename T : : has_caw_flag { } , t . slot ) { <nl> + return t . slot ; <nl> } <nl> <nl> - template < class T > <nl> - typename std : : enable_if < has_caw < T > : : value , ClsRefSlotId > : : type <nl> - operator ( ) ( T const & t ) const { return t . slot ; } <nl> + template < typename T > <nl> + ClsRefSlotId operator ( ) ( T & t ) const { return fun ( t , true ) ; } <nl> } ; <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> mmm a / hphp / hhbbc / dce . cpp <nl> ppp b / hphp / hhbbc / dce . cpp <nl> void dce ( Env & env , const bc : : AKExists & op ) { <nl> * / <nl> <nl> template < typename Op > <nl> - typename std : : enable_if < has_car < Op > : : value , void > : : type <nl> - dce_slot_default ( Env & env , const Op & op ) { <nl> + auto dce_slot_default ( Env & env , const Op & op , bool ) - > <nl> + decltype ( typename Op : : has_car_flag { } , void ( ) ) { <nl> readSlot ( env , op . slot ) ; <nl> } <nl> <nl> template < typename Op > <nl> - typename std : : enable_if < has_caw < Op > : : value , void > : : type <nl> - dce_slot_default ( Env & env , const Op & op ) { <nl> + auto dce_slot_default ( Env & env , const Op & op , bool ) - > <nl> + decltype ( typename Op : : has_caw_flag { } , void ( ) ) { <nl> writeSlot ( env , op . slot ) ; <nl> } <nl> <nl> template < typename Op > <nl> - typename std : : enable_if < ! has_car < Op > : : value & & ! has_caw < Op > : : value , void > : : type <nl> - dce_slot_default ( Env & / * env * / , const Op & / * op * / ) { } <nl> + void dce_slot_default ( Env & , const Op & , int ) { } <nl> <nl> template < class Op > <nl> void dce ( Env & env , const Op & op ) { <nl> addLocGenSet ( env , env . flags . mayReadLocalSet ) ; <nl> push_outputs ( env , op . numPush ( ) ) ; <nl> pop_inputs ( env , op . numPop ( ) ) ; <nl> - dce_slot_default ( env , op ) ; <nl> + dce_slot_default ( env , op , true ) ; <nl> } <nl> <nl> / * <nl> template < class Op > <nl> void minstr_final ( Env & env , const Op & op , int32_t ndiscard ) { <nl> addLocGenSet ( env , env . flags . mayReadLocalSet ) ; <nl> push_outputs ( env , op . numPush ( ) ) ; <nl> - dce_slot_default ( env , op ) ; <nl> + dce_slot_default ( env , op , true ) ; <nl> auto const numPop = op . numPop ( ) ; <nl> auto const stackRead = op . mkey . mcode = = MEC | | op . mkey . mcode = = MPC ? <nl> op . mkey . idx : numPop ; <nl> void remove_unused_locals ( Context const ctx , <nl> <nl> namespace { <nl> <nl> - struct WritableClsRefSlotVisitor : boost : : static_visitor < ClsRefSlotId * > { <nl> + struct WritableClsRefSlotVisitor { <nl> WritableClsRefSlotVisitor ( ) { } <nl> <nl> - template < class T > <nl> - typename std : : enable_if < ! has_car < T > : : value & & ! has_caw < T > : : value , <nl> - ClsRefSlotId * > : : type <nl> - operator ( ) ( T & / * t * / ) const { <nl> - return nullptr ; <nl> - } <nl> + template < typename T > <nl> + std : : nullptr_t fun ( T & , int ) const { return nullptr ; } <nl> + <nl> + template < typename T > <nl> + auto fun ( T & t , bool ) const - > decltype ( & t . slot ) { return & t . slot ; } <nl> + <nl> + template < typename T > <nl> + ClsRefSlotId * operator ( ) ( T & t ) const { return fun ( t , true ) ; } <nl> <nl> - template < class T > <nl> - typename std : : enable_if < <nl> - has_car < T > : : value | | has_caw < T > : : value , ClsRefSlotId * <nl> - > : : type <nl> - operator ( ) ( T & t ) const { return & t . slot ; } <nl> + template < typename T > <nl> + const ClsRefSlotId * operator ( ) ( const T & t ) const { return fun ( t , true ) ; } <nl> } ; <nl> <nl> } <nl>
Simplify ClsRefSlot visitors
facebook/hhvm
3b0c976af5618260f5c097e44c6f0abbd6b35970
2019-03-10T19:17:48Z
mmm a / templates / cocos2dx_files . json <nl> ppp b / templates / cocos2dx_files . json <nl> <nl> " cocos / ui / UIButton . h " , <nl> " cocos / ui / UICheckBox . cpp " , <nl> " cocos / ui / UICheckBox . h " , <nl> + " cocos / ui / UIDeprecated . h " , <nl> " cocos / ui / UIHBox . cpp " , <nl> " cocos / ui / UIHBox . h " , <nl> " cocos / ui / UIHelper . cpp " , <nl> <nl> " cocos / ui / UIImageView . h " , <nl> " cocos / ui / UILayout . cpp " , <nl> " cocos / ui / UILayout . h " , <nl> - " cocos / ui / UILayoutDefine . cpp " , <nl> - " cocos / ui / UILayoutDefine . h " , <nl> " cocos / ui / UILayoutParameter . cpp " , <nl> " cocos / ui / UILayoutParameter . h " , <nl> " cocos / ui / UIListView . cpp " , <nl>
Merge pull request from CocosRobot / update_cocosfiles_1399882304
cocos2d/cocos2d-x
2d468b055f87b4259a64d430bc07570ea209bab2
2014-05-12T08:29:32Z
mmm a / modules / imgproc / src / opencl / integral_sum . cl <nl> ppp b / modules / imgproc / src / opencl / integral_sum . cl <nl> <nl> # define GET_CONFLICT_OFFSET ( lid ) ( ( lid ) > > LOG_NUM_BANKS ) <nl> <nl> # if sdepth = = 4 <nl> + # define sumT int <nl> + # define vecSumT int4 <nl> + # define convertToSum4 convert_int4 <nl> + # elif sdepth = = 5 <nl> + # define sumT float <nl> + # define vecSumT float4 <nl> + # define convertToSum4 convert_float4 <nl> + # endif <nl> + <nl> <nl> - kernel void integral_sum_cols ( __global uchar4 * src , __global int * sum , <nl> - int src_offset , int pre_invalid , int rows , int cols , int src_step , int dst_step ) <nl> + kernel void integral_sum_cols ( __global const uchar4 * src , __global uchar * sum_ptr , <nl> + int src_offset , int rows , int cols , int src_step , int dst_step ) <nl> { <nl> + __global sumT * sum = ( __global sumT * ) sum_ptr ; <nl> int lid = get_local_id ( 0 ) ; <nl> int gid = get_group_id ( 0 ) ; <nl> - int4 src_t [ 2 ] , sum_t [ 2 ] ; <nl> - __local int4 lm_sum [ 2 ] [ LSIZE + LOG_LSIZE ] ; <nl> - __local int * sum_p ; <nl> + vecSumT src_t [ 2 ] , sum_t [ 2 ] ; <nl> + __local vecSumT lm_sum [ 2 ] [ LSIZE + LOG_LSIZE ] ; <nl> + __local sumT * sum_p ; <nl> src_step = src_step > > 2 ; <nl> gid = gid < < 1 ; <nl> - for ( int i = 0 ; i < rows ; i = i + LSIZE_1 ) <nl> + int lid_prim = ( ( lid & 127 ) < < 1 ) + 1 ; <nl> + for ( int i = 0 ; i < rows ; i + = LSIZE_1 ) <nl> { <nl> - src_t [ 0 ] = ( i + lid < rows ? convert_int4 ( src [ src_offset + ( lid + i ) * src_step + gid ] ) : 0 ) ; <nl> - src_t [ 1 ] = ( i + lid < rows ? convert_int4 ( src [ src_offset + ( lid + i ) * src_step + gid + 1 ] ) : 0 ) ; <nl> - <nl> - sum_t [ 0 ] = ( i = = 0 ? 0 : lm_sum [ 0 ] [ LSIZE_2 + LOG_LSIZE ] ) ; <nl> - sum_t [ 1 ] = ( i = = 0 ? 0 : lm_sum [ 1 ] [ LSIZE_2 + LOG_LSIZE ] ) ; <nl> - barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - <nl> - int bf_loc = lid + GET_CONFLICT_OFFSET ( lid ) ; <nl> - lm_sum [ 0 ] [ bf_loc ] = src_t [ 0 ] ; <nl> - <nl> - lm_sum [ 1 ] [ bf_loc ] = src_t [ 1 ] ; <nl> - <nl> - int offset = 1 ; <nl> - for ( int d = LSIZE > > 1 ; d > 0 ; d > > = 1 ) <nl> + if ( i + lid < rows ) <nl> { <nl> - barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - int ai = offset * ( ( ( lid & 127 ) < < 1 ) + 1 ) - 1 , bi = ai + offset ; <nl> - ai + = GET_CONFLICT_OFFSET ( ai ) ; <nl> - bi + = GET_CONFLICT_OFFSET ( bi ) ; <nl> - <nl> - if ( ( lid & 127 ) < d ) <nl> - { <nl> - lm_sum [ lid > > 7 ] [ bi ] + = lm_sum [ lid > > 7 ] [ ai ] ; <nl> - } <nl> - offset < < = 1 ; <nl> + int src_index = mad24 ( ( lid + i ) , src_step , gid + src_offset ) ; <nl> + src_t [ 0 ] = convertToSum4 ( src [ src_index ] ) ; <nl> + src_t [ 1 ] = convertToSum4 ( src [ src_index + 1 ] ) ; <nl> } <nl> - barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - if ( lid < 2 ) <nl> + else <nl> { <nl> - lm_sum [ lid ] [ LSIZE_2 + LOG_LSIZE ] = 0 ; <nl> + src_t [ 0 ] = ( vecSumT ) 0 ; <nl> + src_t [ 1 ] = ( vecSumT ) 0 ; <nl> } <nl> - for ( int d = 1 ; d < LSIZE ; d < < = 1 ) <nl> - { <nl> - barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - offset > > = 1 ; <nl> - int ai = offset * ( ( ( lid & 127 ) < < 1 ) + 1 ) - 1 , bi = ai + offset ; <nl> - ai + = GET_CONFLICT_OFFSET ( ai ) ; <nl> - bi + = GET_CONFLICT_OFFSET ( bi ) ; <nl> <nl> - if ( ( lid & 127 ) < d ) <nl> - { <nl> - lm_sum [ lid > > 7 ] [ bi ] + = lm_sum [ lid > > 7 ] [ ai ] ; <nl> - lm_sum [ lid > > 7 ] [ ai ] = lm_sum [ lid > > 7 ] [ bi ] - lm_sum [ lid > > 7 ] [ ai ] ; <nl> - } <nl> + if ( i = = 0 ) <nl> + { <nl> + sum_t [ 0 ] = ( vecSumT ) 0 ; <nl> + sum_t [ 1 ] = ( vecSumT ) 0 ; <nl> } <nl> - barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - if ( lid > 0 & & ( i + lid ) < = rows ) <nl> + else <nl> { <nl> - int loc_s0 = gid * dst_step + i + lid - 1 - pre_invalid * dst_step / 4 , loc_s1 = loc_s0 + dst_step ; <nl> - lm_sum [ 0 ] [ bf_loc ] + = sum_t [ 0 ] ; <nl> - lm_sum [ 1 ] [ bf_loc ] + = sum_t [ 1 ] ; <nl> - sum_p = ( __local int * ) ( & ( lm_sum [ 0 ] [ bf_loc ] ) ) ; <nl> - for ( int k = 0 ; k < 4 ; k + + ) <nl> - { <nl> - if ( gid * 4 + k > = cols + pre_invalid | | gid * 4 + k < pre_invalid ) continue ; <nl> - sum [ loc_s0 + k * dst_step / 4 ] = sum_p [ k ] ; <nl> - } <nl> - sum_p = ( __local int * ) ( & ( lm_sum [ 1 ] [ bf_loc ] ) ) ; <nl> - for ( int k = 0 ; k < 4 ; k + + ) <nl> - { <nl> - if ( gid * 4 + k + 4 > = cols + pre_invalid ) break ; <nl> - sum [ loc_s1 + k * dst_step / 4 ] = sum_p [ k ] ; <nl> - } <nl> + sum_t [ 0 ] = lm_sum [ 0 ] [ LSIZE_2 + LOG_LSIZE ] ; <nl> + sum_t [ 1 ] = lm_sum [ 1 ] [ LSIZE_2 + LOG_LSIZE ] ; <nl> } <nl> barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - } <nl> - } <nl> - <nl> - kernel void integral_sum_rows ( __global int4 * srcsum , __global int * sum , <nl> - int rows , int cols , int src_step , int sum_step , int sum_offset ) <nl> - { <nl> - int lid = get_local_id ( 0 ) ; <nl> - int gid = get_group_id ( 0 ) ; <nl> - int4 src_t [ 2 ] , sum_t [ 2 ] ; <nl> - __local int4 lm_sum [ 2 ] [ LSIZE + LOG_LSIZE ] ; <nl> - __local int * sum_p ; <nl> - src_step = src_step > > 4 ; <nl> - for ( int i = 0 ; i < rows ; i = i + LSIZE_1 ) <nl> - { <nl> - src_t [ 0 ] = i + lid < rows ? srcsum [ ( lid + i ) * src_step + gid * 2 ] : 0 ; <nl> - src_t [ 1 ] = i + lid < rows ? srcsum [ ( lid + i ) * src_step + gid * 2 + 1 ] : 0 ; <nl> - <nl> - sum_t [ 0 ] = ( i = = 0 ? 0 : lm_sum [ 0 ] [ LSIZE_2 + LOG_LSIZE ] ) ; <nl> - sum_t [ 1 ] = ( i = = 0 ? 0 : lm_sum [ 1 ] [ LSIZE_2 + LOG_LSIZE ] ) ; <nl> - barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> <nl> int bf_loc = lid + GET_CONFLICT_OFFSET ( lid ) ; <nl> - lm_sum [ 0 ] [ bf_loc ] = src_t [ 0 ] ; <nl> <nl> + lm_sum [ 0 ] [ bf_loc ] = src_t [ 0 ] ; <nl> lm_sum [ 1 ] [ bf_loc ] = src_t [ 1 ] ; <nl> <nl> int offset = 1 ; <nl> - for ( int d = LSIZE > > 1 ; d > 0 ; d > > = 1 ) <nl> + for ( int d = LSIZE > > 1 ; d > 0 ; d > > = 1 ) <nl> { <nl> barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - int ai = offset * ( ( ( lid & 127 ) < < 1 ) + 1 ) - 1 , bi = ai + offset ; <nl> + int ai = offset * lid_prim - 1 , bi = ai + offset ; <nl> ai + = GET_CONFLICT_OFFSET ( ai ) ; <nl> bi + = GET_CONFLICT_OFFSET ( bi ) ; <nl> <nl> kernel void integral_sum_rows ( __global int4 * srcsum , __global int * sum , <nl> offset < < = 1 ; <nl> } <nl> barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - if ( lid < 2 ) <nl> + if ( lid < 2 ) <nl> { <nl> lm_sum [ lid ] [ LSIZE_2 + LOG_LSIZE ] = 0 ; <nl> } <nl> - for ( int d = 1 ; d < LSIZE ; d < < = 1 ) <nl> + for ( int d = 1 ; d < LSIZE ; d < < = 1 ) <nl> { <nl> barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> offset > > = 1 ; <nl> - int ai = offset * ( ( ( lid & 127 ) < < 1 ) + 1 ) - 1 , bi = ai + offset ; <nl> + int ai = offset * lid_prim - 1 , bi = ai + offset ; <nl> ai + = GET_CONFLICT_OFFSET ( ai ) ; <nl> bi + = GET_CONFLICT_OFFSET ( bi ) ; <nl> <nl> kernel void integral_sum_rows ( __global int4 * srcsum , __global int * sum , <nl> } <nl> } <nl> barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - if ( gid = = 0 & & ( i + lid ) < = rows ) <nl> - { <nl> - sum [ sum_offset + i + lid ] = 0 ; <nl> - } <nl> - if ( i + lid = = 0 ) <nl> - { <nl> - int loc0 = gid * 2 * sum_step ; <nl> - for ( int k = 1 ; k < = 8 ; k + + ) <nl> - { <nl> - if ( gid * 8 + k > cols ) break ; <nl> - sum [ sum_offset + loc0 + k * sum_step / 4 ] = 0 ; <nl> - } <nl> - } <nl> - <nl> - if ( lid > 0 & & ( i + lid ) < = rows ) <nl> + if ( lid > 0 & & ( i + lid ) < = rows ) <nl> { <nl> - int loc_s0 = sum_offset + gid * 2 * sum_step + sum_step / 4 + i + lid , loc_s1 = loc_s0 + sum_step ; <nl> + int loc_s0 = mad24 ( gid , dst_step , i + lid - 1 ) , loc_s1 = loc_s0 + dst_step ; <nl> lm_sum [ 0 ] [ bf_loc ] + = sum_t [ 0 ] ; <nl> lm_sum [ 1 ] [ bf_loc ] + = sum_t [ 1 ] ; <nl> - sum_p = ( __local int * ) ( & ( lm_sum [ 0 ] [ bf_loc ] ) ) ; <nl> - for ( int k = 0 ; k < 4 ; k + + ) <nl> + sum_p = ( __local sumT * ) ( & ( lm_sum [ 0 ] [ bf_loc ] ) ) ; <nl> + for ( int k = 0 ; k < 4 ; k + + ) <nl> { <nl> - if ( gid * 8 + k > = cols ) break ; <nl> - sum [ loc_s0 + k * sum_step / 4 ] = sum_p [ k ] ; <nl> + if ( gid * 4 + k > = cols ) <nl> + break ; <nl> + sum [ loc_s0 + k * dst_step / 4 ] = sum_p [ k ] ; <nl> } <nl> - sum_p = ( __local int * ) ( & ( lm_sum [ 1 ] [ bf_loc ] ) ) ; <nl> - for ( int k = 0 ; k < 4 ; k + + ) <nl> + sum_p = ( __local sumT * ) ( & ( lm_sum [ 1 ] [ bf_loc ] ) ) ; <nl> + for ( int k = 0 ; k < 4 ; k + + ) <nl> { <nl> - if ( gid * 8 + 4 + k > = cols ) break ; <nl> - sum [ loc_s1 + k * sum_step / 4 ] = sum_p [ k ] ; <nl> + if ( gid * 4 + k + 4 > = cols ) <nl> + break ; <nl> + sum [ loc_s1 + k * dst_step / 4 ] = sum_p [ k ] ; <nl> } <nl> } <nl> barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> } <nl> } <nl> <nl> - # elif sdepth = = 5 <nl> <nl> - kernel void integral_sum_cols ( __global uchar4 * src , __global float * sum , <nl> - int src_offset , int pre_invalid , int rows , int cols , int src_step , int dst_step ) <nl> + kernel void integral_sum_rows ( __global const uchar * srcsum_ptr , __global uchar * sum_ptr , <nl> + int rows , int cols , int src_step , int sum_step , int sum_offset ) <nl> { <nl> + __global const vecSumT * srcsum = ( __global const vecSumT * ) srcsum_ptr ; <nl> + __global sumT * sum = ( __global sumT * ) sum_ptr ; <nl> int lid = get_local_id ( 0 ) ; <nl> int gid = get_group_id ( 0 ) ; <nl> - float4 src_t [ 2 ] , sum_t [ 2 ] ; <nl> - __local float4 lm_sum [ 2 ] [ LSIZE + LOG_LSIZE ] ; <nl> - __local float * sum_p ; <nl> - src_step = src_step > > 2 ; <nl> - gid = gid < < 1 ; <nl> - for ( int i = 0 ; i < rows ; i = i + LSIZE_1 ) <nl> + vecSumT src_t [ 2 ] , sum_t [ 2 ] ; <nl> + __local vecSumT lm_sum [ 2 ] [ LSIZE + LOG_LSIZE ] ; <nl> + __local sumT * sum_p ; <nl> + src_step = src_step > > 4 ; <nl> + int lid_prim = ( ( lid & 127 ) < < 1 ) + 1 ; <nl> + for ( int i = 0 ; i < rows ; i + = LSIZE_1 ) <nl> { <nl> - src_t [ 0 ] = ( i + lid < rows ? convert_float4 ( src [ src_offset + ( lid + i ) * src_step + gid ] ) : ( float4 ) 0 ) ; <nl> - src_t [ 1 ] = ( i + lid < rows ? convert_float4 ( src [ src_offset + ( lid + i ) * src_step + gid + 1 ] ) : ( float4 ) 0 ) ; <nl> - <nl> - sum_t [ 0 ] = ( i = = 0 ? ( float4 ) 0 : lm_sum [ 0 ] [ LSIZE_2 + LOG_LSIZE ] ) ; <nl> - sum_t [ 1 ] = ( i = = 0 ? ( float4 ) 0 : lm_sum [ 1 ] [ LSIZE_2 + LOG_LSIZE ] ) ; <nl> - barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - <nl> - int bf_loc = lid + GET_CONFLICT_OFFSET ( lid ) ; <nl> - lm_sum [ 0 ] [ bf_loc ] = src_t [ 0 ] ; <nl> - <nl> - lm_sum [ 1 ] [ bf_loc ] = src_t [ 1 ] ; <nl> - <nl> - int offset = 1 ; <nl> - for ( int d = LSIZE > > 1 ; d > 0 ; d > > = 1 ) <nl> + if ( i + lid < rows ) <nl> { <nl> - barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - int ai = offset * ( ( ( lid & 127 ) < < 1 ) + 1 ) - 1 , bi = ai + offset ; <nl> - ai + = GET_CONFLICT_OFFSET ( ai ) ; <nl> - bi + = GET_CONFLICT_OFFSET ( bi ) ; <nl> - <nl> - if ( ( lid & 127 ) < d ) <nl> - { <nl> - lm_sum [ lid > > 7 ] [ bi ] + = lm_sum [ lid > > 7 ] [ ai ] ; <nl> - } <nl> - offset < < = 1 ; <nl> + int sum_idx = mad24 ( lid + i , src_step , gid * 2 ) ; <nl> + src_t [ 0 ] = srcsum [ sum_idx ] ; <nl> + src_t [ 1 ] = srcsum [ sum_idx + 1 ] ; <nl> } <nl> - barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - if ( lid < 2 ) <nl> + else <nl> { <nl> - lm_sum [ lid ] [ LSIZE_2 + LOG_LSIZE ] = 0 ; <nl> + src_t [ 0 ] = 0 ; <nl> + src_t [ 1 ] = 0 ; <nl> } <nl> - for ( int d = 1 ; d < LSIZE ; d < < = 1 ) <nl> + if ( i = = 0 ) <nl> { <nl> - barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - offset > > = 1 ; <nl> - int ai = offset * ( ( ( lid & 127 ) < < 1 ) + 1 ) - 1 , bi = ai + offset ; <nl> - ai + = GET_CONFLICT_OFFSET ( ai ) ; <nl> - bi + = GET_CONFLICT_OFFSET ( bi ) ; <nl> - <nl> - if ( ( lid & 127 ) < d ) <nl> - { <nl> - lm_sum [ lid > > 7 ] [ bi ] + = lm_sum [ lid > > 7 ] [ ai ] ; <nl> - lm_sum [ lid > > 7 ] [ ai ] = lm_sum [ lid > > 7 ] [ bi ] - lm_sum [ lid > > 7 ] [ ai ] ; <nl> - } <nl> + sum_t [ 0 ] = 0 ; <nl> + sum_t [ 1 ] = 0 ; <nl> } <nl> - barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - if ( lid > 0 & & ( i + lid ) < = rows ) <nl> + else <nl> { <nl> - int loc_s0 = gid * dst_step + i + lid - 1 - pre_invalid * dst_step / 4 , loc_s1 = loc_s0 + dst_step ; <nl> - lm_sum [ 0 ] [ bf_loc ] + = sum_t [ 0 ] ; <nl> - lm_sum [ 1 ] [ bf_loc ] + = sum_t [ 1 ] ; <nl> - sum_p = ( __local float * ) ( & ( lm_sum [ 0 ] [ bf_loc ] ) ) ; <nl> - for ( int k = 0 ; k < 4 ; k + + ) <nl> - { <nl> - if ( gid * 4 + k > = cols + pre_invalid | | gid * 4 + k < pre_invalid ) continue ; <nl> - sum [ loc_s0 + k * dst_step / 4 ] = sum_p [ k ] ; <nl> - } <nl> - sum_p = ( __local float * ) ( & ( lm_sum [ 1 ] [ bf_loc ] ) ) ; <nl> - for ( int k = 0 ; k < 4 ; k + + ) <nl> - { <nl> - if ( gid * 4 + k + 4 > = cols + pre_invalid ) break ; <nl> - sum [ loc_s1 + k * dst_step / 4 ] = sum_p [ k ] ; <nl> - } <nl> + sum_t [ 0 ] = lm_sum [ 0 ] [ LSIZE_2 + LOG_LSIZE ] ; <nl> + sum_t [ 1 ] = lm_sum [ 1 ] [ LSIZE_2 + LOG_LSIZE ] ; <nl> } <nl> barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - } <nl> - } <nl> - <nl> - kernel void integral_sum_rows ( __global float4 * srcsum , __global float * sum , <nl> - int rows , int cols , int src_step , int sum_step , int sum_offset ) <nl> - { <nl> - int lid = get_local_id ( 0 ) ; <nl> - int gid = get_group_id ( 0 ) ; <nl> - float4 src_t [ 2 ] , sum_t [ 2 ] ; <nl> - __local float4 lm_sum [ 2 ] [ LSIZE + LOG_LSIZE ] ; <nl> - __local float * sum_p ; <nl> - src_step = src_step > > 4 ; <nl> - for ( int i = 0 ; i < rows ; i = i + LSIZE_1 ) <nl> - { <nl> - src_t [ 0 ] = i + lid < rows ? srcsum [ ( lid + i ) * src_step + gid * 2 ] : ( float4 ) 0 ; <nl> - src_t [ 1 ] = i + lid < rows ? srcsum [ ( lid + i ) * src_step + gid * 2 + 1 ] : ( float4 ) 0 ; <nl> - <nl> - sum_t [ 0 ] = ( i = = 0 ? ( float4 ) 0 : lm_sum [ 0 ] [ LSIZE_2 + LOG_LSIZE ] ) ; <nl> - sum_t [ 1 ] = ( i = = 0 ? ( float4 ) 0 : lm_sum [ 1 ] [ LSIZE_2 + LOG_LSIZE ] ) ; <nl> - barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> <nl> int bf_loc = lid + GET_CONFLICT_OFFSET ( lid ) ; <nl> - lm_sum [ 0 ] [ bf_loc ] = src_t [ 0 ] ; <nl> <nl> + lm_sum [ 0 ] [ bf_loc ] = src_t [ 0 ] ; <nl> lm_sum [ 1 ] [ bf_loc ] = src_t [ 1 ] ; <nl> <nl> int offset = 1 ; <nl> - for ( int d = LSIZE > > 1 ; d > 0 ; d > > = 1 ) <nl> + for ( int d = LSIZE > > 1 ; d > 0 ; d > > = 1 ) <nl> { <nl> barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - int ai = offset * ( ( ( lid & 127 ) < < 1 ) + 1 ) - 1 , bi = ai + offset ; <nl> + int ai = offset * lid_prim - 1 , bi = ai + offset ; <nl> ai + = GET_CONFLICT_OFFSET ( ai ) ; <nl> bi + = GET_CONFLICT_OFFSET ( bi ) ; <nl> <nl> kernel void integral_sum_rows ( __global float4 * srcsum , __global float * sum , <nl> offset < < = 1 ; <nl> } <nl> barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - if ( lid < 2 ) <nl> + if ( lid < 2 ) <nl> { <nl> lm_sum [ lid ] [ LSIZE_2 + LOG_LSIZE ] = 0 ; <nl> } <nl> - for ( int d = 1 ; d < LSIZE ; d < < = 1 ) <nl> + for ( int d = 1 ; d < LSIZE ; d < < = 1 ) <nl> { <nl> barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> offset > > = 1 ; <nl> - int ai = offset * ( ( ( lid & 127 ) < < 1 ) + 1 ) - 1 , bi = ai + offset ; <nl> + int ai = offset * lid_prim - 1 , bi = ai + offset ; <nl> ai + = GET_CONFLICT_OFFSET ( ai ) ; <nl> bi + = GET_CONFLICT_OFFSET ( bi ) ; <nl> <nl> - if ( ( lid & 127 ) < d ) <nl> + if ( ( lid & 127 ) < d ) <nl> { <nl> lm_sum [ lid > > 7 ] [ bi ] + = lm_sum [ lid > > 7 ] [ ai ] ; <nl> lm_sum [ lid > > 7 ] [ ai ] = lm_sum [ lid > > 7 ] [ bi ] - lm_sum [ lid > > 7 ] [ ai ] ; <nl> } <nl> } <nl> barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> - if ( gid = = 0 & & ( i + lid ) < = rows ) <nl> + if ( gid = = 0 & & ( i + lid ) < = rows ) <nl> { <nl> sum [ sum_offset + i + lid ] = 0 ; <nl> } <nl> - if ( i + lid = = 0 ) <nl> + if ( i + lid = = 0 ) <nl> { <nl> int loc0 = gid * 2 * sum_step ; <nl> for ( int k = 1 ; k < = 8 ; k + + ) <nl> { <nl> - if ( gid * 8 + k > cols ) break ; <nl> + if ( gid * 8 + k > cols ) <nl> + break ; <nl> sum [ sum_offset + loc0 + k * sum_step / 4 ] = 0 ; <nl> } <nl> } <nl> <nl> - if ( lid > 0 & & ( i + lid ) < = rows ) <nl> + if ( lid > 0 & & ( i + lid ) < = rows ) <nl> { <nl> int loc_s0 = sum_offset + gid * 2 * sum_step + sum_step / 4 + i + lid , loc_s1 = loc_s0 + sum_step ; <nl> lm_sum [ 0 ] [ bf_loc ] + = sum_t [ 0 ] ; <nl> lm_sum [ 1 ] [ bf_loc ] + = sum_t [ 1 ] ; <nl> - sum_p = ( __local float * ) ( & ( lm_sum [ 0 ] [ bf_loc ] ) ) ; <nl> + sum_p = ( __local sumT * ) ( & ( lm_sum [ 0 ] [ bf_loc ] ) ) ; <nl> for ( int k = 0 ; k < 4 ; k + + ) <nl> { <nl> - if ( gid * 8 + k > = cols ) break ; <nl> + if ( gid * 8 + k > = cols ) <nl> + break ; <nl> sum [ loc_s0 + k * sum_step / 4 ] = sum_p [ k ] ; <nl> } <nl> - sum_p = ( __local float * ) ( & ( lm_sum [ 1 ] [ bf_loc ] ) ) ; <nl> + sum_p = ( __local sumT * ) ( & ( lm_sum [ 1 ] [ bf_loc ] ) ) ; <nl> for ( int k = 0 ; k < 4 ; k + + ) <nl> { <nl> - if ( gid * 8 + 4 + k > = cols ) break ; <nl> + if ( gid * 8 + 4 + k > = cols ) <nl> + break ; <nl> sum [ loc_s1 + k * sum_step / 4 ] = sum_p [ k ] ; <nl> } <nl> } <nl> barrier ( CLK_LOCAL_MEM_FENCE ) ; <nl> } <nl> } <nl> - <nl> - # endif <nl> mmm a / modules / imgproc / src / sumpixels . cpp <nl> ppp b / modules / imgproc / src / sumpixels . cpp <nl> static bool ocl_integral ( InputArray _src , OutputArray _sum , int sdepth ) <nl> UMat src = _src . getUMat ( ) , t_sum ( t_size , sdepth ) , sum = _sum . getUMat ( ) ; <nl> t_sum = t_sum ( Range : : all ( ) , Range ( 0 , size . height ) ) ; <nl> <nl> - int offset = ( int ) src . offset / vlen , pre_invalid = ( int ) src . offset % vlen ; <nl> - int vcols = ( pre_invalid + src . cols + vlen - 1 ) / vlen ; <nl> + int offset = ( int ) src . offset / vlen ; <nl> + int vcols = ( src . cols + vlen - 1 ) / vlen ; <nl> int sum_offset = ( int ) sum . offset / vlen ; <nl> <nl> k1 . args ( ocl : : KernelArg : : PtrReadOnly ( src ) , ocl : : KernelArg : : PtrWriteOnly ( t_sum ) , <nl> - offset , pre_invalid , src . rows , src . cols , ( int ) src . step , ( int ) t_sum . step ) ; <nl> + offset , src . rows , src . cols , ( int ) src . step , ( int ) t_sum . step ) ; <nl> size_t gt = ( ( vcols + 1 ) / 2 ) * 256 , lt = 256 ; <nl> if ( ! k1 . run ( 1 , & gt , & lt , false ) ) <nl> return false ; <nl> <nl> ocl : : Kernel k2 ( " integral_sum_rows " , ocl : : imgproc : : integral_sum_oclsrc , <nl> format ( " - D sdepth = % d " , sdepth ) ) ; <nl> - k2 . args ( ocl : : KernelArg : : PtrReadWrite ( t_sum ) , ocl : : KernelArg : : PtrWriteOnly ( sum ) , <nl> + k2 . args ( ocl : : KernelArg : : PtrReadOnly ( t_sum ) , ocl : : KernelArg : : PtrWriteOnly ( sum ) , <nl> t_sum . rows , t_sum . cols , ( int ) t_sum . step , ( int ) sum . step , sum_offset ) ; <nl> <nl> size_t gt2 = t_sum . cols * 32 , lt2 = 256 ; <nl>
Merge pull request from vbystricky : oclopt_integral
opencv/opencv
ce5bae1c676b7adc65971f8e26b809b81a26e99e
2014-06-17T14:23:31Z
mmm a / documentation / sphinx / source / known - limitations . rst <nl> ppp b / documentation / sphinx / source / known - limitations . rst <nl> Long running read / write transactions are a design limitation , see the discussion <nl> * If it needs long - running read snapshots , it can perform versioning in a layer . <nl> * If it needs large bulk inserts , it can use a level of indirection to swap in the inserted data quickly . <nl> <nl> + . . _cluster - size : <nl> + <nl> Cluster size <nl> mmmmmmmmmmmm <nl> <nl> mmm a / documentation / sphinx / source / performance . rst <nl> ppp b / documentation / sphinx / source / performance . rst <nl> <nl> Performance <nl> # # # # # # # # # # # <nl> <nl> - FoundationDB uses commodity hardware to provide your applications with millions of database operations per penny . <nl> + FoundationDB uses commodity hardware to provide high throughputs and low latencies to your application at a variety of scales . <nl> <nl> Scaling <nl> = = = = = = = <nl> <nl> - FoundationDB has an unmatched ability to scale linearly as you add more cores to a cluster . <nl> + FoundationDB scales linearly with the number of cores in a cluster over a wide range of sizes . <nl> <nl> . . image : : / images / scaling . png <nl> <nl> - Here , a cluster of commodity hardware scales to * * 8 . 2 million * * operations / sec doing a 90 % read and 10 % write workload . <nl> + Here , a cluster of commodity hardware scales to * * 8 . 2 million * * operations / sec doing a 90 % read and 10 % write workload with 16 byte keys and values between 8 and 100 bytes . <nl> <nl> The scaling graph uses a 24 - machine EC2 c3 . 8xlarge cluster in which each machine has a 16 - core processor . We ran a FoundationDB server process on each core , yielding a 384 - process cluster for the largest test , and scaled the cluster down for each smaller test . <nl> <nl> Scaling is the ability to efficiently deliver operations at different scales . For FoundationDB , the relevant operations are reads and writes , measured in operations per sec . Scale is measured in the number of processes , which will usually track the number of available cores . FoundationDB offers scalability from partial utilization of a single core on a single machine to full utilization of dozens of powerful multi - core machines in a cluster . <nl> <nl> + See our : ref : ` known limitations < cluster - size > ` for details about the limits of cluster scalability . <nl> + <nl> Latency <nl> = = = = = = = <nl> <nl> For FoundationDB , the significant latencies are those experienced by a Foundatio <nl> <nl> * * * Transaction start * * . This latency will be experienced as part of the first read in a transaction as the read version is obtained . It will typically be a few milliseconds under moderate load , but under high write loads FoundationDB tries to concentrate most transaction latency here . <nl> <nl> - * * * Reads * * . Individual reads should take under 1 ms with moderate loads . If a transaction performs many reads by waiting for each to complete before starting the next , however , these small latencies can add up . You can thus reduce total latency ( and potentially conflicts ) by doing as many of your reads as possible in parallel . FoundationDB supports non - blocking reads , so it ' s easy to perform reads without waiting on them . <nl> + * * * Reads * * . Individual reads should take under 1 ms with moderate loads . If a transaction performs many reads by waiting for each to complete before starting the next , however , these small latencies can add up . You can thus reduce total latency ( and potentially : ref : ` conflicts < conflict - ranges > ` ) by doing as many of your reads as possible in parallel . FoundationDB supports non - blocking reads , so it ' s easy to perform reads without waiting on them . <nl> <nl> - * * * Commit * * . Transactions that perform writes must be committed , and the commit will not succeed until the transaction is durable with full replication . This latency will average under 3 ms with moderate loads . Only a small part of this latency impacts transaction conflicts . <nl> + * * * Commit * * . Transactions that perform writes must be committed , and the commit will not succeed until the transaction is durable with full replication . This latency should average under 3 ms with moderate loads . Only a small part of this latency impacts transaction : ref : ` conflicts < conflict - ranges > ` . <nl> <nl> Throughput ( per core ) <nl> = = = = = = = = = = = = = = = = = = = = = <nl> FoundationDB provides good throughput for the full range of read and write workl <nl> <nl> . . image : : / images / throughput . png <nl> <nl> - FoundationDB offers two : ref : ` storage engines < configuration - storage - engine > ` , optimized for distinct use cases , both of which write to disk before reporting transactions committed . For each storage engine , the graph shows throughput of a single FoundationDB process running on a * * single core * * with saturating read / write workloads ranging from 100 % reads to 100 % writes . Throughput for the unmixed workloads is about : <nl> + FoundationDB offers two : ref : ` storage engines < configuration - storage - engine > ` , optimized for distinct use cases , both of which write to disk before reporting transactions committed . For each storage engine , the graph shows throughput of a single FoundationDB process running on a * * single core * * with saturating read / write workloads ranging from 100 % reads to 100 % writes , all with 16 byte keys and values between 8 and 100 bytes . Throughput for the unmixed workloads is about : <nl> <nl> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> workload ssd engine memory engine <nl> FoundationDB is designed to achieve great performance under high concurrency fro <nl> <nl> . . image : : / images / concurrency . png <nl> <nl> - Its asynchronous design allows it to handle very high concurrency , and for a typical workload with 90 % reads and 10 % writes , maximum throughput is reached at about 200 concurrent operations , achieved with * * 20 * * concurrent transactions per FoundationDB process for a workload using 10 ops / transaction . <nl> + Its asynchronous design allows it to handle very high concurrency , and for a typical workload with 90 % reads and 10 % writes , maximum throughput is reached at about 200 concurrent operations . This number of operations was achieved with * * 20 * * concurrent transactions per FoundationDB process each running 10 operations with 16 byte keys and values between 8 and 100 bytes . <nl> <nl> The concurrency graph uses a single FoundationDB server process on a single core ( E3 - 1240 ) . <nl> <nl> A lot of things affect the simple first - order model of performance you see here . <nl> * Not all CPUs are the same speed . <nl> * To keep up with the performance modeled above , your disk subsystem will need to do a little over 1 IOPS per write , and about 1 IOPS per ( uncached ) read . <nl> * Network performance tuning at the operating system level can be very important for both latency and throughput , especially in larger clusters . <nl> + * Running DR and / or backup requires applying each mutation multiple times and then reading those mutations from the database . Using either feature will reduce throughput . <nl> + * See our : ref : ` known - limitations < known limitations > ` for other considerations which may affect performance . <nl>
Merge pull request from ajbeamon / docs - performance - page - edits
apple/foundationdb
e4275d3178221b9c1f009121cdbbfd36efd94050
2018-03-19T19:43:32Z
mmm a / make / config . mk <nl> ppp b / make / config . mk <nl> USE_STATIC_MKL = NONE <nl> endif <nl> <nl> # mmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> - # Settings for power arch <nl> + # Settings for power and arm arch <nl> # mmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> ARCH : = $ ( shell uname - a ) <nl> - ifneq ( , $ ( filter $ ( ARCH ) , powerpc64le ppc64le ) ) <nl> + ifneq ( , $ ( filter $ ( ARCH ) , armv6l armv7l powerpc64le ppc64le ) ) <nl> USE_SSE = 0 <nl> else <nl> USE_SSE = 1 <nl>
disable SSE for arm hardware e . g . Raspberry Pi ( )
apache/incubator-mxnet
b3c4d25b25123e2163d0043f4b8fb790876231ee
2016-09-22T03:44:21Z
mmm a / flow / flat_buffers . cpp <nl> ppp b / flow / flat_buffers . cpp <nl> TEST_CASE ( " / flow / FlatBuffers / VectorRef " ) { <nl> serializedVector = StringRef ( readerArena , writer . toStringRef ( ) ) ; <nl> } <nl> ArenaObjectReader reader ( readerArena , serializedVector , Unversioned ( ) ) ; <nl> + / / The VectorRef and Arena arguments are intentionally in a different order from the serialize call above . <nl> + / / Arenas need to get serialized after any Ref types whose memory they own . In order for schema evolution to be <nl> + / / possible , it needs to be okay to reorder an Arena so that it appears after a newly added Ref type . For this <nl> + / / reason , Arenas are ignored by the wire protocol entirely . We test that behavior here . <nl> reader . deserialize ( FileIdentifierFor < decltype ( outVec ) > : : value , outVec , vecArena ) ; <nl> } <nl> ASSERT ( src . size ( ) = = outVec . size ( ) ) ; <nl>
Explain test subtlety
apple/foundationdb
997da6882ab8abe1978cc372a5033d87c4752eac
2019-07-29T23:00:14Z
mmm a / tensorflow / lite / micro / tools / make / Makefile <nl> ppp b / tensorflow / lite / micro / tools / make / Makefile <nl> CXX_TOOL : = g + + <nl> CC_TOOL : = gcc <nl> AR_TOOL : = ar <nl> <nl> + # Specify which specialized kernel implementation should be pulled in . This was <nl> + # previously supported via TAGS , but that is soon going to be removed . The <nl> + # reason for removing TAGS is that we no longer support more than a single <nl> + # specialized implementation and we also want to be explicit about what <nl> + # makefiles get included for a given command line invocation . <nl> + # <nl> + # Currently , we are keeping the support for optimized kernels via TAGS for <nl> + # backwards compatibility , but will be removing that in the near future . <nl> + OPTIMIZED_KERNEL_DIR : = <nl> + <nl> # Specify TAGS on the command line to add a particular set of specialized <nl> # implementations , for example TAGS = " CMSIS disco_f746ng " to target a Discovery <nl> # STM32F746NG board , using the CMSIS library ' s implementations where possible . <nl> TEST_SCRIPT : = tensorflow / lite / micro / testing / test_linux_binary . sh <nl> <nl> MICROLITE_LIBS : = - lm <nl> <nl> - <nl> # For each tag specified on the command line we add - D < tag > to the cflags to <nl> # allow for # idefs in the code . <nl> # <nl> MICROLITE_LIBS : = - lm <nl> # and ethos - u directories have been renamed . <nl> TAG_DEFINES : = $ ( foreach TAG , $ ( TAGS ) , - D $ ( shell echo $ ( TAG ) | tr [ a - z ] [ A - Z ] | tr - _ ) ) <nl> <nl> + OPTIMIZED_KERNEL_DEFINES : = <nl> + ifneq ( $ ( OPTIMIZED_KERNEL_DIR ) , ) <nl> + # For backwards compatibility , we are using an empty OPTIMIZED_KERNEL_DIR to <nl> + # impy that we want to fall - back to TAGS . So , we are additionally using <nl> + # OPTIMIZED_KERNEL_DIR = = none to signify that we do not want any optimized <nl> + # implementations . <nl> + ifneq ( $ ( OPTIMIZED_KERNEL_DIR ) , none ) <nl> + OPTIMIZED_KERNEL_DEFINES : = - D $ ( shell echo $ ( OPTIMIZED_KERNEL_DIR ) | tr [ a - z ] [ A - Z ] | tr - _ ) <nl> + endif <nl> + endif <nl> + <nl> OPTIMIZATION_LEVEL : = - O3 <nl> <nl> CC_WARNINGS : = \ <nl> COMMON_FLAGS : = \ <nl> - DTF_LITE_DISABLE_X86_NEON \ <nl> $ ( OPTIMIZATION_LEVEL ) \ <nl> $ ( CC_WARNINGS ) \ <nl> + $ ( OPTIMIZED_KERNEL_DEFINES ) \ <nl> $ ( TAG_DEFINES ) <nl> <nl> CXXFLAGS : = \ <nl> $ ( wildcard tensorflow / lite / micro / memory_planner / * test . cc ) <nl> MICROLITE_BENCHMARK_SRCS : = \ <nl> $ ( wildcard tensorflow / lite / micro / benchmarks / * benchmark . cc ) <nl> <nl> + MICROLITE_CC_KERNEL_SRCS : = \ <nl> + $ ( wildcard tensorflow / lite / micro / kernels / * . cc ) <nl> + MICROLITE_CC_KERNEL_SRCS : = $ ( filter - out $ ( MICROLITE_TEST_SRCS ) , $ ( MICROLITE_CC_KERNEL_SRCS ) ) <nl> + <nl> MICROLITE_TEST_HDRS : = \ <nl> $ ( wildcard tensorflow / lite / micro / testing / * . h ) <nl> <nl> MICROLITE_CC_BASE_SRCS : = \ <nl> $ ( wildcard tensorflow / lite / micro / * . cc ) \ <nl> $ ( wildcard tensorflow / lite / micro / benchmarks / * model_data . cc ) \ <nl> - $ ( wildcard tensorflow / lite / micro / kernels / * . cc ) \ <nl> $ ( wildcard tensorflow / lite / micro / memory_planner / * . cc ) \ <nl> $ ( wildcard tensorflow / lite / micro / testing / * model . cc ) \ <nl> tensorflow / lite / c / common . c \ <nl> ifeq ( $ ( findstring $ ( TARGET ) , $ ( TARGETS_WITHOUT_MAKEFILES ) ) , ) <nl> include $ ( MAKEFILE_DIR ) / targets / $ ( TARGET ) _makefile . inc <nl> endif <nl> <nl> - # Load dependencies for optimized kernel implementations . <nl> - include $ ( wildcard $ ( MAKEFILE_DIR ) / ext_libs / * . inc ) <nl> + ifneq ( $ ( OPTIMIZED_KERNEL_DIR ) , ) <nl> + # The new way of using optimized kernels enforces that only that specific <nl> + # makefile is included . For backwards compatibility , we are using an empty <nl> + # OPTIMIZED_KERNEL_DIR to impy that we want to fall - back to TAGS . So , we are <nl> + # additionally using OPTIMIZED_KERNEL_DIR = = none to signify that we do not want <nl> + # any optimized implementations . <nl> + ifneq ( $ ( OPTIMIZED_KERNEL_DIR ) , none ) <nl> + include $ ( MAKEFILE_DIR ) / ext_libs / $ ( OPTIMIZED_KERNEL_DIR ) . inc <nl> + # Specialize for the optimized kernels <nl> + MICROLITE_CC_KERNEL_SRCS : = $ ( call substitute_specialized_implementations , $ ( MICROLITE_CC_KERNEL_SRCS ) , $ ( OPTIMIZED_KERNEL_DIR ) ) <nl> + endif <nl> <nl> - # Call specialize here so that platform - specific tags can be taken into account . <nl> - MICROLITE_CC_SRCS : = $ ( call specialize , $ ( MICROLITE_CC_SRCS ) ) <nl> + # Specialize for debug_log . micro_time etc . <nl> + MICROLITE_CC_SRCS : = $ ( call substitute_specialized_implementations , $ ( MICROLITE_CC_SRCS ) , $ ( TARGET ) ) <nl> + MICROLITE_CC_SRCS + = $ ( MICROLITE_CC_KERNEL_SRCS ) <nl> + else <nl> + # This is the deprecated way of pulling in optimized kernel implementations . <nl> + # Load dependencies for optimized kernel implementations . <nl> + include $ ( wildcard $ ( MAKEFILE_DIR ) / ext_libs / * . inc ) <nl> + <nl> + # Call specialize here so that platform - specific tags can be taken into account . <nl> + MICROLITE_CC_SRCS + = $ ( MICROLITE_CC_KERNEL_SRCS ) <nl> + MICROLITE_CC_SRCS : = $ ( call specialize , $ ( MICROLITE_CC_SRCS ) ) <nl> + endif <nl> <nl> ALL_TAGS + = $ ( TARGET_ARCH ) <nl> <nl> new file mode 100644 <nl> index 0000000000000 . . c972870cf0293 <nl> mmm / dev / null <nl> ppp b / tensorflow / lite / micro / tools / make / ext_libs / xtensa_hifimini . inc <nl> <nl> + # Every optimized kernel implementation directory ( i . e . <nl> + # micro / kernels / < optimized_kernel_dir > / must have a corresponding <nl> + # micro / tools / make / ext_libs / < optimized_kernel_dir > . inc <nl> + <nl> mmm a / tensorflow / lite / micro / tools / make / helper_functions . inc <nl> ppp b / tensorflow / lite / micro / tools / make / helper_functions . inc <nl> substitute_specialized_implementation = \ <nl> $ ( if $ ( wildcard $ ( 1 ) ) , $ ( firstword $ ( wildcard $ ( dir $ ( 1 ) ) $ ( 2 ) / $ ( notdir $ ( 1 ) ) ) $ ( wildcard $ ( 1 ) ) ) , $ ( 1 ) ) <nl> substitute_specialized_implementations = \ <nl> $ ( foreach source , $ ( 1 ) , $ ( call substitute_specialized_implementation , $ ( source ) , $ ( 2 ) ) ) <nl> + <nl> # Here we ' re first looking for specialized implementations in ref_dir / $ ( TAG1 ) <nl> # and then ref_dir / $ ( TAG2 ) , etc , before falling back to ref_dir ' s <nl> # implementation . <nl> substitute_specialized_implementations = \ <nl> define specialize_on_tags <nl> $ ( if $ ( 2 ) , $ ( call substitute_specialized_implementations , $ ( call specialize_on_tags , $ ( 1 ) , $ ( wordlist 2 , $ ( words $ ( 2 ) ) , $ ( 2 ) ) ) , $ ( firstword $ ( 2 ) ) ) , $ ( 1 ) ) <nl> endef <nl> + <nl> # The entry point that most targets should use to find implementation - specific <nl> # versions of their source files . The only argument is a list of file paths . <nl> specialize = $ ( call specialize_on_tags , $ ( 1 ) , $ ( strip $ ( call reverse , $ ( ALL_TAGS ) ) ) ) <nl>
Specialize sources for target and optimized kernels independently .
tensorflow/tensorflow
9f27888f5071a031c91e2358c8f052606a102f01
2020-11-04T19:31:34Z
mmm a / lib / Sema / MiscDiagnostics . cpp <nl> ppp b / lib / Sema / MiscDiagnostics . cpp <nl> static bool diagAvailability ( TypeChecker & TC , const ValueDecl * D , <nl> } <nl> <nl> / / Diagnose for deprecation <nl> - if ( const AvailabilityAttr * Attr = D - > getAttrs ( ) . getDeprecated ( TC . Context ) ) { <nl> - TC . diagnoseDeprecated ( R . Start , DC , Attr , D - > getFullName ( ) ) ; <nl> + if ( const AvailabilityAttr * Attr = TC . getDeprecated ( D ) ) { <nl> + TC . diagnoseDeprecated ( R , DC , Attr , D - > getFullName ( ) ) ; <nl> } <nl> <nl> / / We only diagnose potentially unavailability here if availability checking <nl> static bool diagAvailability ( TypeChecker & TC , const ValueDecl * D , <nl> return false ; <nl> } <nl> <nl> - <nl> namespace { <nl> class AvailabilityWalker : public ASTWalker { <nl> / / / Describes how the next member reference will be treated as we traverse <nl> mmm a / lib / Sema / TypeCheckType . cpp <nl> ppp b / lib / Sema / TypeCheckType . cpp <nl> static bool checkTypeDeclAvailability ( Decl * TypeDecl , IdentTypeRepr * IdType , <nl> return true ; <nl> } <nl> <nl> - if ( auto * Attr = TypeDecl - > getAttrs ( ) . getDeprecated ( TC . Context ) ) { <nl> - TC . diagnoseDeprecated ( Loc , DC , Attr , CI - > getIdentifier ( ) ) ; <nl> + if ( auto * Attr = TC . getDeprecated ( TypeDecl ) ) { <nl> + TC . diagnoseDeprecated ( CI - > getSourceRange ( ) , DC , Attr , <nl> + CI - > getIdentifier ( ) ) ; <nl> } <nl> <nl> / / Check for potential unavailability because of the minimum <nl> mmm a / lib / Sema / TypeChecker . cpp <nl> ppp b / lib / Sema / TypeChecker . cpp <nl> static Optional < ASTNode > findInnermostAncestor ( <nl> } <nl> <nl> / / / Given a reference range and a declaration context containing the range , <nl> - / / / find an AST node that contains the source range and <nl> - / / / that can be walked to find suitable parents of the SourceRange <nl> - / / / for availability Fix - Its . <nl> - const Decl * rootForAvailabilityFixitFinder ( SourceRange ReferenceRange , <nl> - const DeclContext * ReferenceDC , <nl> - const SourceManager & SM ) { <nl> - / / Drop the const so we can return the decl context as an ASTNode . <nl> - const Decl * D = ReferenceDC - > getInnermostDeclarationDeclContext ( ) ; <nl> - <nl> - if ( D ) <nl> + / / / attempt to find a declaration containing the reference . This may not <nl> + / / / be the innermost declaration containing the range . <nl> + / / / Returns null if no such declaration can be found . <nl> + static const Decl * findContainingDeclaration ( SourceRange ReferenceRange , <nl> + const DeclContext * ReferenceDC , <nl> + const SourceManager & SM ) { <nl> + if ( const Decl * D = ReferenceDC - > getInnermostDeclarationDeclContext ( ) ) <nl> return D ; <nl> <nl> / / We couldn ' t find a suitable node by climbing the DeclContext <nl> / / hierarchy , so fall back to looking for a top - level declaration <nl> / / that contains the reference range . We will hit this case for <nl> / / top - level elements that do not themselves introduce DeclContexts , <nl> - / / such as extensions and global variables . <nl> + / / such as extensions and global variables . If we don ' t have a reference <nl> + / / range , there is nothing we can do , so return null . <nl> + if ( ReferenceRange . isInvalid ( ) ) <nl> + return nullptr ; <nl> + <nl> SourceFile * SF = ReferenceDC - > getParentSourceFile ( ) ; <nl> if ( ! SF ) <nl> return nullptr ; <nl> static void findAvailabilityFixItNodes ( SourceRange ReferenceRange , <nl> <nl> / / Limit tree to search based on the DeclContext of the reference . <nl> const Decl * DeclarationToSearch = <nl> - rootForAvailabilityFixitFinder ( ReferenceRange , ReferenceDC , SM ) ; <nl> + findContainingDeclaration ( ReferenceRange , ReferenceDC , SM ) ; <nl> if ( ! DeclarationToSearch ) <nl> return ; <nl> <nl> bool TypeChecker : : isInsideImplicitFunction ( const DeclContext * DC ) { <nl> return false ; <nl> } <nl> <nl> - void TypeChecker : : diagnoseDeprecated ( SourceLoc ReferenceLoc , <nl> + const AvailabilityAttr * TypeChecker : : getDeprecated ( const Decl * D ) { <nl> + if ( auto * Attr = D - > getAttrs ( ) . getDeprecated ( Context ) ) <nl> + return Attr ; <nl> + <nl> + / / Treat extensions methods as deprecated if their extension <nl> + / / is deprecated . <nl> + DeclContext * DC = D - > getDeclContext ( ) ; <nl> + if ( auto * ED = dyn_cast < ExtensionDecl > ( DC ) ) { <nl> + return getDeprecated ( ED ) ; <nl> + } <nl> + <nl> + return nullptr ; <nl> + } <nl> + <nl> + / / / Returns true if the reference is lexically contained in a declaration <nl> + / / / that is deprecated on all deployment targets . <nl> + static bool isInsideDeprecatedDeclaration ( SourceRange ReferenceRange , <nl> + const DeclContext * ReferenceDC , <nl> + TypeChecker & TC ) { <nl> + ASTContext & Ctx = TC . Context ; <nl> + <nl> + / / Climb the DeclContext hierarchy to see if any of the containing <nl> + / / declarations are deprecated on on all deployment targets . <nl> + const DeclContext * DC = ReferenceDC ; <nl> + do { <nl> + auto * D = DC - > getInnermostDeclarationDeclContext ( ) ; <nl> + if ( ! D ) <nl> + break ; <nl> + <nl> + if ( D - > getAttrs ( ) . getDeprecated ( Ctx ) ) { <nl> + return true ; <nl> + } <nl> + <nl> + / / If we are in an accessor , check to see if the associated <nl> + / / property is deprecated . <nl> + auto * FD = dyn_cast < FuncDecl > ( D ) ; <nl> + if ( FD & & FD - > isAccessor ( ) & & <nl> + TC . getDeprecated ( FD - > getAccessorStorageDecl ( ) ) ) { <nl> + return true ; <nl> + } <nl> + <nl> + DC = DC - > getParent ( ) ; <nl> + } while ( DC ) ; <nl> + <nl> + <nl> + / / Search the AST starting from our innermost declaration context to see if <nl> + / / if the reference is inside a property declaration but not inside an <nl> + / / accessor ( this can happen for the TypeRepr for the declared type of a <nl> + / / property , for example ) . <nl> + / / We can ' t rely on the DeclContext hierarchy climb above because properties <nl> + / / do not introduce a new DeclContext . This search is potentially slow , so we <nl> + / / do it last and only if the reference declaration context is a <nl> + / / type or global context . <nl> + <nl> + if ( ! ReferenceDC - > isTypeContext ( ) & & ! ReferenceDC - > isModuleScopeContext ( ) ) <nl> + return false ; <nl> + <nl> + const Decl * DeclToSearch = <nl> + findContainingDeclaration ( ReferenceRange , ReferenceDC , Ctx . SourceMgr ) ; <nl> + <nl> + / / We may not be able to find a declaration to search if the ReferenceRange <nl> + / / is invalid ( i . e . , we are in synthesized code ) . <nl> + if ( ! DeclToSearch ) <nl> + return false ; <nl> + <nl> + InnermostAncestorFinder : : MatchPredicate IsDeclaration = <nl> + [ ] ( ASTNode Node , ASTWalker : : ParentTy Parent ) { <nl> + return Node . is < Decl * > ( ) ; <nl> + } ; <nl> + <nl> + Optional < ASTNode > FoundDeclarationNode = <nl> + findInnermostAncestor ( ReferenceRange , Ctx . SourceMgr , <nl> + const_cast < Decl * > ( DeclToSearch ) , IsDeclaration ) ; <nl> + <nl> + if ( FoundDeclarationNode . hasValue ( ) ) { <nl> + const Decl * D = FoundDeclarationNode . getValue ( ) . get < Decl * > ( ) ; <nl> + D = abstractSyntaxDeclForAvailabilityAttribute ( D ) ; <nl> + if ( TC . getDeprecated ( D ) ) { <nl> + return true ; <nl> + } <nl> + } <nl> + <nl> + return false ; <nl> + } <nl> + <nl> + void TypeChecker : : diagnoseDeprecated ( SourceRange ReferenceRange , <nl> const DeclContext * ReferenceDC , <nl> const AvailabilityAttr * Attr , <nl> DeclName Name ) { <nl> void TypeChecker : : diagnoseDeprecated ( SourceLoc ReferenceLoc , <nl> / / special - case diagnostics . <nl> if ( ! getLangOpts ( ) . EnableAvailabilityCheckingInImplicitFunctions & & <nl> isInsideImplicitFunction ( ReferenceDC ) ) { <nl> + return ; <nl> + } <nl> + <nl> + / / We match the behavior of clang to not report deprecation warnigs <nl> + / / inside declarations that are themselves deprecated on all deployment <nl> + / / targets . <nl> + if ( isInsideDeprecatedDeclaration ( ReferenceRange , ReferenceDC , * this ) ) { <nl> return ; <nl> } <nl> <nl> void TypeChecker : : diagnoseDeprecated ( SourceLoc ReferenceLoc , <nl> clang : : VersionTuple DeprecatedVersion = Attr - > Deprecated . getValue ( ) ; <nl> <nl> if ( Attr - > Message . empty ( ) ) { <nl> - diagnose ( ReferenceLoc , diag : : availability_deprecated , Name , Platform , <nl> + diagnose ( ReferenceRange . Start , diag : : availability_deprecated , Name , Platform , <nl> DeprecatedVersion ) . highlight ( Attr - > getRange ( ) ) ; <nl> return ; <nl> } <nl> <nl> - diagnose ( ReferenceLoc , diag : : availability_deprecated_msg , Name , Platform , <nl> + diagnose ( ReferenceRange . Start , diag : : availability_deprecated_msg , Name , Platform , <nl> DeprecatedVersion , Attr - > Message ) . highlight ( Attr - > getRange ( ) ) ; <nl> } <nl> <nl> mmm a / lib / Sema / TypeChecker . h <nl> ppp b / lib / Sema / TypeChecker . h <nl> class TypeChecker final : public LazyResolver { <nl> / / / implicit function . <nl> static bool isInsideImplicitFunction ( const DeclContext * DC ) ; <nl> <nl> + / / / Returns the availability attribute indicating deprecation if the <nl> + / / / declaration is deprecated or null otherwise . <nl> + const AvailabilityAttr * getDeprecated ( const Decl * D ) ; <nl> + <nl> / / / Emits a diagnostic for a reference to a declaration that is deprecated . <nl> - void diagnoseDeprecated ( SourceLoc ReferenceLoc , <nl> + void diagnoseDeprecated ( SourceRange SourceRange , <nl> const DeclContext * ReferenceDC , <nl> const AvailabilityAttr * Attr , <nl> DeclName Name ) ; <nl> mmm a / test / Sema / deprecation_osx . swift <nl> ppp b / test / Sema / deprecation_osx . swift <nl> class Sub : Super { <nl> / / rdar : / / problem / 20024980 tracks adding a proper warning in this and similar <nl> / / / cases . <nl> } <nl> + <nl> + @ availability ( OSX , introduced = 10 . 9 , deprecated = 10 . 10 ) <nl> + func functionDeprecatedIn10_10 ( ) { <nl> + let _ = ClassDeprecatedIn10_10 ( ) <nl> + } <nl> + <nl> + @ availability ( OSX , introduced = 10 . 9 , deprecated = 10 . 9 ) <nl> + class ClassDeprecatedIn10_9 { <nl> + } <nl> + <nl> + @ availability ( OSX , introduced = 10 . 8 , deprecated = 10 . 10 ) <nl> + class ClassDeprecatedIn10_10 { <nl> + var other10_10 : ClassDeprecatedIn10_10 = ClassDeprecatedIn10_10 ( ) <nl> + <nl> + func usingDeprecatedIn10_9 ( ) { <nl> + / / Following clang , we don ' t warn here even though we are using a class <nl> + / / that was deprecated before the containing class was deprecated . The <nl> + / / policy is to not warn if the use is inside a declaration that <nl> + / / is deprecated on all deployment targets . We can revisit this policy <nl> + / / if needed . <nl> + let _ = ClassDeprecatedIn10_9 ( ) <nl> + } <nl> + } <nl> + <nl> + class ClassWithComputedPropertyDeprecatedIn10_10 { <nl> + <nl> + @ availability ( OSX , introduced = 10 . 8 , deprecated = 10 . 10 ) <nl> + var annotatedPropertyDeprecatedIn10_10 : ClassDeprecatedIn10_10 { <nl> + get { <nl> + return ClassDeprecatedIn10_10 ( ) <nl> + } <nl> + set ( newValue ) { <nl> + let _ = ClassDeprecatedIn10_10 ( ) <nl> + } <nl> + } <nl> + <nl> + / / We really shouldn ' t be emitting three warnings here . It looks like <nl> + / / we are emitting one for each of the setter and getter , as well . <nl> + var unannotatedPropertyDeprecatedIn10_10 : ClassDeprecatedIn10_10 { / / expected - warning 3 { { ClassDeprecatedIn10_10 ' was deprecated in OS X 10 . 10 } } <nl> + get { <nl> + return ClassDeprecatedIn10_10 ( ) / / expected - warning { { ClassDeprecatedIn10_10 ' was deprecated in OS X 10 . 10 } } <nl> + } <nl> + set ( newValue ) { <nl> + let _ = ClassDeprecatedIn10_10 ( ) / / expected - warning { { ClassDeprecatedIn10_10 ' was deprecated in OS X 10 . 10 } } <nl> + } <nl> + } <nl> + <nl> + var unannotatedStoredPropertyOfTypeDeprecatedIn10_10 : ClassDeprecatedIn10_10 ? = nil / / expected - warning { { ClassDeprecatedIn10_10 ' was deprecated in OS X 10 . 10 } } <nl> + } <nl> + <nl> + func usesFunctionDeprecatedIn10_10 ( ) { <nl> + let _ = ClassDeprecatedIn10_10 ( ) / / expected - warning { { ClassDeprecatedIn10_10 ' was deprecated in OS X 10 . 10 } } <nl> + } <nl> + <nl> + @ availability ( OSX , introduced = 10 . 8 , deprecated = 10 . 10 ) <nl> + func annotatedUsesFunctionDeprecatedIn10_10 ( ) { <nl> + let _ = ClassDeprecatedIn10_10 ( ) <nl> + } <nl> + <nl> + func hasParameterDeprecatedIn10_10 ( p : ClassDeprecatedIn10_10 ) { / / expected - warning { { ClassDeprecatedIn10_10 ' was deprecated in OS X 10 . 10 } } <nl> + } <nl> + <nl> + @ availability ( OSX , introduced = 10 . 8 , deprecated = 10 . 10 ) <nl> + func annotatedHasParameterDeprecatedIn10_10 ( p : ClassDeprecatedIn10_10 ) { <nl> + } <nl> + <nl> + func hasReturnDeprecatedIn10_10 ( ) - > ClassDeprecatedIn10_10 { / / expected - warning { { ClassDeprecatedIn10_10 ' was deprecated in OS X 10 . 10 } } <nl> + } <nl> + <nl> + @ availability ( OSX , introduced = 10 . 8 , deprecated = 10 . 10 ) <nl> + func annotatedHasReturnDeprecatedIn10_10 ( ) - > ClassDeprecatedIn10_10 { <nl> + } <nl> + <nl> + var globalWithDeprecatedType : ClassDeprecatedIn10_10 ? = nil / / expected - warning { { ClassDeprecatedIn10_10 ' was deprecated in OS X 10 . 10 } } <nl> + <nl> + @ availability ( OSX , introduced = 10 . 8 , deprecated = 10 . 10 ) <nl> + var annotatedGlobalWithDeprecatedType : ClassDeprecatedIn10_10 ? = nil <nl> + <nl> + <nl> + enum EnumWithDeprecatedCasePayload { <nl> + case WithDeprecatedPayload ( p : ClassDeprecatedIn10_10 ) / / expected - warning { { ClassDeprecatedIn10_10 ' was deprecated in OS X 10 . 10 } } <nl> + <nl> + @ availability ( OSX , introduced = 10 . 8 , deprecated = 10 . 10 ) <nl> + case AnnotatedWithDeprecatedPayload ( p : ClassDeprecatedIn10_10 ) <nl> + } <nl> + <nl> + extension ClassDeprecatedIn10_10 { / / expected - warning { { ' ClassDeprecatedIn10_10 ' was deprecated in OS X 10 . 10 } } <nl> + <nl> + } <nl> + <nl> + @ availability ( OSX , introduced = 10 . 8 , deprecated = 10 . 10 ) <nl> + extension ClassDeprecatedIn10_10 { <nl> + func methodInExtensionOfClassDeprecatedIn10_10 ( ) { <nl> + } <nl> + } <nl> + <nl> + func callMethodInDeprecatedExtension ( ) { <nl> + let o = ClassDeprecatedIn10_10 ( ) / / expected - warning { { ' ClassDeprecatedIn10_10 ' was deprecated in OS X 10 . 10 } } <nl> + <nl> + o . methodInExtensionOfClassDeprecatedIn10_10 ( ) / / expected - warning { { ' methodInExtensionOfClassDeprecatedIn10_10 ( ) ' was deprecated in OS X 10 . 10 } } <nl> + } <nl>
Sema : Do not emit deprecation warnings for references inside deprecated declarations
apple/swift
3422577752bbd8e703313d36ef37da24c9adc2cb
2015-03-29T06:54:26Z
mmm a / client / dbclient . cpp <nl> ppp b / client / dbclient . cpp <nl> namespace mongo { <nl> say ( toSend ) ; <nl> } <nl> <nl> + void DBClientBase : : insert ( const char * ns , const vector < BSONObj > & v ) { <nl> + Message toSend ; <nl> + <nl> + BufBuilder b ; <nl> + int opts = 0 ; <nl> + b . append ( opts ) ; <nl> + b . append ( ns ) ; <nl> + for ( vector < BSONObj > : : const_iterator i = v . begin ( ) ; i ! = v . end ( ) ; + + i ) <nl> + i - > appendSelfToBufBuilder ( b ) ; <nl> + <nl> + toSend . setData ( dbInsert , b . buf ( ) , b . len ( ) ) ; <nl> + <nl> + say ( toSend ) ; <nl> + } <nl> + <nl> void DBClientBase : : remove ( const char * ns , BSONObj obj , bool justOne ) { <nl> Message toSend ; <nl> <nl> mmm a / client / dbclient . h <nl> ppp b / client / dbclient . h <nl> namespace mongo { <nl> <nl> virtual BSONObj findOne ( const char * ns , BSONObj query , BSONObj * fieldsToReturn = 0 , int queryOptions = 0 ) = 0 ; <nl> <nl> - virtual void insert ( const char * ns , BSONObj obj ) = 0 ; <nl> + virtual void insert ( const char * ns , BSONObj obj ) = 0 ; <nl> + <nl> + virtual void insert ( const char * ns , const vector < BSONObj > & v ) = 0 ; <nl> <nl> / / virtual void remove ( const char * ns , BSONObj obj , bool justOne = 0 ) = 0 ; <nl> <nl> - / / virtual void update ( const char * ns , BSONObj query , BSONObj obj , bool upsert = 0 ) = 0 ; <nl> + virtual void update ( const char * ns , BSONObj query , BSONObj obj , bool upsert = 0 ) = 0 ; <nl> } ; <nl> <nl> / * * <nl> namespace mongo { <nl> * / <nl> virtual void insert ( const char * ns , BSONObj obj ) ; <nl> <nl> + / * * <nl> + insert a vector of objects into the database <nl> + * / <nl> + virtual void insert ( const char * ns , const vector < BSONObj > & v ) ; <nl> <nl> / * * <nl> remove matching objects from the database <nl> namespace mongo { <nl> virtual <nl> BSONObj findOne ( const char * ns , BSONObj query , BSONObj * fieldsToReturn = 0 , int queryOptions = 0 ) ; <nl> <nl> - / / Not implemented <nl> + / / Not yet implemented <nl> virtual void insert ( const char * ns , BSONObj obj ) { <nl> assert ( false ) ; <nl> } <nl> <nl> + / / Not yet implemented <nl> + virtual void insert ( const char * ns , const vector < BSONObj > & v ) { <nl> + assert ( false ) ; <nl> + } <nl> + <nl> + / / Not yet implemented <nl> + virtual void update ( const char * ns , BSONObj query , BSONObj obj , bool upsert = 0 ) { <nl> + assert ( false ) ; <nl> + } <nl> + <nl> string toString ( ) ; <nl> <nl> / * notification that we got a " not master " error . <nl>
Add multi - insert and update functions to client interface
mongodb/mongo
e591c7dcc5330d2165e4f7a7e9e6d5a0194ea4a1
2009-01-23T15:10:21Z
mmm a / tests / cpp - tests / Classes / ShaderTest / ShaderTest . cpp <nl> ppp b / tests / cpp - tests / Classes / ShaderTest / ShaderTest . cpp <nl> bool SpriteBlur : : initWithTexture ( Texture2D * texture , const Rect & rect ) <nl> <nl> void SpriteBlur : : initGLProgram ( ) <nl> { <nl> - GLchar * fragSource = nullptr ; <nl> + GLchar * fragSource = nullptr ; <nl> # if ( CC_TARGET_PLATFORM ! = CC_PLATFORM_WINRT ) <nl> fragSource = ( GLchar * ) String : : createWithContentsOfFile ( <nl> FileUtils : : getInstance ( ) - > fullPathForFilename ( " Shaders / example_Blur . fsh " ) . c_str ( ) ) - > getCString ( ) ; <nl> # else <nl> - fragSource = ( GLchar * ) String : : createWithContentsOfFile ( <nl> + fragSource = ( GLchar * ) String : : createWithContentsOfFile ( <nl> FileUtils : : getInstance ( ) - > fullPathForFilename ( " Shaders / example_Blur_winrt . fsh " ) . c_str ( ) ) - > getCString ( ) ; <nl> # endif <nl> - auto program = GLProgram : : createWithByteArrays ( ccPositionTextureColor_noMVP_vert , fragSource ) ; <nl> + auto program = GLProgram : : createWithByteArrays ( ccPositionTextureColor_noMVP_vert , fragSource ) ; <nl> <nl> auto glProgramState = GLProgramState : : getOrCreateWithGLProgram ( program ) ; <nl> setGLProgramState ( glProgramState ) ; <nl> mmm a / tests / cpp - tests / Classes / ShaderTest / ShaderTest2 . cpp <nl> ppp b / tests / cpp - tests / Classes / ShaderTest / ShaderTest2 . cpp <nl> void EffectBlur : : setTarget ( EffectSprite * sprite ) <nl> { <nl> Size size = sprite - > getTexture ( ) - > getContentSizeInPixels ( ) ; <nl> _glprogramstate - > setUniformVec2 ( " resolution " , size ) ; <nl> + # if ( CC_TARGET_PLATFORM ! = CC_PLATFORM_WINRT ) <nl> _glprogramstate - > setUniformFloat ( " blurRadius " , _blurRadius ) ; <nl> _glprogramstate - > setUniformFloat ( " sampleNum " , _blurSampleNum ) ; <nl> + # endif <nl> } <nl> <nl> bool EffectBlur : : init ( float blurRadius , float sampleNum ) <nl> { <nl> + # if ( CC_TARGET_PLATFORM ! = CC_PLATFORM_WINRT ) <nl> initGLProgramState ( " Shaders / example_Blur . fsh " ) ; <nl> + # else <nl> + initGLProgramState ( " Shaders / example_Blur_winrt . fsh " ) ; <nl> + # endif <nl> _blurRadius = blurRadius ; <nl> _blurSampleNum = sampleNum ; <nl> <nl>
fix blur sprite shader on win8 universal .
cocos2d/cocos2d-x
647848e843c6480e9cd97e33135b2027c347d8d8
2015-07-24T13:04:44Z
mmm a / configure . ac <nl> ppp b / configure . ac <nl> case $ { OS } in <nl> mv qa / pull - tester / tests_config - 2 . py qa / pull - tester / tests_config . py <nl> ; ; <nl> esac <nl> + <nl> + echo <nl> + echo " Options used to compile and link : " <nl> + echo " with wallet = $ enable_wallet " <nl> + echo " with gui / qt = $ bitcoin_enable_qt " <nl> + if test x $ bitcoin_enable_qt ! = xno ; then <nl> + echo " qt version = $ bitcoin_qt_got_major_vers " <nl> + echo " with qr = $ use_qr " <nl> + fi <nl> + echo " with zmq = $ use_zmq " <nl> + echo " with test = $ use_tests " <nl> + echo " with bench = $ use_bench " <nl> + echo " with upnp = $ use_upnp " <nl> + echo " debug enabled = $ enable_debug " <nl> + echo <nl> + echo " target os = $ TARGET_OS " <nl> + echo " build os = $ BUILD_OS " <nl> + echo <nl> + echo " CC = $ CC " <nl> + echo " CFLAGS = $ CFLAGS " <nl> + echo " CPPFLAGS = $ CPPFLAGS " <nl> + echo " CXX = $ CXX " <nl> + echo " CXXFLAGS = $ CXXFLAGS " <nl> + echo " LDFLAGS = $ LDFLAGS " <nl> + echo <nl>
Merge : Add compile and link options echo to configure
bitcoin/bitcoin
a8b2a82618bec43977a65c076f691ec1cddd54be
2016-11-17T15:05:56Z
mmm a / src / video_core / renderer_base . cpp <nl> ppp b / src / video_core / renderer_base . cpp <nl> <nl> # include " core / frontend / emu_window . h " <nl> # include " core / settings . h " <nl> # include " video_core / renderer_base . h " <nl> - # include " video_core / renderer_opengl / gl_rasterizer . h " <nl> <nl> namespace VideoCore { <nl> <nl>
Merge pull request from lioncash / base
yuzu-emu/yuzu
d2b2b05b6a180195fd3b1b973aa50c0123586c76
2018-11-14T02:53:59Z