On Wed, 18 Jul 2012, Andy Dougherty wrote:
> On Tue, 17 Jul 2012, Jonathan "Duke" Leto wrote:
>
> > Howdy,
> >
> > It looks like Parrot_get_cpu_type is only defined in
> > src/platform/generic/misc.c and src/platform/win32/misc.c but not
> > src/platform/netbsd/misc.c .
> >
> > Not sure if that is the issue, but it seems likely.
>
> Yes, that would explain it. The "correct" way to have done it, within
> parrot's src/platform hierarchy, would have been to make two new files,
> something like generic/cpu_type.c and win32/cpu_type.c, along with the
> appropriate tweaks to MANIFEST and the root Makefile. Then no special
> NetBSD tweaks would be needed.
The attached patch implements this. I tested it on Linux and NetBSD. I
have not tested it on Windows.
--
Andy Dougherty [email protected]From 4a9093f70128746e87f00bb047485eae7e379294 Mon Sep 17 00:00:00 2001
From: Andrew Dougherty <[email protected]>
Date: Fri, 3 Aug 2012 13:57:35 -0400
Subject: [PATCH] Move Parrot_cpu_type function out of src/platform/misc.c.
This way, it doesn't need to be repeated elsewhere. For symmetry,
also remove it out of win32/misc.c and give it its own file there as well.
---
MANIFEST | 2 +
config/auto/platform.pm | 1 +
config/gen/makefiles/root.in | 4 ++
src/platform/generic/cpu_type.c | 65 +++++++++++++++++++++++++++++++
src/platform/generic/misc.c | 35 ++---------------
src/platform/netbsd/misc.c | 28 -------------
src/platform/win32/cpu_type.c | 81 +++++++++++++++++++++++++++++++++++++++
src/platform/win32/misc.c | 45 ---------------------
8 files changed, 157 insertions(+), 104 deletions(-)
create mode 100644 src/platform/generic/cpu_type.c
create mode 100644 src/platform/win32/cpu_type.c
diff --git a/MANIFEST b/MANIFEST
index af7cdfa..2ebe04e 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1294,6 +1294,7 @@ src/platform/ansi/time.c []
src/platform/cygwin/math.c []
src/platform/darwin/hires_timer.c []
src/platform/darwin/sysmem.c []
+src/platform/generic/cpu_type.c []
src/platform/generic/dl.c []
src/platform/generic/encoding.c []
src/platform/generic/entropy.c []
@@ -1316,6 +1317,7 @@ src/platform/netbsd/misc.c []
src/platform/openbsd/math.c []
src/platform/solaris/math.c []
src/platform/solaris/time.c []
+src/platform/win32/cpu_type.c []
src/platform/win32/dl.c []
src/platform/win32/entropy.c []
src/platform/win32/env.c []
diff --git a/config/auto/platform.pm b/config/auto/platform.pm
index 922cdab..8d3d703 100644
--- a/config/auto/platform.pm
+++ b/config/auto/platform.pm
@@ -46,6 +46,7 @@ sub _set_implementations {
time.c
encoding.c
env.c
+ cpu_type.c
dl.c
math.c
itimer.c
diff --git a/config/gen/makefiles/root.in b/config/gen/makefiles/root.in
index 178794a..6d423f2 100644
--- a/config/gen/makefiles/root.in
+++ b/config/gen/makefiles/root.in
@@ -1734,6 +1734,8 @@ src/platform/darwin/hires_timer$(O) : src/platform/darwin/hires_timer.c $(PARROT
src/platform/darwin/sysmem$(O) : src/platform/darwin/sysmem.c $(PARROT_H_HEADERS)
+src/platform/generic/cpu_type$(O) : src/platform/generic/cpu_type.c $(PARROT_H_HEADERS)
+
src/platform/generic/dl$(O) : src/platform/generic/dl.c $(PARROT_H_HEADERS)
src/platform/generic/encoding$(O) : src/platform/generic/encoding.c $(PARROT_H_HEADERS)
@@ -1780,6 +1782,8 @@ src/platform/solaris/math$(O) : src/platform/solaris/math.c $(PARROT_H_HEADERS)
src/platform/solaris/time$(O) : src/platform/solaris/time.c $(PARROT_H_HEADERS)
+src/platform/win32/cpu_type$(O) : src/platform/win32/cpu_type.c $(PARROT_H_HEADERS)
+
src/platform/win32/dl$(O) : src/platform/win32/dl.c $(PARROT_H_HEADERS)
src/platform/win32/env$(O) : src/platform/win32/env.c $(PARROT_H_HEADERS)
diff --git a/src/platform/generic/cpu_type.c b/src/platform/generic/cpu_type.c
new file mode 100644
index 0000000..5186100
--- /dev/null
+++ b/src/platform/generic/cpu_type.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2011, Parrot Foundation.
+ */
+
+/*
+
+=head1 NAME
+
+src/platform/generic/cpu_type.c
+
+=head1 DESCRIPTION
+
+Fetch CPU type for non-win32 systems
+For win32, look in platform/win32/cpu_type.c
+
+=head2 Functions
+
+=cut
+
+*/
+
+#include "parrot/parrot.h"
+
+#ifdef PARROT_HAS_HEADER_SYSUTSNAME
+# include <sys/utsname.h>
+#endif
+
+/* HEADERIZER HFILE: none */
+
+/*
+
+=over 4
+
+=item C<STRING *Parrot_get_cpu_type(Parrot_Interp)>
+
+Fetch CPU type for non-win32 systems
+For win32, look in platform/win32/misc.c
+
+=back
+
+=cut
+
+*/
+
+STRING *
+Parrot_get_cpu_type(Parrot_Interp interp) {
+ struct utsname uname_info;
+ char *proc_arch = "";
+
+#ifdef PARROT_HAS_HEADER_SYSUTSNAME
+ uname(&uname_info);
+ proc_arch = uname_info.machine;
+#endif
+ return Parrot_str_new_init(interp, proc_arch, strlen(proc_arch),
+ Parrot_ascii_encoding_ptr, 0);
+
+}
+
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+ */
+
diff --git a/src/platform/generic/misc.c b/src/platform/generic/misc.c
index facf2a8..ee1d600 100644
--- a/src/platform/generic/misc.c
+++ b/src/platform/generic/misc.c
@@ -12,6 +12,10 @@ src/platform/generic/misc.c
Miscellaneous helper functions.
+Please avoid adding to this file. Individual families of functions
+should normally go in individual files. Platform-specific overrides
+then go in the platform-specific directories.
+
=head2 Functions
=cut
@@ -20,10 +24,6 @@ Miscellaneous helper functions.
#include "parrot/parrot.h"
-#ifdef PARROT_HAS_HEADER_SYSUTSNAME
-# include <sys/utsname.h>
-#endif
-
/* HEADERIZER HFILE: none */
/*
@@ -44,33 +44,6 @@ Parrot_platform_init_code(void)
}
/*
-
-=item C<STRING *Parrot_get_cpu_type(Parrot_Interp)>
-
-Fetch CPU type for non-win32 systems
-For win32, look in platform/win32/misc.c
-
-=back
-
-=cut
-
-*/
-
-STRING *
-Parrot_get_cpu_type(Parrot_Interp interp) {
- struct utsname uname_info;
- char *proc_arch = "";
-
-#ifdef PARROT_HAS_HEADER_SYSUTSNAME
- uname(&uname_info);
- proc_arch = uname_info.machine;
-#endif
- return Parrot_str_new_init(interp, proc_arch, strlen(proc_arch),
- Parrot_ascii_encoding_ptr, 0);
-
-}
-
-/*
* Local variables:
* c-file-style: "parrot"
* End:
diff --git a/src/platform/netbsd/misc.c b/src/platform/netbsd/misc.c
index b881c62..db249ba 100644
--- a/src/platform/netbsd/misc.c
+++ b/src/platform/netbsd/misc.c
@@ -22,10 +22,6 @@ Miscellaneous helper functions that are specific to NetBSD.
#include "parrot/parrot.h"
-#ifdef PARROT_HAS_HEADER_SYSUTSNAME
-# include <sys/utsname.h>
-#endif
-
/* HEADERIZER HFILE: none */
/*
@@ -57,30 +53,6 @@ Parrot_platform_init_code(void)
/*
-=item C<STRING *Parrot_get_cpu_type(Parrot_Interp)>
-
-Fetch CPU type.
-
-=cut
-
-*/
-
-STRING *
-Parrot_get_cpu_type(Parrot_Interp interp) {
- struct utsname uname_info;
- char *proc_arch = "";
-
-#ifdef PARROT_HAS_HEADER_SYSUTSNAME
- uname(&uname_info);
- proc_arch = uname_info.machine;
-#endif
- return Parrot_str_new_init(interp, proc_arch, strlen(proc_arch),
- Parrot_ascii_encoding_ptr, 0);
-
-}
-
-/*
-
=back
=cut
diff --git a/src/platform/win32/cpu_type.c b/src/platform/win32/cpu_type.c
new file mode 100644
index 0000000..ea736a0
--- /dev/null
+++ b/src/platform/win32/cpu_type.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2004-2006, Parrot Foundation.
+ */
+
+/*
+
+=head1 NAME
+
+src\platform\win32\cpu_type.c
+
+=head1 DESCRIPTION
+
+Fetch CPU type for win32 systems.
+
+=head2 Functions
+
+=over 4
+
+=cut
+
+*/
+
+#include <ws2tcpip.h>
+#undef CONST
+
+#include "parrot/parrot.h"
+
+/* HEADERIZER HFILE: none */
+
+/*
+
+=item C<STRING * Parrot_get_cpu_type(Parrot_Interp interp)>
+
+Fetch CPU type for win32 systems
+
+=back
+
+=cut
+
+*/
+
+STRING *
+Parrot_get_cpu_type(Parrot_Interp interp) {
+ SYSTEM_INFO sys_info;
+ WORD arch_type;
+ char *proc_arch;
+
+ GetSystemInfo(&sys_info);
+
+ arch_type = sys_info.wProcessorArchitecture;
+ switch (arch_type) {
+ case PROCESSOR_ARCHITECTURE_AMD64:
+ proc_arch = "x64";
+ break;
+ case PROCESSOR_ARCHITECTURE_IA64:
+ proc_arch ="IA64";
+ break;
+ case PROCESSOR_ARCHITECTURE_INTEL:
+ proc_arch ="x86";
+ break;
+ case PROCESSOR_ARCHITECTURE_UNKNOWN:
+ proc_arch ="unknown";
+ break;
+ default:
+ proc_arch ="unknown";
+ break;
+ }
+
+ return Parrot_str_new_init(interp, proc_arch, strlen(proc_arch),
+ Parrot_ascii_encoding_ptr, 0);
+
+}
+
+
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+ */
+
diff --git a/src/platform/win32/misc.c b/src/platform/win32/misc.c
index 35683b4..3e2e57e 100644
--- a/src/platform/win32/misc.c
+++ b/src/platform/win32/misc.c
@@ -56,51 +56,6 @@ Parrot_platform_init_code(void)
}
/*
-
-=item C<STRING * Parrot_get_cpu_type(Parrot_Interp interp)>
-
-Fetch CPU type for win32 systems
-
-=back
-
-=cut
-
-*/
-
-STRING *
-Parrot_get_cpu_type(Parrot_Interp interp) {
- SYSTEM_INFO sys_info;
- WORD arch_type;
- char *proc_arch;
-
- GetSystemInfo(&sys_info);
-
- arch_type = sys_info.wProcessorArchitecture;
- switch (arch_type) {
- case PROCESSOR_ARCHITECTURE_AMD64:
- proc_arch = "x64";
- break;
- case PROCESSOR_ARCHITECTURE_IA64:
- proc_arch ="IA64";
- break;
- case PROCESSOR_ARCHITECTURE_INTEL:
- proc_arch ="x86";
- break;
- case PROCESSOR_ARCHITECTURE_UNKNOWN:
- proc_arch ="unknown";
- break;
- default:
- proc_arch ="unknown";
- break;
- }
-
- return Parrot_str_new_init(interp, proc_arch, strlen(proc_arch),
- Parrot_ascii_encoding_ptr, 0);
-
-}
-
-
-/*
* Local variables:
* c-file-style: "parrot"
* End:
--
1.7.2.5
_______________________________________________
http://lists.parrot.org/mailman/listinfo/parrot-dev