ときどきの雑記帖 RE* (新南口)
あした天気になれ
鼻中隔皮欠損症
真鯛 天然と養殖の見分け方・違いを知りタイ! | 魚食普及推進センター(一般社団法人 大日本水産会)
4/27放送の子ども科学電話相談室で知った。 見分けられるんだねえ。
文房具店
文房具好き必見!東京都内のこだわりが詰まったおしゃれな文房具屋9選
- 銀座 伊東屋 本店/銀座
- アンコーラ銀座本店/銀座
- アンジェ ビュロー エキュート上野店/上野
- カキモリ/蔵前
- タッチアンドフロー 日本橋髙島屋S.C.店/日本橋
- ハイタイドストア ミヤシタパーク/渋谷
- トラベラーズファクトリー 中目黒/中目黒
- THE CAMPUS SHOP/品川
- DESK LABO/下北沢
行ったことがあるのは半分くらいかな
strncpy_s
つづき。
microsoft repositories にあるコードからstrncpy_sを検索してみると いくつかそれっぽいものが見つかる。
ProcDump-for-Linux/profiler/inc/safecrt.h - microsoft/ProcDump-for-Linux
_SAFECRT__INLINE
errno_t __cdecl strncpy_s(char *_Dst, size_t _SizeInBytes, const char *_Src, size_t _Count)
{
char *p;
size_t available;
if (_Count == 0 && _Dst == nullptr && _SizeInBytes == 0)
{
/* this case is allowed; nothing to do */
return 0;
}
/* validation section */
_SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
if (_Count == 0)
{
/* notice that the source string pointer can be nullptr in this case */
_SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
return 0;
}
_SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes);
p = _Dst;
available = _SizeInBytes;
if (_Count == _TRUNCATE)
{
while ((*p++ = *_Src++) != 0 && --available > 0)
{
}
}
else
{
while ((*p++ = *_Src++) != 0 && --available > 0 && --_Count > 0)
{
}
if (_Count == 0)
{
*p = 0;
}
}
if (available == 0)
{
if (_Count == _TRUNCATE)
{
_Dst[_SizeInBytes - 1] = 0;
return STRUNCATE;
}
_SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
_SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
}
_SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
return 0;
}
やっぱり(?)第四引数はrsize_tではなくsize_tで、 その値が_TRUNCATEの場合に特別なことをしている。 その_TRUNCATEの定義はというと
ProcDump-for-Linux/profiler/inc/safecrt.h - microsoft/ProcDump-for-Linux
/* _TRUNCATE */
#if !defined(_TRUNCATE)
#define _TRUNCATE ((size_t)-1)
#endif
やはり。
1 month ago
systemd.timerで起動するserviceにdateコマンドの文字列を渡す #ShellScript - Qiita という記事へのコメントで
$ date "+%Y%m01" --date '20250530 1 month ago'
20250401
$ date "+%Y%m01" --date '20250531 1 month ago'
20250501
となるよ。ということが書かれていたので ソースコードをちょっと読んでみた(最初はドキュメントにあたったのだけど この辺の動作の解説は(たぶん)なかった)。
1 month ago
の取り扱いはこの辺(bisonの文法ファイル)
parse-datetime.y\lib - gnulib.git - gnulib - GNU portability library
rel:
relunit tAGO
{ if (! apply_relative_time (pc, $1, $2)) YYABORT; }
| relunit
{ if (! apply_relative_time (pc, $1, 1)) YYABORT; }
| dayshift
{ if (! apply_relative_time (pc, $1, 1)) YYABORT; }
;
そこから呼び出しているapply_relative_timeの定義をみると
parse-datetime.y\lib - gnulib.git - gnulib - GNU portability library
/* Increment PC->rel by FACTOR * REL (FACTOR is 1 or -1). Return true
if successful, false if an overflow occurred. */
static bool
apply_relative_time (parser_control *pc, relative_time rel, int factor)
{
if (factor < 0
? (ckd_sub (&pc->rel.ns, pc->rel.ns, rel.ns)
| ckd_sub (&pc->rel.seconds, pc->rel.seconds, rel.seconds)
| ckd_sub (&pc->rel.minutes, pc->rel.minutes, rel.minutes)
| ckd_sub (&pc->rel.hour, pc->rel.hour, rel.hour)
| ckd_sub (&pc->rel.day, pc->rel.day, rel.day)
| ckd_sub (&pc->rel.month, pc->rel.month, rel.month)
| ckd_sub (&pc->rel.year, pc->rel.year, rel.year))
: (ckd_add (&pc->rel.ns, pc->rel.ns, rel.ns)
| ckd_add (&pc->rel.seconds, pc->rel.seconds, rel.seconds)
| ckd_add (&pc->rel.minutes, pc->rel.minutes, rel.minutes)
| ckd_add (&pc->rel.hour, pc->rel.hour, rel.hour)
| ckd_add (&pc->rel.day, pc->rel.day, rel.day)
| ckd_add (&pc->rel.month, pc->rel.month, rel.month)
| ckd_add (&pc->rel.year, pc->rel.year, rel.year)))
return false;
pc->rels_seen = true;
return true;
}
ckd_subだのckd_addというのはC23で標準に入った オーバーフローを考慮した加減算のための関数で、 第一引数の型(構造体)は
parse-datetime.y\lib - gnulib.git - gnulib - GNU portability library
/* Information passed to and from the parser. */
typedef struct
{
/* The input string remaining to be parsed. */
const char *input;
/* N, if this is the Nth Tuesday. */
intmax_t day_ordinal;
/* Day of week; Sunday is 0. */
int day_number;
/* tm_isdst flag for the local zone. */
int local_isdst;
/* Time zone, in seconds east of UT. */
int time_zone;
/* Style used for time. */
int meridian;
/* Gregorian year, month, day, hour, minutes, seconds, and nanoseconds. */
textint year;
intmax_t month;
intmax_t day;
intmax_t hour;
intmax_t minutes;
struct timespec seconds; /* includes nanoseconds */
/* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
relative_time rel;
/* Presence or counts of nonterminals of various flavors parsed so far. */
bool timespec_seen;
bool rels_seen;
idx_t dates_seen;
idx_t days_seen;
idx_t J_zones_seen;
idx_t local_zones_seen;
idx_t dsts_seen;
idx_t times_seen;
idx_t zones_seen;
bool year_seen;
#ifdef GNULIB_PARSE_DATETIME2
/* Print debugging output to stderr. */
bool parse_datetime_debug;
#endif
/* Which of the 'seen' parts have been printed when debugging. */
bool debug_dates_seen;
bool debug_days_seen;
bool debug_local_zones_seen;
bool debug_times_seen;
bool debug_zones_seen;
bool debug_year_seen;
/* The user specified explicit ordinal day value. */
bool debug_ordinal_day_seen;
/* Table of local time zone abbreviations, terminated by a null entry. */
table local_time_zone_table[3];
#if !HAVE_STRUCT_TM_TM_ZONE
/* The abbreviations in LOCAL_TIME_ZONE_TABLE. */
char tz_abbr[2][TIME_ZONE_BUFSIZE];
#endif
} parser_control;
とまあ色々「詰め込まれている」。
ちょっと話が戻るけど、1 month ago
の1 month
の部分はここで切り出している
(「切り出し」という表現が妥当かはさておき)
parse-datetime.y\lib - gnulib.git - gnulib - GNU portability library
relunit:
tORDINAL tYEAR_UNIT
{ $$ = RELATIVE_TIME_0; $$.year = $1; }
| tUNUMBER tYEAR_UNIT
{ $$ = RELATIVE_TIME_0; $$.year = $1.value; }
| tYEAR_UNIT
{ $$ = RELATIVE_TIME_0; $$.year = 1; }
| tORDINAL tMONTH_UNIT
{ $$ = RELATIVE_TIME_0; $$.month = $1; }
で、先ほどのckd_subの呼び出しを見ると
ckd_sub (&pc->rel.month, pc->rel.month, rel.month)
と、月の部分の処理しかしていない。つまり、
「n年5月31日」のデータがあったとして、
その1 month ago
は月の部分のみを1減じた日付となり
それは「n年4月31日」となるのだけど、
4月は30日までしかないので調整されて
結局は「n年5月1日」となってしまうことになる
(この辺はたぶんmktimeの動作が反映されている)。
>gdate "+%Y%m01" --date "20250531 1 month ago"
20250501
>gdate "+%Y%m01" --date "20250530 1 month ago"
20250401
>gdate "+%Y%m%d" --date "20250531 1 month ago"
20250501
>gdate "+%Y%m%d" --date "20250530 1 month ago"
20250430
>gdate "+%Y%m%d" --date "20250601 1 month ago"
20250501
parse-datetime.y\lib - gnulib.git - gnulib - GNU portability library
#if HAVE_COMPOUND_LITERALS
# define RELATIVE_TIME_0 ((relative_time) { 0, 0, 0, 0, 0, 0, 0 })
#else
static relative_time const RELATIVE_TIME_0;
#endif
- coreutils/src/date.c at master · coreutils/coreutils
- gnulib/lib at master · coreutils/gnulib
- gnulib/lib/parse-datetime.h at master · coreutils/gnulib
- gnulib/lib/parse-datetime.y at master · coreutils/gnulib
- gnulib/lib/parse-duration.h at master · coreutils/gnulib
- gnulib/lib/parse-duration.c at master · coreutils/gnulib
- gnulib.git - gnulib - GNU portability library
Z
gnulib(というかglibc)の正規表現関数でも
\A
と\z
を使えるようにするパッチが投稿されたのだけど、
Pythonにあわせて\z
じゃなくて\Z
の方が
いいんじゃないか?的な意見。
- [PATCH] regex: Add \A and \z synonyms to ` and '
- Re: [PATCH] regex: Add \A and \z synonyms to ` and '
Python uses \Z for this and Python’s \A … \Z is cleaner and easier to remember than Perl’s \A …
Python 3.12.7 (tags/v3.12.7:0b05ead, Oct 1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.search(r"\Aabc", "abc")
<re.Match object; span=(0, 3), match='abc'>
>>> re.search(r"\Aabc", "xabc")
>>> re.search(r"\Aabc\Z", "abc\n")
>>> re.search(r"\Aabc\Z", "abc")
<re.Match object; span=(0, 3), match='abc'>
>>> re.search(r"\Aabc.\Z", "abc\n", re.DOTALL)
<re.Match object; span=(0, 4), match='abc\n'>
>>> re.search(r"\Aabc\n\Z", "abc\n")
<re.Match object; span=(0, 4), match='abc\n'>
まあPerlの\Z
と\z
はいわゆる「歴史的事情」が反映されたものだしねえ
The Oxford variadic comma
- GCC 15.1 Released With COBOL Compiler & Many Other Improvements - Phoronix
- New C++ features in GCC 15 | Red Hat Developer
The Oxford variadic comma
- GCC 15.1 Released
- New C++ features in GCC 15 | Red Hat Developer
- P3176R1: The Oxford variadic comma
- 117786 – [C++26] P3176R0 - Oxford variadic comma
- C++11と6個のドット - yohhoyの日記
- オックスフォードカンマを使おう。 - IT技術者のための English Writing
- 【Oxford comma とは】カンマの有無で意味が変わる?! | 上級英語ウェブメディア らいトレ
新刊近刊
5月上旬新刊予約受付中
— 書泉_MATH (@rikoushonotana) April 27, 2025
『数理統計学史 ラプラス,ピアソン,フィッシャー,そしてベイズ統計へ』Prakash Gorroochurn/著
鎌倉 稔成/田中 豊/森 裕一/宿久 洋/訳 18,700円(共立出版)
今日のさまざまな統計手法や推定量はなぜ作られ、どのように確立したのか……… pic.twitter.com/ktNNf122zD
ほう。と 数理統計学史 - 共立出版 をみると…
発売日 2025/05/08 ISBN 9784320115781 体裁{ B5・712頁 定価 18,700円 (本体17,000円 + 税10%)
おおう。
5月から6月くらいで気になっているタイトル
- 2025-05-16 アルゴリズム・AIを疑う 誰がブラックボックスをつくるのか (集英社新書) | 宇田川 敦史
- 2025-05-20 なっとく!アルゴリズム 第2版 | アディティア・Y・バーガバ, 株式会社クイープ, 株式会社クイープ
- 2025-05-21 Pythonによるあたらしいデータ分析の教科書 第3版 | 寺田 学, 辻 真吾, 鈴木 たかのり, 福島 真太朗
- 2025-05-29 良いコードの道しるべ 変化に強いソフトウェアを作る原則と実践 | 森 篤史
- 2025-05-30 オープンソースで未来を築こう スキルを磨き、ネットワークを広げ、技術の未来を創造しよう! | VM (Vicky) Brasseur, 角 征典
- 2025-06-11 エンジニア育成現場の「失敗」集めてみた。 42の失敗事例で学ぶ人材育成のうまい進めかた | 出石 聡史
- 2025-06-11 「選べない」はなぜ起こる? | 小島 雄一郎
- 2025-06-21 考える機械たち: 歴史、仕組み、倫理―そして、AIは意思をもつのか? | インガ・ストルムケ, 羽根 由, 小林 聡
まだ現物を拝めていない…
読書録:Apple IIは何を変えたのか パーソナル・ソフトウェア市場の誕生(レイン・ヌーニー著, 山形浩生訳)|TAKASU Masakazu
「ザッケンナ連邦コラーッ!」「イヤーッ!」「アバーッ!」ガンダムのジゴクめいた射撃により次々にサンズ・リバーへ送られていくリックドム!(僕は機械弄りではなくパイロットをやるべきだったのか!?)アムロは困惑した。ララァとの出会いと数多のイクサが彼をNTカラテへと開眼させたのだ!
— フィーエル (@yourayx9) April 27, 2025
「アイエエエ!全滅?12機のリック・ドムが全滅ナンデ?オバケか?コワイ!」
— Funayan(ふなやん)@Team P🏴☠️霊統一 (@funayan666ghost) April 27, 2025
錯乱し失禁寸前のコンスコンに、オペレードロイドの無慈悲なマイコ音声が畳み掛ける!
「敵機、直上ドスエ」
「撃ち落とせ!シャア=サンが見ているんだぞ!」
『戦闘メカ ザブングル』のコラボ飲食店があったら、ドリンクメニューの「ここは地の果て流されてオレ」を注文したいし、「今日もさすらい涙もカレールウ」を買い求めておみやげにしたい。
— 植田清吉GX-T (@shakeeach) April 28, 2025