Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract<Poco::JSON::Object::Ptr>() fails on iPhone 6 #1275

Closed
advntss opened this issue May 16, 2016 · 4 comments
Closed

extract<Poco::JSON::Object::Ptr>() fails on iPhone 6 #1275

advntss opened this issue May 16, 2016 · 4 comments
Assignees
Labels

Comments

@advntss
Copy link

advntss commented May 16, 2016

The code below works fine on iPhone 4s and iPhoneSimulator and Windows as well:

Poco::JSON::Parser jsonParser;
auto parsedJSON = jsonParser.parse("{\"Method\":\"multiply\",\"ArgsJson\":\"[1.1,1.1]\"}");
auto parsedResult = parsedJSON.extract<Poco::JSON::Object::Ptr>();

but fails on iPhone 5/6 with exception message

 Can not convert N4Poco9SharedPtrINS_4JSON6ObjectENS_16ReferenceCounterENS_13ReleasePolicyIS2_EEEE to 4Poco9SharedPtrINS_4JSON6ObjectENS_16ReferenceCounterENS_13ReleasePolicyIS2_EEEE

All Poco libraries for iPhone 6 was built for arm64 architecture using actual make files

./configure --config=iPhone-clang-libc++ --static --no-tests --no-samples --minimal
make POCO_TARGET_OSARCH=arm64 -s -j4

And compiler settings in XCode
image

Please advice how to avoid that fail or fix the sources.

UPD: debugging shows that POCO_LONG_IS_64_BIT is defned

@advntss advntss changed the title JSON parser.parse fails on iPhone 6 if JSON string has multiple properties in single level extract<Poco::JSON::Object::Ptr>() fails on iPhone 6 May 17, 2016
@advntss
Copy link
Author

advntss commented May 18, 2016

Exception is being thrown from the code below in Var.h
Looks like pHolder->type() == typeid(T) comparison somehow returns false for the same type

    template <typename T>
    const T& extract() const
        /// Returns a const reference to the actual value.
        ///
        /// Must be instantiated with the exact type of
        /// the stored value, otherwise a BadCastException
        /// is thrown.
        /// Throws InvalidAccessException if Var is empty.
    {
        VarHolder* pHolder = content();

        if (pHolder && pHolder->type() == typeid(T))
        {
            VarHolderImpl<T>* pHolderImpl = static_cast<VarHolderImpl<T>*>(pHolder);
            return pHolderImpl->value();
        }
        else if (!pHolder)
            throw InvalidAccessException("Can not extract empty value.");
        else
            throw BadCastException(format("Can not convert %s to %s.",
                std::string(pHolder->type().name()),
                std::string(typeid(T).name())));
    }

@AbhinavBansal
Copy link

Hi, Is there a solution to this?

I am also getting Bad cast exception.

Can not convert N4Poco9SharedPtrINS_4JSON6ObjectENS_16ReferenceCounterENS_13ReleasePolicyIS2_EEEE to N4Poco9SharedPtrINS_4JSON6ObjectENS_16ReferenceCounterENS_13ReleasePolicyIS2_EEEE.

My JSON is in the format:
{"AAA":{"BBB":"onemoresuffix.com","deleted":1}}

Code:
Poco::JSON::Parser parser;
Poco::Dynamic::Var result = parser.parse(json);
std::string value = result.convertstd::string();

Interestingly, If I run app in DEBUG mode, it works, but fails in RELEASE mode.
Is there any compiler setting that I should do?
Any help would be appreciated.

@AbhinavBansal
Copy link

Is there anything I can do about it.
I have changed the condition to workaround
strcmp(pHolder->type().name(),typeid(T).name()) == 0 instead of pHolder->type() == typeid(T)

@killerbobjr
Copy link

For arm64 builds, add the compiler flag: -fvisibility=hidden
There seems to be some sort of an issue in ParserHandler that causes Object::get to return a null when compiled without this flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants