ext_php_rs/
flags.rs

1//! Flags and enums used in PHP and the Zend engine.
2
3use bitflags::bitflags;
4
5#[cfg(php81)]
6use crate::ffi::ZEND_ACC_ENUM;
7#[cfg(not(php82))]
8use crate::ffi::ZEND_ACC_REUSE_GET_ITERATOR;
9use crate::ffi::{
10    _IS_BOOL, CONST_CS, CONST_DEPRECATED, CONST_NO_FILE_CACHE, CONST_PERSISTENT, E_COMPILE_ERROR,
11    E_COMPILE_WARNING, E_CORE_ERROR, E_CORE_WARNING, E_DEPRECATED, E_ERROR, E_NOTICE, E_PARSE,
12    E_RECOVERABLE_ERROR, E_STRICT, E_USER_DEPRECATED, E_USER_ERROR, E_USER_NOTICE, E_USER_WARNING,
13    E_WARNING, IS_ARRAY, IS_CALLABLE, IS_CONSTANT_AST, IS_DOUBLE, IS_FALSE, IS_INDIRECT,
14    IS_ITERABLE, IS_LONG, IS_MIXED, IS_NULL, IS_OBJECT, IS_PTR, IS_REFERENCE, IS_RESOURCE,
15    IS_STRING, IS_TRUE, IS_TYPE_COLLECTABLE, IS_TYPE_REFCOUNTED, IS_UNDEF, IS_VOID, PHP_INI_ALL,
16    PHP_INI_PERDIR, PHP_INI_SYSTEM, PHP_INI_USER, Z_TYPE_FLAGS_SHIFT, ZEND_ACC_ABSTRACT,
17    ZEND_ACC_ANON_CLASS, ZEND_ACC_CALL_VIA_TRAMPOLINE, ZEND_ACC_CHANGED, ZEND_ACC_CLOSURE,
18    ZEND_ACC_CONSTANTS_UPDATED, ZEND_ACC_CTOR, ZEND_ACC_DEPRECATED, ZEND_ACC_DONE_PASS_TWO,
19    ZEND_ACC_EARLY_BINDING, ZEND_ACC_FAKE_CLOSURE, ZEND_ACC_FINAL, ZEND_ACC_GENERATOR,
20    ZEND_ACC_HAS_FINALLY_BLOCK, ZEND_ACC_HAS_RETURN_TYPE, ZEND_ACC_HAS_TYPE_HINTS,
21    ZEND_ACC_HEAP_RT_CACHE, ZEND_ACC_IMMUTABLE, ZEND_ACC_IMPLICIT_ABSTRACT_CLASS,
22    ZEND_ACC_INTERFACE, ZEND_ACC_LINKED, ZEND_ACC_NEARLY_LINKED, ZEND_ACC_NEVER_CACHE,
23    ZEND_ACC_NO_DYNAMIC_PROPERTIES, ZEND_ACC_PRELOADED, ZEND_ACC_PRIVATE, ZEND_ACC_PROMOTED,
24    ZEND_ACC_PROTECTED, ZEND_ACC_PUBLIC, ZEND_ACC_RESOLVED_INTERFACES, ZEND_ACC_RESOLVED_PARENT,
25    ZEND_ACC_RETURN_REFERENCE, ZEND_ACC_STATIC, ZEND_ACC_STRICT_TYPES, ZEND_ACC_TOP_LEVEL,
26    ZEND_ACC_TRAIT, ZEND_ACC_TRAIT_CLONE, ZEND_ACC_UNRESOLVED_VARIANCE, ZEND_ACC_USE_GUARDS,
27    ZEND_ACC_USES_THIS, ZEND_ACC_VARIADIC, ZEND_EVAL_CODE, ZEND_HAS_STATIC_IN_METHODS,
28    ZEND_INTERNAL_FUNCTION, ZEND_USER_FUNCTION,
29};
30
31use std::{convert::TryFrom, fmt::Display};
32
33use crate::error::{Error, Result};
34
35bitflags! {
36    /// Flags used for setting the type of Zval.
37    #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
38    pub struct ZvalTypeFlags: u32 {
39        /// Undefined
40        const Undef = IS_UNDEF;
41        /// Null
42        const Null = IS_NULL;
43        /// `false`
44        const False = IS_FALSE;
45        /// `true`
46        const True = IS_TRUE;
47        /// Integer
48        const Long = IS_LONG;
49        /// Floating point number
50        const Double = IS_DOUBLE;
51        /// String
52        const String = IS_STRING;
53        /// Array
54        const Array = IS_ARRAY;
55        /// Object
56        const Object = IS_OBJECT;
57        /// Resource
58        const Resource = IS_RESOURCE;
59        /// Reference
60        const Reference = IS_REFERENCE;
61        /// Callable
62        const Callable = IS_CALLABLE;
63        /// Constant expression
64        const ConstantExpression = IS_CONSTANT_AST;
65        /// Void
66        const Void = IS_VOID;
67        /// Pointer
68        const Ptr = IS_PTR;
69        /// Iterable
70        const Iterable = IS_ITERABLE;
71
72        /// Interned string extended
73        const InternedStringEx = Self::String.bits();
74        /// String extended
75        const StringEx = Self::String.bits() | Self::RefCounted.bits();
76        /// Array extended
77        const ArrayEx = Self::Array.bits() | Self::RefCounted.bits() | Self::Collectable.bits();
78        /// Object extended
79        const ObjectEx = Self::Object.bits() | Self::RefCounted.bits() | Self::Collectable.bits();
80        /// Resource extended
81        const ResourceEx = Self::Resource.bits() | Self::RefCounted.bits();
82        /// Reference extended
83        const ReferenceEx = Self::Reference.bits() | Self::RefCounted.bits();
84        /// Constant ast extended
85        const ConstantAstEx = Self::ConstantExpression.bits() | Self::RefCounted.bits();
86
87        /// Reference counted
88        const RefCounted = (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT);
89        /// Collectable
90        const Collectable = (IS_TYPE_COLLECTABLE << Z_TYPE_FLAGS_SHIFT);
91    }
92}
93
94bitflags! {
95    /// Flags for building classes.
96    #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
97    pub struct ClassFlags: u32 {
98        /// Final class or method
99        const Final = ZEND_ACC_FINAL;
100        /// Abstract method
101        const Abstract = ZEND_ACC_ABSTRACT;
102        /// Immutable `op_array` and class_entries
103        /// (implemented only for lazy loading of `op_array`s)
104        const Immutable = ZEND_ACC_IMMUTABLE;
105        /// Function has typed arguments / class has typed props
106        const HasTypeHints = ZEND_ACC_HAS_TYPE_HINTS;
107        /// Top-level class or function declaration
108        const TopLevel = ZEND_ACC_TOP_LEVEL;
109        /// op_array or class is preloaded
110        const Preloaded = ZEND_ACC_PRELOADED;
111
112        /// Class entry is an interface
113        const Interface = ZEND_ACC_INTERFACE;
114        /// Class entry is a trait
115        const Trait = ZEND_ACC_TRAIT;
116        /// Anonymous class
117        const AnonymousClass = ZEND_ACC_ANON_CLASS;
118        /// Class is an Enum
119        #[cfg(php81)]
120        const Enum = ZEND_ACC_ENUM;
121        /// Class linked with parent, interfaces and traits
122        const Linked = ZEND_ACC_LINKED;
123        /// Class is abstract, since it is set by any abstract method
124        const ImplicitAbstractClass = ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
125        /// Class has magic methods `__get`/`__set`/`__unset`/`__isset` that use guards
126        const UseGuards = ZEND_ACC_USE_GUARDS;
127
128        /// Class constants updated
129        const ConstantsUpdated = ZEND_ACC_CONSTANTS_UPDATED;
130        /// Objects of this class may not have dynamic properties
131        const NoDynamicProperties = ZEND_ACC_NO_DYNAMIC_PROPERTIES;
132        /// User class has methods with static variables
133        const HasStaticInMethods = ZEND_HAS_STATIC_IN_METHODS;
134        /// Children must reuse parent `get_iterator()`
135        #[cfg(not(php82))]
136        const ReuseGetIterator = ZEND_ACC_REUSE_GET_ITERATOR;
137        /// Parent class is resolved (CE)
138        const ResolvedParent = ZEND_ACC_RESOLVED_PARENT;
139        /// Interfaces are resolved (CE)
140        const ResolvedInterfaces = ZEND_ACC_RESOLVED_INTERFACES;
141        /// Class has unresolved variance obligations
142        const UnresolvedVariance = ZEND_ACC_UNRESOLVED_VARIANCE;
143        /// Class is linked apart from variance obligations
144        const NearlyLinked = ZEND_ACC_NEARLY_LINKED;
145
146        /// Class cannot be serialized or unserialized
147        #[cfg(php81)]
148        const NotSerializable = crate::ffi::ZEND_ACC_NOT_SERIALIZABLE;
149    }
150}
151
152bitflags! {
153    /// Flags for building methods.
154    #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
155    pub struct MethodFlags: u32 {
156        /// Visibility public
157        const Public = ZEND_ACC_PUBLIC;
158        /// Visibility protected
159        const Protected = ZEND_ACC_PROTECTED;
160        /// Visibility private
161        const Private = ZEND_ACC_PRIVATE;
162        /// Method or property overrides private one
163        const Changed = ZEND_ACC_CHANGED;
164        /// Static method
165        const Static = ZEND_ACC_STATIC;
166        /// Final method
167        const Final = ZEND_ACC_FINAL;
168        /// Abstract method
169        const Abstract = ZEND_ACC_ABSTRACT;
170        /// Immutable `op_array` and class_entries
171        /// (implemented only for lazy loading of op_arrays)
172        const Immutable = ZEND_ACC_IMMUTABLE;
173        /// Function has typed arguments / class has typed props
174        const HasTypeHints = ZEND_ACC_HAS_TYPE_HINTS;
175        /// Top-level class or function declaration
176        const TopLevel = ZEND_ACC_TOP_LEVEL;
177        /// `op_array` or class is preloaded
178        const Preloaded = ZEND_ACC_PRELOADED;
179
180        /// Deprecation flag
181        const Deprecated = ZEND_ACC_DEPRECATED;
182        /// Function returning by reference
183        const ReturnReference = ZEND_ACC_RETURN_REFERENCE;
184        /// Function has a return type
185        const HasReturnType = ZEND_ACC_HAS_RETURN_TYPE;
186        /// Function with variable number of arguments
187        const Variadic = ZEND_ACC_VARIADIC;
188        /// `op_array` has finally blocks (user only)
189        const HasFinallyBlock = ZEND_ACC_HAS_FINALLY_BLOCK;
190        /// "main" `op_array` with `ZEND_DECLARE_CLASS_DELAYED` opcodes
191        const EarlyBinding = ZEND_ACC_EARLY_BINDING;
192        /// Closure uses `$this`
193        const UsesThis = ZEND_ACC_USES_THIS;
194        /// Call through user function trampoline
195        ///
196        /// # Example
197        /// - `__call`
198        /// - `__callStatic`
199        const CallViaTrampoline = ZEND_ACC_CALL_VIA_TRAMPOLINE;
200        /// Disable inline caching
201        const NeverCache = ZEND_ACC_NEVER_CACHE;
202        /// `op_array` is a clone of trait method
203        const TraitClone = ZEND_ACC_TRAIT_CLONE;
204        /// Function is a constructor
205        const IsConstructor = ZEND_ACC_CTOR;
206        /// Function is a closure
207        const Closure = ZEND_ACC_CLOSURE;
208        /// Function is a fake closure
209        const FakeClosure = ZEND_ACC_FAKE_CLOSURE;
210        /// Function is a generator
211        const Generator = ZEND_ACC_GENERATOR;
212        /// Function was processed by pass two (user only)
213        const DonePassTwo = ZEND_ACC_DONE_PASS_TWO;
214        /// `run_time_cache` allocated on heap (user only)
215        const HeapRTCache = ZEND_ACC_HEAP_RT_CACHE;
216        /// `op_array` uses strict mode types
217        const StrictTypes = ZEND_ACC_STRICT_TYPES;
218    }
219}
220
221bitflags! {
222    /// Flags for building properties.
223    #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
224    pub struct PropertyFlags: u32 {
225        /// Visibility public
226        const Public = ZEND_ACC_PUBLIC;
227        /// Visibility protected
228        const Protected = ZEND_ACC_PROTECTED;
229        /// Visibility private
230        const Private = ZEND_ACC_PRIVATE;
231        /// Property or method overrides private one
232        const Changed = ZEND_ACC_CHANGED;
233        /// Static property
234        const Static = ZEND_ACC_STATIC;
235        /// Promoted property
236        const Promoted = ZEND_ACC_PROMOTED;
237    }
238}
239
240bitflags! {
241    /// Flags for building constants.
242    #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
243    pub struct ConstantFlags: u32 {
244        /// Visibility public
245        const Public = ZEND_ACC_PUBLIC;
246        /// Visibility protected
247        const Protected = ZEND_ACC_PROTECTED;
248        /// Visibility private
249        const Private = ZEND_ACC_PRIVATE;
250        /// Promoted constant
251        const Promoted = ZEND_ACC_PROMOTED;
252    }
253}
254
255bitflags! {
256    /// Flags for building module global constants.
257    #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
258    pub struct GlobalConstantFlags: u32 {
259        /// No longer used -- always case-sensitive
260        #[deprecated(note = "No longer used -- always case-sensitive")]
261        const CaseSensitive = CONST_CS;
262        /// Persistent
263        const Persistent = CONST_PERSISTENT;
264        /// Can't be saved in file cache
265        const NoFileCache = CONST_NO_FILE_CACHE;
266        /// Deprecated (this flag is not deprecated, it literally means the constant is deprecated)
267        const Deprecated = CONST_DEPRECATED;
268    }
269}
270
271bitflags! {
272    /// Represents the result of a function.
273    #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
274    pub struct ZendResult: i32 {
275        /// Function call was successful.
276        const Success = 0;
277        /// Function call failed.
278        const Failure = -1;
279    }
280}
281
282bitflags! {
283    /// Represents permissions for where a configuration setting may be set.
284    pub struct IniEntryPermission: u32 {
285        /// User
286        const User = PHP_INI_USER;
287        /// Per directory
288        const PerDir = PHP_INI_PERDIR;
289        /// System
290        const System = PHP_INI_SYSTEM;
291        /// All
292        const All = PHP_INI_ALL;
293    }
294}
295
296bitflags! {
297    /// Represents error types when used via php_error_docref for example.
298    pub struct ErrorType: u32 {
299        /// Error
300        const Error = E_ERROR;
301        /// Warning
302        const Warning = E_WARNING;
303        /// Parse
304        const Parse = E_PARSE;
305        /// Notice
306        const Notice = E_NOTICE;
307        /// Core error
308        const CoreError = E_CORE_ERROR;
309        /// Core warning
310        const CoreWarning = E_CORE_WARNING;
311        /// Compile error
312        const CompileError = E_COMPILE_ERROR;
313        /// Compile warning
314        const CompileWarning = E_COMPILE_WARNING;
315        /// User error
316        #[cfg_attr(php84, deprecated = "`E_USER_ERROR` is deprecated since PHP 8.4. Throw an exception instead.")]
317        const UserError = E_USER_ERROR;
318        /// User warning
319        const UserWarning = E_USER_WARNING;
320        /// User notice
321        const UserNotice = E_USER_NOTICE;
322        /// Strict
323        const Strict = E_STRICT;
324        /// Recoverable error
325        const RecoverableError = E_RECOVERABLE_ERROR;
326        /// Deprecated
327        const Deprecated = E_DEPRECATED;
328        /// User deprecated
329        const UserDeprecated = E_USER_DEPRECATED;
330    }
331}
332
333/// Represents the type of a function.
334#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
335pub enum FunctionType {
336    /// Internal function
337    Internal,
338    /// User function
339    User,
340    /// Eval code
341    Eval,
342}
343
344impl From<u8> for FunctionType {
345    #[allow(clippy::bad_bit_mask)]
346    fn from(value: u8) -> Self {
347        match value.into() {
348            ZEND_INTERNAL_FUNCTION => Self::Internal,
349            ZEND_USER_FUNCTION => Self::User,
350            ZEND_EVAL_CODE => Self::Eval,
351            _ => panic!("Unknown function type: {value}"),
352        }
353    }
354}
355
356/// Valid data types for PHP.
357#[repr(C, u8)]
358#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
359pub enum DataType {
360    /// Undefined
361    Undef,
362    /// `null`
363    Null,
364    /// `false`
365    False,
366    /// `true`
367    True,
368    /// Integer (the irony)
369    Long,
370    /// Floating point number
371    Double,
372    /// String
373    String,
374    /// Array
375    Array,
376    /// Iterable
377    Iterable,
378    /// Object
379    Object(Option<&'static str>),
380    /// Resource
381    Resource,
382    /// Reference
383    Reference,
384    /// Callable
385    Callable,
386    /// Constant expression
387    ConstantExpression,
388    /// Void
389    #[default]
390    Void,
391    /// Mixed
392    Mixed,
393    /// Boolean
394    Bool,
395    /// Pointer
396    Ptr,
397    /// Indirect (internal)
398    Indirect,
399}
400
401impl DataType {
402    /// Returns the integer representation of the data type.
403    #[must_use]
404    pub const fn as_u32(&self) -> u32 {
405        match self {
406            DataType::Undef => IS_UNDEF,
407            DataType::Null => IS_NULL,
408            DataType::False => IS_FALSE,
409            DataType::True => IS_TRUE,
410            DataType::Long => IS_LONG,
411            DataType::Double => IS_DOUBLE,
412            DataType::String => IS_STRING,
413            DataType::Array => IS_ARRAY,
414            DataType::Object(_) => IS_OBJECT,
415            DataType::Resource | DataType::Reference => IS_RESOURCE,
416            DataType::Indirect => IS_INDIRECT,
417            DataType::Callable => IS_CALLABLE,
418            DataType::ConstantExpression => IS_CONSTANT_AST,
419            DataType::Void => IS_VOID,
420            DataType::Mixed => IS_MIXED,
421            DataType::Bool => _IS_BOOL,
422            DataType::Ptr => IS_PTR,
423            DataType::Iterable => IS_ITERABLE,
424        }
425    }
426}
427
428// TODO: Ideally want something like this
429// pub struct Type {
430//     data_type: DataType,
431//     is_refcounted: bool,
432//     is_collectable: bool,
433//     is_immutable: bool,
434//     is_persistent: bool,
435// }
436//
437// impl From<u32> for Type { ... }
438
439impl TryFrom<ZvalTypeFlags> for DataType {
440    type Error = Error;
441
442    fn try_from(value: ZvalTypeFlags) -> Result<Self> {
443        macro_rules! contains {
444            ($t: ident) => {
445                if value.contains(ZvalTypeFlags::$t) {
446                    return Ok(DataType::$t);
447                }
448            };
449        }
450
451        contains!(Undef);
452        contains!(Null);
453        contains!(False);
454        contains!(True);
455        contains!(False);
456        contains!(Long);
457        contains!(Double);
458        contains!(String);
459        contains!(Array);
460        contains!(Resource);
461        contains!(Callable);
462        contains!(ConstantExpression);
463        contains!(Void);
464
465        if value.contains(ZvalTypeFlags::Object) {
466            return Ok(DataType::Object(None));
467        }
468
469        Err(Error::UnknownDatatype(0))
470    }
471}
472
473impl From<u32> for DataType {
474    #[allow(clippy::bad_bit_mask)]
475    fn from(value: u32) -> Self {
476        macro_rules! contains {
477            ($c: ident, $t: ident) => {
478                if (value & $c) == $c {
479                    return DataType::$t;
480                }
481            };
482        }
483
484        contains!(IS_VOID, Void);
485        contains!(IS_PTR, Ptr);
486        contains!(IS_INDIRECT, Indirect);
487        contains!(IS_CALLABLE, Callable);
488        contains!(IS_CONSTANT_AST, ConstantExpression);
489        contains!(IS_REFERENCE, Reference);
490        contains!(IS_RESOURCE, Resource);
491        contains!(IS_ARRAY, Array);
492        contains!(IS_STRING, String);
493        contains!(IS_DOUBLE, Double);
494        contains!(IS_LONG, Long);
495        contains!(IS_TRUE, True);
496        contains!(IS_FALSE, False);
497        contains!(IS_NULL, Null);
498
499        if (value & IS_OBJECT) == IS_OBJECT {
500            return DataType::Object(None);
501        }
502
503        contains!(IS_UNDEF, Undef);
504
505        DataType::Mixed
506    }
507}
508
509impl Display for DataType {
510    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
511        match self {
512            DataType::Undef => write!(f, "Undefined"),
513            DataType::Null => write!(f, "Null"),
514            DataType::False => write!(f, "False"),
515            DataType::True => write!(f, "True"),
516            DataType::Long => write!(f, "Long"),
517            DataType::Double => write!(f, "Double"),
518            DataType::String => write!(f, "String"),
519            DataType::Array => write!(f, "Array"),
520            DataType::Object(obj) => write!(f, "{}", obj.as_deref().unwrap_or("Object")),
521            DataType::Resource => write!(f, "Resource"),
522            DataType::Reference => write!(f, "Reference"),
523            DataType::Callable => write!(f, "Callable"),
524            DataType::ConstantExpression => write!(f, "Constant Expression"),
525            DataType::Void => write!(f, "Void"),
526            DataType::Bool => write!(f, "Bool"),
527            DataType::Mixed => write!(f, "Mixed"),
528            DataType::Ptr => write!(f, "Pointer"),
529            DataType::Indirect => write!(f, "Indirect"),
530            DataType::Iterable => write!(f, "Iterable"),
531        }
532    }
533}
534
535#[cfg(test)]
536mod tests {
537    #![allow(clippy::unnecessary_fallible_conversions)]
538    use super::DataType;
539    use crate::ffi::{
540        IS_ARRAY, IS_ARRAY_EX, IS_CONSTANT_AST, IS_CONSTANT_AST_EX, IS_DOUBLE, IS_FALSE,
541        IS_INDIRECT, IS_INTERNED_STRING_EX, IS_LONG, IS_NULL, IS_OBJECT, IS_OBJECT_EX, IS_PTR,
542        IS_REFERENCE, IS_REFERENCE_EX, IS_RESOURCE, IS_RESOURCE_EX, IS_STRING, IS_STRING_EX,
543        IS_TRUE, IS_UNDEF, IS_VOID,
544    };
545    use std::convert::TryFrom;
546
547    #[test]
548    fn test_datatype() {
549        macro_rules! test {
550            ($c: ident, $t: ident) => {
551                assert_eq!(DataType::try_from($c), Ok(DataType::$t));
552            };
553        }
554
555        test!(IS_UNDEF, Undef);
556        test!(IS_NULL, Null);
557        test!(IS_FALSE, False);
558        test!(IS_TRUE, True);
559        test!(IS_LONG, Long);
560        test!(IS_DOUBLE, Double);
561        test!(IS_STRING, String);
562        test!(IS_ARRAY, Array);
563        assert_eq!(DataType::try_from(IS_OBJECT), Ok(DataType::Object(None)));
564        test!(IS_RESOURCE, Resource);
565        test!(IS_REFERENCE, Reference);
566        test!(IS_CONSTANT_AST, ConstantExpression);
567        test!(IS_INDIRECT, Indirect);
568        test!(IS_VOID, Void);
569        test!(IS_PTR, Ptr);
570
571        test!(IS_INTERNED_STRING_EX, String);
572        test!(IS_STRING_EX, String);
573        test!(IS_ARRAY_EX, Array);
574        assert_eq!(DataType::try_from(IS_OBJECT_EX), Ok(DataType::Object(None)));
575        test!(IS_RESOURCE_EX, Resource);
576        test!(IS_REFERENCE_EX, Reference);
577        test!(IS_CONSTANT_AST_EX, ConstantExpression);
578    }
579}