What if you remove lines 33-35? Does it panic?

Maybe some other init function fills testFunctionsMap?
For maps, use a nil check before creation, not length check!

2020. január 21., kedd 14:24:27 UTC+1 időpontban Graham Nicholls a 
következőt írta:
>
> I have the following code:
>
>   3 /*
>   4   selinux.go - return the sestatus
>   5
>   6
>   7   The lines below are preamble to the import of "C" -
>   8   they should be left untouched
>   9 */
>  10
>  11 // //cgo  linux CFLAGS: -Iinclude -I.
>  12 // #cgo pkg-config: libselinux
>  13 // #include <selinux/selinux.h>
>  14 // #include <selinux/label.h>
>  15 // #include <stdlib.h>
>  16 // #include <stdio.h>
>  17 // #include <sys/types.h>
>  18 // #include <sys/stat.h>
>  19
>  20 import "C"
>  21 import (
>  22   "fmt"
>  23   "net/http"
>  24 )
>  25
>  26 const (
>  27   Enforcing  = 1
>  28   Permissive = 0
>  29   Disabled   = -1
>  30 )
>  31
>  32 func init() {
>  33   if len(testFunctionsMap) == 0 {
>  34     testFunctionsMap = make(funcPtrMap)
>  35   }
>  36   testFunctionsMap["selinux"] = SELinuxStatus
>  37   initCtr++
>  38 }
>
> The program also has several other files all in package main. The init 
> functions in those files do get called; this init function doesn't - 
> "selinux" never gets added to the testFunctionsMap.
>
> This used to work - I think on 1.9 was the previous version.  I've looked 
> at the release notes, and it seems that work has been done on cgo - but I 
> can't see anything which might explain this behaviour.  
>
> Thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4da0547c-bd60-4c0e-a816-47ba01871c98%40googlegroups.com.

Reply via email to