|
9 | 9 | * | BingChunMoLi <bingchunmoli@bingchunmoli.com> |
10 | 10 | * | |
11 | 11 | * Created On : <2023-08-28> |
12 | | - * Last Modified : <2026-03-17> |
| 12 | + * Last Modified : <2026-03-18> |
13 | 13 | * |
14 | 14 | * |
15 | 15 | * xy: 襄阳、咸阳 |
|
18 | 18 | * |
19 | 19 | * 该库的特点是混合多种编程语言风味 (绝大多数为 Ruby),每个 API |
20 | 20 | * 均使用 @flavor 标注其参考依据 |
| 21 | + * |
| 22 | + * |
| 23 | + * 说明: |
| 24 | + * 1. 完全不考虑OOM等内存分配失败的情况 |
| 25 | + * |
21 | 26 | * ------------------------------------------------------------*/ |
22 | 27 |
|
23 | 28 | #ifndef XY_H |
24 | 29 | #define XY_H |
25 | 30 |
|
26 | | -#define _XY_Version "v0.2.2.1-2026/03/17" |
| 31 | +#define _XY_Version "v0.2.2.2-2026/03/18" |
27 | 32 | #define _XY_Maintain_URL "https://github.com/RubyMetric/chsrc/blob/dev/lib/xy.h" |
28 | 33 | #define _XY_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc/blob/dev/lib/xy.h" |
29 | 34 |
|
@@ -279,10 +284,9 @@ xy_str_gsub (const char *str, const char *pat, const char *replace) |
279 | 284 | else |
280 | 285 | break; |
281 | 286 | } |
282 | | - // puti(count); DEBUG 匹配次数 |
| 287 | + // print(count); /* DEBUG 匹配次数 */ |
283 | 288 |
|
284 | 289 | char *ret = malloc (unit * count + len + 1); |
285 | | - if (!ret) return NULL; |
286 | 290 | char *retcur = ret; |
287 | 291 |
|
288 | 292 | cur = str; |
@@ -377,11 +381,6 @@ xy_strcat (unsigned int count, ...) |
377 | 381 | ret = realloc (ret, al_cur); |
378 | 382 | cur = ret + diff; |
379 | 383 | } |
380 | | - if (NULL == ret) |
381 | | - { |
382 | | - _xy_internal_warn ("xy_strcat(): No availble memory to allocate!"); |
383 | | - return NULL; |
384 | | - } |
385 | 384 | strcpy (cur, str); |
386 | 385 | // puts(ret); |
387 | 386 | cur += strlen (str); |
@@ -743,11 +742,6 @@ xy_file_read (const char *path) |
743 | 742 | rewind (fp); |
744 | 743 |
|
745 | 744 | char *buf = xy_malloc0 ((size_t) size + 1); |
746 | | - if (!buf) |
747 | | - { |
748 | | - fclose (fp); |
749 | | - return xy_strdup (""); |
750 | | - } |
751 | 745 |
|
752 | 746 | size_t read_bytes = fread (buf, 1, (size_t) size, fp); |
753 | 747 | if (read_bytes < (size_t) size && ferror (fp)) |
@@ -979,15 +973,14 @@ xy_run_iter_lines (const char *cmd, unsigned long n, bool (*func) (const char |
979 | 973 | if (NULL == fgets (buf, size, stream)) |
980 | 974 | break; |
981 | 975 | /* 存在换行的总是会把换行符读出来,删掉 */ |
982 | | - if (ret) |
983 | | - free (ret); |
| 976 | + if (ret) free (ret); /* 上次读到的需要释放 */ |
984 | 977 | ret = xy_str_delete_suffix (buf, "\n"); |
985 | 978 | count += 1; |
986 | 979 | if (n == count) |
987 | 980 | break; |
988 | 981 | if (func) |
989 | 982 | { |
990 | | - if (func (ret)) |
| 983 | + if (func (ret)) |
991 | 984 | break; |
992 | 985 | } |
993 | 986 | } |
@@ -1476,7 +1469,6 @@ XySeq_t* |
1476 | 1469 | xy_seq_new (void) |
1477 | 1470 | { |
1478 | 1471 | XySeq_t *seq = xy_malloc0 (sizeof (XySeq_t)); |
1479 | | - if (!seq) return NULL; |
1480 | 1472 |
|
1481 | 1473 | seq->first_item = NULL; |
1482 | 1474 | seq->last_item = NULL; |
|
0 commit comments