Re: [PATCH v4] builtin/gc: correct total_ram calculation with HAVE_BSD_SYSCTL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Carlo Marcelo Arenas Belón <carenas@xxxxxxxxx> writes:

>  #elif defined(HAVE_BSD_SYSCTL) && (defined(HW_MEMSIZE) || defined(HW_PHYSMEM) || defined(HW_PHYSMEM64))
> -	int64_t physical_memory;
> +	uint64_t physical_memory = 0;
>  	int mib[2];
>  	size_t length;
>  
> @@ -529,9 +529,18 @@ static uint64_t total_ram(void)
>  # else
>  	mib[1] = HW_PHYSMEM;
>  # endif
> -	length = sizeof(int64_t);
> -	if (!sysctl(mib, 2, &physical_memory, &length, NULL, 0))
> +	length = sizeof(physical_memory);
> +	if (!sysctl(mib, 2, &physical_memory, &length, NULL, 0)) {
> +# ifndef __LITTLE_ENDIAN__
> +		if (length == 4) {
> +			unsigned mem;

Don't we guarantee that uint32_t is always available?  If not, we
should and use that type instead of "unsigned", I think.

Also I do not quite see the point of limiting this fallback to
little-endian architectures.  It wouldn't be called from any
performance critical codepaths, would it?

Thanks.

> +			if (!sysctl(mib, 2, &mem, &length, NULL, 0))
> +				physical_memory = mem;
> +		}
> +# endif
>  		return physical_memory;
> +	}
>  #elif defined(GIT_WINDOWS_NATIVE)
>  	MEMORYSTATUSEX memInfo;




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux