@@ -414,6 +414,14 @@ fn (mut g Gen) get_embed_field_name(field_type ast.Type, field_name string) stri
414414 return s
415415}
416416
417+ fn (mut g Gen) init_shared_field (field ast.StructField) {
418+ field_typ := field.typ.deref ()
419+ shared_styp := g.styp (field_typ)
420+ g.write ('(${shared_styp }*)__dup${shared_styp }(&(${shared_styp }){.mtx= {0}, .val=' )
421+ g.write (g.type_default (field_typ.clear_flag (.shared_f)))
422+ g.write ('}, sizeof(${shared_styp }))' )
423+ }
424+
417425fn (mut g Gen) zero_struct_field (field ast.StructField) bool {
418426 old_inside_cast_in_heap := g.inside_cast_in_heap
419427 g.inside_cast_in_heap = 0
@@ -428,6 +436,11 @@ fn (mut g Gen) zero_struct_field(field ast.StructField) bool {
428436 return false
429437 } else if ! field.has_default_expr {
430438 mut has_option_field := false
439+ if sym.info.is_shared || field.typ.has_flag (.shared_f) {
440+ g.write ('.${field_name } = ' )
441+ g.init_shared_field (field)
442+ return true
443+ }
431444 for fd in sym.info.fields {
432445 if fd.typ.has_flag (.option) {
433446 has_option_field = true
@@ -520,6 +533,8 @@ fn (mut g Gen) zero_struct_field(field ast.StructField) bool {
520533 }
521534 }
522535 g.write ('}' )
536+ } else if field.typ.has_flag (.shared_f) {
537+ g.init_shared_field (field)
523538 } else {
524539 g.write (g.type_default (field.typ))
525540 }
@@ -570,7 +585,11 @@ fn (mut g Gen) struct_decl(s ast.Struct, name string, is_anon bool) {
570585 }
571586 }
572587 if is_anon {
573- g.type_definitions.write_string ('\t ${name } ' )
588+ if s.is_shared {
589+ g.type_definitions.write_string ('\t __shared__${name }* ' )
590+ } else {
591+ g.type_definitions.write_string ('\t ${name } ' )
592+ }
574593 return
575594 } else if s.is_union {
576595 if g.is_cc_msvc && aligned_attr != '' {
0 commit comments