Proof of concept

This commit is contained in:
2026-05-13 22:53:52 +02:00
parent 19afa4795a
commit a75a898183
3 changed files with 64 additions and 0 deletions
+2
View File
@@ -53,3 +53,5 @@ dkms.conf
# debug information files # debug information files
*.dwo *.dwo
/sc
+3
View File
@@ -0,0 +1,3 @@
gcc scope-count.c -o sc
./sc
+59
View File
@@ -0,0 +1,59 @@
#include <stdio.h>
#include <stdlib.h>
struct ScopeCount
{
int count;
int is_alias;
void *item;
};
int scope_count(void *item, int is_alias)
{
struct ScopeCount sc;
sc.count = 0;
sc.is_alias = 0;
sc.item = item;
sc.count++;
sc.is_alias = is_alias;
return sc.count;
}
void end_scope(struct ScopeCount *sc)
{
if (sc->count == 0)
{
free(sc->item);
}
sc->count--;
}
struct ScopeCount do_something()
{
struct ScopeCount sc;
sc.count = 1;
sc.is_alias = 0;
sc.item = malloc(sizeof(int));
*(int *)sc.item = 67;
end_scope(&sc);
return sc;
}
int main()
{
struct ScopeCount sc = do_something();
printf("value: %d\n", *(int *)sc.item);
end_scope(&sc);
printf("value: %d\n", *(int *)sc.item);
return 0;
}