From a1bb3dc448bc313427fedb4c435763acb90853fc Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 9 Aug 2011 23:41:09 -0700 Subject: Makefile target for running Python tests. --- Makefile | 18 +++++++++++++----- upb/def.c | 12 +++--------- upb/def.h | 3 +++ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 177a221..6fb994a 100644 --- a/Makefile +++ b/Makefile @@ -136,7 +136,7 @@ OBJ=$(patsubst %.c,%.o,$(SRC)) PICOBJ=$(patsubst %.c,%.lo,$(SRC)) ifneq (, $(findstring DUPB_USE_JIT_X64, $(USER_CFLAGS))) -upb/pb/decoder.o: upb/pb/decoder_x86.h +upb/pb/decoder.o upb/pb/decoder.lo: upb/pb/decoder_x86.h ifeq (, $(findstring DNDEBUG, $(USER_CFLAGS))) $(error "JIT only works with -DNDEBUG enabled!") endif @@ -197,10 +197,6 @@ descriptorgen: upb/descriptor.pb tools/upbc tools/upbc: tools/upbc.c $(LIBUPB) -# Language extensions. -python: $(LIBUPB_PIC) - cd lang_ext/python && python setup.py build - # Tests. ####################################################################### tests/test.proto.pb: tests/test.proto @@ -397,3 +393,15 @@ lua: $(LUAEXT) lang_ext/lua/upb.so: lang_ext/lua/upb.c $(LIBUPB_PIC) $(E) CC lang_ext/lua/upb.c $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) $(LUA_CPPFLAGS) -fpic -shared -o $@ $< upb/libupb_pic.a $(LUA_LDFLAGS) + + +# Python extension ############################################################# + +PYTHONEXT=lang_ext/python/build/install/lib/python/upb/__init__.so +python: $(PYTHONEXT) +$(PYTHONEXT): $(LIBUPB_PIC) lang_ext/python/upb.c + $(E) PYTHON lang_ext/python/upb.c + $(Q) cd lang_ext/python && python setup.py build install --home=build/install + +pythontest: $(PYTHONEXT) + cd lang_ext/python && cp test.py build/install/lib/python && python ./build/install/lib/python/test.py diff --git a/upb/def.c b/upb/def.c index e90a288..7de247e 100644 --- a/upb/def.c +++ b/upb/def.c @@ -103,7 +103,6 @@ static void upb_def_init(upb_def *def, upb_deftype_t type) { } static void upb_def_uninit(upb_def *def) { - //fprintf(stderr, "Freeing def: %p\n", def); free(def->fqname); } @@ -115,23 +114,17 @@ static void upb_def_uninit(upb_def *def) { // are replaced with pointers to the actual def being referenced. typedef struct _upb_unresolveddef { upb_def base; - - // The target type name. This may or may not be fully qualified. It is - // tempting to want to use base.fqname for this, but that will be qualified - // which is inappropriate for a name we still have to resolve. - char *name; } upb_unresolveddef; // Is passed a ref on the string. static upb_unresolveddef *upb_unresolveddef_new(const char *str) { upb_unresolveddef *def = malloc(sizeof(*def)); upb_def_init(&def->base, UPB_DEF_UNRESOLVED); - def->name = strdup(str); + def->base.fqname = strdup(str); return def; } static void upb_unresolveddef_free(struct _upb_unresolveddef *def) { - free(def->name); upb_def_uninit(&def->base); free(def); } @@ -729,7 +722,8 @@ bool upb_symtab_add(upb_symtab *s, upb_def **defs, int n, upb_status *status) { } if (!upb_hassubdef(f)) continue; // No resolving necessary. - const char *name = upb_downcast_unresolveddef(f->def)->name; + upb_downcast_unresolveddef(f->def); // Type check. + const char *name = f->def->fqname; // Resolve from either the addtab (pending adds) or symtab (existing // defs). If both exist, prefer the pending add, because it will be diff --git a/upb/def.h b/upb/def.h index 9571773..66d3c70 100644 --- a/upb/def.h +++ b/upb/def.h @@ -117,6 +117,9 @@ INLINE struct _upb_msgdef *upb_fielddef_msgdef(upb_fielddef *f) { INLINE struct _upb_accessor_vtbl *upb_fielddef_accessor(upb_fielddef *f) { return f->accessor; } +INLINE const char *upb_fielddef_typename(upb_fielddef *f) { + return f->def ? f->def->fqname : NULL; +} // Only meaningful once the def is in a symtab (returns NULL otherwise, or for // a fielddef where !upb_hassubdef(f)). -- cgit v1.2.3