Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c8a5437
gitignore: update
giuseppe Dec 12, 2025
7579c03
source: add emit() helper function for code generation
giuseppe Dec 12, 2025
064fcbb
source: extract free_and_null() helper pattern
giuseppe Dec 12, 2025
419526a
source: extract null_check_return() helper pattern (partial)
giuseppe Dec 12, 2025
cc817ed
source: continue null_check_return() pattern extraction
giuseppe Dec 12, 2025
46ce297
source: extract calloc_with_check() helper pattern
giuseppe Dec 12, 2025
e80d362
source: extract check_gen_status() helper pattern
giuseppe Dec 12, 2025
002af18
source: convert parse_map_string_obj() to multi-line f-strings
giuseppe Dec 12, 2025
ae23175
source: convert parse_obj_type_array() to multi-line f-strings
giuseppe Dec 12, 2025
47e7dc5
source: convert get_map_string_obj() to multi-line f-strings
giuseppe Dec 12, 2025
66e333d
source: convert get_obj_arr_obj_array() to f-strings (object branch)
giuseppe Dec 12, 2025
a2fd73f
source: complete get_obj_arr_obj_array() conversion to f-strings
giuseppe Dec 12, 2025
41596b9
source: convert c_file_map_str() to multi-line f-strings
giuseppe Dec 12, 2025
112ab7f
source: convert c_file_str() to multi-line f-strings
giuseppe Dec 12, 2025
d62a55f
source: convert make_c_array_free() to multi-line f-strings
giuseppe Dec 12, 2025
39fa66d
source: convert make_c_free() to multi-line f-strings
giuseppe Dec 12, 2025
d37383d
source: convert parse_obj_type() to multi-line f-strings
giuseppe Dec 12, 2025
4d2f6e5
source: add do_read_value() helper to reduce boilerplate
giuseppe Dec 12, 2025
7a62656
source: add emit_asprintf_error() helper to reduce boilerplate
giuseppe Dec 12, 2025
05ee4de
source: add emit_value_error() helper for error wrapping
giuseppe Dec 12, 2025
3366b93
source: add emit_invalid_type_check() helper for YAJL validation
giuseppe Dec 12, 2025
aa9271c
source: add YAJL generation helper functions
giuseppe Dec 12, 2025
7f5fcb5
source: apply YAJL helpers to get_map_string_obj()
giuseppe Dec 12, 2025
a2cc69b
source: apply YAJL helpers to get_obj_arr_obj_array()
giuseppe Dec 12, 2025
6dcd043
source: apply YAJL helpers to get_c_json()
giuseppe Dec 12, 2025
717d035
source: apply YAJL helpers to get_c_epilog_for_array_make_gen()
giuseppe Dec 12, 2025
a23b40c
source: apply emit_gen_key() helper to get_obj_arr_obj()
giuseppe Dec 12, 2025
6ae8e2d
source: consolidate numeric type conversion with helper function
giuseppe Dec 12, 2025
858f199
source: remove dead code in make_clone()
giuseppe Dec 12, 2025
c174b06
source: remove superfluous else after return
giuseppe Dec 12, 2025
c3686db
source: add TypeHandler classes for type-specific C code generation
giuseppe Dec 12, 2025
2fc8679
source: use TypeHandler.emit_parse() in parse_obj_type()
giuseppe Dec 12, 2025
141fa50
source: use TypeHandler in make_c_free() and make_clone()
giuseppe Dec 12, 2025
633c0b5
source: add ObjectType, MapStringObjectType, and BasicMapType handlers
giuseppe Dec 12, 2025
971a65b
source: add ArrayType handler for array operations
giuseppe Dec 12, 2025
20de7a4
source: add emit_clone() to MapStringObjectType and BasicMapType
giuseppe Dec 12, 2025
b49928d
source: remove dead code in make_c_free()
giuseppe Dec 12, 2025
31824dc
source: remove dead code in read_val_generator()
giuseppe Dec 12, 2025
45a1b35
source: skip handler for object type in make_clone()
giuseppe Dec 12, 2025
df11b0a
helpers: rename judge_* functions to clearer names
giuseppe Dec 12, 2025
73e8f9e
source: inline array functions into ArrayType handler
giuseppe Dec 12, 2025
337925c
source: inline trivial wrapper functions
giuseppe Dec 12, 2025
e59b696
source: inline c_file_str() into ArrayType.emit_free()
giuseppe Dec 12, 2025
4ff4117
source: inline c_file_map_str() into make_c_free()
giuseppe Dec 12, 2025
11b951f
source: extract get_compound_children() helper
giuseppe Dec 12, 2025
d91d34a
source: add emit_gen_key_with_check() helper
giuseppe Dec 12, 2025
81ff1fa
source: document ObjectType.emit_clone() design decision
giuseppe Dec 12, 2025
fed6acc
source: add BooleanPointerType.emit_generate() and emit_json_value()
giuseppe Dec 12, 2025
dc24f9a
source: refactor ArrayType using ArraySubtypeHandler classes
giuseppe Dec 12, 2025
7d7e02c
source: add struct-level methods to TypeHandler classes
giuseppe Dec 12, 2025
a425a84
source: rename doublearray to nested_array
giuseppe Dec 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 42 additions & 78 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
*.a
aclocal.m4
autom4te.cache/

# Generated files in root directory
/config_*.c
/config_*.h
/defs*.c
/defs*.h
/features_*.c
/features_*.h
/state_*.c
/state_*.h
/basic_test_*
/test_*
/*_schema.c
/*_schema.h
/libocispec-*.tar.*
/libocispec-*/
/target/
build-aux/compile
build-aux/config.guess
build-aux/config.sub
Expand All @@ -24,87 +41,34 @@ Makefile
Makefile.in
*.o
ocispec.pc
src/basic_test_double_array.c
src/basic_test_double_array.h
src/basic_test_double_array_item.c
src/basic_test_double_array_item.h
src/basic-test_stamp
src/basic_test_top_array_int.c
src/basic_test_top_array_int.h
src/basic_test_top_array_string.c
src/basic_test_top_array_string.h
src/basic_test_top_double_array_int.c
src/basic_test_top_double_array_int.h
src/basic_test_top_double_array_obj.c
src/basic_test_top_double_array_obj.h
src/basic_test_top_double_array_refobj.c
src/basic_test_top_double_array_refobj.h
src/basic_test_top_double_array_string.c
src/basic_test_top_double_array_string.h
src/.deps/
src/.dirstamp
src/image_manifest_items_image_manifest_items_schema.c
src/image_manifest_items_image_manifest_items_schema.h
src/image_manifest_stamp
src/image_spec_schema_config_schema.c
src/image_spec_schema_config_schema.h
src/image_spec_schema_content_descriptor.c
src/image_spec_schema_content_descriptor.h
src/image_spec_schema_defs.c
src/image_spec_schema_defs_descriptor.c
src/image_spec_schema_defs_descriptor.h
src/image_spec_schema_defs.h
src/image_spec_schema_image_index_schema.c
src/image_spec_schema_image_index_schema.h
src/image_spec_schema_image_layout_schema.c
src/image_spec_schema_image_layout_schema.h
src/image_spec_schema_image_manifest_schema.c
src/image_spec_schema_image_manifest_schema.h
src/image_spec_stamp
src/*.lo
src/__pycache__/
src/runtime_spec_schema_config_linux.c
src/runtime_spec_schema_config_linux.h
src/runtime_spec_schema_config_zos.c
src/runtime_spec_schema_config_zos.h
src/runtime_spec_schema_config_schema.c
src/runtime_spec_schema_config_schema.h
src/runtime_spec_schema_config_solaris.c
src/runtime_spec_schema_config_solaris.h
src/runtime_spec_schema_config_vm.c
src/runtime_spec_schema_config_vm.h
src/runtime_spec_schema_config_windows.c
src/runtime_spec_schema_config_windows.h
src/runtime_spec_schema_defs.c
src/runtime_spec_schema_defs.h
src/runtime_spec_schema_defs_linux.c
src/runtime_spec_schema_defs_linux.h
src/runtime_spec_schema_defs_zos.c
src/runtime_spec_schema_defs_zos.h
src/runtime_spec_schema_defs_vm.c
src/runtime_spec_schema_defs_vm.h
src/runtime_spec_schema_defs_windows.c
src/runtime_spec_schema_defs_windows.h
src/runtime_spec_schema_state_schema.c
src/runtime_spec_schema_state_schema.h
src/runtime_spec_stamp
src/validate
stamp-h1
*_stamp

# Generated files in src/ocispec/
src/ocispec/.dirstamp
src/ocispec/.deps/
src/ocispec/__pycache__/
src/ocispec/*.lo
src/ocispec/*.o
src/ocispec/*_stamp
src/ocispec/basic_test_*
src/ocispec/test_*
src/ocispec/image_manifest_*
src/ocispec/image_spec_*
src/ocispec/runtime_spec_*
src/ocispec/*_schema.*
src/ocispec/config_*
src/ocispec/defs_*
src/ocispec/defs.*
src/ocispec/features_*
src/ocispec/state_*
src/ocispec/validate

tests/.deps/
tests/.dirstamp
tests/test-1
tests/test-10
tests/test-11
tests/test-2
tests/test-3
tests/test-4
tests/test-5
tests/test-6
tests/test-7
tests/test-8
tests/test-9
tests/test-*.log
tests/test-*.trs
tests/test-[0-9]*
tests/*.log
tests/*.trs
test-suite.log
build-aux/config.guess~
build-aux/config.sub~
Expand Down
4 changes: 2 additions & 2 deletions src/ocispec/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def gen_type_arr_typnode(node_info, src, typ, refname):
subtyp=item_type.subtyp,
subtypobj=item_type.subtypobj,
subtypname=item_type.subtypname,
required=item_type.required, doublearray=True), src
required=item_type.required, nested_array=True), src
else:
return helpers.SchemaNode(name,
typ,
Expand Down Expand Up @@ -650,7 +650,7 @@ def parse_schema(schema_info, schema, prefix):
item_type, _ = resolve_type(schema_info, helpers.HierarchicalName(""), \
schema['items'], schema['items'], schema_info.name.name)
if item_type.typ == 'array' and not helpers.valid_basic_map_name(item_type.subtyp):
item_type.doublearray = True
item_type.nested_array = True
return item_type
else:
return helpers.SchemaNode(helpers.HierarchicalName(prefix), 'array', None, item_type.typ, \
Expand Down
12 changes: 6 additions & 6 deletions src/ocispec/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def append_header_arr(obj, header, prefix):
helpers.get_map_c_types(i.typ)
header.append(f" {c_typ}{' ' if '*' not in c_typ else ''}{i.fixname};\n")
for i in obj.subtypobj:
if helpers.judge_data_type(i.typ) or i.typ == 'boolean':
if helpers.is_numeric_type(i.typ) or i.typ == 'boolean':
header.append(f" unsigned int {i.fixname}_present : 1;\n")
typename = helpers.get_name_substr(obj.name, prefix)
header.append(f"}}\n{typename};\n\n")
Expand Down Expand Up @@ -100,7 +100,7 @@ def append_header_child_arr(child, header, prefix):
c_typ = helpers.get_prefixed_pointer(child.name, child.subtyp, prefix)

dflag = ""
if child.doublearray:
if child.nested_array:
dflag = "*"

if helpers.valid_basic_map_name(child.subtyp):
Expand All @@ -110,7 +110,7 @@ def append_header_child_arr(child, header, prefix):
else:
header.append(f" {c_typ}{' ' if '*' not in c_typ else ''}**{dflag}{child.fixname};\n")

if child.doublearray and not helpers.valid_basic_map_name(child.subtyp):
if child.nested_array and not helpers.valid_basic_map_name(child.subtyp):
header.append(f" size_t *{child.fixname + '_item_lens'};\n")

header.append(f" size_t {child.fixname + '_len'};\n\n")
Expand Down Expand Up @@ -157,7 +157,7 @@ def append_type_c_header(obj, header, prefix):
header.append(" char unuseful; // unuseful definition to avoid empty struct\n")
present_tags = []
for i in obj.children or []:
if helpers.judge_data_type(i.typ) or i.typ == 'boolean':
if helpers.is_numeric_type(i.typ) or i.typ == 'boolean':
present_tags.append(f" unsigned int {i.fixname}_present : 1;\n")
if i.typ == 'array':
append_header_child_arr(i, header, prefix)
Expand All @@ -180,7 +180,7 @@ def header_reflect_top_array(obj, prefix, header):
c_typ = helpers.get_prefixed_pointer(obj.name, obj.subtyp, prefix) or \
helpers.get_map_c_types(obj.subtyp)
if obj.subtypobj is not None:
if obj.doublearray and obj.subtypname is not None:
if obj.nested_array and obj.subtypname is not None:
c_typ = obj.subtypname + " *"
else:
c_typ = helpers.get_name_substr(obj.name, prefix) + " *"
Expand All @@ -189,7 +189,7 @@ def header_reflect_top_array(obj, prefix, header):

typename = helpers.get_top_array_type_name(obj.name, prefix)
header.append("typedef struct {\n")
if obj.doublearray:
if obj.nested_array:
header.append(f" {c_typ}{' ' if '*' not in c_typ else ''}**items;\n")
header.append(" size_t *subitem_lens;\n\n")
else:
Expand Down
28 changes: 8 additions & 20 deletions src/ocispec/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,33 +192,21 @@ def is_compound_type(typ):
'''
return typ in ('object', 'array', 'mapStringObject')

def judge_data_type(typ):
'''
Description: Check numeric type
Interface: None
History: 2019-06-17
'''
def is_numeric_type(typ):
'''Check if typ is a numeric type (int, uint, double, etc.).'''
if (typ.startswith("int") or typ.startswith("uint")) and \
"Pointer" not in typ:
return True
return typ in ("integer", "UID", "GID", "double")

def judge_data_pointer_type(typ):
'''
Description: Check numeric pointer type
Interface: None
History: 2019-06-17
'''
def is_numeric_pointer_type(typ):
'''Check if typ is a pointer to a numeric type.'''
if (typ.startswith("int") or typ.startswith("uint")) and "Pointer" in typ:
return True
return False

def obtain_data_pointer_type(typ):
'''
Description: Get numeric pointer type
Interface: None
History: 2019-06-17
'''
def get_pointer_base_type(typ):
'''Extract the base type from a pointer type (e.g., "int64Pointer" -> "int64").'''
index = typ.find("Pointer")
return typ[0:index] if index != -1 else ""

Expand Down Expand Up @@ -266,7 +254,7 @@ class SchemaNode:
History: 2019-06-17
'''
def __init__(self, name, typ, children, subtyp=None, subtypobj=None, subtypname=None, \
required=None, doublearray=False):
required=None, nested_array=False):
self.typ = typ
self.children = children
self.subtyp = subtyp
Expand All @@ -276,7 +264,7 @@ def __init__(self, name, typ, children, subtyp=None, subtypobj=None, subtypname=
self.name = conv_to_c_style(name.name.replace('.', '_'))
self.origname = name.leaf or name.name
self.fixname = conv_to_c_style(self.origname.replace('.', '_'))
self.doublearray = doublearray
self.nested_array = nested_array



Expand Down
Loading
Loading