HackerTrans
TopNewTrendsCommentsPastAskShowJobs

yairlenga

no profile record

Submissions

[untitled]

1 points·by yairlenga·mês passado·0 comments

Python Streaming JSON Formatter That Works with Existing Serializers

medium.com
1 points·by yairlenga·há 2 meses·1 comments

Automatic Enum Handling in C – Parsing, Validating and Iterating

medium.com
3 points·by yairlenga·há 2 meses·0 comments

Automatic Enum Stringification in C via Build-Time Code Generation

medium.com
1 points·by yairlenga·há 3 meses·1 comments

Avoiding Malloc for Small Strings in C with Variable Length Arrays (VLAs)

medium.com
2 points·by yairlenga·há 3 meses·1 comments

Optimizing Chained Strcmp Calls for Speed and Clarity

medium.com
2 points·by yairlenga·há 3 meses·1 comments

Safer Casting in C – With Zero Runtime Cost – Making Casts Visible, Auditable

medium.com
4 points·by yairlenga·há 3 meses·2 comments

[untitled]

1 points·by yairlenga·há 4 meses·0 comments

comments

yairlenga
·há 2 meses·discuss
Most JSON serializers give you only two choices: compact machine output, or fully expanded "pretty-print" for humans. Neither is ideal when JSON needs to be consumed by both.

I wrote a small Python module called jsonfold, post processing the output of json.dump() (and other similar serializers). It will selectively fold short lines and small containers while still keeping the JSON readable.

It works as a lightweight wrapper for file-like objects, and it does NOT re-parse the JSON stream, so it can handle large documents with fixed memory usage and linear processing time.

Sample output (line width, level of folding, ... can be customized):

{ "a": { "b": { "c": "abc" } }, "x": { "y": { "z": "xyz" } } }
yairlenga
·há 2 meses·discuss
[dead]
yairlenga
·há 3 meses·discuss
If you maintain C code, you've probably written enum-to-string conversion functions by hand (either with switch statement, lookup tables or similar).

I wrote about autoamtic enum stringification in C - using build-time code generation from the DWARF debug information that is produced by the GCC/Clang compilers. (Medium, no Paywall).

I found the approach to reduce effort and errors for producing debug printout, logging, parsing config files, etc.

At the end, the developer can write something like:

  enum country_code {
    ISO3_AFG = 4,    /* Afghanistan */
    ISO3_ALB = 8,    /* Albania */
    ISO3_ATA = 10,   /* Antarctica */
    ISO3_DZA = 12,   /* Algeria \*/
    ...
  } ;

  ENUM_DESCRIBE(country3, country_code)

  void foo(enum country_code c)
  {
    printf("Called with C=%s\n", ENUM_LABEL_OF(country3, c))  ;
  }

Sharing in the hope that other developer can use this code. Can be integrated into any code with files (".c" source, ".h" header and python code generator) - available on my GitHub (MIT License).

Any feedback will be appreciated.
yairlenga
·há 3 meses·discuss
This looks at replacing malloc/free for small temporary strings with VLAs, using a stack-first approach with heap fallback. Benchmarks were a bit surprising—allocator behavior (especially on musl) changes the trade-offs more than I expected. Interested in how others approach temporary allocation patterns.
yairlenga
·há 3 meses·discuss
I looked at a common pattern in C codebases — long chains of strcmp over fixed strings (ISO currency codes in this case) — and explored how far you can push it without refactoring the structure. Experimented with few approaches (memcmp, filtering, etc.), and ended with a simple 4CC-based technique that compiles down to integer compares and is noticeably faster in practice.
yairlenga
·há 3 meses·discuss
I ran into a few subtle bugs around casts in C—mostly pointer precedence and intent not being obvious in reviews.

Things like (long *)buf + 1 are easy to misread at a glance.

I tried making casts more explicit with small macros (CAST_PTR1, etc.) and adding some compile-time checks.

Curious how others deal with this—warnings, conventions, or just careful review?
yairlenga
·há 4 meses·discuss
On modern Unix systems it is possible to estimate remaining stack space with reasonable accuracy by combining stack limits and the current stack pointer.

The article explores three approaches (getrlimit, pthread_getattr_np, and constructor initialization) and demonstrates a small helper API to inspect available stack space at runtime