[Git][cmucl/cmucl][issue-120-software-type-in-c] 2 commits: Use static buffer to hold results
Raymond Toy (@rtoy)
gitlab at common-lisp.net
Mon Mar 13 14:35:15 UTC 2023
Raymond Toy pushed to branch issue-120-software-type-in-c at cmucl / cmucl
Commits:
a47e8963 by Raymond Toy at 2023-03-13T07:31:19-07:00
Use static buffer to hold results
Instead of dynamically allocating space to the the results for
`software-type` and `software-version`, use a static string in each
function. Fill the string with desired result and return it.
The Lisp interface needs to be updated not to free the memory now
since it's not dynamically allocated.
- - - - -
98ae551c by Raymond Toy at 2023-03-13T07:33:45-07:00
Update pot files.
The location of the docstrings have moved and have changed, so the pot
files need to be updated.
- - - - -
4 changed files:
- src/code/misc.lisp
- src/i18n/locale/cmucl-linux-os.pot
- src/i18n/locale/cmucl.pot
- src/lisp/os-common.c
Changes:
=====================================
src/code/misc.lisp
=====================================
@@ -199,9 +199,7 @@
(alien:extern-alien "os_software_type"
(function (alien:* c-call:c-string)))))
(unless (zerop (sap-int (alien:alien-sap software-type)))
- (alien:cast software-type c-call:c-string)))
- (when software-type
- (alien:free-alien software-type))))))
+ (alien:cast software-type c-call:c-string)))))))
*software-type*)
(defvar *software-version* nil
@@ -219,9 +217,7 @@
(alien:extern-alien "os_software_version"
(function (alien:* c-call:c-string)))))
(unless (zerop (sap-int (alien:alien-sap version)))
- (alien:cast version c-call:c-string)))
- (when version
- (alien:free-alien version)))))
+ (alien:cast version c-call:c-string))))))
*software-version*))
(defvar *short-site-name* (intl:gettext "Unknown")
=====================================
src/i18n/locale/cmucl-linux-os.pot
=====================================
@@ -15,10 +15,6 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
-#: src/code/linux-os.lisp
-msgid "Returns a string describing version of the supporting software."
-msgstr ""
-
#: src/code/linux-os.lisp
msgid "Unix system call getrusage failed: ~A."
msgstr ""
=====================================
src/i18n/locale/cmucl.pot
=====================================
@@ -5605,14 +5605,14 @@ msgid ""
" NIL if no such character exists."
msgstr ""
-#: src/code/misc.lisp
+#: src/code/misc-doc.lisp src/code/misc.lisp
msgid ""
"Returns the documentation string of Doc-Type for X, or NIL if\n"
" none exists. System doc-types are VARIABLE, FUNCTION, STRUCTURE, TYPE,\n"
" SETF, and T."
msgstr ""
-#: src/code/misc.lisp
+#: src/code/misc-doc.lisp src/code/misc.lisp
msgid "~S is not the name of a structure type."
msgstr ""
@@ -5643,13 +5643,21 @@ msgid "Returns a string giving the name of the local machine."
msgstr ""
#: src/code/misc.lisp
-msgid "The value of SOFTWARE-TYPE. Set in FOO-os.lisp."
+msgid "The value of SOFTWARE-TYPE."
msgstr ""
#: src/code/misc.lisp
msgid "Returns a string describing the supporting software."
msgstr ""
+#: src/code/misc.lisp
+msgid "Version string for supporting software"
+msgstr ""
+
+#: src/code/misc.lisp
+msgid "Returns a string describing version of the supporting software."
+msgstr ""
+
#: src/code/misc.lisp
msgid "The value of SHORT-SITE-NAME. Set in library:site-init.lisp."
msgstr ""
=====================================
src/lisp/os-common.c
=====================================
@@ -817,43 +817,47 @@ os_get_locale_codeset()
#endif
char*
-os_software_version()
+os_software_version(void)
{
- int status;
struct utsname uts;
- char *version = NULL;
+ /*
+ * Buffer large enough to hold the release and version that's used
+ * for Linux and Solaris.
+ */
+ static char result[sizeof(uts.release) + sizeof(uts.version)];
+
+ int status;
status = uname(&uts);
- if (status == 0) {
- int version_length;
+ if (status != 0) {
+ return NULL;
+ }
+
#if defined(UNAME_RELEASE_AND_VERSION)
- version_length = strlen(uts.release) + strlen(uts.version) + 2;
- version = malloc(version_length);
- if (version) {
- strcpy(version, uts.release);
- strcat(version, " ");
- strcat(version, uts.version);
- }
+ strcpy(result, uts.release);
+ strcat(result, " ");
+ strcat(result, uts.version);
#else
- version = strdup(uts.version);
+ strcpy(result, uts.version);
#endif
- }
- return version;
+ return result;
}
#undef UNAME_RELEASE_AND_VERSION
char*
-os_software_type()
+os_software_type(void)
{
int status;
struct utsname uts;
- char *os_name = NULL;
+ static char os_name[sizeof(uts.sysname)];
status = uname(&uts);
- if (status == 0) {
- os_name = strdup(uts.sysname);
+ if (status != 0) {
+ return NULL;
}
+
+ strcpy(os_name, uts.sysname);
return os_name;
}
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/d8f99abf569c7ae830abeb2b08f6f52b910a4b78...98ae551c8d398259c1168f3a80605dd1c4a8d18c
--
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/d8f99abf569c7ae830abeb2b08f6f52b910a4b78...98ae551c8d398259c1168f3a80605dd1c4a8d18c
You're receiving this email because of your account on gitlab.common-lisp.net.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cmucl-cvs/attachments/20230313/77eddc6a/attachment-0001.html>
More information about the cmucl-cvs
mailing list