Proof of concept
This commit is contained in:
@@ -53,3 +53,5 @@ dkms.conf
|
|||||||
|
|
||||||
# debug information files
|
# debug information files
|
||||||
*.dwo
|
*.dwo
|
||||||
|
|
||||||
|
/sc
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user