Commit e2acd854 authored by Jon Skeet's avatar Jon Skeet

Merged master

parents d9dc05e5 b36395b2
......@@ -27,7 +27,6 @@ src/Makefile
/config.h
config.log
config.status
pbconfig.h
libtool
protobuf-lite.pc
......
sudo: required
# Note: travis currently does not support listing more than one language so
# this cheats and claims to only be cpp. If they add multiple language
# support, this should probably get updated to install steps and/or
# rvm/gemfile/jdk/etc. entries rather than manually doing the work.
language: cpp
os:
- linux
......@@ -22,5 +26,31 @@ env:
- CONFIG=ruby21
- CONFIG=ruby22
- CONFIG=jruby
matrix:
exclude:
# It's nontrivial to programmatically install a new JDK from the command
# line on OS X, so we rely on testing on Linux for Java code.
- os: osx
env: CONFIG=java_jdk6
- os: osx
env: CONFIG=java_jdk7
- os: osx
env: CONFIG=java_oracle7
- os: osx
env: CONFIG=javanano_jdk6
- os: osx
env: CONFIG=javanano_jdk7
- os: osx
env: CONFIG=javanano_oracle7
# Requires installing mono, currently travis.sh is doing that with apt-get
# which doesn't work on OS X.
- os: osx
env: CONFIG=csharp
allow_failures:
# These currently do not work on OS X but are being worked on by @haberman.
- os: osx
env: CONFIG=ruby22
- os: osx
env: CONFIG=jruby
notifications:
email: false
This diff is collapsed.
......@@ -5,7 +5,7 @@
# dependent projects use the :git notation to refer to the library.
Pod::Spec.new do |s|
s.name = 'Protobuf'
s.version = '3.0.0'
s.version = '3.0.0-alpha-4-pre'
s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.'
s.homepage = 'https://github.com/google/protobuf'
s.license = 'New BSD'
......@@ -13,23 +13,23 @@ Pod::Spec.new do |s|
s.source_files = 'objectivec/*.{h,m}',
'objectivec/google/protobuf/Any.pbobjc.{h,m}',
'objectivec/google/protobuf/Api.pbobjc.{h,m}',
'objectivec/google/protobuf/Descriptor.pbobjc.{h,m}',
'objectivec/google/protobuf/Duration.pbobjc.h',
'objectivec/google/protobuf/Empty.pbobjc.{h,m}',
'objectivec/google/protobuf/FieldMask.pbobjc.{h,m}',
'objectivec/google/protobuf/SourceContext.pbobjc.{h,m}',
'objectivec/google/protobuf/Struct.pbobjc.{h,m}',
'objectivec/google/protobuf/Timestamp.pbobjc.h',
'objectivec/google/protobuf/Type.pbobjc.{h,m}'
'objectivec/google/protobuf/Wrappers.pbobjc.{h,m}'
# Timestamp.pbobjc.m and Duration.pbobjc.m are #imported by GPBWellKnownTypes.m. So we can't
# compile them (duplicate symbols), but we need them available for the importing:
s.preserve_paths = 'objectivec/google/protobuf/Duration.pbobjc.m',
'objectivec/google/protobuf/Timestamp.pbobjc.m'
# The following would cause duplicate symbol definitions. GPBProtocolBuffers is expected to be
# left out, as it's an umbrella implementation file. For Api, Struct and Type, see issue #449.
s.exclude_files = 'objectivec/GPBProtocolBuffers.m',
'objectivec/google/protobuf/Api.pbobjc.{h,m}',
'objectivec/google/protobuf/Struct.pbobjc.{h,m}',
'objectivec/google/protobuf/Type.pbobjc.{h,m}'
# left out, as it's an umbrella implementation file.
s.exclude_files = 'objectivec/GPBProtocolBuffers.m'
s.header_mappings_dir = 'objectivec'
s.ios.deployment_target = '6.0'
......
Protocol Buffers - Google's data interchange format
===================================================
[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf)
[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf) [![Build status](https://ci.appveyor.com/api/projects/status/73ctee6ua4w2ruin?svg=true)](https://ci.appveyor.com/project/protobuf/protobuf)
Copyright 2008 Google Inc.
......@@ -156,7 +156,7 @@ For advanced usage information on configure and make, see INSTALL.txt.
C++ Installation - Windows
--------------------------
If you are using Microsoft Visual C++, see vsprojects/readme.txt.
If you are using Microsoft Visual C++, see cmake/README.md.
If you are using Cygwin or MinGW, follow the Unix installation
instructions, above.
......
# Only test one combination: "Visual Studio 12 + Win64 + Debug + DLL". We can
# test more combinations but AppVeyor just takes too long to finish (each
# combination takes ~15mins).
platform:
- Win64
configuration:
- Debug
environment:
matrix:
- BUILD_DLL: ON
install:
- ps: Start-FileDownload https://googletest.googlecode.com/files/gtest-1.7.0.zip
- 7z x gtest-1.7.0.zip
- rename gtest-1.7.0 gtest
before_build:
- if %platform%==Win32 set generator=Visual Studio 12
- if %platform%==Win64 set generator=Visual Studio 12 Win64
- if %platform%==Win32 set vcplatform=Win32
- if %platform%==Win64 set vcplatform=x64
build_script:
- mkdir build
- cd build
- cmake -G "%generator%" -DBUILD_SHARED_LIBS=%BUILD_DLL% ../cmake
- msbuild protobuf.sln /p:Platform=%vcplatform% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
- cd %configuration%
- tests.exe
......@@ -8,11 +8,11 @@ if (MSVC)
option(ZLIB "Build with zlib support" OFF)
endif (MSVC)
add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD)
find_package(Threads REQUIRED)
if (CMAKE_USE_PTHREADS_INIT)
set(HAVE_PTHREAD 1)
else (CMAKE_USE_PTHREADS_INIT)
set(HAVE_PTHREAD 0)
add_definitions(-DHAVE_PTHREAD)
endif (CMAKE_USE_PTHREADS_INIT)
if (MSVC)
......@@ -36,6 +36,10 @@ else (MSVC)
endif (ZLIB_FOUND)
endif (MSVC)
if (HAVE_ZLIB)
add_definitions(-DHAVE_ZLIB)
endif (HAVE_ZLIB)
if (MSVC)
if (BUILD_SHARED_LIBS)
add_definitions(-DPROTOBUF_USE_DLLS)
......@@ -43,10 +47,11 @@ if (MSVC)
add_definitions(/wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305)
endif (MSVC)
include(find_hash_map.cmake)
configure_file(config.h.in config.h)
configure_file(pbconfig.h.in google/protobuf/stubs/pbconfig.h)
if (MSVC)
string(REPLACE "/" "\\" PROTOBUF_SOURCE_WIN32_PATH ${protobuf_SOURCE_DIR})
string(REPLACE "/" "\\" PROTOBUF_BINARY_WIN32_PATH ${protobuf_BINARY_DIR})
configure_file(extract_includes.bat.in extract_includes.bat)
endif (MSVC)
get_filename_component(protobuf_source_dir ${protobuf_SOURCE_DIR} PATH)
......@@ -67,6 +72,7 @@ endif (MSVC)
include(libprotobuf-lite.cmake)
include(libprotobuf.cmake)
include(libprotoc.cmake)
include(protoc.cmake)
if (BUILD_TESTING)
include(protoc.cmake)
include(tests.cmake)
endif (BUILD_TESTING)
......@@ -5,15 +5,21 @@ on your computer before proceeding.
Compiling and Installing
========================
1. Check whether a gtest directory exists in the upper level directory. If
you checkout the code from github via "git clone", this gtest directory
won't exist and you won't be able to build the tests described below. To
avoid this problem consider downloading one of the release tar balls which
contains gtest already and copying the gest directory from there to your
protobuf directory:
1. Check whether a gtest directory exists in the upper level directory. If you
checkout the code from github via "git clone", this gtest directory won't
exist and you won't be able to build protobuf unit-tests. Consider using one
of the release tar balls instead:
https://github.com/google/protobuf/releases
These release tar balls are more stable versions of protobuf and already
have the gtest directory included.
You can also download gtest by yourself and put it in the right place.
If you absolutely don't want to build and run protobuf unit-tests, skip
this step and use protobuf at your own risk.
2. Use cmake to generate MSVC project files. Running the following commands
in a command shell will generate project files for Visual Studio 2008 in
a sub-directory named "build".
......@@ -23,21 +29,27 @@ Compiling and Installing
$ cd build
$ cmake -G "Visual Studio 9 2008" ..
If you don't have gtest, skip the build of tests by turning off the
BUILD_TESTING option:
$ cmake -G "Visutal Studio 9 2008" -DBUILD_TESTING=OFF ..
3. Open the generated protobuf.sln file in Microsoft Visual Studio.
4. Choose "Debug" or "Release" configuration as desired.
5. From the Build menu, choose "Build Solution". Wait for compiling to finish.
6. From a command shell, run tests.exe and lite-test.exe and check that all
tests pass. Make sure you have changed the working directory to the output
directory because tests.exe will try to find and run test_plugin.exe
in the working directory.
6. If you have built tests, run tests.exe and lite-test.exe from a command
shell and check that all tests pass. Make sure you have changed the working
directory to the output directory because tests.exe will try to find and run
test_plugin.exe in the working directory.
7. Run extract_includes.bat to copy all the public headers into a separate
"include" directory (under the top-level package directory).
"include" directory. This batch script can be found along with the generated
protobuf.sln file in the same directory.
8. Copy the contents of the include directory to wherever you want to put
headers.
9. Copy protoc.exe wherever you put build tools (probably somewhere in your
PATH).
10. Copy libprotobuf.lib, libprotobuf-lite.lib, and libprotoc.lib wherever you
put libraries.
put libraries.
To avoid conflicts between the MSVC debug and release runtime libraries, when
compiling a debug build of your application, you may need to link against a
......
#define GOOGLE_PROTOBUF_CMAKE_BUILD
#define HAVE_PTHREAD ${HAVE_PTHREAD}
#define HAVE_ZLIB ${HAVE_ZLIB}
This diff is collapsed.
include(CheckCXXSourceCompiles)
function(find_hash_map)
set(HAVE_HASH_MAP 1 PARENT_SCOPE)
set(HAVE_HASH_SET 1 PARENT_SCOPE)
# Search for hash_map in the following order:
# 1. <unordered_map> ::std::unordered_map
# 2. <tr1/unordered_map> ::std::tr1::unordered_map
# 3. <hash_map> ::hash_map
# 4. <hash_map> ::stdext::hash_map
# 5. <ext/hash_map> ::std::hash_map
# 6. <ext/hash_map> ::__gnu_cxx::hash_map
check_cxx_source_compiles("
#include <unordered_map>
int main() { ::std::unordered_map<int, int> v; return v[0]; }
" HAS_STD_UNORDERED_MAP)
if (HAS_STD_UNORDERED_MAP)
set(HASH_NAMESPACE ::std PARENT_SCOPE)
set(HASH_MAP_H <unordered_map> PARENT_SCOPE)
set(HASH_MAP_CLASS unordered_map PARENT_SCOPE)
set(HASH_SET_H <unordered_set> PARENT_SCOPE)
set(HASH_SET_CLASS unordered_set PARENT_SCOPE)
return()
endif (HAS_STD_UNORDERED_MAP)
check_cxx_source_compiles("
#include <tr1/unordered_map>
int main() { ::std::tr1::unordered_map<int, int> v; return v[0]; }
" HAS_STD_TR1_UNORDERED_MAP)
if (HAS_STD_TR1_UNORDERED_MAP)
set(HASH_NAMESPACE ::std::tr1 PARENT_SCOPE)
set(HASH_MAP_H <tr1/unordered_map> PARENT_SCOPE)
set(HASH_MAP_CLASS unordered_map PARENT_SCOPE)
set(HASH_SET_H <tr1/unordered_set> PARENT_SCOPE)
set(HASH_SET_CLASS unordered_set PARENT_SCOPE)
return()
endif (HAS_STD_TR1_UNORDERED_MAP)
check_cxx_source_compiles("
#include <hash_map>
int main() { ::hash_map<int, int> v; return v[0]; }
" HAS_HASH_MAP)
if (HAS_HASH_MAP)
set(HASH_NAMESPACE :: PARENT_SCOPE)
set(HASH_MAP_H <hash_map> PARENT_SCOPE)
set(HASH_MAP_CLASS hash_map PARENT_SCOPE)
set(HASH_SET_H <hash_set> PARENT_SCOPE)
set(HASH_SET_CLASS hash_set PARENT_SCOPE)
return()
endif (HAS_HASH_MAP)
check_cxx_source_compiles("
#include <hash_map>
int main() { ::stdext::hash_map<int, int> v; return v[0]; }
" HAS_STDEXT_HASH_MAP)
if (HAS_STDEXT_HASH_MAP)
set(HASH_NAMESPACE ::stdext PARENT_SCOPE)
set(HASH_MAP_H <hash_map> PARENT_SCOPE)
set(HASH_MAP_CLASS hash_map PARENT_SCOPE)
set(HASH_SET_H <hash_set> PARENT_SCOPE)
set(HASH_SET_CLASS hash_set PARENT_SCOPE)
return()
endif (HAS_STDEXT_HASH_MAP)
check_cxx_source_compiles("
#include <ext/hash_map>
int main() { ::std::hash_map<int, int> v; return v[0]; }
" HAS_STD_HASH_MAP)
if (HAS_STD_HASH_MAP)
set(HASH_NAMESPACE ::std PARENT_SCOPE)
set(HASH_MAP_H <ext/hash_map> PARENT_SCOPE)
set(HASH_MAP_CLASS hash_map PARENT_SCOPE)
set(HASH_SET_H <ext/hash_set> PARENT_SCOPE)
set(HASH_SET_CLASS hash_set PARENT_SCOPE)
return()
endif (HAS_STD_HASH_MAP)
check_cxx_source_compiles("
#include <ext/hash_map>
int main() { ::__gnu_cxx::hash_map<int, int> v; return v[0]; }
" HAS_GNU_CXX_HASH_MAP)
if (HAS_GNU_CXX_HASH_MAP)
set(HASH_NAMESPACE ::gnu_cxx PARENT_SCOPE)
set(HASH_MAP_H <ext/hash_map> PARENT_SCOPE)
set(HASH_MAP_CLASS hash_map PARENT_SCOPE)
set(HASH_SET_H <ext/hash_set> PARENT_SCOPE)
set(HASH_SET_CLASS hash_set PARENT_SCOPE)
return()
endif (HAS_GNU_CXX_HASH_MAP)
set(HAVE_HASH_MAP 0 PARENT_SCOPE)
set(HAVE_HASH_SET 0 PARENT_SCOPE)
endfunction()
function(find_hash_compare)
if (MSVC)
check_cxx_source_compiles("
#include ${HASH_MAP_H}
int main() { ::std::hash_compare<int> cp; return cp(0); }
" HAS_STD_HASH_COMPARE)
if (HAS_STD_HASH_COMPARE)
set(HASH_COMPARE ::std::hash_compare PARENT_SCOPE)
return()
endif (HAS_STD_HASH_COMPARE)
check_cxx_source_compiles("
#include ${HASH_MAP_H}
int main() { ::stdext::hash_compare<int> cp; return cp(0); }
" HAS_STDEXT_HASH_COMPARE)
if (HAS_STDEXT_HASH_COMPARE)
set(HASH_COMPARE ::stdext::hash_compare PARENT_SCOPE)
return()
endif (HAS_STDEXT_HASH_COMPARE)
endif (MSVC)
set(HASH_COMPARE PARENT_SCOPE)
endfunction()
find_hash_map()
find_hash_compare()
#define GOOGLE_PROTOBUF_HAVE_HASH_MAP ${HAVE_HASH_MAP}
#define GOOGLE_PROTOBUF_HAVE_HASH_SET ${HAVE_HASH_MAP}
#define GOOGLE_PROTOBUF_HASH_NAMESPACE ${HASH_NAMESPACE}
#define GOOGLE_PROTOBUF_HASH_MAP_H ${HASH_MAP_H}
#define GOOGLE_PROTOBUF_HASH_MAP_CLASS ${HASH_MAP_CLASS}
#define GOOGLE_PROTOBUF_HASH_SET_H ${HASH_SET_H}
#define GOOGLE_PROTOBUF_HASH_SET_CLASS ${HASH_SET_CLASS}
#define GOOGLE_PROTOBUF_HASH_COMPARE ${HASH_COMPARE}
......@@ -25,6 +25,7 @@ set(tests_protos
google/protobuf/unittest_drop_unknown_fields.proto
google/protobuf/unittest_embed_optimize_for.proto
google/protobuf/unittest_empty.proto
google/protobuf/unittest_enormous_descriptor.proto
google/protobuf/unittest_import.proto
google/protobuf/unittest_import_public.proto
google/protobuf/unittest_lite_imports_nonlite.proto
......
......@@ -39,8 +39,8 @@ set_variable_value() {
/^set\\($VARNAME/ {
start = 1;
print \$0;
split(values, vlist, \" \");
for (i = 1; i <= length(vlist); ++i) {
len = split(values, vlist, \" \");
for (i = 1; i <= len; ++i) {
printf(\" %s%s\\n\", prefix, vlist[i]);
}
next;
......@@ -58,12 +58,12 @@ set_variable_value() {
sort_files() {
for FILE in $@; do
echo $FILE
done | sort | uniq
done | LC_ALL=C sort | uniq
}
MAKEFILE=../src/Makefile.am
CMAKE_DIR=.
EXTRACT_INCLUDES_BAT=../vsprojects/extract_includes.bat
EXTRACT_INCLUDES_BAT=extract_includes.bat.in
[ -f "$MAKEFILE" ] || {
echo "Cannot find: $MAKEFILE"
......@@ -105,10 +105,17 @@ set_variable_value $CMAKE_DIR/tests.cmake tests_files $COMMON_PREFIX $TEST_SOURC
set_variable_value $CMAKE_DIR/tests.cmake lite_test_files $COMMON_PREFIX $LITE_TEST_SOURCES
# Generate extract_includes.bat
for HEADER in $HEADERS; do
echo $(dirname $HEADER) | sed "s/\\//\\\\/g"
done | sort | uniq | sed "s/^/mkdir include\\\\/" > $EXTRACT_INCLUDES_BAT
for HEADER in $HEADERS; do
WINPATH=$(echo $HEADER | sed 's;/;\\\\;g')
echo "copy ..\\src\\$WINPATH include\\$WINPATH" >> $EXTRACT_INCLUDES_BAT
echo "mkdir include" > $EXTRACT_INCLUDES_BAT
for HEADER in $PUBLIC_HEADERS; do
HEADER_DIR=$(dirname $HEADER)
while [ ! "$HEADER_DIR" = "." ]; do
echo $HEADER_DIR | sed "s/\\//\\\\/g"
HEADER_DIR=$(dirname $HEADER_DIR)
done
done | sort | uniq | sed "s/^/mkdir include\\\\/" >> $EXTRACT_INCLUDES_BAT
for HEADER in $PUBLIC_HEADERS; do
WINPATH=$(echo $HEADER | sed 's;/;\\;g')
echo "copy \${PROTOBUF_SOURCE_WIN32_PATH}\\..\\src\\$WINPATH include\\$WINPATH" >> $EXTRACT_INCLUDES_BAT
done
# Add pbconfig.h.
echo "copy \${PROTOBUF_BINARY_WIN32_PATH}\\google\\protobuf\\stubs\\pbconfig.h include\\google\\protobuf\\stubs\\pbconfig.h" >> $EXTRACT_INCLUDES_BAT
HASH_MAP_CLASS
HASH_MAP_H
HASH_NAMESPACE
HASH_SET_CLASS
HASH_SET_H
HAVE_HASH_MAP
HAVE_HASH_SET
......@@ -17,6 +17,9 @@ AC_INIT([Protocol Buffers],[3.0.0-alpha-4-pre],[protobuf@googlegroups.com],[prot
AM_MAINTAINER_MODE([enable])
AC_CONFIG_SRCDIR(src/google/protobuf/message.cc)
# The config file is generated but not used by the source code, since we only
# need very few of them, e.g. HAVE_PTHREAD and HAVE_ZLIB. Those macros are
# passed down in CXXFLAGS manually in src/Makefile.am
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
......@@ -146,6 +149,9 @@ AS_IF([test "$with_protoc" != "no"], [
AM_CONDITIONAL([USE_EXTERNAL_PROTOC], [test "$with_protoc" != "no"])
ACX_PTHREAD
AM_CONDITIONAL([HAVE_PTHREAD], [test "x$acx_pthread_ok" = "xyes"])
# We still keep this for improving pbconfig.h for unsupported platforms.
AC_CXX_STL_HASH
case "$target_os" in
......
......@@ -57,7 +57,7 @@ conformance-java: javac_middleman
# Targets for actually running tests.
test_cpp: protoc_middleman conformance-test-runner conformance-cpp
./conformance-test-runner ./conformance-cpp
./conformance-test-runner --failure_list failure_list_cpp.txt ./conformance-cpp
test_java: protoc_middleman conformance-test-runner conformance-java
./conformance-test-runner ./conformance-java
This diff is collapsed.
......@@ -83,24 +83,50 @@ class ConformanceTestSuite {
public:
ConformanceTestSuite() : verbose_(false) {}
// Sets the list of tests that are expected to fail when RunSuite() is called.
// RunSuite() will fail unless the set of failing tests is exactly the same
// as this list.
void SetFailureList(const std::vector<std::string>& failure_list);
// Run all the conformance tests against the given test runner.
// Test output will be stored in "output".
void RunSuite(ConformanceTestRunner* runner, std::string* output);
//
// Returns true if the set of failing tests was exactly the same as the
// failure list. If SetFailureList() was not called, returns true if all
// tests passed.
bool RunSuite(ConformanceTestRunner* runner, std::string* output);
private:
void ReportSuccess();
void ReportFailure(const char* fmt, ...);
void RunTest(const conformance::ConformanceRequest& request,
void ReportSuccess(const std::string& test_name);
void ReportFailure(const std::string& test_name, const char* fmt, ...);
void RunTest(const std::string& test_name,
const conformance::ConformanceRequest& request,
conformance::ConformanceResponse* response);
void DoExpectParseFailureForProto(const std::string& proto, int line);
void TestPrematureEOFForType(
google::protobuf::internal::WireFormatLite::FieldType type);
void ExpectParseFailureForProto(const std::string& proto,
const std::string& test_name);
void ExpectHardParseFailureForProto(const std::string& proto,
const std::string& test_name);
void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type);
bool CheckSetEmpty(const set<string>& set_to_check, const char* msg);
ConformanceTestRunner* runner_;
int successes_;
int failures_;
bool verbose_;
std::string output_;
// The set of test names that are expected to fail in this run, but haven't
// failed yet.
std::set<std::string> expected_to_fail_;
// The set of test names that have been run. Used to ensure that there are no
// duplicate names in the suite.
std::set<std::string> test_names_;
// The set of tests that failed, but weren't expected to.
std::set<std::string> unexpected_failing_tests_;
// The set of tests that succeeded, but weren't expected to.
std::set<std::string> unexpected_succeeding_tests_;
};
} // namespace protobuf
......
......@@ -55,6 +55,8 @@
#include <errno.h>
#include <unistd.h>
#include <fstream>
#include <vector>
#include "conformance.pb.h"
#include "conformance_test.h"
......@@ -62,6 +64,8 @@
using conformance::ConformanceRequest;
using conformance::ConformanceResponse;
using google::protobuf::internal::scoped_array;
using std::string;
using std::vector;
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
......@@ -180,18 +184,67 @@ class ForkPipeRunner : public google::protobuf::ConformanceTestRunner {
std::string executable_;
};
void UsageError() {
fprintf(stderr,
"Usage: conformance-test-runner [options] <test-program>\n");
fprintf(stderr, "\n");
fprintf(stderr, "Options:\n");
fprintf(stderr,
" --failure_list <filename> Use to specify list of tests\n");
fprintf(stderr,
" that are expected to fail. File\n");
fprintf(stderr,
" should contain one test name per\n");
fprintf(stderr,
" line. Use '#' for comments.\n");
exit(1);
}
void ParseFailureList(const char *filename, vector<string>* failure_list) {
std::ifstream infile(filename);
for (string line; getline(infile, line);) {
// Remove whitespace.
line.erase(std::remove_if(line.begin(), line.end(), ::isspace),
line.end());
// Remove comments.
line = line.substr(0, line.find("#"));
if (!line.empty()) {
failure_list->push_back(line);
}
}
}
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "Usage: conformance-test-runner <test-program>\n");
exit(1);
int arg = 1;
char *program;
vector<string> failure_list;
for (int arg = 1; arg < argc; ++arg) {
if (strcmp(argv[arg], "--failure_list") == 0) {
if (++arg == argc) UsageError();
ParseFailureList(argv[arg], &failure_list);
} else if (argv[arg][0] == '-') {
fprintf(stderr, "Unknown option: %s\n", argv[arg]);
UsageError();
} else {
if (arg != argc - 1) {
fprintf(stderr, "Too many arguments.\n");
UsageError();
}
program = argv[arg];
}
}
ForkPipeRunner runner(argv[1]);
ForkPipeRunner runner(program);
google::protobuf::ConformanceTestSuite suite;
suite.SetFailureList(failure_list);
std::string output;
suite.RunSuite(&runner, &output);
bool ok = suite.RunSuite(&runner, &output);
fwrite(output.c_str(), 1, output.size(), stderr);
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
# This is the list of conformance tests that are known to fail for the C++
# implementation right now. These should be fixed.
#
# By listing them here we can keep tabs on which ones are failing and be sure
# that we don't introduce regressions in other tests.
#
# TODO(haberman): insert links to corresponding bugs tracking the issue.
# Should we use GitHub issues or the Google-internal bug tracker?
PrematureEofBeforeKnownRepeatedValue.MESSAGE
PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE
PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE
PrematureEofInPackedField.BOOL
PrematureEofInPackedField.ENUM
PrematureEofInPackedField.INT32
PrematureEofInPackedField.INT64
PrematureEofInPackedField.SINT32
PrematureEofInPackedField.SINT64
PrematureEofInPackedField.UINT32
PrematureEofInPackedField.UINT64
PrematureEofInsideKnownRepeatedValue.MESSAGE
......@@ -33,6 +33,7 @@ package com.google.protobuf.nano;
import java.io.IOException;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
/**
......@@ -61,6 +62,7 @@ public final class CodedOutputByteBufferNano {
private CodedOutputByteBufferNano(final ByteBuffer buffer) {
this.buffer = buffer;
this.buffer.order(ByteOrder.LITTLE_ENDIAN);
}
/**
......@@ -1038,24 +1040,20 @@ public final class CodedOutputByteBufferNano {
/** Write a little-endian 32-bit integer. */
public void writeRawLittleEndian32(final int value) throws IOException {
writeRawByte((value ) & 0xFF);
writeRawByte((value >> 8) & 0xFF);
writeRawByte((value >> 16) & 0xFF);
writeRawByte((value >> 24) & 0xFF);
if (buffer.remaining() < 4) {
throw new OutOfSpaceException(buffer.position(), buffer.limit());
}
buffer.putInt(value);
}
public static final int LITTLE_ENDIAN_32_SIZE = 4;
/** Write a little-endian 64-bit integer. */
public void writeRawLittleEndian64(final long value) throws IOException {
writeRawByte((int)(value ) & 0xFF);
writeRawByte((int)(value >> 8) & 0xFF);
writeRawByte((int)(value >> 16) & 0xFF);
writeRawByte((int)(value >> 24) & 0xFF);
writeRawByte((int)(value >> 32) & 0xFF);
writeRawByte((int)(value >> 40) & 0xFF);
writeRawByte((int)(value >> 48) & 0xFF);
writeRawByte((int)(value >> 56) & 0xFF);
if (buffer.remaining() < 8) {
throw new OutOfSpaceException(buffer.position(), buffer.limit());
}
buffer.putLong(value);
}
public static final int LITTLE_ENDIAN_64_SIZE = 8;
......
#!/bin/bash
# Invoked by the Xcode projects to build the protos needed for the unittests.
set -eu
readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/protos"
# Helper for bailing.
die() {
echo "Error: $1"
exit 2
}
# What to do.
case "${ACTION}" in
"")
# Build, fall thru
;;
"clean")
rm -rf "${OUTPUT_DIR}"
exit 0
;;
*)
die "Unknown action requested: ${ACTION}"
;;
esac
# Move to the top of the protobuf directories.
cd "${SRCROOT}/.."
[[ -x src/protoc ]] || \
die "Could not find the protoc binary; make sure you have built it (objectivec/DevTools/full_mac_build.sh -h)."
RUN_PROTOC=no
if [[ ! -d "${OUTPUT_DIR}" ]] ; then
RUN_PROTOC=yes
else
# Find the newest input file (protos, compiler, and this script).
# (these patterns catch some extra stuff, but better to over sample than
# under)
readonly NewestInput=$(find \
src/google/protobuf/*.proto \
objectivec/Tests/*.proto \
src/.libs src/*.la src/protoc \
objectivec/DevTools/compile_testing_protos.sh \
-type f -print0 \
| xargs -0 stat -f "%m %N" \
| sort -n | tail -n1 | cut -f2- -d" ")
# Find the oldest output file.
readonly OldestOutput=$(find \
"${OUTPUT_DIR}" \
-type f -print0 \
| xargs -0 stat -f "%m %N" \
| sort -n -r | tail -n1 | cut -f2- -d" ")
# If the newest input is newer than the oldest output, regenerate.
if [[ "${NewestInput}" -nt "${OldestOutput}" ]] ; then
RUN_PROTOC=yes
fi
fi
if [[ "${RUN_PROTOC}" != "yes" ]] ; then
# Up to date.
exit 0
fi
# Ensure the output dir exists
mkdir -p "${OUTPUT_DIR}/google/protobuf"
CORE_PROTO_FILES=( \
src/google/protobuf/unittest_custom_options.proto \
src/google/protobuf/unittest_enormous_descriptor.proto \
src/google/protobuf/unittest_embed_optimize_for.proto \
src/google/protobuf/unittest_empty.proto \
src/google/protobuf/unittest_import.proto \
src/google/protobuf/unittest_import_lite.proto \
src/google/protobuf/unittest_lite.proto \
src/google/protobuf/unittest_mset.proto \
src/google/protobuf/unittest_no_generic_services.proto \
src/google/protobuf/unittest_optimize_for.proto \
src/google/protobuf/unittest.proto \
src/google/protobuf/unittest_import_public.proto \
src/google/protobuf/unittest_import_public_lite.proto \
src/google/protobuf/unittest_drop_unknown_fields.proto \
src/google/protobuf/unittest_preserve_unknown_enum.proto \
src/google/protobuf/map_lite_unittest.proto \
src/google/protobuf/map_proto2_unittest.proto \
src/google/protobuf/map_unittest.proto \
)
compile_proto() {
src/protoc \
--objc_out="${OUTPUT_DIR}/google/protobuf" \
--proto_path=src/google/protobuf/ \
--proto_path=src \
$*
}
for a_proto in "${CORE_PROTO_FILES[@]}" ; do
compile_proto "${a_proto}"
done
OBJC_PROTO_FILES=( \
objectivec/Tests/unittest_cycle.proto \
objectivec/Tests/unittest_runtime_proto2.proto \
objectivec/Tests/unittest_runtime_proto3.proto \
objectivec/Tests/unittest_objc.proto \
objectivec/Tests/unittest_objc_startup.proto \
)
for a_proto in "${OBJC_PROTO_FILES[@]}" ; do
compile_proto --proto_path="objectivec/Tests" "${a_proto}"
done
......@@ -162,7 +162,7 @@ wrapped_make -j "${NUM_MAKE_JOBS}" all
wrapped_make -j "${NUM_MAKE_JOBS}" check
header "Ensuring the ObjC descriptors are current."
# Find the newest input file (protos, compiler, and this script).
# Find the newest input file (protos, compiler, and the generator script).
# (these patterns catch some extra stuff, but better to over sample than under)
readonly NewestInput=$(find \
src/google/protobuf/*.proto \
......
......@@ -30,7 +30,7 @@
#import <Foundation/Foundation.h>
#import "GPBTypes.h"
#import "GPBRuntimeTypes.h"
// These classes are used for repeated fields of basic data types. They are used because
// they perform better than boxing into NSNumbers in NSArrays.
......
......@@ -60,7 +60,7 @@
- (int64_t)readSInt64;
- (BOOL)readBool;
- (NSString *)readString;
- (NSData *)readData;
- (NSData *)readBytes;
// Read an embedded message field value from the stream.
- (void)readMessage:(GPBMessage *)message
......
......@@ -38,7 +38,7 @@
static const NSUInteger kDefaultRecursionLimit = 64;
static inline void CheckSize(GPBCodedInputStreamState *state, size_t size) {
static void CheckSize(GPBCodedInputStreamState *state, size_t size) {
size_t newSize = state->bufferPos + size;
if (newSize > state->bufferSize) {
[NSException raise:NSParseErrorException format:@""];
......@@ -50,26 +50,26 @@ static inline void CheckSize(GPBCodedInputStreamState *state, size_t size) {
}
}
static inline int8_t ReadRawByte(GPBCodedInputStreamState *state) {
static int8_t ReadRawByte(GPBCodedInputStreamState *state) {
CheckSize(state, sizeof(int8_t));
return ((int8_t *)state->bytes)[state->bufferPos++];
}
static inline int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) {
static int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) {
CheckSize(state, sizeof(int32_t));
int32_t value = OSReadLittleInt32(state->bytes, state->bufferPos);
state->bufferPos += sizeof(int32_t);
return value;
}
static inline int64_t ReadRawLittleEndian64(GPBCodedInputStreamState *state) {
static int64_t ReadRawLittleEndian64(GPBCodedInputStreamState *state) {
CheckSize(state, sizeof(int64_t));
int64_t value = OSReadLittleInt64(state->bytes, state->bufferPos);
state->bufferPos += sizeof(int64_t);
return value;
}
static inline int32_t ReadRawVarint32(GPBCodedInputStreamState *state) {
static int32_t ReadRawVarint32(GPBCodedInputStreamState *state) {
int8_t tmp = ReadRawByte(state);
if (tmp >= 0) {
return tmp;
......@@ -104,7 +104,7 @@ static inline int32_t ReadRawVarint32(GPBCodedInputStreamState *state) {
return result;
}
static inline int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
static int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
int32_t shift = 0;
int64_t result = 0;
while (shift < 64) {
......@@ -119,7 +119,7 @@ static inline int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
return 0;
}
static inline void SkipRawData(GPBCodedInputStreamState *state, size_t size) {
static void SkipRawData(GPBCodedInputStreamState *state, size_t size) {
CheckSize(state, size);
state->bufferPos += size;
}
......@@ -222,7 +222,7 @@ NSString *GPBCodedInputStreamReadRetainedString(
return result;
}
NSData *GPBCodedInputStreamReadRetainedData(GPBCodedInputStreamState *state) {
NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) {
int32_t size = ReadRawVarint32(state);
if (size < 0) return nil;
CheckSize(state, size);
......@@ -232,7 +232,7 @@ NSData *GPBCodedInputStreamReadRetainedData(GPBCodedInputStreamState *state) {
return result;
}
NSData *GPBCodedInputStreamReadRetainedDataNoCopy(
NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(
GPBCodedInputStreamState *state) {
int32_t size = ReadRawVarint32(state);
if (size < 0) return nil;
......@@ -453,8 +453,8 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
GPBCodedInputStreamPopLimit(&state_, oldLimit);
}
- (NSData *)readData {
return [GPBCodedInputStreamReadRetainedData(&state_) autorelease];
- (NSData *)readBytes {
return [GPBCodedInputStreamReadRetainedBytes(&state_) autorelease];
}
- (uint32_t)readUInt32 {
......@@ -499,7 +499,7 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
// Returns true if the passed in bytes are 7 bit ascii.
// This routine needs to be fast.
static inline bool AreBytesIn7BitASCII(const uint8_t *bytes, NSUInteger len) {
static bool AreBytesIn7BitASCII(const uint8_t *bytes, NSUInteger len) {
// In the loops below, it's more efficient to collect rather than do
// conditional at every step.
#if __LP64__
......@@ -587,7 +587,7 @@ static inline bool AreBytesIn7BitASCII(const uint8_t *bytes, NSUInteger len) {
return true;
}
static inline void GPBStringInitStringValue(GPBString *string) {
static void GPBStringInitStringValue(GPBString *string) {
OSSpinLockLock(&string->lock_);
GPBStringInitStringValueAlreadyLocked(string);
OSSpinLockUnlock(&string->lock_);
......
......@@ -114,9 +114,9 @@ int64_t GPBCodedInputStreamReadSInt64(GPBCodedInputStreamState *state);
BOOL GPBCodedInputStreamReadBool(GPBCodedInputStreamState *state);
NSString *GPBCodedInputStreamReadRetainedString(GPBCodedInputStreamState *state)
__attribute((ns_returns_retained));
NSData *GPBCodedInputStreamReadRetainedData(GPBCodedInputStreamState *state)
NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state)
__attribute((ns_returns_retained));
NSData *GPBCodedInputStreamReadRetainedDataNoCopy(
NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(
GPBCodedInputStreamState *state) __attribute((ns_returns_retained));
size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state,
......
This diff is collapsed.
This diff is collapsed.
......@@ -30,7 +30,7 @@
#import <Foundation/Foundation.h>
#import "GPBTypes.h"
#import "GPBRuntimeTypes.h"
@class GPBEnumDescriptor;
@class GPBFieldDescriptor;
......@@ -89,14 +89,14 @@ typedef NS_ENUM(NSInteger, GPBFieldType) {
@property(nonatomic, readonly, copy) NSString *name;
@property(nonatomic, readonly) uint32_t number;
@property(nonatomic, readonly) GPBType type;
@property(nonatomic, readonly) GPBDataType dataType;
@property(nonatomic, readonly) BOOL hasDefaultValue;
@property(nonatomic, readonly) GPBValue defaultValue;
@property(nonatomic, readonly) GPBGenericValue defaultValue;
@property(nonatomic, readonly, getter=isRequired) BOOL required;
@property(nonatomic, readonly, getter=isOptional) BOOL optional;
@property(nonatomic, readonly) GPBFieldType fieldType;
// If it is a map, the value type is in -type.
@property(nonatomic, readonly) GPBType mapKeyType;
@property(nonatomic, readonly) GPBDataType mapKeyDataType;
@property(nonatomic, readonly, getter=isPackable) BOOL packable;
@property(nonatomic, readonly, assign) GPBOneofDescriptor *containingOneof;
......@@ -129,12 +129,14 @@ typedef NS_ENUM(NSInteger, GPBFieldType) {
@end
@interface GPBExtensionDescriptor : NSObject
@interface GPBExtensionDescriptor : NSObject<NSCopying>
@property(nonatomic, readonly) uint32_t fieldNumber;
@property(nonatomic, readonly) GPBType type;
@property(nonatomic, readonly) Class containingMessageClass;
@property(nonatomic, readonly) GPBDataType dataType;
@property(nonatomic, readonly, getter=isRepeated) BOOL repeated;
@property(nonatomic, readonly, getter=isPackable) BOOL packable;
@property(nonatomic, readonly, assign) Class msgClass;
@property(nonatomic, readonly) NSString *singletonName;
@property(nonatomic, readonly, strong) GPBEnumDescriptor *enumDescriptor;
@property(nonatomic, readonly) id defaultValue;
@end
This diff is collapsed.
......@@ -33,6 +33,7 @@
// subject to change at any time without notice.
#import "GPBDescriptor.h"
#import "GPBWireFormat.h"
// Describes attributes of the field.
typedef NS_OPTIONS(uint32_t, GPBFieldFlags) {
......@@ -66,8 +67,6 @@ typedef NS_OPTIONS(uint32_t, GPBFieldFlags) {
// set, the name can be derived from the ObjC name.
GPBFieldTextFormatNameCustom = 1 << 16,
// Indicates the field has an enum descriptor.
// TODO(thomasvl): Output the CPP check to use descFunc or validator based
// on final compile. This will then get added based on that.
GPBFieldHasEnumDescriptor = 1 << 17,
};
......@@ -84,21 +83,21 @@ typedef struct GPBMessageFieldDescription {
int32_t hasIndex;
// Field flags. Use accessor functions below.
GPBFieldFlags flags;
// Type of the ivar.
GPBType type;
// Data type of the ivar.
GPBDataType dataType;
// Offset of the variable into it's structure struct.
size_t offset;
// FieldOptions protobuf, serialized as string.
const char *fieldOptions;
GPBValue defaultValue; // Default value for the ivar.
GPBGenericValue defaultValue; // Default value for the ivar.
union {
const char *className; // Name for message class.
// For enums only: If EnumDescriptors are compiled in, it will be that,
// otherwise it will be the verifier.
GPBEnumDescriptorFunc enumDescFunc;
GPBEnumValidationFunc enumVerifier;
} typeSpecific;
} dataTypeSpecific;
} GPBMessageFieldDescription;
// Describes a oneof.
......@@ -133,10 +132,10 @@ typedef NS_OPTIONS(uint32_t, GPBExtensionOptions) {
// An extension
typedef struct GPBExtensionDescription {
const char *singletonName;
GPBType type;
GPBDataType dataType;
const char *extendedClass;
int32_t fieldNumber;
GPBValue defaultValue;
GPBGenericValue defaultValue;
const char *messageOrGroupClassName;
GPBExtensionOptions options;
GPBEnumDescriptorFunc enumDescriptorFunc;
......@@ -217,7 +216,7 @@ typedef struct GPBExtensionDescription {
SEL getSel_;
SEL setSel_;
SEL hasSel_;
SEL hasOrCountSel_; // *Count for map<>/repeated fields, has* otherwise.
SEL setHasSel_;
}
......@@ -254,10 +253,18 @@ typedef struct GPBExtensionDescription {
@package
GPBExtensionDescription *description_;
}
@property(nonatomic, readonly) GPBWireFormat wireType;
// For repeated extensions, alternateWireType is the wireType with the opposite
// value for the packable property. i.e. - if the extension was marked packed
// it would be the wire type for unpacked; if the extension was marked unpacked,
// it would be the wire type for packed.
@property(nonatomic, readonly) GPBWireFormat alternateWireType;
// description has to be long lived, it is held as a raw pointer.
- (instancetype)initWithExtensionDescription:
(GPBExtensionDescription *)description;
(GPBExtensionDescription *)description;
- (NSComparisonResult)compareByFieldNumber:(GPBExtensionDescriptor *)other;
@end
CF_EXTERN_C_BEGIN
......@@ -267,8 +274,8 @@ GPB_INLINE BOOL GPBFieldIsMapOrArray(GPBFieldDescriptor *field) {
(GPBFieldRepeated | GPBFieldMapKeyMask)) != 0;
}
GPB_INLINE GPBType GPBGetFieldType(GPBFieldDescriptor *field) {
return field->description_->type;
GPB_INLINE GPBDataType GPBGetFieldDataType(GPBFieldDescriptor *field) {
return field->description_->dataType;
}
GPB_INLINE int32_t GPBFieldHasIndex(GPBFieldDescriptor *field) {
......@@ -281,6 +288,12 @@ GPB_INLINE uint32_t GPBFieldNumber(GPBFieldDescriptor *field) {
uint32_t GPBFieldTag(GPBFieldDescriptor *self);
// For repeated fields, alternateWireType is the wireType with the opposite
// value for the packable property. i.e. - if the field was marked packed it
// would be the wire type for unpacked; if the field was marked unpacked, it
// would be the wire type for packed.
uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self);
GPB_INLINE BOOL GPBPreserveUnknownFields(GPBFileSyntax syntax) {
return syntax != GPBFileSyntaxProto3;
}
......@@ -289,4 +302,17 @@ GPB_INLINE BOOL GPBHasPreservingUnknownEnumSemantics(GPBFileSyntax syntax) {
return syntax == GPBFileSyntaxProto3;
}
GPB_INLINE BOOL GPBExtensionIsRepeated(GPBExtensionDescription *description) {
return (description->options & GPBExtensionRepeated) != 0;
}
GPB_INLINE BOOL GPBExtensionIsPacked(GPBExtensionDescription *description) {
return (description->options & GPBExtensionPacked) != 0;
}
GPB_INLINE BOOL GPBExtensionIsWireFormat(GPBExtensionDescription *description) {
return (description->options & GPBExtensionSetWireFormat) != 0;
}
CF_EXTERN_C_END
......@@ -30,7 +30,7 @@
#import <Foundation/Foundation.h>
#import "GPBTypes.h"
#import "GPBRuntimeTypes.h"
// These classes are used for map fields of basic data types. They are used because
// they perform better than boxing into NSNumbers in NSDictionaries.
......
This diff is collapsed.
......@@ -41,7 +41,8 @@
- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field;
- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
asField:(GPBFieldDescriptor *)field;
- (void)setGPBValue:(GPBValue *)value forGPBValueKey:(GPBValue *)key;
- (void)setGPBGenericValue:(GPBGenericValue *)value
forGPBGenericValueKey:(GPBGenericValue *)key;
- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block;
@end
......@@ -75,8 +76,8 @@
//%
//%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Enum()
//%- (NSData *)serializedDataForUnknownValue:(int32_t)value
//% forKey:(GPBValue *)key
//% keyType:(GPBType)keyType;
//% forKey:(GPBGenericValue *)key
//% keyDataType:(GPBDataType)keyDataType;
//%
//%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt32)
......@@ -129,8 +130,8 @@
GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
}
- (NSData *)serializedDataForUnknownValue:(int32_t)value
forKey:(GPBValue *)key
keyType:(GPBType)keyType;
forKey:(GPBGenericValue *)key
keyDataType:(GPBDataType)keyDataType;
@end
@interface GPBUInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
......@@ -192,8 +193,8 @@
GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
}
- (NSData *)serializedDataForUnknownValue:(int32_t)value
forKey:(GPBValue *)key
keyType:(GPBType)keyType;
forKey:(GPBGenericValue *)key
keyDataType:(GPBDataType)keyDataType;
@end
@interface GPBInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
......@@ -255,8 +256,8 @@
GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
}
- (NSData *)serializedDataForUnknownValue:(int32_t)value
forKey:(GPBValue *)key
keyType:(GPBType)keyType;
forKey:(GPBGenericValue *)key
keyDataType:(GPBDataType)keyDataType;
@end
@interface GPBUInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
......@@ -318,8 +319,8 @@
GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
}
- (NSData *)serializedDataForUnknownValue:(int32_t)value
forKey:(GPBValue *)key
keyType:(GPBType)keyType;
forKey:(GPBGenericValue *)key
keyDataType:(GPBDataType)keyDataType;
@end
@interface GPBInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
......@@ -381,8 +382,8 @@
GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
}
- (NSData *)serializedDataForUnknownValue:(int32_t)value
forKey:(GPBValue *)key
keyType:(GPBType)keyType;
forKey:(GPBGenericValue *)key
keyDataType:(GPBDataType)keyDataType;
@end
@interface GPBBoolObjectDictionary () <GPBDictionaryInternalsProtocol> {
......@@ -444,8 +445,8 @@
GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
}
- (NSData *)serializedDataForUnknownValue:(int32_t)value
forKey:(GPBValue *)key
keyType:(GPBType)keyType;
forKey:(GPBGenericValue *)key
keyDataType:(GPBDataType)keyDataType;
@end
//%PDDM-EXPAND-END (6 expansions)
......
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#import <Foundation/Foundation.h>
#import "GPBExtensionField.h"
struct GPBExtensionDescription;
@interface GPBExtensionField ()
- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
message:(GPBMessage *)message;
- (instancetype)initWithDescription:(struct GPBExtensionDescription *)description;
- (size_t)computeSerializedSizeIncludingTag:(id)value;
- (void)writeValue:(id)value
includingTagToCodedOutputStream:(GPBCodedOutputStream *)output;
- (NSComparisonResult)compareByFieldNumber:(GPBExtensionField *)other;
@end
......@@ -30,22 +30,21 @@
#import <Foundation/Foundation.h>
#import "GPBWireFormat.h"
#import "GPBTypes.h"
#import "GPBDescriptor.h"
@class GPBCodedInputStream;
@class GPBCodedOutputStream;
@class GPBExtensionRegistry;
@class GPBDescriptor;
@class GPBExtensionDescriptor;
@interface GPBExtensionField : NSObject<NSCopying>
void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension,
BOOL isPackedOnStream,
GPBCodedInputStream *input,
GPBExtensionRegistry *extensionRegistry,
GPBMessage *message);
@property(nonatomic, readonly) int32_t fieldNumber;
@property(nonatomic, readonly) GPBWireFormat wireType;
@property(nonatomic, readonly) BOOL isRepeated;
@property(nonatomic, readonly) GPBDescriptor *containingType;
@property(nonatomic, readonly) id defaultValue;
@property(nonatomic, readonly) GPBExtensionDescriptor *descriptor;
size_t GPBComputeExtensionSerializedSizeIncludingTag(
GPBExtensionDescriptor *extension, id value);
@end
void GPBWriteExtensionValueToOutputStream(GPBExtensionDescriptor *extension,
id value,
GPBCodedOutputStream *output);
......@@ -31,7 +31,7 @@
#import <Foundation/Foundation.h>
@class GPBDescriptor;
@class GPBExtensionField;
@class GPBExtensionDescriptor;
// A table of known extensions, searchable by name or field number. When
// parsing a protocol message that might have extensions, you must provide an
......@@ -54,10 +54,10 @@
//
@interface GPBExtensionRegistry : NSObject<NSCopying>
- (void)addExtension:(GPBExtensionField *)extension;
- (void)addExtension:(GPBExtensionDescriptor *)extension;
- (void)addExtensions:(GPBExtensionRegistry *)registry;
- (GPBExtensionField *)getExtension:(GPBDescriptor *)containingType
fieldNumber:(NSInteger)fieldNumber;
- (GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
fieldNumber:(NSInteger)fieldNumber;
@end
......@@ -32,7 +32,6 @@
#import "GPBBootstrap.h"
#import "GPBDescriptor.h"
#import "GPBExtensionField.h"
@implementation GPBExtensionRegistry {
// TODO(dmaclach): Reimplement with CFDictionaries that don't use
......@@ -60,31 +59,34 @@
return result;
}
- (NSMutableDictionary *)extensionMapForContainingType:
(GPBDescriptor *)containingType {
- (NSMutableDictionary *)extensionMapForContainingMessageClass:
(Class)containingMessageClass {
NSMutableDictionary *extensionMap =
[mutableClassMap_ objectForKey:containingType];
[mutableClassMap_ objectForKey:containingMessageClass];
if (extensionMap == nil) {
extensionMap = [NSMutableDictionary dictionary];
[mutableClassMap_ setObject:extensionMap forKey:containingType];
[mutableClassMap_ setObject:extensionMap
forKey:(id<NSCopying>)containingMessageClass];
}
return extensionMap;
}
- (void)addExtension:(GPBExtensionField *)extension {
- (void)addExtension:(GPBExtensionDescriptor *)extension {
if (extension == nil) {
return;
}
GPBDescriptor *containingType = [extension containingType];
Class containingMessageClass = extension.containingMessageClass;
NSMutableDictionary *extensionMap =
[self extensionMapForContainingType:containingType];
[extensionMap setObject:extension forKey:@([extension fieldNumber])];
[self extensionMapForContainingMessageClass:containingMessageClass];
[extensionMap setObject:extension forKey:@(extension.fieldNumber)];
}
- (GPBExtensionField *)getExtension:(GPBDescriptor *)containingType
fieldNumber:(NSInteger)fieldNumber {
NSDictionary *extensionMap = [mutableClassMap_ objectForKey:containingType];
- (GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
fieldNumber:(NSInteger)fieldNumber {
Class messageClass = descriptor.messageClass;
NSDictionary *extensionMap =
[mutableClassMap_ objectForKey:messageClass];
return [extensionMap objectForKey:@(fieldNumber)];
}
......@@ -94,11 +96,11 @@
return;
}
NSMutableDictionary *otherClassMap = registry->mutableClassMap_;
for (GPBDescriptor *containingType in otherClassMap) {
for (Class containingMessageClass in otherClassMap) {
NSMutableDictionary *extensionMap =
[self extensionMapForContainingType:containingType];
[self extensionMapForContainingMessageClass:containingMessageClass];
NSMutableDictionary *otherExtensionMap =
[registry extensionMapForContainingType:containingType];
[registry extensionMapForContainingMessageClass:containingMessageClass];
[extensionMap addEntriesFromDictionary:otherExtensionMap];
}
}
......
......@@ -35,7 +35,7 @@
@class GPBDescriptor;
@class GPBCodedInputStream;
@class GPBCodedOutputStream;
@class GPBExtensionField;
@class GPBExtensionDescriptor;
@class GPBExtensionRegistry;
@class GPBFieldDescriptor;
@class GPBUnknownFieldSet;
......@@ -148,14 +148,14 @@ CF_EXTERN_C_END
// Extensions use boxed values (NSNumbers) for PODs, NSMutableArrays for
// repeated. If the extension is a Message one will be auto created for you
// and returned similar to fields.
- (BOOL)hasExtension:(GPBExtensionField *)extension;
- (id)getExtension:(GPBExtensionField *)extension;
- (void)setExtension:(GPBExtensionField *)extension value:(id)value;
- (void)addExtension:(GPBExtensionField *)extension value:(id)value;
- (void)setExtension:(GPBExtensionField *)extension
- (BOOL)hasExtension:(GPBExtensionDescriptor *)extension;
- (id)getExtension:(GPBExtensionDescriptor *)extension;
- (void)setExtension:(GPBExtensionDescriptor *)extension value:(id)value;
- (void)addExtension:(GPBExtensionDescriptor *)extension value:(id)value;
- (void)setExtension:(GPBExtensionDescriptor *)extension
index:(NSUInteger)index
value:(id)value;
- (void)clearExtension:(GPBExtensionField *)extension;
- (void)clearExtension:(GPBExtensionDescriptor *)extension;
- (void)setUnknownFields:(GPBUnknownFieldSet *)unknownFields;
......
This diff is collapsed.
......@@ -67,9 +67,9 @@ typedef struct GPBMessage_Storage *GPBMessage_StoragePtr;
// Gets an extension value without autocreating the result if not found. (i.e.
// returns nil if the extension is not set)
- (id)getExistingExtension:(GPBExtensionField *)extension;
- (id)getExistingExtension:(GPBExtensionDescriptor *)extension;
// Returns an array of GPBExtensionField* for all the extensions currently
// Returns an array of GPBExtensionDescriptor* for all the extensions currently
// in use on the message. They are sorted by field number.
- (NSArray *)sortedExtensionsInUse;
......
......@@ -35,11 +35,10 @@
#import "GPBCodedOutputStream.h"
#import "GPBDescriptor.h"
#import "GPBDictionary.h"
#import "GPBExtensionField.h"
#import "GPBExtensionRegistry.h"
#import "GPBField.h"
#import "GPBMessage.h"
#import "GPBRootObject.h"
#import "GPBUnknownField.h"
#import "GPBUnknownFieldSet.h"
#import "GPBUtilities.h"
#import "GPBWireFormat.h"
......@@ -36,14 +36,27 @@
#import "GPBCodedOutputStream.m"
#import "GPBDescriptor.m"
#import "GPBDictionary.m"
#import "GPBExtensionField.m"
#import "GPBExtensionInternals.m"
#import "GPBExtensionRegistry.m"
#import "GPBField.m"
#import "GPBMessage.m"
#import "GPBRootObject.m"
#import "GPBUnknownField.m"
#import "GPBUnknownFieldSet.m"
#import "GPBUtilities.m"
#import "GPBWellKnownTypes.m"
#import "GPBWireFormat.m"
#import "google/protobuf/Descriptor.pbobjc.m"
// Duration and Timestamp are #imported into GPBWellKnownTypes.m to the
// Objective C categories added will always be linked in with the classes.
#import "google/protobuf/Any.pbobjc.m"
#import "google/protobuf/Api.pbobjc.m"
// #import "google/protobuf/Duration.pbobjc.m"
#import "google/protobuf/Empty.pbobjc.m"
#import "google/protobuf/FieldMask.pbobjc.m"
#import "google/protobuf/SourceContext.pbobjc.m"
#import "google/protobuf/Struct.pbobjc.m"
// #import "google/protobuf/Timestamp.pbobjc.m"
#import "google/protobuf/Type.pbobjc.m"
#import "google/protobuf/Wrappers.pbobjc.m"
......@@ -34,8 +34,7 @@
#import "GPBProtocolBuffers.h"
#import "GPBDescriptor_PackagePrivate.h"
#import "GPBExtensionField_PackagePrivate.h"
#import "GPBExtensionRegistry.h"
#import "GPBExtensionInternals.h"
#import "GPBMessage_PackagePrivate.h"
#import "GPBRootObject_PackagePrivate.h"
#import "GPBUtilities_PackagePrivate.h"
......@@ -36,7 +36,6 @@
#import <CoreFoundation/CoreFoundation.h>
#import "GPBDescriptor.h"
#import "GPBExtensionField.h"
#import "GPBUtilities_PackagePrivate.h"
@interface GPBExtensionDescriptor (GPBRootObject)
......@@ -130,14 +129,14 @@ static CFMutableDictionaryRef gExtensionSingletonDictionary = NULL;
return nil;
}
+ (void)globallyRegisterExtension:(GPBExtensionField *)field {
const char *key = [field.descriptor singletonNameC];
+ (void)globallyRegisterExtension:(GPBExtensionDescriptor *)field {
const char *key = [field singletonNameC];
OSSpinLockLock(&gExtensionSingletonDictionaryLock_);
CFDictionarySetValue(gExtensionSingletonDictionary, key, field);
OSSpinLockUnlock(&gExtensionSingletonDictionaryLock_);
}
GPB_INLINE id ExtensionForName(id self, SEL _cmd) {
static id ExtensionForName(id self, SEL _cmd) {
// Really fast way of doing "classname_selName".
// This came up as a hotspot (creation of NSString *) when accessing a
// lot of extensions.
......
......@@ -32,12 +32,12 @@
#import "GPBRootObject.h"
@class GPBExtensionField;
@class GPBExtensionDescriptor;
@interface GPBRootObject ()
// Globally register.
+ (void)globallyRegisterExtension:(GPBExtensionField *)field;
+ (void)globallyRegisterExtension:(GPBExtensionDescriptor *)field;
@end
......
......@@ -63,36 +63,36 @@ typedef union {
GPB_UNSAFE_UNRETAINED NSString *valueString;
GPB_UNSAFE_UNRETAINED GPBMessage *valueMessage;
int32_t valueEnum;
} GPBValue;
} GPBGenericValue;
// Do not change the order of this enum (or add things to it) without thinking
// about it very carefully. There are several things that depend on the order.
typedef enum {
GPBTypeBool = 0,
GPBTypeFixed32,
GPBTypeSFixed32,
GPBTypeFloat,
GPBTypeFixed64,
GPBTypeSFixed64,
GPBTypeDouble,
GPBTypeInt32,
GPBTypeInt64,
GPBTypeSInt32,
GPBTypeSInt64,
GPBTypeUInt32,
GPBTypeUInt64,
GPBTypeData, // Maps to Bytes Protobuf type
GPBTypeString,
GPBTypeMessage,
GPBTypeGroup,
GPBTypeEnum,
} GPBType;
GPBDataTypeBool = 0,
GPBDataTypeFixed32,
GPBDataTypeSFixed32,
GPBDataTypeFloat,
GPBDataTypeFixed64,
GPBDataTypeSFixed64,
GPBDataTypeDouble,
GPBDataTypeInt32,
GPBDataTypeInt64,
GPBDataTypeSInt32,
GPBDataTypeSInt64,
GPBDataTypeUInt32,
GPBDataTypeUInt64,
GPBDataTypeBytes,
GPBDataTypeString,
GPBDataTypeMessage,
GPBDataTypeGroup,
GPBDataTypeEnum,
} GPBDataType;
enum {
// A count of the number of types in GPBType. Separated out from the GPBType
// enum to avoid warnings regarding not handling GPBTypeCount in switch
// statements.
GPBTypeCount = GPBTypeEnum + 1
// A count of the number of types in GPBDataType. Separated out from the
// GPBDataType enum to avoid warnings regarding not handling
// GPBDataType_Count in switch statements.
GPBDataType_Count = GPBDataTypeEnum + 1
};
// An extension range.
......
......@@ -35,7 +35,7 @@
@class GPBUInt64Array;
@class GPBUnknownFieldSet;
@interface GPBField : NSObject<NSCopying>
@interface GPBUnknownField : NSObject<NSCopying>
@property(nonatomic, readonly, assign) int32_t number;
......@@ -43,8 +43,8 @@
@property(nonatomic, readonly, strong) GPBUInt64Array *varintList;
@property(nonatomic, readonly, strong) GPBUInt32Array *fixed32List;
@property(nonatomic, readonly, strong) GPBUInt64Array *fixed64List;
@property(nonatomic, readonly, strong) NSArray *lengthDelimitedList;
@property(nonatomic, readonly, strong) NSArray *groupList;
@property(nonatomic, readonly, strong) NSArray *lengthDelimitedList; // NSData
@property(nonatomic, readonly, strong) NSArray *groupList; // GPBUnknownFieldSet
// Only one of these should be used per Field.
- (void)addVarint:(uint64_t)value;
......
......@@ -28,12 +28,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#import "GPBField_PackagePrivate.h"
#import "GPBUnknownField_PackagePrivate.h"
#import "GPBArray.h"
#import "GPBCodedOutputStream.h"
@interface GPBField () {
@implementation GPBUnknownField {
@protected
int32_t number_;
GPBUInt64Array *mutableVarintList_;
......@@ -42,9 +42,6 @@
NSMutableArray *mutableLengthDelimitedList_;
NSMutableArray *mutableGroupList_;
}
@end
@implementation GPBField
@synthesize number = number_;
@synthesize varintList = mutableVarintList_;
......@@ -71,7 +68,8 @@
}
- (id)copyWithZone:(NSZone *)zone {
GPBField *result = [[GPBField allocWithZone:zone] initWithNumber:number_];
GPBUnknownField *result =
[[GPBUnknownField allocWithZone:zone] initWithNumber:number_];
result->mutableFixed32List_ = [mutableFixed32List_ copyWithZone:zone];
result->mutableFixed64List_ = [mutableFixed64List_ copyWithZone:zone];
result->mutableLengthDelimitedList_ =
......@@ -91,8 +89,8 @@
- (BOOL)isEqual:(id)object {
if (self == object) return YES;
if (![object isKindOfClass:[GPBField class]]) return NO;
GPBField *field = (GPBField *)object;
if (![object isKindOfClass:[GPBUnknownField class]]) return NO;
GPBUnknownField *field = (GPBUnknownField *)object;
BOOL equalVarint =
(mutableVarintList_.count == 0 && field->mutableVarintList_.count == 0) ||
[mutableVarintList_ isEqual:field->mutableVarintList_];
......@@ -131,23 +129,23 @@
- (void)writeToOutput:(GPBCodedOutputStream *)output {
NSUInteger count = mutableVarintList_.count;
if (count > 0) {
[output writeUInt64s:number_ values:mutableVarintList_ tag:0];
[output writeUInt64Array:number_ values:mutableVarintList_ tag:0];
}
count = mutableFixed32List_.count;
if (count > 0) {
[output writeFixed32s:number_ values:mutableFixed32List_ tag:0];
[output writeFixed32Array:number_ values:mutableFixed32List_ tag:0];
}
count = mutableFixed64List_.count;
if (count > 0) {
[output writeFixed64s:number_ values:mutableFixed64List_ tag:0];
[output writeFixed64Array:number_ values:mutableFixed64List_ tag:0];
}
count = mutableLengthDelimitedList_.count;
if (count > 0) {
[output writeDatas:number_ values:mutableLengthDelimitedList_];
[output writeBytesArray:number_ values:mutableLengthDelimitedList_];
}
count = mutableGroupList_.count;
if (count > 0) {
[output writeUnknownGroups:number_ values:mutableGroupList_];
[output writeUnknownGroupArray:number_ values:mutableGroupList_];
}
}
......@@ -173,7 +171,7 @@
}];
for (NSData *data in mutableLengthDelimitedList_) {
result += GPBComputeDataSize(number, data);
result += GPBComputeBytesSize(number, data);
}
for (GPBUnknownFieldSet *set in mutableGroupList_) {
......@@ -229,7 +227,7 @@
return description;
}
- (void)mergeFromField:(GPBField *)other {
- (void)mergeFromField:(GPBUnknownField *)other {
GPBUInt64Array *otherVarintList = other.varintList;
if (otherVarintList.count > 0) {
if (mutableVarintList_ == nil) {
......
......@@ -30,15 +30,15 @@
#import <Foundation/Foundation.h>
@class GPBField;
@class GPBUnknownField;
@interface GPBUnknownFieldSet : NSObject<NSCopying>
- (BOOL)hasField:(int32_t)number;
- (GPBField *)getField:(int32_t)number;
- (GPBUnknownField *)getField:(int32_t)number;
- (NSUInteger)countOfFields;
- (void)addField:(GPBField *)field;
- (void)addField:(GPBUnknownField *)field;
// Returns an NSArray of the GPBFields sorted by the field numbers.
- (NSArray *)sortedFields;
......
......@@ -32,7 +32,7 @@
#import "GPBCodedInputStream_PackagePrivate.h"
#import "GPBCodedOutputStream.h"
#import "GPBField_PackagePrivate.h"
#import "GPBUnknownField_PackagePrivate.h"
#import "GPBUtilities.h"
#import "GPBWireFormat.h"
......@@ -85,10 +85,10 @@ static void checkNumber(int32_t number) {
static void CopyWorker(const void *key, const void *value, void *context) {
#pragma unused(key)
GPBField *field = value;
GPBUnknownField *field = value;
GPBUnknownFieldSet *result = context;
GPBField *copied = [field copy];
GPBUnknownField *copied = [field copy];
[result addField:copied];
[copied release];
}
......@@ -136,9 +136,10 @@ static void CopyWorker(const void *key, const void *value, void *context) {
return fields_ ? (CFDictionaryGetValue(fields_, (void *)key) != nil) : NO;
}
- (GPBField *)getField:(int32_t)number {
- (GPBUnknownField *)getField:(int32_t)number {
ssize_t key = number;
GPBField *result = fields_ ? CFDictionaryGetValue(fields_, (void *)key) : nil;
GPBUnknownField *result =
fields_ ? CFDictionaryGetValue(fields_, (void *)key) : nil;
return result;
}
......@@ -150,12 +151,12 @@ static void CopyWorker(const void *key, const void *value, void *context) {
if (!fields_) return nil;
size_t count = CFDictionaryGetCount(fields_);
ssize_t keys[count];
GPBField *values[count];
GPBUnknownField *values[count];
CFDictionaryGetKeysAndValues(fields_, (const void **)keys,
(const void **)values);
struct GPBFieldPair {
ssize_t key;
GPBField *value;
GPBUnknownField *value;
} pairs[count];
for (size_t i = 0; i < count; ++i) {
pairs[i].key = keys[i];
......@@ -179,13 +180,13 @@ static void CopyWorker(const void *key, const void *value, void *context) {
if (!fields_) return;
size_t count = CFDictionaryGetCount(fields_);
ssize_t keys[count];
GPBField *values[count];
GPBUnknownField *values[count];
CFDictionaryGetKeysAndValues(fields_, (const void **)keys,
(const void **)values);
if (count > 1) {
struct GPBFieldPair {
ssize_t key;
GPBField *value;
GPBUnknownField *value;
} pairs[count];
for (size_t i = 0; i < count; ++i) {
......@@ -199,7 +200,7 @@ static void CopyWorker(const void *key, const void *value, void *context) {
return (a->key > b->key) ? 1 : ((a->key == b->key) ? 0 : -1);
});
for (size_t i = 0; i < count; ++i) {
GPBField *value = pairs[i].value;
GPBUnknownField *value = pairs[i].value;
[value writeToOutput:output];
}
} else {
......@@ -219,7 +220,7 @@ static void CopyWorker(const void *key, const void *value, void *context) {
static void GPBUnknownFieldSetSerializedSize(const void *key, const void *value,
void *context) {
#pragma unused(key)
GPBField *field = value;
GPBUnknownField *field = value;
size_t *result = context;
*result += [field serializedSize];
}
......@@ -237,7 +238,7 @@ static void GPBUnknownFieldSetWriteAsMessageSetTo(const void *key,
const void *value,
void *context) {
#pragma unused(key)
GPBField *field = value;
GPBUnknownField *field = value;
GPBCodedOutputStream *output = context;
[field writeAsMessageSetExtensionToOutput:output];
}
......@@ -253,7 +254,7 @@ static void GPBUnknownFieldSetSerializedSizeAsMessageSet(const void *key,
const void *value,
void *context) {
#pragma unused(key)
GPBField *field = value;
GPBUnknownField *field = value;
size_t *result = context;
*result += [field serializedSizeAsMessageSetExtension];
}
......@@ -280,7 +281,7 @@ static void GPBUnknownFieldSetSerializedSizeAsMessageSet(const void *key,
return GPBWireFormatGetTagWireType(tag) != GPBWireFormatEndGroup;
}
- (void)addField:(GPBField *)field {
- (void)addField:(GPBUnknownField *)field {
int32_t number = [field number];
checkNumber(number);
if (!fields_) {
......@@ -297,12 +298,12 @@ static void GPBUnknownFieldSetSerializedSizeAsMessageSet(const void *key,
CFDictionarySetValue(fields_, (const void *)key, field);
}
- (GPBField *)mutableFieldForNumber:(int32_t)number create:(BOOL)create {
- (GPBUnknownField *)mutableFieldForNumber:(int32_t)number create:(BOOL)create {
ssize_t key = number;
GPBField *existing =
GPBUnknownField *existing =
fields_ ? CFDictionaryGetValue(fields_, (const void *)key) : nil;
if (!existing && create) {
existing = [[GPBField alloc] initWithNumber:number];
existing = [[GPBUnknownField alloc] initWithNumber:number];
// This retains existing.
[self addField:existing];
[existing release];
......@@ -314,19 +315,19 @@ static void GPBUnknownFieldSetMergeUnknownFields(const void *key,
const void *value,
void *context) {
#pragma unused(key)
GPBField *field = value;
GPBUnknownField *field = value;
GPBUnknownFieldSet *self = context;
int32_t number = [field number];
checkNumber(number);
GPBField *oldField = [self mutableFieldForNumber:number create:NO];
GPBUnknownField *oldField = [self mutableFieldForNumber:number create:NO];
if (oldField) {
[oldField mergeFromField:field];
} else {
// Merge only comes from GPBMessage's mergeFrom:, so it means we are on
// mutable message and are an mutable instance, so make sure we need
// mutable fields.
GPBField *fieldCopy = [field copy];
GPBUnknownField *fieldCopy = [field copy];
[self addField:fieldCopy];
[fieldCopy release];
}
......@@ -356,18 +357,18 @@ static void GPBUnknownFieldSetMergeUnknownFields(const void *key,
GPBCodedInputStreamState *state = &input->state_;
switch (GPBWireFormatGetTagWireType(tag)) {
case GPBWireFormatVarint: {
GPBField *field = [self mutableFieldForNumber:number create:YES];
GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
[field addVarint:GPBCodedInputStreamReadInt64(state)];
return YES;
}
case GPBWireFormatFixed64: {
GPBField *field = [self mutableFieldForNumber:number create:YES];
GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
[field addFixed64:GPBCodedInputStreamReadFixed64(state)];
return YES;
}
case GPBWireFormatLengthDelimited: {
NSData *data = GPBCodedInputStreamReadRetainedData(state);
GPBField *field = [self mutableFieldForNumber:number create:YES];
NSData *data = GPBCodedInputStreamReadRetainedBytes(state);
GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
[field addLengthDelimited:data];
[data release];
return YES;
......@@ -375,7 +376,7 @@ static void GPBUnknownFieldSetMergeUnknownFields(const void *key,
case GPBWireFormatStartGroup: {
GPBUnknownFieldSet *unknownFieldSet = [[GPBUnknownFieldSet alloc] init];
[input readUnknownGroup:number message:unknownFieldSet];
GPBField *field = [self mutableFieldForNumber:number create:YES];
GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
[field addGroup:unknownFieldSet];
[unknownFieldSet release];
return YES;
......@@ -383,7 +384,7 @@ static void GPBUnknownFieldSetMergeUnknownFields(const void *key,
case GPBWireFormatEndGroup:
return NO;
case GPBWireFormatFixed32: {
GPBField *field = [self mutableFieldForNumber:number create:YES];
GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
[field addFixed32:GPBCodedInputStreamReadFixed32(state)];
return YES;
}
......@@ -396,7 +397,7 @@ static void GPBUnknownFieldSetMergeUnknownFields(const void *key,
}
- (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data {
GPBField *field = [self mutableFieldForNumber:fieldNum create:YES];
GPBUnknownField *field = [self mutableFieldForNumber:fieldNum create:YES];
[field addLengthDelimited:data];
}
......
......@@ -30,11 +30,11 @@
#import <Foundation/Foundation.h>
#import "GPBField.h"
#import "GPBUnknownField.h"
@class GPBCodedOutputStream;
@interface GPBField ()
@interface GPBUnknownField ()
- (instancetype)initWithNumber:(int32_t)number;
......@@ -44,6 +44,6 @@
- (void)writeAsMessageSetExtensionToOutput:(GPBCodedOutputStream *)output;
- (size_t)serializedSizeAsMessageSetExtension;
- (void)mergeFromField:(GPBField *)other;
- (void)mergeFromField:(GPBUnknownField *)other;
@end
This diff is collapsed.
This diff is collapsed.
......@@ -48,6 +48,15 @@
CF_EXTERN_C_BEGIN
// These two are used to inject a runtime check for version mismatch into the
// generated sources to make sure they are linked with a supporting runtime.
void GPBCheckRuntimeVersionInternal(int32_t version);
GPB_INLINE void GPBDebugCheckRuntimeVersion() {
#if DEBUG
GPBCheckRuntimeVersionInternal(GOOGLE_PROTOBUF_OBJC_GEN_VERSION);
#endif
}
// Conversion functions for de/serializing floating point types.
GPB_INLINE int64_t GPBConvertDoubleToInt64(double v) {
......@@ -116,40 +125,38 @@ GPB_INLINE uint64_t GPBEncodeZigZag64(int64_t n) {
return (n << 1) ^ (n >> 63);
}
GPB_INLINE BOOL GPBTypeIsObject(GPBType type) {
GPB_INLINE BOOL GPBDataTypeIsObject(GPBDataType type) {
switch (type) {
case GPBTypeData:
case GPBTypeString:
case GPBTypeMessage:
case GPBTypeGroup:
case GPBDataTypeBytes:
case GPBDataTypeString:
case GPBDataTypeMessage:
case GPBDataTypeGroup:
return YES;
default:
return NO;
}
}
GPB_INLINE BOOL GPBTypeIsMessage(GPBType type) {
GPB_INLINE BOOL GPBDataTypeIsMessage(GPBDataType type) {
switch (type) {
case GPBTypeMessage:
case GPBTypeGroup:
case GPBDataTypeMessage:
case GPBDataTypeGroup:
return YES;
default:
return NO;
}
}
GPB_INLINE BOOL GPBTypeIsEnum(GPBType type) { return type == GPBTypeEnum; }
GPB_INLINE BOOL GPBFieldTypeIsMessage(GPBFieldDescriptor *field) {
return GPBTypeIsMessage(field->description_->type);
GPB_INLINE BOOL GPBFieldDataTypeIsMessage(GPBFieldDescriptor *field) {
return GPBDataTypeIsMessage(field->description_->dataType);
}
GPB_INLINE BOOL GPBFieldTypeIsObject(GPBFieldDescriptor *field) {
return GPBTypeIsObject(field->description_->type);
GPB_INLINE BOOL GPBFieldDataTypeIsObject(GPBFieldDescriptor *field) {
return GPBDataTypeIsObject(field->description_->dataType);
}
GPB_INLINE BOOL GPBExtensionIsMessage(GPBExtensionDescriptor *ext) {
return GPBTypeIsMessage(ext->description_->type);
return GPBDataTypeIsMessage(ext->description_->dataType);
}
// The field is an array/map or it has an object value.
......@@ -158,7 +165,7 @@ GPB_INLINE BOOL GPBFieldStoresObject(GPBFieldDescriptor *field) {
if ((desc->flags & (GPBFieldRepeated | GPBFieldMapKeyMask)) != 0) {
return YES;
}
return GPBTypeIsObject(desc->type);
return GPBDataTypeIsObject(desc->dataType);
}
BOOL GPBGetHasIvar(GPBMessage *self, int32_t index, uint32_t fieldNumber);
......@@ -272,109 +279,6 @@ void GPBSetAutocreatedRetainedObjectIvarWithField(
void GPBClearAutocreatedMessageIvarWithField(GPBMessage *self,
GPBFieldDescriptor *field);
// Utilities for applying various functions based on Objective C types.
// A basic functor that is passed a field and a context. Returns YES
// if the calling function should continue processing, and NO if the calling
// function should stop processing.
typedef BOOL (*GPBApplyFunction)(GPBFieldDescriptor *field, void *context);
// Functions called for various types. See ApplyFunctionsToMessageFields.
typedef enum {
GPBApplyFunctionObject,
GPBApplyFunctionBool,
GPBApplyFunctionInt32,
GPBApplyFunctionUInt32,
GPBApplyFunctionInt64,
GPBApplyFunctionUInt64,
GPBApplyFunctionFloat,
GPBApplyFunctionDouble,
} GPBApplyFunctionOrder;
enum {
// A count of the number of types in GPBApplyFunctionOrder. Separated out
// from the GPBApplyFunctionOrder enum to avoid warnings regarding not
// handling GPBApplyFunctionCount in switch statements.
GPBApplyFunctionCount = GPBApplyFunctionDouble + 1
};
typedef GPBApplyFunction GPBApplyFunctions[GPBApplyFunctionCount];
// Functions called for various types.
// See ApplyStrictFunctionsToMessageFields.
// They are in the same order as the GPBTypes enum.
typedef GPBApplyFunction GPBApplyStrictFunctions[GPBTypeCount];
// A macro for easily initializing a GPBApplyFunctions struct
// GPBApplyFunctions foo = GPBAPPLY_FUNCTIONS_INIT(Foo);
#define GPBAPPLY_FUNCTIONS_INIT(PREFIX) \
{ \
PREFIX##Object, \
PREFIX##Bool, \
PREFIX##Int32, \
PREFIX##UInt32, \
PREFIX##Int64, \
PREFIX##UInt64, \
PREFIX##Float, \
PREFIX##Double, \
}
// A macro for easily initializing a GPBApplyStrictFunctions struct
// GPBApplyStrictFunctions foo = GPBAPPLY_STRICT_FUNCTIONS_INIT(Foo);
// These need to stay in the same order as
// the GPBType enum.
#define GPBAPPLY_STRICT_FUNCTIONS_INIT(PREFIX) \
{ \
PREFIX##Bool, \
PREFIX##Fixed32, \
PREFIX##SFixed32, \
PREFIX##Float, \
PREFIX##Fixed64, \
PREFIX##SFixed64, \
PREFIX##Double, \
PREFIX##Int32, \
PREFIX##Int64, \
PREFIX##SInt32, \
PREFIX##SInt64, \
PREFIX##UInt32, \
PREFIX##UInt64, \
PREFIX##Data, \
PREFIX##String, \
PREFIX##Message, \
PREFIX##Group, \
PREFIX##Enum, \
}
// Iterates over the fields of a proto |msg| and applies the functions in
// |functions| to them with |context|. If one of the functions in |functions|
// returns NO, it will return immediately and not process the rest of the
// ivars. The types in the fields are mapped so:
// Int32, Enum, SInt32 and SFixed32 will be mapped to the int32Function,
// UInt32 and Fixed32 will be mapped to the uint32Function,
// Bytes, String, Message and Group will be mapped to the objectFunction,
// etc..
// If you require more specific mappings look at
// GPBApplyStrictFunctionsToMessageFields.
void GPBApplyFunctionsToMessageFields(GPBApplyFunctions *functions,
GPBMessage *msg, void *context);
// Iterates over the fields of a proto |msg| and applies the functions in
// |functions| to them with |context|. If one of the functions in |functions|
// returns NO, it will return immediately and not process the rest of the
// ivars. The types in the fields are mapped directly:
// Int32 -> functions[GPBTypeInt32],
// SFixed32 -> functions[GPBTypeSFixed32],
// etc...
// If you can use looser mappings look at GPBApplyFunctionsToMessageFields.
void GPBApplyStrictFunctionsToMessageFields(GPBApplyStrictFunctions *functions,
GPBMessage *msg, void *context);
// Applies the appropriate function in |functions| based on |field|.
// Returns the value from function(name, context).
// Throws an exception if the type is unrecognized.
BOOL GPBApplyFunctionsBasedOnField(GPBFieldDescriptor *field,
GPBApplyFunctions *functions, void *context);
// Returns an Objective C encoding for |selector|. |instanceSel| should be
// YES if it's an instance selector (as opposed to a class selector).
// |selector| must be a selector from MessageSignatureProtocol.
......@@ -410,7 +314,7 @@ GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, SInt32)
GPB_MESSAGE_SIGNATURE_ENTRY(int64_t, SInt64)
GPB_MESSAGE_SIGNATURE_ENTRY(uint32_t, UInt32)
GPB_MESSAGE_SIGNATURE_ENTRY(uint64_t, UInt64)
GPB_MESSAGE_SIGNATURE_ENTRY(NSData *, Data)
GPB_MESSAGE_SIGNATURE_ENTRY(NSData *, Bytes)
GPB_MESSAGE_SIGNATURE_ENTRY(NSString *, String)
GPB_MESSAGE_SIGNATURE_ENTRY(GPBMessage *, Message)
GPB_MESSAGE_SIGNATURE_ENTRY(GPBMessage *, Group)
......@@ -419,6 +323,7 @@ GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, Enum)
#undef GPB_MESSAGE_SIGNATURE_ENTRY
- (id)getArray;
- (NSUInteger)getArrayCount;
- (void)setArray:(NSArray *)array;
+ (id)getClassValue;
@end
......
......@@ -28,7 +28,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#import "GPBTypes.h"
#import "GPBRuntimeTypes.h"
CF_EXTERN_C_BEGIN
......@@ -52,7 +52,7 @@ uint32_t GPBWireFormatMakeTag(uint32_t fieldNumber, GPBWireFormat wireType)
GPBWireFormat GPBWireFormatGetTagWireType(uint32_t tag) __attribute__((const));
uint32_t GPBWireFormatGetTagFieldNumber(uint32_t tag) __attribute__((const));
GPBWireFormat GPBWireFormatForType(GPBType type, BOOL isPacked)
GPBWireFormat GPBWireFormatForType(GPBDataType dataType, BOOL isPacked)
__attribute__((const));
#define GPBWireFormatMessageSetItemTag \
......
......@@ -49,30 +49,30 @@ uint32_t GPBWireFormatGetTagFieldNumber(uint32_t tag) {
return GPBLogicalRightShift32(tag, GPBWireFormatTagTypeBits);
}
GPBWireFormat GPBWireFormatForType(GPBType type, BOOL isPacked) {
GPBWireFormat GPBWireFormatForType(GPBDataType type, BOOL isPacked) {
if (isPacked) {
return GPBWireFormatLengthDelimited;
}
static const GPBWireFormat format[GPBTypeCount] = {
GPBWireFormatVarint, // GPBTypeBool
GPBWireFormatFixed32, // GPBTypeFixed32
GPBWireFormatFixed32, // GPBTypeSFixed32
GPBWireFormatFixed32, // GPBTypeFloat
GPBWireFormatFixed64, // GPBTypeFixed64
GPBWireFormatFixed64, // GPBTypeSFixed64
GPBWireFormatFixed64, // GPBTypeDouble
GPBWireFormatVarint, // GPBTypeInt32
GPBWireFormatVarint, // GPBTypeInt64
GPBWireFormatVarint, // GPBTypeSInt32
GPBWireFormatVarint, // GPBTypeSInt64
GPBWireFormatVarint, // GPBTypeUInt32
GPBWireFormatVarint, // GPBTypeUInt64
GPBWireFormatLengthDelimited, // GPBTypeBytes
GPBWireFormatLengthDelimited, // GPBTypeString
GPBWireFormatLengthDelimited, // GPBTypeMessage
GPBWireFormatStartGroup, // GPBTypeGroup
GPBWireFormatVarint // GPBTypeEnum
static const GPBWireFormat format[GPBDataType_Count] = {
GPBWireFormatVarint, // GPBDataTypeBool
GPBWireFormatFixed32, // GPBDataTypeFixed32
GPBWireFormatFixed32, // GPBDataTypeSFixed32
GPBWireFormatFixed32, // GPBDataTypeFloat
GPBWireFormatFixed64, // GPBDataTypeFixed64
GPBWireFormatFixed64, // GPBDataTypeSFixed64
GPBWireFormatFixed64, // GPBDataTypeDouble
GPBWireFormatVarint, // GPBDataTypeInt32
GPBWireFormatVarint, // GPBDataTypeInt64
GPBWireFormatVarint, // GPBDataTypeSInt32
GPBWireFormatVarint, // GPBDataTypeSInt64
GPBWireFormatVarint, // GPBDataTypeUInt32
GPBWireFormatVarint, // GPBDataTypeUInt64
GPBWireFormatLengthDelimited, // GPBDataTypeBytes
GPBWireFormatLengthDelimited, // GPBDataTypeString
GPBWireFormatLengthDelimited, // GPBDataTypeMessage
GPBWireFormatStartGroup, // GPBDataTypeGroup
GPBWireFormatVarint // GPBDataTypeEnum
};
return format[type];
}
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0620"
LastUpgradeVersion = "0630"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0610"
LastUpgradeVersion = "0630"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......
This diff is collapsed.
// Protocol Buffers - Google's data interchange format
// Copyright 2014 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Test the filter system for the ObjC Protocol Buffer Compiler to test
// multiple filter support.
Other
......@@ -41,16 +41,15 @@
#import "google/protobuf/UnittestEmbedOptimizeFor.pbobjc.h"
#import "google/protobuf/UnittestEmpty.pbobjc.h"
#import "google/protobuf/UnittestEnormousDescriptor.pbobjc.h"
#import "google/protobuf/UnittestFilter.pbobjc.h"
#import "google/protobuf/UnittestImport.pbobjc.h"
#import "google/protobuf/UnittestImportLite.pbobjc.h"
#import "google/protobuf/UnittestImportPublic.pbobjc.h"
#import "google/protobuf/UnittestImportPublicLite.pbobjc.h"
#import "google/protobuf/UnittestLite.pbobjc.h"
#import "google/protobuf/UnittestMset.pbobjc.h"
#import "google/protobuf/UnittestNameMangling.pbobjc.h"
#import "google/protobuf/UnittestNoGenericServices.pbobjc.h"
#import "google/protobuf/UnittestObjc.pbobjc.h"
#import "google/protobuf/UnittestObjcStartup.pbobjc.h"
#import "google/protobuf/UnittestOptimizeFor.pbobjc.h"
#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h"
#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
......
......@@ -260,7 +260,7 @@
[GPBCodedInputStream streamWithData:[NSMutableData dataWithData:data]];
XCTAssertEqual(tag, [input readTag]);
XCTAssertThrows([input readData]);
XCTAssertThrows([input readBytes]);
}
// Verifies fix for b/10315336.
......
......@@ -196,7 +196,8 @@ static const int kNumMessages = 100;
NSArray *threads = [self createThreadsWithSelector:sel object:messages];
[self startThreads:threads];
[self joinThreads:threads];
GPBExtensionField *extension = [UnittestRoot optionalForeignMessageExtension];
GPBExtensionDescriptor *extension =
[UnittestRoot optionalForeignMessageExtension];
for (TestAllExtensions *message in messages) {
XCTAssertFalse([message hasExtension:extension]);
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -152,6 +152,7 @@ typedef GPB_ENUM(GPBFieldMask_FieldNumber) {
// The set of field mask paths.
// |pathsArray| contains |NSString|
@property(nonatomic, readwrite, strong) NSMutableArray *pathsArray;
@property(nonatomic, readonly) NSUInteger pathsArray_Count;
@end
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment